修复没有文件时还会发送上传请求的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" :hide-upload-btn="true"
@uploaded="onUploaded" @uploaded="onUploaded"
@failed="onFailed" @failed="onFailed"
@added="(files) => files && (file_count += files.length)"
@removed="(files) => files && (file_count -= files.length)"
/> />
</q-item-section> </q-item-section>
</q-item> </q-item>
@ -102,12 +104,14 @@ export default defineComponent({
let uploader: any = ref(null); let uploader: any = ref(null);
let loading = ref(false); let loading = ref(false);
let upload_url = ref(""); let upload_url = ref("");
let file_count = ref(0);
return { return {
show_dialog, show_dialog,
loading, loading,
upload_url, upload_url,
uploader, uploader,
file_count,
loga(a: any) { loga(a: any) {
console.log(a); console.log(a);
}, },
@ -146,6 +150,7 @@ export default defineComponent({
resetData() { resetData() {
loading.value = false; loading.value = false;
upload_url.value = ""; upload_url.value = "";
file_count.value = 0;
}, },
showBackgroundImage() { showBackgroundImage() {
viewerApi({ viewerApi({
@ -164,6 +169,15 @@ export default defineComponent({
}); });
}, },
async onSubmit() { 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; loading.value = true;
try { try {
$q.dialog({ $q.dialog({

View File

@ -41,6 +41,8 @@
:hide-upload-btn="true" :hide-upload-btn="true"
@uploaded="onUploaded" @uploaded="onUploaded"
@failed="onFailed" @failed="onFailed"
@added="(files) => files && (file_count += files.length)"
@removed="(files) => files && (file_count -= files.length)"
/> />
</q-item-section> </q-item-section>
</q-item> </q-item>
@ -94,12 +96,14 @@ export default defineComponent({
let uploader: any = ref(null); let uploader: any = ref(null);
let loading = ref(false); let loading = ref(false);
let upload_url = ref(""); let upload_url = ref("");
let file_count = ref(0);
return { return {
show_dialog, show_dialog,
loading, loading,
upload_url, upload_url,
uploader, uploader,
file_count,
generatorFileUploadHeaders(files: File[]) { generatorFileUploadHeaders(files: File[]) {
if (files.length > 0) { if (files.length > 0) {
return [ return [
@ -132,8 +136,18 @@ export default defineComponent({
resetData() { resetData() {
loading.value = false; loading.value = false;
upload_url.value = ""; upload_url.value = "";
file_count.value = 0;
}, },
async onSubmit() { 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; loading.value = true;
try { try {
$q.dialog({ $q.dialog({

View File

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

View File

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