bri-components 1.2.54 → 1.2.56

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.
@@ -2,6 +2,7 @@
2
2
  <div class="cascaderPicker">
3
3
  <Dropdown
4
4
  style="width: 100%;"
5
+ v-clickoutside="clickCancel"
5
6
  trigger="custom"
6
7
  :visible="showModal"
7
8
  :placement="placement"
@@ -13,7 +14,7 @@
13
14
  <div @click.stop="clickInput">
14
15
  <slot>
15
16
  <Input
16
- :value="activeStr"
17
+ v-model="inputStr"
17
18
  :placeholder="selfPropsObj._placeholder"
18
19
  :disabled="selfPropsObj._disabled"
19
20
  :readonly="true"
@@ -27,47 +28,51 @@
27
28
  <div
28
29
  slot="list"
29
30
  class="wrap"
31
+ @click.stop="0"
30
32
  >
31
- <!-- 按钮 -->
33
+ <!-- 头部 -->
32
34
  <div class="wrap-header">
33
35
  <!-- 搜索 -->
34
36
  <div class="wrap-header-left">
35
- <Input
36
- v-if="filterable"
37
- class="search"
38
- v-model="searchName"
39
- placeholder="请输入关键字或标识"
40
- search
41
- @on-enter="search"
42
- @on-search="search"
43
- @on-change="search"
44
- />
45
-
46
- <template>
47
- <div
48
- v-if="useMode"
49
- class="mode"
50
- @click="showMode = showMode === 'default' ? 'flat' : 'default'"
51
- >
52
- <dsh-icons :list="[{ icon: 'md-swap' }]" />
53
- <span class="mode-name">
54
- {{ showMode === "default" ? "按层级" : "按平级" }}
55
- </span>
56
- </div>
57
-
58
- <Tooltip
59
- v-else
60
- style="margin-left: 5px; cursor: pointer;"
61
- content="在搜索时,会出现层级和平级切换开关,但搜索出的结果超100个时,将不支持使用模式切换,因为此时平级方式不方便,不适用"
62
- max-width="250"
63
- transfer
64
- >
65
- <Icon
66
- class="item-header-help"
67
- type="md-help-circle"
68
- size="16"
69
- ></Icon>
70
- </Tooltip>
37
+ <template v-if="filterable">
38
+ <!-- 搜索框 -->
39
+ <Input
40
+ class="search"
41
+ v-model="searchName"
42
+ placeholder="请输入关键字或标识"
43
+ search
44
+ @on-enter="search"
45
+ @on-search="search"
46
+ @on-change="search"
47
+ />
48
+
49
+ <!-- 模式切换 -->
50
+ <template>
51
+ <div
52
+ v-if="canUseModeSwitch"
53
+ class="mode"
54
+ @click="showMode = showMode === 'default' ? 'flat' : 'default'"
55
+ >
56
+ <dsh-icons :list="[{ icon: 'md-swap' }]" />
57
+ <span class="mode-name">
58
+ {{ showMode === "default" ? "按层级" : "按平级" }}
59
+ </span>
60
+ </div>
61
+
62
+ <Tooltip
63
+ v-else
64
+ style="margin-left: 5px; cursor: pointer;"
65
+ :content="modeTip"
66
+ max-width="250"
67
+ transfer
68
+ >
69
+ <Icon
70
+ class="item-header-help"
71
+ type="md-help-circle"
72
+ size="16"
73
+ ></Icon>
74
+ </Tooltip>
75
+ </template>
71
76
  </template>
72
77
  </div>
73
78
 
@@ -84,7 +89,7 @@
84
89
  <!-- 选中项tabs -->
85
90
  <div class="wrap-content-tabs">
86
91
  <span
87
- v-for="(tabItem, tabIndex) in curSelectLinealDatas"
92
+ v-for="(tabItem, tabIndex) in selectedLinealDatas"
88
93
  :key="tabIndex"
89
94
  class="item"
90
95
  @click="curTabIndex = tabIndex"
@@ -102,68 +107,64 @@
102
107
  <!-- 列表 -->
103
108
  <div class="wrap-content-list">
104
109
  <!-- 有数据 -->
105
- <DropdownMenu
110
+ <div
106
111
  v-if="showTreeData.length"
107
112
  class="wrap-content-list-menu"
108
113
  >
109
114
  <!-- 拍平方式 -->
110
115
  <template v-if="useFlatMode">
111
- <DropdownItem
112
- v-for="dataItem in showFlatData"
113
- :key="dataItem[valueKey]"
116
+ <div
117
+ v-for="nodeItem in showFlatData"
118
+ :key="nodeItem[valueKey]"
114
119
  :class="{
