fix: Issues #230 done.

This commit is contained in:
chiayin
2024-03-22 15:42:20 +08:00
parent af2e9c75e3
commit dfc0d9a7a6
3 changed files with 90 additions and 3 deletions

View File

@@ -425,3 +425,32 @@ export async function deleteSuccess() {
customClass: customClass
})
};
/**
* Really deleted information
* @param {string} files 被刪除的檔案 html
* @param {array} reallyDeldetData 被刪除的檔案 data未取得 recordId 而傳入
*/
export async function reallyDeldetInformation(files, reallyDeldetData) {
const filesStore = FilesStore();
const deleteCustomClass = { ...customClass };
const htmlText = `<div class="text-left mx-4 space-y-1"><p>The following file(s) have been deleted by other user(s):</p><ul class="list-disc ml-6">${files}</ul></div>`;
let recordIdData = [];
deleteCustomClass.confirmButton = '!inline-block !rounded-full !text-sm !font-medium !text-center !align-middle !transition-colors !duration-300 !px-5 !py-2 !w-[100px] !h-[40px] !text-primary !bg-neutral-10 !border !border-primary';
deleteCustomClass.cancelButton = null;
await Swal.fire({
title: 'FILE(S) DELETED BY OTHER USER(S)',
html: htmlText,
icon: 'info',
iconColor: '#0099FF',
customClass: deleteCustomClass,
confirmButtonColor: '#ffffff',
didOpen: () => {
const confirmButton = Swal.getConfirmButton();
confirmButton.style.border = '1px solid #0099FF';
}
});
recordIdData = await Promise.all(reallyDeldetData.map(file => filesStore.deletionRecord(file.id)));
await filesStore.fetchAllFiles();
}

View File

@@ -259,7 +259,6 @@ export default defineStore('filesStore', {
let api;
if(id == null || isNaN(id)) {
console.error('Delete File API:', id);
return $toast.default('Delete File API Error.', {position: 'bottom'});
};
loading.isLoading = true;
@@ -287,6 +286,22 @@ export default defineStore('filesStore', {
loading.isLoading = false;
}
},
/**
* Remove a Deletion Record真刪除被 Admin 或被其他帳號刪除的檔案
*/
async deletionRecord(id) {
let api = '';
loading.isLoading = true;
api = `/api/deletion/${id}`;
try {
const response = await axios.delete(api);
} catch(error) {
apiError(error, 'Failed to Remove a Deletion Record.')
} finally {
loading.isLoading = false;
}
},
/**
* Download file as CSV
* @param { string } type log | filter | log-check | filter-check

View File

@@ -223,7 +223,7 @@
import IconVector from '@/components/icons/IconVector.vue';
import IconList from '@/components/icons/IconList.vue';
import IconGrid from '@/components/icons/IconGrid.vue';
import { renameModal, deleteFileModal } from '@/module/alertModal.js';
import { renameModal, deleteFileModal, reallyDeldetInformation } from '@/module/alertModal.js';
export default {
data() {
@@ -318,6 +318,19 @@
isCompareDisabledButton: function() {
let result = this.primaryDragData.length === 0 || this.secondaryDragData.length === 0 ? true : false;
return result;
},
/**
* Really deleted information
*/
reallyDeldetData: function() {
let result = [];
if(this.store.allFiles.length !== 0){
result = JSON.parse(JSON.stringify(this.store.allFiles));
result = result.filter(file => file.is_deleted === true);
}
return result
}
},
watch: {
@@ -331,8 +344,14 @@
},
allFiles: {
handler(newValue) {
this.compareData = JSON.parse(JSON.stringify(newValue));
if(newValue != null) this.compareData = JSON.parse(JSON.stringify(newValue));
}
},
reallyDeldetData: {
handler(newValue, oldValue) {
if(newValue.length !== 0 && oldValue.length === 0) this.showReallyDeldet();
},
immediate: true
}
},
methods: {
@@ -471,6 +490,30 @@
deleteFileModal(srt, this.selectedType, this.selectedId, this.selecteName);
srt = '';
},
/**
* 顯示被 Admin 或被其他帳號刪除的檔案
*/
showReallyDeldet(){
let srt = '';
if(this.reallyDeldetData.length !== 0) {
this.reallyDeldetData.forEach(file => {
switch (file.type) {
case 'log-check':
file.type = 'rule';
break;
case 'filter-check':
file.type = 'rule';
break;
}
let content = `<li>[${file.type}] ${file.name}</li>`;
srt += content;
});
}
reallyDeldetInformation(srt, this.reallyDeldetData);
srt = '';
},
/**
* Download file as CSV
* @param {string} type