bri-components 1.2.53 → 1.2.54

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.
@@ -22,13 +22,12 @@
22
22
 
23
23
  <div class="InfoCascader-content-right">
24
24
  <div class="InfoCascader-content-right-title">
25
- {{curName}}说明
25
+ {{ curName }}说明
26
26
  </div>
27
27
  <p
28
28
  class="InfoCascader-content-right-content"
29
29
  v-html="description"
30
- >
31
- </p>
30
+ ></p>
32
31
  </div>
33
32
  </div>
34
33
 
@@ -89,9 +88,9 @@
89
88
  operationMap: {
90
89
  canCancel: {
91
90
  name: "取消",
92
- type: "clickCancel",
93
- event: "clickCancel",
94
- class: "z-default"
91
+ type: "canCancel",
92
+ class: "z-default",
93
+ event: "clickCancel"
95
94
  },
96
95
  canConfirm: {
97
96
  name: "确定",
@@ -109,116 +108,128 @@
109
108
  return this.showModal;
110
109
  },
111
110
  set (val) {
112
- this.$emit("changeShowModal", val);
111
+ this.$emit("close", val);
113
112
  }
114
113
  },
114
+
115
115
  modalPropsObj () {
116
116
  return {
117
117
  title: this.propsObj._name
118
118
  };
119
119
  },
120
+ selfPropsObj () {
121
+ return {
122
+ ...this.propsObj
123
+ };
124
+ },
125
+ saveKey () {
126
+ return this.selfPropsObj._saveKey;
127
+ },
128
+ resourceKey () {
129
+ return this.selfPropsObj._resourceKey;
130
+ },
131
+
120
132
  initData () {
121
- return this.loop(this.data, null, this.value);
133
+ return this.loop(this.data, null);
122
134
  },
123
135
  treeData () {
124
- if (!this.searchData.search) { // 内容为空时,查询所有
136
+ // 内容为空时,查询所有
137
+ if (!this.searchData.search) {
125
138
  return this.initData;
126
- }
127
- let that = this;
128
- const rebuildData = (value, treeList) => {
129
- that.show = false;
130
- let newarr = [];
131
- treeList.forEach(element => {
132
- if (element.children && element.children.length) {
133
- const ab = rebuildData(value, element.children);
134
- const obj = {
135
- ...element,
136
- expand: true,
137
- children: ab
138
- };
139
- if (ab && ab.length) {
140
- newarr.push(obj);
141
- } else if (element.title.indexOf(value) > -1) {
142
- element.expand = true;
143
- newarr.push(element);
144
- }
145
- } else {
146
- if (element.title.indexOf(value) > -1) {
147
- newarr.push(element);
139
+ } else {
140
+ const loop = (value, treeList) => {
141
+ let newarr = [];
142
+ treeList.forEach(element => {
143
+ if (element.children && element.children.length) {
144
+ const ab = loop(value, element.children);
145
+ const obj = {
146
+ ...element,
147
+ expand: true,
148
+ children: ab
149
+ };
150
+ if (ab && ab.length) {
151
+ newarr.push(obj);
152
+ } else if (element.title.indexOf(value) > -1) {
153
+ element.expand = true;
154
+ newarr.push(element);
155
+ }
156
+ } else {
157
+ if (element.title.indexOf(value) > -1) {
158
+ newarr.push(element);
159
+ }
148
160
  }
149
- }
150
- });
151
- that.show = true;
152
- return newarr;
153
- };
154
- return rebuildData(this.searchData.search, this.initData);
161
+ });
162
+ return newarr;
163
+ };
164
+
165
+ return loop(this.searchData.search, this.initData);
166
+ }
155
167
  }
156
168
  },
