htui-yllkbz 1.5.16 → 1.5.18

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.
@@ -4,132 +4,127 @@
4
4
  * @Author: hutao
5
5
  * @Date: 2021-11-11 11:23:24
6
6
  * @LastEditors: hutao
7
- * @LastEditTime: 2023-05-09 10:27:33
7
+ * @LastEditTime: 2024-08-03 16:22:31
8
8
  -->
9
9
  <template>
10
- <div v-loading="state.loading" style="background:#fff">
10
+ <div v-loading="state.loading"
11
+ style="background:#fff">
11
12
  <article>
12
- <el-table
13
- ref="comTable"
14
- :height="height"
15
- :max-height="maxHeight"
16
- :sum-text="sumText"
17
- :show-summary="showSummary"
18
- :summary-method="summaryMethod"
19
- :border="border"
20
- :default-expand-all="defaultExpandAll"
21
- :expand-row-keys="expandRowKeys"
22
- :stripe="stripe !== undefined ? stripe : true"
23
- :size="size || 'small'"
24
- :fit="fit"
25
- :span-method="spanMethodCom"
26
- :header-row-style="
13
+ <el-table ref="comTable"
14
+ :height="height"
15
+ :max-height="maxHeight"
16
+ :sum-text="sumText"
17
+ :show-summary="showSummary"
18
+ :summary-method="summaryMethod"
19
+ :border="border"
20
+ :default-expand-all="defaultExpandAll"
21
+ :expand-row-keys="expandRowKeys"
22
+ :stripe="stripe !== undefined ? stripe : true"
23
+ :size="size || 'small'"
24
+ :fit="fit"
25
+ :span-method="spanMethodCom"
26
+ :header-row-style="
27
27
  headerRowStyle || { background: 'var(--primary-92)' }
28
28
  "
29
- :header-row-class-name="headerRowClassName"
30
- :header-cell-class-name="headerCellClassName"
31
- :header-cell-style="headerCellStyle"
32
- :show-header="showHeader"
33
- :empty-text="emptyText || '暂无数据'"
34
- :row-style="rowStyle"
35
- :cell-style="cellStyle"
36
- :row-class-name="rowClassName"
37
- :cell-class-name="cellClassName"
38
- :current-row-key="currentRowKey"
39
- :highlight-current-row="highlightCurrentRow"
40
- :row-key="rowKey || 'id'"
41
- :data="data"
42
- tooltip-effect="dark"
43
- :tree-props="treeProps"
44
- @row-click="
29
+ :header-row-class-name="headerRowClassName"
30
+ :header-cell-class-name="headerCellClassName"
31
+ :header-cell-style="headerCellStyle"
32
+ :show-header="showHeader"
33
+ :empty-text="emptyText || '暂无数据'"
34
+ :row-style="rowStyle"
35
+ :cell-style="cellStyle"
36
+ :row-class-name="rowClassName"
37
+ :cell-class-name="cellClassName"
38
+ :current-row-key="currentRowKey"
39
+ :highlight-current-row="highlightCurrentRow"
40
+ :row-key="rowKey || 'id'"
41
+ :data="data"
42
+ tooltip-effect="dark"
43
+ :tree-props="treeProps"
44
+ @row-click="
45
45
  (row, column, event) => $emit('row-click', row, column, event)
46
46
  "
47
- @row-contextmenu="
47
+ @row-contextmenu="
48
48
  (row, column, event) => $emit('row-contextmenu', row, column, event)
49
49
  "
50
- @row-dblclick="
50
+ @row-dblclick="
51
51
  (row, column, event) => $emit('row-dblclick', row, column, event)
52
52
  "
53
- @header-click="(column, event) => $emit('header-click', column, event)"
54
- @header-contextmenu="
53
+ @header-click="(column, event) => $emit('header-click', column, event)"
54
+ @header-contextmenu="
55
55
  (column, event) => $emit('header-contextmenu', column, event)
56
56
  "
57
- @sort-change="
57
+ @header-dragend="headerDragend"
58
+ @sort-change="
58
59
  ({ column, prop, order }) =>
