feat: Files uploadFailedSecond error text done.

This commit is contained in:
chiayin
2024-01-17 16:59:57 +08:00
parent a9f991a715
commit b23d89bc38
2 changed files with 39 additions and 30 deletions

View File

@@ -171,7 +171,7 @@ export async function leaveConformance(next, addConformanceCreateCheckId, toPath
* @param { string } failureType
* @param { string } failureMsg
*/
export async function uploadFailedFirst(failureType, failureMsg) {
export async function uploadFailedFirst(failureType, failureMsg, failureLoc) {
// 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 = '';
@@ -180,16 +180,16 @@ export async function uploadFailedFirst(failureType, failureMsg) {
value = 'File size exceeds 90MB.';
break;
case 'encoding':
value = 'not in UTF-8';
value = `Please use [UFT-8] for character encoding: (Row #${failureLoc})`;
break;
case 'insufficient_columns':
value = 'insufficient columns';
value = 'Need at least five columns of data.';
break;
case 'empty':
value = 'the csv file is empty';
value = 'Need at least one record of data.';
break;
case 'name_suffix':
value = 'the filename does not ends with .csv';
value = 'File is not in [csv] format.';
break;
default:
value = failureMsg;
@@ -207,31 +207,41 @@ export async function uploadFailedFirst(failureType, failureMsg) {
};
/**
* Upload failde Second
* @param { string } failureType
* @param { string } failureMsg
* @param { array } detail
*/
export async function uploadFailedSecond(failureType, failureMsg) {
let value = '';
switch (failureType) {
export async function uploadFailedSecond(detail) {
let srt = '';
let manySrt = '';
detail.forEach(i => {
let content = '';
switch (i.type) {
case 'too_many':
manySrt = 'There are more errors.';
break;
case 'unrecognized':
content = `<li>Data unregnizable in [Status] Column: (Row #${i.loc[1]}, "${i.input}")</li>`;
break;
case 'malformed':
value = failureMsg;
content = `<li>Data malformed in [Timestamp] Column: (Row #${i.loc[1]}, "${i.input}")</li>`;
break;
case 'missing':
value = failureMsg;
break;
default:
value = failureMsg;
content = `<li>Data missing in [${i.loc[2]}] Column: (Row #${i.loc[1]})</li>`;
break;
}
srt += content;
});
await Swal.fire({
title: 'UPLOAD FAILED',
html: value,
html: `<div class="w-[500px] text-left mx-auto space-y-1"><p>The following errors have been detected:</p><ul class="list-disc ml-6">${srt}</ul><p>${manySrt} Please check.</p></div>`,
timer: 5000, // 停留5秒後自動關閉
showConfirmButton: false,
icon: 'error',
iconColor: '#FF3366',
customClass: customClass
})
});
srt = '';
};
/**
* Upload Success
@@ -277,7 +287,6 @@ export async function uploadConfirm(fetchData) {
export async function uploadloader() {
await Swal.fire({
html: '<span class="loaderBar mt-7"></span>',
// timer: 5000, // 停留5秒後自動關閉
showConfirmButton: false,
allowOutsideClick: false,
customClass: customClass,

View File

@@ -123,16 +123,17 @@ export default defineStore('filesStore', {
uploadloader(); // 進度條
try {
const response = await axios.post(api, fromData, config);
console.log('第一階段 response:', response);
this.uploadId = response.data.id;
this.$router.push({name: 'Upload'});
Swal.close(); // 關閉進度條
} catch(error) {
console.log('第一階段 error:', error);
if(error.response.status === 422) {
// 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'
uploadFailedFirst(error.response.data.detail[0].type, error.response.data.detail[0].msg);
let detail = error.response.data.detail;
uploadFailedFirst(detail[0].type, detail[0].msg, detail[0].loc[2]);
} else {
Swal.close(); // 關閉進度條
apiError(error, 'Failed to upload the files.');
@@ -164,7 +165,6 @@ export default defineStore('filesStore', {
uploadloader(); // 進度條
try {
const response = await axios.post(api, data);
console.log('第二階段 response:', response);
this.uploadLogId = await response.data.id;
await Swal.close(); // 關閉進度條
@@ -172,10 +172,10 @@ export default defineStore('filesStore', {
await uploadSuccess();
this.$router.push({name: 'Files'});
} catch(error) {
console.log('第二階段 error:', error);
if(error.response.status === 422) {
uploadFailedSecond(error.response.data.detail[0].type, error.response.data.detail[0].msg);
let detail = [...error.response.data.detail];
uploadFailedSecond(detail);
} else {
Swal.close(); // 關閉進度條
apiError(error, 'Failed to upload the log files.');