157
169
  created () {
158
- this.curSelect.codeArr = this.value;
159
- if (this.value && this.value.length) {
160
- // 回显已选择的名称
161
- const loop = (arr) => {
162
- for (let item of arr) {
163
- if (item.codeArr.length == this.value.length && item.codeArr.every((code, idx) => code === this.value[idx])) {
164
- this.curName = item.name;
165
- break;
166
- }
167
- if (item.children.length) {
168
- loop(item.children);
169
- }
170
- }
171
- };
172
- loop(this.initData);
173
- this.getDescription(this.value);
174
- }
170
+ this.init();
175
171
  },
176
172
  methods: {
177
- change (node) {
178
- this.curName = node.name;
179
- if (node.codeArr.length && this.curSelect.codeArr && this.curSelect.codeArr.length === node.codeArr.length && node.codeArr.every((code, idx) => code === this.curSelect.codeArr[idx])) {
180
- this.curSelect = {};
181
- } else {
182
- if (!this.propsObj._cascaderLevel || node.level == this.propsObj._cascaderLevel || !node.children.length) {
183
- this.curSelect = node;
184
- }
185
- this.getDescription(node.codeArr);
173
+ init () {
174
+ this.curSelect.keys = this.value;
175
+
176
+ if (this.value.length) {
177
+ // 回显已选择的名称
178
+ const loop = (arr) => {
179
+ for (let item of arr) {
180
+ if (
181
+ item.keys.length === this.value.length &&
182
+ item.keys.every((code, idx) => code === this.value[idx])
183
+ ) {
184
+ this.curName = item.name;
185
+ break;
186
+ }
187
+ if (item.children.length) {
188
+ loop(item.children);
189
+ }
190
+ }
191
+ };
192
+ loop(this.initData);
193
+ this.getDescription(this.value);
186
194
  }
187
195
  },
188
- getDescription (nodeKeys) {
189
- this.$https({
190
- url: {
191
- module: "sheet",
192
- name: "getResourceDescription"
193
- },
194
- params: {
195
- resourceKey: this.propsObj._resourceKey,
196
- nodeKeys
197
- },
198
- callback: data => {
199
- this.description = data;
200
- }
201
- });
202
- },
196
+
203
197
  clickCancel () {
204
- this.$emit("changeShowModal", false);
198
+ this.$emit("close", false);
205
199
  },
206
200
  clickConfirm () {
207
201
  if (this.curName) {
208
- this.$emit("input", this.curSelect.codeArr);
209
- this.$emit("change", this.curSelect.codeArr);
210
- this.$emit("changeShowModal", false);
202
+ this.$emit("input", this.curSelect.keys);
203
+ this.$emit("change", this.curSelect.keys);
204
+ this.$emit("close", false);
211
205
  } else {
212
206
  this.$Message.warning(`请选择${this.propsObj._name}!`);
213
207
  }
208
+ },
209
+ change (node) {
210
+ this.curName = node.name;
214
211
 
212
+ if (
213
+ this.curSelect.keys &&
214
+ this.curSelect.keys.length === node.keys.length &&
215
+ node.keys.length &&
216
+ node.keys.every((code, idx) => code === this.curSelect.keys[idx])
217
+ ) {
218
+ this.curSelect = {};
219
+ } else {
220
+ if (!this.propsObj._cascaderLevel || node.level == this.propsObj._cascaderLevel || !node.children.length) {
221
+ this.curSelect = node;
222
+ }
223
+ this.getDescription(node.keys);
224
+ }
215
225
  },
216
- loop (data = [], level, codeArr) {
226
+
227
+ loop (data = [], level) {
217
228
  return data
218
229
  ? data.reduce((arr, item) => {
219
230
  item.expand = false;
220
231
  if (this.value.length) {
221
- let arr = this.$getTreeLinealDatas(this.value, this.data);
232
+ let arr = this.$getTreeLinealDatas(this.value, this.data, undefined, this.saveKey);
222
233
  arr.forEach(i => { i.expand = true; });
223
234
  }
224
235
  const newItem = {
@@ -229,7 +240,7 @@
229
240
  render: (h, { root, node, data }) => {
230
241
  return h("span", {
231
242
  class: {
232
- "ivu-tree-title-selected": this.curSelect.codeArr && this.curSelect.codeArr.length && this.curSelect.codeArr.length === data.codeArr.length && this.curSelect.codeArr.every((code, idx) => code === data.codeArr[idx])
243
+ "ivu-tree-title-selected": this.curSelect.keys && this.curSelect.keys.length && this.curSelect.keys.length === data.keys.length && this.curSelect.keys.every((code, idx) => code === data.keys[idx])
233
244
  },
234
245
  style: {
235
246
  display: "inline-block",
@@ -244,13 +255,28 @@
244
255
  }
245
256
  };
246
257
  if (!level || level > item.level) {
247
- newItem.children = this.loop(item.children, level, this.value);
258
+ newItem.children = this.loop(item.children, level);
248
259
  }
249
260
  arr.push(newItem);
250
261
 
251
262
  return arr;
252
263
  }, [])
253
264
  : [];
265
+ },
266
+ getDescription (nodeKeys) {
267
+ this.$https({
268
+ url: {
269
+ module: "sheet",
270
+ name: "getResourceDescription"
271
+ },
272
+ params: {
273
+ resourceKey: this.resourceKey,
274
+ nodeKeys
275
+ },
276
+ callback: data => {
277
+ this.description = data;
278
+ }
279
+ });
254
280
  }
255
281
  }
256
282
  };
@@ -0,0 +1,187 @@
1
+ import controlMixin from "../../controlMixin.js";
2
+ import { regionData, userIndustryData } from "bri-datas";
3
+
4
+ export default {
5
+ mixins: [
6
+ controlMixin
7
+ ],
8
+ components: {},
9
+ props: {},
10
+ data () {
11
+ return {};
12
+ },
13
+ computed: {
14
+ basePropsObj () {
15
+ const _joinSymbol = this.propsObj._joinSymbol || "/";
16
+ return {
17
+ _cascaderFilterVals: [], // 过滤级联数据,只保留的数组
18
+ _changeOnSelect: false, // 每级菜单都可取值
19
+ _filterable: true,
20
+ _renderFormat: (labels) => labels.join(_joinSymbol),
21
+
22
+ ...this.propsObj,
23
+ ...this.commonDealPropsObj,
24
+
25
+ _saveKey: this.propsObj._saveKey || "_key",
26
+ _valueKey: this.propsObj._valueKey || "code",
27
+ _nameKey: this.propsObj._nameKey || "name",
28
+ _joinSymbol: _joinSymbol // 级联拼接符
29
+ };
30
+ },
31
+ cascaderLevel () {
32
+ return this.selfPropsObj._cascaderLevel;
33
+ },
34
+ cascaderFilterVals () {
35
+ return this.selfPropsObj._cascaderFilterVals;
36
+ },
37
+ changeOnSelect () {
38
+ return this.isOnSearch ? true : this.selfPropsObj._changeOnSelect;
39
+ },
40
+ saveKey () {
41
+ return this.selfPropsObj._saveKey;
42
+ },
43
+ valueKey () {
44
+ return this.selfPropsObj._valueKey;
45
+ },
46
+ nameKey () {
47
+ return this.selfPropsObj._nameKey;
48
+ },
49
+ renderFormat () {
50
+ return this.selfPropsObj._renderFormat;
51
+ },
52
+
53
+ originData () {
54
+ return ["region", "regions"].includes(this.controlType)
55
+ ? regionData
56
+ : ["userIndustry"].includes(this.controlType)
57
+ ? userIndustryData
58
+ : this.selfPropsObj._data;
59
+ },
60
+ cascaderData () {
61
+ const loop = (data = [], level, parentKeys = [], filterVals = [], isMobile = false) => {
62
+ if (data && filterVals.length) {
63
+ data = data.filter(item => filterVals.includes(item[this.saveKey]));
64
+ }
65
+
66
+ return data
67
+ ? data.reduce((arr, item) => {
68
+ let newItem = {
69
+ keys: [...parentKeys, item[this.saveKey]], // !!此处就是用_key拼,不会用别的属性
70
+ code: [...parentKeys, item._key].join(""),
71
+ ...item
72
+ };
73
+ newItem = {
74
+ ...newItem,
75
+ value: newItem[this.valueKey],
76
+ label: newItem[this.nameKey]
77
+ };
78
+
79
+ if (
80
+ (!level || level > newItem.level) &&
81
+ (newItem.children && newItem.children.length)
82
+ ) {
83
+ newItem.loading = false; // 此代码pc端在用:为了所请求的级,出现继续加载的箭头图标
84
+ newItem.children = loop(newItem.children, level, newItem.keys, undefined, isMobile);
85
+ } else {
86
+ newItem.children = isMobile ? undefined : [];
87
+ newItem.isLeaf = true;
88
+ }
89
+ arr.push(newItem);
90
+
91
+ return arr;
92
+ }, [])
93
+ : [];
94
+ };
95
+
96
+ return loop(this.originData, this.cascaderLevel, undefined, this.cascaderFilterVals, this.isMobile);
97
+ },
98
+ curValName: {
99
+ get () {
100
+ return this.transformFullName(this.curValList);
101
+ },
102
+ set (val) {
103
+ if (!val) {
104
+ this.clickClear();
105
+ }
106
+ }
107
+ },
108
+ showVal () {
109
+ return this.$isEmptyData(this.curValList)
110
+ ? this.emptyShowVal
111
+ : this.curValName;
112
+ },
113
+ curValNameList () {
114
+ return this.curValList.map(item => this.transformFullName(item));
115
+ },
116
+ showMulVal () {
117
+ return this.$isEmptyData(this.curValList)
118
+ ? this.emptyShowVal
119
+ : this.curValNameList.join(",");
120
+ }
121
+ },
122
+ created () { },
123
+ methods: {
124
+ // 点击选择框 进行选择
125
+ clickInput (e) {
126
+ if (!this.selfPropsObj._disabled) {
127
+ this.openModal();
128
+ } else {
129
+ e.stopPropagation();
130
+ }
131
+ },
132
+
133
+ // 点击清除
134
+ clickClear () {
135
+ this.curValList = [];
136
+ },
137
+ // 删除
138
+ clickDeleteItem (nameItem, index) {
139
+ this.curValList.splice(index, 1);
140
+ this.curValList = [...this.curValList];
141
+ },
142
+ confirmCb (val, selectedOptions) {
143
+ this.curValList = val;
144
+
145
+ this.closeModal();
146
+ },
147
+ confirmMulCb (val, selectedOptions) {
148
+ if (this.curValList.some(item => JSON.stringify(item) == JSON.stringify(val))) {
149
+ this.$Message.error({
150
+ content: `"${this.transformFullName(val)}"已选择,请勿重复选择!`,
151
+ duration: 4
152
+ });
153
+ } else {
154
+ this.curValList = [...this.curValList, val];
155
+
156
+ this.closeModal();
157
+ }
158
+ },
159
+
160
+ /* --------- 级联面板 -------- */
161
+ clickConfirm (val, selectedOptions) {
162
+ if (val.length) {
163
+ if (!this.changeOnSelect && !selectedOptions.slice(-1)[0].isLeaf) {
164
+ this.$Message.error({
165
+ content: "请选择到末级数据!",
166
+ duration: 2
167
+ });
168
+ } else {
169
+ this.multipleMode
170
+ ? this.confirmMulCb(val, selectedOptions)
171
+ : this.confirmCb(val, selectedOptions);
172
+ }
173
+ } else {
174
+ this.$Message.error({
175
+ content: "请选择数据!",
176
+ duration: 2
177
+ });
178
+ }
179
+ },
180
+
181
+ /* --------- 工具类 -------- */
182
+ // 转化出级联全名
183
+ transformFullName (val) {
184
+ return this.renderFormat(this.$getTreeLinealDatas(val, this.cascaderData, this.nameKey, this.saveKey));
185
+ }
186
+ }
187
+ };