haiwei-ui 1.3.0 → 1.3.2

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.
@@ -13,7 +13,8 @@
13
13
  <section class="nm-tree-select-content">
14
14
  <!--搜索框-->
15
15
  <div class="nm-tree-select-search-wrapper">
16
- <el-input :size="fontSize" v-if="filterable" class="nm-tree-select-search" v-model="keyword" placeholder="请输入内容" prefix-icon="el-icon-search"></el-input>
16
+ <el-input :size="fontSize" v-if="filterable" class="nm-tree-select-search" v-model="keyword"
17
+ placeholder="请输入内容" prefix-icon="el-icon-search"></el-input>
17
18
  </div>
18
19
  <!--树结构-->
19
20
  <div class="nm-tree-select-tree-wrapper">
@@ -42,284 +43,285 @@
42
43
  </template>
43
44
  </nm-box>
44
45
  <!--展示-->
45
- <el-input ref="input" :value="label" class="nm-tree-select-input" :placeholder="placeholder" :disabled="disabled" :suffix-icon="visible ? 'el-icon-arrow-up' : 'el-icon-arrow-down'" readonly slot="reference"></el-input>
46
+ <el-input ref="input" :value="label" class="nm-tree-select-input" :placeholder="placeholder" :disabled="disabled"
47
+ :suffix-icon="visible ? 'el-icon-arrow-up' : 'el-icon-arrow-down'" readonly slot="reference"></el-input>
46
48
  </el-popover>
47
49
  </template>
48
50
  <script>