115
120
  'item': true,
116
- 'item-active': curSelectObj && dataItem[valueKey] === curSelectObj[valueKey],
117
- 'item-disabled': dataItem.disabled
121
+ 'item-active': selectedLastOption && nodeItem[valueKey] === selectedLastOption[valueKey],
122
+ 'item-disabled': nodeItem.disabled
118
123
  }"
119
- :name="dataItem[valueKey]"
120
- :disabled="dataItem.disabled"
121
- @click.native.stop="clickItem(dataItem)"
124
+ @click="clickItem(nodeItem)"
122
125
  >
123
126
  <span class="item-name">
124
- {{ dataItem[nameKey] }}
127
+ {{ nodeItem[nameKey] }}
125
128
  </span>
126
129
 
127
130
  <span class="item-icon">
128
131
  <dsh-icons :list="[{
129
- icon: curSelectObj && dataItem[valueKey] === curSelectObj[valueKey]
132
+ icon: selectedLastOption && nodeItem[valueKey] === selectedLastOption[valueKey]
130
133
  ? 'md-checkmark'
131
134
  : ''
132
135
  }]" />
133
136
  </span>
134
- </DropdownItem>
137
+ </div>
135
138
  </template>
136
139
 
137
140
  <!-- 层级方式 -->
138
141
  <template v-else>
139
- <DropdownItem
140
- v-for="dataItem in curSelectLinealData.data"
141
- :key="dataItem[valueKey]"
142
+ <div
143
+ v-for="nodeItem in curSelectedLinealData.data"
144
+ :key="nodeItem[valueKey]"
142
145
  :class="{
143
146
  'item': true,
144
- 'item-active': dataItem[valueKey] === curSelectLinealData[valueKey],
145
- 'item-disabled': dataItem.disabled
147
+ 'item-active': nodeItem[valueKey] === curSelectedLinealData[valueKey],
148
+ 'item-disabled': nodeItem.disabled
146
149
  }"
147
- :name="dataItem[valueKey]"
148
- :disabled="dataItem.disabled"
149
- @click.native.stop="clickItem(dataItem)"
150
+ @click="clickItem(nodeItem)"
150
151
  >
151
152
  <span class="item-name">
152
- {{ dataItem[nameKey] }}
153
+ {{ nodeItem[nameKey] }}
153
154
  </span>
154
155
 
155
156
  <span class="item-icon">
156
157
  <dsh-icons :list="[{
157
- icon: dataItem[valueKey] === curSelectLinealData[valueKey]
158
+ icon: nodeItem[valueKey] === curSelectedLinealData[valueKey]
158
159
  ? 'md-checkmark'
159
- : dataItem.children.length
160
+ : nodeItem.children.length
160
161
  ? 'ios-arrow-forward'
161
162
  : ''
162
163
  }]" />
163
164
  </span>
164
- </DropdownItem>
165
+ </div>
165
166
  </template>
166
- </DropdownMenu>
167
+ </div>
167
168
 
168
169
  <!-- 无数据 -->
169
170
  <div
@@ -180,39 +181,15 @@
180
181
  </template>
181
182
 
182
183
  <script>
