feat : 扫码上传的本地删除改为接口删除

This commit is contained in:
2025-12-22 11:39:50 +08:00
parent 79fb997640
commit 577ec92ac8

View File

@@ -66,9 +66,12 @@ const pollingTimer = ref(null);
const isPolling = ref(false);
const isVisible = ref(false);
const uuid = ref(null);
const fileCount = ref(0);
const fileList = ref([]);
const delFiles = ref([]); //本地记录删除的文件
const deleting = ref(false);
const fileCount = computed(() => {
return fileList.value.length ?? 0;
});
// 计算加载文本
const loadingText = computed(() => ({
@@ -113,10 +116,16 @@ function preViewImage(file) {
$api.msg('文件地址丢失');
}
}
function delFile(file, idx) {
async function delFile(file, idx) {
deleting.value = true;
try {
await $api.createRequest(`/app/kiosk/${file.id}`, {sessionId: uuid.value,ids: [file.id]}, 'delete', true);
} catch (error) {
$api.msg(error);
} finally {
deleting.value = false;
}
fileList.value.splice(idx, 1);
fileCount.value = fileList.value.length
delFiles.value.push(file.fileUrl);
}
function open() {
@@ -149,9 +158,7 @@ function handleConfirm() {
// 重置所有状态
function resetState() {
delFiles.value = []
fileList.value = [];
fileCount.value = 0;
loading.value = false;
stopPolling();
}
@@ -204,7 +211,7 @@ function makeQrcode() {
// config.baseUrl + '/app/kiosk/upload'
// }`;
console.log(htmlPath);
console.log('剩余可上传文件数量:',props.leaveFileCount)
console.log('剩余可上传文件数量:', props.leaveFileCount);
return new Promise((resolve, reject) => {
setTimeout(() => {
uQRCode.make({
@@ -237,20 +244,16 @@ function startPolling() {
// 轮询检查上传状态
const poll = async () => {
if (!isPolling.value || !isVisible.value) return;
if (!isPolling.value || !isVisible.value || deleting.value) return;
const { data } = await $api.createRequest('/app/kiosk/list', { sessionId: uuid.value });
// const { data } = await $api.createRequest('/app/kiosk/list',{sessionId:props.sessionId});
if (data && data.length) {
// 上传完成,触发事件
fileList.value = data.filter((item) => !delFiles.value.includes(item.fileUrl))
fileCount.value = fileList.value.length;
// emit('onSend', data);
fileList.value = data;
}
if (isPolling.value && isVisible.value) {
pollingTimer.value = setTimeout(poll, 2000); // 每2秒轮询一次
}
};
poll();
}