59
60
  $emit('sort-change', { column, prop, order })
60
61
  "
61
- @expand-change="(row, da) => $emit('expand-change', row, da)"
62
- @filter-change="(filter) => $emit('filter-change', filter)"
63
- @current-change="
62
+ @expand-change="(row, da) => $emit('expand-change', row, da)"
63
+ @filter-change="(filter) => $emit('filter-change', filter)"
64
+ @current-change="
64
65
  (currentRow, oldCurrentRow) =>
65
66
  $emit('current-change', currentRow, oldCurrentRow)
66
67
  "
67
- @select="(selection, row) => $emit('select', selection, row)"
68
- @select-all="(selection) => $emit('select-all', selection)"
69
- @selection-change="(selection) => $emit('selection-change', selection)"
70
- @cell-mouse-enter="
68
+ @select="(selection, row) => $emit('select', selection, row)"
69
+ @select-all="(selection) => $emit('select-all', selection)"
70
+ @selection-change="(selection) => $emit('selection-change', selection)"
71
+ @cell-mouse-enter="
71
72
  (row, column, cell, event) =>
72
73
  $emit('cell-mouse-enter', row, column, cell, event)
73
74
  "
74
- @cell-mouse-leave="
75
+ @cell-mouse-leave="
75
76
  (row, column, cell, event) =>
76
77
  $emit('cell-mouse-leave', row, column, cell, event)
77
78
  "
78
- @cell-click="
79
+ @cell-click="
79
80
  (row, column, cell, event) =>
80
81
  $emit('cell-click', row, column, cell, event)
81
82
  "
82
- @cell-dblclick="
83
+ @cell-dblclick="
83
84
  (row, column, cell, event) =>
84
85
  $emit('cell-dblclick', row, column, cell, event)
85
- "
86
- >
87
- <template slot="empty"> <slot name="empty"> </slot> </template>
88
- <el-table-column
89
- width="55"
90
- :resizable="false"
91
- v-if="checked"
92
- :reserve-selection="reserveSelection"
93
- :selectable="(row) => row[selectKey] !== false"
94
- type="selection"
95
- >
86
+ ">
87
+ <template slot="empty">
88
+ <slot name="empty"> </slot>
89
+ </template>
90
+ <el-table-column width="55"
91
+ :resizable="false"
92
+ v-if="checked"
93
+ :reserve-selection="reserveSelection"
94
+ :selectable="(row) => row[selectKey] !== false"
95
+ type="selection">
96
96
  </el-table-column>
97
- <el-table-column v-if="isExpand" type="expand">
97
+ <el-table-column v-if="isExpand"
98
+ type="expand">
98
99
  <!-- 展开行专用 -->
99
100
  <template slot-scope="props">
100
- <slot
101
- name="expand"
102
- :row="props.row"
103
- :column="props.column"
104
- :rowIndex="props.$index"
105
- >
101
+ <slot name="expand"
102
+ :row="props.row"
103
+ :column="props.column"
104
+ :rowIndex="props.$index">
106
105
  </slot>
107
106
  </template>
108
107
  </el-table-column>
109
- <el-table-column
110
- v-if="!hideOrder"
111
- :resizable="false"
112
- :label="keyName === undefined ? '序号' : keyName"
113
- :align="'center'"
114
- width="55"
115
- >
108
+ <el-table-column v-if="!hideOrder"
109
+ :resizable="false"
110
+ :label="keyName === undefined ? '序号' : keyName"
111
+ :align="'center'"
112
+ width="55">
116
113
  <template slot="header">
117
114
  <slot :name="'header_order'">
118
- <div @click="showFilterModel" v-if="showFilter" title="筛选排序">
119
- <el-button type="text"
120
- ><i class="el-icon-s-grid"></i
121
- ></el-button>
115
+ <div @click="showFilterModel"
116
+ v-if="showFilter"
117
+ title="筛选排序">
118
+ <el-button type="text"><i class="el-icon-s-grid"></i></el-button>
122
119
  </div>