184
+ import cascaderPickerMixin from "./cascaderPickerMixin.js";
185
+
183
186
  export default {
184
187
  name: "cascaderPicker",
185
- mixins: [],
188
+ mixins: [
189
+ cascaderPickerMixin
190
+ ],
186
191
  components: {},
187
192
  props: {
188
- value: {
189
- type: Boolean,
190
- default: false
191
- },
192
-
193
- activeValue: {
194
- type: Array,
195
- default () {
196
- return [];
197
- }
198
- },
199
- activeStr: {
200
- type: String,
201
- default: ""
202
- },
203
- data: {
204
- type: Array,
205
- drfault () {
206
- return [];
207
- }
208
- },
209
- propsObj: {
210
- type: Object,
211
- default () {
212
- return {};
213
- }
214
- },
215
-
216
193
  placement: {
217
194
  type: String,
218
195
  default: "bottom-start"
@@ -220,103 +197,15 @@
220
197
  },
221
198
  data () {
222
199
  return {
223
- searchName: "",
224
- showMode: "default", // "flat", "default"
225
-
226
- curTabIndex: 0,
227
- curSelectObj: undefined,
228
- curSelectVal: [],
229
-
230
- operationMap: {
231
- canCancel: {
232
- name: "取消",
233
- type: "canCancel",
234
- btnType: "cancel",
235
- size: "small",
236
- event: "clickCancel"
237
- },
238
- canConfirm: {
239
- name: "确认",
240
- type: "canConfirm",
241
- btnType: "primary",
242
- size: "small",
243
- event: "clickConfirm"
244
- }
245
- }
200
+ curTabIndex: 0
246
201
  };
247
202
  },
248
203
  computed: {
249
- showModal: {
250
- get () {
251
- return this.value;
252
- },
253
- set (bool) {
254
- this.$emit("input", bool);
255
- }
256
- },
257
-
258
- selfPropsObj () {
259
- return {
260
- ...this.propsObj
261
- };
262
- },
263
- filterable () {
264
- return this.selfPropsObj._filterable;
265
- },
266
- changeOnSelect () {
267
- return this.selfPropsObj._changeOnSelect;
268
- },
269
- saveKey () {
270
- return this.selfPropsObj._saveKey;
271
- },
272
- valueKey () {
273
- return this.selfPropsObj._valueKey;
274
- },
275
- nameKey () {
276
- return this.selfPropsObj._nameKey;
204
+ initData () {
205
+ return this.data;
277
206
  },
278
- renderFormat () {
279
- return this.selfPropsObj._renderFormat;
280
- },
281
-
282
- useMode () {
283
- return this.filterable &&
284
- this.searchName.trim() &&
285
- this.showFlatData.length < 200;
286
- },
287
- useFlatMode () {
288
- return this.useMode &&
289
- this.showMode === "flat";
290
- },
291
- showTreeData () {
292
- return this.$getTreeDataByMatchFunc(node => {
293
- return (
294
- this.changeOnSelect
295
- ? true
296
- : node.isLeaf
297
- ) && (
298
- this.searchName.trim()
299
- ? node[this.nameKey].includes(this.searchName.trim()) || node[this.valueKey].includes(this.searchName.trim())
300
- : true
301
- );
302
- }, this.data);
303
- },
304
- showFlatData () {
305
- return this.$getTreeLinealDatasArr(this.showTreeData).map(arrItem => {
306
- return {
307
- ...arrItem.slice(-1)[0],
308
- [this.nameKey]: this.renderFormat(arrItem.map(item => item[this.nameKey]))
309
- };
310
- });
311
- },
312
- curSelectedOptions () {
313
- return this.$getTreeLinealDatas(this.curSelectVal, this.showTreeData, undefined, this.saveKey);
314
- },
315
- curSelectLinealData () {
316
- return this.curSelectLinealDatas[this.curTabIndex];
317
- },
318
- curSelectLinealDatas () {
319
- const arr = this.curSelectedOptions.map((item, index, list) => {
207
+ selectedLinealDatas () {
208
+ const arr = this.selectedOptions.map((item, index, list) => {
320
209
  return {
321
210
  ...item,
322
211
  data: index === 0 ? this.showTreeData : list[index - 1].children
@@ -327,66 +216,50 @@
327
216
  ...arr,
328
217
 
329
218
  ...(
330
- this.curSelectedOptions.length === 0
331
- ? [
332
- {
333
- data: this.showTreeData
334
- }
335
- ]
336
- : this.curTabIndex + 1 > this.curSelectedOptions.length && this.curSelectedOptions.slice(-1)[0].children.length
219
+ this.selectedOptions.length
220
+ ? this.selectedLastOption.children.length && this.curTabIndex + 1 > this.selectedOptions.length
337
221
  ? [
338
222
  {
339
- data: this.curSelectedOptions.slice(-1)[0].children
223
+ data: this.selectedLastOption.children
340
224
  }
341
225
  ]
342
226
  : []
227
+ : [
228
+ {
229
+ data: this.showTreeData
230
+ }
231
+ ]
343
232
  )
344
233
  ];
234
+ },
235
+ curSelectedLinealData () {
236
+ return this.selectedLinealDatas[this.curTabIndex];
345
237
  }
346
238
  },
347
239
  created () {
348
240
  this.init();
349
241
  },
350
242
  methods: {
243
+ // 初始化
351
244
  init () {
352
- this.curSelectVal = this.activeValue;
353
- this.curTabIndex = this.curSelectVal.length === 0 ? 0 : this.curSelectVal.length - 1;
245
+ this.selectedValue = this.activeValue;
246
+ this.curTabIndex = this.selectedOptions.length
247
+ ? this.selectedLastOption.children.length
248
+ ? this.selectedOptions.length
249
+ : this.selectedOptions.length - 1
250
+ : 0;
354
251
  },
355
252
 
356
253
  search () {
357
- this.curSelectVal = [];
254
+ this.selectedValue = [];
255
+ this.showMode = "default";
358
256
  this.curTabIndex = 0;
359
257
  },
360
- clickInput () {
361
- if (!this.selfPropsObj._disabled) {
362
- this.showModal = true;
363
- }
364
- },
365
- clickItem (dataItem) {
366
- this.curSelectObj = dataItem;
367
- this.curOldSelectVal = this.curSelectVal;
368
- this.curSelectVal = dataItem.keys;
369
- // 过滤重复点击
370
- if (JSON.stringify(this.curSelectVal) !== JSON.stringify(this.curOldSelectVal)) {
371
- const obj = {
372
- value: this.curSelectVal,
373
- selectedOptions: this.curSelectedOptions,
374
- tabIndex: this.curTabIndex
375
- };
376
- this.$emit("change", obj);
377
- !dataItem.children.length && this.$emit("finish", obj);
378
- }
379
-
258
+ clickItemCb (node) {
380
259
  // 区分展示方式
381
- if (this.showMode === "default" && dataItem.children.length) {
260
+ if (this.showMode === "default" && node.children.length) {
382
261
  this.curTabIndex = this.curTabIndex + 1;
383
262
  }
384
- },
385
- clickCancel () {
386
- this.showModal = false;
387
- },
388
- clickConfirm () {
389
- this.$emit("confirm", this.curSelectVal, this.curSelectedOptions);
390
263
  }
391
264
  }
392
265
  };
@@ -395,11 +268,13 @@
395
268
  <style lang="less">
396
269
  .cascaderPicker {
397
270
  &-down {
398
- min-width: 400px;
399
- max-width: 400px;
400
- max-height: 600px; // 必须有
401
- border: 0.5px solid #e5e5e5;
402
- box-shadow: 0 3px 14px 2px rgba(0,0,0,0.05), 0 8px 10px 1px rgba(0,0,0,0.06), 0 5px 5px -3px rgba(0,0,0,0.1);
271
+ &.ivu-select-dropdown {
272
+ min-width: 400px;
273
+ max-width: 400px;
274
+ max-height: 600px; // 必须有
275
+ border: 0.5px solid #e5e5e5;
276
+ box-shadow: 0 3px 14px 2px rgba(0,0,0,0.05), 0 8px 10px 1px rgba(0,0,0,0.06), 0 5px 5px -3px rgba(0,0,0,0.1);
277
+ }
403
278
 
404
279
  .wrap {
405
280
  &-header {
@@ -484,6 +359,7 @@
484
359
  padding: 8px 10px;
485
360
  border-radius: @borderRadius;
486
361
  line-height: 16px;
362
+ cursor: pointer;
487
363
  display: flex;
488
364
  flex-direction: row;
489
365
  justify-content: space-between;
@@ -0,0 +1,202 @@
1
+ export default {
2
+ mixins: [],
3
+ components: {},
4
+ props: {
5
+ value: {
6
+ type: Boolean,
7
+ default: false
8
+ },
9
+
10
+ activeValue: {
11
+ type: Array,
12
+ default () {
13
+ return [];
14
+ }
15
+ },
16
+ activeStr: {
17
+ type: String,
18
+ default: ""
19
+ },
20
+ data: {
21
+ type: Array,
22
+ drfault () {
23
+ return [];
24
+ }
25
+ },
26
+ propsObj: {
27
+ type: Object,
28
+ default () {
29
+ return {};
30
+ }
31
+ }
32
+ },
33
+ data () {
34
+ return {
35
+ searchName: "",
36
+ showMode: "default", // "flat", "default"
37
+ maxFlatModeSearchNum: 80,
38
+
39
+ selectedValue: [],
40
+
41
+ operationMap: {
42
+ canCancel: {
43
+ name: "取消",
44
+ type: "canCancel",
45
+ btnType: "cancel",
46
+ size: "small",
47
+ event: "clickCancel"
48
+ },
49
+ canConfirm: {
50
+ name: "确认",
51
+ type: "canConfirm",
52
+ btnType: "primary",
53
+ size: "small",
54
+ event: "clickConfirm"
55
+ }
56
+ }
57
+ };
58
+ },
59
+ computed: {
60
+ showModal: {
61
+ get () {
62
+ return this.value;
63
+ },
64
+ set (bool) {
65
+ this.$emit("input", bool);
66
+ }
67
+ },
68
+
69
+ selfPropsObj () {
70
+ return {
71
+ ...this.propsObj
72
+ };
73
+ },
74
+ filterable () {
75
+ return this.selfPropsObj._filterable;
76
+ },
77
+ changeOnSelect () {
78
+ return this.selfPropsObj._changeOnSelect;
79
+ },
80
+ saveKey () {
81
+ return this.selfPropsObj._saveKey;
82
+ },
83
+ valueKey () {
84
+ return this.selfPropsObj._valueKey;
85
+ },
86
+ nameKey () {
87
+ return this.selfPropsObj._nameKey;
88
+ },
89
+ renderFormat () {
90
+ return this.selfPropsObj._renderFormat;
91
+ },
92
+ resourceKey () {
93
+ return this.selfPropsObj._resourceKey;
94
+ },
95
+
96
+ canUseModeSwitch () {
97
+ return this.searchName.trim() &&
98
+ this.showFlatData.length < this.maxFlatModeSearchNum;
99
+ },
100
+ useFlatMode () {
101
+ return this.filterable &&
102
+ this.canUseModeSwitch &&
103
+ this.showMode === "flat";
104
+ },
105
+ modeTip () {
106
+ return `在搜索时,会出现层级和平级切换开关,但搜索出的结果超${this.maxFlatModeSearchNum}个时,\
107
+ 将不支持使用模式切换,因为此时平级方式不方便,不适用`;
108
+ },
109
+
110
+ inputStr: {
111
+ get () {
112
+ return this.activeStr;
113
+ },
114
+ set (str) {
115
+ if (!str) {
116
+ this.$emit("clear", []);
117
+ }
118
+ }
119
+ },
120
+ matchFunc () {
121
+ return node => {
122
+ return (
123
+ this.changeOnSelect
124
+ ? true
125
+ : node.isLeaf
126
+ ) && (
127
+ this.searchName.trim()
128
+ ? node[this.nameKey].includes(this.searchName.trim()) || node[this.valueKey].includes(this.searchName.trim())
129
+ : true
130
+ );
131
+ };
132
+ },
133
+ showTreeData () {
134
+ return this.$getTreeDataByMatchFunc(this.matchFunc, this.initData);
135
+ },
136
+ showFlatData () {
137
+ return this.$getListDataByMatchFunc(this.matchFunc, this.initData).map(arrItem => {
138
+ return {
139
+ ...arrItem.slice(-1)[0],
140
+ [this.nameKey]: this.renderFormat(arrItem.map(item => item[this.nameKey]))
141
+ };
142
+ });
143
+ },
144
+ // 选中项 -各级数据对象集合
145
+ selectedOptions () {
146
+ return this.$getTreeLinealDatas(this.selectedValue, this.showTreeData, undefined, this.saveKey);
147
+ },
148
+ // 选中项 -最后一级数据对象
149
+ selectedLastOption () {
150
+ return this.selectedOptions.slice(-1)[0];
151
+ },
152
+ // 选中项 -名字
153
+ selectedName () {
154
+ return this.selectedLastOption ? this.selectedLastOption[this.nameKey] : "";
155
+ }
156
+ },
157
+ created () { },
158
+ methods: {
159
+ clickInput () {
160
+ if (!this.selfPropsObj._disabled) {
161
+ this.showModal = true;
162
+ }
163
+ },
164
+ clickItem (node) {
165
+ this.oldSelectedValue = this.selectedValue;
166
+ this.selectedValue = node.keys;
167
+ // 避免重复点击
168
+ if (JSON.stringify(this.selectedValue) !== JSON.stringify(this.oldSelectedValue)) {
169
+ const obj = {
170
+ value: this.selectedValue,
171
+ selectedOptions: this.selectedOptions,
172
+ tabIndex: this.curTabIndex
173
+ };
174
+ this.$emit("change", obj);
175
+ !node.children.length && this.$emit("finish", obj);
176
+ }
177
+
178
+ this.clickItemCb && this.clickItemCb(node);
179
+ },
180
+ clickCancel () {
181
+ this.showModal = false;
182
+ },
183
+ clickConfirm () {
184
+ if (this.selectedValue.length && this.selectedOptions.length) {
185
+ if (!this.changeOnSelect && !this.selectedLastOption.isLeaf) {
186
+ this.$Message.error({
187
+ content: "请选择到末级数据!",
188
+ duration: 2
189
+ });
190
+ } else {
191
+ this.$emit("confirm", this.selectedValue, this.selectedOptions);
192
+ }
193
+ } else {
194
+ this.$Message.error({
195
+ content: "请选择数据!",
196
+ duration: 2
197
+ });
198
+ }
199
+ }
200
+
201
+ }
202
+ };