<template>
|
<a-card
|
:bordered="false"
|
title="模板管理"
|
>
|
<!-- 查询区域 -->
|
<div class="table-page-search-wrapper">
|
<a-form
|
layout="inline"
|
@keyup.enter.native="searchQuery"
|
>
|
<a-row :gutter="24">
|
<a-col
|
:md="6"
|
:sm="8"
|
>
|
<a-form-item label="名称">
|
<j-input
|
placeholder="请输入名称检索"
|
v-model="queryParam.name"
|
></j-input>
|
</a-form-item>
|
</a-col>
|
</a-row>
|
</a-form>
|
</div>
|
|
<!-- 操作按钮区域 -->
|
<div class="table-operator">
|
<a-button
|
type="primary"
|
@click="searchQuery"
|
icon="search"
|
>查询</a-button>
|
<a-button
|
@click="searchReset"
|
icon="reload"
|
>重置</a-button>
|
<a-button
|
@click="handleAdd"
|
type="primary"
|
icon="upload"
|
>标准模板上传</a-button>
|
<a-dropdown v-if="selectedRowKeys.length > 0">
|
<a-menu slot="overlay">
|
<a-menu-item
|
key="1"
|
@click="batchDel"
|
>
|
<a-icon type="delete" />删除
|
</a-menu-item>
|
</a-menu>
|
<a-button style="margin-left: 8px">
|
批量操作
|
<a-icon type="down" />
|
</a-button>
|
</a-dropdown>
|
</div>
|
|
<!-- table区域-begin -->
|
<div>
|
<div
|
class="ant-alert ant-alert-info"
|
style="margin-bottom: 16px"
|
>
|
<i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择
|
<a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
|
<a
|
style="margin-left: 24px"
|
@click="onClearSelected"
|
>清空</a>
|
</div>
|
|
<a-table
|
ref="table"
|
size="middle"
|
bordered
|
rowKey="id"
|
:columns="columns"
|
:dataSource="dataSource"
|
:pagination="ipagination"
|
:loading="loading"
|
:rowSelection="{
|
selectedRowKeys: selectedRowKeys,
|
onChange: onSelectChange,
|
getCheckboxProps: getCheckboxProps,
|
}"
|
@change="handleTableChange"
|
>
|
<!--字符串超长截取省略号显示-->
|
<span
|
slot="description"
|
slot-scope="text"
|
>
|
<j-ellipsis
|
:value="text"
|
:length="20"
|
/>
|
</span>
|
|
<span
|
slot="size"
|
slot-scope="text"
|
class="error"
|
>
|
{{ sizeConvert(text) }}
|
</span>
|
|
<span
|
slot="format"
|
slot-scope="text"
|
class="success"
|
>
|
<a-icon
|
v-if="text == 'pdf'"
|
type="file-pdf"
|
/>
|
<a-icon
|
v-else-if="text == 'xls' || text == 'xlsx'"
|
type="file-excel"
|
/>
|
<a-icon
|
v-else-if="text == 'doc' || text == 'docx'"
|
type="file-word"
|
/>
|
<a-icon
|
v-else-if="
|
text == 'jpg' ||
|
text == 'bmp' ||
|
text == 'gif' ||
|
text == 'png' ||
|
text == 'jpeg' ||
|
text == 'tiff' ||
|
text == 'psd' ||
|
text == 'raw' ||
|
text == 'tif' ||
|
text == 'pcx' ||
|
text == 'tga' ||
|
text == 'exif' ||
|
text == 'fpx' ||
|
text == 'svg' ||
|
text == 'cdr' ||
|
text == 'pcd' ||
|
text == 'dxf' ||
|
text == 'ufo' ||
|
text == 'eps'
|
"
|
type="file-image"
|
/>
|
<a-icon
|
v-else-if="text == 'ppt'"
|
type="file-ppt"
|
/>
|
<a-icon
|
v-else-if="text == 'text'"
|
type="file-text"
|
/>
|
<a-icon
|
v-else-if="text == 'zip' || text == 'rar'"
|
type="file-zip"
|
/>
|
<a-icon
|
v-else
|
type="file-unknown"
|
/>
|
{{ text }}
|
</span>
|
|
<span
|
slot="action"
|
slot-scope="text, record"
|
>
|
<Tooltip
|
placement="top"
|
title="预览图片"
|
>
|
<img
|
v-if="
|
record.path && (record.format.toLowerCase()=='jpg'||record.format.toLowerCase()=='bmp'||record.format.toLowerCase()=='png'||record.format.toLowerCase()=='jpeg'||record.format.toLowerCase()=='gif')
|
"
|
width="30"
|
height="14"
|
border="1"
|
draggable="false"
|
:preview="record.id"
|
:preview-text="record.name"
|
:src="record.src"
|
/>
|
</Tooltip>
|
<!-- :src="'http://127.0.0.1:8090/mes/sys/common/static//2022-03/30/051ce6948b96dc2eed0d66a838eb443e468b1990919a8fafd9f145869f587c38'" -->
|
|
<a
|
v-if="record.path && record.format.toLowerCase() == 'pdf'"
|
href="javascript:;"
|
@click="view(record)"
|
>
|
预览
|
</a>
|
|
<a-divider
|
v-if="
|
record.path &&
|
(record.format.toLowerCase() == 'jpg' ||
|
record.format.toLowerCase() == 'bmp' ||
|
record.format.toLowerCase() == 'png' ||
|
record.format.toLowerCase() == 'jpeg' ||
|
record.format.toLowerCase() == 'gif' ||
|
record.format.toLowerCase() == 'pdf')
|
"
|
type="vertical"
|
/>
|
|
<a
|
href="javascript:;"
|
@click="handleDownload(record)"
|
>下载</a>
|
|
<a-divider type="vertical" />
|
<a-popconfirm
|
title="确定删除吗?"
|
@confirm="() => handleDelete(record.id)"
|
>
|
<a :disabled="record.uploadRelaCount != 0">删除</a>
|
</a-popconfirm>
|
</span>
|
</a-table>
|
</div>
|
<!-- table区域-end -->
|
<pdf-view ref="pdfview"></pdf-view>
|
<!-- 表单区域 -->
|
<upload-model
|
ref="modalForm"
|
@ok="modalFormOk"
|
></upload-model>
|
</a-card>
|
</template>
|
|
<script>
|
import UploadModel from './modules/uploadModel/UploadModel'
|
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
|
import JDictSelectTag from '@/components/dict/JDictSelectTag'
|
import JSearchSelectTag from '@/components/dict/JSearchSelectTag'
|
import { initDictOptions, filterDictText } from '@/components/dict/JDictSelectUtil'
|
import { getAction, requestPut, downFile, getFileAccessHttpUrl } from '@/api/manage'
|
import JInput from '@/components/jeecg/JInput'
|
import JEllipsis from '@/components/jeecg/JEllipsis'
|
import Tooltip from 'ant-design-vue/es/tooltip'
|
|
import { preview } from 'vue-photo-preview'
|
import { ACCESS_TOKEN } from '@/store/mutation-types'
|
import Vue from 'vue'
|
import PdfView from '../common/PdfView' //PDF预览
|
|
export default {
|
name: 'UploadList',
|
mixins: [JeecgListMixin],
|
components: {
|
UploadModel,
|
JDictSelectTag,
|
JInput,
|
JEllipsis,
|
JSearchSelectTag,
|
Tooltip,
|
PdfView,
|
preview,
|
},
|
data() {
|
return {
|
columns: [
|
{
|
title: '#',
|
dataIndex: '',
|
key: 'rowIndex',
|
width: 50,
|
align: 'center',
|
customRender: function (t, r, index) {
|
return parseInt(index) + 1
|
},
|
},
|
{
|
title: '名称',
|
align: 'center',
|
dataIndex: 'name',
|
sorter: true,
|
},
|
{
|
title: '格式',
|
align: 'center',
|
dataIndex: 'format',
|
scopedSlots: { customRender: 'format' },
|
sorter: true,
|
},
|
{
|
title: '大小',
|
align: 'center',
|
dataIndex: 'size',
|
scopedSlots: { customRender: 'size' },
|
sorter: true,
|
},
|
{
|
title: '描述',
|
align: 'center',
|
dataIndex: 'description',
|
scopedSlots: { customRender: 'description' },
|
sorter: true,
|
},
|
{
|
title: '上传人',
|
align: 'center',
|
dataIndex: 'createBy',
|
sorter: true,
|
},
|
{
|
title: '上传时间',
|
align: 'center',
|
dataIndex: 'createTime',
|
sorter: true,
|
},
|
|
{
|
width: 150,
|
title: '操作',
|
dataIndex: 'action',
|
align: 'center',
|
scopedSlots: { customRender: 'action' },
|
},
|
],
|
url: {
|
list: '/sys/upload/listByType',
|
uploadRelaListByUploadId: '/sys/uploadRela/listByUploadId',
|
delete: '/sys/upload/delete',
|
deleteBatch: '/sys/upload/deleteBatch',
|
urlDownload: '/sys/common/static',
|
download: '/sys/upload/downloadFile',
|
// download: '/sys/upload/downloadFileByType',
|
realityUrl: 'sys/upload/realityUrl',
|
},
|
path: '',
|
}
|
},
|
methods: {
|
getCheckboxProps(record) {
|
return {
|
props: {
|
disabled: record.uploadRelaCount != 0,
|
},
|
}
|
},
|
view(record) {
|
// let realPath;
|
// //获取当前文件真实路径
|
// getAction(this.url.realityUrl, { id: record.id }).then((res) => {
|
// if (res.success) {
|
// let path = res.message;
|
// console.log("获取后台路径path---------------->" + path);
|
// realPath = this.url.urlDownload + '/' + path;
|
// }
|
// }).then(() => {
|
// this.$refs.pdfview.showPdf(realPath);
|
// })
|
// this.$refs.pdfview.showPdf('http://127.0.0.1:8090/mes/sys/common/static//2022-03/30/8bc6d02e2421bf94ff73afedc422cf42b9f8c868c8dbb0689f598e87902ed2fd')
|
this.$refs.pdfview.showPdf(record.src);
|
},
|
loadData(arg) {
|
if (arg === 1) {
|
this.ipagination.current = 1
|
}
|
|
var params = this.getQueryParams() //查询条件
|
this.loading = true
|
getAction(this.url.list, params).then((res) => {
|
if (res.success) {
|
for (let i = 0; i < res.result.records.length; i++) {
|
let r = res.result.records[i]
|
r.src = this.getSrc(res.result.records[i])
|
}
|
this.dataSource = res.result.records
|
console.log('dataSource', this.dataSource);
|
this.ipagination.total = res.result.total
|
}
|
this.loading = false
|
})
|
},
|
//拼装src
|
getSrc(record) {
|
if (!record.path) {
|
return ''
|
}
|
//本地:local\Minio:minio\阿里云:alioss
|
if (record.uploadType == 'local') {
|
//根据发布状态修改https 或 http
|
// return getFileAccessHttpUrl(record.path + record.encodeName, this.url.urlDownload, window._CONFIG['hyperTextTransfer'])
|
return window._CONFIG['domianURL'] + this.url.urlDownload + "/" + record.path + record.encodeName;
|
// return window._CONFIG['domianURL'] + this.url.urlDownload + "/" + record.path + record.encodeName;
|
} else if (record.uploadType == 'alioss') {
|
const OSS = require('ali-oss')
|
const client = new OSS({
|
// region以杭州为例(oss-cn-hangzhou),其他region按实际情况填写。
|
region: window._CONFIG['region'],
|
// 阿里云主账号AccessKey拥有所有API的访问权限,风险很高。强烈建议您创建并使用RAM账号进行API访问或日常运维,请登录RAM控制台创建RAM账号。
|
accessKeyId: window._CONFIG['accessKeyId'],
|
accessKeySecret: window._CONFIG['accessKeySecret'],
|
bucket: window._CONFIG['bucket'],
|
})
|
// object-key表示从OSS下载文件时需要指定包含文件后缀在内的完整路径,例如abc/efg/123.jpg。
|
return client.signatureUrl(record.path)
|
}
|
},
|
handleDownload(record) {
|
downFile(this.url.download, { id: record.id }).then((res) => {
|
if (!res) {
|
this.$message.warning('文件下载失败')
|
return
|
} else {
|
let fileName = record.name
|
if (typeof window.navigator.msSaveBlob !== 'undefined') {
|
window.navigator.msSaveBlob(new Blob([res]), fileName)
|
} else {
|
let url = window.URL.createObjectURL(new Blob([res]))
|
let link = document.createElement('a')
|
link.style.display = 'none'
|
link.href = url
|
link.setAttribute('download', fileName)
|
document.body.appendChild(link)
|
link.click()
|
document.body.removeChild(link) //下载完成移除元素
|
window.URL.revokeObjectURL(url) //释放掉blob对象
|
}
|
}
|
})
|
},
|
sizeConvert(limit) {
|
var size = ''
|
if (limit < 0.1 * 1024) {
|
size = parseFloat(limit).toFixed(2) + 'B' //小于0.1KB,则转化成B
|
} else if (limit < 0.1 * 1024 * 1024) {
|
size = (parseFloat(limit) / 1024).toFixed(2) + 'KB' //小于0.1MB,则转化成KB
|
} else if (limit < 0.1 * 1024 * 1024 * 1024) {
|
size = (parseFloat(limit) / (1024 * 1024)).toFixed(2) + 'MB' //小于0.1GB,则转化成MB
|
} else {
|
size = (parseFloat(limit) / (1024 * 1024 * 1024)).toFixed(2) + 'GB' //其他转化成GB
|
}
|
var sizeStr = size + '' //转成字符串
|
var index = sizeStr.indexOf('.') //获取小数点处的索引
|
var dou = sizeStr.substr(index + 1, 2) //获取小数点后两位的值
|
if (dou == '00') {
|
//判断后两位是否为00,如果是则删除00
|
return sizeStr.substring(0, index) + sizeStr.substr(index + 3, 2)
|
}
|
return size
|
},
|
handleAdd: function () {
|
this.$refs.modalForm.add()
|
this.$refs.modalForm.title = '文件上传'
|
this.$refs.modalForm.disableSubmit = false
|
},
|
},
|
computed: {
|
importExcelUrl: function () {
|
console.log('请求地址为::', `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`)
|
return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
|
},
|
},
|
mounted() {
|
this.$previewRefresh()
|
this.$preview.on('close', () => {
|
this.isShow = false
|
})
|
},
|
}
|
</script>
|
<style>
|
@import '~@assets/less/common.less';
|
.frozenRowClass {
|
color: #c9c9c9;
|
}
|
.success {
|
color: green;
|
}
|
.error {
|
color: red;
|
}
|
.fontweight {
|
font-weight: bold;
|
}
|
</style>
|