bri-components 1.3.60 → 1.3.62

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.
@@ -0,0 +1,124 @@
1
+ export default {
2
+ mixins: [],
3
+ components: {},
4
+ props: {},
5
+ data () {
6
+ return {};
7
+ },
8
+ computed: {
9
+ allListData () {
10
+ console.log("allListData");
11
+ this.data.forEach(item => {
12
+ !item._id && this.$set(item, "_id", this.$ObjectID().str);
13
+
14
+ if (this.initFlag) {
15
+ item.__old__ = true; // 标记老数据(initFlag不用在data中声明)
16
+ item.__isRendered__ = true;
17
+ item.__isShow__ = true;
18
+ item.__isTmpShow__ = true;
19
+ item.__isSearchShow__ = false;
20
+ }
21
+ });
22
+
23
+ this.initFlag = false;
24
+ return this.data;
25
+ },
26
+ footerData () {
27
+ return this.isSearching
28
+ ? []
29
+ : this.useSummary && this.allListData.length
30
+ ? [
31
+ this.filterColumns.reduce((obj, col) => {
32
+ return {
33
+ ...obj,
34
+ [col._key]: col._type === "number" && ![undefined, null, "", "no"].includes(col._summaryType)
35
+ ? this.$calNumList(
36
+ this.allListData.map(item => item[col._key]),
37
+ col._summaryType,
38
+ { ...col, _defaultDigit: 2 }
39
+ )
40
+ : (obj[col._key] || "--")
41
+ };
42
+ }, {
43
+ _id: this.$ObjectID().str,
44
+ __index__: "汇总",
45
+ __operation__: "——"
46
+ })
47
+ ]
48
+ : [];
49
+ },
50
+
51
+ tablePropsObj () {
52
+ return {
53
+ maxHeight: this.contentHeight,
54
+ cellStyleOption: {
55
+ bodyCellClass: ({ column, row, rowIndex }) => {
56
+ return "bri-table-td" +
57
+ `${this.getRowCanEdit(row)
58
+ ? " bri-table-td-edit"
59
+ : ""
60
+ }` +
61
+ `${this.isSearching
62
+ ? !row.__isSearchShow__
63
+ ? " bri-table-td-hide"
64
+ : ""
65
+ : ""
66
+ }`;
67
+ }
68
+ }
69
+ };
70
+ },
71
+ showColumns () {
72
+ return [
73
+ ...(this.useSelection === true ? [this.selectionColumn] : []),
74
+ ...(this.useIndex === true ? [this.indexColumn] : []),
75
+ ...this.$transformToColumns(this.contentColumns),
76
+ ...(this.$getOperationList(["canDelete"]).length ? [this.operationColumn] : [])
77
+ ];
78
+ },
79
+ indexColumn () {
80
+ return {
81
+ title: "序号",
82
+ _key: "__index__",
83
+ key: "__index__",
84
+ field: "__index__",
85
+ width: 76,
86
+ align: "center",
87
+ fixed: "left",
88
+ renderBodyCell: ({ column, row, rowIndex }) => ++rowIndex
89
+ };
90
+ }
91
+ },
92
+ created () { },
93
+ methods: {
94
+ // 点击 -添加行
95
+ clickCreate (operationItem, row, rowIndex) {
96
+ const list = this.allListData;
97
+ const newRow = {
98
+ ...this.$deepCopy(this.selfRowDefault),
99
+ _id: this.$ObjectID().str,
100
+ __isRendered__: true,
101
+ __isShow__: true,
102
+ __isTmpShow__: true,
103
+ __isSearchShow__: false
104
+ };
105
+ const newRowIndex = rowIndex == null ? list.length : rowIndex + 1;
106
+ list.splice(newRowIndex, 0, newRow);
107
+ this.$forceUpdate(); // 自定义页中点击添加一行没有更新页面
108
+
109
+ this.change("createRow", null, newRow, newRowIndex);
110
+ },
111
+ // 点击 -删除行
112
+ clickDelete (operationItem, row, rowIndex) {
113
+ this.$Modal.confirm({
114
+ title: "提示",
115
+ content: "确定删除吗?",
116
+ onOk: () => {
117
+ this.allListData.splice(rowIndex, 1);
118
+
119
+ this.change("deleteRow", null, row, rowIndex);
120
+ }
121
+ });
122
+ }
123
+ }
124
+ };
@@ -0,0 +1,410 @@
1
+ export default {
2
+ mixins: [],
3
+ components: {},
4
+ props: {},
5
+ data () {
6
+ return {
7
+ deleteProperties: ["__treeIndex__", "__old__", "__isExpand__", "__isRendered__", "__isShow__", "__isTmpShow__", "__isSearchShow__"], // 除了__readonly__和__isQuote__不处理
8
+ isExpandAction: false,
9
+
10
+ searchMode: "flat" // "flat", "tree"
11
+
12
+ };
13
+ },
14
+ computed: {
15
+ selfPropsObj () {
16
+ return {
17
+ _maxLevel: 3, // 最大级数
18
+ ...this.commonPropsObj
19
+ };
20
+ },
21
+ maxLevel () {
22
+ return this.selfPropsObj._maxLevel || 3;
23
+ },
24
+
25
+ allTreeData () {
26
+ console.log("allTreeData");
27
+ return this.getCalcuedTree(this.data, this.columns);
28
+ },
29
+ allListData () {
30
+ console.log("allListData");
31
+ return this.$getTreeFlatArr(this.allTreeData);
32
+ },
33
+ footerData () {
34
+ console.log("footerData");
35
+ return this.isSearching
36
+ ? []
37
+ : this.useSummary && this.allListData.length
38
+ ? [
39
+ this.filterColumns.reduce((obj, col) => {
40
+ return {
41
+ ...obj,
42
+ [col._key]: col._type === "number" && ![undefined, null, "", "no"].includes(col._summaryType)
43
+ ? this.$calNumList(
44
+ this.allListData
45
+ .filter(item => item.level === 1)
46
+ .map(item => item[col._key]),
47
+ col._summaryType,
48
+ { ...col, _defaultDigit: 2 }
49
+ )
50
+ : (obj[col._key] || "--")
51
+ };
52
+ }, {
53
+ _id: this.$ObjectID().str,
54
+ __index__: "汇总",
55
+ __isExpand__: "-",
56
+ __operation__: "——"
57
+ })
58
+ ]
59
+ : [];
60
+ },
61
+
62
+ tablePropsObj () {
63
+ return {
64
+ maxHeight: this.contentHeight,
65
+ // rowStyleOption: {
66
+ // hoverHighlight: true,
67
+ // clickHighlight: true,
68
+ // stripe: true // 斑马纹
69
+ // },
70
+ cellStyleOption: {
71
+ bodyCellClass: ({ row, column, rowIndex }) => {
72
+ return "bri-table-td" +
73
+ `${this.getRowCanEdit(row)
74
+ ? " bri-table-td-edit"
75
+ : ""
76
+ }` +
77
+ `${this.isSearching
78
+ ? !row.__isSearchShow__
79
+ ? " bri-table-td-hide"
80
+ : ""
81
+ : !row.__isShow__
82
+ ? " bri-table-td-hide"
83
+ : this.isExpandAction
84
+ ? " bri-table-td-visible"
85
+ : ""
86
+ }` +
87
+ `${["__isExpand__"].includes(column._key)
88
+ ? " bri-table-td-expand"
89
+ : ["__index__"].includes(column._key)
90
+ ? " bri-table-td-index"
91
+ : ""
92
+ }`;
93
+ }
94
+ },
95
+ // 通过实例方法 hideColumnsByKeys(keys)将列隐藏,通过实例方法 showColumnsByKeys(keys)将隐藏的列显示
96
+ columnHiddenOption: {
97
+ defaultHiddenColumnKeys: []
98
+ }
99
+ };
100
+ },
101
+ showColumns () {
102
+ return [
103
+ ...(this.useSelection === true ? [this.selectionColumn] : []),
104
+ this.expandColumn,
105
+ ...(this.useIndex === true ? [this.indexColumn] : []),
106
+ ...this.$transformToColumns(this.contentColumns),
107
+ ...(this.isSearching
108
+ ? []
109
+ : this.$getOperationList(["canDelete"]).length
110
+ ? [this.operationColumn]
111
+ : [])
112
+ ];
113
+ },
114
+ expandColumn () {
115
+ return {
116
+ // title: "开/合",
117
+ _key: "__isExpand__",
118
+ key: "__isExpand__",
119
+ field: "__isExpand__",
120
+ width: 48,
121
+ align: "center",
122
+ fixed: "left",
123
+ renderBodyCell: ({ row, column, rowIndex }, h) => {
124
+ return this.isSearching && this.searchMode === "flat"
125
+ ? h("span", "")
126
+ : row.children && row.children.length
127
+ ? h("Icon", {
128
+ style: {
129
+ width: "16px",
130
+ height: "16px",
131
+ cursor: "pointer",
132
+ transform: row.__isExpand__ ? "rotate(90deg)" : "rotate(0deg)",
133
+ transition: "transform 0.3s"
134
+ },
135
+ props: {
136
+ type: "ios-arrow-forward",
137
+ size: "18"
138
+ },
139
+ on: {
140
+ click: () => {
141
+ this.toggleExpand(row, !row.__isExpand__);
142
+ }
143
+ }
144
+ })
145
+ : h("span", "");
146
+ }
147
+ };
148
+ },
149
+ indexColumn () {
150
+ return {
151
+ title: "序号",
152
+ _key: "__index__",
153
+ key: "__index__",
154
+ field: "__index__",
155
+ width: 28 + 16 + (this.maxLevel - 1) * 38,
156
+ align: "left",
157
+ fixed: "left",
158
+ renderBodyCell: ({ row, column, rowIndex }, h) => {
159
+ return [
160
+ h("div", {
161
+ style: {
162
+ paddingLeft: `${(row.level - 1) * 18}px`,
163
+ fontWeight: "500"
164
+ }
165
+ }, row.__treeIndex__),
166
+
167
+ // 添加符
168
+ this.operationMap.canCreate && row.level < this.maxLevel && !this.isSearching
169
+ ? h("div", {
170
+ style: {
171
+ position: "absolute",
172
+ bottom: "0px",
173
+ right: "0px",
174
+ display: "inline-block",
175
+ width: "16px",
176
+ height: " 16px",
177
+ border: "1px solid #dcdee2",
178
+ backgroundColor: "#ffffff",
179
+ lineHeight: "12px",
180
+ cursor: "pointer",
181
+ verticalAlign: "middle",
182
+ transition: "color .2s ease-in-out,border-color .2s ease-in-out"
183
+ }
184
+ }, [
185
+ h("Icon", {
186
+ style: {
187
+ fontWeight: "500"
188
+ },
189
+ props: {
190
+ type: "ios-add", // "md-add-circle"
191
+ size: "14"
192
+ },
193
+ on: {
194
+ click: () => {
195
+ this.clickCreate(this.operationMap.canCreate, row, rowIndex);
196
+ }
197
+ }
198
+ })
199
+ ])
200
+ : h("span", "")
201
+ ];
202
+ }
203
+ };
204
+ }
205
+ },
206
+ created () { },
207
+ methods: {
208
+ // 本身的初始化
209
+ selfReset () {
210
+ this.isExpandAction = false;
211
+ this.searchMode = "flat";
212
+ this.dftAdvSearch = {
213
+ logic: "and",
214
+ conditions: []
215
+ };
216
+ },
217
+
218
+ // 筛选回调
219
+ searchCb (conditions) {
220
+ this.isExpandAction = false;
221
+ this.dftAdvSearch.conditions = conditions;
222
+ },
223
+ // 展开/隐藏节点
224
+ toggleExpand (row, bool = true) {
225
+ this.isExpandAction = true;
226
+ // row.__isExpand__ = bool;
227
+ this.$set(row, "__isExpand__", bool);
228
+
229
+ this.toggleDescendantsShow(row, bool);
230
+ },
231
+
232
+ // 点击 -添加一行
233
+ clickCreate (operationItem, row, rowIndex) {
234
+ const newRow = {
235
+ ...this.$deepCopy(this.selfRowDefault),
236
+ _id: this.$ObjectID().str,
237
+ isLeaf: true,
238
+ children: [],
239
+ // __old__: false,
240
+ __isExpand__: false,
241
+ __isRendered__: true,
242
+ __isShow__: true,
243
+ __isTmpShow__: false,
244
+ __isSearchShow__: false
245
+ };
246
+
247
+ // !row代表最上级节点
248
+ if (!row) {
249
+ this.data.push({
250
+ ...newRow,
251
+ level: 1
252
+ });
253
+ } else {
254
+ row.children.push({
255
+ ...newRow,
256
+ level: row.level + 1
257
+ });
258
+
259
+ this.toggleExpand(row, true);
260
+ }
261
+ },
262
+ // 点击 -删除行
263
+ clickDelete (operationItem, row, rowIndex) {
264
+ this.$Modal.confirm({
265
+ title: "警告",
266
+ content: "确定删除吗?",
267
+ onOk: () => {
268
+ const parentNode = this.getParentNode(row, this.data);
269
+ const index = parentNode.children.findIndex(childNode => childNode._id === row._id);
270
+ parentNode.children.splice(index, 1);
271
+ }
272
+ });
273
+ },
274
+
275
+ /* ------ 工具方法 ------- */
276
+ // 加工树形数据
277
+ getCalcuedTree (treeData = [], columns = []) {
278
+ const loop = (list = [], parentRow) =>
279
+ list.forEach((row) => {
280
+ // 递归到叶子节点前 从上往下要处理的
281
+ columns.reduce((newRow, col) => {
282
+ const isNumberSummary = col._type === "number" && ![undefined, null, "", "no"].includes(col._summaryType);
283
+ const isDateSummary = col._type === "date" && ![undefined, null, ""].includes(col._writeSort);
284
+
285
+ if (isNumberSummary || isDateSummary) {
286
+ const val = isNumberSummary
287
+ ? newRow[col._key]
288
+ : ["downToUp"].includes(col._writeSort)
289
+ ? newRow[col._key]
290
+ : !parentRow || parentRow[col._key]
291
+ ? newRow[col._key]
292
+ : undefined;
293
+
294
+ this.$set(newRow, col._key, val);
295
+ }
296
+
297
+ return newRow;
298
+ }, row);
299
+
300
+ if (row.children && row.children.length) {
301
+ row.isLeaf = false;
302
+ loop(row.children, row);
303
+
304
+ // 递归到叶子节点后 从下往上要处理的
305
+ columns.reduce((newRow, col) => {
306
+ const isNumberSummary = col._type === "number" && ![undefined, null, "", "no"].includes(col._summaryType);
307
+ const isDateSummary = col._type === "date" && ![undefined, null, ""].includes(col._writeSort);
308
+
309
+ if (isNumberSummary || isDateSummary) {
310
+ const val = isNumberSummary
311
+ ? this.$calNumList(
312
+ newRow.children.map(subRow => subRow[col._key]),
313
+ col._summaryType,
314
+ { ...col, _defaultDigit: 2 },
315
+ false
316
+ )
317
+ : ["downToUp"].includes(col._writeSort)
318
+ ? this.$calDateList(
319
+ newRow.children.map(subRow => subRow[col._key]),
320
+ col._compareOperator,
321
+ col._dateType
322
+ )
323
+ : newRow[col._key];
324
+
325
+ this.$set(newRow, col._key, val);
326
+ }
327
+
328
+ return newRow;
329
+ }, row);
330
+ } else {
331
+ row.isLeaf = true;
332
+ }
333
+
334
+ // 初次进来把前端存的状态值全部清除(除了__readonly__)
335
+ if (this.initFlag) {
336
+ this.deleteProperties.forEach(property => {
337
+ delete row[property];
338
+ });
339
+
340
+ row.__old__ = true; // 老的数据都打上标记 尽管不一定会用
341
+ // row.__isExpand__ = false;
342
+ // row.__isSearchShow__ = false;
343
+ // 第一级的需要显示出来
344
+ if (row.level == 1) {
345
+ row.__isRendered__ = true;
346
+ row.__isShow__ = true;
347
+ row.__isTmpShow__ = true;
348
+ } else {
349
+ // row.__isRendered__ = false;
350
+ // row.__isShow__ = false;
351
+ // row.__isTmpShow__ = false;
352
+ }
353
+ }
354
+ });
355
+ loop(treeData);
356
+
357
+ this.initFlag = false;
358
+ return treeData;
359
+ },
360
+ // 获取父节点
361
+ getParentNode (curRow, tree = []) {
362
+ if (curRow.level === 1) {
363
+ return {
364
+ children: tree
365
+ };
366
+ } else {
367
+ let parentNode;
368
+
369
+ const loop = (list = []) => {
370
+ return list.some(row => {
371
+ if (row.level === curRow.level - 1) {
372
+ const isExist = row.children.some(childNode => childNode._id === curRow._id);
373
+ parentNode = row;
374
+ return isExist;
375
+ } else {
376
+ return loop(row.children);
377
+ }
378
+ });
379
+ };
380
+ loop(tree);
381
+
382
+ return parentNode;
383
+ }
384
+ },
385
+ // 切换子孙后代的显示/隐藏
386
+ toggleDescendantsShow (row, bool) {
387
+ const loop = (row, isFirstSon) => {
388
+ if (row.children && row.children.length) {
389
+ row.children.forEach(subRow => {
390
+ if (isFirstSon) {
391
+ this.$set(subRow, "__isRendered__", true);
392
+ this.$set(subRow, "__isShow__", bool);
393
+ this.$set(subRow, "__isTmpShow__", bool);
394
+ } else {
395
+ if (bool) {
396
+ this.$set(subRow, "__isShow__", subRow.__isTmpShow__);
397
+ } else {
398
+ this.$set(subRow, "__isShow__", false);
399
+ }
400
+ }
401
+
402
+ loop(subRow);
403
+ });
404
+ }
405
+ };
406
+
407
+ loop(row, true);
408
+ }
409
+ }
410
+ };