bri-components 1.3.30 → 1.3.31

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,10 +1,17 @@
1
1
  <template>
2
2
  <div class="DshTreeTable">
3
+ <dsh-buttons
4
+ class="DshTreeTable-btns"
5
+ itemClass="DshTreeTable-btns-item"
6
+ :list="$getOperationList(topOperationBtns)"
7
+ @click="$dispatchEvent($event)"
8
+ ></dsh-buttons>
9
+
3
10
  <!-- 搜索条件 -->
4
11
  <template v-if="searchFormList.length">
5
12
  <dsh-default-search
6
13
  :formList="searchFormList"
7
- :initValue="[]"
14
+ :initValue="advSearchObj.conditions"
8
15
  :labelWidth="searchLabelWidth"
9
16
  @change="searchCb"
10
17
  ></dsh-default-search>
@@ -20,6 +27,51 @@
20
27
  @changeSelect="changeSelect"
21
28
  @selectAll="changeSelect"
22
29
  ></bri-table>
30
+
31
+ <!-- 添加行 -->
32
+ <dsh-buttons
33
+ v-if="!isSearching"
34
+ class="DshFlatTable-create"
35
+ :list="$getOperationList(['canCreate'])"
36
+ @click="$dispatchEvent($event)"
37
+ ></dsh-buttons>
38
+
39
+ <!-- 全屏模式 -->
40
+ <dsh-modal
41
+ v-model="isEnlarge"
42
+ mode="custom"
43
+ :propsObj="modalPropsObj"
44
+ >
45
+ <template v-if="enlargeFlag">
46
+ <!-- 搜索条件 -->
47
+ <template v-if="searchFormList.length">
48
+ <dsh-default-search
49
+ :formList="searchFormList"
50
+ :initValue="advSearchObj.conditions"
51
+ :labelWidth="searchLabelWidth"
52
+ @change="searchCb"
53
+ ></dsh-default-search>
54
+ </template>
55
+
56
+ <!-- 表格 -->
57
+ <bri-table
58
+ class="DshTreeTable-main"
59
+ :columns="showColumns"
60
+ :data="listData"
61
+ :footer-data="footerData"
62
+ :propsObj="tablePropsObj"
63
+ @changeSelect="changeSelect"
64
+ @selectAll="changeSelect"
65
+ ></bri-table>
66
+
67
+ <!-- 添加行 -->
68
+ <dsh-buttons
69
+ class="DshFlatTable-create"
70
+ :list="$getOperationList(['canCreate'])"
71
+ @click="$dispatchEvent($event)"
72
+ ></dsh-buttons>
73
+ </template>
74
+ </dsh-modal>
23
75
  </div>
24
76
  </template>
25
77
 
@@ -37,6 +89,10 @@
37
89
  props: {},
