feat: Upload failde Second Modal done.
This commit is contained in:
@@ -16,7 +16,7 @@
|
|||||||
</template>
|
</template>
|
||||||
<script>
|
<script>
|
||||||
import IconUploarding from '../icons/IconUploarding.vue';
|
import IconUploarding from '../icons/IconUploarding.vue';
|
||||||
import { uploadFailed } from '@/module/alertModal.js'
|
import { uploadFailedFirst } from '@/module/alertModal.js'
|
||||||
import { storeToRefs } from 'pinia';
|
import { storeToRefs } from 'pinia';
|
||||||
import FilesStore from '@/stores/files.js';
|
import FilesStore from '@/stores/files.js';
|
||||||
|
|
||||||
@@ -46,7 +46,7 @@ export default {
|
|||||||
// 判斷是否有檔案
|
// 判斷是否有檔案
|
||||||
if(target && target.files) uploadFile = target.files[0];
|
if(target && target.files) uploadFile = target.files[0];
|
||||||
// 判斷檔案大小不可超過 90MB (90(MB)*1024(KB)*1024(Bytes)=94,371,840)
|
// 判斷檔案大小不可超過 90MB (90(MB)*1024(KB)*1024(Bytes)=94,371,840)
|
||||||
if(uploadFile.size >= 94371840) return uploadFailed('size')
|
if(uploadFile.size >= 94371840) return uploadFailedFirst('size')
|
||||||
// 將檔案加進 formData,欄位一定要「csv」
|
// 將檔案加進 formData,欄位一定要「csv」
|
||||||
formData.append('csv', uploadFile);
|
formData.append('csv', uploadFile);
|
||||||
// 呼叫第一階段上傳 API
|
// 呼叫第一階段上傳 API
|
||||||
|
|||||||
@@ -167,11 +167,11 @@ export async function leaveConformance(next, addConformanceCreateCheckId, toPath
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
* Upload failde
|
* Upload failde First
|
||||||
* @param { string } failureType
|
* @param { string } failureType
|
||||||
* @param { string } failureMsg
|
* @param { string } failureMsg
|
||||||
*/
|
*/
|
||||||
export async function uploadFailed(failureType, failureMsg) {
|
export async function uploadFailedFirst(failureType, failureMsg) {
|
||||||
// msg: 'not in UTF-8' | 'insufficient columns' | 'the csv file is empty' | 'the filename does not ends with .csv'
|
// 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'
|
// type: 'encoding' | 'insufficient_columns' | 'empty' | 'name_suffix'
|
||||||
let value = '';
|
let value = '';
|
||||||
@@ -205,6 +205,34 @@ export async function uploadFailed(failureType, failureMsg) {
|
|||||||
customClass: customClass
|
customClass: customClass
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
/**
|
||||||
|
* Upload failde Second
|
||||||
|
* @param { string } failureType
|
||||||
|
* @param { string } failureMsg
|
||||||
|
*/
|
||||||
|
export async function uploadFailedSecond(failureType, failureMsg) {
|
||||||
|
let value = '';
|
||||||
|
switch (failureType) {
|
||||||
|
case 'malformed':
|
||||||
|
value = failureMsg;
|
||||||
|
break;
|
||||||
|
case 'missing':
|
||||||
|
value = failureMsg;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
value = failureMsg;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
await Swal.fire({
|
||||||
|
title: 'UPLOAD FAILED',
|
||||||
|
html: value,
|
||||||
|
timer: 5000, // 停留5秒後自動關閉
|
||||||
|
showConfirmButton: false,
|
||||||
|
icon: 'error',
|
||||||
|
iconColor: '#FF3366',
|
||||||
|
customClass: customClass
|
||||||
|
})
|
||||||
|
};
|
||||||
/**
|
/**
|
||||||
* Upload Success
|
* Upload Success
|
||||||
* @param { string } value
|
* @param { string } value
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import axios from "axios";
|
|||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import apiError from '@/module/apiError.js';
|
import apiError from '@/module/apiError.js';
|
||||||
import Swal from 'sweetalert2';
|
import Swal from 'sweetalert2';
|
||||||
import { uploadFailed, uploadloader, uploadSuccess } from '@/module/alertModal.js'
|
import { uploadFailedFirst, uploadFailedSecond, uploadloader, uploadSuccess } from '@/module/alertModal.js'
|
||||||
|
|
||||||
export default defineStore('filesStore', {
|
export default defineStore('filesStore', {
|
||||||
state: () => ({
|
state: () => ({
|
||||||
@@ -119,7 +119,7 @@ export default defineStore('filesStore', {
|
|||||||
if(error.response.status === 422) {
|
if(error.response.status === 422) {
|
||||||
// msg: 'not in UTF-8' | 'insufficient columns' | 'the csv file is empty' | 'the filename does not ends with .csv'
|
// 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'
|
// type: 'encoding' | 'insufficient_columns' | 'empty' | 'name_suffix'
|
||||||
uploadFailed(error.response.data.detail[0].type, error.response.data.detail[0].msg);
|
uploadFailedFirst(error.response.data.detail[0].type, error.response.data.detail[0].msg);
|
||||||
} else {
|
} else {
|
||||||
Swal.close(); // 關閉進度條
|
Swal.close(); // 關閉進度條
|
||||||
apiError(error, 'Failed to upload the files.');
|
apiError(error, 'Failed to upload the files.');
|
||||||
@@ -159,7 +159,7 @@ export default defineStore('filesStore', {
|
|||||||
} catch(error) {
|
} catch(error) {
|
||||||
console.log('error:', error);
|
console.log('error:', error);
|
||||||
if(error.response.status === 422) {
|
if(error.response.status === 422) {
|
||||||
uploadFailed(error.response.data.detail[0].type, error.response.data.detail[0].msg);
|
uploadFailedSecond(error.response.data.detail[0].type, error.response.data.detail[0].msg);
|
||||||
} else {
|
} else {
|
||||||
Swal.close(); // 關閉進度條
|
Swal.close(); // 關閉進度條
|
||||||
apiError(error, 'Failed to upload the log files.');
|
apiError(error, 'Failed to upload the log files.');
|
||||||
|
|||||||
@@ -86,7 +86,7 @@
|
|||||||
import { storeToRefs } from 'pinia';
|
import { storeToRefs } from 'pinia';
|
||||||
import LoadingStore from '@/stores/loading.js';
|
import LoadingStore from '@/stores/loading.js';
|
||||||
import FilesStore from '@/stores/files.js';
|
import FilesStore from '@/stores/files.js';
|
||||||
import { uploadFailed, uploadSuccess, uploadConfirm } from '@/module/alertModal.js'
|
import { uploadFailedFirst, uploadSuccess, uploadConfirm } from '@/module/alertModal.js'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
setup() {
|
setup() {
|
||||||
@@ -147,7 +147,7 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
uploadFailed,
|
uploadFailedFirst,
|
||||||
uploadSuccess,
|
uploadSuccess,
|
||||||
uploadConfirm,
|
uploadConfirm,
|
||||||
/**
|
/**
|
||||||
@@ -264,7 +264,6 @@ export default {
|
|||||||
|
|
||||||
// 取得欲更改的檔名,
|
// 取得欲更改的檔名,
|
||||||
this.uploadFileName = this.fileName;
|
this.uploadFileName = this.fileName;
|
||||||
// this.filesStore.rename();
|
|
||||||
// 設定第二階段上傳的 data
|
// 設定第二階段上傳的 data
|
||||||
haveValueData.forEach(column => {
|
haveValueData.forEach(column => {
|
||||||
switch (column.code) {
|
switch (column.code) {
|
||||||
|
|||||||
Reference in New Issue
Block a user