feat: Files uploadFailedSecond error text done.
This commit is contained in:
@@ -171,7 +171,7 @@ export async function leaveConformance(next, addConformanceCreateCheckId, toPath
|
|||||||
* @param { string } failureType
|
* @param { string } failureType
|
||||||
* @param { string } failureMsg
|
* @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'
|
// 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 = '';
|
||||||
@@ -180,16 +180,16 @@ export async function uploadFailedFirst(failureType, failureMsg) {
|
|||||||
value = 'File size exceeds 90MB.';
|
value = 'File size exceeds 90MB.';
|
||||||
break;
|
break;
|
||||||
case 'encoding':
|
case 'encoding':
|
||||||
value = 'not in UTF-8';
|
value = `Please use [UFT-8] for character encoding: (Row #${failureLoc})`;
|
||||||
break;
|
break;
|
||||||
case 'insufficient_columns':
|
case 'insufficient_columns':
|
||||||
value = 'insufficient columns';
|
value = 'Need at least five columns of data.';
|
||||||
break;
|
break;
|
||||||
case 'empty':
|
case 'empty':
|
||||||
value = 'the csv file is empty';
|
value = 'Need at least one record of data.';
|
||||||
break;
|
break;
|
||||||
case 'name_suffix':
|
case 'name_suffix':
|
||||||
value = 'the filename does not ends with .csv';
|
value = 'File is not in [csv] format.';
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
value = failureMsg;
|
value = failureMsg;
|
||||||
@@ -207,31 +207,41 @@ export async function uploadFailedFirst(failureType, failureMsg) {
|
|||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
* Upload failde Second
|
* Upload failde Second
|
||||||
* @param { string } failureType
|
* @param { array } detail
|
||||||
* @param { string } failureMsg
|
|
||||||
*/
|
*/
|
||||||
export async function uploadFailedSecond(failureType, failureMsg) {
|
export async function uploadFailedSecond(detail) {
|
||||||
let value = '';
|
let srt = '';
|
||||||
switch (failureType) {
|
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':
|
case 'malformed':
|
||||||
value = failureMsg;
|
content = `<li>Data malformed in [Timestamp] Column: (Row #${i.loc[1]}, "${i.input}")</li>`;
|
||||||
break;
|
break;
|
||||||
case 'missing':
|
case 'missing':
|
||||||
value = failureMsg;
|
content = `<li>Data missing in [${i.loc[2]}] Column: (Row #${i.loc[1]})</li>`;
|
||||||
break;
|
|
||||||
default:
|
|
||||||
value = failureMsg;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
srt += content;
|
||||||
|
});
|
||||||
await Swal.fire({
|
await Swal.fire({
|
||||||
title: 'UPLOAD FAILED',
|
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秒後自動關閉
|
timer: 5000, // 停留5秒後自動關閉
|
||||||
showConfirmButton: false,
|
showConfirmButton: false,
|
||||||
icon: 'error',
|
icon: 'error',
|
||||||
iconColor: '#FF3366',
|
iconColor: '#FF3366',
|
||||||
customClass: customClass
|
customClass: customClass
|
||||||
})
|
});
|
||||||
|
srt = '';
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
* Upload Success
|
* Upload Success
|
||||||
@@ -277,7 +287,6 @@ export async function uploadConfirm(fetchData) {
|
|||||||
export async function uploadloader() {
|
export async function uploadloader() {
|
||||||
await Swal.fire({
|
await Swal.fire({
|
||||||
html: '<span class="loaderBar mt-7"></span>',
|
html: '<span class="loaderBar mt-7"></span>',
|
||||||
// timer: 5000, // 停留5秒後自動關閉
|
|
||||||
showConfirmButton: false,
|
showConfirmButton: false,
|
||||||
allowOutsideClick: false,
|
allowOutsideClick: false,
|
||||||
customClass: customClass,
|
customClass: customClass,
|
||||||
|
|||||||
@@ -123,16 +123,17 @@ export default defineStore('filesStore', {
|
|||||||
uploadloader(); // 進度條
|
uploadloader(); // 進度條
|
||||||
try {
|
try {
|
||||||
const response = await axios.post(api, fromData, config);
|
const response = await axios.post(api, fromData, config);
|
||||||
console.log('第一階段 response:', response);
|
|
||||||
this.uploadId = response.data.id;
|
this.uploadId = response.data.id;
|
||||||
this.$router.push({name: 'Upload'});
|
this.$router.push({name: 'Upload'});
|
||||||
Swal.close(); // 關閉進度條
|
Swal.close(); // 關閉進度條
|
||||||
} catch(error) {
|
} catch(error) {
|
||||||
console.log('第一階段 error:', error);
|
|
||||||
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'
|
||||||
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 {
|
} else {
|
||||||
Swal.close(); // 關閉進度條
|
Swal.close(); // 關閉進度條
|
||||||
apiError(error, 'Failed to upload the files.');
|
apiError(error, 'Failed to upload the files.');
|
||||||
@@ -164,7 +165,6 @@ export default defineStore('filesStore', {
|
|||||||
uploadloader(); // 進度條
|
uploadloader(); // 進度條
|
||||||
try {
|
try {
|
||||||
const response = await axios.post(api, data);
|
const response = await axios.post(api, data);
|
||||||
console.log('第二階段 response:', response);
|
|
||||||
|
|
||||||
this.uploadLogId = await response.data.id;
|
this.uploadLogId = await response.data.id;
|
||||||
await Swal.close(); // 關閉進度條
|
await Swal.close(); // 關閉進度條
|
||||||
@@ -172,10 +172,10 @@ export default defineStore('filesStore', {
|
|||||||
await uploadSuccess();
|
await uploadSuccess();
|
||||||
this.$router.push({name: 'Files'});
|
this.$router.push({name: 'Files'});
|
||||||
} catch(error) {
|
} catch(error) {
|
||||||
console.log('第二階段 error:', error);
|
|
||||||
|
|
||||||
if(error.response.status === 422) {
|
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 {
|
} else {
|
||||||
Swal.close(); // 關閉進度條
|
Swal.close(); // 關閉進度條
|
||||||
apiError(error, 'Failed to upload the log files.');
|
apiError(error, 'Failed to upload the log files.');
|
||||||
|
|||||||
Reference in New Issue
Block a user