2019-10-20 11:42:56 +08:00
|
|
|
|
<template>
|
2019-12-27 16:28:41 +08:00
|
|
|
|
<div v-loading.fullscreen.lock="fullscreenLoading">
|
2020-02-03 10:58:29 +08:00
|
|
|
|
<div class="upload">
|
2019-10-26 23:25:43 +08:00
|
|
|
|
<el-upload
|
2019-12-15 15:10:40 +08:00
|
|
|
|
:action="`${path}/fileUploadAndDownload/upload`"
|
2019-10-26 23:25:43 +08:00
|
|
|
|
:before-upload="checkFile"
|
2019-11-24 11:13:55 +08:00
|
|
|
|
:headers="{'x-token':token}"
|
2019-10-26 23:25:43 +08:00
|
|
|
|
:on-error="uploadError"
|
|
|
|
|
:on-success="uploadSuccess"
|
2019-11-24 11:13:55 +08:00
|
|
|
|
:show-file-list="false"
|
2019-10-26 23:25:43 +08:00
|
|
|
|
>
|
|
|
|
|
<el-button size="small" type="primary">点击上传</el-button>
|
|
|
|
|
<div class="el-upload__tip" slot="tip">只能上传jpg/png文件,且不超过500kb</div>
|
|
|
|
|
</el-upload>
|
|
|
|
|
<el-table :data="tableData" border stripe>
|
|
|
|
|
<el-table-column label="预览" width="100">
|
|
|
|
|
<template slot-scope="scope">
|
|
|
|
|
<img :alt="scope.row.alt" :src="scope.row.url" height="80" width="80" />
|
|
|
|
|
</template>
|
|
|
|
|
</el-table-column>
|
2019-11-24 11:13:55 +08:00
|
|
|
|
<el-table-column label="日期" prop="UpdatedAt" width="180">
|
|
|
|
|
<template slot-scope="scope">
|
2019-12-12 17:17:27 +08:00
|
|
|
|
<div>{{scope.row.UpdatedAt|formatDate}}</div>
|
2019-11-24 11:13:55 +08:00
|
|
|
|
</template>
|
|
|
|
|
</el-table-column>
|
2019-10-26 23:25:43 +08:00
|
|
|
|
<el-table-column label="文件名" prop="name" width="180"></el-table-column>
|
|
|
|
|
<el-table-column label="链接" prop="url"></el-table-column>
|
|
|
|
|
<el-table-column label="标签" prop="tag" width="100">
|
|
|
|
|
<template slot-scope="scope">
|
|
|
|
|
<el-tag
|
|
|
|
|
:type="scope.row.tag === 'jpg' ? 'primary' : 'success'"
|
|
|
|
|
disable-transitions
|
|
|
|
|
>{{scope.row.tag}}</el-tag>
|
|
|
|
|
</template>
|
|
|
|
|
</el-table-column>
|
|
|
|
|
<el-table-column label="操作" width="100">
|
|
|
|
|
<template slot-scope="scope">
|
|
|
|
|
<el-button @click="downloadFile(scope.row)" size="small" type="text">下载</el-button>
|
2019-11-24 11:13:55 +08:00
|
|
|
|
<el-button @click="deleteFile(scope.row)" size="small" type="text">删除</el-button>
|
2019-10-26 23:25:43 +08:00
|
|
|
|
</template>
|
|
|
|
|
</el-table-column>
|
|
|
|
|
</el-table>
|
|
|
|
|
<el-pagination
|
|
|
|
|
:current-page="page"
|
|
|
|
|
:page-size="pageSize"
|
|
|
|
|
:page-sizes="[10, 30, 50, 100]"
|
|
|
|
|
:style="{float:'right',padding:'20px'}"
|
|
|
|
|
:total="total"
|
|
|
|
|
@current-change="handleCurrentChange"
|
|
|
|
|
@size-change="handleSizeChange"
|
|
|
|
|
layout="total, sizes, prev, pager, next, jumper"
|
|
|
|
|
></el-pagination>
|
2020-02-03 10:58:29 +08:00
|
|
|
|
</div>
|
2019-10-25 17:34:36 +08:00
|
|
|
|
</div>
|
2019-10-20 11:42:56 +08:00
|
|
|
|
</template>
|
2019-10-25 17:34:36 +08:00
|
|
|
|
|
2019-10-20 11:42:56 +08:00
|
|
|
|
<script>
|
2019-12-15 15:10:40 +08:00
|
|
|
|
const path = process.env.VUE_APP_BASE_API
|
2019-10-25 17:34:36 +08:00
|
|
|
|
import { mapGetters } from 'vuex'
|
|
|
|
|
import infoList from '@/components/mixins/infoList'
|
2019-11-24 11:13:55 +08:00
|
|
|
|
import { getFileList, deleteFile } from '@/api/fileUploadAndDownload'
|
2019-10-26 23:25:43 +08:00
|
|
|
|
import { downloadImage } from '@/utils/downloadImg'
|
2019-11-24 11:13:55 +08:00
|
|
|
|
import { formatTimeToStr } from '@/utils/data'
|
2019-10-20 11:42:56 +08:00
|
|
|
|
export default {
|
2019-10-25 17:34:36 +08:00
|
|
|
|
name: 'Upload',
|
|
|
|
|
mixins: [infoList],
|
|
|
|
|
data() {
|
|
|
|
|
return {
|
2019-12-27 16:28:41 +08:00
|
|
|
|
fullscreenLoading:false,
|
2019-10-26 23:25:43 +08:00
|
|
|
|
listApi: getFileList,
|
|
|
|
|
listKey: 'list',
|
2019-12-15 15:10:40 +08:00
|
|
|
|
path: path,
|
2019-10-25 17:34:36 +08:00
|
|
|
|
tableData: [
|
|
|
|
|
{
|
2019-10-26 23:25:43 +08:00
|
|
|
|
UpdatedAt: '2019-10-25',
|
2019-10-25 17:34:36 +08:00
|
|
|
|
name: '文件名.jpg',
|
|
|
|
|
url: 'http://qmplusimg.henrongyi.top/1571321688timg.jpg',
|
|
|
|
|
tag: 'jpg'
|
|
|
|
|
},
|
|
|
|
|
{
|
2019-10-26 23:25:43 +08:00
|
|
|
|
UpdatedAt: '2019-10-25',
|
2019-10-25 17:34:36 +08:00
|
|
|
|
name: '文件名.jpg',
|
|
|
|
|
url: 'http://qmplusimg.henrongyi.top/157162774820191015140921496.gif',
|
|
|
|
|
tag: 'gif'
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
computed: {
|
|
|
|
|
...mapGetters('user', ['userInfo', 'token'])
|
|
|
|
|
},
|
2019-11-24 11:13:55 +08:00
|
|
|
|
filters: {
|
|
|
|
|
formatDate: function(time) {
|
|
|
|
|
if (time != null && time != '') {
|
|
|
|
|
var date = new Date(time)
|
|
|
|
|
return formatTimeToStr(date, 'yyyy-MM-dd hh:mm:ss')
|
|
|
|
|
} else {
|
|
|
|
|
return ''
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
2019-10-25 17:34:36 +08:00
|
|
|
|
methods: {
|
2019-11-24 11:13:55 +08:00
|
|
|
|
async deleteFile(row) {
|
2019-12-15 15:10:40 +08:00
|
|
|
|
this.$confirm('此操作将永久文件, 是否继续?', '提示', {
|
2019-11-24 11:13:55 +08:00
|
|
|
|
confirmButtonText: '确定',
|
|
|
|
|
cancelButtonText: '取消',
|
|
|
|
|
type: 'warning'
|
|
|
|
|
})
|
|
|
|
|
.then(async () => {
|
|
|
|
|
const res = await deleteFile(row)
|
|
|
|
|
if (res.success) {
|
|
|
|
|
this.$message({
|
|
|
|
|
type: 'success',
|
|
|
|
|
message: '删除成功!'
|
|
|
|
|
})
|
|
|
|
|
this.getTableData()
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.catch(() => {
|
|
|
|
|
this.$message({
|
|
|
|
|
type: 'info',
|
|
|
|
|
message: '已取消删除'
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
},
|
2019-10-25 17:34:36 +08:00
|
|
|
|
checkFile(file) {
|
2019-12-27 16:28:41 +08:00
|
|
|
|
this.fullscreenLoading = true
|
2019-10-25 17:34:36 +08:00
|
|
|
|
const isJPG = file.type === 'image/jpeg'
|
2019-10-26 23:25:43 +08:00
|
|
|
|
const isPng = file.type === 'image/png'
|
2019-10-25 17:34:36 +08:00
|
|
|
|
const isLt2M = file.size / 1024 / 1024 < 2
|
2019-11-24 11:13:55 +08:00
|
|
|
|
if (!isJPG && !isPng) {
|
2019-10-26 23:25:43 +08:00
|
|
|
|
this.$message.error('上传头像图片只能是 JPG或png 格式!')
|
2019-12-27 16:28:41 +08:00
|
|
|
|
this.fullscreenLoading = false
|
2019-10-25 17:34:36 +08:00
|
|
|
|
}
|
|
|
|
|
if (!isLt2M) {
|
|
|
|
|
this.$message.error('上传头像图片大小不能超过 2MB!')
|
2019-12-27 16:28:41 +08:00
|
|
|
|
this.fullscreenLoading = false
|
2019-10-25 17:34:36 +08:00
|
|
|
|
}
|
2019-10-26 23:25:43 +08:00
|
|
|
|
return (isPng || isJPG) && isLt2M
|
2019-10-25 17:34:36 +08:00
|
|
|
|
},
|
2019-10-30 17:21:11 +08:00
|
|
|
|
uploadSuccess(res) {
|
2019-10-26 23:25:43 +08:00
|
|
|
|
this.$message({
|
|
|
|
|
type: 'success',
|
|
|
|
|
message: '上传成功'
|
|
|
|
|
})
|
2019-11-24 11:13:55 +08:00
|
|
|
|
if (res.success) {
|
2019-10-30 17:21:11 +08:00
|
|
|
|
this.getTableData()
|
|
|
|
|
}
|
2019-12-27 16:28:41 +08:00
|
|
|
|
this.fullscreenLoading = false
|
2019-10-26 23:25:43 +08:00
|
|
|
|
},
|
2019-10-30 17:21:11 +08:00
|
|
|
|
uploadError() {
|
2019-10-26 23:25:43 +08:00
|
|
|
|
this.$message({
|
|
|
|
|
type: 'error',
|
|
|
|
|
message: '上传失败'
|
|
|
|
|
})
|
2019-12-27 16:28:41 +08:00
|
|
|
|
this.fullscreenLoading = false
|
|
|
|
|
|
2019-10-26 23:25:43 +08:00
|
|
|
|
},
|
|
|
|
|
downloadFile(row) {
|
|
|
|
|
downloadImage(row.url, row.name)
|
2019-10-25 17:34:36 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2019-10-20 11:42:56 +08:00
|
|
|
|
}
|
|
|
|
|
</script>
|