2019-11-19 13:44:19 +08:00
|
|
|
|
<template>
|
|
|
|
|
<div class="app-container" style="padding: 8px;">
|
|
|
|
|
<!--表单组件-->
|
2020-01-07 23:32:27 +08:00
|
|
|
|
<eForm ref="form" />
|
2019-11-19 13:44:19 +08:00
|
|
|
|
<!-- 工具栏 -->
|
|
|
|
|
<div class="head-container">
|
2020-01-07 23:32:27 +08:00
|
|
|
|
<div v-if="crud.props.searchToggle">
|
|
|
|
|
<!-- 搜索 -->
|
|
|
|
|
<el-input v-model="query.key" clearable size="small" placeholder="输入文件名称搜索" style="width: 200px;" class="filter-item" @keyup.enter.native="toQuery" />
|
|
|
|
|
<el-date-picker
|
|
|
|
|
v-model="query.c"
|
|
|
|
|
:default-time="['00:00:00','23:59:59']"
|
|
|
|
|
type="daterange"
|
|
|
|
|
range-separator=":"
|
|
|
|
|
size="small"
|
|
|
|
|
class="date-item"
|
|
|
|
|
value-format="yyyy-MM-dd HH:mm:ss"
|
|
|
|
|
start-placeholder="开始日期"
|
|
|
|
|
end-placeholder="结束日期"
|
|
|
|
|
/>
|
|
|
|
|
<rrOperation :crud="crud" />
|
2019-11-19 13:44:19 +08:00
|
|
|
|
</div>
|
2020-01-07 23:32:27 +08:00
|
|
|
|
<crudOperation :permission="permission">
|
|
|
|
|
<template slot="left">
|
|
|
|
|
<!-- 上传 -->
|
|
|
|
|
<el-button class="filter-item" size="mini" type="primary" icon="el-icon-upload" @click="dialog = true">上传</el-button>
|
|
|
|
|
<!-- 同步 -->
|
|
|
|
|
<el-button :icon="icon" class="filter-item" size="mini" type="warning" @click="synchronize">同步</el-button>
|
|
|
|
|
<!-- 配置 -->
|
|
|
|
|
<el-button
|
|
|
|
|
class="filter-item"
|
|
|
|
|
size="mini"
|
|
|
|
|
type="success"
|
|
|
|
|
icon="el-icon-s-tools"
|
|
|
|
|
@click="doConfig"
|
|
|
|
|
>配置</el-button>
|
|
|
|
|
</template>
|
|
|
|
|
</crudOperation>
|
2019-11-19 13:44:19 +08:00
|
|
|
|
<!-- 文件上传 -->
|
|
|
|
|
<el-dialog :visible.sync="dialog" :close-on-click-modal="false" append-to-body width="500px" @close="doSubmit">
|
|
|
|
|
<el-upload
|
|
|
|
|
:before-remove="handleBeforeRemove"
|
|
|
|
|
:on-success="handleSuccess"
|
|
|
|
|
:on-error="handleError"
|
|
|
|
|
:file-list="fileList"
|
|
|
|
|
:headers="headers"
|
|
|
|
|
:action="qiNiuUploadApi"
|
|
|
|
|
class="upload-demo"
|
2020-01-07 23:32:27 +08:00
|
|
|
|
multiple
|
|
|
|
|
>
|
2019-11-19 13:44:19 +08:00
|
|
|
|
<el-button size="small" type="primary">点击上传</el-button>
|
|
|
|
|
<div slot="tip" style="display: block;" class="el-upload__tip">请勿上传违法文件,且文件不超过15M</div>
|
|
|
|
|
</el-upload>
|
|
|
|
|
<div slot="footer" class="dialog-footer">
|
|
|
|
|
<el-button type="primary" @click="doSubmit">确认</el-button>
|
|
|
|
|
</div>
|
|
|
|
|
</el-dialog>
|
|
|
|
|
<!--表格渲染-->
|
2020-01-07 23:32:27 +08:00
|
|
|
|
<el-table ref="table" v-loading="crud.loading" :data="crud.data" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
|
|
|
|
|
<el-table-column type="selection" width="55" />
|
|
|
|
|
<el-table-column v-if="columns.visible('name')" prop="name" :show-overflow-tooltip="true" label="文件名">
|
2019-11-19 13:44:19 +08:00
|
|
|
|
<template slot-scope="scope">
|
2020-01-07 23:32:27 +08:00
|
|
|
|
<a href="JavaScript:" class="el-link el-link--primary" target="_blank" type="primary" @click="download(scope.row.id)">{{ scope.row.key }}</a>
|
2019-11-19 13:44:19 +08:00
|
|
|
|
</template>
|
|
|
|
|
</el-table-column>
|
2020-01-07 23:32:27 +08:00
|
|
|
|
<el-table-column v-if="columns.visible('suffix')" :show-overflow-tooltip="true" prop="suffix" label="文件类型" @selection-change="crud.selectionChangeHandler" />
|
|
|
|
|
<el-table-column v-if="columns.visible('bucket')" prop="bucket" label="空间名称" />
|
|
|
|
|
<el-table-column v-if="columns.visible('size')" prop="size" label="文件大小" />
|
|
|
|
|
<el-table-column v-if="columns.visible('type')" prop="type" label="空间类型" />
|
|
|
|
|
<el-table-column v-if="columns.visible('updateTime')" prop="updateTime" label="创建日期">
|
2019-11-19 13:44:19 +08:00
|
|
|
|
<template slot-scope="scope">
|
|
|
|
|
<span>{{ parseTime(scope.row.updateTime) }}</span>
|
|
|
|
|
</template>
|
|
|
|
|
</el-table-column>
|
|
|
|
|
</el-table>
|
|
|
|
|
<!--分页组件-->
|
2020-01-07 23:32:27 +08:00
|
|
|
|
<pagination />
|
2019-11-19 13:44:19 +08:00
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
2020-01-07 23:32:27 +08:00
|
|
|
|
import crudQiNiu from '@/api/tools/qiniu'
|
2019-11-19 13:44:19 +08:00
|
|
|
|
import { mapGetters } from 'vuex'
|
|
|
|
|
import { getToken } from '@/utils/auth'
|
|
|
|
|
import eForm from './form'
|
2020-01-07 23:32:27 +08:00
|
|
|
|
import CRUD, { presenter, header, crud } from '@crud/crud'
|
|
|
|
|
import rrOperation from '@crud/RR.operation'
|
|
|
|
|
import crudOperation from '@crud/CRUD.operation'
|
|
|
|
|
import pagination from '@crud/Pagination'
|
|
|
|
|
|
|
|
|
|
// crud交由presenter持有
|
|
|
|
|
const defaultCrud = CRUD({ title: '七牛云文件', url: 'api/qiNiuContent', crudMethod: { ...crudQiNiu }})
|
2019-11-19 13:44:19 +08:00
|
|
|
|
export default {
|
2020-01-07 23:32:27 +08:00
|
|
|
|
components: { eForm, pagination, crudOperation, rrOperation },
|
|
|
|
|
mixins: [presenter(defaultCrud), header(), crud()],
|
2019-11-19 13:44:19 +08:00
|
|
|
|
data() {
|
|
|
|
|
return {
|
2020-01-07 23:32:27 +08:00
|
|
|
|
permission: {
|
|
|
|
|
del: ['admin', 'storage:del']
|
|
|
|
|
},
|
|
|
|
|
title: '文件', dialog: false,
|
|
|
|
|
icon: 'el-icon-refresh',
|
|
|
|
|
url: '', headers: { 'Authorization': getToken() },
|
|
|
|
|
dialogImageUrl: '', dialogVisible: false, fileList: [], files: [], newWin: null
|
2019-11-19 13:44:19 +08:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
computed: {
|
|
|
|
|
...mapGetters([
|
|
|
|
|
'qiNiuUploadApi'
|
|
|
|
|
])
|
|
|
|
|
},
|
|
|
|
|
watch: {
|
|
|
|
|
url(newVal, oldVal) {
|
|
|
|
|
if (newVal && this.newWin) {
|
|
|
|
|
this.newWin.sessionStorage.clear()
|
|
|
|
|
this.newWin.location.href = newVal
|
|
|
|
|
// 重定向后把url和newWin重置
|
|
|
|
|
this.url = ''
|
|
|
|
|
this.newWin = null
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
2020-01-07 23:32:27 +08:00
|
|
|
|
created() {
|
|
|
|
|
this.crud.optShow.add = false
|
|
|
|
|
this.crud.optShow.edit = false
|
|
|
|
|
},
|
2019-11-19 13:44:19 +08:00
|
|
|
|
methods: {
|
2020-01-07 23:32:27 +08:00
|
|
|
|
// 七牛云配置
|
2019-11-19 13:44:19 +08:00
|
|
|
|
doConfig() {
|
|
|
|
|
const _this = this.$refs.form
|
|
|
|
|
_this.init()
|
|
|
|
|
_this.dialog = true
|
|
|
|
|
},
|
|
|
|
|
handleSuccess(response, file, fileList) {
|
|
|
|
|
const uid = file.uid
|
|
|
|
|
const id = response.id
|
|
|
|
|
this.files.push({ uid, id })
|
|
|
|
|
},
|
|
|
|
|
handleBeforeRemove(file, fileList) {
|
|
|
|
|
for (let i = 0; i < this.files.length; i++) {
|
|
|
|
|
if (this.files[i].uid === file.uid) {
|
2020-01-07 23:32:27 +08:00
|
|
|
|
crudQiNiu.del([this.files[i].id]).then(res => {})
|
2019-11-19 13:44:19 +08:00
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
handlePictureCardPreview(file) {
|
|
|
|
|
this.dialogImageUrl = file.url
|
|
|
|
|
this.dialogVisible = true
|
|
|
|
|
},
|
|
|
|
|
// 刷新列表数据
|
|
|
|
|
doSubmit() {
|
|
|
|
|
this.fileList = []
|
|
|
|
|
this.dialogVisible = false
|
|
|
|
|
this.dialogImageUrl = ''
|
|
|
|
|
this.dialog = false
|
2020-01-07 23:32:27 +08:00
|
|
|
|
this.crud.toQuery()
|
2019-11-19 13:44:19 +08:00
|
|
|
|
},
|
|
|
|
|
// 监听上传失败
|
|
|
|
|
handleError(e, file, fileList) {
|
|
|
|
|
const msg = JSON.parse(e.message)
|
2020-01-07 23:32:27 +08:00
|
|
|
|
this.crud.notify(msg.message, CRUD.NOTIFICATION_TYPE.ERROR)
|
|
|
|
|
},
|
|
|
|
|
// 下载文件
|
|
|
|
|
download(id) {
|
|
|
|
|
this.downloadLoading = true
|
|
|
|
|
// 先打开一个空的新窗口,再请求
|
|
|
|
|
this.newWin = window.open()
|
|
|
|
|
crudQiNiu.download(id).then(res => {
|
|
|
|
|
this.downloadLoading = false
|
|
|
|
|
this.url = res.url
|
|
|
|
|
}).catch(err => {
|
|
|
|
|
this.downloadLoading = false
|
|
|
|
|
console.log(err.response.data.message)
|
2019-11-19 13:44:19 +08:00
|
|
|
|
})
|
|
|
|
|
},
|
2020-01-07 23:32:27 +08:00
|
|
|
|
// 同步数据
|
2019-11-19 13:44:19 +08:00
|
|
|
|
synchronize() {
|
|
|
|
|
this.icon = 'el-icon-loading'
|
2020-01-07 23:32:27 +08:00
|
|
|
|
crudQiNiu.sync().then(res => {
|
2019-11-19 13:44:19 +08:00
|
|
|
|
this.icon = 'el-icon-refresh'
|
|
|
|
|
this.$message({
|
|
|
|
|
showClose: true,
|
|
|
|
|
message: '数据同步成功',
|
|
|
|
|
type: 'success',
|
|
|
|
|
duration: 1500
|
|
|
|
|
})
|
2020-01-07 23:32:27 +08:00
|
|
|
|
this.crud.toQuery()
|
2019-11-19 13:44:19 +08:00
|
|
|
|
}).catch(err => {
|
|
|
|
|
this.icon = 'el-icon-refresh'
|
|
|
|
|
console.log(err.response.data.message)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
|
|
|
|
|
|
</style>
|