templateManage.vue
2.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<!--
* @Author: panda
* @Date: 2021-10-21 14:20:51
* @LastEditTime: 2021-10-21 16:50:32
* @LastEditors: Please set LastEditors
* @Description: 导出导入模板管理
* @FilePath: /BS6/src/views/public/templateManage.vue
-->
<template>
<el-dialog
:title="$t('button.template')"
:lock-scroll="false"
:visible="dialogVisible"
width="30%"
@close="closeClick"
class="upDatadialog"
>
<div class="btn-box">
<el-button size="small" icon="el-icon-download" @click="downloadtemplate" class="downbbtn">{{ $t('button.downloadtemplate') }}</el-button>
<el-upload
class="upload"
:action="uploadurl"
:data="updata"
:before-upload="beforeUpload"
:on-success="uploadSuccess"
:limit="1"
:file-list="fileList">
<el-button size="small" icon="el-icon-upload2">{{ $t('button.uploadData') }}</el-button>
</el-upload>
</div>
<span slot="footer" class="dialog-footer">
<el-button size="small" @click="dialogVisible = false">{{ $t('button.cancel') }}</el-button>
<el-button size="small" type="primary">{{ $t('button.confirm') }}</el-button>
</span>
</el-dialog>
</template>
<script>
const { platform } = window._vionConfig
export default {
data() {
return {
dialogVisible: false,
exporturl:'',
type:'',
fileList:[],
exportData:"",
uploadurl:'',
updata:{
platform: platform,
authorization:'',
}
};
},
methods: {
//Excel 上传限制
beforeUpload(file) {
let isExcel = ['xls','xlsx'].includes(file.name.substring(file.name.lastIndexOf('.')+1));
if (!isExcel) {
this.$message.error(this.$t("请上传Excel格式文件"));
}
return isExcel;
},
/**
* @description: 初始化导入导出数据
* @param {*} type 导入或导出类型
* @return {*}
*/
dialogInit(type) {
this.type = type;
this.exporturl = `${window._vionConfig.apiUrl}/${type}/template?authorization=${this.$cookie.get("atoken")}`;
this.updata.authorization = this.$cookie.get("atoken")
this.uploadurl = `${window._vionConfig.apiUrl}/${type}/importExcel`
this.dialogVisible = true;
},
/**
* @description: 下载模板
* @param {*}
* @return {*}
*/
downloadtemplate(){
window.open(this.exporturl)
},
uploadSuccess(){
this.$message({
message: '上传成功!',
type: 'success'
})
this.$emit('refresh')
},
closeClick(){
this.dialogVisible = false;
},
}
};
</script>
<style>
.downbbtn{
margin-right: 20px;
float: left;
}
.upload{
float: left;
}
</style>