bri-components 1.4.7-0 → 1.4.7

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.
@@ -1,7 +1,14 @@
1
1
  export default {
2
2
  mixins: [],
3
3
  components: {},
4
- props: {},
4
+ props: {
5
+ rowspanMap: {
6
+ type: Object,
7
+ default () {
8
+ return {};
9
+ }
10
+ }
11
+ },
5
12
  data () {
6
13
  return {};
7
14
  },
@@ -12,7 +19,31 @@ export default {
12
19
  };
13
20
  },
14
21
  mergeRowColKeys () {
15
- return this.selfPropsObj._mergeRowColKeys || []; // 配置端有问题,高级依赖时值成undefined了
22
+ const mergeRowColKeys = this.selfPropsObj._mergeRowColKeys || []; // 配置端有问题,高级依赖时值成undefined了
23
+ return this.selfColumns
24
+ .filter(colItem => mergeRowColKeys.includes(colItem._key))
25
+ .map(colItem => colItem._key);
26
+ },
27
+ // 一级合并列keys(一级合并列:左侧第一合并列和右侧和并列)
28
+ firstMergeRowColKeys () {
29
+ if (this.mergeRowColKeys.length) {
30
+ const firstNormalIndex = this.selfColumns.findIndex(colItem => !this.mergeRowColKeys.includes(colItem._key));
31
+
32
+ // -1代表无普通单元格,0代表第一列就是普通单元格
33
+ return [-1, 0].includes(firstNormalIndex)
34
+ ? this.mergeRowColKeys
35
+ : [
36
+ this.mergeRowColKeys[0],
37
+ ...this.selfColumns
38
+ .filter((colItem, colIndex) => colIndex > firstNormalIndex && this.mergeRowColKeys.includes(colItem._key))
39
+ .map(colItem => colItem._key)
40
+ ];
41
+ } else {
42
+ return [];
43
+ }
44
+ },
45
+ notFirstMergeRowColKeys () {
46
+ return this.mergeRowColKeys.filter(colKey => !this.firstMergeRowColKeys.includes(colKey));
16
47
  },
17
48
 
18
49
  allListData () {
@@ -23,6 +54,12 @@ export default {
23
54
  this.initFlag = false;
24
55
  return this.data;
25
56
  },
57
+ allListMap () {
58
+ return this.$arrToMap(this.allListData, "_id");
59
+ },
60
+ // allListIds () {
61
+ // return this.allListData.map(rowItem => rowItem._id);
62
+ // },
26
63
  footerData () {
27
64
  return this.isSearching
28
65
  ? []
@@ -74,53 +111,119 @@ export default {
74
111
  ];
75
112
  }
76
113
  };
77
- },
78
- mergeRowColumns () {
79
- return this.selfColumns.filter(colItem => this.mergeRowColKeys.includes(colItem._key));
80
114
  }
81
115
  },
