feat: upload done.

This commit is contained in:
chiayin
2023-12-29 16:05:27 +08:00
parent cd2ab42125
commit 9ef441ee83
8 changed files with 384 additions and 207 deletions

View File

@@ -1,7 +1,7 @@
import Swal from 'sweetalert2';
import AllMapDataStore from '@/stores/allMapData.js';
import ConformanceStore from '@/stores/conformance.js';
import LoginStore from '@/stores/login.js';
import FilesStore from '@/stores/files.js';
const customClass = {
container: '!z-[99999]',
@@ -168,13 +168,36 @@ export async function leaveConformance(next, addConformanceCreateCheckId, toPath
};
/**
* Upload failde
* @param { string } value
* @param { string } failureType
* @param { string } failureMsg
*/
export async function uploadFailde(value) {
value = value ? value : '';
export async function uploadFailed(failureType, failureMsg) {
// msg: 'not in UTF-8' | 'insufficient columns' | 'the csv file is empty' | 'the filename does not ends with .csv'
// type: 'encoding' | 'insufficient_columns' | 'empty' | 'name_suffix'
let value = '';
switch (failureType) {
case 'size':
value = '檔案大小不可超過 90MB';
break;
case 'encoding':
value = 'not in UTF-8';
break;
case 'insufficient_columns':
value = 'insufficient columns';
break;
case 'empty':
value = 'the csv file is empty';
break;
case 'name_suffix':
value = 'the filename does not ends with .csv';
break;
default:
value = failureMsg;
break;
}
await Swal.fire({
title: 'UPLOAD FAILED',
html: `(錯誤樣態由前後端自行確認,呈現於此處) e.g.您的資料格式錯誤,請檢查資料後再重新上傳。`,
html: value,
timer: 5000, // 停留5秒後自動關閉
showConfirmButton: false,
icon: 'error',
@@ -197,8 +220,12 @@ export async function uploadSuccess() {
})
};
/**
* Confirm whether to upload the file */
export async function uploadConfirm() {
* Confirm whether to upload the file
* @param { object } fetchData
*/
export async function uploadConfirm(fetchData) {
const filesStore = FilesStore();
const result = await Swal.fire({
title: 'ARE YOU SURE?',
html: 'After uploading, you wont be able to modify labels.',
@@ -210,10 +237,10 @@ export async function uploadConfirm() {
showCancelButton: true,
cancelButtonText: 'No',
cancelButtonColor: '#94a3b8',
customClass: customClass
customClass: customClass,
})
if(result.isConfirmed) {
uploadloader(); // 跑馬燈
filesStore.uploadLog(fetchData);
} else if(result.dismiss === 'cancel') {
// 什麼都不做
} else if(result.dismiss === 'backdrop') {
@@ -226,10 +253,9 @@ export async function uploadConfirm() {
export async function uploadloader() {
await Swal.fire({
html: '<span class="loaderBar mt-7"></span>',
timer: 5000, // 停留5秒後自動關閉
// timer: 5000, // 停留5秒後自動關閉
showConfirmButton: false,
allowOutsideClick: false,
// allowOutsideClick: () => !Swal.isLoading()
customClass: customClass
customClass: customClass,
})
};