From c79afe56e2c8a28ef5b61a82ee9000d1c39b33f4 Mon Sep 17 00:00:00 2001 From: zlwu <704541015@qq.com> Date: Sun, 10 Aug 2025 20:16:20 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mobile/src/components/FileUpload/index.vue | 181 +++++++++--- .../src/components/Process/approvalButton.vue | 60 +++- .../src/components/Process/submitVerify.vue | 140 ++++++--- .../src/pages/xg/xsjcxx/xsqj/leave/index.vue | 16 ++ .../pages/xg/xsjcxx/xsqj/leaveEdit/index.vue | 269 ++++++++++++------ 5 files changed, 497 insertions(+), 169 deletions(-) diff --git a/mobile/src/components/FileUpload/index.vue b/mobile/src/components/FileUpload/index.vue index 29026487..48ed290c 100644 --- a/mobile/src/components/FileUpload/index.vue +++ b/mobile/src/components/FileUpload/index.vue @@ -37,7 +37,7 @@ - 下载 - + --> {{ uploadPercent }}% + + + + + + @@ -89,7 +118,7 @@ import { REQUEST_CONFIG } from '@/common/config.js'; export default { name: 'FileUpload', props: { - modelValue: { + value: { type: [String, Object, Array], default: () => [], }, @@ -119,12 +148,16 @@ export default { default: false, }, }, + emits: ['input', 'submit', 'cancel'], data() { return { fileList: [], uploading: false, showProgress: false, uploadPercent: 0, + showDeleteConfirm: false, + deleteIndex: -1, + showClearConfirm: false, }; }, computed: { @@ -133,7 +166,7 @@ export default { }, }, watch: { - modelValue: { + value: { handler: 'initFileList', immediate: true, deep: true, @@ -149,10 +182,10 @@ export default { } else if (typeof val === 'string' && val.trim()) { // 如果是字符串,调用API获取文件详情 try { + const ids = val.split(',').filter((id) => id.trim()); const response = await this.request({ - url: '/resource/oss/listByIds', - method: 'POST', - data: val.split(',').filter((id) => id.trim()), + url: `/resource/oss/listByIds/${encodeURIComponent(ids.join(','))}`, + method: 'GET', }); if (response.code === 200) { @@ -387,37 +420,54 @@ export default { }, // 删除文件 - async handleDelete(index) { + handleDelete(index) { + console.log('handleDelete', index); + this.deleteIndex = index; + this.showDeleteConfirm = true; + }, + + // 确认删除 + async confirmDelete() { try { - const result = await this.showConfirm('确定要删除这个文件吗?'); - if (result.confirm) { - const file = this.fileList[index]; + const file = this.fileList[this.deleteIndex]; - // 如果有ossId,调用删除API - if (file.ossId) { - try { - await this.request({ - url: `/resource/oss/${file.ossId}`, - method: 'DELETE', - }); - } catch (error) { - console.error('删除文件失败:', error); - } + // 如果有ossId,调用删除API + if (file.ossId) { + try { + await this.request({ + url: `/resource/oss/${file.ossId}`, + method: 'DELETE', + }); + } catch (error) { + console.error('删除文件失败:', error); } - - this.fileList.splice(index, 1); - this.emitChange(); - - uni.showToast({ - title: '删除成功', - icon: 'success', - }); } + + this.fileList.splice(this.deleteIndex, 1); + this.emitChange(); + + uni.showToast({ + title: '删除成功', + icon: 'success', + }); } catch (error) { console.error('删除文件失败:', error); + uni.showToast({ + title: '删除失败', + icon: 'none', + }); + } finally { + this.showDeleteConfirm = false; + this.deleteIndex = -1; } }, + // 取消删除 + cancelDelete() { + this.showDeleteConfirm = false; + this.deleteIndex = -1; + }, + // 获取文件名 getFileName(name) { if (!name) return '未知文件'; @@ -442,7 +492,8 @@ export default { // 发出变更事件 emitChange() { const value = this.listToString(this.fileList); - this.$emit('update:modelValue', value); + console.log('longwu---emitChange', value); + this.$emit('input', value); }, // 转换为字符串 @@ -464,6 +515,59 @@ export default { }); }, + // 提交文件 + handleSubmit() { + if (this.fileList.length === 0) { + uni.showToast({ + title: '请先选择文件', + icon: 'none', + }); + return; + } + + // 发出提交事件,传递文件列表 + this.$emit('submit', { + fileList: this.fileList, + ossIds: this.listToString(this.fileList), + }); + }, + + // 取消操作 + handleCancel() { + if (this.fileList.length > 0) { + this.showClearConfirm = true; + } else { + this.$emit('cancel'); + } + }, + + // 确认清空文件 + confirmClear() { + try { + this.fileList = []; + this.emitChange(); + this.$emit('cancel'); + + uni.showToast({ + title: '已清空文件列表', + icon: 'success', + }); + } catch (error) { + console.error('清空文件失败:', error); + uni.showToast({ + title: '清空文件失败', + icon: 'none', + }); + } finally { + this.showClearConfirm = false; + } + }, + + // 取消清空文件 + cancelClear() { + this.showClearConfirm = false; + }, + // 请求方法 async request(options) { const { request } = await import('@/common/request.js'); @@ -475,17 +579,24 @@ export default { diff --git a/mobile/src/components/Process/submitVerify.vue b/mobile/src/components/Process/submitVerify.vue index 95a47e24..395e201f 100644 --- a/mobile/src/components/Process/submitVerify.vue +++ b/mobile/src/components/Process/submitVerify.vue @@ -1,12 +1,13 @@