38
90
  data () {
39
91
  return {
92
+ deleteProperties: ["__treeIndex__", "__isExpand__", "__isRendered__", "__isShow__", "__isTmpShow__", "__isSearchingShow__"], // 除了__old__
93
+ isExpandAction: false,
94
+
95
+ searchMode: "flat", // "flat", "tree"
40
96
  advSearchObj: {
41
97
  logic: "and",
42
98
  conditions: []
@@ -49,11 +105,23 @@
49
105
  },
50
106
  listData () {
51
107
  console.log("listData");
52
- const treeData = this.getCalcuTree(this.data, this.filterColumns);
53
- return this.$getTreeFlatArr(treeData, node =>
54
- (this.searchFormList.length ? this.$isAdvRelyAccord(this.advSearchObj, node) : true) &&
55
- (node.level === 1 || node.__isRendered__)
56
- );
108
+ const treeData = this.getCalcuedTree(this.data, this.filterColumns);
109
+ return this.$getTreeFlatArr(treeData, node => {
110
+ if (this.isSearching) {
111
+ if (node.__isRendered__ === true) {
112
+ node.__isSearchingShow__ = false;
113
+ }
114
+
115
+ const bool = this.$isAdvRelyAccord(this.advSearchObj, node);
116
+ if (bool) {
117
+ node.__isRendered__ = true;
118
+ node.__isSearchingShow__ = true;
119
+ }
120
+ return bool || node.__isRendered__;
121
+ } else {
122
+ return node.__isRendered__;
123
+ }
124
+ });
57
125
  },
58
126
  footerData () {
59
127
  console.log("footerData");
@@ -120,8 +188,22 @@
120
188
  cellStyleOption: {
121
189
  bodyCellClass: ({ row, column, rowIndex }) => {
122
190
  return "bri-table-td" +
123
- `${this.canEdit ? " bri-table-td-edit" : " bri-table-td-show"}` +
124
- `${row.__isShow__ === false ? " bri-table-td-hide" : ""}` +
191
+ `${
192
+ this.canEdit
193
+ ? " bri-table-td-edit"
194
+ : " bri-table-td-show"
195
+ }` +
196
+ `${
197
+ this.isSearching
198
+ ? !row.__isSearchingShow__
199
+ ? " bri-table-td-hide"
200
+ : ""
201
+ : !row.__isShow__
202
+ ? " bri-table-td-hide"
203
+ : row.__isShow__ === true && this.isExpandAction
204
+ ? " bri-table-td-visible"
205
+ : ""
206
+ }` +
125
207
  `${
126
208
  ["__isExpand__"].includes(column._key)
127
209
  ? " bri-table-td-expand"
@@ -146,7 +228,7 @@
146
228
  this.expandColumn,
147
229
  ...(this.useIndex === true ? [this.indexColumn] : []),
148
230
  ...this.$transformToColumns(this.contentColumns),
149
- ...(this.$getOperationList(["canDelete"]).length ? [this.operationColumn] : [])
231
+ ...(!this.isSearching && this.$getOperationList(["canDelete"]).length ? [this.operationColumn] : [])
150
232
  ];
151
233
  },
152
234
  expandColumn () {
@@ -159,14 +241,14 @@
159
241
  align: "center",
160
242
  fixed: "left",
161
243
  renderBodyCell: ({ row, column, rowIndex }, h) => {
162
- return row.children && row.children.length
244
+ return row.children && row.children.length && (this.isSearching ? this.searchMode === "tree" : true)
163
245
  ? h("Icon", {
164
246
  style: {
165
247
  width: "16px",
166
248
  height: "16px",
167
249
  cursor: "pointer",
168
250
  transform: row.__isExpand__ ? "rotate(90deg)" : "rotate(0deg)",
169
- transition: "transform 0.4s"
251
+ transition: "transform 0.3s"
170
252
  },
171
253
  props: {
172
254
  type: "ios-arrow-forward",
@@ -188,20 +270,20 @@
188
270
  _key: "__index__",
189
271
  key: "__index__",
190
272
  field: "__index__",
191
- width: 28 + 16 + (this.maxLevel - 1) * 36,
273
+ width: 28 + 16 + (this.maxLevel - 1) * 38,
192
274
  align: "left",
193
275
  fixed: "left",
194
276
  renderBodyCell: ({ row, column, rowIndex }, h) => {
195
277
  return [
196
278
  h("div", {
197
279
  style: {
198
- paddingLeft: `${(row.level - 1) * 16}px`,
280
+ paddingLeft: `${(row.level - 1) * 18}px`,
199
281
  fontWeight: "500"
200
282
  }
201
283
  }, row.__treeIndex__),
202
284
 
203
285
  // 添加符
204
- row.level < this.maxLevel && !this.isSearching
286
+ this.operationMap.canCreate && row.level < this.maxLevel && !this.isSearching
205
287
  ? h("div", {
206
288
  style: {
207
289
  position: "absolute",
@@ -241,30 +323,47 @@
241
323
  },
242
324
  created () {},
243
325
  methods: {
244
- // 默认筛选回调
326
+ // 筛选回调
245
327
  searchCb (conditions) {
328
+ this.isExpandAction = false;
246
329
  this.advSearchObj = {
247
330
  ...this.advSearchObj,
248
331
  conditions: conditions
249
332
  };
250
333
  },
334
+ // 展开/隐藏节点
251
335
  toggleExpand (row, bool = true) {
252
- this.$set(row, "__isRendered__", true);// 作用不大 可有可无
336
+ this.isExpandAction = true;
337
+ // this.$set(row, "__isRendered__", true);
338
+ // this.$set(row, "__isShow__", true);
253
339
  this.$set(row, "__isExpand__", bool);
254
340
 
255
341
  this.toggleDescendantsShow(row, bool);
256
342
  },
257
343
  // 点击 -添加一行
258
344
  clickCreate (operationItem, row, rowIndex) {
259
- row.children.push({
260
- _id: this.$ObjectID().str,
261
- ...this.$deepCopy(this.rowDefault),
262
- level: row.level + 1,
263
- isLeaf: true,
264
- children: []
265
- });
345
+ // !row代表最上级节点
346
+ if (!row) {
347
+ this.data.push({
348
+ _id: this.$ObjectID().str,
349
+ ...this.$deepCopy(this.rowDefault),
350
+ level: 1,
351
+ isLeaf: true,
352
+ children: [],
353
+ __isRendered__: true,
354
+ __isShow__: true
355
+ });
356
+ } else {
357
+ row.children.push({
358
+ _id: this.$ObjectID().str,
359
+ ...this.$deepCopy(this.rowDefault),
360
+ level: row.level + 1,
361
+ isLeaf: true,
362
+ children: []
363
+ });
266
364
 
267
- this.toggleExpand(row, true);
365
+ this.toggleExpand(row, true);
366
+ }
268
367
  },
269
368
  // 点击 -删除行
270
369
  clickDelete (operationItem, row, rowIndex) {
@@ -272,17 +371,20 @@
272
371
  title: "警告",
273
372
  content: "确定删除吗?",
274
373
  onOk: () => {
275
- const parentNode = this.getParentNode(this.data, row);
374
+ const parentNode = this.getParentNode(row, this.data);
276
375
  const index = parentNode.children.findIndex(childNode => childNode._id === row._id);
277
376
  parentNode.children.splice(index, 1);
278
- console.log(index);
279
- console.log(parentNode);
280
377
  }
281
378
  });
282
379
  },
380
+ // 点击导出
381
+ clickExport (operationItem) {
382
+ // operationItem.disabled = true;
383
+ },
283
384
 
284
385
  /* ------ 工具方法 ------- */
285
- getCalcuTree (tree = [], columns) {
386
+ // 加工树形数据
387
+ getCalcuedTree (treeData = [], columns) {
286
388
  const loop = (list = []) =>
287
389
  list.reduce((newList, node) => {
288
390
  if (node.children && node.children.length) {
@@ -307,15 +409,30 @@
307
409
  node.isLeaf = true;
308
410
  }
309
411
 
412
+ // 初次进来把前端存的状态值全部清除,除了__old__
413
+ if (!this.initFlag) {
414
+ this.deleteProperties.forEach(property => {
415
+ delete node[property];
416
+ });
417
+
418
+ if (node.level == 1) {
419
+ node.__isRendered__ = true;
420
+ node.__isShow__ = true;
421
+ }
422
+ }
423
+
310
424
  return [
311
425
  ...newList,
312
426
  node
313
427
  ];
314
428
  }, []);
315
429
 
316
- return loop(tree);
430
+ treeData = loop(treeData);
431
+ this.initFlag = true;
432
+ return treeData;
317
433
  },
318
- getParentNode (tree = [], curNode) {
434
+ // 获取父节点
435
+ getParentNode (curNode, tree = []) {
319
436
  if (curNode.level === 1) {
320
437
  return {
321
438
  children: tree
@@ -339,6 +456,7 @@
339
456
  return parentNode;
340
457
  }
341
458
  },
459
+ // 切换子孙后代的显示/隐藏
342
460
  toggleDescendantsShow (node, bool) {
343
461
  const loop = (node, isFirstSon) => {
344
462
  if (node.children && node.children.length) {
@@ -368,6 +486,16 @@
368
486
 
369
487
  <style lang="less" scoped>
370
488
  .DshTreeTable {
489
+ &-btns {
490
+ margin-bottom: 5px;
491
+ text-align: right;
492
+ color: @textColor;
493
+
494
+ &-item {
495
+
496
+ }
497
+ }
498
+
371
499
  &-main {
372
500
  width: 100%;
373
501
  height: auto;
@@ -67,6 +67,11 @@ export default {
67
67
  : [];
68
68
  },
69
69
 
70
+ selfPropsObj () {
71
+ return {
72
+ ...this.commonPropsObj
73
+ };
74
+ },
70
75
  tablePropsObj () {
71
76
  return {
72
77
  maxHeight: this.contentHeight,
@@ -81,11 +86,6 @@ export default {
81
86
  }
82
87
  };
83
88
  },
84
- selfPropsObj () {
85
- return {
86
- ...this.commonPropsObj
87
- };
88
- },
89
89
 
90
90
  filterColumns () {
91
91
  return this.columns.filter(col => this.$isAdvRelyShow(col, this.listData, this.parentObj, true));
@@ -226,43 +226,6 @@ export default {
226
226
  },
227
227
  ...colItem
228
228
  }));
229
- },
230
-
231
- allOperationMap () {
232
- return {
233
- canCreate: {
234
- name: "添加一行",
235
- type: "canCreate",
236
- size: "default",
237
- long: true,
238
- disabled: !!this.disabledCreateBtn,
239
- event: "clickCreate",
240
- btnType: "default"
241
- },
242
- canDelete: {
243
- name: "删除",
244
- type: "canDelete",
245
- btnType: "errorText",
246
- icon: "ios-trash-outline",
247
- size: "small",
248
- disabled: false,
249
- event: "clickDelete"
250
- },
251
- changeVal: {
252
- name: "改变输入框值",
253
- type: "changeVal",
254
- event: "changeVal"
255
- }
256
- };
257
- },
258
- operationMap () {
259
- return this.canEdit
260
- ? this.$categoryMapToMap(
261
- this.allOperationMap,
262
- null,
263
- this.disabledBtns ? ["canCreate", "canDelete"] : []
264
- )
265
- : {};
266
229
  }
267
230
  },
268
231
  created () { },
@@ -39,10 +39,71 @@ export default {
39
39
  data () {
40
40
  return {
41
41
  showRuleMessage: false, // 显示校验文字
42
- ruleRecordMap: {}
42
+ ruleRecordMap: {},
43
+
44
+ isEnlarge: false,
45
+ enlargeFlag: true, // 为重渲染膜态框内容而用
46
+ showImportModal: false,
47
+ timer: null,
48
+
49
+ topOperationMap: {
50
+ canImport: {
51
+ name: "导入",
52
+ type: "canImport",
53
+ icon: "ios-create-outline",
54
+ size: "small",
55
+ btnType: "text",
56
+ event: "clickImport"
57
+ },
58
+ canExport: {
59
+ name: "导出",
60
+ type: "canExport",
61
+ icon: "md-share-alt",
62
+ size: "small",
63
+ btnType: "text",
64
+ event: "clickExport"
65
+ },
66
+ canEnlarge: {
67
+ name: "全屏展示",
68
+ type: "canEnlarge",
69
+ icon: "md-expand",
70
+ size: "small",
71
+ btnType: "text",
72
+ event: "clickEnlarge"
73
+ }
74
+ },
75
+ baseOperationMap: {
76
+ canCreate: {
77
+ name: "添加一行",
78
+ type: "canCreate",
79
+ size: "default",
80
+ long: true,
81
+ disabled: false,
82
+ event: "clickCreate",
83
+ btnType: "default"
84
+ },
85
+ canDelete: {
86
+ name: "删除",
87
+ type: "canDelete",
88
+ btnType: "errorText",
89
+ icon: "ios-trash-outline",
90
+ size: "small",
91
+ disabled: false,
92
+ event: "clickDelete"
93
+ },
94
+ changeVal: {
95
+ name: "改变输入框值",
96
+ type: "changeVal",
97
+ event: "changeVal"
98
+ }
99
+ }
43
100
  };
44
101
  },
45
102
  computed: {
103
+ selfRowDefault () {
104
+ return this.$filterObj(this.filterColumns, this.rowDefault);
105
+ },
106
+
46
107
  commonPropsObj () {
47
108
  return {
48
109
  // isShare: false, // 是否是分享页在用
@@ -57,6 +118,8 @@ export default {
57
118
  _disabledBtns: false, // 禁用增删按钮
58
119
  _disabledCreateBtn: false, // 置灰新增按钮,目前只内部使用,comp_web数据表配置页那块
59
120
  _disabledOldDataRow: false, // 置灰老数据行包含删除
121
+ _isImport: false, // 导入
122
+ _isExport: false, // 导出
60
123
  ...this.propsObj,
61
124
 
62
125
  _contentHeight: this.propsObj._contentHeight || 500 // 表格最大高度
@@ -98,9 +161,69 @@ export default {
98
161
  disabledOldDataRow () {
99
162
  return this.selfPropsObj._disabledOldDataRow;
100
163
  },
164
+ isImport () {
165
+ return this.selfPropsObj._isImport;
166
+ },
167
+ isExport () {
168
+ return this.selfPropsObj._isExport;
169
+ },
101
170
 
102
- selfRowDefault () {
103
- return this.$filterObj(this.filterColumns, this.rowDefault);
171
+ modalPropsObj () {
172
+ return {
173
+ title: this.propsObj._key,
174
+ fullscreen: true,
175
+ showSlotClose: false,
176
+ closable: true
177
+ };
178
+ },
179
+ importParams () {
180
+ return {
181
+ _key: this.propsObj._key,
182
+ _id: this.parentObj._id
183
+ };
184
+ },
185
+
186
+ topOperationBtns () {
187
+ return Object.keys(this.topOperationMap);
188
+ },
189
+ baseOperationBtns () {
190
+ return Object.keys(this.baseOperationMap);
191
+ },
192
+ allOperationMap () {
193
+ return {
194
+ ...(this.topOperationMap || {}),
195
+ ...(this.baseOperationMap || {}),
196
+
197
+ canCreate: {
198
+ ...this.baseOperationMap.canCreate,
199
+ disabled: !!this.disabledCreateBtn
200
+ }
201
+ };
202
+ },
203
+ operationMap () {
204
+ return this.$categoryMapToMap(
205
+ this.allOperationMap,
206
+ undefined,
207
+ undefined,
208
+ this.canEdit
209
+ ? [
210
+ "canEnlarge",
211
+ ...(this.isImport ? ["canImport"] : []),
212
+ ...(this.isExport ? ["canExport"] : []),
213
+ ...(this.disabledBtns ? ["changeVal"] : this.baseOperationBtns)
214
+ ]
215
+ : [
216
+ "canEnlarge",
217
+ ...(this.isExport ? ["canExport"] : [])
218
+ ]
219
+ );
220
+ }
221
+ },
222
+ watch: {
223
+ isEnlarge (bool) {
224
+ setTimeout(() => {
225
+ this.enlargeFlag = bool;
226
+ }, 0);
104
227
  }
105
228
  },
106
229
  created () { },
@@ -111,6 +234,80 @@ export default {
111
234
 
112
235
  return this.listData.every((row, rowIndex) => this.getRowRuleResult(row, rowIndex));
113
236
  },
237
+
238
+ // 打开全屏模态框
239
+ clickEnlarge (operationItem) {
240
+ this.isEnlarge = true;
241
+ },
242
+ // 点击导入
243
+ clickImport () {
244
+ this.showImportModal = true;
245
+ },
246
+ // 点击导出
247
+ clickExport (operationItem) {
248
+ this.handleExport(operationItem);
249
+ },
250
+
251
+ // 导入成功回调
252
+ importCb (data) {
253
+ this.parentObj[this.propsObj._key] = data;
254
+ this.change("import");
255
+ },
256
+ // 接口 -导出
257
+ handleExport (operationItem) {
258
+ operationItem.disabled = true;
259
+
260
+ this.$https({
261
+ url: {
262
+ module: "sheet",
263
+ name: this.isDshFlatTable ? "exportFlatTableExcel" : "exportCascaderTableExcel",
264
+ params: {
265
+ modKey: this.propsObj.modKey
266
+ }
267
+ },
268
+ params: {
269
+ screenKey: this.propsObj.screenKey,
270
+ _key: this.propsObj._key,
271
+ _id: this.parentObj._id
272
+ },
273
+ callback: data => {
274
+ this.getJobStatus(operationItem, data.jobId, data.excel_url);
275
+ this.timer = setInterval(() => {
276
+ this.getJobStatus(operationItem, data.jobId, data.excel_url);
277
+ }, 1000);
278
+ }
279
+ });
280
+ },
281
+ // 接口 -获取导出地址
282
+ getJobStatus (operationItem, id, url) {
283
+ this.$https({
284
+ url: {
285
+ module: "sheet",
286
+ name: "getJobStatus"
287
+ },
288
+ params: {
289
+ jobId: id
290
+ },
291
+ callback: data => {
292
+ operationItem.disabled = false;
293
+ clearInterval(this.timer);
294
+
295
+ if (data.status === "completed") {
296
+ window.location.href = data.url;
297
+ } else if (data.status === "failed") {
298
+ this.$Message.info({
299
+ content: "操作失败,请稍后再试"
300
+ });
301
+ }
302
+ },
303
+ error: data => {
304
+ operationItem.disabled = false;
305
+ this.timer = null;
306
+ }
307
+ });
308
+ },
309
+
310
+ /* --------------- 工具方法 ------------- */
114
311
  // 整行校验结果
115
312
  getRowRuleResult (row, rowIndex) {
116
313
  return this.filterColumns.every(column => this.getColRuleResult(column, row, rowIndex).bool);
@@ -126,17 +323,16 @@ export default {
126
323
  };
127
324
  }
128
325
  },
129
-
130
- /* --------------- 工具方法 ------------- */
131
326
  getRowCanEdit (row) {
132
327
  return this.canEdit && ( // 是否是编辑状态
133
328
  this.disabledOldDataRow ? !!row.__isCreate__ : true); // 是否让老数据行置灰
134
329
  },
135
330
  getColCanEdit (col, row) {
136
331
  return (col.dependRowCanEdit ? row.canEdit !== false : true) && // 在老数据行里某些列不可编辑
332
+ (row.__old__ ? col._oldCanEdit : true) && // 在老数据行不可编辑(除_oldCanEdit=true的外)
333
+ (["number"].includes(col._type) && ![undefined, null, "", "no"].includes(col._summaryType) ? row.isLeaf !== false : true) && // 级联表格 -“需要计的数字列 且 不是叶子行的”不可编辑(必须用isLeaf !== false判断,因为牵扯内部表格也在用)
137
334
  col._enterType !== "calculate" && // 计算的不可编辑
138
- col._readonly !== true && // 不能为只读
139
- (["number"].includes(col._type) && ![undefined, null, "", "no"].includes(col._summaryType) ? row.isLeaf !== false : true); // 级联表格 -“需要计的数字列 且 不是叶子行的”不可编辑(必须用isLeaf !== false判断,因为牵扯内部表格也在用)
335
+ col._readonly !== true; // 不能为只读
140
336
  },
141
337
  getUnitCanEdit (col, row) {
142
338
  return this.getRowCanEdit(row) &&