49
- export default {
50
- data() {
51
- return {
52
- title_: this.title,
53
- /**树配置 */
54
- treeOptions: {
55
- data: [],
56
- nodeKey: 'id',
57
- props: {
58
- children: 'children',
59
- label: 'label'
60
- },
61
- showCheckbox: true,
62
- checkStrictly: true,
63
- defaultExpandAll: this.defaultExpandAll,
64
- defaultExpandedKeys: [],
65
- filterNodeMethod: this.filterNode
51
+ export default {
52
+ data() {
53
+ return {
54
+ title_: this.title,
55
+ /**树配置 */
56
+ treeOptions: {
57
+ data: [],
58
+ nodeKey: 'id',
59
+ props: {
60
+ children: 'children',
61
+ label: 'label'
66
62
  },
67
- /**树事件 */
68
- treeOn: {
69
- check: this.onCheck,
70
- 'node-expand': this.onNodeExpand,
71
- 'node-collapse': this.onNodeCollapse
72
- },
73
- /**是否显示 */
74
- visible: false,
75
- /**输入框显示文本 */
76
- label: '',
77
- /**过滤关键字 */
78
- keyword: '',
79
- /**已选项 */
80
- selection: [],
81
- /**折叠状态 */
82
- collapsed: false,
83
- /**加载动画 */
84
- loading: false
85
- }
86
- },
87
- props: {
88
- value: [String, Number, Array],
89
- placeholder: {
90
- type: String,
91
- default: '请选择...'
92
- },
93
- /**头部标题 */
94
- title: {
95
- type: String,
96
- default: '请选择'
97
- },
98
- /**图标 */
99
- icon: {
100
- type: String,
101
- default: 'tree'
63
+ showCheckbox: true,
64
+ checkStrictly: true,
65
+ defaultExpandAll: this.defaultExpandAll,
66
+ defaultExpandedKeys: [],
67
+ filterNodeMethod: this.filterNode
102
68
  },
103
- /**宽度 */
104
- width: {
105
- type: String,
106
- default: '250px'
69
+ /**树事件 */
70
+ treeOn: {
71
+ check: this.onCheck,
72
+ 'node-expand': this.onNodeExpand,
73
+ 'node-collapse': this.onNodeCollapse
107
74
  },
108
- /**高度 */
109
- height: {
110
- type: String,
111
- default: '400px'
112
- },
113
- /**可搜索的 */
114
- filterable: Boolean,
115
- /**禁用的 */
116
- disabled: Boolean,
117
- /**多选 */
118
- multiple: Boolean,
119
- /**多选时最多可以选择的项目数,为 0 则不限制 */
120
- multipleLimit: {
121
- type: Number,
122
- default: 0
123
- },
124
- /**多选时展示用的分隔符 */
125
- separator: {
126
- type: String,
127
- default: '/'
128
- },
129
- /**是否显示折叠/展开全部按钮 */
130
- collapseAll: Boolean,
131
- /**默认展开所有 */
132
- defaultExpandAll: Boolean,
133
- /**不显示加载动画 */
134
- noLoading: Boolean,
135
- /**是否显示刷新按钮 */
136
- refresh: Boolean
75
+ /**是否显示 */
76
+ visible: false,
77
+ /**输入框显示文本 */
78
+ label: '',
79
+ /**过滤关键字 */
80
+ keyword: '',
81
+ /**已选项 */
82
+ selection: [],
83
+ /**折叠状态 */
84
+ collapsed: false,
85
+ /**加载动画 */
86
+ loading: false
87
+ }
88
+ },
89
+ props: {
90
+ value: [String, Number, Array],
91
+ placeholder: {
92
+ type: String,
93
+ default: '请选择...'
137
94
  },
138
- computed: {
139
- popperClass() {
140
- return `nm-tree-select-popover ${this.filterable ? 'filterable' : ''}`
141
- },
142
- selection_() {
143
- let sl = this.selection
144
- return this.multiple ? sl.map(m => m) : sl.length > 0 ? sl[0] : null
145
- },
146
- /**已选中的值 */
147
- value_() {
148
- let sl = this.selection
149
- return this.multiple ? sl.map(m => m.id) : sl.length > 0 ? sl[0].id : ''
150
- },
151
- showLoading() {
152
- return !this.noLoading && this.loading
153
- }
95
+ /**头部标题 */
96
+ title: {
97
+ type: String,
98
+ default: '请选择'
154
99
  },
155
- methods: {
156
- refreshTree() {
157
- this.loading = true
158
- this.action().then(data => {
159
- this.treeOptions.data = data
160
- this.change()
161
- this.loading = false
162
- })
163
- },
164
- /**
165
- * @description 选项更改处理
166
- */
167
- change() {
168
- if (!this.value) return
169
-
170
- let data = this.treeOptions.data
171
- if (data.length < 1) return
100
+ /**图标 */
101
+ icon: {
102
+ type: String,
103
+ default: 'tree'
104
+ },
105
+ /**宽度 */
106
+ width: {
107
+ type: String,
108
+ default: '250px'
109
+ },
110
+ /**高度 */
111
+ height: {
112
+ type: String,
113
+ default: '400px'
114
+ },
115
+ /**可搜索的 */
116
+ filterable: Boolean,
117
+ /**禁用的 */
118
+ disabled: Boolean,
119
+ /**多选 */
120
+ multiple: Boolean,
121
+ /**多选时最多可以选择的项目数,为 0 则不限制 */
122
+ multipleLimit: {
123
+ type: Number,
124
+ default: 0
125
+ },
126
+ /**多选时展示用的分隔符 */
127
+ separator: {
128
+ type: String,
129
+ default: '/'
130
+ },
131
+ /**是否显示折叠/展开全部按钮 */
132
+ collapseAll: Boolean,
133
+ /**默认展开所有 */
134
+ defaultExpandAll: Boolean,
135
+ /**不显示加载动画 */
136
+ noLoading: Boolean,
137
+ /**是否显示刷新按钮 */
138
+ refresh: Boolean
139
+ },
140
+ computed: {
141
+ popperClass() {
142
+ return `nm-tree-select-popover ${this.filterable ? 'filterable' : ''}`
143
+ },
144
+ selection_() {
145
+ let sl = this.selection
146
+ return this.multiple ? sl.map(m => m) : sl.length > 0 ? sl[0] : null
147
+ },
148
+ /**已选中的值 */
149
+ value_() {
150
+ let sl = this.selection
151
+ return this.multiple ? sl.map(m => m.id) : sl.length > 0 ? sl[0].id : ''
152
+ },
153
+ showLoading() {
154
+ return !this.noLoading && this.loading
155
+ }
156
+ },
157
+ methods: {
158
+ refreshTree() {
159
+ this.loading = true
160
+ this.action().then(data => {
161
+ this.treeOptions.data = data
162
+ this.change()
163
+ this.loading = false
164
+ })
165
+ },
166
+ /**
167
+ * @description 选项更改处理
168
+ */
169
+ change() {
170
+ if (!this.value) return
172
171
 
173
- let value = this.multiple ? this.value : [this.value]
172
+ let data = this.treeOptions.data
173
+ if (data.length < 1) return
174
174
 
175
- //设置显示文本
176
- this.setLabel(value)
177
- //清除已选项
178
- this.selection = []
179
- //要展开的选项
180
- this.treeOptions.defaultExpandedKeys = value
175
+ let value = this.multiple ? this.value : [this.value]
181
176
 
182
- this.$nextTick(() => {
183
- this.setCheckedKeys(value)
184
- this.$emit('change', this.value_, this.selection_)
185
- })
186
- },
187
- /**保存 */
188
- save() {
189
- if (this.multiple && this.multipleLimit > 0 && this.selection.length > this.multipleLimit) {
190
- this.showLimitMsg()
191
- return
192
- }
193
- this.setLabel(this.multiple ? this.value_ : [this.value_])
194
- this.$emit('input', this.value_)
195
- this.$emit('change', this.value_, this.selection_)
196
- this.visible = false
197
- },
198
- /**重置 */
199
- reset() {
200
- this.selection = this.multiple ? [] : ''
201
- this.setCheckedKeys([])
177
+ //设置显示文本
178
+ this.setLabel(value)
179
+ //清除已选项
180
+ this.selection = []
181
+ //要展开的选项
182
+ this.treeOptions.defaultExpandedKeys = value
202
183
 
203
- this.setLabel(this.multiple ? this.value_ : [this.value_])
204
- this.$emit('input', this.value_)
184
+ this.$nextTick(() => {
185
+ this.setCheckedKeys(value)
205
186
  this.$emit('change', this.value_, this.selection_)
206
- },
207
- setLabel(ids) {
208
- let datas = []
209
- if (ids && ids.length > 0) {
210
- ids.map(m => {
211
- let nodeData = this.getNodeData(this.treeOptions.data, m)
212
- if (nodeData) {
213
- datas.push(nodeData)
214
- }
215
- })
216
- }
217
- this.label = datas.map(m => m.label).join(` ${this.separator} `)
218
- },
219
- //递归获取当前数据对象
220
- getNodeData(list, id) {
221
- for (let i = 0; i < list.length; i++) {
222
- const m = list[i]
223
- if (m.id === id) {
224
- return m
225
- }
187
+ })
188
+ },
189
+ /**保存 */
190
+ save() {
191
+ if (this.multiple && this.multipleLimit > 0 && this.selection.length > this.multipleLimit) {
192
+ this.showLimitMsg()
193
+ return
194
+ }
195
+ this.setLabel(this.multiple ? this.value_ : [this.value_])
196
+ this.$emit('input', this.value_)
197
+ this.$emit('change', this.value_, this.selection_)
198
+ this.visible = false
199
+ },
200
+ /**重置 */
201
+ reset() {
202
+ this.selection = this.multiple ? [] : ''
203
+ this.setCheckedKeys([])
226
204
 
227
- if (m.children) {
228
- const nodeData = this.getNodeData(m.children, id)
229
- if (nodeData != null) return nodeData
230
- }
231
- }
232
- return null
233
- },
234
- /**设置选中 */
235
- setCheckedKeys(keys) {
236
- this.$refs.tree.setCheckedKeys(keys || this.selection.map(m => m.id))
237
- },
238
- /**过滤方法 */
239
- filterNode(value, data) {
240
- if (!value) return true
241
- return data.label.indexOf(value) !== -1
242
- },
243
- /**显示限制提醒消息 */
244
- showLimitMsg() {
245
- this._warning(`最多只能选择${this.multipleLimit}个`)
246
- },
247
- /**复选框点击事件 */
248
- onCheck(data, curr) {
249
- const { checkedNodes, checkedKeys } = curr
250
- if (this.multiple) {
251
- if (this.multipleLimit > 0 && checkedKeys.length > this.multipleLimit) {
252
- this.showLimitMsg()
253
- this.setCheckedKeys() //恢复
254
- return
205
+ this.setLabel(this.multiple ? this.value_ : [this.value_])
206
+ this.$emit('input', this.value_)
207
+ this.$emit('change', this.value_, this.selection_)
208
+ },
209
+ setLabel(ids) {
210
+ let datas = []
211
+ if (ids && ids.length > 0) {
212
+ ids.map(m => {
213
+ let nodeData = this.getNodeData(this.treeOptions.data, m)
214
+ if (nodeData) {
215
+ datas.push(nodeData)
255
216
  }
256
- this.selection = checkedNodes.map(m => m.item)
257
- } else {
258
- this.selection = checkedKeys.length > 0 ? [data.item] : []
259
- this.setCheckedKeys()
217
+ })
218
+ }
219
+ this.label = datas.map(m => m.label).join(` ${this.separator} `)
220
+ },
221
+ //递归获取当前数据对象
222
+ getNodeData(list, id) {
223
+ for (let i = 0; i < list.length; i++) {
224
+ const m = list[i]
225
+ if (m.id === id) {
226
+ return m
260
227
  }
261
228
 
262
- this.$emit('check', data, curr)
263
- },
264
- /**折叠展开全部事件 */
265
- onCollapseAll() {
266
- this.collapsed = !this.collapsed
267
- let treeStore = this.$refs.tree.store
268
- for (var i = 0; i < treeStore._getAllNodes().length; i++) {
269
- treeStore._getAllNodes()[i].expanded = !this.collapsed
229
+ if (m.children) {
230
+ const nodeData = this.getNodeData(m.children, id)
231
+ if (nodeData != null) return nodeData
270
232
  }
271
- },
272
- /**节点被点击时的回调 */
273
- onNodeClick(data, node, cmp) {
274
- this.$emit('node-click', data, node, cmp)
275
- },
276
- /**节点选中状态发生变化时的回调 */
277
- onCheckChange(data, checked, indeterminate) {
278
- this.$emit('check-change', data, checked, indeterminate)
279
- },
280
- /**当前选中节点变化时触发的事件 */
281
- onCurrentChange(data, node) {
282
- this.$emit('current-change', data, node)
283
- },
284
- /**节点被展开时触发的事件 */
285
- onNodeExpand(data, node, cmp) {
286
- //记录展开的节点
287
- this.treeOptions.defaultExpandedKeys.push(data.id)
288
- this.$emit('node-expand', data, node, cmp)
289
- },
290
- /**节点被关闭时触发的事件 */
291
- onNodeCollapse(data, node, cmp) {
292
- //移除展开的节点
293
- this.$_.pull(this.treeOptions.defaultExpandedKeys, data.id)
294
- this.$emit('node-collapse', data, node, cmp)
295
233
  }
234
+ return null
296
235
  },
297
- created() {
298
- this.refreshTree()
236
+ /**设置选中 */
237
+ setCheckedKeys(keys) {
238
+ this.$refs.tree.setCheckedKeys(keys || this.selection.map(m => m.id))
299
239
  },
300
- mounted() {
301
- this.$nextTick(() => {
302
- //初始化宽高
303
- let el = this.$refs.popover.$el.querySelector('.el-popover')
304
- el.style.height = this.height
305
- el.style.width = this.width
306
- })
240
+ /**过滤方法 */
241
+ filterNode(value, data) {
242
+ if (!value) return true
243
+ return data.label.indexOf(value) !== -1
307
244
  },
308
- watch: {
309
- title(val) {
310
- this.title_ = val
311
- },
312
- value(val) {
313
- if (val !== this.value_) {
314
- this.change()
245
+ /**显示限制提醒消息 */
246
+ showLimitMsg() {
247
+ this._warning(`最多只能选择${this.multipleLimit}个`)
248
+ },
249
+ /**复选框点击事件 */
250
+ onCheck(data, curr) {
251
+ const { checkedNodes, checkedKeys } = curr
252
+ if (this.multiple) {
253
+ if (this.multipleLimit > 0 && checkedKeys.length > this.multipleLimit) {
254
+ this.showLimitMsg()
255
+ this.setCheckedKeys() //恢复
256
+ return
315
257
  }
316
- },
317
- defaultExpandAll(val) {
318
- this.treeOptions.defaultExpandAll = val
319
- },
320
- keyword(val) {
321
- if (this.filterable) this.$refs.tree.filter(val)
258
+ this.selection = checkedNodes.map(m => m.item)
259
+ } else {
260
+ this.selection = checkedKeys.length > 0 ? [data.item] : []
261
+ this.setCheckedKeys()
262
+ }
263
+
264
+ this.$emit('check', data, curr)
265
+ },
266
+ /**折叠展开全部事件 */
267
+ onCollapseAll() {
268
+ this.collapsed = !this.collapsed
269
+ let treeStore = this.$refs.tree.store
270
+ for (var i = 0; i < treeStore._getAllNodes().length; i++) {
271
+ treeStore._getAllNodes()[i].expanded = !this.collapsed
322
272
  }
273
+ },
274
+ /**节点被点击时的回调 */
275
+ onNodeClick(data, node, cmp) {
276
+ this.$emit('node-click', data, node, cmp)
277
+ },
278
+ /**节点选中状态发生变化时的回调 */
279
+ onCheckChange(data, checked, indeterminate) {
280
+ this.$emit('check-change', data, checked, indeterminate)
281
+ },
282
+ /**当前选中节点变化时触发的事件 */
283
+ onCurrentChange(data, node) {
284
+ this.$emit('current-change', data, node)
285
+ },
286
+ /**节点被展开时触发的事件 */
287
+ onNodeExpand(data, node, cmp) {
288
+ //记录展开的节点
289
+ this.treeOptions.defaultExpandedKeys.push(data.id)
290
+ this.$emit('node-expand', data, node, cmp)
291
+ },
292
+ /**节点被关闭时触发的事件 */
293
+ onNodeCollapse(data, node, cmp) {
294
+ //移除展开的节点
295
+ this.$_.pull(this.treeOptions.defaultExpandedKeys, data.id)
296
+ this.$emit('node-collapse', data, node, cmp)
297
+ }
298
+ },
299
+ created() {
300
+ this.refreshTree()
301
+ },
302
+ mounted() {
303
+ this.$nextTick(() => {
304
+ //初始化宽高
305
+ let el = this.$refs.popover.$el.querySelector('.el-popover')
306
+ el.style.height = this.height
307
+ el.style.width = this.width
308
+ })
309
+ },
310
+ watch: {
311
+ title(val) {
312
+ this.title_ = val
313
+ },
314
+ value(val) {
315
+ if (val !== this.value_) {
316
+ this.change()
317
+ }
318
+ },
319
+ defaultExpandAll(val) {
320
+ this.treeOptions.defaultExpandAll = val
321
+ },
322
+ keyword(val) {
323
+ if (this.filterable) this.$refs.tree.filter(val)
323
324
  }
324
325
  }
326
+ }
325
327
  </script>
@@ -5,23 +5,23 @@
5
5
  </div>
6
6
  </template>
7
7
  <script>
8
- export default {
9
- name: 'Txt',
10
- props: {
11
- // 文本
12
- text: String,
13
- // 类型 primary\success\warning\danger
14
- type: {
15
- type: String,
16
- default: 'warning'
17
- },
18
- /** 显示图标 */
19
- icon: Boolean,
20
- /** 字体大小 */
21
- size: {
22
- type: [Number, String],
23
- default: 12
24
- }
8
+ export default {
9
+ name: 'Txt',
10
+ props: {
11
+ // 文本
12
+ text: String,
13
+ // 类型 primary\success\warning\danger
14
+ type: {
15
+ type: String,
16
+ default: 'warning'
17
+ },
18
+ /** 显示图标 */
19
+ icon: Boolean,
20
+ /** 字体大小 */
21
+ size: {
22
+ type: [Number, String],
23
+ default: 12
25
24
  }
26
25
  }
26
+ }
27
27
  </script>