vue2-client 1.8.111 → 1.8.112
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -8,6 +8,13 @@
|
|
|
8
8
|
:columns="tableColumns"
|
|
9
9
|
:dataSource="tableData"
|
|
10
10
|
:rowKey="record => record.id">
|
|
11
|
+
<template slot="footer">
|
|
12
|
+
<a-space>
|
|
13
|
+
<span v-for="column in tableColumns" :key="column.key">
|
|
14
|
+
<strong v-if="column.sum !== undefined">{{ `${column.key} : ${column.sum}` }}</strong>
|
|
15
|
+
</span>
|
|
16
|
+
</a-space>
|
|
17
|
+
</template>
|
|
11
18
|
</a-table>
|
|
12
19
|
<a-result
|
|
13
20
|
v-else
|
|
@@ -76,12 +83,22 @@ export default {
|
|
|
76
83
|
return
|
|
77
84
|
}
|
|
78
85
|
const sample = this.tableData[0]
|
|
79
|
-
this.tableColumns = Object.keys(sample).map(key =>
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
86
|
+
this.tableColumns = Object.keys(sample).map(key => {
|
|
87
|
+
// 检查是否所有的值都是数字
|
|
88
|
+
const allNumbers = this.tableData.every(item => typeof item[key] === 'number')
|
|
89
|
+
let sum = 0
|
|
90
|
+
if (allNumbers) {
|
|
91
|
+
// 计算总和
|
|
92
|
+
sum = this.tableData.reduce((total, item) => total + item[key], 0)
|
|
93
|
+
}
|
|
94
|
+
return {
|
|
95
|
+
title: key, // 使用键名作为列标题
|
|
96
|
+
dataIndex: key, // 数据索引与键名相同
|
|
97
|
+
key: key,
|
|
98
|
+
ellipsis: true,
|
|
99
|
+
sum: allNumbers ? sum : undefined, // 如果所有的值都是数字,添加总和
|
|
100
|
+
}
|
|
101
|
+
})
|
|
85
102
|
let totalWidth = 0
|
|
86
103
|
// 设置表格宽度
|
|
87
104
|
for (let i = 0; i < this.tableColumns.length; i++) {
|