common.js
1.5 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
import axios from 'axios'
export const Common = {
// 提示框
confirmDialog: (tipData) => {
tipData.that.$confirm(tipData.tipText, tipData.tipTitle, {
confirmButtonText: tipData.confirmButtonText || '确定',
cancelButtonText: tipData.cancelButtonText || '取消',
type: tipData.type,
showCancelButton: tipData.showCancelButton
}).then(() => {
tipData.callBack ? tipData.callBack() : ''
}).catch(() => {
tipData.errorCallBack ? tipData.errorCallBack() : ''
})
},
/**
* 导出excel
* */
exportExcel: function (options) {
if (!options) {
return false
}
console.log(options.data)
axios({
method: options.method || 'POST',
url: options.url,
params: options.data,
responseType: 'blob',
headers: {
Authorization: localStorage.getItem('token') || ''
}
}).then(response => {
if (!response) {
return
}
let url = window.URL.createObjectURL(new Blob([response.data], {
type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8'
}))
let link = document.createElement('a')
link.style.display = 'none'
link.href = url
link.setAttribute('download', options.fileName || 'excel.xlsx')
document.body.appendChild(link)
link.click()
if (options.success) {
(options.success)()
}
}).catch((error) => {
if (options.errorFunc) {
(options.errorFunc)(error)
}
})
}
}