修复没有文件时还会发送上传请求的BUG

This commit is contained in:
fangxiang 2021-08-16 16:20:35 +08:00
parent fd2cbc8570
commit 479c6a1f60
4 changed files with 55 additions and 4 deletions

View File

@ -41,6 +41,8 @@
:hide-upload-btn="true"
@uploaded="onUploaded"
@failed="onFailed"
@added="(files) => files && (file_count += files.length)"
@removed="(files) => files && (file_count -= files.length)"
/>
</q-item-section>
</q-item>
@ -102,12 +104,14 @@ export default defineComponent({
let uploader: any = ref(null);
let loading = ref(false);
let upload_url = ref("");
let file_count = ref(0);
return {
show_dialog,
loading,
upload_url,
uploader,
file_count,
loga(a: any) {
console.log(a);
},
@ -146,6 +150,7 @@ export default defineComponent({
resetData() {
loading.value = false;
upload_url.value = "";
file_count.value = 0;
},
showBackgroundImage() {
viewerApi({
@ -164,6 +169,15 @@ export default defineComponent({
});
},
async onSubmit() {
if (file_count.value <= 0) {
$q.notify({
type: "warning",
message: $t.t("please select file first") + "!",
position: "top",
timeout: 1500,
});
return;
}
loading.value = true;
try {
$q.dialog({

View File

@ -41,6 +41,8 @@
:hide-upload-btn="true"
@uploaded="onUploaded"
@failed="onFailed"
@added="(files) => files && (file_count += files.length)"
@removed="(files) => files && (file_count -= files.length)"
/>
</q-item-section>
</q-item>
@ -94,12 +96,14 @@ export default defineComponent({
let uploader: any = ref(null);
let loading = ref(false);
let upload_url = ref("");
let file_count = ref(0);
return {
show_dialog,
loading,
upload_url,
uploader,
file_count,
generatorFileUploadHeaders(files: File[]) {
if (files.length > 0) {
return [
@ -132,8 +136,18 @@ export default defineComponent({
resetData() {
loading.value = false;
upload_url.value = "";
file_count.value = 0;
},
async onSubmit() {
if (file_count.value <= 0) {
$q.notify({
type: "warning",
message: $t.t("please select file first") + "!",
position: "top",
timeout: 1500,
});
return;
}
loading.value = true;
try {
$q.dialog({

View File

@ -35,6 +35,7 @@
:hint="$t('please input') + $t('upgrade type') + ':'"
:options="select_options"
v-model="upgrade_type"
@update:model-value="file_count = 0"
>
</q-select>
</q-item-section>
@ -53,6 +54,8 @@
:hide-upload-btn="true"
@uploaded="onUploaded"
@failed="onFailed"
@added="(files) => files && (file_count += files.length)"
@removed="(files) => files && (file_count -= files.length)"
/>
<q-uploader
v-if="upgrade_type == 'rootfs'"
@ -66,6 +69,8 @@
:hide-upload-btn="true"
@uploaded="onUploaded"
@failed="onFailed"
@added="(files) => files && (file_count += files.length)"
@removed="(files) => files && (file_count -= files.length)"
/>
</q-item-section>
</q-item>
@ -120,6 +125,7 @@ export default defineComponent({
let loading = ref(false);
let upload_url_software = ref("");
let upload_url_rootfs = ref("");
let file_count = ref(0);
let select_options = ["software", "rootfs"];
let upgrade_type = ref("software");
@ -131,6 +137,7 @@ export default defineComponent({
upload_url_rootfs,
uploader_software,
uploader_rootfs,
file_count,
upgrade_type,
select_options,
generatorFileUploadHeaders(files: File[]) {
@ -148,6 +155,9 @@ export default defineComponent({
}
return [];
},
loga(a: any) {
console.log(a);
},
showDialog() {
show_dialog.value = true;
@ -170,10 +180,24 @@ export default defineComponent({
loading.value = false;
upload_url_software.value = "";
upload_url_rootfs.value = "";
file_count.value = 0;
},
async onSubmit() {
async onSubmit(a: any) {
if (file_count.value <= 0) {
$q.notify({
type: "warning",
message: $t.t("please select file first") + "!",
position: "top",
timeout: 1500,
});
return;
}
loading.value = true;
try {
let upgrader =
upgrade_type.value == "software"
? uploader_software.value
: uploader_rootfs.value;
$q.dialog({
title: "Confirm",
message: $t.t("use this file to upgrade") + "?",
@ -181,9 +205,7 @@ export default defineComponent({
persistent: true,
})
.onOk(() => {
upgrade_type.value == "software"
? uploader_software.value.upload()
: uploader_rootfs.value.upload();
upgrader.upload();
})
.onCancel(() => {
loading.value = false;

View File

@ -88,4 +88,5 @@ export default {
"use this file to upgrade": "使用这个升级文件",
software: "软件",
rootfs: "文件系统",
"please select file first": "请先选择文件",
};