Commit 1d71d2cc by dqjdda

优化代码

parent b428376e
...@@ -31,11 +31,4 @@ export function edit(data) { ...@@ -31,11 +31,4 @@ export function edit(data) {
}) })
} }
export function downloadStorage(params) { export default { add, edit, del, delAll }
return request({
url: 'api/localStorage/download',
method: 'get',
params,
responseType: 'blob'
})
}
...@@ -15,11 +15,4 @@ export function delAll(ids) { ...@@ -15,11 +15,4 @@ export function delAll(ids) {
}) })
} }
export function downloadPicture(params) { export default { del, delAll }
return request({
url: 'api/pictures/download',
method: 'get',
params,
responseType: 'blob'
})
}
...@@ -44,11 +44,4 @@ export function delAll(ids) { ...@@ -44,11 +44,4 @@ export function delAll(ids) {
}) })
} }
export function downloadQiNiu(params) { export default { del, download, sync, delAll }
return request({
url: 'api/qiNiuContent/download/list',
method: 'get',
params,
responseType: 'blob'
})
}
...@@ -31,6 +31,7 @@ export default { ...@@ -31,6 +31,7 @@ export default {
loading: true, loading: true,
// 删除 Loading 属性 // 删除 Loading 属性
delLoading: false, delLoading: false,
delAllLoading: false,
// 弹窗属性 // 弹窗属性
dialog: false, dialog: false,
// Form 表单 // Form 表单
...@@ -171,6 +172,41 @@ export default { ...@@ -171,6 +172,41 @@ export default {
afterDelMethod() { afterDelMethod() {
}, },
/** /**
* 多选删除提示
*/
beforeDelAllMethod() {
this.$confirm('你确定删除选中的数据吗?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
this.delAllMethod()
})
},
/**
* 多选删除
*/
delAllMethod() {
this.delAllLoading = true
const data = this.$refs.table.selection
const ids = []
for (let i = 0; i < data.length; i++) {
ids.push(data[i].id)
}
this.crudMethod.delAll(ids).then(() => {
this.delAllLoading = false
this.dleChangePage(ids.length)
this.init()
this.$notify({
title: '删除成功',
type: 'success',
duration: 2500
})
}).catch(() => {
this.delAllLoading = false
})
},
/**
* 显示新增弹窗前可以调用该方法 * 显示新增弹窗前可以调用该方法
*/ */
beforeShowAddForm() { beforeShowAddForm() {
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<!--搜索--> <!--搜索-->
<el-input v-model="query.filename" clearable size="small" placeholder="输入文件名" style="width: 200px;" class="filter-item" @keyup.enter.native="toQuery" /> <el-input v-model="query.filename" clearable size="small" placeholder="输入文件名" style="width: 200px;" class="filter-item" @keyup.enter.native="toQuery" />
<el-date-picker <el-date-picker
v-model="query.date" v-model="query.createTime"
:default-time="['00:00:00','23:59:59']" :default-time="['00:00:00','23:59:59']"
type="daterange" type="daterange"
range-separator=":" range-separator=":"
...@@ -17,7 +17,6 @@ ...@@ -17,7 +17,6 @@
/> />
<el-button class="filter-item" size="mini" type="success" icon="el-icon-search" @click="toQuery">搜索</el-button> <el-button class="filter-item" size="mini" type="success" icon="el-icon-search" @click="toQuery">搜索</el-button>
<!-- 上传 --> <!-- 上传 -->
<div style="display: inline-block;margin: 0px 2px;">
<el-button <el-button
v-permission="['admin','pictures:add']" v-permission="['admin','pictures:add']"
class="filter-item" class="filter-item"
...@@ -26,18 +25,16 @@ ...@@ -26,18 +25,16 @@
icon="el-icon-upload" icon="el-icon-upload"
@click="dialog = true" @click="dialog = true"
>上传图片</el-button> >上传图片</el-button>
</div>
<div v-permission="['admin','pictures:del']" style="display: inline-block;">
<el-button <el-button
v-permission="['admin','pictures:del']"
:loading="delAllLoading" :loading="delAllLoading"
:disabled="data.length === 0 || $refs.table.selection.length === 0" :disabled="data.length === 0 || $refs.table.selection.length === 0"
class="filter-item" class="filter-item"
size="mini" size="mini"
type="danger" type="danger"
icon="el-icon-delete" icon="el-icon-delete"
@click="open" @click="beforeDelAllMethod"
>删除</el-button> >删除</el-button>
</div>
<!-- 导出 --> <!-- 导出 -->
<div style="display: inline-block;"> <div style="display: inline-block;">
<el-button <el-button
...@@ -46,7 +43,7 @@ ...@@ -46,7 +43,7 @@
class="filter-item" class="filter-item"
type="warning" type="warning"
icon="el-icon-download" icon="el-icon-download"
@click="download" @click="downloadMethod"
>导出</el-button> >导出</el-button>
</div> </div>
</div> </div>
...@@ -77,8 +74,14 @@ ...@@ -77,8 +74,14 @@
<el-table-column prop="filename" label="文件名" /> <el-table-column prop="filename" label="文件名" />
<el-table-column prop="username" label="上传者" /> <el-table-column prop="username" label="上传者" />
<el-table-column ref="table" :show-overflow-tooltip="true" prop="url" label="缩略图"> <el-table-column ref="table" :show-overflow-tooltip="true" prop="url" label="缩略图">
<template slot-scope="scope"> <template slot-scope="{row}">
<a :href="scope.row.url" style="color: #42b983" target="_blank"><img :src="scope.row.url" alt="点击打开" class="el-avatar"></a> <el-image
:src="row.url"
:preview-src-list="[row.url]"
fit="contain"
lazy
class="el-avatar"
/>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column prop="size" label="文件大小" /> <el-table-column prop="size" label="文件大小" />
...@@ -99,7 +102,7 @@ ...@@ -99,7 +102,7 @@
<p>确定删除本条数据吗?</p> <p>确定删除本条数据吗?</p>
<div style="text-align: right; margin: 0"> <div style="text-align: right; margin: 0">
<el-button size="mini" type="text" @click="$refs[scope.row.id].doClose()">取消</el-button> <el-button size="mini" type="text" @click="$refs[scope.row.id].doClose()">取消</el-button>
<el-button :loading="delLoading" type="primary" size="mini" @click="subDelete(scope.row.id)">确定</el-button> <el-button :loading="delLoading" type="primary" size="mini" @click="delMethod(scope.row.id)">确定</el-button>
</div> </div>
<el-button slot="reference" type="danger" icon="el-icon-delete" size="mini" /> <el-button slot="reference" type="danger" icon="el-icon-delete" size="mini" />
</el-popover> </el-popover>
...@@ -119,23 +122,20 @@ ...@@ -119,23 +122,20 @@
</template> </template>
<script> <script>
import checkPermission from '@/utils/permission' // 权限判断函数 import crud from '@/mixins/crud'
import initData from '@/mixins/initData'
import { parseTime, downloadFile } from '@/utils/index'
import { mapGetters } from 'vuex' import { mapGetters } from 'vuex'
import { del, delAll, downloadPicture } from '@/api/tools/picture' import crudPic from '@/api/tools/picture'
import { getToken } from '@/utils/auth' import { getToken } from '@/utils/auth'
export default { export default {
name: 'Pictures', name: 'Pictures',
mixins: [initData], mixins: [crud],
data() { data() {
return { return {
delLoading: false, title: '图片',
delAllLoading: false, crudMethod: { ...crudPic },
headers: { headers: {
'Authorization': 'Bearer ' + getToken() 'Authorization': 'Bearer ' + getToken()
}, },
dialog: false,
dialogImageUrl: '', dialogImageUrl: '',
dialogVisible: false, dialogVisible: false,
fileList: [], fileList: [],
...@@ -153,69 +153,10 @@ export default { ...@@ -153,69 +153,10 @@ export default {
}) })
}, },
methods: { methods: {
parseTime,
checkPermission,
beforeInit() { beforeInit() {
this.url = 'api/pictures' this.url = 'api/pictures'
const sort = 'id,desc'
const query = this.query
const filename = query.filename
this.params = { page: this.page, size: this.size, sort: sort }
if (filename) { this.params[filename] = filename }
if (query.date) {
this.params['startTime'] = query.date[0]
this.params['endTime'] = query.date[1]
}
return true return true
}, },
subDelete(id) {
this.delLoading = true
del(id).then(res => {
this.delLoading = false
this.$refs[id].doClose()
this.dleChangePage()
this.init()
this.$notify({
title: '删除成功',
type: 'success',
duration: 2500
})
}).catch(err => {
this.delLoading = false
this.$refs[id].doClose()
console.log(err.response.data.message)
})
},
doDelete() {
this.delAllLoading = true
const data = this.$refs.table.selection
const ids = []
for (let i = 0; i < data.length; i++) {
ids.push(data[i].id)
}
delAll(ids).then(res => {
this.delAllLoading = false
this.init()
this.dleChangePage(ids.length)
this.$notify({
title: '删除成功',
type: 'success',
duration: 2500
})
}).catch(err => {
this.delAllLoading = false
console.log(err.response.data.message)
})
},
open() {
this.$confirm('你确定删除选中的数据吗?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
this.doDelete()
})
},
handleSuccess(response, file, fileList) { handleSuccess(response, file, fileList) {
const uid = file.uid const uid = file.uid
const id = response.id const id = response.id
...@@ -224,7 +165,7 @@ export default { ...@@ -224,7 +165,7 @@ export default {
handleBeforeRemove(file, fileList) { handleBeforeRemove(file, fileList) {
for (let i = 0; i < this.pictures.length; i++) { for (let i = 0; i < this.pictures.length; i++) {
if (this.pictures[i].uid === file.uid) { if (this.pictures[i].uid === file.uid) {
del(this.pictures[i].id).then(res => {}) this.crudMethod.del(this.pictures[i].id).then(res => {})
return true return true
} }
} }
...@@ -249,16 +190,6 @@ export default { ...@@ -249,16 +190,6 @@ export default {
type: 'error', type: 'error',
duration: 2500 duration: 2500
}) })
},
download() {
this.beforeInit()
this.downloadLoading = true
downloadPicture(this.params).then(result => {
downloadFile(result, '图片列表', 'xlsx')
this.downloadLoading = false
}).catch(() => {
this.downloadLoading = false
})
} }
} }
} }
......
<template>
<el-dialog :append-to-body="true" :close-on-click-modal="false" :before-close="cancel" :visible.sync="dialog" :title="isAdd ? '上传文件' : '编辑文件'" width="500px">
<el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">
<el-form-item label="文件名">
<el-input v-model="form.name" style="width: 370px;" />
</el-form-item>
<!-- 上传文件 -->
<el-form-item v-if="isAdd" label="上传">
<el-upload
ref="upload"
:limit="1"
:before-upload="beforeUpload"
:auto-upload="false"
:headers="headers"
:on-success="handleSuccess"
:on-error="handleError"
:action="fileUploadApi + '?name=' + form.name"
>
<div class="eladmin-upload"><i class="el-icon-upload" /> 添加文件</div>
<div slot="tip" class="el-upload__tip">可上传任意格式文件,且不超过100M</div>
</el-upload>
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button type="text" @click="cancel">取消</el-button>
<el-button :loading="loading" type="primary" @click="doSubmit">确认</el-button>
</div>
</el-dialog>
</template>
<script>
import { mapGetters } from 'vuex'
import { getToken } from '@/utils/auth'
import { edit } from '@/api/tools/localStorage'
export default {
props: {
isAdd: {
type: Boolean,
required: true
}
},
data() {
return {
loading: false, dialog: false,
headers: { 'Authorization': 'Bearer ' + getToken() },
form: {
id: '',
name: ''
},
rules: {
}
}
},
computed: {
...mapGetters([
'fileUploadApi'
])
},
methods: {
cancel() {
this.resetForm()
},
doSubmit() {
this.loading = true
if (this.isAdd) {
this.$refs.upload.submit()
} else this.doEdit()
},
doEdit() {
edit(this.form).then(res => {
this.resetForm()
this.$notify({
title: '修改成功',
type: 'success',
duration: 2500
})
this.loading = false
this.$parent.init()
}).catch(err => {
this.loading = false
console.log(err.response.data.message)
})
},
resetForm() {
this.dialog = false
this.$refs['form'].resetFields()
this.form = {
id: '',
name: ''
}
},
beforeUpload(file) {
let isLt2M = true
isLt2M = file.size / 1024 / 1024 < 100
if (!isLt2M) {
this.$message.error('上传文件大小不能超过 100MB!')
}
this.loading = false
return isLt2M
},
handleSuccess(response, file, fileList) {
this.dialog = false
this.resetForm()
this.$refs.upload.clearFiles()
this.$parent.init()
},
// 监听上传失败
handleError(e, file, fileList) {
const msg = JSON.parse(e.message)
this.$notify({
title: msg.message,
type: 'error',
duration: 2500
})
this.loading = false
}
}
}
</script>
<style scoped>
</style>
...@@ -3,9 +3,9 @@ ...@@ -3,9 +3,9 @@
<!--工具栏--> <!--工具栏-->
<div class="head-container"> <div class="head-container">
<!-- 搜索 --> <!-- 搜索 -->
<el-input v-model="query.value" clearable size="small" placeholder="输入内容模糊搜索" style="width: 200px;" class="filter-item" @keyup.enter.native="toQuery" /> <el-input v-model="query.blurry" clearable size="small" placeholder="输入内容模糊搜索" style="width: 200px;" class="filter-item" @keyup.enter.native="toQuery" />
<el-date-picker <el-date-picker
v-model="query.date" v-model="query.createTime"
:default-time="['00:00:00','23:59:59']" :default-time="['00:00:00','23:59:59']"
type="daterange" type="daterange"
range-separator=":" range-separator=":"
...@@ -17,19 +17,16 @@ ...@@ -17,19 +17,16 @@
/> />
<el-button class="filter-item" size="mini" type="success" icon="el-icon-search" @click="toQuery">搜索</el-button> <el-button class="filter-item" size="mini" type="success" icon="el-icon-search" @click="toQuery">搜索</el-button>
<!-- 新增 --> <!-- 新增 -->
<div style="display: inline-block;margin: 0px 2px;">
<el-button <el-button
v-permission="['admin','storage:add']" v-permission="['admin','storage:add']"
class="filter-item" class="filter-item"
size="mini" size="mini"
type="primary" type="primary"
icon="el-icon-upload" icon="el-icon-upload"
@click="add" @click="showAddFormDialog"
>文件上传 >文件上传
</el-button> </el-button>
</div>
<!-- 多选删除 --> <!-- 多选删除 -->
<div style="display: inline-block;margin: 0px 2px;">
<el-button <el-button
v-permission="['admin','storage:del']" v-permission="['admin','storage:del']"
:loading="delAllLoading" :loading="delAllLoading"
...@@ -38,24 +35,47 @@ ...@@ -38,24 +35,47 @@
size="mini" size="mini"
type="danger" type="danger"
icon="el-icon-delete" icon="el-icon-delete"
@click="open" @click="beforeDelAllMethod"
>删除 >删除
</el-button> </el-button>
</div>
<!-- 导出 --> <!-- 导出 -->
<div style="display: inline-block;">
<el-button <el-button
:loading="downloadLoading" :loading="downloadLoading"
size="mini" size="mini"
class="filter-item" class="filter-item"
type="warning" type="warning"
icon="el-icon-download" icon="el-icon-download"
@click="download" @click="downloadMethod"
>导出</el-button> >导出</el-button>
</div> </div>
</div>
<!--表单组件--> <!--表单组件-->
<eForm ref="form" :is-add="isAdd" /> <el-dialog :append-to-body="true" :close-on-click-modal="false" :before-close="cancel" :visible.sync="dialog" :title="getFormTitle()" width="500px">
<el-form ref="form" :model="form" size="small" label-width="80px">
<el-form-item label="文件名">
<el-input v-model="form.name" style="width: 370px;" />
</el-form-item>
<!-- 上传文件 -->
<el-form-item v-if="isAdd" label="上传">
<el-upload
ref="upload"
:limit="1"
:before-upload="beforeUpload"
:auto-upload="false"
:headers="headers"
:on-success="handleSuccess"
:on-error="handleError"
:action="fileUploadApi + '?name=' + form.name"
>
<div class="eladmin-upload"><i class="el-icon-upload" /> 添加文件</div>
<div slot="tip" class="el-upload__tip">可上传任意格式文件,且不超过100M</div>
</el-upload>
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button type="text" @click="cancel">取消</el-button>
<el-button :loading="loading" type="primary" @click="submitMethod">确认</el-button>
</div>
</el-dialog>
<!--表格渲染--> <!--表格渲染-->
<el-table ref="table" v-loading="loading" :data="data" size="small" style="width: 100%;"> <el-table ref="table" v-loading="loading" :data="data" size="small" style="width: 100%;">
<el-table-column type="selection" width="55" /> <el-table-column type="selection" width="55" />
...@@ -106,7 +126,7 @@ ...@@ -106,7 +126,7 @@
</el-table-column> </el-table-column>
<el-table-column v-if="checkPermission(['admin','storage:edit','storage:del'])" label="操作" width="150px" align="center"> <el-table-column v-if="checkPermission(['admin','storage:edit','storage:del'])" label="操作" width="150px" align="center">
<template slot-scope="scope"> <template slot-scope="scope">
<el-button v-permission="['admin','storage:edit']" size="mini" type="primary" icon="el-icon-edit" @click="edit(scope.row)" /> <el-button v-permission="['admin','storage:edit']" size="mini" type="primary" icon="el-icon-edit" @click="showEditFormDialog(scope.row)" />
<el-popover <el-popover
:ref="scope.row.id" :ref="scope.row.id"
v-permission="['admin','storage:del']" v-permission="['admin','storage:del']"
...@@ -116,7 +136,7 @@ ...@@ -116,7 +136,7 @@
<p>确定删除本条数据吗?</p> <p>确定删除本条数据吗?</p>
<div style="text-align: right; margin: 0"> <div style="text-align: right; margin: 0">
<el-button size="mini" type="text" @click="$refs[scope.row.id].doClose()">取消</el-button> <el-button size="mini" type="text" @click="$refs[scope.row.id].doClose()">取消</el-button>
<el-button :loading="delLoading" type="primary" size="mini" @click="subDelete(scope.row.id)">确定 <el-button :loading="delLoading" type="primary" size="mini" @click="delMethod(scope.row.id)">确定
</el-button> </el-button>
</div> </div>
<el-button slot="reference" type="danger" icon="el-icon-delete" size="mini" /> <el-button slot="reference" type="danger" icon="el-icon-delete" size="mini" />
...@@ -138,28 +158,24 @@ ...@@ -138,28 +158,24 @@
<script> <script>
import { mapGetters } from 'vuex' import { mapGetters } from 'vuex'
import checkPermission from '@/utils/permission' import { getToken } from '@/utils/auth'
import initData from '@/mixins/initData' import crud from '@/mixins/crud'
import { del, delAll, downloadStorage } from '@/api/tools/localStorage' import crudFile from '@/api/tools/localStorage'
import { parseTime, downloadFile } from '@/utils/index'
import eForm from './form'
export default { export default {
components: { eForm }, mixins: [crud],
mixins: [initData],
data() { data() {
return { return {
delLoading: false, delAllLoading: false, title: '文件',
queryTypeOptions: [ crudMethod: { ...crudFile },
{ key: 'name', display_name: '文件名' }, delAllLoading: false,
{ key: 'suffix', display_name: '后缀' }, headers: { 'Authorization': 'Bearer ' + getToken() },
{ key: 'type', display_name: '类型' }, form: { id: null, name: null }
{ key: 'operate', display_name: '操作人' }
]
} }
}, },
computed: { computed: {
...mapGetters([ ...mapGetters([
'baseApi' 'baseApi',
'fileUploadApi'
]) ])
}, },
created() { created() {
...@@ -168,91 +184,39 @@ export default { ...@@ -168,91 +184,39 @@ export default {
}) })
}, },
methods: { methods: {
parseTime, // 获取数据前设置好接口地址
checkPermission,
beforeInit() { beforeInit() {
this.url = 'api/localStorage' this.url = 'api/localStorage'
const sort = 'id,desc'
this.params = { page: this.page, size: this.size, sort: sort }
const query = this.query
const value = query.value
if (value) { this.params['blurry'] = value }
if (query.date) {
this.params['startTime'] = query.date[0]
this.params['endTime'] = query.date[1]
}
return true return true
}, },
subDelete(id) { // 上传文件
this.delLoading = true addMethod() {
del(id).then(res => { this.$refs.upload.submit()
this.delLoading = false
this.$refs[id].doClose()
this.dleChangePage()
this.init()
this.$notify({
title: '删除成功',
type: 'success',
duration: 2500
})
}).catch(err => {
this.delLoading = false
this.$refs[id].doClose()
console.log(err.response.data.message)
})
},
add() {
this.isAdd = true
this.$refs.form.dialog = true
}, },
edit(data) { beforeUpload(file) {
this.isAdd = false let isLt2M = true
const _this = this.$refs.form isLt2M = file.size / 1024 / 1024 < 100
_this.form = { if (!isLt2M) {
id: data.id, this.$message.error('上传文件大小不能超过 100MB!')
name: data.name
} }
_this.dialog = true this.loading = false
return isLt2M
}, },
doDelete() { handleSuccess(response, file, fileList) {
this.delAllLoading = true this.dialog = false
const data = this.$refs.table.selection this.cancel()
const ids = [] this.$refs.upload.clearFiles()
for (let i = 0; i < data.length; i++) {
ids.push(data[i].id)
}
delAll(ids).then(res => {
this.delAllLoading = false
this.dleChangePage(ids.length)
this.init() this.init()
},
// 监听上传失败
handleError(e, file, fileList) {
const msg = JSON.parse(e.message)
this.$notify({ this.$notify({
title: '删除成功', title: msg.message,
type: 'success', type: 'error',
duration: 2500 duration: 2500
}) })
}).catch(err => { this.loading = false
this.delAllLoading = false
console.log(err.response.data.message)
})
},
open() {
this.$confirm('你确定删除选中的数据吗?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
this.doDelete()
})
},
download() {
this.beforeInit()
this.downloadLoading = true
downloadStorage(this.params).then(result => {
downloadFile(result, '文件列表', 'xlsx')
this.downloadLoading = false
}).catch(() => {
this.downloadLoading = false
})
} }
} }
} }
......
<template> <template>
<!--上传图片-->
<el-dialog :visible.sync="dialog" :close-on-click-modal="false" title="七牛云配置" append-to-body width="580px"> <el-dialog :visible.sync="dialog" :close-on-click-modal="false" title="七牛云配置" append-to-body width="580px">
<el-form ref="form" :model="form" :rules="rules" style="margin-top: 6px;" size="small" label-width="110px"> <el-form ref="form" :model="form" :rules="rules" style="margin-top: 6px;" size="small" label-width="110px">
<el-form-item label="Access Key" prop="accessKey"> <el-form-item label="Access Key" prop="accessKey">
......
...@@ -5,9 +5,9 @@ ...@@ -5,9 +5,9 @@
<!-- 工具栏 --> <!-- 工具栏 -->
<div class="head-container"> <div class="head-container">
<!-- 搜索 --> <!-- 搜索 -->
<el-input v-model="query.value" clearable size="small" placeholder="输入文件名称搜索" style="width: 200px;" class="filter-item" @keyup.enter.native="toQuery" /> <el-input v-model="query.key" clearable size="small" placeholder="输入文件名称搜索" style="width: 200px;" class="filter-item" @keyup.enter.native="toQuery" />
<el-date-picker <el-date-picker
v-model="query.date" v-model="query.c"
:default-time="['00:00:00','23:59:59']" :default-time="['00:00:00','23:59:59']"
type="daterange" type="daterange"
range-separator=":" range-separator=":"
...@@ -19,13 +19,10 @@ ...@@ -19,13 +19,10 @@
/> />
<el-button class="filter-item" size="mini" type="success" icon="el-icon-search" @click="toQuery">搜索</el-button> <el-button class="filter-item" size="mini" type="success" icon="el-icon-search" @click="toQuery">搜索</el-button>
<!-- 上传 --> <!-- 上传 -->
<div style="display: inline-block;margin: 0px 2px;">
<el-button class="filter-item" size="mini" type="primary" icon="el-icon-upload" @click="dialog = true">上传文件</el-button> <el-button class="filter-item" size="mini" type="primary" icon="el-icon-upload" @click="dialog = true">上传文件</el-button>
</div>
<!-- 同步 --> <!-- 同步 -->
<el-button :icon="icon" class="filter-item" size="mini" type="warning" @click="synchronize">同步数据</el-button> <el-button :icon="icon" class="filter-item" size="mini" type="warning" @click="synchronize">同步数据</el-button>
<!-- 配置 --> <!-- 配置 -->
<div style="display: inline-block;margin: 0px 2px;">
<el-button <el-button
class="filter-item" class="filter-item"
size="mini" size="mini"
...@@ -33,9 +30,7 @@ ...@@ -33,9 +30,7 @@
icon="el-icon-s-tools" icon="el-icon-s-tools"
@click="doConfig" @click="doConfig"
>七牛配置</el-button> >七牛配置</el-button>
</div>
<!-- 多选删除 --> <!-- 多选删除 -->
<div style="display: inline-block;margin: 0px 2px;">
<el-button <el-button
:loading="delAllLoading" :loading="delAllLoading"
:disabled="data.length === 0 || $refs.table.selection.length === 0" :disabled="data.length === 0 || $refs.table.selection.length === 0"
...@@ -43,20 +38,17 @@ ...@@ -43,20 +38,17 @@
size="mini" size="mini"
type="danger" type="danger"
icon="el-icon-delete" icon="el-icon-delete"
@click="open" @click="beforeDelAllMethod"
>删除</el-button> >删除</el-button>
</div>
<!-- 导出 --> <!-- 导出 -->
<div style="display: inline-block;">
<el-button <el-button
:loading="downloadLoading" :loading="downloadLoading"
size="mini" size="mini"
class="filter-item" class="filter-item"
type="warning" type="warning"
icon="el-icon-download" icon="el-icon-download"
@click="downloadList" @click="downloadMethod"
>导出</el-button> >导出</el-button>
</div>
<!-- 文件上传 --> <!-- 文件上传 -->
<el-dialog :visible.sync="dialog" :close-on-click-modal="false" append-to-body width="500px" @close="doSubmit"> <el-dialog :visible.sync="dialog" :close-on-click-modal="false" append-to-body width="500px" @close="doSubmit">
<el-upload <el-upload
...@@ -103,7 +95,7 @@ ...@@ -103,7 +95,7 @@
<p>确定删除本条数据吗?</p> <p>确定删除本条数据吗?</p>
<div style="text-align: right; margin: 0"> <div style="text-align: right; margin: 0">
<el-button size="mini" type="text" @click="$refs[scope.row.id].doClose()">取消</el-button> <el-button size="mini" type="text" @click="$refs[scope.row.id].doClose()">取消</el-button>
<el-button :loading="delLoading" type="primary" size="mini" @click="subDelete(scope.row.id)">确定</el-button> <el-button :loading="delLoading" type="primary" size="mini" @click="delMethod(scope.row.id)">确定</el-button>
</div> </div>
<el-button slot="reference" type="danger" icon="el-icon-delete" size="mini" /> <el-button slot="reference" type="danger" icon="el-icon-delete" size="mini" />
</el-popover> </el-popover>
...@@ -124,21 +116,21 @@ ...@@ -124,21 +116,21 @@
</template> </template>
<script> <script>
import initData from '@/mixins/initData' import crud from '@/mixins/crud'
import { del, download, sync, delAll, downloadQiNiu } from '@/api/tools/qiniu' import crudQiNiu from '@/api/tools/qiniu'
import { parseTime, downloadFile } from '@/utils/index'
import { mapGetters } from 'vuex' import { mapGetters } from 'vuex'
import { getToken } from '@/utils/auth' import { getToken } from '@/utils/auth'
import eForm from './form' import eForm from './form'
export default { export default {
components: { eForm }, components: { eForm },
mixins: [initData], mixins: [crud],
data() { data() {
return { return {
icon: 'el-icon-refresh', delAllLoading: false, title: '文件',
crudMethod: { ...crudQiNiu },
icon: 'el-icon-refresh',
url: '', headers: { 'Authorization': 'Bearer ' + getToken() }, dialog: false, url: '', headers: { 'Authorization': 'Bearer ' + getToken() }, dialog: false,
dialogImageUrl: '', dialogVisible: false, fileList: [], files: [], dialogImageUrl: '', dialogVisible: false, fileList: [], files: [], newWin: null
newWin: null, downloadLoading: false, delLoading: false
} }
}, },
computed: { computed: {
...@@ -158,54 +150,17 @@ export default { ...@@ -158,54 +150,17 @@ export default {
} }
}, },
methods: { methods: {
parseTime, // 获取数据前设置好接口地址
beforeInit() { beforeInit() {
this.url = 'api/qiNiuContent' this.url = 'api/qiNiuContent'
const sort = 'id,desc'
const query = this.query
const value = query.value
this.params = { page: this.page, size: this.size, sort: sort }
if (value) { this.params['key'] = value }
if (query.date) {
this.params['startTime'] = query.date[0]
this.params['endTime'] = query.date[1]
}
return true return true
}, },
// 七牛云配置
doConfig() { doConfig() {
const _this = this.$refs.form const _this = this.$refs.form
_this.init() _this.init()
_this.dialog = true _this.dialog = true
}, },
subDelete(id) {
this.delLoading = true
del(id).then(res => {
this.delLoading = false
this.$refs[id].doClose()
this.init()
this.$notify({
title: '删除成功',
type: 'success',
duration: 2500
})
}).catch(err => {
this.delLoading = false
this.$refs[id].doClose()
console.log(err.response.data.message)
})
},
download(id) {
this.downloadLoading = true
// 先打开一个空的新窗口,再请求
this.newWin = window.open()
download(id).then(res => {
this.downloadLoading = false
this.url = res.url
}).catch(err => {
this.downloadLoading = false
console.log(err.response.data.message)
})
},
handleSuccess(response, file, fileList) { handleSuccess(response, file, fileList) {
const uid = file.uid const uid = file.uid
const id = response.id const id = response.id
...@@ -214,7 +169,7 @@ export default { ...@@ -214,7 +169,7 @@ export default {
handleBeforeRemove(file, fileList) { handleBeforeRemove(file, fileList) {
for (let i = 0; i < this.files.length; i++) { for (let i = 0; i < this.files.length; i++) {
if (this.files[i].uid === file.uid) { if (this.files[i].uid === file.uid) {
del(this.files[i].id).then(res => {}) this.crudMethod.del(this.files[i].id).then(res => {})
return true return true
} }
} }
...@@ -234,18 +189,26 @@ export default { ...@@ -234,18 +189,26 @@ export default {
// 监听上传失败 // 监听上传失败
handleError(e, file, fileList) { handleError(e, file, fileList) {
const msg = JSON.parse(e.message) const msg = JSON.parse(e.message)
this.$notify({ this.notify(msg.message, 'error')
title: msg.message, },
type: 'error', // 下载文件
duration: 2500 download(id) {
this.downloadLoading = true
// 先打开一个空的新窗口,再请求
this.newWin = window.open()
this.crudMethod.download(id).then(res => {
this.downloadLoading = false
this.url = res.url
}).catch(err => {
this.downloadLoading = false
console.log(err.response.data.message)
}) })
}, },
// 同步数据
synchronize() { synchronize() {
this.icon = 'el-icon-loading' this.icon = 'el-icon-loading'
this.buttonName = '同步中' this.crudMethod.sync().then(res => {
sync().then(res => {
this.icon = 'el-icon-refresh' this.icon = 'el-icon-refresh'
this.buttonName = '同步数据'
this.$message({ this.$message({
showClose: true, showClose: true,
message: '数据同步成功', message: '数据同步成功',
...@@ -255,49 +218,8 @@ export default { ...@@ -255,49 +218,8 @@ export default {
this.toQuery() this.toQuery()
}).catch(err => { }).catch(err => {
this.icon = 'el-icon-refresh' this.icon = 'el-icon-refresh'
this.buttonName = '同步数据'
console.log(err.response.data.message)
})
},
doDelete() {
this.delAllLoading = true
const data = this.$refs.table.selection
const ids = []
for (let i = 0; i < data.length; i++) {
ids.push(data[i].id)
}
delAll(ids).then(res => {
this.delAllLoading = false
this.dleChangePage(ids.length)
this.init()
this.$notify({
title: '删除成功',
type: 'success',
duration: 2500
})
}).catch(err => {
this.delAllLoading = false
console.log(err.response.data.message) console.log(err.response.data.message)
}) })
},
open() {
this.$confirm('你确定删除选中的数据吗?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
this.doDelete()
})
},
downloadList() {
this.beforeInit()
this.downloadLoading = true
downloadQiNiu(this.params).then(result => {
downloadFile(result, '七牛云文件列表', 'xlsx')
this.downloadLoading = false
}).catch(() => {
this.downloadLoading = false
})
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment