bri-components 1.4.84 → 1.4.85

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": "bri-components",
3
- "version": "1.4.84",
3
+ "version": "1.4.85",
4
4
  "author": "dengshanghui",
5
5
  "description": "a component lib for vue project",
6
6
  "main": "src/index.js",
@@ -143,13 +143,20 @@
143
143
  methods: {
144
144
  /* -------- 方法 ------- */
145
145
  getOptions (index) {
146
+ const compareDate = this[`curVal${index === 0 ? 1 : 0}`];
147
+ const compareDateStr = this.$transformToDateStr(compareDate, "/", this.subType);
148
+ const compareOperator = index === 0 ? "ltAet" : "gtAet";
149
+
146
150
  return {
147
151
  shortcuts: this.getShortCuts(index),
148
152
  disabledDate: (date) => {
149
153
  const curDateStr = this.$transformToDateStr(date, "/", this.subType);
150
154
  const rangeBool = this.$isWithinRange(curDateStr, this.selfPropsObj._minDate, this.selfPropsObj._maxDate);
155
+ const compareBool = compareDateStr
156
+ ? !this.$isComparedAccord(curDateStr, compareDateStr, compareOperator, "date", this.subType, this.subType)
157
+ : false;
151
158
 
152
- return !rangeBool;
159
+ return !rangeBool || compareBool;
153
160
  }
154
161
  };
155
162
  }
@@ -63,6 +63,7 @@
63
63
  }"
64
64
  :allFormList="allFormList"
65
65
  :parentObj="value"
66
+ :treeColumns="treeForm"
66
67
  ></dsh-tree-table>
67
68
  </div>
68
69
  </dsh-modal>
@@ -104,6 +105,7 @@
104
105
  :propsObj="defaultPropsObj"
105
106
  :allFormList="allFormList"
106
107
  :parentObj="value"
108
+ :treeColumns="treeForm"
107
109
  @change="change"
108
110
  ></dsh-tree-table>
109
111
  </template>
@@ -144,6 +146,7 @@
144
146
  :propsObj="selfPropsObj"
145
147
  :allFormList="allFormList"
146
148
  :parentObj="value"
149
+ :treeColumns="treeForm"
147
150
  @change="change"
148
151
  ></dsh-tree-table>
149
152
  </template>
@@ -1,14 +1,7 @@
1
1
  export default {
2
2
  mixins: [],
3
3
  components: {},
4
- props: {
5
- treeColumns: {
6
- type: Array,
7
- default () {
8
- return [];
9
- }
10
- }
11
- },
4
+ props: {},
12
5
  data () {
13
6
  return {};
14
7
  },
@@ -26,215 +19,225 @@ export default {
26
19
  oldReadonlyTreeColKeys () {
27
20
  return this.isDftSet ? [] : this.selfPropsObj._oldReadonlyTreeColKeys || []; // 配置端有问题,高级依赖时值成undefined了
28
21
  },
29
-
30
22
  // 替换tableBaseMixin里的
31
23
  noborderColKeys () {
32
24
  return [
33
- ...this.treeColumns.map(colItem => colItem._key),
25
+ ...this.treeColKeys,
34
26
  ...this.selfPropsObj._noborderColKeys
35
27
  ];
36
28
  },
29
+ // 替换tableBaseMixin里的
37
30
  showCreateBtnColKeys () {
38
31
  return [
39
- ...this.treeFormKeys,
32
+ ...this.treeColKeys,
40
33
  ...(this.selfPropsObj._showCreateBtnColKeys || [])
41
34
  ];
42
35
  },
36
+ // 替换tableBaseMixin里的
43
37
  searchTitle () {
44
38
  return `${this.isSearching ? "筛选" : "全部"}数据,共 ${this.selfTotal} 条;`;
45
39
  },
46
40
 
41
+ /* --- 列字段 --- */
42
+ showColumns () {
43
+ return [
44
+ ...this.$transformToColumns(this.showContentColumns),
45
+ ...(!this.isSearching && this.rowOperationList.length ? [this.selfOperationColumn] : [])
46
+ ];
47
+ },
48
+ // 替换tableBaseMixin里的
49
+ contentColumns () {
50
+ return [
51
+ ...this.treeColumns.reduce((arr, colItem) => ([
52
+ ...arr,
53
+ {
54
+ ...colItem,
55
+ colType: "tree"
56
+ },
57
+ ...colItem._treeSubForm.map(subColItem => ({
58
+ ...subColItem,
59
+ colType: "summary",
60
+ nodeKey: colItem._key
61
+ }))
62
+ ]), []),
63
+ ...this.usedColumns.map(colItem => ({
64
+ ...colItem,
65
+ colType: "data",
66
+ nodeKey: this.treeColKeys[this.treeColKeys.length - 1]
67
+ }))
68
+ ].map(colItem => ({
69
+ renderHeaderCell: ({ column }, h) => {
70
+ return this.contentThCellRender(h, { column });
71
+ },
72
+ renderBodyCell: ({ row, rowIndex, column }, h) => {
73
+ row = row[column.nodeKey || column._key];
74
+
75
+ return column.colType === "summary"
76
+ ? this.getSummaryTdVal({ row, rowIndex, column })
77
+ : this.contentTdCellRender(h, { row, rowIndex, column });
78
+ },
79
+ ...colItem
80
+ }));
81
+ },
82
+ selfOperationColumn () {
83
+ return {
84
+ ...this.operationColumn,
85
+ nodeKey: this.treeColKeys[this.treeColKeys.length - 1],
86
+ renderBodyCell: ({ row, rowIndex, column }, h) => {
87
+ row = row[column.nodeKey || column._key];
88
+
89
+ return this.operationTdCellRender(h, { row, rowIndex, column });
90
+ }
91
+ };
92
+ },
93
+
94
+ /* --- 数据 --- */
47
95
  allTreeData () {
48
- return this.getCalcuedTree(this.data, this.treeColumns, this.selfColumns);
96
+ // console.log("allTreeData");
97
+ return this.getCalcuedTree(this.data, this.selfColumns, this.treeColumns);
49
98
  },
50
99
  allListData () {
51
- return this.$getTreeFlatArr(this.data, node => !(node.children && node.children.length));
100
+ // console.log("allListData");
101
+ return this.$getTreeFlatArr(this.allTreeData, node => !(node.children && node.children.length));
52
102
  },
53
103
  showListData () {
54
- return this.transformRows(this.allTreeData, this.treeColumns);
55
- },
104
+ // console.log("showListData");
105
+ const loop = (nodes = [], finalRows = []) => {
106
+ // 先层层过滤
107
+ const subLoop = (nodes = []) =>
108
+ nodes.filter(row =>
109
+ row.children && row.children.length
110
+ ? !!subLoop(row.children).length
111
+ : this.isSearching
112
+ ? this.$isAdvRelyAccord(this.finalTableAdvSearch, row)
113
+ : true
114
+ );
115
+ nodes = subLoop(nodes);
56
116
 
57
- showColumns () {
58
- return this.mergeColumns(this.treeColumns);
117
+ return nodes.reduce((rows, node, nodeIndex) => {
118
+ // 创建行,并把节点数据(对象类型)注入到行对象内
119
+ if (nodeIndex !== 0 || rows.length === 0) {
120
+ rows.push({
121
+ _id: this.$ObjectID().str
122
+ });
123
+ }
124
+ const curCol = this.treeColumns[node.level - 1];
125
+ const curRow = rows[rows.length - 1];
126
+ Object.assign(curRow, { [curCol._key]: node });
127
+
128
+ // 判断是否叶子节点,做对应操作
129
+ if (node.children && node.children.length) {
130
+ const oldLength = rows.length - 1;
131
+ const newRows = loop(node.children, rows);
132
+ node.total = newRows.length - oldLength;
133
+ return newRows;
134
+ } else {
135
+ return rows;
136
+ }
137
+ }, finalRows);
138
+ };
139
+
140
+ return loop(this.allTreeData);
59
141
  }
60
142
  },
61
- created () {
62
- this.init();
63
- },
143
+ created () { },
64
144
  mounted () { },
65
145
  methods: {
66
- // 初始化
67
- init () {
68
- this.treeColumns.forEach((treeFormItem, treeFormIndex) => {
69
- this.$set(treeFormItem, "level", treeFormIndex + 1);
70
- // this.$set(treeFormItem, "canDelete", true);
71
- });
72
- },
73
-
74
146
  // 转化树数据
75
- getCalcuedTree (nodes = [], treeForm = [], subForm = []) {
76
- treeForm.forEach((treeFormItem, treeFormIndex) => {
77
- // treeFormItem.canDelete = true; // 每次计算,重置一下
78
- treeFormItem.level = treeFormIndex + 1; // treeColumns更新,缺少level
79
- });
80
-
81
- // 循环遍树节点
147
+ getCalcuedTree (nodes = [], subCols = [], treeCols = []) {
82
148
  const loop = (nodes = [], parentNodes = []) => {
83
- nodes.forEach(rowItem => {
149
+ nodes.forEach(row => {
84
150
  // 初始化树节点的数据,给节点加上一些属性并监测,注入到节点对象中
85
- let curCol = treeForm[rowItem.level - 1];
86
- this.$setObj(rowItem, {
151
+ let curCol = treeCols[row.level - 1];
152
+ this.$setObj(row, {
87
153
  _key: curCol._key,
88
- level: curCol.level,
89
154
  isLeaf: false,
90
155
  total: 1
91
156
  });
92
157
 
93
- // 最后一列(根节点)
94
- if (rowItem.level === treeForm.length) {
95
- rowItem.children = [];
96
- rowItem.isLeaf = true;
158
+ // 根节点
159
+ if (row.level === treeCols.length) {
160
+ row.children = [];
161
+ row.isLeaf = true;
97
162
 
98
163
  // // TODO:特殊处理-叶子节点上注入对应表头列们的name值
99
- // const treeNodes = [...parentNodes, rowItem];
100
- // treeForm.forEach((treeFormItem, treeFormIndex) => {
101
- // rowItem[treeFormItem._key] = treeNodes[treeFormIndex].name;
102
- // // this.$set(rowItem, treeFormItem._key, treeNodes[treeFormIndex].name)
164
+ // const treeNodes = [...parentNodes, row];
165
+ // treeCols.forEach((colItem, colIndex) => {
166
+ // row[colItem._key] = treeNodes[colIndex].name;
103
167
  // });
104
168
  }
105
- // 非最后一列(最后一列前的列,非根节点),需继续向下循环
169
+ // 非根节点,需继续向下循环
106
170
  else {
107
- // 非最后一列的 正常的非根节点
108
- if (rowItem.children && rowItem.children.length) {
109
- loop(rowItem.children, [...parentNodes, rowItem]);
171
+ // 正常的非根节点
172
+ if (row.children && row.children.length) {
173
+ loop(row.children, [...parentNodes, row]);
110
174
  }
111
- // 非最后一列的 新增的非根节点(此时是新增一列或新增非根节点行) -添加一个子节点,并把该节点上的subForm属性值全部给下级节点
112
- // 特别提示:新增的是根节点行,不会走此处代码
175
+ // 特殊的非根节点(此时是新增一列 或 新增了非根节点行) -添加一个子节点,并把该节点上的subForm属性值全部给下级节点(新增的是根节点行,不会走此处代码)
113
176
  else {
114
- const newNode = this.getNewRowData(rowItem.level + 1, rowItem.children);
115
-
116
- subForm.forEach(subFormItem => {
117
- // 用$set也可以
118
- newNode[subFormItem._key] = rowItem[subFormItem._key];
119
- delete rowItem[subFormItem._key];
177
+ const newNode = this.getNewRowData(row.level + 1, row.children);
178
+ subCols.forEach(subCol => {
179
+ newNode[subCol._key] = row[subCol._key]; // 用$set也可以
180
+ delete row[subCol._key];
120
181
  });
121
- rowItem.children.push(newNode);
182
+ row.children.push(newNode);
122
183
 
123
- loop(rowItem.children, [...parentNodes, rowItem]);
184
+ loop(row.children, [...parentNodes, row]);
124
185
  }
125
186
  }
126
187
 
127
- this.fixRowItem(rowItem);
188
+ this.fixRowData(row);
128
189
  });
129
190
  };
130
- loop(nodes);
131
191
 
132
- this.isDeleteColStatus = false;
192
+ loop(nodes);
133
193
  this.initFlag = false;
134
194
  return nodes;
135
195
  },
136
- // 转化表格数据
137
- transformRows (nodes = [], treeForm = []) {
138
- const loop = (nodes = [], rows = []) => {
139
- nodes = this.getFilteredNodes(nodes);
140
-
141
- return nodes.reduce((rows, node, nodeIndex) => {
142
- // 创建行,并把节点数据(对象类型)注入到行对象内
143
- if (nodeIndex !== 0 || rows.length === 0) {
144
- rows.push({
145
- _id: this.$ObjectID().str,
146
- __isRendered__: true,
147
- __isShow__: true,
148
- __isTmpShow__: true
149
- // __isSearchShow__: false,
150
- // __isExpand__: false,
151
- });
152
- }
153
- const curCol = treeForm[node.level - 1];
154
- const curRow = rows[rows.length - 1];
155
- Object.assign(curRow, { [curCol._key]: node });
156
-
157
- // 判断是否叶子节点,做对应操作
158
- if (node.children && node.children.length) {
159
- const oldLength = rows.length - 1;
160
- const newRows = loop(node.children, rows);
161
- node.total = newRows.length - oldLength;
162
- return newRows;
163
- } else {
164
- return rows;
165
- }
166
- }, rows);
167
- };
168
- return loop(nodes);
196
+ fixSelfRowData (row) {
197
+ if (this.initFlag) {
198
+ // 根节点
199
+ if (!(row.children && row.children.length)) {
200
+ // 每条数据都补充全所有字段值(赋一个默认的空值)
201
+ this.selfColumns.forEach((colItem) => {
202
+ // 不用row[colItem._key] === undefined判断,是因为后端给的空值不可靠,多选的有时候都能给null
203
+ if (!Object.prototype.hasOwnProperty.call(row, colItem._key) && this.$isEmptyData(row[colItem._key])) {
204
+ this.$set(row, colItem._key, this.$deepCopy(this.dftInitValMap[colItem._type]));
205
+ }
206
+ });
207
+ }
208
+ }
169
209
  },
170
- // 合并表头
171
- mergeColumns (treeForm = [], subForm = this.showContentColumns) {
172
- return this.$transformToColumns(
173
- [
174
- ...treeForm.reduce((arr, treeFormItem) => ([
175
- ...arr,
176
- {
177
- ...treeFormItem,
178
- colType: "tree"
179
- },
180
- ...treeFormItem._treeSubForm.map(treeSubFormItem => ({
181
- ...treeSubFormItem,
182
- nodeKey: treeFormItem._key,
183
- colType: "summary"
184
- }))
185
- ]), []),
186
- ...subForm.map(subFormItem => ({
187
- ...subFormItem,
188
- nodeKey: treeForm[treeForm.length - 1]._key,
189
- colType: "data"
190
- })),
191
- ...(
192
- !this.isSearching && this.rowOperationList.length
193
- ? [{
194
- ...this.operationColumn,
195
- nodeKey: treeForm[treeForm.length - 1]._key,
196
- colType: "operation"
197
- }]
198
- : []
199
- )
200
- ].map(colItem => ({
201
- ...colItem,
202
- renderHeaderCell: ({ column }, h) => {
203
- return this.contentThCellRender(h, { column });
204
- },
205
- renderBodyCell: ({ row, rowIndex, column }, h) => {
206
- row = row[column.nodeKey || column._key];
207
210
 
208
- return column.colType === "summary"
209
- ? this.getSummaryTdVal({ row, rowIndex, column })
210
- : column.colType === "operation"
211
- ? this.operationTdCellRender(h, { row, rowIndex, column })
212
- : this.contentTdCellRender(h, { row, rowIndex, column });
213
- }
214
- }))
215
- );
216
- },
217
- getFilteredNodes (nodes = []) {
218
- const loop = (nodes = []) => {
219
- return nodes.filter(rowItem => {
220
- if (rowItem.children && rowItem.children.length) {
221
- if (this.isSearching) {
222
- rowItem.__isSearchShow__ = true;
223
- }
211
+ // 单元格 -汇总节点单元格-获取值
212
+ getSummaryTdVal ({ row, rowIndex, column }) {
213
+ const calFieldFormItem = this.selfColumns.find(item => item._key === column._calField);
224
214
 
225
- const children = loop(rowItem.children);
226
- return !!children.length;
227
- } else {
228
- return this.dealSearchShow(rowItem);
229
- }
230
- });
231
- };
215
+ if (column._calField && calFieldFormItem && column._operator) {
216
+ const loop = (nodes, arr = []) =>
217
+ nodes.reduce((arr, node) => {
218
+ return node.children.length
219
+ ? loop(node.children, arr)
220
+ : [
221
+ ...arr,
222
+ node[column._calField] || 0
223
+ ];
224
+ }, arr);
225
+ const list = loop(row.children);
232
226
 
233
- return loop(nodes);
227
+ return this.$calNumList(list, column._operator, calFieldFormItem);
228
+ } else {
229
+ return !column._calField && !column._operator
230
+ ? "未选择来源列和算法"
231
+ : !column._calField
232
+ ? "未选择来源列"
233
+ : !calFieldFormItem
234
+ ? `来源列${column._calField}被删除`
235
+ : "未选择算法";
236
+ }
234
237
  },
235
-
236
238
  bodyCellSpan ({ row, rowIndex, column }) {
237
239
  row = row[column.nodeKey || column._key];
240
+
238
241
  return {
239
242
  rowspan: row
240
243
  ? row.total || 1
@@ -242,36 +245,7 @@ export default {
242
245
  colspan: 1
243
246
  };
244
247
  },
245
- // 单元格 -汇总节点单元格-获取值
246
- getSummaryTdVal ({ row, rowIndex, column }) {
247
- if (column._calField && column._operator) {
248
- const calFieldFormItem = this.selfColumns.find(item => item._key === column._calField);
249
248
 
250
- if (calFieldFormItem) {
251
- let loop = (nodes, arr) => {
252
- return nodes.reduce((arr, node) => {
253
- if (node.children.length) {
254
- return loop(node.children, arr);
255
- } else {
256
- arr.push(node[column._calField] || 0);
257
- return arr;
258
- }
259
- }, arr);
260
- };
261
- let list = loop(row.children, []);
262
-
263
- return this.$calNumList(list, column._operator, calFieldFormItem);
264
- } else {
265
- return `来源列${column._calField}被删除`;
266
- }
267
- } else {
268
- return !column._calField && !column._operator
269
- ? "未选择来源列和算法"
270
- : !column._calField
271
- ? "未选择来源列"
272
- : "未选择算法";
273
- }
274
- },
275
249
  // 加工单元格对应的配置
276
250
  getSelfResetCol ({ row, rowIndex, column }) {
277
251
  return column.colType === "tree"
@@ -286,16 +260,16 @@ export default {
286
260
  return (this.getIsDftRow(row) ? !this.dftReadonlyTreeColKeys.includes(column._key) : true) && // 默认行的某列是否可编辑
287
261
  (row.__old__ === true ? !this.oldReadonlyTreeColKeys.includes(column._key) : true); // 老数据行里某些列不可编辑
288
262
  },
289
- // getNewRowData时,额外补充的行相关的数据(针对层级属性的列)
290
- getSelfNewRowData (level, list = []) {
291
- const column = this.treeForm[level - 1];
292
- const dftVal = column._default;
293
- const initDftVal = this.initDftValMap[column._type];
263
+ // getNewRowData时,额外补充的行相关的数据(针对层级列)
264
+ getSelfNewRowData (level) {
265
+ const column = this.treeColumns[level - 1];
294
266
 
295
267
  return {
296
- name: this.$isEmptyData(dftVal)
297
- ? initDftVal
298
- : dftVal
268
+ name: this.$deepCopy(
269
+ this.$isEmptyData(dftVal)
270
+ ? this.dftInitValMap[column._type]
271
+ : column._default
272
+ )
299
273
  };
300
274
  }
301
275
  }