n20-common-lib 3.0.29 → 3.0.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "n20-common-lib",
3
- "version": "3.0.29",
3
+ "version": "3.0.31",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "serve": "vue-cli-service serve",
@@ -57,6 +57,7 @@
57
57
  @cell-mouseenter="handleCellMouseEnter"
58
58
  @cell-mouseleave="handleCellMouseLeave"
59
59
  @scroll="handleTableScroll"
60
+ @toggle-tree-expand="syncExpandState"
60
61
  >
61
62
  <template v-for="(item, i) in _columns">
62
63
  <slot v-if="item.slotName" :name="item.slotName" :column="item"></slot>
@@ -196,24 +197,34 @@
196
197
  </template>
197
198
  </vxe-column>
198
199
  </template>
199
- <vxe-column
200
- fixed="right"
201
- header-class-name="fixed-column__static"
202
- :min-width="showColumn && showSetsize ? 80 : 50"
203
- >
204
- <div slot="header">
205
- <i
206
- v-if="showColumn"
207
- v-title="$lc('设置显示列')"
208
- class="v3-icon-system-solution pointer"
209
- @click="$emit('visible-column')"
210
- ></i>
211
- <tableSetSize v-if="showSetsize" :size="sizeC" v-bind="$attrs" @update:size="sizeUp" @resize="sizeSet" />
212
- </div>
200
+ <vxe-column fixed="right" header-class-name="fixed-column__static" :min-width="clacStaticColumnWidth">
201
+ <template #header>
202
+ <div class="flex-box flex-v flex-c">
203
+ <i
204
+ v-if="showColumn"
205
+ v-title="$lc('设置显示列')"
206
+ class="v3-icon-system-solution pointer"
207
+ :class="hoverIconKey === 'showColumn' ? 'color-primary' : ''"
208
+ @mouseenter="hoverIconKey = 'showColumn'"
209
+ @mouseleave="hoverIconKey = null"
210
+ @click="$emit('visible-column')"
211
+ ></i>
212
+ <tableSetSize v-if="showSetsize" :size="sizeC" v-bind="$attrs" @update:size="sizeUp" @resize="sizeSet" />
213
+ <i
214
+ v-if="$attrs.treeConfig || $attrs['tree-config']"
215
+ v-title="!isExpand ? $lc('展开分组') : $lc('折叠分组')"
216
+ class="pointer"
217
+ :class="[isExpand ? 'v3-icon-group-collapse' : 'v3-icon-group-expand', hoverIconKey === 'toggleExpand' ? 'color-primary' : '']"
218
+ @mouseenter="hoverIconKey = 'toggleExpand'"
219
+ @mouseleave="hoverIconKey = null"
220
+ @click="toggleExpand"
221
+ ></i>
222
+ </div>
223
+ </template>
213
224
  </vxe-column>
214
225
  <template #empty>
215
226
  <slot name="empty">
216
- <empty type="empty" :content="$lc('暂无数据')" :height="200" :width="200" />
227
+ <empty type="noData" :content="$lc('暂无数据')" :height="200" :width="200" />
217
228
  </slot>
218
229
  </template>
219
230
  </vxe-table>
@@ -429,7 +440,9 @@ export default {
429
440
  hoverHideTimer: null, // 隐藏延迟定时器
430
441
  isHoverOnBtnGroup: false, // 鼠标是否在按钮组上
431
442
  isDropdownVisible: false, // "更多"下拉菜单是否展开
432
- hoverHeaderProp: null // 当前悬停表头列的 prop
443
+ hoverHeaderProp: null, // 当前悬停表头列的 prop
444
+ hoverIconKey: null, // 当前悬停的静态列头图标标识
445
+ isExpand: false
433
446
  }
434
447
  },
435
448
  computed: {
@@ -474,6 +487,12 @@ export default {
474
487
  right: 0, // 固定在右侧设置列按钮左边
475
488
  height: `${this.hoverBtnsPosition.height}px`
476
489
  }
490
+ },
491
+ // 计算列宽
492
+ clacStaticColumnWidth() {
493
+ const hasExpand = this.$attrs.expandConfig || this.$attrs['expand-config']
494
+ const activeCount = [this.showColumn, this.showSetsize, hasExpand].filter(Boolean).length
495
+ return activeCount === 3 ? 100 : activeCount === 2 ? 80 : 50
477
496
  }
478
497
  },
479
498
  watch: {
@@ -499,6 +518,38 @@ export default {
499
518
  this.clearHoverTimers()
500
519
  },
501
520
  methods: {
521
+ /**
522
+ * 一键展开/折叠表格树形行(仅处理第一层级数据行)
523
+ * 通过 vxe-table 的 setTreeExpand API 批量设置顶层行的展开状态,
524
+ * await Promise 完成后再同步 isExpand 状态,保证图标与实际展开状态一致
525
+ * 不直接操作 DOM,不影响排序、筛选等原有逻辑
526
+ * @returns {Promise<void>}
527
+ */
528
+ async toggleExpand() {
529
+ const $table = this.$refs.vxeTable
530
+ if (!$table) return
531
+ // 仅取顶层数据行(data prop 中的第一层,不包含子级)
532
+ const topLevelRows = this.data || []
533
+ if (topLevelRows.length === 0) return
534
+ // 切换展开状态:当前已展开则折叠,当前已折叠则展开
535
+ const nextExpand = !this.isExpand
536
+ // setTreeExpand 返回 Promise,await 确保展开动作完成后再更新图标状态
537
+ await $table.setTreeExpand(topLevelRows, nextExpand)
538
+ this.isExpand = nextExpand
539
+ },
540
+ /**
541
+ * 同步单行手动展开/折叠后的图标状态
542
+ * 监听 vxe-table toggle-tree-expand 事件,根据当前所有顶层行展开情况更新 isExpand
543
+ * @param {Object} expandRecords - vxe-table 当前所有已展开的行记录
544
+ * @returns {void}
545
+ */
546
+ syncExpandState({ expandRecords }) {
547
+ const topLevelRows = this.data || []
548
+ if (topLevelRows.length === 0) return
549
+ // 若顶层行全部处于展开状态则认为是"已展开",否则为"未全部展开"
550
+ const expandSet = new Set(expandRecords)
551
+ this.isExpand = topLevelRows.every((row) => expandSet.has(row))
552
+ },
502
553
  // 锁定列:将该列 fixed 设为 'left',直接修改 prop 对象并刷新表格
503
554
  lockColumn(item) {
504
555
  if (item.fixed || item.static) return
@@ -1,6 +1,12 @@
1
1
  <template>
2
2
  <el-dropdown @command="setSize">
3
- <i v-title="$lc('行高')" class="v3-icon-line-height pointer"></i>
3
+ <i
4
+ v-title="$lc('行高')"
5
+ class="v3-icon-line-height pointer"
6
+ :class="hoverIconKey === 'height' ? 'color-primary' : ''"
7
+ @mouseenter="hoverIconKey = 'height'"
8
+ @mouseleave="hoverIconKey = null"
9
+ ></i>
4
10
  <el-dropdown-menu slot="dropdown">
5
11
  <el-dropdown-item command="small">{{ _lang === 'zh' ? '默认' : 'small' }}</el-dropdown-item>
6
12
  <el-dropdown-item command="mini">{{ _lang === 'zh' ? '紧凑' : 'mini' }}</el-dropdown-item>
@@ -36,7 +42,8 @@ export default {
36
42
  data() {
37
43
  let _this = this
38
44
  return {
39
- sizeC: localStorage.getItem('table-size') || _this.size
45
+ sizeC: localStorage.getItem('table-size') || _this.size,
46
+ hoverIconKey: null
40
47
  }
41
48
  },
42
49
  watch: {