Merge remote-tracking branch 'origin/master'

This commit is contained in:
赵旭 2024-08-29 22:20:45 +08:00
commit 7a0e5680b8
14 changed files with 698 additions and 47 deletions

View File

@ -52,11 +52,12 @@
"dayjs": "^1.11.12",
"echarts": "5.4.0",
"element-ui": "2.15.12",
"file-saver": "2.0.5",
"file-saver": "^2.0.5",
"fuse.js": "6.6.2",
"highlight.js": "9.18.5",
"js-beautify": "1.13.0",
"jsencrypt": "3.3.1",
"jszip": "^3.10.1",
"min-dash": "3.5.2",
"nprogress": "0.2.0",
"qrcode.vue": "^1.7.0",

View File

@ -0,0 +1,24 @@
import request from '@/utils/request'
export function updateArchives(data){
return request({
url: "/archives/update",
method: "post",
data
})
}
export function queryArchivesPage(params){
return request({
url: "/archives/list",
method: "get",
params
})
}
export function removeArchivesById(id){
return request({
url: "/archives/remove/" + id,
method: 'delete'
})
}

View File

@ -98,8 +98,13 @@ export default {
return this.isShowTip && (this.fileType || this.fileSize);
},
},
mounted(){
//
this.initFiles()
},
watch: {
value(val) {
if (val) {
let temp = 1;
const list = Array.isArray(val)? val : this.value.split(",");
@ -116,6 +121,26 @@ export default {
},
},
methods: {
/**
* 手动加载文件列表为了解决本组件value值变化可能会出现监听不到的情况
*/
initFiles(){
if(this.fileList.length==0){
//
if (!this.value){
return;
}
let temp = 1;
const list = Array.isArray(this.value)? this.value : this.value.split(",");
this.fileList = list.map((item) => {
if (typeof item === "string") {
item = { name: item, url: item };
}
item.uid = item.uid || new Date().getTime() + temp++;
return item;
});
}
},
handleBeforeUpload(file) {
if (this.fileType.length) {
const name = file.name.split(".");

View File

@ -1,5 +0,0 @@
import {v4 as uuidv4} from 'uuid'
export function createUUID(){
return uuidv4().replace(/-/g, '')
}

View File

@ -0,0 +1,17 @@
import { v4 as uuidv4 } from 'uuid'
export function createUUID() {
return uuidv4().replace(/-/g, '')
}
export function createHashCodeByStr(str) {
let hash = 0
if (str.length === 0) return hash
for (let i = 0; i < str.length; i++) {
const char = str.charCodeAt(i)
hash = ((hash << 5) - hash) + char
hash = hash & hash // 转换为32位整数
}
// 将整数转换为16进制字符串以缩短code长度
return Math.abs(hash).toString(16)
}

View File

@ -169,6 +169,8 @@ export const DICT_TYPE = {
RESCUE_CAR_TYPE: 'rescue_car_type',
// 档案分类
ARCHIVES_TYPE: 'archives_type',
// 档案项分类
ARCHIVES_ITEM_TYPE: 'archives_item_type',
}
/**

29
src/utils/downloadZIP.js Normal file
View File

@ -0,0 +1,29 @@
import JSZip from 'jszip'
import { saveAs } from 'file-saver'
export async function downloadFilesAsZip(fileObject) {
const zip = new JSZip()
for (const item of fileObject.files) {
try {
const response = await fetch(item.url)
if (!response.ok) {
throw new Error(`下载失败 ${item.url}: ${response.status}`)
}
const blob = await response.blob()
// 提取文件名,假设文件路径中最后一部分为文件名
const fileName = item.name
zip.file(fileName, blob)
} catch (error) {
console.error(`下载失败 ${item.url}:`, error)
}
}
// 生成压缩文件
try {
const content = await zip.generateAsync({ type: 'blob' });
// 保存压缩文件
saveAs(content, fileObject.zipName);
} catch (error) {
console.error('生成ZIP错误', error);
}
}

View File

@ -186,7 +186,7 @@
<script>
import * as PropertyDealItemApi from '@/api/company/property/propertydealitem'
import { createUUID } from '@/utils/createUUID'
import { createUUID } from '@/utils/createUniqueCode'
import * as PropertyDealApi from '@/api/company/property/propertydeal'
import * as PropertyApi from '@/api/company/property/property'
import { getCompanyList } from '@/api/base/company'

View File

@ -149,7 +149,7 @@
<script>
import { createUUID } from '@/utils/createUUID'
import { createUUID } from '@/utils/createUniqueCode'
import * as PropertyApi from '@/api/company/property/property'
import * as PropertyDealApi from '@/api/company/property/propertydeal'
import * as PropertyDealItemApi from '@/api/company/property/propertydealitem'

View File

@ -1,8 +1,9 @@
<template>
<div class="app-container">
<!-- 档案目录 -->
<div class="left">
<div class="left_top">
当前选择的是:&nbsp;&nbsp;{{ chooseData }}
当前选择的是:&nbsp;&nbsp;{{ chooseData.dictLabel }}
</div>
<!-- 操作工具栏 -->
<el-row :gutter="10" class="mb8" style="margin-top: 1rem">
@ -33,6 +34,7 @@
:filter-node-method="filterNode"
@node-click="handleNodeClick"
highlight-current
:default-checked-keys="[chooseData.id]"
>
<template v-slot="{ node, data }">
<!-- 自定义节点内容 -->
@ -42,17 +44,20 @@
</template>
</el-tree>
</div>
<!-- 具体表格 -->
<div class="right">
<el-empty style="margin-top: 10%" v-if="!chooseData" description="请先选择目录"></el-empty>
<div v-else>
<!-- 搜索栏 -->
<el-empty style="margin-top: 10%" v-show="!chooseData" description="请先选择目录"></el-empty>
<div v-show="!!chooseData">
<el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
label-width="90px"
>
<el-form-item label="名称" prop="fileName">
<el-input v-model="queryParams.fileName" placeholder="请输入名称" clearable @keyup.enter.native="handleQuery"/>
<el-form-item label="名称" prop="archivesName">
<el-input v-model="queryParams.archivesName" placeholder="请输入名称" clearable @keyup.enter.native="handleQuery"/>
</el-form-item>
<el-form-item label="时间区间" prop="fileDateArray">
<el-date-picker v-model="queryParams.fileDateArray" style="width: 240px" value-format="yyyy-MM-dd HH:mm:ss"
<el-form-item v-if="activeTab === 'contract_type'" label="时间区间" prop="queryDateArray">
<el-date-picker v-model="queryParams.queryDateArray" style="width: 240px" value-format="yyyy-MM-dd HH:mm:ss"
type="daterange"
range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"
:default-time="['00:00:00', '23:59:59']"
@ -65,31 +70,86 @@
</el-form>
<!-- 操作工具栏 -->
<el-row :gutter="10" class="mb8">
<el-col :span="1.5">
<el-button type="primary" plain icon="el-icon-plus" size="mini"
v-hasPermi="['company:staff:create']"
<el-row :gutter="10" class="mb8" style="margin-bottom: 1rem">
<el-col :span="1.5" v-if="chooseData.isCreated">
<el-button type="primary" plain icon="el-icon-plus" size="mini" @click="openTableFrom(undefined)"
>新增
</el-button>
</el-col>
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
<right-toolbar :showSearch.sync="showSearch" @queryTable="getTabList"></right-toolbar>
</el-row>
<!-- 表格 -->
<el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true" :row-class-name="getRowClass">
<el-table-column label="序号" align="center" width="80">
<template scope="scope">
<span>{{ scope.$index + 1 }}</span>
</template>
</el-table-column>
<el-table-column :show-overflow-tooltip="true" label="档案名称" align="center" prop="archivesName" width="180"/>
<el-table-column label="档案类别" align="center" prop="sex" width="80">
<template v-slot="scope">
<dict-tag :type="DICT_TYPE.ARCHIVES_ITEM_TYPE" :value="scope.row.archivesType"/>
</template>
</el-table-column>
<el-table-column :show-overflow-tooltip="true" label="档案存放位置" align="center" prop="archivesPhysicsUrl" width="180"/>
<el-table-column v-if="activeTab === 'contract_type'" label="签订日期" align="center" prop="signTime" width="180"/>
<el-table-column v-if="activeTab === 'contract_type'" label="到期日期" align="center" prop="expireTime" width="180"/>
<el-table-column label="备注" align="center" prop="remark" width="180" :show-overflow-tooltip="true"/>
<el-table-column v-if="chooseData.isUpdated || chooseData.isDeleted" label="操作" align="center" class-name="small-padding fixed-width" fixed="right" width="180">
<template v-slot="scope">
<el-button v-if="chooseData.isUpdated" size="mini" type="text" icon="el-icon-edit" @click="openTableFrom(scope.row)"
>修改
</el-button>
<el-button v-if="chooseData.isDeleted" size="mini" type="text" icon="el-icon-delete" @click="handleItemDelete(scope.row)"
>删除
</el-button>
<el-dropdown @command="(command) => handleCommand(command, scope.$index, scope.row)">
<el-button size="mini" type="text" icon="el-icon-d-arrow-right">更多</el-button>
<el-dropdown-menu slot="dropdown">
<el-dropdown-item command="showItem" size="mini" type="text" icon="el-icon-search"
>查看详情
</el-dropdown-item>
<el-dropdown-item v-if="chooseData.isDownload" command="downloadItem" size="mini" type="text" icon="el-icon-download"
>下载
</el-dropdown-item>
</el-dropdown-menu>
</el-dropdown>
</template>
</el-table-column>
</el-table>
</div>
<div style="margin-bottom: 10rem">
<!-- 分页组件 -->
<pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize"
@pagination="getTabList"
/>
</div>
</div>
<ArchivesCatalogForm ref="formRef" @success="getList"/>
<ArchivesForm ref="archivesFormRef" @success="getTabList" />
<ArchivesShowForm ref="archivesShowFormRef" @success="getTabList" />
</div>
</template>
<script>
import { getArchivesCatalogList, removeArchivesRoleAndDict } from '@/api/company/archives/archivesRole'
import {queryArchivesPage, removeArchivesById} from '@/api/company/archives/archives'
import ArchivesCatalogForm from '@/views/knowledge/views/archives/form/ArchivesCatalogForm'
import ArchivesForm from '@/views/knowledge/views/archives/form/ArchivesForm'
import {downloadFilesAsZip} from '@/utils/downloadZIP'
import ArchivesShowForm from '@/views/knowledge/views/archives/form/ArchivesShowForm'
export default {
name: 'ArchivesTable',
components: {
ArchivesCatalogForm
ArchivesCatalogForm,
ArchivesForm,
ArchivesShowForm
},
props: {
activeTab: {
@ -103,8 +163,11 @@ export default {
filterText: '',
chooseData: '',
queryParams: {
fileName: null,
fileDateArray: null
archivesName: null,
queryDateArray: null,
pageNo: 1,
pageSize: 10,
dataId: null
},
//
showSearch: true,
@ -113,7 +176,12 @@ export default {
dictDataTree: [],
selectNodes: [],
//
treeLoading : true
treeLoading : true,
//
loading: false,
list: [],
total: 0,
chooseDataId: 0,
}
},
watch: {
@ -157,7 +225,11 @@ export default {
},
//
handleNodeClick(e) {
this.chooseData = e.dictLabel
this.loading = true
this.chooseData = e
this.chooseDataId = e.dataId
this.queryParams.dataId = e.dataId
this.getTabList()
},
//
filterNode(value, data) {
@ -171,11 +243,13 @@ export default {
return text
},
handleQuery() {
this.queryParams.pageNo = 1
this.getTabList();
},
/** 重置按钮操作 */
resetQuery() {
this.resetForm('queryForm')
this.queryParams.queryDateArray = null
this.handleQuery()
},
handleSelectionChange(selection) {
@ -199,6 +273,77 @@ export default {
this.$modal.msgSuccess('删除成功')
} catch {
}
},
/** 获取表格数据 */
async getTabList(){
this.loading = true
const res = await queryArchivesPage(this.queryParams)
this.list = res.data.records
this.total = res.data.total
this.loading = false
},
openTableFrom(row){
const data = {
...row,
activeTab: this.activeTab,
dataId: this.chooseDataId
}
this.$refs['archivesFormRef'].open(data)
},
async handleItemDelete(row){
const id = row.id
const name = row.archivesName
try {
await this.$modal.confirm('是否确认删除名称为"' + name + '"的数据项?')
await removeArchivesById(id)
await this.getTabList()
this.$modal.msgSuccess('删除成功')
}catch {}
},
// ZIP
async downloadItem(row){
const fileObject = {
zipName: row.archivesName,
files: row.archivesUrls.split(",").map(item => {
return {
name: item.split("|")[1],
url: item.split("|")[0],
uid: item.split("|")[2],
status: item.split("|")[3]
}
})
}
await downloadFilesAsZip(fileObject)
},
handleCommand(command, index, row){
switch (command){
case 'showItem':
row = {
...row,
activeTab: this.activeTab
}
this.$refs["archivesShowFormRef"].open(row)
break
case 'downloadItem':
this.downloadItem(row)
break
default:
break
}
},
//
getRowClass(row, rowIndex){
if (this.activeTab !== 'contract_type'){
return '';
}
const diffTime = new Date(row.row.expireTime) - new Date()
const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));
if (diffDays < 0 || diffDays <= 30){
return 'one-month-row';
}else if (diffDays <= 90){
return 'three-months-row';
}
return ''
}
}
}
@ -243,4 +388,12 @@ div {
::v-deep .el-tree-node__expand-icon.is-leaf {
display: none;
}
::v-deep .el-table .one-month-row td{
background-color: #ffcccc !important; /* 红色背景 */
}
::v-deep .el-table .three-months-row td{
background-color: #ffffcc !important; /* 黄色背景 */
}
</style>

View File

@ -1,16 +0,0 @@
<template>
<div class="app-container">
</div>
</template>
<script>
export default {
name: 'ArchivesType',
}
</script>
<style scoped>
</style>

View File

@ -89,6 +89,26 @@
</el-form-item>
</el-col>
</el-row>
<el-row :gutter="1">
<el-col :span="24">
<el-form-item label="下载权限" prop="downloadRoleIds">
<el-select
style="width: 100%"
filterable
clearable
v-model="formData.downloadRoleIds" multiple placeholder="请选择有下载权限的角色"
>
<el-option
v-for="(item, index) in roleList"
:key="index"
:label="item.name"
:value="item.id"
>
</el-option>
</el-select>
</el-form-item>
</el-col>
</el-row>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button type="primary" @click="submitForm" :disabled="formLoading"> </el-button>
@ -118,6 +138,7 @@ export default {
updateRoleIds: null,
createRoleIds: null,
deleteRoleIds: null,
downloadRoleIds: null,
dictLabel: null,
},
formRules:{
@ -125,6 +146,7 @@ export default {
updateRoleIds: [{required: true, message: "修改权限不能为空", trigger: "blur"}],
deleteRoleIds: [{required: true, message: "删除权限不能为空", trigger: "blur"}],
createRoleIds: [{required: true, message: "新增权限不能为空", trigger: "blur"}],
downloadRoleIds: [{required: true, message: "下载权限不能为空", trigger: "blur"}],
dictLabel: [{required: true, message: "档案名称不能为空", trigger: "blur"}],
},
roleList: [],
@ -139,10 +161,11 @@ export default {
if (data.dataId) {
this.formData = {
...data,
queryRoleIds: data.queryRoleIds.split(",").map(item => parseInt(item)),
createRoleIds: data.createRoleIds.split(",").map(item => parseInt(item)),
updateRoleIds: data.updateRoleIds.split(",").map(item => parseInt(item)),
deleteRoleIds: data.deleteRoleIds.split(",").map(item => parseInt(item))
queryRoleIds: data.queryRoleIds ? data.queryRoleIds.split(",").map(item => parseInt(item)) : null,
createRoleIds: data.createRoleIds ? data.createRoleIds.split(",").map(item => parseInt(item)) : null,
updateRoleIds: data.updateRoleIds ? data.updateRoleIds.split(",").map(item => parseInt(item)) : null,
deleteRoleIds: data.deleteRoleIds ? data.deleteRoleIds.split(",").map(item => parseInt(item)) : null,
downloadRoleIds: data.downloadRoleIds ? data.downloadRoleIds.split(",").map(item => parseInt(item)) : null
}
}
await this.listRoles()
@ -165,8 +188,8 @@ export default {
updateRoleIds: this.formData.updateRoleIds.join(","),
deleteRoleIds: this.formData.deleteRoleIds.join(","),
createRoleIds: this.formData.createRoleIds.join(","),
downloadRoleIds: this.formData.deleteRoleIds.join(","),
}
console.log(data)
//
if (data.dataId) {
await updateArchivesRoleAndDict(data)
@ -193,6 +216,7 @@ export default {
updateRoleIds: null,
createRoleIds: null,
deleteRoleIds: null,
downloadRoleIds: null,
dictLabel: null,
}
this.resetForm('formRef')

View File

@ -0,0 +1,198 @@
<template>
<div class="app-container">
<el-dialog :title="dialogTitle" :visible.sync="dialogVisible" width="80%" v-dialogDrag append-to-body>
<el-form ref="formRef" :model="formData" :rules="formRules" v-loading="formLoading" label-width="145px">
<!-- 档案信息 -->
<el-card class="box-card">
<!-- 卡片头 -->
<div slot="header" class="clearfix">
<i class="el-icon-plus"/>
<span>档案信息</span>
</div>
<!-- 卡片内容 -->
<div>
<el-row :gutter="2">
<el-col :span="12">
<el-form-item label="档案名称" prop="archivesName">
<el-input v-model="formData.archivesName" placeholder="请输入档案名称"/>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="档案存放位置" prop="archivesPhysicsUrl">
<el-input v-model="formData.archivesPhysicsUrl" placeholder="请输入档案存放位置"/>
</el-form-item>
</el-col>
</el-row>
<el-row :gutter="2" v-if="activeTab === 'contract_type'">
<el-col :span="12">
<el-form-item label="签订日期" prop="signTime">
<el-date-picker clearable v-model="formData.signTime" type="date" value-format="yyyy-MM-dd"
placeholder="选择签订日期"
/>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="到期日期" prop="expireTime">
<el-date-picker clearable v-model="formData.expireTime" type="date" value-format="yyyy-MM-dd"
placeholder="到期日期"
/>
</el-form-item>
</el-col>
</el-row>
</div>
</el-card>
<!-- 档案内容 -->
<el-card class="box-card">
<!-- 卡片头 -->
<div slot="header" class="clearfix">
<i class="el-icon-plus"/>
<span>档案内容</span>
</div>
<!-- 卡片内容 -->
<div>
<el-form-item label="档案类型" prop="archivesType">
<el-radio-group v-model="formData.archivesType">
<el-radio-button
v-for="dict in this.getDictDatas(DICT_TYPE.ARCHIVES_ITEM_TYPE)"
:key="dict.value"
:label="dict.value"
>
{{ dict.label }}
</el-radio-button>
</el-radio-group>
</el-form-item>
<el-form-item label="文件上传" prop="archivesUrls">
<FileUpload ref="fileUpload" v-model="formData.archivesUrls" :limit="50" />
</el-form-item>
<el-form-item label="备注" prop="remark">
<el-input type="textarea" v-model="formData.remark" maxlength="200"
show-word-limit />
</el-form-item>
</div>
</el-card>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button type="primary" @click="submitForm" :disabled="formLoading"> </el-button>
<el-button @click="dialogVisible = false"> </el-button>
</div>
</el-dialog>
</div>
</template>
<script>
import {createHashCodeByStr} from '@/utils/createUniqueCode'
import {updateArchives} from '@/api/company/archives/archives'
export default {
name: 'ArchivesForm',
data() {
return {
dialogTitle: null,
dialogVisible: false,
// 12
formLoading: false,
//
formData: {
id: null,
archivesName: null,
archivesPhysicsUrl: null,
signTime: null,
expireTime: null,
archivesType: "01",
archivesUrls: null,
remark: null,
dataId: null,
archivesCode: null,
},
//
formRules: {
archivesName: [{required: true, message: "档案名称不能为空", trigger: "blur"}],
archivesPhysicsUrl: [{required: true, message: "档案存放地址不能为空", trigger: "blur"}],
signTime: [{required: true, message: "签订日期不能为空", trigger: "blur"}],
expireTime: [{required: true, message: "到期日期不能为空", trigger: "blur"}],
archivesUrls: [{required: true, message: "文件不能为空", trigger: 'blur'}]
},
activeItemType: "01",
activeTab: '',
}
},
methods: {
/** 打开弹窗 */
async open(data) {
this.reset()
//
if (data.id) {
this.formData = {
...data,
}
this.formData.archivesUrls = this.buildUrls(data.archivesUrls)
}
this.dialogTitle = data.id ? '修改档案' : '新增档案'
this.activeTab = data.activeTab
this.formData.dataId = data.dataId
this.dialogVisible = true
},
//
async submitForm() {
//
await this.$refs['formRef'].validate()
try {
this.formLoading = true
this.formData.archivesUrls = this.buildUrls(undefined)
this.formData.archivesCode = createHashCodeByStr(this.formData.archivesName)
const data = this.formData
//
if (data.id){
await updateArchives(data)
this.$modal.msgSuccess('修改成功')
this.dialogVisible = false
this.$emit('success')
return
}
//
await updateArchives(data)
this.$modal.msgSuccess('新增成功')
this.dialogVisible = false
this.$emit('success')
}finally {
this.formLoading = false
}
},
//
buildUrls(data){
if (data){
return data.split(",").map(item => {
return {
name: item.split("|")[1],
url: item.split("|")[0],
uid: item.split("|")[2],
status: item.split("|")[3]
}
})
}
return this.formData.archivesUrls.map(item => `${item.url}|${item.name}|${item.uid}|${item.status}`).join(",")
},
reset(){
this.formData = {
id: null,
archivesName: null,
archivesPhysicsUrl: null,
signTime: null,
expireTime: null,
archivesType: "01",
archivesUrls: null,
remark: null,
dataId: null,
archivesCode: null,
}
this.resetForm('formRef')
}
}
}
</script>
<style scoped>
.box-card {
margin-bottom: 10px;
}
</style>

View File

@ -0,0 +1,199 @@
<template>
<div class="app-container">
<el-dialog :title="dialogTitle" :visible.sync="dialogVisible" width="80%" v-dialogDrag append-to-body>
<el-form ref="formRef" :model="formData" v-loading="formLoading" label-width="145px">
<!-- 档案信息 -->
<el-card class="box-card">
<!-- 卡片头 -->
<div slot="header" class="clearfix">
<i class="el-icon-plus"/>
<span>档案信息</span>
</div>
<!-- 卡片内容 -->
<div>
<el-row :gutter="2">
<el-col :span="12">
<el-form-item label="档案名称" prop="archivesName">
<el-input disabled v-model="formData.archivesName" placeholder="请输入档案名称"/>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="档案存放位置" prop="archivesPhysicsUrl">
<el-input disabled v-model="formData.archivesPhysicsUrl" placeholder="请输入档案存放位置"/>
</el-form-item>
</el-col>
</el-row>
<el-row :gutter="2" v-if="activeTab === 'contract_type'">
<el-col :span="12">
<el-form-item label="签订日期" prop="signTime">
<el-date-picker disabled clearable v-model="formData.signTime" type="date" value-format="yyyy-MM-dd"
placeholder="选择签订日期"
/>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="到期日期" prop="expireTime">
<el-date-picker disabled clearable v-model="formData.expireTime" type="date" value-format="yyyy-MM-dd"
placeholder="到期日期"
/>
</el-form-item>
</el-col>
</el-row>
</div>
</el-card>
<!-- 档案内容 -->
<el-card class="box-card">
<!-- 卡片头 -->
<div slot="header" class="clearfix">
<i class="el-icon-plus"/>
<span>档案内容</span>
</div>
<!-- 卡片内容 -->
<div class="card-content" style="display: flex; flex-direction: column; align-items: center;">
<div v-for="(file, index) in formData.files" :key="index" class="file-item">
<!-- 文件名 -->
<div class="file-name" v-if="file.fileType !== 'file'">{{ file.fileName }}</div>
<!-- 根据文件类型渲染不同的内容 -->
<div v-if="file.fileType === 'image'" class="image-preview">
<el-image
style="max-width: 100%; max-height: 100%"
:src="file.fileUrl"
:preview-src-list="file.fileUrl">
</el-image>
</div>
<div v-else-if="file.fileType === 'video'" class="video-preview">
<video :src="file.fileUrl" controls style="max-width: 100%; max-height: 100%;"></video>
</div>
<div v-else-if="file.fileType === 'audio'" class="audio-preview">
<audio :src="file.fileUrl" controls style="max-width: 100%; max-height: 300px;"></audio>
</div>
<div v-else class="file-link">
<a :href="file.fileUrl" target="_blank">{{ file.fileName }}</a>
</div>
<hr/>
</div>
</div>
</el-card>
</el-form>
</el-dialog>
</div>
</template>
<script>
export default {
name: 'ArchivesShow',
data() {
return {
dialogTitle: null,
dialogVisible: false,
// 12
formLoading: false,
//
formData: {
files: [
{
fileName: null,
fileType: null,
fileUrl: null
}
]
},
activeTab: null,
//
fileTypeMap: {
//
jpg: 'image',
jpeg: 'image',
png: 'image',
gif: 'image',
bmp: 'image',
tif: 'image',
tiff: 'image',
svg: 'image',
webp: 'image',
//
mp4: 'video',
avi: 'video',
mkv: 'video',
mov: 'video',
flv: 'video',
wmv: 'video',
mpg: 'video',
mpeg: 'video',
m4v: 'video',
//
mp3: 'audio',
wav: 'audio',
aac: 'audio',
flac: 'audio',
ogg: 'audio',
m4a: 'audio',
//
default: 'file'
}
}
},
methods: {
/** 打开弹窗 */
async open(data) {
this.formData = {
...data,
files: this.buildFiles(data.archivesUrls)
}
this.activeTab = data.activeTab
this.dialogTitle = '查看档案'
this.dialogVisible = true
},
buildFiles(data) {
return data.split(',').map(item => {
return {
fileName: item.split('|')[1],
fileUrl: item.split('|')[0],
fileType: this.fileTypeMap[item.split('|')[1].split('.').pop().toLowerCase()] || this.fileTypeMap.default
}
})
}
}
}
</script>
<style scoped>
.box-card {
margin-bottom: 10px;
}
.card-content {
display: flex;
flex-direction: column;
align-items: center;
padding: 20px;
}
.file-item {
margin-bottom: 20px;
width: 100%;
text-align: center;
}
.file-name {
font-size: 16px;
margin-bottom: 10px;
color: #333;
}
.image-preview img,
.video-preview video,
.audio-preview audio {
max-width: 100%;
max-height: 300px;
}
.file-link {
text-align: center;
}
</style>