mixin.js
3.05 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
let mixin = {
data() {
return {
// 表格选择数据
selectionChangeList: [],
needMergeArr: [],
rowMergeArrs: {},
}
},
mounted() {
this.rowMergeArrs = this.rowMergeHandle(this.needMergeArr, this.PageData.records); // 处理数据
},
methods: {
tableRowClassName({ row, rowIndex }) {
if ((rowIndex + 1) % 2 === 0) {
return 'success-row';
}
return '';
},
// 表格多选操作
handleSelectionChange(value) {
this.selectionChangeList.length = 0
value.map((item, index) => {
this.selectionChangeList[index] = item.id
})
},
// 导出数据
getExportList(url, name = '列表数据') {
this.$confirm('此操作将进行文件导出, 是否继续?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
let loading = this.$loading({
lock: true,
text: '生在生成请稍后',
spinner: 'el-icon-loading',
background: 'rgba(0, 0, 0, 0.7)'
})
require.ensure([], () => {
let { export_json_to_excel } = require('../../vendor/Export2Excel');
let tHeader = ['id', '名称', '开始时间', '结束时间']
let filterVal = ['id', 'title', 'startTime', 'endTime'];
let data = this.formatJson(filterVal, this.PageData.records)
export_json_to_excel(tHeader, data, name)
loading.close();
})
}).catch(() => {
this.$message({
type: 'info',
message: '已取消'
})
})
},
formatJson(filterVal, jsonData) {
return jsonData.map(v => filterVal.map(j => v[j]))
},
// 表格索引得问题
indexMethod(index) {
return index + 1 + (this.PageData.current - 1) * this.PageData.size;
},
handleCurrentChange(val) {
this.initData.currentPage = val
this._initData()
},
handleSizeChange(val) {
console.log(val)
this.initData.pageSize = val
this._initData()
},
// 合并表格
mergeAction(val, rowIndex, colData) {
let _row = this.rowMergeArrs[val].rowArr[rowIndex];
let _col = _row > 0 ? 1 : 0;
return [_row, _col];
},
rowMergeHandle(arr, data) {
if (!Array.isArray(arr) && !arr.length) return false;
if (!Array.isArray(data) && !data.length) return false;
let needMerge = {};
arr.forEach((i) => {
needMerge[i] = {
rowArr: [],
rowMergeNum: 0,
};
data.forEach((item, index) => {
if (index === 0) {
needMerge[i].rowArr.push(1);
needMerge[i].rowMergeNum = 0;
} else {
if (item[i] === data[index - 1][i]) {
needMerge[i].rowArr[needMerge[i].rowMergeNum] += 1;
needMerge[i].rowArr.push(0);
} else {
needMerge[i].rowArr.push(1);
needMerge[i].rowMergeNum = index;
}
}
});
});
return needMerge;
},
}
}
export default mixin