feat(file): 完善文件管理功能,增加图片管理和权限控制
- 添加管理员权限验证,删除按钮仅对管理员显示 - 实现文件编辑权限控制,仅创建者或管理员可编辑 - 新增多图上传功能,支持文件和图片两种上传模式 - 实现图片预览轮播功能,支持缩略图导航和计数显示 - 添加文件替换功能,支持编辑模式下替换主文件 - 优化图片管理界面,支持添加、删除和替换操作 - 重构上传组件,使用OSS直传替代原有拖拽上传 - 新增图片关联API接口,支持文件与多张图片关联 - 实现批量图片上传处理,按顺序串行上传避免冲突 - 优化表单重置逻辑,清空临时文件和图片数据 - 添加文件类型自动识别和分类展示功能 - 修复可见用户加载异常导致的重复ID问题 - 优化错误处理机制,提升用户体验和系统稳定性
This commit is contained in:
@@ -105,3 +105,45 @@ export function listVisibleUserByFileId(fileId) {
|
||||
params: { fileId: fileId }
|
||||
})
|
||||
}
|
||||
|
||||
// ============ OSS 上传 ============
|
||||
|
||||
// 上传文件到OSS
|
||||
export function uploadFile(file) {
|
||||
const formData = new FormData()
|
||||
formData.append('file', file)
|
||||
return request({
|
||||
url: '/system/oss/upload',
|
||||
method: 'post',
|
||||
data: formData,
|
||||
headers: { 'Content-Type': 'multipart/form-data' }
|
||||
})
|
||||
}
|
||||
|
||||
// ============ 文件图片关联 ============
|
||||
|
||||
// 新增图片关联
|
||||
export function addFileImage(data) {
|
||||
return request({
|
||||
url: '/system/fileImage',
|
||||
method: 'post',
|
||||
data: data
|
||||
})
|
||||
}
|
||||
|
||||
// 修改图片关联(替换图片)
|
||||
export function updateFileImage(data) {
|
||||
return request({
|
||||
url: '/system/fileImage',
|
||||
method: 'put',
|
||||
data: data
|
||||
})
|
||||
}
|
||||
|
||||
// 删除图片关联
|
||||
export function delFileImage(imageIds) {
|
||||
return request({
|
||||
url: '/system/fileImage/' + imageIds,
|
||||
method: 'delete'
|
||||
})
|
||||
}
|
||||
|
||||
@@ -49,7 +49,11 @@ export function parseTime(time, pattern) {
|
||||
// 表单重置
|
||||
export function resetForm(refName) {
|
||||
if (this.$refs[refName]) {
|
||||
this.$refs[refName].resetFields();
|
||||
try {
|
||||
this.$refs[refName].resetFields();
|
||||
} catch (e) {
|
||||
console.warn('resetFields error:', e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@
|
||||
@clear="handleQuery"
|
||||
/>
|
||||
<el-button type="primary" icon="el-icon-plus" size="mini" @click="handleAdd">上传文件</el-button>
|
||||
<el-button type="danger" icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete">删除</el-button>
|
||||
<el-button v-if="isAdmin" type="danger" icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete">删除</el-button>
|
||||
<span v-if="selectedCardIds.length > 0" class="selected-count">已选 {{ selectedCardIds.length }} 项</span>
|
||||
</div>
|
||||
|
||||
@@ -119,6 +119,7 @@
|
||||
</div>
|
||||
<div class="card-actions">
|
||||
<el-button type="text" size="mini" icon="el-icon-view" @click.stop="handleShowInfo(file)">详情</el-button>
|
||||
<el-button v-if="isAdmin || file.createBy === $store.getters.name" type="text" size="mini" icon="el-icon-edit" @click.stop="handleUpdate(file)">编辑</el-button>
|
||||
<el-button type="text" size="mini" icon="el-icon-download" @click.stop="downloadFile(file)">下载</el-button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -139,25 +140,75 @@
|
||||
<el-dialog :title="dialogTitle" :visible.sync="open" width="650px" append-to-body @close="handleDialogClose">
|
||||
<el-form ref="form" :model="form" :rules="rules" label-width="100px">
|
||||
<el-form-item label="文件名称" prop="fileName">
|
||||
<el-input v-model="form.fileName" placeholder="请输入文件名称" :disabled="isEdit" />
|
||||
<el-input v-model="form.fileName" placeholder="请输入文件名称" />
|
||||
</el-form-item>
|
||||
<el-form-item label="上传文件" v-if="!isEdit">
|
||||
<el-upload
|
||||
ref="upload"
|
||||
:action="uploadUrl"
|
||||
:headers="uploadHeaders"
|
||||
:file-list="uploadFileList"
|
||||
:before-upload="handleBeforeUpload"
|
||||
:on-success="handleUploadSuccess"
|
||||
:on-error="handleUploadError"
|
||||
:auto-upload="false"
|
||||
:limit="1"
|
||||
class="upload-demo"
|
||||
drag
|
||||
>
|
||||
<i class="el-icon-upload"></i>
|
||||
<div class="el-upload__text">将文件拖到此处,或<em>点击选取</em></div>
|
||||
</el-upload>
|
||||
<!-- 上传模式 - 选择方式 -->
|
||||
<el-form-item label="上传方式" v-if="!isEdit">
|
||||
<el-radio-group v-model="uploadMode">
|
||||
<el-radio label="file">上传文件</el-radio>
|
||||
<el-radio label="image">上传图片</el-radio>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
<!-- 上传文件 -->
|
||||
<el-form-item v-if="!isEdit && uploadMode === 'file'" label="选择文件" required>
|
||||
<div class="file-upload-area">
|
||||
<input type="file" ref="mainFileInput" style="display:none" @change="handleMainFileSelect" />
|
||||
<el-button type="primary" @click="$refs.mainFileInput.click()">选择文件</el-button>
|
||||
<span class="upload-hint">支持 pdf / xlsx / docx / 图片 等格式</span>
|
||||
<div v-if="mainFile" class="main-file-info">
|
||||
<i class="el-icon-document"></i>
|
||||
<span class="main-file-name">{{ mainFile.name }}</span>
|
||||
<span class="main-file-size">({{ formatFileSize(mainFile.size) }})</span>
|
||||
<el-button type="text" size="mini" icon="el-icon-delete" @click="removeMainFile" style="color:#f56c6c;"></el-button>
|
||||
</div>
|
||||
</div>
|
||||
</el-form-item>
|
||||
<!-- 上传图片(多张) -->
|
||||
<el-form-item v-if="!isEdit && uploadMode === 'image'" label="选择图片" required>
|
||||
<div class="image-upload-area">
|
||||
<input type="file" multiple accept="image/*" ref="fileInput" style="display:none" @change="handleFileSelect" />
|
||||
<el-button @click="$refs.fileInput.click()">选择图片</el-button>
|
||||
<span class="upload-hint">支持多选 jpg/png/webp/bmp</span>
|
||||
<div v-if="stagedImages.length > 0" class="image-grid">
|
||||
<div v-for="(img, idx) in stagedImages" :key="idx" class="image-item">
|
||||
<img :src="img.url" />
|
||||
<div class="image-item-mask">
|
||||
<el-button type="danger" size="mini" icon="el-icon-delete" circle @click="removeStagedImage(idx)"></el-button>
|
||||
</div>
|
||||
<div class="image-item-name">{{ img.name }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</el-form-item>
|
||||
<!-- 编辑模式 - 主文件信息 -->
|
||||
<el-form-item label="当前文件" v-if="isEdit && form.filePath">
|
||||
<div class="main-file-info">
|
||||
<i class="el-icon-document"></i>
|
||||
<span class="main-file-name">{{ form.fileName }}</span>
|
||||
<span class="main-file-size" v-if="form.fileSize">({{ formatFileSize(form.fileSize) }})</span>
|
||||
<el-button type="text" size="mini" icon="el-icon-refresh" @click="handleReplaceMainFile" style="margin-left:8px;">替换</el-button>
|
||||
<el-button type="text" size="mini" icon="el-icon-download" @click="downloadFile(form)" v-if="form.filePath">下载</el-button>
|
||||
<input type="file" ref="replaceMainFileInput" style="display:none" @change="handleReplaceMainFileSelect" />
|
||||
</div>
|
||||
</el-form-item>
|
||||
<!-- 编辑模式 - 图片管理 -->
|
||||
<el-form-item label="文件图片" v-if="isEdit">
|
||||
<div v-if="form.imageList && form.imageList.length > 0" class="image-grid">
|
||||
<div v-for="(img, idx) in form.imageList" :key="img.imageId || idx" class="image-item">
|
||||
<img :src="img.imagePath" />
|
||||
<div class="image-item-mask">
|
||||
<el-button type="warning" size="mini" icon="el-icon-refresh" circle @click="handleReplaceImage(idx)" title="替换"></el-button>
|
||||
<el-button type="danger" size="mini" icon="el-icon-delete" circle @click="handleRemoveImage(idx)" title="删除"></el-button>
|
||||
</div>
|
||||
<div class="image-item-name">{{ img.imageName }}</div>
|
||||
</div>
|
||||
<div class="image-item image-add-btn" @click="handleAddImage">
|
||||
<i class="el-icon-plus"></i>
|
||||
<span>添加图片</span>
|
||||
</div>
|
||||
<input type="file" multiple accept="image/*" ref="editFileInput" style="display:none" @change="handleEditFileSelect" />
|
||||
</div>
|
||||
<div v-else class="no-images-hint">暂无图片,<el-button type="text" @click="handleAddImage">添加图片</el-button></div>
|
||||
</el-form-item>
|
||||
<el-form-item label="订单编号" prop="orderNo">
|
||||
<el-input v-model="form.orderNo" placeholder="请输入订单编号" />
|
||||
@@ -194,14 +245,33 @@
|
||||
<div v-if="infoFile" class="info-dialog-body">
|
||||
<div class="info-main-row">
|
||||
<div class="info-preview">
|
||||
<ImagePreview v-if="infoFileCategory === 'image'" :src="infoFile.filePath" />
|
||||
<PdfPreview v-else-if="infoFileCategory === 'pdf'" :src="infoFile.filePath" />
|
||||
<DocxPreview v-else-if="infoFileCategory === 'docx'" :src="infoFile.filePath" />
|
||||
<XlsxPreview v-else-if="infoFileCategory === 'xlsx'" :src="infoFile.filePath" />
|
||||
<XlsPreview v-else-if="infoFileCategory === 'xls'" :src="infoFile.filePath" />
|
||||
<div v-else class="info-preview-empty">
|
||||
<el-empty description="暂不支持预览此文件类型" />
|
||||
</div>
|
||||
<!-- 多图模式 -->
|
||||
<template v-if="infoFile.imageList && infoFile.imageList.length > 0">
|
||||
<div class="image-carousel-wrap">
|
||||
<el-carousel height="400px" indicator-position="none" arrow="always" ref="previewCarousel" @change="handlePreviewChange">
|
||||
<el-carousel-item v-for="(img, idx) in infoFile.imageList" :key="idx">
|
||||
<el-image :src="img.imagePath" fit="contain" :preview-src-list="previewSrcList" :initial-index="idx" class="carousel-image" />
|
||||
</el-carousel-item>
|
||||
</el-carousel>
|
||||
<div class="thumbnail-strip">
|
||||
<div v-for="(img, idx) in infoFile.imageList" :key="idx" class="thumbnail-item" :class="{ active: activeImageIndex === idx }" @click="handleThumbnailClick(idx)">
|
||||
<img :src="img.imagePath" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="image-counter">{{ activeImageIndex + 1 }} / {{ infoFile.imageList.length }}</div>
|
||||
</div>
|
||||
</template>
|
||||
<!-- 单文件模式 -->
|
||||
<template v-else>
|
||||
<ImagePreview v-if="infoFileCategory === 'image'" :src="infoFile.filePath" />
|
||||
<PdfPreview v-else-if="infoFileCategory === 'pdf'" :src="infoFile.filePath" />
|
||||
<DocxPreview v-else-if="infoFileCategory === 'docx'" :src="infoFile.filePath" />
|
||||
<XlsxPreview v-else-if="infoFileCategory === 'xlsx'" :src="infoFile.filePath" />
|
||||
<XlsPreview v-else-if="infoFileCategory === 'xls'" :src="infoFile.filePath" />
|
||||
<div v-else class="info-preview-empty">
|
||||
<el-empty description="暂不支持预览此文件类型" />
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
<div class="info-meta">
|
||||
<el-descriptions :column="1" border size="small">
|
||||
@@ -260,9 +330,8 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { listFile, getFile, addFile, updateFile, delFile, exportFile, listVisibleUser, addVisibleUser, delVisibleUser, listVisibleUserByFileId, listRelatedToMe, incrementView } from '@/api/system/file'
|
||||
import { listFile, getFile, addFile, updateFile, delFile, exportFile, listVisibleUser, addVisibleUser, delVisibleUser, listVisibleUserByFileId, listRelatedToMe, incrementView, uploadFile, delFileImage } from '@/api/system/file'
|
||||
import { listFileComment, addFileComment } from '@/api/system/fileComment'
|
||||
import { getToken } from '@/utils/auth'
|
||||
import UserSelect from '@/components/KLPService/UserSelect/index'
|
||||
import ImagePreview from '@/components/FilePreview/preview/image/index.vue'
|
||||
import PdfPreview from '@/components/FilePreview/preview/pdf/index.vue'
|
||||
@@ -326,7 +395,8 @@ export default {
|
||||
fileType: undefined,
|
||||
scopeType: 1,
|
||||
visibleUsers: [],
|
||||
remark: undefined
|
||||
remark: undefined,
|
||||
imageList: []
|
||||
},
|
||||
// 可见用户原始数据(编辑时回显)
|
||||
originalVisibleUsers: [],
|
||||
@@ -346,12 +416,12 @@ export default {
|
||||
privateFiles: 0,
|
||||
myFiles: 0
|
||||
},
|
||||
// 上传相关
|
||||
uploadUrl: process.env.VUE_APP_BASE_API + '/system/oss/upload',
|
||||
uploadHeaders: {
|
||||
Authorization: 'Bearer ' + getToken()
|
||||
},
|
||||
uploadFileList: [],
|
||||
// 上传方式 file | image
|
||||
uploadMode: 'file',
|
||||
// 多图上传
|
||||
mainFile: null,
|
||||
stagedImages: [],
|
||||
uploading: false,
|
||||
// 文件详情弹窗
|
||||
infoVisible: false,
|
||||
infoTitle: '',
|
||||
@@ -360,7 +430,9 @@ export default {
|
||||
comments: [],
|
||||
commentExpanded: false,
|
||||
commentInput: '',
|
||||
commentLoading: false
|
||||
commentLoading: false,
|
||||
// 详情弹窗多图预览
|
||||
activeImageIndex: 0
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
@@ -380,6 +452,22 @@ export default {
|
||||
if (ext === 'xlsx') return 'xlsx'
|
||||
if (ext === 'xls') return 'xls'
|
||||
return 'other'
|
||||
},
|
||||
/** 多图预览源列表(用于全屏查看) */
|
||||
previewSrcList() {
|
||||
if (this.infoFile && this.infoFile.imageList && this.infoFile.imageList.length > 0) {
|
||||
return this.infoFile.imageList.map(img => img.imagePath)
|
||||
}
|
||||
return []
|
||||
},
|
||||
/** 是否管理员 */
|
||||
isAdmin() {
|
||||
try {
|
||||
const roles = this.$store.getters.roles
|
||||
return roles && roles.some && roles.some(r => r === 'admin')
|
||||
} catch (e) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
},
|
||||
created() {
|
||||
@@ -446,10 +534,6 @@ export default {
|
||||
if (size < 1024 * 1024) return (size / 1024).toFixed(1) + ' KB'
|
||||
return (size / 1024 / 1024).toFixed(1) + ' MB'
|
||||
},
|
||||
/** 是否可编辑 */
|
||||
canEdit(row) {
|
||||
return row.createBy === this.$store.getters.name
|
||||
},
|
||||
/** 卡片选中判断 */
|
||||
isSelected(fileId) {
|
||||
return this.selectedCardIds.includes(fileId)
|
||||
@@ -492,11 +576,14 @@ export default {
|
||||
fileType: undefined,
|
||||
scopeType: 1,
|
||||
visibleUsers: [],
|
||||
remark: undefined
|
||||
remark: undefined,
|
||||
imageList: []
|
||||
}
|
||||
this.uploadFileList = []
|
||||
this.stagedImages = []
|
||||
this.mainFile = null
|
||||
this.originalVisibleUsers = []
|
||||
this.isEdit = false
|
||||
this.uploadMode = 'file'
|
||||
this.resetForm('form')
|
||||
},
|
||||
/** 可见范围切换 */
|
||||
@@ -547,6 +634,9 @@ export default {
|
||||
handleUpdate(row) {
|
||||
this.reset()
|
||||
this.isEdit = true
|
||||
this.dialogTitle = '编辑文件'
|
||||
// 先打开对话框,让用户感知操作已触发
|
||||
this.open = true
|
||||
const fileId = row.fileId || this.ids[0]
|
||||
getFile(fileId).then(response => {
|
||||
const data = response.data
|
||||
@@ -561,55 +651,225 @@ export default {
|
||||
fileType: data.fileType,
|
||||
scopeType: data.scopeType,
|
||||
visibleUsers: [],
|
||||
remark: data.remark
|
||||
remark: data.remark,
|
||||
imageList: data.imageList || []
|
||||
}
|
||||
if (data.scopeType === 2) {
|
||||
listVisibleUserByFileId(fileId).then(res => {
|
||||
const rows = res.rows || []
|
||||
this.form.visibleUsers = rows.map(r => r.userId)
|
||||
this.originalVisibleUsers = [...this.form.visibleUsers]
|
||||
// 去重,防止重复 userId 导致 el-select 渲染异常
|
||||
const userIds = [...new Set(rows.map(r => r.userId).filter(id => id != null))]
|
||||
this.form.visibleUsers = userIds
|
||||
this.originalVisibleUsers = [...userIds]
|
||||
}).catch(() => {
|
||||
// 可见用户加载失败不影响对话框使用
|
||||
})
|
||||
}
|
||||
this.open = true
|
||||
this.dialogTitle = '编辑文件'
|
||||
}).catch(() => {
|
||||
this.$modal.msgError('获取文件信息失败')
|
||||
this.open = false
|
||||
})
|
||||
},
|
||||
/** 上传前校验 */
|
||||
handleBeforeUpload(file) {
|
||||
/** 上传模式:选择图片 */
|
||||
handleFileSelect(event) {
|
||||
const files = Array.from(event.target.files || [])
|
||||
files.forEach(file => {
|
||||
if (!file.type.startsWith('image/')) return
|
||||
this.stagedImages.push({
|
||||
file: file,
|
||||
url: URL.createObjectURL(file),
|
||||
name: file.name
|
||||
})
|
||||
})
|
||||
event.target.value = ''
|
||||
},
|
||||
|
||||
/** 上传模式:移除已选图片 */
|
||||
removeStagedImage(idx) {
|
||||
const img = this.stagedImages[idx]
|
||||
if (img && img.url) {
|
||||
URL.revokeObjectURL(img.url)
|
||||
}
|
||||
this.stagedImages.splice(idx, 1)
|
||||
},
|
||||
|
||||
/** 编辑模式:替换图片 */
|
||||
handleReplaceImage(idx) {
|
||||
this._replaceIndex = idx
|
||||
this.$refs.editFileInput.click()
|
||||
},
|
||||
|
||||
/** 编辑模式:删除图片 */
|
||||
handleRemoveImage(idx) {
|
||||
this.$modal.confirm('是否确认删除此图片?').then(() => {
|
||||
this.form.imageList.splice(idx, 1)
|
||||
}).catch(() => {})
|
||||
},
|
||||
|
||||
/** 编辑模式:添加新图片 */
|
||||
handleAddImage() {
|
||||
this._replaceIndex = null
|
||||
this.$refs.editFileInput.click()
|
||||
},
|
||||
|
||||
/** 编辑模式:文件选择后上传到 OSS */
|
||||
handleEditFileSelect(event) {
|
||||
const files = Array.from(event.target.files || [])
|
||||
if (files.length === 0) return
|
||||
event.target.value = ''
|
||||
|
||||
this.uploading = true
|
||||
const promises = files
|
||||
.filter(file => file.type.startsWith('image/'))
|
||||
.map(file => {
|
||||
return uploadFile(file).then(res => {
|
||||
if (res.code === 200) {
|
||||
return {
|
||||
imageName: file.name,
|
||||
imagePath: res.data.url,
|
||||
imageSize: file.size,
|
||||
suffix: file.name.split('.').pop().toLowerCase()
|
||||
}
|
||||
} else {
|
||||
this.$modal.msgError(res.msg || file.name + ' 上传失败')
|
||||
return null
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
Promise.all(promises).then(results => {
|
||||
const validResults = results.filter(r => r != null)
|
||||
if (validResults.length === 0) return
|
||||
if (this._replaceIndex !== null && this._replaceIndex !== undefined) {
|
||||
validResults.forEach((img, i) => {
|
||||
const idx = this._replaceIndex + i
|
||||
if (idx < this.form.imageList.length) {
|
||||
this.$set(this.form.imageList, idx, img)
|
||||
} else {
|
||||
this.form.imageList.push(img)
|
||||
}
|
||||
})
|
||||
this._replaceIndex = null
|
||||
} else {
|
||||
validResults.forEach(img => this.form.imageList.push(img))
|
||||
}
|
||||
}).catch(() => {
|
||||
this.$modal.msgError('图片上传失败,请重试')
|
||||
}).finally(() => {
|
||||
this.uploading = false
|
||||
})
|
||||
},
|
||||
|
||||
/** 上传模式:选择主文件 */
|
||||
handleMainFileSelect(event) {
|
||||
const file = event.target.files && event.target.files[0]
|
||||
if (!file) return
|
||||
event.target.value = ''
|
||||
this.mainFile = file
|
||||
if (!this.form.fileName) {
|
||||
this.form.fileName = file.name
|
||||
}
|
||||
const ext = file.name.substring(file.name.lastIndexOf('.') + 1).toLowerCase()
|
||||
this.form.suffix = ext
|
||||
this.form.fileSize = file.size
|
||||
},
|
||||
/** 上传成功 */
|
||||
handleUploadSuccess(response, file, fileList) {
|
||||
if (response.code === 200) {
|
||||
this.form.filePath = response.data.url
|
||||
this.form.fileName = this.form.fileName || response.data.fileName
|
||||
this.$modal.msgSuccess('文件上传成功')
|
||||
this.doSubmit()
|
||||
} else {
|
||||
this.$modal.msgError(response.msg || '上传失败')
|
||||
const name = file.name.lastIndexOf('.') > 0
|
||||
? file.name.substring(0, file.name.lastIndexOf('.'))
|
||||
: file.name
|
||||
this.form.fileName = name
|
||||
}
|
||||
},
|
||||
/** 上传失败 */
|
||||
handleUploadError(err, file, fileList) {
|
||||
this.$modal.msgError('文件上传失败')
|
||||
|
||||
/** 上传模式:移除已选主文件 */
|
||||
removeMainFile() {
|
||||
this.mainFile = null
|
||||
},
|
||||
|
||||
/** 编辑模式:触发替换主文件 */
|
||||
handleReplaceMainFile() {
|
||||
this.$refs.replaceMainFileInput.click()
|
||||
},
|
||||
|
||||
/** 编辑模式:选择替换的主文件后直接上传 OSS 并更新表单 */
|
||||
handleReplaceMainFileSelect(event) {
|
||||
const file = event.target.files && event.target.files[0]
|
||||
if (!file) return
|
||||
event.target.value = ''
|
||||
this.uploading = true
|
||||
uploadFile(file).then(res => {
|
||||
if (res.code === 200) {
|
||||
this.form.filePath = res.data.url
|
||||
this.form.fileSize = file.size
|
||||
const ext = file.name.split('.').pop().toLowerCase()
|
||||
this.form.suffix = ext
|
||||
if (!this.form.fileName) {
|
||||
this.form.fileName = file.name.lastIndexOf('.') > 0
|
||||
? file.name.substring(0, file.name.lastIndexOf('.'))
|
||||
: file.name
|
||||
}
|
||||
this.$modal.msgSuccess('文件替换成功')
|
||||
} else {
|
||||
this.$modal.msgError(res.msg || '文件上传失败')
|
||||
}
|
||||
}).catch(() => {
|
||||
this.$modal.msgError('文件上传失败')
|
||||
}).finally(() => {
|
||||
this.uploading = false
|
||||
})
|
||||
},
|
||||
|
||||
/** 提交表单 */
|
||||
submitForm() {
|
||||
this.$refs['form'].validate(valid => {
|
||||
if (valid) {
|
||||
if (this.isEdit) {
|
||||
this.doSubmit()
|
||||
} else {
|
||||
if (this.$refs.upload && this.$refs.upload.uploadFiles.length > 0) {
|
||||
this.$refs.upload.submit()
|
||||
} else {
|
||||
} else if (this.uploadMode === 'file') {
|
||||
// 上传文件模式
|
||||
if (!this.mainFile) {
|
||||
this.$modal.msgWarning('请选择要上传的文件')
|
||||
return
|
||||
}
|
||||
this.uploading = true
|
||||
uploadFile(this.mainFile).then(res => {
|
||||
if (res.code === 200) {
|
||||
this.form.filePath = res.data.url
|
||||
this.form.fileSize = this.mainFile.size
|
||||
this.form.suffix = this.mainFile.name.split('.').pop().toLowerCase()
|
||||
this.doSubmit()
|
||||
} else {
|
||||
this.$modal.msgError(res.msg || '文件上传失败')
|
||||
}
|
||||
}).catch(() => {
|
||||
this.$modal.msgError('文件上传失败,请重试')
|
||||
}).finally(() => {
|
||||
this.uploading = false
|
||||
})
|
||||
} else if (this.uploadMode === 'image') {
|
||||
// 上传图片模式(串行避免前端防重复提交拦截)
|
||||
if (!this.stagedImages || this.stagedImages.length === 0) {
|
||||
this.$modal.msgWarning('请选择要上传的图片')
|
||||
return
|
||||
}
|
||||
this.uploading = true
|
||||
const imageList = []
|
||||
const uploadNext = (idx) => {
|
||||
if (idx >= this.stagedImages.length) {
|
||||
this.form.imageList = imageList
|
||||
this.doSubmit()
|
||||
return
|
||||
}
|
||||
const img = this.stagedImages[idx]
|
||||
uploadFile(img.file).then(res => {
|
||||
if (res.code === 200) {
|
||||
imageList.push({
|
||||
imageName: img.name,
|
||||
imagePath: res.data.url,
|
||||
imageSize: img.file.size,
|
||||
suffix: img.name.split('.').pop().toLowerCase()
|
||||
})
|
||||
}
|
||||
uploadNext(idx + 1)
|
||||
}).catch(() => {
|
||||
this.$modal.msgError('图片上传失败:' + img.name)
|
||||
this.uploading = false
|
||||
})
|
||||
}
|
||||
uploadNext(0)
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -679,10 +939,30 @@ export default {
|
||||
},
|
||||
/** 打开详情弹窗 */
|
||||
handleShowInfo(row) {
|
||||
this.infoFile = row
|
||||
this.activeImageIndex = 0
|
||||
this.infoTitle = '文件详情 - ' + row.fileName
|
||||
this.infoVisible = true
|
||||
incrementView(row.fileId)
|
||||
// 加载完整详情(含 imageList)
|
||||
getFile(row.fileId).then(response => {
|
||||
this.infoFile = response.data
|
||||
}).catch(() => {
|
||||
// 详情加载失败时用行数据兜底
|
||||
this.infoFile = row
|
||||
})
|
||||
},
|
||||
|
||||
/** 多图预览切换 */
|
||||
handlePreviewChange(idx) {
|
||||
this.activeImageIndex = idx
|
||||
},
|
||||
|
||||
/** 缩略图点击跳转 */
|
||||
handleThumbnailClick(idx) {
|
||||
this.activeImageIndex = idx
|
||||
if (this.$refs.previewCarousel) {
|
||||
this.$refs.previewCarousel.setActiveItem(idx)
|
||||
}
|
||||
},
|
||||
/** 点击行选中 */
|
||||
handleRowClick(row) {
|
||||
@@ -1168,4 +1448,206 @@ export default {
|
||||
padding: 8px 12px;
|
||||
border-top: 1px solid #f2f2f2;
|
||||
}
|
||||
|
||||
/* 图片上传/编辑区域 */
|
||||
.image-upload-area {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.upload-hint {
|
||||
font-size: 12px;
|
||||
color: #909399;
|
||||
margin-left: 8px;
|
||||
}
|
||||
|
||||
.image-grid {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 10px;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.image-item {
|
||||
position: relative;
|
||||
width: 100px;
|
||||
height: 100px;
|
||||
border: 1px solid #dcdfe6;
|
||||
border-radius: 4px;
|
||||
overflow: hidden;
|
||||
cursor: default;
|
||||
background: #fafafa;
|
||||
}
|
||||
|
||||
.image-item img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
}
|
||||
|
||||
.image-item-mask {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background: rgba(0, 0, 0, 0.5);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 6px;
|
||||
opacity: 0;
|
||||
transition: opacity 0.2s;
|
||||
}
|
||||
|
||||
.image-item:hover .image-item-mask {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.image-item-name {
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
padding: 2px 4px;
|
||||
font-size: 11px;
|
||||
color: #fff;
|
||||
background: rgba(0, 0, 0, 0.6);
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.image-add-btn {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
cursor: pointer;
|
||||
border: 1px dashed #dcdfe6;
|
||||
color: #909399;
|
||||
font-size: 12px;
|
||||
transition: all 0.2s;
|
||||
}
|
||||
|
||||
.image-add-btn:hover {
|
||||
border-color: #409eff;
|
||||
color: #409eff;
|
||||
}
|
||||
|
||||
.image-add-btn i {
|
||||
font-size: 28px;
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
.image-count {
|
||||
font-size: 12px;
|
||||
color: #909399;
|
||||
margin-top: 6px;
|
||||
}
|
||||
|
||||
/* 主文件上传区域 */
|
||||
.file-upload-area {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.main-file-info {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
margin-top: 8px;
|
||||
padding: 8px 12px;
|
||||
background: #f5f7fa;
|
||||
border: 1px solid #e4e7ed;
|
||||
border-radius: 4px;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.main-file-info .el-icon-document {
|
||||
font-size: 18px;
|
||||
color: #409eff;
|
||||
}
|
||||
|
||||
.main-file-name {
|
||||
color: #303133;
|
||||
max-width: 260px;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.main-file-size {
|
||||
color: #909399;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.no-images-hint {
|
||||
font-size: 13px;
|
||||
color: #909399;
|
||||
}
|
||||
|
||||
/* 详情弹窗多图轮播 */
|
||||
.image-carousel-wrap {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.image-carousel-wrap .el-carousel {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.carousel-image {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.carousel-image /deep/ .el-image__inner {
|
||||
max-width: 100%;
|
||||
max-height: 100%;
|
||||
}
|
||||
|
||||
.thumbnail-strip {
|
||||
display: flex;
|
||||
gap: 6px;
|
||||
padding: 8px 0;
|
||||
overflow-x: auto;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.thumbnail-item {
|
||||
width: 56px;
|
||||
height: 56px;
|
||||
border: 2px solid transparent;
|
||||
border-radius: 4px;
|
||||
overflow: hidden;
|
||||
cursor: pointer;
|
||||
flex-shrink: 0;
|
||||
transition: border-color 0.2s;
|
||||
}
|
||||
|
||||
.thumbnail-item:hover {
|
||||
border-color: #409eff;
|
||||
}
|
||||
|
||||
.thumbnail-item.active {
|
||||
border-color: #409eff;
|
||||
}
|
||||
|
||||
.thumbnail-item img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
}
|
||||
|
||||
.image-counter {
|
||||
text-align: center;
|
||||
font-size: 12px;
|
||||
color: #909399;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -150,25 +150,75 @@
|
||||
<el-dialog :title="dialogTitle" :visible.sync="open" width="650px" append-to-body @close="handleDialogClose">
|
||||
<el-form ref="form" :model="form" :rules="rules" label-width="100px">
|
||||
<el-form-item label="文件名称" prop="fileName">
|
||||
<el-input v-model="form.fileName" placeholder="请输入文件名称" :disabled="isEdit" />
|
||||
<el-input v-model="form.fileName" placeholder="请输入文件名称" />
|
||||
</el-form-item>
|
||||
<el-form-item label="上传文件" v-if="!isEdit">
|
||||
<el-upload
|
||||
ref="upload"
|
||||
:action="uploadUrl"
|
||||
:headers="uploadHeaders"
|
||||
:file-list="uploadFileList"
|
||||
:before-upload="handleBeforeUpload"
|
||||
:on-success="handleUploadSuccess"
|
||||
:on-error="handleUploadError"
|
||||
:auto-upload="false"
|
||||
:limit="1"
|
||||
class="upload-demo"
|
||||
drag
|
||||
>
|
||||
<i class="el-icon-upload"></i>
|
||||
<div class="el-upload__text">将文件拖到此处,或<em>点击选取</em></div>
|
||||
</el-upload>
|
||||
<!-- 上传模式 - 选择方式 -->
|
||||
<el-form-item label="上传方式" v-if="!isEdit">
|
||||
<el-radio-group v-model="uploadMode">
|
||||
<el-radio label="file">上传文件</el-radio>
|
||||
<el-radio label="image">上传图片</el-radio>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
<!-- 上传文件 -->
|
||||
<el-form-item v-if="!isEdit && uploadMode === 'file'" label="选择文件" required>
|
||||
<div class="file-upload-area">
|
||||
<input type="file" ref="mainFileInput" style="display:none" @change="handleMainFileSelect" />
|
||||
<el-button type="primary" @click="$refs.mainFileInput.click()">选择文件</el-button>
|
||||
<span class="upload-hint">支持 pdf / xlsx / docx / 图片 等格式</span>
|
||||
<div v-if="mainFile" class="main-file-info">
|
||||
<i class="el-icon-document"></i>
|
||||
<span class="main-file-name">{{ mainFile.name }}</span>
|
||||
<span class="main-file-size">({{ formatFileSize(mainFile.size) }})</span>
|
||||
<el-button type="text" size="mini" icon="el-icon-delete" @click="removeMainFile" style="color:#f56c6c;"></el-button>
|
||||
</div>
|
||||
</div>
|
||||
</el-form-item>
|
||||
<!-- 上传图片(多张) -->
|
||||
<el-form-item v-if="!isEdit && uploadMode === 'image'" label="选择图片" required>
|
||||
<div class="image-upload-area">
|
||||
<input type="file" multiple accept="image/*" ref="fileInput" style="display:none" @change="handleFileSelect" />
|
||||
<el-button @click="$refs.fileInput.click()">选择图片</el-button>
|
||||
<span class="upload-hint">支持多选 jpg/png/webp/bmp</span>
|
||||
<div v-if="stagedImages.length > 0" class="image-grid">
|
||||
<div v-for="(img, idx) in stagedImages" :key="idx" class="image-item">
|
||||
<img :src="img.url" />
|
||||
<div class="image-item-mask">
|
||||
<el-button type="danger" size="mini" icon="el-icon-delete" circle @click="removeStagedImage(idx)"></el-button>
|
||||
</div>
|
||||
<div class="image-item-name">{{ img.name }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</el-form-item>
|
||||
<!-- 编辑模式 - 主文件信息 -->
|
||||
<el-form-item label="当前文件" v-if="isEdit && form.filePath">
|
||||
<div class="main-file-info">
|
||||
<i class="el-icon-document"></i>
|
||||
<span class="main-file-name">{{ form.fileName }}</span>
|
||||
<span class="main-file-size" v-if="form.fileSize">({{ formatFileSize(form.fileSize) }})</span>
|
||||
<el-button type="text" size="mini" icon="el-icon-refresh" @click="handleReplaceMainFile" style="margin-left:8px;">替换</el-button>
|
||||
<el-button type="text" size="mini" icon="el-icon-download" @click="downloadFile(form)" v-if="form.filePath">下载</el-button>
|
||||
<input type="file" ref="replaceMainFileInput" style="display:none" @change="handleReplaceMainFileSelect" />
|
||||
</div>
|
||||
</el-form-item>
|
||||
<!-- 编辑模式 - 图片管理 -->
|
||||
<el-form-item label="文件图片" v-if="isEdit">
|
||||
<div v-if="form.imageList && form.imageList.length > 0" class="image-grid">
|
||||
<div v-for="(img, idx) in form.imageList" :key="img.imageId || idx" class="image-item">
|
||||
<img :src="img.imagePath" />
|
||||
<div class="image-item-mask">
|
||||
<el-button type="warning" size="mini" icon="el-icon-refresh" circle @click="handleReplaceImage(idx)" title="替换"></el-button>
|
||||
<el-button type="danger" size="mini" icon="el-icon-delete" circle @click="handleRemoveImage(idx)" title="删除"></el-button>
|
||||
</div>
|
||||
<div class="image-item-name">{{ img.imageName }}</div>
|
||||
</div>
|
||||
<div class="image-item image-add-btn" @click="handleAddImage">
|
||||
<i class="el-icon-plus"></i>
|
||||
<span>添加图片</span>
|
||||
</div>
|
||||
<input type="file" multiple accept="image/*" ref="editFileInput" style="display:none" @change="handleEditFileSelect" />
|
||||
</div>
|
||||
<div v-else class="no-images-hint">暂无图片,<el-button type="text" @click="handleAddImage">添加图片</el-button></div>
|
||||
</el-form-item>
|
||||
<el-form-item label="订单编号" prop="orderNo">
|
||||
<el-input v-model="form.orderNo" placeholder="请输入订单编号" />
|
||||
@@ -204,14 +254,33 @@
|
||||
<el-dialog :title="infoTitle" :visible.sync="infoVisible" width="1100px" append-to-body top="5vh" @close="handleInfoClose">
|
||||
<div v-if="infoFile" class="info-dialog-body">
|
||||
<div class="info-preview">
|
||||
<ImagePreview v-if="infoFileCategory === 'image'" :src="infoFile.filePath" />
|
||||
<PdfPreview v-else-if="infoFileCategory === 'pdf'" :src="infoFile.filePath" />
|
||||
<DocxPreview v-else-if="infoFileCategory === 'docx'" :src="infoFile.filePath" />
|
||||
<XlsxPreview v-else-if="infoFileCategory === 'xlsx'" :src="infoFile.filePath" />
|
||||
<XlsPreview v-else-if="infoFileCategory === 'xls'" :src="infoFile.filePath" />
|
||||
<div v-else class="info-preview-empty">
|
||||
<el-empty description="暂不支持预览此文件类型" />
|
||||
</div>
|
||||
<!-- 多图模式 -->
|
||||
<template v-if="infoFile.imageList && infoFile.imageList.length > 0">
|
||||
<div class="image-carousel-wrap">
|
||||
<el-carousel height="400px" indicator-position="none" arrow="always" ref="previewCarousel" @change="handlePreviewChange">
|
||||
<el-carousel-item v-for="(img, idx) in infoFile.imageList" :key="idx">
|
||||
<el-image :src="img.imagePath" fit="contain" :preview-src-list="previewSrcList" :initial-index="idx" class="carousel-image" />
|
||||
</el-carousel-item>
|
||||
</el-carousel>
|
||||
<div class="thumbnail-strip">
|
||||
<div v-for="(img, idx) in infoFile.imageList" :key="idx" class="thumbnail-item" :class="{ active: activeImageIndex === idx }" @click="handleThumbnailClick(idx)">
|
||||
<img :src="img.imagePath" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="image-counter">{{ activeImageIndex + 1 }} / {{ infoFile.imageList.length }}</div>
|
||||
</div>
|
||||
</template>
|
||||
<!-- 单文件模式 -->
|
||||
<template v-else>
|
||||
<ImagePreview v-if="infoFileCategory === 'image'" :src="infoFile.filePath" />
|
||||
<PdfPreview v-else-if="infoFileCategory === 'pdf'" :src="infoFile.filePath" />
|
||||
<DocxPreview v-else-if="infoFileCategory === 'docx'" :src="infoFile.filePath" />
|
||||
<XlsxPreview v-else-if="infoFileCategory === 'xlsx'" :src="infoFile.filePath" />
|
||||
<XlsPreview v-else-if="infoFileCategory === 'xls'" :src="infoFile.filePath" />
|
||||
<div v-else class="info-preview-empty">
|
||||
<el-empty description="暂不支持预览此文件类型" />
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
<div class="info-meta">
|
||||
<el-descriptions :column="1" border size="small">
|
||||
@@ -269,9 +338,8 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { listFile, getFile, addFile, updateFile, delFile, exportFile, listVisibleUser, addVisibleUser, delVisibleUser, listVisibleUserByFileId, listRelatedToMe, incrementView } from '@/api/system/file'
|
||||
import { listFile, getFile, addFile, updateFile, delFile, exportFile, listVisibleUser, addVisibleUser, delVisibleUser, listVisibleUserByFileId, listRelatedToMe, incrementView, uploadFile, delFileImage } from '@/api/system/file'
|
||||
import { listFileComment, addFileComment } from '@/api/system/fileComment'
|
||||
import { getToken } from '@/utils/auth'
|
||||
import UserSelect from '@/components/KLPService/UserSelect/index'
|
||||
import ImagePreview from '@/components/FilePreview/preview/image/index.vue'
|
||||
import PdfPreview from '@/components/FilePreview/preview/pdf/index.vue'
|
||||
@@ -338,7 +406,8 @@ export default {
|
||||
fileType: undefined,
|
||||
scopeType: 1,
|
||||
visibleUsers: [],
|
||||
remark: undefined
|
||||
remark: undefined,
|
||||
imageList: []
|
||||
},
|
||||
// 可见用户原始数据(编辑时回显)
|
||||
originalVisibleUsers: [],
|
||||
@@ -351,12 +420,12 @@ export default {
|
||||
{ required: true, message: '请选择文件类型', trigger: 'change' }
|
||||
]
|
||||
},
|
||||
// 上传相关
|
||||
uploadUrl: process.env.VUE_APP_BASE_API + '/system/oss/upload',
|
||||
uploadHeaders: {
|
||||
Authorization: 'Bearer ' + getToken()
|
||||
},
|
||||
uploadFileList: [],
|
||||
// 上传方式 file | image
|
||||
uploadMode: 'file',
|
||||
// 多图上传
|
||||
mainFile: null,
|
||||
stagedImages: [],
|
||||
uploading: false,
|
||||
// 文件详情弹窗
|
||||
infoVisible: false,
|
||||
infoTitle: '',
|
||||
@@ -365,7 +434,9 @@ export default {
|
||||
comments: [],
|
||||
commentExpanded: false,
|
||||
commentInput: '',
|
||||
commentLoading: false
|
||||
commentLoading: false,
|
||||
// 详情弹窗多图预览
|
||||
activeImageIndex: 0
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
@@ -385,6 +456,13 @@ export default {
|
||||
if (ext === 'xlsx') return 'xlsx'
|
||||
if (ext === 'xls') return 'xls'
|
||||
return 'other'
|
||||
},
|
||||
/** 多图预览源列表(用于全屏查看) */
|
||||
previewSrcList() {
|
||||
if (this.infoFile && this.infoFile.imageList && this.infoFile.imageList.length > 0) {
|
||||
return this.infoFile.imageList.map(img => img.imagePath)
|
||||
}
|
||||
return []
|
||||
}
|
||||
},
|
||||
created() {
|
||||
@@ -458,20 +536,23 @@ export default {
|
||||
reset() {
|
||||
this.form = {
|
||||
fileId: undefined,
|
||||
fileName: undefined,
|
||||
filePath: undefined,
|
||||
fileSize: undefined,
|
||||
suffix: undefined,
|
||||
orderNo: undefined,
|
||||
dept: undefined,
|
||||
fileType: undefined,
|
||||
fileName: '',
|
||||
filePath: '',
|
||||
fileSize: '',
|
||||
suffix: '',
|
||||
orderNo: '',
|
||||
dept: '',
|
||||
fileType: '',
|
||||
scopeType: 1,
|
||||
visibleUsers: [],
|
||||
remark: undefined
|
||||
remark: '',
|
||||
imageList: []
|
||||
}
|
||||
this.uploadFileList = []
|
||||
this.stagedImages = []
|
||||
this.mainFile = null
|
||||
this.originalVisibleUsers = []
|
||||
this.isEdit = false
|
||||
this.uploadMode = 'file'
|
||||
this.resetForm('form')
|
||||
},
|
||||
/** 可见范围切换 */
|
||||
@@ -527,6 +608,9 @@ export default {
|
||||
handleUpdate(row) {
|
||||
this.reset()
|
||||
this.isEdit = true
|
||||
this.dialogTitle = '编辑文件'
|
||||
// 先打开对话框,让用户感知操作已触发
|
||||
this.open = true
|
||||
const fileId = row.fileId || this.ids[0]
|
||||
getFile(fileId).then(response => {
|
||||
const data = response.data
|
||||
@@ -541,55 +625,228 @@ export default {
|
||||
fileType: data.fileType,
|
||||
scopeType: data.scopeType,
|
||||
visibleUsers: [],
|
||||
remark: data.remark
|
||||
remark: data.remark,
|
||||
imageList: data.imageList || []
|
||||
}
|
||||
if (data.scopeType === 2) {
|
||||
listVisibleUserByFileId(fileId).then(res => {
|
||||
const rows = res.rows || []
|
||||
this.form.visibleUsers = rows.map(r => r.userId)
|
||||
this.originalVisibleUsers = [...this.form.visibleUsers]
|
||||
// 去重,防止重复 userId 导致 el-select 渲染异常
|
||||
const userIds = [...new Set(rows.map(r => r.userId).filter(id => id != null))]
|
||||
this.form.visibleUsers = userIds
|
||||
this.originalVisibleUsers = [...userIds]
|
||||
}).catch(() => {
|
||||
// 可见用户加载失败不影响对话框使用
|
||||
})
|
||||
}
|
||||
this.open = true
|
||||
this.dialogTitle = '编辑文件'
|
||||
}).catch(() => {
|
||||
this.$modal.msgError('获取文件信息失败')
|
||||
this.open = false
|
||||
})
|
||||
},
|
||||
/** 上传前校验 */
|
||||
handleBeforeUpload(file) {
|
||||
/** 上传模式:选择图片 */
|
||||
handleFileSelect(event) {
|
||||
const files = Array.from(event.target.files || [])
|
||||
files.forEach(file => {
|
||||
if (!file.type.startsWith('image/')) return
|
||||
this.stagedImages.push({
|
||||
file: file,
|
||||
url: URL.createObjectURL(file),
|
||||
name: file.name
|
||||
})
|
||||
})
|
||||
event.target.value = ''
|
||||
},
|
||||
|
||||
/** 上传模式:移除已选图片 */
|
||||
removeStagedImage(idx) {
|
||||
const img = this.stagedImages[idx]
|
||||
if (img && img.url) {
|
||||
URL.revokeObjectURL(img.url)
|
||||
}
|
||||
this.stagedImages.splice(idx, 1)
|
||||
},
|
||||
|
||||
/** 编辑模式:替换图片 */
|
||||
handleReplaceImage(idx) {
|
||||
this._replaceIndex = idx
|
||||
this.$refs.editFileInput.click()
|
||||
},
|
||||
|
||||
/** 编辑模式:删除图片 */
|
||||
handleRemoveImage(idx) {
|
||||
this.$modal.confirm('是否确认删除此图片?').then(() => {
|
||||
this.form.imageList.splice(idx, 1)
|
||||
}).catch(() => {})
|
||||
},
|
||||
|
||||
/** 编辑模式:添加新图片 */
|
||||
handleAddImage() {
|
||||
this._replaceIndex = null
|
||||
this.$refs.editFileInput.click()
|
||||
},
|
||||
|
||||
/** 编辑模式:文件选择后上传到 OSS */
|
||||
handleEditFileSelect(event) {
|
||||
const files = Array.from(event.target.files || [])
|
||||
if (files.length === 0) return
|
||||
event.target.value = ''
|
||||
|
||||
this.uploading = true
|
||||
const promises = files
|
||||
.filter(file => file.type.startsWith('image/'))
|
||||
.map(file => {
|
||||
return uploadFile(file).then(res => {
|
||||
if (res.code === 200) {
|
||||
return {
|
||||
imageName: file.name,
|
||||
imagePath: res.data.url,
|
||||
imageSize: file.size,
|
||||
suffix: file.name.split('.').pop().toLowerCase()
|
||||
}
|
||||
} else {
|
||||
this.$modal.msgError(res.msg || file.name + ' 上传失败')
|
||||
return null
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
Promise.all(promises).then(results => {
|
||||
const validResults = results.filter(r => r != null)
|
||||
if (validResults.length === 0) return
|
||||
if (this._replaceIndex !== null && this._replaceIndex !== undefined) {
|
||||
// 替换已有图片
|
||||
validResults.forEach((img, i) => {
|
||||
const idx = this._replaceIndex + i
|
||||
if (idx < this.form.imageList.length) {
|
||||
this.$set(this.form.imageList, idx, img)
|
||||
} else {
|
||||
this.form.imageList.push(img)
|
||||
}
|
||||
})
|
||||
this._replaceIndex = null
|
||||
} else {
|
||||
// 新增图片
|
||||
validResults.forEach(img => this.form.imageList.push(img))
|
||||
}
|
||||
}).catch(() => {
|
||||
this.$modal.msgError('图片上传失败,请重试')
|
||||
}).finally(() => {
|
||||
this.uploading = false
|
||||
})
|
||||
},
|
||||
|
||||
/** 上传模式:选择主文件 */
|
||||
handleMainFileSelect(event) {
|
||||
const file = event.target.files && event.target.files[0]
|
||||
if (!file) return
|
||||
event.target.value = ''
|
||||
this.mainFile = file
|
||||
// 自动填充文件名(不含扩展名)
|
||||
if (!this.form.fileName) {
|
||||
this.form.fileName = file.name
|
||||
}
|
||||
const ext = file.name.substring(file.name.lastIndexOf('.') + 1).toLowerCase()
|
||||
this.form.suffix = ext
|
||||
this.form.fileSize = file.size
|
||||
},
|
||||
/** 上传成功 */
|
||||
handleUploadSuccess(response, file, fileList) {
|
||||
if (response.code === 200) {
|
||||
this.form.filePath = response.data.url
|
||||
this.form.fileName = this.form.fileName || response.data.fileName
|
||||
this.$modal.msgSuccess('文件上传成功')
|
||||
this.doSubmit()
|
||||
} else {
|
||||
this.$modal.msgError(response.msg || '上传失败')
|
||||
const name = file.name.lastIndexOf('.') > 0
|
||||
? file.name.substring(0, file.name.lastIndexOf('.'))
|
||||
: file.name
|
||||
this.form.fileName = name
|
||||
}
|
||||
},
|
||||
/** 上传失败 */
|
||||
handleUploadError(err, file, fileList) {
|
||||
this.$modal.msgError('文件上传失败')
|
||||
|
||||
/** 上传模式:移除已选主文件 */
|
||||
removeMainFile() {
|
||||
this.mainFile = null
|
||||
},
|
||||
|
||||
/** 编辑模式:触发替换主文件 */
|
||||
handleReplaceMainFile() {
|
||||
this.$refs.replaceMainFileInput.click()
|
||||
},
|
||||
|
||||
/** 编辑模式:选择替换的主文件后直接上传 OSS 并更新表单 */
|
||||
handleReplaceMainFileSelect(event) {
|
||||
const file = event.target.files && event.target.files[0]
|
||||
if (!file) return
|
||||
event.target.value = ''
|
||||
this.uploading = true
|
||||
uploadFile(file).then(res => {
|
||||
if (res.code === 200) {
|
||||
this.form.filePath = res.data.url
|
||||
this.form.fileSize = file.size
|
||||
const ext = file.name.split('.').pop().toLowerCase()
|
||||
this.form.suffix = ext
|
||||
if (!this.form.fileName) {
|
||||
this.form.fileName = file.name.lastIndexOf('.') > 0
|
||||
? file.name.substring(0, file.name.lastIndexOf('.'))
|
||||
: file.name
|
||||
}
|
||||
this.$modal.msgSuccess('文件替换成功')
|
||||
} else {
|
||||
this.$modal.msgError(res.msg || '文件上传失败')
|
||||
}
|
||||
}).catch(() => {
|
||||
this.$modal.msgError('文件上传失败')
|
||||
}).finally(() => {
|
||||
this.uploading = false
|
||||
})
|
||||
},
|
||||
|
||||
/** 提交表单 */
|
||||
submitForm() {
|
||||
this.$refs['form'].validate(valid => {
|
||||
if (valid) {
|
||||
if (this.isEdit) {
|
||||
this.doSubmit()
|
||||
} else {
|
||||
if (this.$refs.upload && this.$refs.upload.uploadFiles.length > 0) {
|
||||
this.$refs.upload.submit()
|
||||
} else {
|
||||
} else if (this.uploadMode === 'file') {
|
||||
// 上传文件模式
|
||||
if (!this.mainFile) {
|
||||
this.$modal.msgWarning('请选择要上传的文件')
|
||||
return
|
||||
}
|
||||
this.uploading = true
|
||||
uploadFile(this.mainFile).then(res => {
|
||||
if (res.code === 200) {
|
||||
this.form.filePath = res.data.url
|
||||
this.form.fileSize = this.mainFile.size
|
||||
this.form.suffix = this.mainFile.name.split('.').pop().toLowerCase()
|
||||
this.doSubmit()
|
||||
} else {
|
||||
this.$modal.msgError(res.msg || '文件上传失败')
|
||||
}
|
||||
}).catch(() => {
|
||||
this.$modal.msgError('文件上传失败,请重试')
|
||||
}).finally(() => {
|
||||
this.uploading = false
|
||||
})
|
||||
} else if (this.uploadMode === 'image') {
|
||||
// 上传图片模式(串行避免前端防重复提交拦截)
|
||||
if (!this.stagedImages || this.stagedImages.length === 0) {
|
||||
this.$modal.msgWarning('请选择要上传的图片')
|
||||
return
|
||||
}
|
||||
this.uploading = true
|
||||
const imageList = []
|
||||
const uploadNext = (idx) => {
|
||||
if (idx >= this.stagedImages.length) {
|
||||
this.form.imageList = imageList
|
||||
this.doSubmit()
|
||||
return
|
||||
}
|
||||
const img = this.stagedImages[idx]
|
||||
uploadFile(img.file).then(res => {
|
||||
if (res.code === 200) {
|
||||
imageList.push({
|
||||
imageName: img.name,
|
||||
imagePath: res.data.url,
|
||||
imageSize: img.file.size,
|
||||
suffix: img.name.split('.').pop().toLowerCase()
|
||||
})
|
||||
}
|
||||
uploadNext(idx + 1)
|
||||
}).catch(() => {
|
||||
this.$modal.msgError('图片上传失败:' + img.name)
|
||||
this.uploading = false
|
||||
})
|
||||
}
|
||||
uploadNext(0)
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -665,10 +922,30 @@ export default {
|
||||
},
|
||||
/** 打开详情弹窗 */
|
||||
handleShowInfo(row) {
|
||||
this.infoFile = row
|
||||
this.activeImageIndex = 0
|
||||
this.infoTitle = '文件详情 - ' + row.fileName
|
||||
this.infoVisible = true
|
||||
incrementView(row.fileId)
|
||||
// 加载完整详情(含 imageList)
|
||||
getFile(row.fileId).then(response => {
|
||||
this.infoFile = response.data
|
||||
}).catch(() => {
|
||||
// 详情加载失败时用行数据兜底
|
||||
this.infoFile = row
|
||||
})
|
||||
},
|
||||
|
||||
/** 多图预览切换 */
|
||||
handlePreviewChange(idx) {
|
||||
this.activeImageIndex = idx
|
||||
},
|
||||
|
||||
/** 缩略图点击跳转 */
|
||||
handleThumbnailClick(idx) {
|
||||
this.activeImageIndex = idx
|
||||
if (this.$refs.previewCarousel) {
|
||||
this.$refs.previewCarousel.setActiveItem(idx)
|
||||
}
|
||||
},
|
||||
/** 点击行选中 */
|
||||
handleRowClick(row) {
|
||||
@@ -829,11 +1106,6 @@ export default {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
/* 上传区域 */
|
||||
.upload-demo {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
/* 操作列按钮对齐 */
|
||||
.action-cell {
|
||||
display: flex;
|
||||
@@ -962,6 +1234,208 @@ export default {
|
||||
padding: 8px 12px;
|
||||
border-top: 1px solid #f2f2f2;
|
||||
}
|
||||
|
||||
/* 图片上传/编辑区域 */
|
||||
.image-upload-area {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.upload-hint {
|
||||
font-size: 12px;
|
||||
color: #909399;
|
||||
margin-left: 8px;
|
||||
}
|
||||
|
||||
.image-grid {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 10px;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.image-item {
|
||||
position: relative;
|
||||
width: 100px;
|
||||
height: 100px;
|
||||
border: 1px solid #dcdfe6;
|
||||
border-radius: 4px;
|
||||
overflow: hidden;
|
||||
cursor: default;
|
||||
background: #fafafa;
|
||||
}
|
||||
|
||||
.image-item img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
}
|
||||
|
||||
.image-item-mask {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background: rgba(0, 0, 0, 0.5);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 6px;
|
||||
opacity: 0;
|
||||
transition: opacity 0.2s;
|
||||
}
|
||||
|
||||
.image-item:hover .image-item-mask {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.image-item-name {
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
padding: 2px 4px;
|
||||
font-size: 11px;
|
||||
color: #fff;
|
||||
background: rgba(0, 0, 0, 0.6);
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.image-add-btn {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
cursor: pointer;
|
||||
border: 1px dashed #dcdfe6;
|
||||
color: #909399;
|
||||
font-size: 12px;
|
||||
transition: all 0.2s;
|
||||
}
|
||||
|
||||
.image-add-btn:hover {
|
||||
border-color: #409eff;
|
||||
color: #409eff;
|
||||
}
|
||||
|
||||
.image-add-btn i {
|
||||
font-size: 28px;
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
.image-count {
|
||||
font-size: 12px;
|
||||
color: #909399;
|
||||
margin-top: 6px;
|
||||
}
|
||||
|
||||
/* 主文件上传区域 */
|
||||
.file-upload-area {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.main-file-info {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
margin-top: 8px;
|
||||
padding: 8px 12px;
|
||||
background: #f5f7fa;
|
||||
border: 1px solid #e4e7ed;
|
||||
border-radius: 4px;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.main-file-info .el-icon-document {
|
||||
font-size: 18px;
|
||||
color: #409eff;
|
||||
}
|
||||
|
||||
.main-file-name {
|
||||
color: #303133;
|
||||
max-width: 260px;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.main-file-size {
|
||||
color: #909399;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.no-images-hint {
|
||||
font-size: 13px;
|
||||
color: #909399;
|
||||
}
|
||||
|
||||
/* 详情弹窗多图轮播 */
|
||||
.image-carousel-wrap {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.image-carousel-wrap .el-carousel {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.carousel-image {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.carousel-image /deep/ .el-image__inner {
|
||||
max-width: 100%;
|
||||
max-height: 100%;
|
||||
}
|
||||
|
||||
.thumbnail-strip {
|
||||
display: flex;
|
||||
gap: 6px;
|
||||
padding: 8px 0;
|
||||
overflow-x: auto;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.thumbnail-item {
|
||||
width: 56px;
|
||||
height: 56px;
|
||||
border: 2px solid transparent;
|
||||
border-radius: 4px;
|
||||
overflow: hidden;
|
||||
cursor: pointer;
|
||||
flex-shrink: 0;
|
||||
transition: border-color 0.2s;
|
||||
}
|
||||
|
||||
.thumbnail-item:hover {
|
||||
border-color: #409eff;
|
||||
}
|
||||
|
||||
.thumbnail-item.active {
|
||||
border-color: #409eff;
|
||||
}
|
||||
|
||||
.thumbnail-item img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
}
|
||||
|
||||
.image-counter {
|
||||
text-align: center;
|
||||
font-size: 12px;
|
||||
color: #909399;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
</style>
|
||||
|
||||
<!-- 表格选中行高亮 -->
|
||||
|
||||
Reference in New Issue
Block a user