123
120
  <span v-else>{{ keyName || '序号' }}</span>
124
121
  </slot>
125
122
  </template>
126
123
  <template slot-scope="{ row, column, $index }">
127
- <slot
128
- name="body_order"
129
- :row="row"
130
- :column="column"
131
- :$index="$index"
132
- >
124
+ <slot name="body_order"
125
+ :row="row"
126
+ :column="column"
127
+ :$index="$index">
133
128
  {{
134
129
  (state.pageInfo.currentPage - 1) * state.pageInfo.pageSize +
135
130
  ($index + 1)
@@ -138,169 +133,147 @@
138
133
  </template>
139
134
  </el-table-column>
140
135
 
141
- <template v-for="(item, index) in state.showColumns">
142
- <HtTableColumn
143
- :key="`${item.key}_${index}`"
144
- :item="item"
145
- @showFiles="showFiles"
146
- >
147
- <template
148
- v-for="child in allChildren"
149
- :slot="child.key"
150
- slot-scope="scope"
151
- >
152
- <slot
153
- :name="child.key"
154
- :row="scope.row"
155
- :column="scope.column"
156
- :rowIndex="scope.rowIndex"
157
- >
136
+ <template v-for="(item, index) in showColumns">
137
+
138
+ <HtTableColumn :key="`${item.key}_${index}`"
139
+ :item="item"
140
+ @showFiles="showFiles">
141
+ <template v-for="child in allChildren"
142
+ :slot="child.key"
143
+ slot-scope="scope">
144
+ <slot :name="child.key"
145
+ :row="scope.row"
146
+ :column="scope.column"
147
+ :rowIndex="scope.rowIndex">
158
148
  </slot>
159
149
  </template>
160
- <template
161
- v-for="child in allChildren"
162
- slot-scope="{ column, $index }"
163
- :slot="'header_' + child.key"
164
- >
165
- <slot
166
- :name="'header_' + child.key"
167
- :column="column"
168
- :$index="$index"
169
- ></slot>
150
+ <template v-for="child in allChildren"
151
+ slot-scope="{ column, $index }"
152
+ :slot="'header_' + child.key">
153
+ <slot :name="'header_' + child.key"
154
+ :column="column"
155
+ :$index="$index"></slot>
170
156
  </template>
171
157
 
172
- <template :slot="item.key" slot-scope="scope">
173
- <slot
174
- :name="item.key"
175
- :row="scope.row"
176
- :column="scope.column"
177
- :rowIndex="scope.rowIndex"
178
- >
158
+ <template :slot="item.key"
159
+ slot-scope="scope">
160
+
161
+ <slot :name="item.key"
162
+ :row="scope.row"
163
+ :column="scope.column"
164
+ :rowIndex="scope.rowIndex">
179
165
  </slot>
180
166
  </template>
181
- <template
182
- slot-scope="{ column, $index }"
183
- :slot="'header_' + item.key"
184
- >
185
- <slot
186
- :name="'header_' + item.key"
187
- :column="column"
188
- :$index="$index"
189
- ></slot>
167
+ <template slot-scope="{ column, $index }"
168
+ :slot="'header_' + item.key">
169
+ <slot :name="'header_' + item.key"
170
+ :column="column"
171
+ :$index="$index"></slot>
190
172
  </template>
191
173
  </HtTableColumn>
192
174
  </template>
193
175
  </el-table>
194
176
  </article>
195
- <footer v-if="!hidePage" class="ht-table-footer">
177
+ <footer v-if="!hidePage"
178
+ class="ht-table-footer">
196
179
  <el-row name="footer">
197
180
  <!-- 此处建议使用el-col -->
198
181
  <slot name="footerLeft"></slot>
199
182
 
200
183
  <el-col :span="$slots['footerLeft'] ? 12 : 24">
201
184
  <!-- <p style="width:90px;float:left">共{{data.length}}条</p> -->
202
- <PageInfo
203
- :hide-on-single-page="pagination && pagination.hideOnSinglePage"
204
- :small="pagination && pagination.small"
205
- :style="pageStyle"
206
- @onchange="(e) => $emit('onchange', e)"
207
- :page-sizes="pagination && pagination.pageSizes"
208
- :page-info="state.pageInfo"
209
- ></PageInfo>
185
+ <PageInfo :hide-on-single-page="pagination && pagination.hideOnSinglePage"
186
+ :small="pagination && pagination.small"
187
+ :style="pageStyle"
188
+ @onchange="(e) => $emit('onchange', e)"
189
+ :page-sizes="pagination && pagination.pageSizes"
190
+ :page-info="state.pageInfo"></PageInfo>
210
191
  </el-col>
211
192
  </el-row>
212
193
  </footer>
213
194
  <!-- 详情弹框 -->
214
- <el-dialog
215
- :visible.sync="state.visibleFilter"
216
- title="属性设置"
217
- v-if="state.visibleFilter"
218
- :append-to-body="true"
219
- :modal-append-to-body="true"
220
- :close-on-click-modal="true"
221
- width="400px"
222
- >
223
- <p
224
- slot="title"
225
- style="font-weight:700;font-size:18px;float:left;margin:0"
226
- >
195
+ <el-dialog :visible.sync="state.visibleFilter"
196
+ title="属性设置"
197
+ v-if="state.visibleFilter"
198
+ :append-to-body="true"
199
+ :modal-append-to-body="true"
200
+ :close-on-click-modal="true"
201
+ width="400px">
202
+ <p slot="title"
203
+ style="font-weight:700;font-size:18px;float:left;margin:0">
227
204
  自定义列展示
228
205
  </p>
229
206
  <div style="overflow:hidden;height:35vh;margin-top:12px">
230
207
  <el-scrollbar style="height: calc(35vh + 17px)">
231
- <el-tree
232
- :data="getAllColumns"
233
- ref="tree"
234
- show-checkbox
235
- :expand-on-click-node="false"
236
- node-key="key"
237
- :check-on-click-node="false"
238
- @node-drag-start="handleDragStart"
239
- @node-drag-enter="handleDragEnter"
240
- @node-drag-leave="handleDragLeave"
241
- @node-drag-over="handleDragOver"
242
- @node-drag-end="handleDragEnd"
243
- @node-drop="handleDrop"
244
- :default-checked-keys="state.checkedColumnKeys"
245
- @check-change="changeColumns"
246
- :allow-drag="allowDrag"
247
- :draggable="draggable"
248
- :allow-drop="allowDrop"
249
- >
250
- <span class="custom-tree-node" slot-scope="{ node, data }">
251
- <slot :name="'header_' + data.key" :column="data"
252
- >{{ data.title
208
+ <el-tree :data="getAllColumns"
209
+ ref="tree"
210
+ show-checkbox
211
+ :expand-on-click-node="false"
212
+ node-key="key"
213
+ :check-on-click-node="false"
214
+ @node-drag-start="handleDragStart"
215
+ @node-drag-enter="handleDragEnter"
216
+ @node-drag-leave="handleDragLeave"
217
+ @node-drag-over="handleDragOver"
218
+ @node-drag-end="handleDragEnd"
219
+ @node-drop="handleDrop"
220
+ :default-checked-keys="state.checkedColumnKeys"
221
+ @check-change="changeColumns"
222
+ :allow-drag="allowDrag"
223
+ :draggable="draggable"
224
+ :allow-drop="allowDrop">
225
+ <span class="custom-tree-node"
226
+ slot-scope="{ node, data }">
227
+ <slot :name="'header_' + data.key"
228
+ :column="data">{{ data.title
253
229
  }}<span style="color:#C0C4CC">{{
254
230
  data.property ? `(${data.property})` : ''
255
- }}</span></slot
256
- >
231
+ }}</span></slot>
257
232
  </span>
258
233
  </el-tree>
259
234
  </el-scrollbar>
260
235
  </div>
261
236
  <span slot="footer">
262
- <el-button type="primary" @click="confirmSortAndshow">确定</el-button>
237
+ <el-button type="primary"
238
+ @click="confirmSortAndshow">确定</el-button>
263
239
  <el-button @click="state.visibleFilter = false">取消</el-button>
264
240
  <el-button @click="resetColumn">重置</el-button>
265
241
  </span>
266
242
  </el-dialog>
267
243
  <!-- 附件详情弹框 -->
268
- <el-dialog
269
- :visible.sync="state.visibleFile"
270
- v-if="state.visibleFile"
271
- title="附件查看"
272
- :append-to-body="true"
273
- :modal-append-to-body="true"
274
- :close-on-click-modal="true"
275
- width="400px"
276
- :center="true"
277
- >
278
- <p
279
- slot="title"
280
- style="font-weight:700;font-size:18px;float:left;margin:0"
281
- >
244
+ <el-dialog :visible.sync="state.visibleFile"
245
+ v-if="state.visibleFile"
246
+ title="附件查看"
247
+ :append-to-body="true"
248
+ :modal-append-to-body="true"
249
+ :close-on-click-modal="true"
250
+ width="400px"
251
+ :center="true">
252
+ <p slot="title"
253
+ style="font-weight:700;font-size:18px;float:left;margin:0">
282
254
  附件查看
283
255
  </p>
284
256
 
285
257
  <div style="overflow:hidden;height:calc(30vh)">
286
258
  <el-scrollbar style="height: calc(100% + 17px)">
287
- <HtUploadFiles :disabled="true" v-model="state.files"></HtUploadFiles>
259
+ <HtUploadFiles :disabled="true"
260
+ v-model="state.files"></HtUploadFiles>
288
261
  </el-scrollbar>
289
262
  </div>
290
263
  </el-dialog>
291
264
  </div>
292
265
  </template>
293
266
  <script lang="ts">
294
- import { Component, Prop, Vue, Watch } from 'vue-property-decorator';
295
- import { Column, PageInfoType } from '@/packages/type';
296
- import PageInfo from '@/packages/PageInfo/index.vue';
297
- import HtUploadFiles from '@/packages/HtUploadFiles/index.vue';
298
- import HtShowBaseData from '@/packages/HtShowBaseData';
299
- import HtOrgInfo from '@/packages/HtOrgInfo';
300
- import HtSelectUnit from '@/packages/HtSelectUnit';
301
- import HtTableColumn from './htTableColumn.vue';
302
- import ElmentUI from 'element-ui';
303
- import { getSpanMethod } from './table-span-method';
267
+ import { Component, Prop, Vue, Watch } from "vue-property-decorator";
268
+ import { Column, PageInfoType } from "@/packages/type";
269
+ import PageInfo from "@/packages/PageInfo/index.vue";
270
+ import HtUploadFiles from "@/packages/HtUploadFiles/index.vue";
271
+ import HtShowBaseData from "@/packages/HtShowBaseData";
272
+ import HtOrgInfo from "@/packages/HtOrgInfo";
273
+ import HtSelectUnit from "@/packages/HtSelectUnit";
274
+ import HtTableColumn from "./htTableColumn.vue";
275
+ import ElmentUI from "element-ui";
276
+ import { getSpanMethod } from "./table-span-method";
304
277
  Vue.use(ElmentUI);
305
278
  interface State {
306
279
  pageInfo: PageInfoType;
@@ -323,7 +296,7 @@ interface State {
323
296
  files?: string;
324
297
  }
325
298
  @Component({
326
- name: 'HtTable',
299
+ name: "HtTable",
327
300
  components: {
328
301
  PageInfo,
329
302
  HtUploadFiles,
@@ -342,7 +315,7 @@ export default class HtTable extends Vue {
342
315
  /** 分页样式自定义 */
343
316
  @Prop() pageStyle!: string;
344
317
  /** 合计行第一列的文本 */
345
- @Prop({ default: '合计' }) sumText!: string;
318
+ @Prop({ default: "合计" }) sumText!: string;
346
319
  @Prop({ default: false }) defaultExpandAll!: boolean;
347
320
  @Prop() expandRowKeys!: string[];
348
321
  /** 自定义合并方法 */
@@ -373,8 +346,8 @@ export default class HtTable extends Vue {
373
346
  @Prop() maxHeight?: string | number;
374
347
  @Prop() rowKey?: string;
375
348
  @Prop() stripe?: boolean;
376
- @Prop() border?: boolean;
377
- @Prop() size?: 'medium' | 'small' | 'mini';
349
+ @Prop({ default: true }) border?: boolean;
350
+ @Prop() size?: "medium" | "small" | "mini";
378
351
  @Prop() fit?: boolean;
379
352
  @Prop() showHeader?: boolean;
380
353
  @Prop() rowClassName?: any;
@@ -382,7 +355,7 @@ export default class HtTable extends Vue {
382
355
  /** 是否启用复选框 */
383
356
  @Prop() checked!: boolean;
384
357
  /** 设置的禁用字段值--与check同步 */
385
- @Prop({ default: 'selectable' }) selectKey?: string;
358
+ @Prop({ default: "selectable" }) selectKey?: string;
386
359
  /** 仅对 type=selection 的列有效,类型为 Function,Function 的返回值用来决定这一行的 CheckBox 是否可以勾选 */
387
360
  @Prop() selectable?: any;
388
361
  @Prop() currentRowKey?: string | number;
@@ -445,7 +418,7 @@ export default class HtTable extends Vue {
445
418
  this.state.visibleFilter = false;
446
419
  if (this.uuId) {
447
420
  window.localStorage.setItem(
448
- 'table_' + this.uuId,
421
+ "table_" + this.uuId,
449
422
  JSON.stringify(this.columns || [])
450
423
  );
451
424
  }
@@ -453,25 +426,35 @@ export default class HtTable extends Vue {
453
426
  /** 获取展示的keys值 */
454
427
  getShowKeys(data: Column[]) {
455
428
  const arr: string[] = [];
456
- data.forEach((item) => {
457
- if (item.checked) {
458
- arr.push(item.key);
459
- }
460
- });
429
+ function findKeys(array: Column[]) {
430
+ array.forEach((item) => {
431
+ if (item.checked) {
432
+ arr.push(item.key);
433
+ }
434
+ if (item.children?.length) {
435
+ findKeys(item.children);
436
+ }
437
+ });
438
+ }
439
+ findKeys(data);
440
+
461
441
  this.state.showColumnKeys = arr;
462
442
  }
463
443
  /** 初始化columns */
464
444
  creatInitColumnKey(columns: Column[]) {
465
445
  this.state.allColumns = columns;
466
- this.state.showColumns = columns;
467
-
468
- this.state.allColumns.forEach((item) => {
469
- item.checked = item.checked === false ? false : true;
470
- });
471
- this.$nextTick(() => {
472
- (this.$refs.comTable as any).doLayout();
473
- // el-table加ref="comTable"
474
- });
446
+ /** 如果没有配置默认展示的字段则展示全部字段 */
447
+ const checkTrueArr = columns.filter((item) => item.checked !== false);
448
+ if (!checkTrueArr.length) {
449
+ this.state.allColumns.forEach((item) => {
450
+ item.checked = true;
451
+ });
452
+ } else {
453
+ this.state.allColumns.forEach((item) => {
454
+ item.checked = item.checked === false ? false : true;
455
+ });
456
+ }
457
+ this.setTableHeader(this.state.allColumns);
475
458
  this.getShowKeys(this.state.allColumns);
476
459
  }
477
460
  doLayout() {
@@ -481,7 +464,7 @@ export default class HtTable extends Vue {
481
464
  });
482
465
  }
483
466
  /** 展示附件信息 */
484
- showFiles(val = '') {
467
+ showFiles(val = "") {
485
468
  this.state.files = val;
486
469
  this.state.visibleFile = true;
487
470
  }
@@ -519,14 +502,76 @@ export default class HtTable extends Vue {
519
502
  // console.log("tree drop: ", dropNode, dropType);
520
503
  }
521
504
  /** 节点是否被插入 */
522
- allowDrop(draggingNode: any, dropNode: any, type: string) {
523
- return type !== 'inner';
505
+ allowDrop(_draggingNode: any, _dropNode: any, type: string) {
506
+ if (_draggingNode.level === _dropNode.level) {
507
+ return type === "prev" || type === "next";
508
+ } else {
509
+ // 不同级进行处理
510
+ return false;
511
+ }
524
512
  }
525
513
  /** 节点是否允许拖动 */
526
514
  allowDrag(draggingNode: any) {
527
515
  return !draggingNode.data.disabled;
528
516
  }
517
+ headerDragend(
518
+ newWidth: number,
519
+ _oldWidth: number,
520
+ column: any,
521
+ _event: MouseEvent
522
+ ) {
523
+ const allColumnsStr: string | null = window.localStorage.getItem(
524
+ "table_" + this.uuId
525
+ );
526
+ if (allColumnsStr) {
527
+ const Columns = JSON.parse(allColumnsStr);
529
528
 
529
+ let currentIndex: {
530
+ parentIndex: number;
531
+ currentIndex: number;
532
+ } = { parentIndex: -1, currentIndex: -1 };
533
+ function getCIndex(arr: Column[], _parent?: Column, pIndex = -1) {
534
+ for (let i = 0; i < arr.length; i++) {
535
+ if (arr[i].key === column.property) {
536
+ currentIndex = {
537
+ parentIndex: pIndex,
538
+ currentIndex: i,
539
+ };
540
+ break;
541
+ } else {
542
+ getCIndex(arr[i].children || [], arr[i], i);
543
+ }
544
+ }
545
+ }
546
+ getCIndex(Columns, undefined, undefined);
547
+ if (currentIndex.parentIndex > -1) {
548
+ Columns[currentIndex.parentIndex].children[
549
+ currentIndex.currentIndex
550
+ ].width = newWidth;
551
+ this.setTableHeader(Columns);
552
+ } else if (
553
+ currentIndex.parentIndex == -1 &&
554
+ currentIndex.currentIndex > -1
555
+ ) {
556
+ Columns[currentIndex.currentIndex].width = newWidth;
557
+ this.setTableHeader(Columns);
558
+ }
559
+ }
560
+ }
561
+ /** 缓存table头部信息 */
562
+ setTableHeader(allColumns: Column[]) {
563
+ if (this.uuId) {
564
+ window.localStorage.setItem(
565
+ "table_" + this.uuId,
566
+ JSON.stringify(allColumns)
567
+ );
568
+ }
569
+ this.state.showColumns = allColumns;
570
+
571
+ this.state.visibleFilter = false;
572
+ this.state.loading = false;
573
+ this.doLayout();
574
+ }
530
575
  /** 现在自定义列弹窗 */
531
576
  showFilterModel() {
532
577
  this.state.visibleFilter = true;
@@ -534,14 +579,8 @@ export default class HtTable extends Vue {
534
579
  this.state.allColumns = JSON.parse(JSON.stringify(this.state.showColumns));
535
580
  }
536
581
  /** 自定义列表时候选中列 */
537
- changeColumns(node: any, checked: boolean) {
538
- let { checkedColumnKeys } = this.state;
539
- if (checked) {
540
- checkedColumnKeys.push(node.key);
541
- } else {
542
- checkedColumnKeys = checkedColumnKeys.filter((item) => item !== node.key);
543
- }
544
- this.state.checkedColumnKeys = checkedColumnKeys;
582
+ changeColumns() {
583
+ this.state.checkedColumnKeys = (this.$refs.tree as any).getCheckedKeys();
545
584
  }
546
585
  /** 自定义列排序的确定功能 */
547
586
  confirmSortAndshow() {
@@ -549,50 +588,46 @@ export default class HtTable extends Vue {
549
588
  this.state.showColumns = [];
550
589
  this.state.allColumns = this.getAllColumns;
551
590
  const { allColumns, checkedColumnKeys } = this.state;
552
- //对列表check复制
553
- allColumns.forEach(
554
- (item) => (item.checked = checkedColumnKeys.includes(item.key))
555
- );
591
+
592
+ function findChecked(colums: Column[]) {
593
+ colums.forEach((item) => {
594
+ item.checked = checkedColumnKeys.includes(item.key);
595
+ //如果子级不存在直接处理
596
+ if (!item.children?.length) {
597
+ } else {
598
+ findChecked(item.children);
599
+ }
600
+ });
601
+ }
602
+ findChecked(allColumns);
603
+
556
604
  //将复选框选中行展示到列中 */
557
605
  this.state.showColumnKeys = checkedColumnKeys;
558
606
  //将列的顺序进行处理已经存储
559
607
 
560
- if (this.uuId) {
561
- window.localStorage.setItem(
562
- 'table_' + this.uuId,
563
- JSON.stringify(allColumns)
564
- );
565
- }
566
- this.state.showColumns = allColumns;
567
- this.state.visibleFilter = false;
568
- this.state.loading = false;
569
- this.$nextTick(() => {
570
- (this.$refs.comTable as any).doLayout();
571
- // el-table加ref="multipleTable"
572
- });
608
+ this.setTableHeader(allColumns);
573
609
 
574
610
  /** 自定义列回调 */
575
- this.$emit('customColumn', allColumns);
611
+ this.$emit("customColumn", allColumns);
576
612
  }
577
613
 
578
614
  /** 获取显示出来的table头信息 */
579
615
  get showColumns() {
580
- const { showColumnKeys, showColumns } = this.state;
581
- let obj: any = {};
582
- for (const key in showColumnKeys) {
583
- obj = { ...obj, [showColumnKeys[key]]: true };
584
- }
585
- /** 缓存起来下次使用 --todo只做了显示没有做排序缓存 */
586
- if (this.uuId) {
587
- window.localStorage.setItem(
588
- 'table_' + this.uuId,
589
- JSON.stringify(showColumnKeys)
590
- );
591
- }
616
+ const stateColumns: Column[] = JSON.parse(
617
+ JSON.stringify(this.state.showColumns)
618
+ );
592
619
 
593
- const data = showColumns.filter((item) => obj[item.key as string]);
594
- return data;
620
+ stateColumns.forEach((item) => {
621
+ if (item.children?.length && item.checked == false) {
622
+ const isChecked = !!item.children.find((item) => item.checked);
623
+ item.checked = isChecked;
624
+ item.children = item.children.filter((item) => item.checked !== false);
625
+ }
626
+ });
627
+ console.log("showColumns", stateColumns);
628
+ return stateColumns;
595
629
  }
630
+
596
631
  get allChildren() {
597
632
  const { showColumns } = this.state;
598
633
  let allchildren: Column[] = [];
@@ -605,7 +640,7 @@ export default class HtTable extends Vue {
605
640
  }
606
641
 
607
642
  /** 监听 */
608
- @Watch('pageInfo')
643
+ @Watch("pageInfo")
609
644
  setPageInfo(val?: PageInfoType) {
610
645
  if (val) {
611
646
  const pageInfo: PageInfoType = val;
@@ -622,7 +657,12 @@ export default class HtTable extends Vue {
622
657
 
623
658
  return allColumns.filter((item) => !item.hide);
624
659
  }
625
- @Watch('columns', { immediate: true })
660
+ @Watch("showColumns")
661
+ resetShowCOlums() {
662
+ console.log("重置");
663
+ this.doLayout();
664
+ }
665
+ @Watch("columns", { immediate: true })
626
666
  setColumns(columns?: Column[]) {
627
667
  if (!columns) {
628
668
  return;
@@ -634,7 +674,7 @@ export default class HtTable extends Vue {
634
674
  //---showColumnKeys 要改变
635
675
  //---排列顺序要改变 todo
636
676
  const allColumns: string | null = window.localStorage.getItem(
637
- 'table_' + this.uuId
677
+ "table_" + this.uuId
638
678
  );
639
679
  if (allColumns) {
640
680
  this.state.allColumns = JSON.parse(allColumns);