|
|
@@ -3,10 +3,12 @@
|
|
|
* 高级查询按钮调用 superQuery方法 高级查询组件ref定义为superQueryModal
|
|
|
* data中url定义 list为查询列表 delete为删除单条记录 deleteBatch为批量删除
|
|
|
*/
|
|
|
+import Vue from 'vue'
|
|
|
import { filterObj } from '@/utils/util'
|
|
|
import { postAction, getAction } from '@/api/request'
|
|
|
+import store from '@/store'
|
|
|
|
|
|
-export const JeecgListMixin = {
|
|
|
+export const listMixin = {
|
|
|
data() {
|
|
|
return {
|
|
|
/* 查询条件-请不要在queryParam中声明非字符串值的属性 */
|
|
|
@@ -57,6 +59,11 @@ export const JeecgListMixin = {
|
|
|
}
|
|
|
},
|
|
|
computed: {
|
|
|
+ // token header
|
|
|
+ tokenHeader() {
|
|
|
+ const head = { 'Authorization': store.getters.token }
|
|
|
+ return head
|
|
|
+ }
|
|
|
},
|
|
|
methods: {
|
|
|
loadData(arg) {
|
|
|
@@ -70,7 +77,7 @@ export const JeecgListMixin = {
|
|
|
}
|
|
|
var params = this.getQueryParams()// 查询条件
|
|
|
this.loading = true
|
|
|
- getAction(this.url.list, params).then((res) => {
|
|
|
+ postAction(this.url.list, params).then((res) => {
|
|
|
if (res.success) {
|
|
|
// update-begin---author:zhangyafei Date:20201118 for:适配不分页的数据列表------------
|
|
|
this.dataSource = res.result.records || res.result
|
|
|
@@ -244,6 +251,93 @@ export const JeecgListMixin = {
|
|
|
this.$refs.modalForm.edit(record)
|
|
|
this.$refs.modalForm.title = '详情'
|
|
|
this.$refs.modalForm.disableSubmit = true
|
|
|
+ },
|
|
|
+ /* 导出 */
|
|
|
+ handleExportXls2() {
|
|
|
+ const paramsStr = encodeURI(JSON.stringify(this.getQueryParams()))
|
|
|
+ const url = ``
|
|
|
+ window.location.href = url
|
|
|
+ },
|
|
|
+ handleExportXls(fileName) {
|
|
|
+ if (!fileName || typeof fileName !== 'string') {
|
|
|
+ fileName = '导出文件'
|
|
|
+ }
|
|
|
+ const param = this.getQueryParams()
|
|
|
+ if (this.selectedRowKeys && this.selectedRowKeys.length > 0) {
|
|
|
+ param['selections'] = this.selectedRowKeys.join(',')
|
|
|
+ }
|
|
|
+ console.log('导出参数', param)
|
|
|
+ downFile(this.url.exportXlsUrl, param).then((data) => {
|
|
|
+ if (!data) {
|
|
|
+ this.$message.warning('文件下载失败')
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if (typeof window.navigator.msSaveBlob !== 'undefined') {
|
|
|
+ window.navigator.msSaveBlob(new Blob([data], { type: 'application/vnd.ms-excel' }), fileName + '.xls')
|
|
|
+ } else {
|
|
|
+ const url = window.URL.createObjectURL(new Blob([data], { type: 'application/vnd.ms-excel' }))
|
|
|
+ const link = document.createElement('a')
|
|
|
+ link.style.display = 'none'
|
|
|
+ link.href = url
|
|
|
+ link.setAttribute('download', fileName + '.xls')
|
|
|
+ document.body.appendChild(link)
|
|
|
+ link.click()
|
|
|
+ document.body.removeChild(link) // 下载完成移除元素
|
|
|
+ window.URL.revokeObjectURL(url) // 释放掉blob对象
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ /* 导入 */
|
|
|
+ handleImportExcel(info) {
|
|
|
+ this.loading = true
|
|
|
+ if (info.file.status !== 'uploading') {
|
|
|
+ console.log(info.file, info.fileList)
|
|
|
+ }
|
|
|
+ if (info.file.status === 'done') {
|
|
|
+ this.loading = false
|
|
|
+ if (info.file.response.success) {
|
|
|
+ // this.$message.success(`${info.file.name} 文件上传成功`);
|
|
|
+ if (info.file.response.code === 201) {
|
|
|
+ const { message, result: { msg, fileUrl, fileName }} = info.file.response
|
|
|
+ const href = fileUrl
|
|
|
+ this.$warning({
|
|
|
+ title: message,
|
|
|
+ content: (<div>
|
|
|
+ <span>{msg}</span><br/>
|
|
|
+ <span>具体详情请 <a href={href} target='_blank' download={fileName}>点击下载</a> </span>
|
|
|
+ </div>
|
|
|
+ )
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ this.$message.success(info.file.response.message || `${info.file.name} 文件上传成功`)
|
|
|
+ }
|
|
|
+ this.loadData()
|
|
|
+ } else {
|
|
|
+ this.$message.error(`${info.file.name} ${info.file.response.message}.`)
|
|
|
+ }
|
|
|
+ } else if (info.file.status === 'error') {
|
|
|
+ this.loading = false
|
|
|
+ if (info.file.response.status === 500) {
|
|
|
+ const data = info.file.response
|
|
|
+ const token = store.getters.token
|
|
|
+ if (token && data.message.includes('Token失效')) {
|
|
|
+ this.$error({
|
|
|
+ title: '登录已过期',
|
|
|
+ content: '很抱歉,登录已过期,请重新登录',
|
|
|
+ okText: '重新登录',
|
|
|
+ mask: false,
|
|
|
+ onOk: () => {
|
|
|
+ store.dispatch('Logout').then(() => {
|
|
|
+ Vue.ls.remove(ACCESS_TOKEN)
|
|
|
+ window.location.reload()
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ this.$message.error(`文件上传失败: ${info.file.msg} `)
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|