|
|
@@ -0,0 +1,695 @@
|
|
|
+<template>
|
|
|
+ <div class="work-draft-container">
|
|
|
+ <ht-editor
|
|
|
+ v-model="workingPaperContent"
|
|
|
+ class="working-paper-editor"
|
|
|
+ height="500px"
|
|
|
+ width="100%"
|
|
|
+ :config="editorConfig"
|
|
|
+ :disabled="disabled"
|
|
|
+ @ready="onEditorReady"
|
|
|
+ />
|
|
|
+ <!-- 工作底稿列表 -->
|
|
|
+ <div>
|
|
|
+ <el-button
|
|
|
+ type="primary"
|
|
|
+ size="small"
|
|
|
+ :disabled="disabled"
|
|
|
+ @click="handleAddWorkingPaper"
|
|
|
+ >
|
|
|
+ 核增核减记录
|
|
|
+ </el-button>
|
|
|
+ </div>
|
|
|
+ <el-table
|
|
|
+ v-loading="loading"
|
|
|
+ :data="workingPaperRecords"
|
|
|
+ style="width: 100%; margin-top: 20px"
|
|
|
+ border
|
|
|
+ >
|
|
|
+ <!-- <el-table-column type="selection" width="55"></el-table-column> -->
|
|
|
+ <el-table-column prop="id" label="序号" width="80">
|
|
|
+ <template slot-scope="scope">
|
|
|
+ {{ scope.$index + 1 }}
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ <el-table-column
|
|
|
+ prop="auditSubject"
|
|
|
+ label="核增核减科目"
|
|
|
+ width="180"
|
|
|
+ ></el-table-column>
|
|
|
+ <el-table-column
|
|
|
+ prop="basicInfo"
|
|
|
+ label="基本情况"
|
|
|
+ width="200"
|
|
|
+ ></el-table-column>
|
|
|
+ <el-table-column prop="auditDesc" label="核增核减说明"></el-table-column>
|
|
|
+ <el-table-column
|
|
|
+ prop="auditTime"
|
|
|
+ label="时间"
|
|
|
+ width="180"
|
|
|
+ ></el-table-column>
|
|
|
+ <el-table-column label="附件" width="100">
|
|
|
+ <template slot-scope="scope">
|
|
|
+ <el-button
|
|
|
+ v-if="scope.row.attachments && scope.row.attachments.length > 0"
|
|
|
+ type="text"
|
|
|
+ size="small"
|
|
|
+ @click="handlePreviewWorkingPaperAttachment(scope.row)"
|
|
|
+ >
|
|
|
+ 查看
|
|
|
+ </el-button>
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ <el-table-column label="操作" width="150">
|
|
|
+ <template slot-scope="scope">
|
|
|
+ <el-button
|
|
|
+ type="text"
|
|
|
+ size="small"
|
|
|
+ :disabled="disabled"
|
|
|
+ @click="handleEditWorkingPaper(scope.row)"
|
|
|
+ >
|
|
|
+ 修改
|
|
|
+ </el-button>
|
|
|
+ <el-button
|
|
|
+ type="text"
|
|
|
+ size="small"
|
|
|
+ :disabled="disabled"
|
|
|
+ @click="handleDeleteWorkingPaper(scope.row)"
|
|
|
+ >
|
|
|
+ 删除
|
|
|
+ </el-button>
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ </el-table>
|
|
|
+
|
|
|
+ <!-- 工作底稿编辑弹窗 -->
|
|
|
+ <el-dialog
|
|
|
+ :title="workingPaperDialogTitle"
|
|
|
+ :visible.sync="workingPaperDialogVisible"
|
|
|
+ width="70%"
|
|
|
+ :modal="false"
|
|
|
+ append-to-body
|
|
|
+ >
|
|
|
+ <el-form
|
|
|
+ ref="workingPaperForm"
|
|
|
+ :model="workingPaperForm"
|
|
|
+ :rules="workingPaperRules"
|
|
|
+ label-width="120px"
|
|
|
+ >
|
|
|
+ <el-form-item label="被审核科目" prop="subject">
|
|
|
+ <el-input
|
|
|
+ v-model="workingPaperForm.subject"
|
|
|
+ placeholder="请输入被审核科目"
|
|
|
+ />
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="基本情况" prop="basicSituation">
|
|
|
+ <el-input
|
|
|
+ v-model="workingPaperForm.basicSituation"
|
|
|
+ type="textarea"
|
|
|
+ :rows="4"
|
|
|
+ placeholder="请输入基本情况"
|
|
|
+ />
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="核增核减说明" prop="description">
|
|
|
+ <el-input
|
|
|
+ v-model="workingPaperForm.description"
|
|
|
+ type="textarea"
|
|
|
+ :rows="4"
|
|
|
+ placeholder="请输入核增核减说明"
|
|
|
+ />
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="日期">
|
|
|
+ <el-date-picker
|
|
|
+ v-model="workingPaperForm.auditDate"
|
|
|
+ type="date"
|
|
|
+ placeholder="选择日期"
|
|
|
+ style="width: 100%"
|
|
|
+ />
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="时间范围">
|
|
|
+ <div style="display: flex; gap: 10px">
|
|
|
+ <el-time-picker
|
|
|
+ v-model="workingPaperForm.startTime"
|
|
|
+ format="HH:mm"
|
|
|
+ placeholder="开始时间"
|
|
|
+ style="flex: 1"
|
|
|
+ />
|
|
|
+ <span>-</span>
|
|
|
+ <el-time-picker
|
|
|
+ v-model="workingPaperForm.endTime"
|
|
|
+ format="HH:mm"
|
|
|
+ placeholder="结束时间"
|
|
|
+ style="flex: 1"
|
|
|
+ />
|
|
|
+ </div>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="上传附件" prop="fileList">
|
|
|
+ <el-upload
|
|
|
+ class="upload-demo"
|
|
|
+ :action="''"
|
|
|
+ :http-request="handleFileUpload"
|
|
|
+ :on-remove="handleFileRemove"
|
|
|
+ :before-upload="beforeFileUpload"
|
|
|
+ :on-success="handleFileUploadSuccess"
|
|
|
+ :on-error="handleFileUploadError"
|
|
|
+ :on-progress="handleFileUploadProgress"
|
|
|
+ :file-list="workingPaperForm.fileList"
|
|
|
+ :limit="1"
|
|
|
+ :on-exceed="handleFileExceed"
|
|
|
+ >
|
|
|
+ <el-button
|
|
|
+ v-show="
|
|
|
+ !workingPaperForm.fileList ||
|
|
|
+ workingPaperForm.fileList.length === 0
|
|
|
+ "
|
|
|
+ size="small"
|
|
|
+ type="primary"
|
|
|
+ >
|
|
|
+ 选择文件
|
|
|
+ </el-button>
|
|
|
+ <div slot="tip" class="el-upload__tip">
|
|
|
+ 支持 pdf, doc, docx, xls, xlsx, csv 格式,单个文件不超过50MB
|
|
|
+ </div>
|
|
|
+ </el-upload>
|
|
|
+ </el-form-item>
|
|
|
+ </el-form>
|
|
|
+ <div slot="footer" class="dialog-footer">
|
|
|
+ <el-button @click="workingPaperDialogVisible = false">取消</el-button>
|
|
|
+ <el-button type="primary" @click="handleWorkingPaperSubmit">
|
|
|
+ 确定
|
|
|
+ </el-button>
|
|
|
+ </div>
|
|
|
+ </el-dialog>
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script>
|
|
|
+ import {
|
|
|
+ getTaskDraftList,
|
|
|
+ addTaskDraft,
|
|
|
+ deleteTaskDraft,
|
|
|
+ } from '@/api/audit/taskDraft'
|
|
|
+ import { uploadFile } from '@/api/file'
|
|
|
+ export default {
|
|
|
+ name: 'WorkDraft',
|
|
|
+ props: {
|
|
|
+ id: {
|
|
|
+ type: [String, Number],
|
|
|
+ default: null,
|
|
|
+ },
|
|
|
+ disabled: {
|
|
|
+ type: Boolean,
|
|
|
+ default: false,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ data() {
|
|
|
+ return {
|
|
|
+ loading: false,
|
|
|
+ editorConfig: {
|
|
|
+ // 可以在这里覆盖全局配置的选项
|
|
|
+ height: '300px',
|
|
|
+ placeholder: '请输入内容...',
|
|
|
+ excludeMenus: ['image', 'video'],
|
|
|
+ },
|
|
|
+ // 工作底稿数据
|
|
|
+ workingPaperContent: '工作底稿内容将在这里展示。',
|
|
|
+ // 工作底稿记录列表
|
|
|
+ workingPaperRecords: [],
|
|
|
+ // 工作底稿弹窗
|
|
|
+ workingPaperDialogVisible: false,
|
|
|
+ workingPaperDialogTitle: '添加工作底稿',
|
|
|
+ isEditWorkingPaper: false,
|
|
|
+ workingPaperForm: {
|
|
|
+ id: '',
|
|
|
+ subject: '',
|
|
|
+ basicSituation: '',
|
|
|
+ description: '',
|
|
|
+ auditDate: '',
|
|
|
+ startTime: '',
|
|
|
+ endTime: '',
|
|
|
+ attachments: [],
|
|
|
+ fileList: [],
|
|
|
+ attachmentUrl: '',
|
|
|
+ },
|
|
|
+ workingPaperRules: {
|
|
|
+ subject: [
|
|
|
+ { required: true, message: '请输入被审核科目', trigger: 'blur' },
|
|
|
+ ],
|
|
|
+ basicSituation: [
|
|
|
+ { required: true, message: '请输入基本情况', trigger: 'blur' },
|
|
|
+ ],
|
|
|
+ description: [
|
|
|
+ { required: true, message: '请输入核增核减说明', trigger: 'blur' },
|
|
|
+ ],
|
|
|
+ },
|
|
|
+ }
|
|
|
+ },
|
|
|
+ mounted() {
|
|
|
+ this.getWorkingPaperRecords()
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ // 获取工作底稿列表
|
|
|
+ async getWorkingPaperRecords() {
|
|
|
+ if (!this.id) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ this.loading = true
|
|
|
+ const res = await getTaskDraftList({ taskId: this.id })
|
|
|
+ if (res && res.value) {
|
|
|
+ // 处理数据,格式化时间显示
|
|
|
+ this.workingPaperRecords = (res.value || []).map((item) => {
|
|
|
+ // 格式化时间显示,如果后端返回的是 time 字段,直接使用
|
|
|
+ let auditTime = ''
|
|
|
+ if (item.time) {
|
|
|
+ auditTime = item.time
|
|
|
+ } else if (item.auditTime) {
|
|
|
+ auditTime = item.auditTime
|
|
|
+ } else if (item.auditDate) {
|
|
|
+ const date = new Date(item.auditDate)
|
|
|
+ const formattedDate = `${date.getFullYear()}-${String(
|
|
|
+ date.getMonth() + 1
|
|
|
+ ).padStart(2, '0')}-${String(date.getDate()).padStart(2, '0')}`
|
|
|
+ const startTime = item.startTime || '00:00'
|
|
|
+ const endTime = item.endTime || '23:59'
|
|
|
+ auditTime = `${formattedDate} ${startTime}-${endTime}`
|
|
|
+ }
|
|
|
+ // 字段名映射
|
|
|
+ return {
|
|
|
+ ...item,
|
|
|
+ auditSubject: item.subject || item.auditSubject,
|
|
|
+ basicInfo: item.basicSituation || item.basicInfo,
|
|
|
+ auditDesc: item.description || item.auditDesc,
|
|
|
+ auditTime: auditTime,
|
|
|
+ }
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ this.workingPaperRecords = []
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ this.$message.error('获取工作底稿列表失败')
|
|
|
+ console.error('获取工作底稿列表失败:', error)
|
|
|
+ this.workingPaperRecords = []
|
|
|
+ } finally {
|
|
|
+ this.loading = false
|
|
|
+ }
|
|
|
+ },
|
|
|
+ onEditorReady(editor) {
|
|
|
+ // 编辑器初始化完成后的回调
|
|
|
+ console.log('编辑器已就绪', editor)
|
|
|
+ // 可以在这里获取编辑器实例,进行更多操作
|
|
|
+ },
|
|
|
+ // 工作底稿操作
|
|
|
+ handleAddWorkingPaper() {
|
|
|
+ this.isEditWorkingPaper = false
|
|
|
+ this.workingPaperDialogTitle = '添加工作底稿'
|
|
|
+ this.workingPaperForm = {
|
|
|
+ id: '',
|
|
|
+ subject: '',
|
|
|
+ basicSituation: '',
|
|
|
+ description: '',
|
|
|
+ auditDate: new Date(),
|
|
|
+ startTime: '',
|
|
|
+ endTime: '',
|
|
|
+ attachments: [],
|
|
|
+ fileList: [],
|
|
|
+ attachmentUrl: '',
|
|
|
+ }
|
|
|
+ // 重置表单验证状态
|
|
|
+ if (this.$refs.workingPaperForm) {
|
|
|
+ this.$refs.workingPaperForm.resetFields()
|
|
|
+ }
|
|
|
+ this.workingPaperDialogVisible = true
|
|
|
+ },
|
|
|
+
|
|
|
+ handleEditWorkingPaper(row) {
|
|
|
+ this.isEditWorkingPaper = true
|
|
|
+ this.workingPaperDialogTitle = '修改工作底稿'
|
|
|
+ // 解析时间字符串
|
|
|
+ let auditDate = new Date()
|
|
|
+ let startTime = null
|
|
|
+ let endTime = null
|
|
|
+
|
|
|
+ // 优先使用 time 字段,如果没有则使用 auditTime,再没有则使用分开的日期时间
|
|
|
+ const timeStr = row.time || row.auditTime || ''
|
|
|
+ if (timeStr) {
|
|
|
+ const timeParts = timeStr.split(' ')
|
|
|
+ if (timeParts.length >= 2) {
|
|
|
+ const date = timeParts[0]
|
|
|
+ const timeRange = timeParts[1].split('-')
|
|
|
+ auditDate = new Date(date)
|
|
|
+ // 将时间字符串转换为 Date 对象
|
|
|
+ if (timeRange[0]) {
|
|
|
+ const [hours, minutes] = timeRange[0].split(':')
|
|
|
+ startTime = new Date()
|
|
|
+ startTime.setHours(
|
|
|
+ parseInt(hours) || 0,
|
|
|
+ parseInt(minutes) || 0,
|
|
|
+ 0,
|
|
|
+ 0
|
|
|
+ )
|
|
|
+ }
|
|
|
+ if (timeRange[1]) {
|
|
|
+ const [hours, minutes] = timeRange[1].split(':')
|
|
|
+ endTime = new Date()
|
|
|
+ endTime.setHours(
|
|
|
+ parseInt(hours) || 0,
|
|
|
+ parseInt(minutes) || 0,
|
|
|
+ 0,
|
|
|
+ 0
|
|
|
+ )
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if (row.auditDate) {
|
|
|
+ auditDate = new Date(row.auditDate)
|
|
|
+ // 将时间字符串转换为 Date 对象
|
|
|
+ if (row.startTime) {
|
|
|
+ const [hours, minutes] = row.startTime.split(':')
|
|
|
+ startTime = new Date()
|
|
|
+ startTime.setHours(
|
|
|
+ parseInt(hours) || 0,
|
|
|
+ parseInt(minutes) || 0,
|
|
|
+ 0,
|
|
|
+ 0
|
|
|
+ )
|
|
|
+ }
|
|
|
+ if (row.endTime) {
|
|
|
+ const [hours, minutes] = row.endTime.split(':')
|
|
|
+ endTime = new Date()
|
|
|
+ endTime.setHours(parseInt(hours) || 0, parseInt(minutes) || 0, 0, 0)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理文件列表
|
|
|
+ let fileList = []
|
|
|
+ if (row.attachmentUrl) {
|
|
|
+ fileList = [
|
|
|
+ {
|
|
|
+ name: row.fileName || '附件',
|
|
|
+ url: row.attachmentUrl,
|
|
|
+ response: { savePath: row.attachmentUrl },
|
|
|
+ },
|
|
|
+ ]
|
|
|
+ }
|
|
|
+
|
|
|
+ // 字段名映射
|
|
|
+ this.workingPaperForm = {
|
|
|
+ ...row,
|
|
|
+ subject: row.subject || row.auditSubject || '',
|
|
|
+ basicSituation: row.basicSituation || row.basicInfo || '',
|
|
|
+ description: row.description || row.auditDesc || '',
|
|
|
+ auditDate: auditDate,
|
|
|
+ startTime: startTime,
|
|
|
+ endTime: endTime,
|
|
|
+ fileList: fileList,
|
|
|
+ attachmentUrl: row.attachmentUrl || '',
|
|
|
+ }
|
|
|
+ this.workingPaperDialogVisible = true
|
|
|
+ },
|
|
|
+
|
|
|
+ async handleDeleteWorkingPaper(row) {
|
|
|
+ try {
|
|
|
+ await this.$confirm('确定要删除这条工作底稿吗?', '提示', {
|
|
|
+ confirmButtonText: '确定',
|
|
|
+ cancelButtonText: '取消',
|
|
|
+ type: 'warning',
|
|
|
+ })
|
|
|
+
|
|
|
+ const res = await deleteTaskDraft({ id: row.id })
|
|
|
+ if (res.code === 200) {
|
|
|
+ this.$message.success('工作底稿已删除')
|
|
|
+ // 重新获取列表
|
|
|
+ this.getWorkingPaperRecords()
|
|
|
+ } else {
|
|
|
+ this.$message.error(res.message || '删除失败')
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ if (error !== 'cancel') {
|
|
|
+ this.$message.error('删除失败')
|
|
|
+ console.error('删除工作底稿失败:', error)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ async handleWorkingPaperSubmit() {
|
|
|
+ try {
|
|
|
+ await this.$refs.workingPaperForm.validate()
|
|
|
+
|
|
|
+ // 格式化日期
|
|
|
+ const auditDate = new Date(this.workingPaperForm.auditDate)
|
|
|
+ const formattedDate = `${auditDate.getFullYear()}-${String(
|
|
|
+ auditDate.getMonth() + 1
|
|
|
+ ).padStart(2, '0')}-${String(auditDate.getDate()).padStart(2, '0')}`
|
|
|
+
|
|
|
+ // 格式化时间(如果没有选择时间,使用默认值)
|
|
|
+ const startTime = this.workingPaperForm.startTime
|
|
|
+ ? this.formatTime(this.workingPaperForm.startTime)
|
|
|
+ : '00:00'
|
|
|
+ const endTime = this.workingPaperForm.endTime
|
|
|
+ ? this.formatTime(this.workingPaperForm.endTime)
|
|
|
+ : '23:59'
|
|
|
+
|
|
|
+ // 合并日期和时间范围为 time 字段
|
|
|
+ const time = `${formattedDate} ${startTime}-${endTime}`
|
|
|
+
|
|
|
+ // 构造提交数据
|
|
|
+ const formData = {
|
|
|
+ taskId: this.id,
|
|
|
+ subject: this.workingPaperForm.subject,
|
|
|
+ basicSituation: this.workingPaperForm.basicSituation,
|
|
|
+ description: this.workingPaperForm.description,
|
|
|
+ time: time,
|
|
|
+ attachmentUrl: this.workingPaperForm.attachmentUrl,
|
|
|
+ }
|
|
|
+
|
|
|
+ // 如果是编辑模式,添加 id
|
|
|
+ if (this.isEditWorkingPaper && this.workingPaperForm.id) {
|
|
|
+ formData.id = this.workingPaperForm.id
|
|
|
+ }
|
|
|
+
|
|
|
+ const res = await addTaskDraft(formData)
|
|
|
+ if (res.code === 200) {
|
|
|
+ this.$message.success(
|
|
|
+ this.isEditWorkingPaper ? '工作底稿修改成功' : '工作底稿添加成功'
|
|
|
+ )
|
|
|
+ this.workingPaperDialogVisible = false
|
|
|
+ // 重新获取列表
|
|
|
+ this.getWorkingPaperRecords()
|
|
|
+ } else {
|
|
|
+ this.$message.error(
|
|
|
+ res.message || (this.isEditWorkingPaper ? '修改失败' : '添加失败')
|
|
|
+ )
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ if (error !== 'cancel') {
|
|
|
+ this.$message.error(
|
|
|
+ this.isEditWorkingPaper ? '修改失败' : '添加失败'
|
|
|
+ )
|
|
|
+ console.error('提交工作底稿失败:', error)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ // 格式化时间为 HH:mm 格式
|
|
|
+ formatTime(time) {
|
|
|
+ if (!time) return ''
|
|
|
+ if (typeof time === 'string') {
|
|
|
+ // 如果已经是字符串格式 HH:mm,直接返回
|
|
|
+ if (/^\d{2}:\d{2}$/.test(time)) {
|
|
|
+ return time
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 如果是 Date 对象
|
|
|
+ if (time instanceof Date) {
|
|
|
+ const hours = String(time.getHours()).padStart(2, '0')
|
|
|
+ const minutes = String(time.getMinutes()).padStart(2, '0')
|
|
|
+ return `${hours}:${minutes}`
|
|
|
+ }
|
|
|
+ return ''
|
|
|
+ },
|
|
|
+
|
|
|
+ handlePreviewWorkingPaperAttachment(row) {
|
|
|
+ const attachments =
|
|
|
+ row.attachments && Array.isArray(row.attachments)
|
|
|
+ ? row.attachments
|
|
|
+ : []
|
|
|
+ if (attachments.length === 0) {
|
|
|
+ this.$message.info('暂无附件')
|
|
|
+ return
|
|
|
+ }
|
|
|
+ this.$message({
|
|
|
+ type: 'info',
|
|
|
+ message: `预览附件:${attachments.join(', ')}`,
|
|
|
+ })
|
|
|
+ },
|
|
|
+
|
|
|
+ // 文件上传前验证
|
|
|
+ beforeFileUpload(file) {
|
|
|
+ const allowedTypes = [
|
|
|
+ 'application/pdf',
|
|
|
+ 'application/msword',
|
|
|
+ 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
|
|
+ 'application/vnd.ms-excel',
|
|
|
+ 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
|
|
+ 'text/csv',
|
|
|
+ ]
|
|
|
+
|
|
|
+ const allowedExtensions = [
|
|
|
+ '.pdf',
|
|
|
+ '.doc',
|
|
|
+ '.docx',
|
|
|
+ '.xls',
|
|
|
+ '.xlsx',
|
|
|
+ '.csv',
|
|
|
+ ]
|
|
|
+ const fileExtension = '.' + file.name.split('.').pop().toLowerCase()
|
|
|
+
|
|
|
+ // 检查文件格式
|
|
|
+ const isCorrectType = allowedTypes.includes(file.type)
|
|
|
+ const isCorrectExtension = allowedExtensions.includes(fileExtension)
|
|
|
+
|
|
|
+ if (!isCorrectType && !isCorrectExtension) {
|
|
|
+ this.$message.error(
|
|
|
+ '只允许上传 pdf, doc, docx, xls, xlsx, csv 格式的文件!'
|
|
|
+ )
|
|
|
+ return false
|
|
|
+ }
|
|
|
+
|
|
|
+ // 检查文件大小 (50MB)
|
|
|
+ const isLt50M = file.size / 1024 / 1024 < 50
|
|
|
+ if (!isLt50M) {
|
|
|
+ this.$message.error('文件大小不能超过 50MB!')
|
|
|
+ return false
|
|
|
+ }
|
|
|
+
|
|
|
+ return true
|
|
|
+ },
|
|
|
+
|
|
|
+ // 自定义上传方法
|
|
|
+ async handleFileUpload(options) {
|
|
|
+ const { file, onProgress, onSuccess, onError } = options
|
|
|
+
|
|
|
+ // 检查是否已经上传了文件
|
|
|
+ if (
|
|
|
+ this.workingPaperForm.fileList &&
|
|
|
+ this.workingPaperForm.fileList.length >= 1
|
|
|
+ ) {
|
|
|
+ this.$message.warning('只能上传一个文件,请先删除已上传的文件')
|
|
|
+ if (onError) {
|
|
|
+ onError(new Error('只能上传一个文件'))
|
|
|
+ }
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ const formData = new FormData()
|
|
|
+ formData.append('file', file)
|
|
|
+
|
|
|
+ try {
|
|
|
+ // 显示上传进度
|
|
|
+ if (onProgress) {
|
|
|
+ onProgress({ percent: 0 })
|
|
|
+ }
|
|
|
+
|
|
|
+ // 调用上传API
|
|
|
+ const uploadRes = await uploadFile('/api/file/v1/upload', formData, {
|
|
|
+ onUploadProgress: (progressEvent) => {
|
|
|
+ // 计算上传进度
|
|
|
+ if (progressEvent.total) {
|
|
|
+ const percent = Math.round(
|
|
|
+ (progressEvent.loaded * 100) / progressEvent.total
|
|
|
+ )
|
|
|
+ if (onProgress) {
|
|
|
+ onProgress({ percent })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ })
|
|
|
+
|
|
|
+ // 检查上传结果
|
|
|
+ if (uploadRes && uploadRes.code === 200 && uploadRes.value) {
|
|
|
+ const fileInfo = uploadRes.value
|
|
|
+ // 构造文件信息对象,符合element-ui upload组件的格式
|
|
|
+ const fileObj = {
|
|
|
+ uid: file.uid,
|
|
|
+ name: file.name,
|
|
|
+ status: 'success',
|
|
|
+ size: file.size,
|
|
|
+ response: fileInfo,
|
|
|
+ url: fileInfo.savePath || fileInfo.url,
|
|
|
+ }
|
|
|
+
|
|
|
+ if (onSuccess) {
|
|
|
+ onSuccess(fileInfo, fileObj)
|
|
|
+ this.workingPaperForm.attachmentUrl =
|
|
|
+ fileInfo.savePath || fileInfo.url
|
|
|
+ }
|
|
|
+
|
|
|
+ this.$message.success(`${file.name} 上传成功`)
|
|
|
+ } else {
|
|
|
+ throw new Error(uploadRes?.message || '上传失败,请稍后重试')
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ console.error('文件上传失败:', error)
|
|
|
+ this.$message.error(`文件上传失败:${error.message || '未知错误'}`)
|
|
|
+ if (onError) {
|
|
|
+ onError(error)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ // 上传成功回调
|
|
|
+ handleFileUploadSuccess(response, file, fileList) {
|
|
|
+ // 更新文件列表,添加文件URL信息
|
|
|
+ this.workingPaperForm.fileList = fileList.map((item) => {
|
|
|
+ if (item.uid === file.uid && response) {
|
|
|
+ return {
|
|
|
+ ...item,
|
|
|
+ url: response.savePath || response.url || item.url,
|
|
|
+ response: response,
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return item
|
|
|
+ })
|
|
|
+ },
|
|
|
+
|
|
|
+ // 上传进度回调
|
|
|
+ handleFileUploadProgress(event, file, fileList) {
|
|
|
+ // element-ui 会自动处理上传进度显示
|
|
|
+ },
|
|
|
+
|
|
|
+ // 上传失败回调
|
|
|
+ handleFileUploadError(err, file, fileList) {
|
|
|
+ console.error('文件上传错误:', err)
|
|
|
+ this.$message.error(`${file.name} 上传失败`)
|
|
|
+ // 从文件列表中移除失败的文件
|
|
|
+ this.workingPaperForm.fileList = fileList.filter(
|
|
|
+ (item) => item.uid !== file.uid
|
|
|
+ )
|
|
|
+ },
|
|
|
+
|
|
|
+ // 超出文件数量限制
|
|
|
+ handleFileExceed(files, fileList) {
|
|
|
+ this.$message.warning(
|
|
|
+ `当前限制选择 1 个文件,本次选择了 ${files.length} 个文件,共选择了 ${fileList.length} 个文件`
|
|
|
+ )
|
|
|
+ },
|
|
|
+
|
|
|
+ // 移除文件
|
|
|
+ handleFileRemove(file, fileList) {
|
|
|
+ this.workingPaperForm.fileList = fileList
|
|
|
+ this.workingPaperForm.attachmentUrl = ''
|
|
|
+ this.$message.info(`${file.name} 已移除`)
|
|
|
+ },
|
|
|
+ },
|
|
|
+ }
|
|
|
+</script>
|
|
|
+
|
|
|
+<style scoped>
|
|
|
+ .work-draft-container {
|
|
|
+ padding: 20px;
|
|
|
+ }
|
|
|
+
|
|
|
+ .working-paper-editor {
|
|
|
+ margin-bottom: 20px;
|
|
|
+ }
|
|
|
+</style>
|