82
- created () { },
116
+ created () {
117
+ this.initRowspan();
118
+ },
83
119
  methods: {
120
+ // 本身的初始化
121
+ selfReset () {
122
+ this.initRowspan();
123
+ },
124
+ // 初始化合并单元格的rowspan
125
+ initRowspan () {
126
+ if (this.mergeRowColKeys.length) {
127
+ this.$set(this.tableDataObj, "rowspanMap", this.tableDataObj.rowspanMap || {});
128
+
129
+ this.allListData.forEach((rowItem, rowIndex) => {
130
+ this.mergeRowColKeys.forEach(colKey => {
131
+ const column = { _key: colKey };
132
+
133
+ // 新增时,行的_id被置换,rowspanMap也要相应置换
134
+ if (this.idRecordMap[rowItem._id]) {
135
+ const oldId = this.idRecordMap[rowItem._id];
136
+ this.rowspanMap[this.getMixKey(rowItem, column)] = this.getRealRowspan({
137
+ row: { ...rowItem, _id: oldId },
138
+ rowIndex,
139
+ column
140
+ });
141
+
142
+ // 清除rowspanMap里和默认行老_id相关的
143
+ delete this.rowspanMap[this.getMixKey({ _id: oldId }, column)];
144
+ }
145
+ else {
146
+ this.rowspanMap[this.getMixKey(rowItem, column)] = this.getRealRowspan({ row: rowItem, rowIndex, column });
147
+ }
148
+ });
149
+ });
150
+
151
+ // 清除rowspanMap无用的(针对老数据)
152
+ Object.keys(this.rowspanMap).forEach(mixKey => {
153
+ const id = mixKey.split("dsh")[0];
154
+ if (!this.allListMap[id]) {
155
+ delete this.rowspanMap[mixKey];
156
+ }
157
+ });
158
+ }
159
+ },
160
+
84
161
  // 点击 -添加行
85
- clickCreate (operationItem, row, rowIndex, col) {
162
+ clickCreate (operationItem, row, rowIndex, column) {
163
+ const curColKey = column ? column._key : undefined;
86
164
  const list = this.data;
87
165
  const newRow = this.getNewRowData();
88
166
 
89
167
  // 处理单元格合并相关
90
- if (col) {
91
- // 当前列是合并列,则该列之前的合并列,要复制这一行对应列的值;
92
- if (this.mergeRowColKeys.includes(col._key)) {
93
- const newList = this.allListData.slice(rowIndex); // 从该行开始截取
94
- const nextRowIndex = this.$isEmptyData(row[col._key])
95
- ? 1
96
- : newList.findIndex(rowItem => rowItem[col._key] !== row[col._key]); // 寻找该单元格值开始不一样的行(特殊情况是最后一行,nextRowIndex为-1)
97
- row = nextRowIndex < 0
98
- ? newList[newList.length - 1]
99
- : newList[nextRowIndex - 1]; // 取该单元格值一样的最后一行
100
-
101
- const colIndex = this.mergeRowColumns.findIndex(column => column._key === col._key);
102
- this.mergeRowColumns.reduce((obj, column, columnIndex) => {
103
- return columnIndex < colIndex
104
- ? Object.assign(obj, {
105
- [column._key]: this.$deepCopy(row[column._key])
106
- })
107
- : obj;
108
- }, newRow);
168
+ if (this.mergeRowColKeys.length) {
169
+ // 非底部按钮添加时
170
+ if (row) {
171
+ // 寻找对应的行数据 -当前列是合并列会寻找,普通列不用找(就是row)
172
+ if (this.mergeRowColKeys.includes(curColKey)) {
173
+ const newList = this.allListData.slice(rowIndex); // 从该行开始截取
174
+ const nextRowIndex = this.$isEmptyData(row[curColKey])
175
+ ? 1
176
+ : newList.findIndex(rowItem => !this.isCompareSame(column, row, rowItem)); // 寻找该单元格值开始不一样的行(特殊情况是最后一行,nextRowIndex为-1)
177
+ row = nextRowIndex < 0
178
+ ? newList[newList.length - 1]
179
+ : newList[nextRowIndex - 1]; // 取该单元格值一样的最后一行
180
+ }
181
+
182
+ // 寻找要复制值的列
183
+ // 当前列:一级合并列,不复制值;
184
+ if (this.firstMergeRowColKeys.includes(curColKey)) {
185
+ // 新增的行做rowspan记录
186
+ this.mergeRowColKeys.forEach(colKey => {
187
+ this.rowspanMap[this.getMixKey(newRow, { _key: colKey })] = 1; // 新增的行做rowspan记录
188
+ });
189
+ }
190
+ // 当前列:普通合并列(非一级合并列),该列之前的合并列和一级合并列 复制值给新的行
191
+ // 当前列:非合并列 -全部复制值给新的行
192
+ else {
193
+ const notFirstCopyColKeys = this.notFirstMergeRowColKeys.includes(curColKey)
194
+ ? this.notFirstMergeRowColKeys.filter((colKey, colIndex, list) => colIndex < list.findIndex(colKey => colKey === curColKey))
195
+ : this.notFirstMergeRowColKeys;
196
+ const noCopyColKeys = this.notFirstMergeRowColKeys.includes(curColKey)
197
+ ? this.notFirstMergeRowColKeys.filter((colKey, colIndex, list) => colIndex >= list.findIndex(colKey => colKey === curColKey))
198
+ : [];
199
+ const copyColKeys = notFirstCopyColKeys.concat(this.firstMergeRowColKeys);
200
+
201
+ // 复制值
202
+ copyColKeys.reduce((obj, colKey, colIndex) => {
203
+ return Object.assign(obj, {
204
+ [colKey]: this.$deepCopy(row[colKey])
205
+ });
206
+ }, newRow);
207
+
208
+ // 做rowspan记录
209
+ copyColKeys.forEach(colKey => {
210
+ this.createMergeUnitRowspan({ row, rowIndex, column: { _key: colKey } });
211
+ this.rowspanMap[this.getMixKey(newRow, { _key: colKey })] = 0; // 新增的行做rowspan记录
212
+ }, newRow);
213
+ noCopyColKeys.forEach(colKey => {
214
+ this.rowspanMap[this.getMixKey(newRow, { _key: colKey })] = 1; // 新增的行做rowspan记录
215
+ });
216
+ }
109
217
  }
110
- // 当前列是非合并列,按该列前的最后合并列的操作处理(操作列时,colIndex < 0)
218
+ // 底部按钮添加时
111
219
  else {
112
- const colIndex = this.selfColumns.findIndex(column => column._key === col._key);
113
- const mergeRowColumns = this.selfColumns.filter((column, columnIndex) =>
114
- (colIndex < 0 ? true : columnIndex <= colIndex) &&
115
- this.mergeRowColKeys.includes(column._key)
116
- );
117
- mergeRowColumns.slice(0, mergeRowColumns.length - 1).reduce((obj, column) => {
118
- return Object.assign(obj, {
119
- [column._key]: this.$deepCopy(row[column._key])
120
- });
121
- }, newRow);
220
+ // 新增的行做rowspan记录
221
+ this.mergeRowColKeys.forEach(colKey => {
222
+ this.rowspanMap[this.getMixKey(newRow, { _key: colKey })] = 1; // 新增的行做rowspan记录
223
+ });
122
224
  }
123
225
  }
226
+
124
227
  const newRowIndex = row
125
228
  ? list.findIndex(rowItem => rowItem._id === row._id) + 1
126
229
  : list.length;
@@ -134,47 +237,129 @@ export default {
134
237
  title: "提示",
135
238
  content: "确定删除吗?",
136
239
  onOk: () => {
240
+ // 处理单元格合并相关
241
+ if (this.mergeRowColKeys.length) {
242
+ this.mergeRowColKeys.forEach(colKey => {
243
+ this.deleteMergeUnitRowspan({ row, rowIndex, column: { _key: colKey } });
244
+ });
245
+ }
137
246
  this.data.splice(rowIndex, 1);
138
247
 
139
248
  this.change("deleteRow", row, rowIndex, null);
140
249
  }
141
250
  });
142
251
  },
252
+ quickChangeVal (operationItem, row, rowIndex, column, params) {
253
+ this.$set(this.ruleRecordMap, this.getMixKey(row, column), { showRuleMessage: true });
254
+ this.dealSameRowsVal({ row, rowIndex, column });
255
+
256
+ this.change("quickChangeVal", row, rowIndex, column, ...params);
257
+ },
258
+ changeVal (operationItem, row, rowIndex, column, params) {
259
+ this.$set(this.ruleRecordMap, this.getMixKey(row, column), { showRuleMessage: true });
260
+ if (!["text", "textarea", "idcard", "email", "phone", "url", "password", "serialNumber"].includes(column._key)) {
261
+ this.dealSameRowsVal({ row, rowIndex, column });
262
+ }
263
+
264
+ this.change("changeVal", row, rowIndex, column, ...params);
265
+ },
143
266
 
144
267
  /* ----------- 方法 ---------- */
145
- selfBodyCellClass ({ row, rowIndex, column }) {
146
- return `${this.mergeRowColKeys && this.mergeRowColKeys.includes(column._key)
147
- ? " bri-table-td-merge"
148
- : ""
149
- }`;
268
+ // 加工单元格对应的配置
269
+ getSelfResetCol ({ row, rowIndex, column }) {
270
+ return this.mergeRowColKeys.includes(column._key)
271
+ ? {
272
+ _heightAuto: true
273
+ }
274
+ : {};
150
275
  },
151
276
  bodyCellSpan ({ row, rowIndex, column }) {
152
- rowIndex = this.showListData.findIndex(dataItem => dataItem._id === row._id);
277
+ return {
278
+ rowspan: this.mergeRowColKeys.includes(column._key)
279
+ ? this.isSearching
280
+ ? this.getRowspan({ row, rowIndex, column })
281
+ : this.getRealRowspan({ row, rowIndex, column })
282
+ : 1,
283
+ colspan: 1
284
+ };
285
+ },
286
+ // 获取合并单元格真实的rowspan
287
+ getRealRowspan ({ row, rowIndex, column }) {
288
+ return ![undefined, null].includes(this.rowspanMap[this.getMixKey(row, column)])
289
+ ? this.rowspanMap[this.getMixKey(row, column)]
290
+ : ![undefined, null].includes(this.rowspanMap[this.getMixKey(row, column, false)])
291
+ ? this.rowspanMap[this.getMixKey(row, column, false)]
292
+ : this.getRowspan({ row, rowIndex, column }, this.allListData);
293
+ },
294
+ // 计算rowspan
295
+ getRowspan ({ row, rowIndex, column }, list = this.showListData) {
296
+ let rowspan = 1;
297
+ rowIndex = list.findIndex(dataItem => dataItem._id === row._id);
153
298
 
154
- // 合并单元格(单元格值为空时不合并)
155
299
  if (
156
300
  this.mergeRowColKeys.includes(column._key) &&
157
- rowIndex > -1 &&
158
- !this.$isEmptyData(row[column._key])
301
+ rowIndex > -1 // 代表显示出来的行
159
302
  ) {
160
- if (
161
- rowIndex !== 0 &&
162
- row[column._key] === this.showListData[rowIndex - 1][column._key]
163
- ) {
164
- return {
165
- rowspan: 0,
166
- colspan: 0
167
- };
303
+ if (rowIndex !== 0 && this.isCompareSame(column, row, list[rowIndex - 1])) {
304
+ rowspan = 0;
168
305
  } else {
169
- const newList = this.showListData.slice(rowIndex);
170
- const newIndex = newList.findIndex(rowItem => row[column._key] !== rowItem[column._key]);
171
-
172
- return {
173
- rowspan: newIndex === -1 ? newList.length : newIndex,
174
- colspan: 1
175
- };
306
+ const newList = list.slice(rowIndex + 1);
307
+ const newIndex = newList.findIndex(rowItem => !this.isCompareSame(column, row, rowItem));
308
+ rowspan = 1 + (newIndex === -1 ? newList.length : newIndex);
176
309
  }
177
310
  }
311
+
312
+ return rowspan;
313
+ },
314
+ // 添加一行后 处理合并单元格的rowspan
315
+ createMergeUnitRowspan ({ row, rowIndex, column }, list = this.allListData) {
316
+ rowIndex = list.findIndex(dataItem => dataItem._id === row._id);
317
+
318
+ if (rowIndex > -1) {
319
+ let fistMergeRow = this.rowspanMap[this.getMixKey(row, column)] === 0
320
+ ? list.slice(0, rowIndex).findLast(rowItem => this.rowspanMap[this.getMixKey(rowItem, column)] > 1)
321
+ : row;
322
+
323
+ this.rowspanMap[this.getMixKey(fistMergeRow, column)] = this.rowspanMap[this.getMixKey(fistMergeRow, column)] + 1;
324
+ }
325
+ else {
326
+ this.rowspanMap[this.getMixKey(row, column)] = 1;
327
+ }
328
+ },
329
+ // 删除一行后 处理合并单元格的rowspan
330
+ deleteMergeUnitRowspan ({ row, rowIndex, column }, list = this.allListData) {
331
+ rowIndex = list.findIndex(dataItem => dataItem._id === row._id);
332
+ let fistMergeRow = this.rowspanMap[this.getMixKey(row, column)] === 0
333
+ ? list.slice(0, rowIndex).findLast(rowItem => this.rowspanMap[this.getMixKey(rowItem, column)] > 1)
334
+ : row;
335
+
336
+ // 当前单元格合并了下面的 -把合并数减去1给下一单元格
337
+ if (this.rowspanMap[this.getMixKey(row, column)] > 1) {
338
+ nextRow = list[rowIndex + 1];
339
+ this.rowspanMap[this.getMixKey(nextRow, column)] = this.rowspanMap[this.getMixKey(row, column)] - 1;
340
+ }
341
+ // 当前单元格被上面的合并了 -最上面的合并单元格合并数减去1
342
+ else if (this.rowspanMap[this.getMixKey(row, column)] === 0) {
343
+ this.rowspanMap[this.getMixKey(fistMergeRow, column)] = this.rowspanMap[this.getMixKey(fistMergeRow, column)] - 1;
344
+ }
345
+ // 当前单元格单独存在(无合并)
346
+ else if (this.rowspanMap[this.getMixKey(row, column)] === 1) {
347
+ // 无处理
348
+ }
349
+
350
+ // 清除被删除单元格的rowspan记录
351
+ delete this.rowspanMap[this.getMixKey(row, column)];
352
+ },
353
+
354
+ // 合并单元格的行,某列的值全部跟着修改
355
+ dealSameRowsVal ({ row, rowIndex, column }, list = this.allListData) {
356
+ if (this.mergeRowColKeys.includes(column._key) && this.rowspanMap[this.getMixKey(row, column)] > 1) {
357
+ const indexInAll = list.findIndex(dataItem => dataItem._id === row._id);
358
+ list.slice(indexInAll + 1, indexInAll + this.rowspanMap[this.getMixKey(row, column)])
359
+ .forEach(rowItem => {
360
+ rowItem[column._key] = this.$deepCopy(row[column._key]);
361
+ });
362
+ }
178
363
  }
179
364
  }
180
365
  };