diff --git a/pages/chat/components/uploadQrcode.vue b/pages/chat/components/uploadQrcode.vue index 219872b..6ed3e49 100644 --- a/pages/chat/components/uploadQrcode.vue +++ b/pages/chat/components/uploadQrcode.vue @@ -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(); } @@ -179,23 +186,23 @@ async function initQrCode() { } function makeQrcode() { - const protocol = window.location.protocol; - const host = window.location.host; - const isLocal = host.includes('localhost') || host.includes('127.0.0.1'); - // const pathPrefix = isLocal ? '' : '/rgpp-api/all-in-one'; - let pathPrefix = ''; - if (host.includes('localhost') || host.includes('127.0.0.1')) { - pathPrefix = ''; - } else if (host.includes('qd.zhaopinzao8dian.com')) { - // 外网测试环境 - pathPrefix = '/app'; - } else if (host.includes('fw.rc.qingdao.gov.cn')) { - // 青岛政务网环境 - pathPrefix = '/rgpp-api/all-in-one'; - } else { - pathPrefix = ''; - } - const htmlPath = `${protocol}//${host}${pathPrefix}/static/upload.html?sessionId=${uuid.value}&uploadApi=${config.baseUrl}/app/kiosk/upload&fileCount=${props.leaveFileCount}`; + const protocol = window.location.protocol; + const host = window.location.host; + const isLocal = host.includes('localhost') || host.includes('127.0.0.1'); + // const pathPrefix = isLocal ? '' : '/rgpp-api/all-in-one'; + let pathPrefix = ''; + if (host.includes('localhost') || host.includes('127.0.0.1')) { + pathPrefix = ''; + } else if (host.includes('qd.zhaopinzao8dian.com')) { + // 外网测试环境 + pathPrefix = '/app'; + } else if (host.includes('fw.rc.qingdao.gov.cn')) { + // 青岛政务网环境 + pathPrefix = '/rgpp-api/all-in-one'; + } else { + pathPrefix = ''; + } + const htmlPath = `${protocol}//${host}${pathPrefix}/static/upload.html?sessionId=${uuid.value}&uploadApi=${config.baseUrl}/app/kiosk/upload&fileCount=${props.leaveFileCount}`; // const htmlPath = `${window.location.host}/static/upload.html?sessionId=${uuid.value}&uploadApi=${ // config.baseUrl + '/app/kiosk/upload' @@ -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(); }