haiwei-ui 1.2.7 → 1.2.9
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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "haiwei-ui",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.9",
|
|
4
4
|
"description": "HaiWei前端组件库",
|
|
5
5
|
"author": "Eric",
|
|
6
6
|
"license": "ISC",
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"scripts": {
|
|
9
9
|
"serve": "vue-cli-service lint && vue-cli-service serve",
|
|
10
10
|
"build": "vue-cli-service lint && vue-cli-service build",
|
|
11
|
-
"lint": "vue-cli-service lint",
|
|
11
|
+
"lint": "vue-cli-service lint --fit",
|
|
12
12
|
"cm": "rimraf node_modules && rimraf dist",
|
|
13
13
|
"cc": "rimraf node_modules/.cache",
|
|
14
14
|
"i": "cd ./script && npm_install.bat",
|
|
@@ -13,6 +13,9 @@
|
|
|
13
13
|
<el-form-item v-if="exportEnabled" v-nm-has="exportBtnCode">
|
|
14
14
|
<nm-button type="primary" @click="onExport" icon="export" text="导出" />
|
|
15
15
|
</el-form-item>
|
|
16
|
+
<el-form-item v-if="importEnabled" v-nm-has="importBtnCode">
|
|
17
|
+
<nm-button type="primary" @click="onImport" icon="import" text="导入" />
|
|
18
|
+
</el-form-item>
|
|
16
19
|
<el-form-item v-if="advanced_.enabled">
|
|
17
20
|
<nm-button ref="showAdvnacedBtn" type="warning" @click="onAdvancedClick">
|
|
18
21
|
高级查询
|
|
@@ -93,7 +96,11 @@ export default {
|
|
|
93
96
|
/**显示导出按钮 */
|
|
94
97
|
exportEnabled: Boolean,
|
|
95
98
|
/**导出按钮权限编码 */
|
|
96
|
-
exportBtnCode: String
|
|
99
|
+
exportBtnCode: String,
|
|
100
|
+
/**显示导入按钮 */
|
|
101
|
+
importEnabled: Boolean,
|
|
102
|
+
/**导入按钮权限编码 */
|
|
103
|
+
importBtnCode: String
|
|
97
104
|
},
|
|
98
105
|
computed: {
|
|
99
106
|
model_() {
|
|
@@ -189,6 +196,9 @@ export default {
|
|
|
189
196
|
},
|
|
190
197
|
onExport() {
|
|
191
198
|
this.$parent.triggerExport()
|
|
199
|
+
},
|
|
200
|
+
onImport() {
|
|
201
|
+
this.$parent.triggerImport()
|
|
192
202
|
}
|
|
193
203
|
},
|
|
194
204
|
mounted() {
|
|
@@ -104,9 +104,39 @@
|
|
|
104
104
|
const parent = this.$parent
|
|
105
105
|
|
|
106
106
|
// 检查是否启用树形全选
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
107
|
+
const isTreeSelectAllEnabled = parent.isTreeSelectAllEnabled && parent.isTreeSelectAllEnabled()
|
|
108
|
+
|
|
109
|
+
if (isTreeSelectAllEnabled) {
|
|
110
|
+
// 判断是全选还是取消全选
|
|
111
|
+
const visibleRowsCount = this.rows.length
|
|
112
|
+
|
|
113
|
+
// 简化逻辑:如果selection为空数组,肯定是取消全选
|
|
114
|
+
// 如果selection不为空,需要进一步判断
|
|
115
|
+
let isSelectAllOperation = false
|
|
116
|
+
|
|
117
|
+
if (selection.length === 0) {
|
|
118
|
+
// selection为空数组,肯定是取消全选
|
|
119
|
+
isSelectAllOperation = false
|
|
120
|
+
} else {
|
|
121
|
+
// selection不为空,需要判断
|
|
122
|
+
const hasExistingSelection = parent.selection && parent.selection.length > 0
|
|
123
|
+
const hasManySelected = hasExistingSelection && parent.selection.length > visibleRowsCount
|
|
124
|
+
|
|
125
|
+
if (!hasExistingSelection) {
|
|
126
|
+
// 还没有选择任何记录,肯定是全选操作
|
|
127
|
+
isSelectAllOperation = true
|
|
128
|
+
} else if (hasManySelected) {
|
|
129
|
+
// 已经选择了很多记录(包括子节点),肯定是取消全选操作
|
|
130
|
+
isSelectAllOperation = false
|
|
131
|
+
} else {
|
|
132
|
+
// 其他情况:选择了一些记录但不多
|
|
133
|
+
// 如果selection包含当前页显示的所有行,那么是全选操作
|
|
134
|
+
// 否则是取消全选操作
|
|
135
|
+
isSelectAllOperation = selection.length >= visibleRowsCount
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
if (isSelectAllOperation) {
|
|
110
140
|
// 选择所有节点(包括子节点)
|
|
111
141
|
parent.selectAllTreeNodes(parent.rows, parent.selection)
|
|
112
142
|
} else {
|
|
@@ -495,6 +495,11 @@ export default {
|
|
|
495
495
|
|
|
496
496
|
if (!isSelected) {
|
|
497
497
|
selection.push(node)
|
|
498
|
+
|
|
499
|
+
// 更新表格UI选择状态
|
|
500
|
+
if (this.$refs.table && this.$refs.table.toggleRowSelection) {
|
|
501
|
+
this.$refs.table.toggleRowSelection(node, true)
|
|
502
|
+
}
|
|
498
503
|
}
|
|
499
504
|
|
|
500
505
|
// 递归处理子节点
|
|
@@ -516,13 +521,18 @@ export default {
|
|
|
516
521
|
const rowKeyValue = typeof this.rowKey === 'function' ? this.rowKey(node) : node[this.rowKey]
|
|
517
522
|
|
|
518
523
|
// 从选择中移除当前节点
|
|
519
|
-
const
|
|
524
|
+
const selectedIndex = selection.findIndex(s => {
|
|
520
525
|
const selectedKey = typeof this.rowKey === 'function' ? this.rowKey(s) : s[this.rowKey]
|
|
521
526
|
return selectedKey === rowKeyValue
|
|
522
527
|
})
|
|
523
528
|
|
|
524
|
-
if (
|
|
525
|
-
selection.splice(
|
|
529
|
+
if (selectedIndex > -1) {
|
|
530
|
+
selection.splice(selectedIndex, 1)
|
|
531
|
+
|
|
532
|
+
// 更新表格UI选择状态
|
|
533
|
+
if (this.$refs.table && this.$refs.table.toggleRowSelection) {
|
|
534
|
+
this.$refs.table.toggleRowSelection(node, false)
|
|
535
|
+
}
|
|
526
536
|
}
|
|
527
537
|
|
|
528
538
|
// 递归处理子节点
|
|
@@ -538,7 +548,21 @@ export default {
|
|
|
538
548
|
/** 检查是否启用树形全选 */
|
|
539
549
|
isTreeSelectAllEnabled() {
|
|
540
550
|
const treeSelectAllOptions = this.$_.assignIn({}, def.treeSelectAllOptions, this.treeSelectAll)
|
|
541
|
-
|
|
551
|
+
const enabled = treeSelectAllOptions.enabled
|
|
552
|
+
|
|
553
|
+
// 检查是否启用树形全选:需要同时满足以下条件:
|
|
554
|
+
// 1. treeSelectAll.enabled 为 true
|
|
555
|
+
// 2. treeProps 存在
|
|
556
|
+
// 3. treeProps.children 存在(可以是任何值,只要存在就行)
|
|
557
|
+
const hasTreeProps = !!this.treeProps
|
|
558
|
+
const hasChildrenProp = hasTreeProps && this.treeProps.children !== undefined && this.treeProps.children !== null
|
|
559
|
+
|
|
560
|
+
return enabled && hasTreeProps && hasChildrenProp
|
|
561
|
+
},
|
|
562
|
+
|
|
563
|
+
/** 获取选中的记录 */
|
|
564
|
+
getSelection() {
|
|
565
|
+
return this.selection
|
|
542
566
|
}
|
|
543
567
|
},
|
|
544
568
|
mounted() {
|
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<nm-list v-bind="list">
|
|
2
|
+
<nm-list ref="list" v-bind="list">
|
|
3
3
|
<template v-slot:querybar>
|
|
4
4
|
<el-form-item label="姓名:" prop="name">
|
|
5
5
|
<el-input v-model="list.model.name" />
|
|
6
6
|
</el-form-item>
|
|
7
7
|
</template>
|
|
8
8
|
|
|
9
|
+
<!-- 操作按钮 -->
|
|
10
|
+
<template v-slot:querybar-buttons>
|
|
11
|
+
<nm-button type="primary" text="显示选中" icon="view" @click="showSelection" />
|
|
12
|
+
</template>
|
|
13
|
+
|
|
9
14
|
<template v-slot:col-operation>
|
|
10
15
|
<nm-button type="text" text="编辑" icon="edit" />
|
|
11
16
|
<nm-button-delete type="text" :action="remove" id="1" @success="onSuccess" />
|
|
@@ -21,7 +26,24 @@
|
|
|
21
26
|
icon: 'list',
|
|
22
27
|
action: this.query,
|
|
23
28
|
rowKey: 'id',
|
|
29
|
+
|
|
30
|
+
/** 启用多选功能 */
|
|
31
|
+
multiple: true,
|
|
32
|
+
|
|
33
|
+
/** 树形全选配置 */
|
|
34
|
+
treeSelectAll: {
|
|
35
|
+
enabled: true, // 启用树形全选
|
|
36
|
+
defaultSelectAll: true // 默认全部选择
|
|
37
|
+
},
|
|
38
|
+
|
|
39
|
+
/** 树形表格配置 */
|
|
24
40
|
treeProps: { children: 'children', hasChildren: 'hasChildren' },
|
|
41
|
+
defaultExpandAll: true,
|
|
42
|
+
|
|
43
|
+
/** 选择列配置 */
|
|
44
|
+
selectionWidth: '55',
|
|
45
|
+
selectionFixed: true,
|
|
46
|
+
|
|
25
47
|
model: {
|
|
26
48
|
name: ''
|
|
27
49
|
},
|
|
@@ -84,6 +106,20 @@
|
|
|
84
106
|
remove() {},
|
|
85
107
|
onSuccess() {
|
|
86
108
|
this.query()
|
|
109
|
+
},
|
|
110
|
+
|
|
111
|
+
/** 显示选中的记录 */
|
|
112
|
+
showSelection() {
|
|
113
|
+
const listRef = this.$refs.list
|
|
114
|
+
if (listRef && listRef.getSelection) {
|
|
115
|
+
const selection = listRef.getSelection()
|
|
116
|
+
if (selection && selection.length > 0) {
|
|
117
|
+
const names = selection.map(item => item.name).join(', ')
|
|
118
|
+
this.$message.success(`已选中 ${selection.length} 条记录:${names}`)
|
|
119
|
+
} else {
|
|
120
|
+
this.$message.info('没有选中任何记录')
|
|
121
|
+
}
|
|
122
|
+
}
|
|
87
123
|
}
|
|
88
124
|
}
|
|
89
125
|
}
|