|
@@ -0,0 +1,191 @@
|
|
|
+<!--文件上传组件-->
|
|
|
+<template>
|
|
|
+ <div>
|
|
|
+ <el-divider content-position="left"><i class="el-icon-document"></i> 附件</el-divider>
|
|
|
+ <el-upload ref="upload" style="display: inline-block; :show-header='status'" action=""
|
|
|
+ :limit="999" :http-request="httpRequest"
|
|
|
+ multiple
|
|
|
+ :on-exceed="(files, fileList) =>{
|
|
|
+ $message.warning(`当前限制选择 999 个文件,本次选择了 ${files.length} 个文件,共选择了 ${files.length + fileList.length} 个文件`)
|
|
|
+ }"
|
|
|
+ :show-file-list="false"
|
|
|
+ :on-change="changes"
|
|
|
+ :on-progress="uploadVideoProcess"
|
|
|
+ :file-list="fileList">
|
|
|
+ <el-button type="info" size="mini" >点击上传</el-button>
|
|
|
+ </el-upload>
|
|
|
+ <div style="height: calc(100% - 80px);margin-top: 10px">
|
|
|
+ <!-- 进度条 -->
|
|
|
+ <el-progress style="margin-left: 5em" v-if="progressFlag" :percentage="loadProgress"></el-progress>
|
|
|
+ <vxe-table
|
|
|
+ border="inner"
|
|
|
+ auto-resize
|
|
|
+ resizable
|
|
|
+ :loading="loading"
|
|
|
+ size="small"
|
|
|
+ ref="uploadTable"
|
|
|
+ show-header-overflow
|
|
|
+ show-overflow
|
|
|
+ highlight-hover-row
|
|
|
+ :menu-config="{}"
|
|
|
+ :print-config="{}"
|
|
|
+ :sort-config="{remote:true}"
|
|
|
+ :data="dataListNew"
|
|
|
+ :checkbox-config="{}">
|
|
|
+ <vxe-column type="seq" width="40"></vxe-column>
|
|
|
+ <vxe-column title="文件名称" field="name">
|
|
|
+ <template slot-scope="scope">
|
|
|
+ <!-- <div v-if="ifName(scope.row) === true">-->
|
|
|
+ <!-- <el-image-->
|
|
|
+ <!-- style="width: 100px; height: 100px"-->
|
|
|
+ <!-- :src="src"-->
|
|
|
+ <!-- :preview-src-list="srcList" lazy>-->
|
|
|
+ <!-- </el-image>-->
|
|
|
+ <!-- </div>-->
|
|
|
+ <!-- <div v-else>-->
|
|
|
+ <!-- <el-link type="primary" :underline="false" @click="showFile(scope.row)">{{scope.row.name}}</el-link>-->
|
|
|
+ <!-- </div>-->
|
|
|
+ <el-link type="primary" :underline="false" @click="showFile(scope.row)">{{scope.row.name}}</el-link>
|
|
|
+ </template>
|
|
|
+ </vxe-column>
|
|
|
+ <vxe-column title="创建人" field="createBy.name"></vxe-column>
|
|
|
+ <vxe-column title="创建时间" field="createDate"></vxe-column>
|
|
|
+ <vxe-column title="操作" width="200px" fixed="right" align="center">
|
|
|
+ <template slot-scope="scope">
|
|
|
+ <el-button type="text" icon="el-icon-edit" size="small" @click="toHref(scope.row)" :disabled="false">下载</el-button>
|
|
|
+ <el-button type="text" icon="el-icon-delete" size="small" @click="deleteById(scope.row, scope.$rowIndex)">删除</el-button>
|
|
|
+ </template>
|
|
|
+ </vxe-column>
|
|
|
+ </vxe-table>
|
|
|
+ </div>
|
|
|
+ <el-image-viewer v-if="showViewer" :on-close="closeViewer" :url-list="[url]" :zIndex=9999></el-image-viewer>
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script>
|
|
|
+ // eslint-disable-next-line no-unused-vars
|
|
|
+ import OSSSerivce, {
|
|
|
+ httpRequest,
|
|
|
+ // eslint-disable-next-line no-unused-vars
|
|
|
+ handleRemove,
|
|
|
+ fileName,
|
|
|
+ // eslint-disable-next-line no-unused-vars
|
|
|
+ beforeAvatarUpload,
|
|
|
+ // eslint-disable-next-line no-unused-vars
|
|
|
+ openWindowOnUrl,
|
|
|
+ // eslint-disable-next-line no-unused-vars
|
|
|
+ toHref
|
|
|
+ } from '@/api/sys/OSSService'
|
|
|
+ import ElImageViewer from 'element-ui/packages/image/src/image-viewer'
|
|
|
+ import moment from 'moment'
|
|
|
+ export default {
|
|
|
+ data () {
|
|
|
+ return {
|
|
|
+ loading: false,
|
|
|
+ progressFlag: false,
|
|
|
+ loadProgress: 0,
|
|
|
+ fileList: [],
|
|
|
+ dataList: [],
|
|
|
+ dataListNew: [],
|
|
|
+ url: '',
|
|
|
+ showViewer: false,
|
|
|
+ ossService: null,
|
|
|
+ auth: ''
|
|
|
+ }
|
|
|
+ },
|
|
|
+ watch: {
|
|
|
+ },
|
|
|
+ created () {
|
|
|
+ this.ossService = new OSSSerivce()
|
|
|
+ },
|
|
|
+ components: {
|
|
|
+ ElImageViewer
|
|
|
+ },
|
|
|
+ mounted () {
|
|
|
+ window.onPreview = this.onPreview
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ newUpload (method, fileList) {
|
|
|
+ this.auth = method
|
|
|
+ this.dataList = JSON.parse(JSON.stringify(fileList))
|
|
|
+ this.dataListNew = JSON.parse(JSON.stringify(fileList))
|
|
|
+ },
|
|
|
+ async httpRequest (file) {
|
|
|
+ await httpRequest(file, fileName(file), 'projectRecords')
|
|
|
+ },
|
|
|
+ uploadVideoProcess (event, file, fileList) {
|
|
|
+ this.progressFlag = true // 显示进度条
|
|
|
+ this.loadProgress = parseInt(event.percent) // 动态获取文件上传进度
|
|
|
+ if (this.loadProgress >= 100) {
|
|
|
+ this.loadProgress = 100
|
|
|
+ setTimeout(() => { this.progressFlag = false }, 1000) // 一秒后关闭进度条
|
|
|
+ }
|
|
|
+ },
|
|
|
+ changes (file, fileList) {
|
|
|
+ this.dataListNew = []
|
|
|
+ this.dataList.forEach((item) => {
|
|
|
+ this.dataListNew.push(item)
|
|
|
+ })
|
|
|
+ fileList.forEach((item) => {
|
|
|
+ item.createDate = moment(new Date()).format('YYYY-MM-DD HH:mm:ss')
|
|
|
+ item.createBy = {
|
|
|
+ id: '',
|
|
|
+ name: ''
|
|
|
+ }
|
|
|
+ item.createBy.id = this.$store.state.user.id
|
|
|
+ item.createBy.name = this.$store.state.user.name
|
|
|
+ this.dataListNew.push(item)
|
|
|
+ })
|
|
|
+ this.dataListNew.forEach(item => {
|
|
|
+ if (item.raw !== undefined && item.raw !== null && item.raw !== {}) {
|
|
|
+ item.url = item.raw.url
|
|
|
+ }
|
|
|
+ })
|
|
|
+ beforeAvatarUpload(file)
|
|
|
+ },
|
|
|
+ showFile (row) {
|
|
|
+ openWindowOnUrl(row)
|
|
|
+ },
|
|
|
+ onPreview (url) {
|
|
|
+ this.url = url
|
|
|
+ this.showViewer = true
|
|
|
+ },
|
|
|
+ // 关闭查看器
|
|
|
+ closeViewer () {
|
|
|
+ this.url = ''
|
|
|
+ this.showViewer = false
|
|
|
+ },
|
|
|
+ toHref (row) {
|
|
|
+ toHref(row)
|
|
|
+ },
|
|
|
+ deleteById (row, index) {
|
|
|
+ this.dataListNew.splice(index, 1)
|
|
|
+ if (row.id !== null && row.id !== '' && row.id !== undefined) {
|
|
|
+ this.dataList.splice(index, 1)
|
|
|
+ // this.ossService.deleteMsgById(row.id)
|
|
|
+ } else {
|
|
|
+ let num
|
|
|
+ if (this.dataList.length > 0) {
|
|
|
+ num = this.dataList.length - 1
|
|
|
+ } else {
|
|
|
+ num = 0
|
|
|
+ }
|
|
|
+ this.$refs.upload.uploadFiles.splice(index - num, 1)
|
|
|
+ }
|
|
|
+ },
|
|
|
+ clearUpload () {
|
|
|
+ this.$refs.upload.uploadFiles = []
|
|
|
+ },
|
|
|
+ getDataList () {
|
|
|
+ return this.dataListNew
|
|
|
+ },
|
|
|
+ checkProgress () {
|
|
|
+ if (this.progressFlag === true) {
|
|
|
+ this.$message.warning('请等待文件上传完成再进行提交')
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+</script>
|