@94ai/nf-table 8.0.5 → 8.0.12

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.
@@ -200,19 +200,17 @@ onBeforeMount(() => {
200
200
  i.attr = {}
201
201
  }
202
202
  })
203
-
204
203
  const list = props.tableColumns.filter(item => !item.destory)
205
-
206
204
  // 可选列表 → 字段区分
207
205
  setFields(list)
208
- // 已选列表
209
- updateColumn()
210
206
  if (currentTable.value.findIndex((item) => !!item.type) > -1) {
211
207
  unChangedColumn.value.push('selection')
212
208
  }
213
209
  if (currentTable.value.findIndex((item) => (item.prop || item.attr?.prop) === props.operationPropKey) > -1) {
214
210
  unChangedColumn.value.push(props.operationPropKey)
215
211
  }
212
+ // 已选列表
213
+ updateColumn()
216
214
  if (currentTable.value.every(i => !i.initHidden)) {
217
215
  showColumn.value = currentTable.value.map(i => i.prop)
218
216
  checkedCount.value = list.length
@@ -260,7 +258,7 @@ const checkedCount = ref(0) // 勾选的数量
260
258
  const updateColumn = () => {
261
259
  fixedColumn.value = []
262
260
  unFixedColumn.value = []
263
- currentTable.value.filter(item => !item.initHidden).map(item => {
261
+ currentTable.value.filter(item => !item.initHidden && !unChangedColumn.value.includes(item.prop)).map(item => {
264
262
  if (item.attr.fixed) {
265
263
  fixedColumn.value.push(item)
266
264
  } else {
@@ -272,23 +270,27 @@ const updateColumn = () => {
272
270
 
273
271
 
274
272
  const pullAwayColumn = (column) => {
275
- const unFixedIndex = unFixedColumn.value.findIndex(item => item.prop === column.prop)
276
- const fixedIndex = fixedColumn.value.findIndex(item => item.prop === column.prop)
277
- if (unFixedIndex > -1) {
278
- unFixedColumn.value.splice(unFixedIndex, 1)
279
- } else if (fixedIndex > -1) {
280
- fixedColumn.value.splice(fixedIndex, 1)
273
+ if (!unChangedColumn.value.includes(column.prop)) {
274
+ const unFixedIndex = unFixedColumn.value.findIndex(item => item.prop === column.prop)
275
+ const fixedIndex = fixedColumn.value.findIndex(item => item.prop === column.prop)
276
+ if (unFixedIndex > -1) {
277
+ unFixedColumn.value.splice(unFixedIndex, 1)
278
+ } else if (fixedIndex > -1) {
279
+ fixedColumn.value.splice(fixedIndex, 1)
280
+ }
281
281
  }
282
282
  }
283
283
 
284
284
  const insertColumn = (column, append = false) => {
285
- const unFixedIndex = unFixedColumn.value.findIndex(item => item.prop === column.prop)
286
- const fixedIndex = fixedColumn.value.findIndex(item => item.prop === column.prop)
287
- if (unFixedIndex === -1 && fixedIndex === -1) {
288
- if (append) {
289
- unFixedColumn.value.push(column)
290
- } else {
291
- unFixedColumn.value.unshift(column)
285
+ if (!unChangedColumn.value.includes(column.prop)) {
286
+ const unFixedIndex = unFixedColumn.value.findIndex(item => item.prop === column.prop)
287
+ const fixedIndex = fixedColumn.value.findIndex(item => item.prop === column.prop)
288
+ if (unFixedIndex === -1 && fixedIndex === -1) {
289
+ if (append) {
290
+ (column.attr.fixed ? fixedColumn.value : unFixedColumn.value).push(column)
291
+ } else {
292
+ (column.attr.fixed ? fixedColumn.value : unFixedColumn.value).unshift(column)
293
+ }
292
294
  }
293
295
  }
294
296
  }
@@ -335,12 +337,16 @@ const handleCheckAllChange = (v) => {
335
337
  if (v) { // 全选前为空,全选还原成最原始默认的顺序
336
338
  let flag = false
337
339
  if (columnName.value && fields.value.length) { // 搜索时,全选
338
- if (searchValue.length && currentTable.value.length && searchValue.length === currentTable.value.length) {
339
- if (!unFixedColumn.value.length && !fixedColumn.value.length) {
340
- flag = true
340
+ if (!unFixedColumn.value.filter(item => !unChangedColumn.value.includes(item.prop)).length &&
341
+ !fixedColumn.value.filter(item => !unChangedColumn.value.includes(item.prop)).length) {
342
+ if (searchValue.length &&
343
+ currentTable.value.length &&
344
+ searchValue.filter(item => !unChangedColumn.value.includes(item.prop)).length === currentTable.value.filter(item => !unChangedColumn.value.includes(item.prop)).length) {
345
+ flag = true
341
346
  }
342
347
  }
343
- } else if (!unFixedColumn.value.length && !fixedColumn.value.length) {
348
+ } else if (!unFixedColumn.value.filter(item => !unChangedColumn.value.includes(item.prop)).length &&
349
+ !fixedColumn.value.filter(item => !unChangedColumn.value.includes(item.prop)).length) { // 未搜索,全选
344
350
  flag = true
345
351
  }
346
352
  if (flag) {
@@ -351,15 +357,21 @@ const handleCheckAllChange = (v) => {
351
357
  const item = currentTable.value.find(item => item.prop === column.prop)
352
358
  if (item) {
353
359
  item.initHidden = false
354
- newColumns.push(item)
360
+ const cloneItem = deepClone(item)
361
+ if (!cloneItem.attr) {
362
+ cloneItem.attr = {}
363
+ }
364
+ newColumns.push(cloneItem)
355
365
  }
356
366
  })
357
367
  currentTable.value = newColumns
358
368
  currentTable.value.map(item => {
359
- if (item.attr.fixed) {
360
- fixedColumn.value.push(item)
361
- } else {
362
- unFixedColumn.value.push(item)
369
+ if (!unChangedColumn.value.includes(item.prop)) {
370
+ if (item.attr.fixed) {
371
+ fixedColumn.value.push(item)
372
+ } else {
373
+ unFixedColumn.value.push(item)
374
+ }
363
375
  }
364
376
  })
365
377
  updateCheckStatus()
@@ -370,12 +382,12 @@ const handleCheckAllChange = (v) => {
370
382
  // 搜索时,全选
371
383
  if (columnName.value && fields.value.length) {
372
384
  searchValue.map(item => {
373
- if (v) { // 追加
374
- insertColumn(item, true)
375
- } else {
376
- pullAwayColumn(item)
377
- }
378
385
  if (!unChangedColumn.value.includes(item.prop)) {
386
+ if (v) { // 追加
387
+ insertColumn(item, true)
388
+ } else {
389
+ pullAwayColumn(item)
390
+ }
379
391
  item.initHidden = !v
380
392
  // 清除列目时,清除固定属性
381
393
  v ? '' : item.attr.fixed = false
@@ -383,12 +395,12 @@ const handleCheckAllChange = (v) => {
383
395
  })
384
396
  } else {
385
397
  currentTable.value.map(item => {
386
- if (v) { // 追加
387
- insertColumn(item, true)
388
- } else {
389
- pullAwayColumn(item)
390
- }
391
398
  if (!unChangedColumn.value.includes(item.prop)) {
399
+ if (v) { // 追加
400
+ insertColumn(item, true)
401
+ } else {
402
+ pullAwayColumn(item)
403
+ }
392
404
  item.initHidden = !v
393
405
  // 清除列目时,清除固定属性
394
406
  v ? '' : item.attr.fixed = false
@@ -454,14 +466,23 @@ const syncTableColumnsToCookies = () => {
454
466
  })
455
467
  throw new Error(props.selectEmptyWarningTips)
456
468
  }
457
- const selectionPropItemIndex = newTableColumns.findIndex((item) => !!item.type)
458
- if (selectionPropItemIndex > -1) {
469
+ const selectionPropItemIndex = newTableColumns.findIndex(item => !!item.type)
470
+ if (selectionPropItemIndex > -1) { // 历史数据找到了
459
471
  newTableColumns.unshift(newTableColumns.splice(selectionPropItemIndex, 1)[0])
472
+ } else { // 没有
473
+ const typeItem = currentTable.value.find(item => !!item.type)
474
+ if (typeItem) {
475
+ newTableColumns.unshift(deepClone(typeItem))
476
+ }
460
477
  }
461
- const operationPropItemIndex = newTableColumns.findIndex((item) => (item.prop || item.attr?.prop) === props.operationPropKey)
462
-
478
+ const operationPropItemIndex = newTableColumns.findIndex(item => (item.prop || item.attr?.prop) === props.operationPropKey)
463
479
  if (operationPropItemIndex > -1) {
464
480
  newTableColumns.push(newTableColumns.splice(operationPropItemIndex, 1)[0])
481
+ } else {
482
+ const operationItem = currentTable.value.find(item => (item.prop || item.attr?.prop) === props.operationPropKey)
483
+ if (operationItem) {
484
+ newTableColumns.unshift(deepClone(operationItem))
485
+ }
465
486
  }
466
487
  const columnState = {}
467
488
  const obj: Record<string, any> = {}
@@ -62,7 +62,7 @@
62
62
  :key="column.key || column.prop || column.type"
63
63
  :type="column.type"
64
64
  :prop="column.prop"
65
- :label="column.label"
65
+ :label="resolveValue(column.label)"
66
66
  v-bind="column.attr"
67
67
  >
68
68
  </el-table-column>
@@ -71,7 +71,7 @@
71
71
  :key="column.key || column.prop || column.type"
72
72
  :type="column.type"
73
73
  :prop="column.prop"
74
- :label="column.label"
74
+ :label="resolveValue(column.label)"
75
75
  v-bind="column.attr"
76
76
  >
77
77
  <template slot-scope="scope" v-if="column.slot">
@@ -84,7 +84,7 @@
84
84
  :key="column.key || column.prop || column.type"
85
85
  :type="column.type"
86
86
  :prop="column.prop"
87
- :label="column.label"
87
+ :label="resolveValue(column.label)"
88
88
  v-bind="column.attr"
89
89
  >
90
90
  <!-- column套column -->
@@ -101,7 +101,7 @@
101
101
  name="operationIconColumnCheck"
102
102
  :column="column"
103
103
  >
104
- <span style="white-space:nowrap"> {{ column.label }} </span>
104
+ <span style="white-space:nowrap"> {{ resolveValue(column.label) }} </span>
105
105
  <el-tooltip
106
106
  popper-class="actionTooltipRef"
107
107
  placement="top"
@@ -116,7 +116,7 @@
116
116
  <template v-else-if="column.labelTooltip">
117
117
  <el-tooltip :placement="column.labelTooltipPlacement || 'right'" effect="dark">
118
118
  <div slot="content">{{ column.labelTooltip }}</div>
119
- <span class="bottom-line" style="white-space:nowrap"> {{ column.label }} </span>
119
+ <span class="bottom-line" style="white-space:nowrap"> {{ resolveValue(column.label) }} </span>
120
120
  </el-tooltip>
121
121
  </template>
122
122
  <!-- 头部插槽 -->
@@ -125,7 +125,7 @@
125
125
  </template>
126
126
  <!-- 默认 -->
127
127
  <span v-else>
128
- {{ column.label }}
128
+ {{ resolveValue(column.label) }}
129
129
  </span>
130
130
  </template>
131
131
  <!-- -------------- 内容区域 -------------- -->
@@ -152,20 +152,20 @@
152
152
  <template v-for="(item, index) in getOperationListLocal(column, scope)">
153
153
  <nf-button
154
154
  v-if="!resolveValue(item.destroy, scope.row, scope)"
155
- :size="item.size || 'mini'"
156
- :type="resolveValue(item.type || 'primary', scope.row, scope)"
157
- :text="item.text !== false"
155
+ :size="resolveValue(item.size || 'mini', scope.row, scope)"
156
+ :type="resolveValue(item.type || 'primary', scope.row, scope, scope.row, scope)"
157
+ :text="resolveValue(item.text === undefined ? true : item.text, scope.row, scope)"
158
158
  :disabled="resolveValue(item.disabled, scope.row, scope)"
159
159
  :loading="resolveValue(item.loading, scope.row, scope)"
160
- :class="item.class"
161
- :plain="item.plain"
162
- :icon="item.icon"
163
- :round="item.round"
164
- :circle="item.circle"
165
- :style="item.style"
160
+ :class="resolveValue(item.class, scope.row, scope)"
161
+ :plain="resolveValue(item.plain, scope.row, scope)"
162
+ :icon="resolveValue(item.icon, scope.row, scope)"
163
+ :round="resolveValue(item.round, scope.row, scope)"
164
+ :circle="resolveValue(item.circle, scope.row, scope)"
165
+ :style="resolveValue(item.style, scope.row, scope)"
166
166
  v-on="eventsOperationListBtns(item, scope)"
167
167
  :key="item.key || index"
168
- >{{ item.name }}
168
+ >{{ resolveValue(item.name, scope.row, scope) }}
169
169
  </nf-button>
170
170
  </template>
171
171
  </nf-action>
@@ -200,19 +200,19 @@
200
200
  <nf-button
201
201
  :key="item.key || index"
202
202
  v-if="item.element === 'el-button'"
203
- :size="item.size || 'mini'"
204
- :type="item.type || 'text'"
205
- :text="item.text !== false"
203
+ :size="resolveValue(item.size || 'mini')"
204
+ :type="resolveValue(item.type || 'text')"
205
+ :text="resolveValue(item.text === undefined ? true : item.text)"
206
206
  :disabled="resolveValue(item.disabled)"
207
207
  :loading="resolveValue(item.loading)"
208
- :class="item.class"
209
- :plain="item.plain"
210
- :icon="item.icon"
211
- :round="item.round"
212
- :circle="item.circle"
208
+ :class="resolveValue(item.class)"
209
+ :plain="resolveValue(item.plain)"
210
+ :icon="resolveValue(item.icon)"
211
+ :round="resolveValue(item.round)"
212
+ :circle="resolveValue(item.circle)"
213
213
  :style="getActionBarItemStyle(item, {marginLeft: '0px'})"
214
214
  v-on="item.events"
215
- >{{ item.value }}
215
+ >{{ resolveValue(item.value) }}
216
216
  </nf-button>
217
217
  <el-checkbox
218
218
  :key="item.key || index"
@@ -230,7 +230,7 @@
230
230
  :style="getActionBarItemStyle(item)"
231
231
  v-if="item.element === 'el-checkbox'"
232
232
  v-on="item.events"
233
- >{{ item.text }}
233
+ >{{ resolveValue(item.text) }}
234
234
  </el-checkbox>
235
235
  <el-checkbox-group
236
236
  :key="item.key || index"
@@ -269,7 +269,7 @@
269
269
  :style="{...(itemChildren.style || {}), marginRight: j === 0 ? 0 : '16px'}"
270
270
  v-if="itemChildren.element === 'el-checkbox'"
271
271
  v-on="itemChildren.events"
272
- >{{ item.text }}
272
+ >{{ resolveValue(item.text) }}
273
273
  </el-checkbox>
274
274
  <el-checkbox-button
275
275
  :key="itemChildren.key || j"
@@ -287,7 +287,7 @@
287
287
  :style="{...(itemChildren.style || {}), marginRight: j === 0 ? 0 : '16px'}"
288
288
  v-if="itemChildren.element === 'el-checkbox-button'"
289
289
  v-on="itemChildren.events"
290
- >{{ item.text }}
290
+ >{{ resolveValue(item.text) }}
291
291
  </el-checkbox-button>
292
292
  </template>
293
293
  </template>
@@ -308,7 +308,7 @@
308
308
  :style="getActionBarItemStyle(item)"
309
309
  v-if="item.element === 'el-checkbox-button'"
310
310
  v-on="item.events"
311
- >{{ item.text }}
311
+ >{{ resolveValue(item.text) }}
312
312
  </el-checkbox-button>
313
313
  <el-radio
314
314
  :key="item.key || index"
@@ -322,7 +322,7 @@
322
322
  :style="getActionBarItemStyle(item)"
323
323
  v-if="item.element === 'el-radio'"
324
324
  v-on="item.events"
325
- >{{ item.text }}
325
+ >{{ resolveValue(item.text) }}
326
326
  </el-radio>
327
327
  <el-radio-group
328
328
  :key="item.key || index"
@@ -352,7 +352,7 @@
352
352
  :style="{...(itemChildren.style || {}), marginRight: j === 0 ? 0 : '16px'}"
353
353
  v-if="itemChildren.element === 'el-radio'"
354
354
  v-on="itemChildren.events"
355
- >{{ item.text }}
355
+ >{{ resolveValue(item.text) }}
356
356
  </el-radio>
357
357
  <el-radio-button
358
358
  :key="itemChildren.key || j"
@@ -366,7 +366,7 @@
366
366
  :style="{...(itemChildren.style || {}), marginRight: j === 0 ? 0 : '16px'}"
367
367
  v-if="itemChildren.element === 'el-radio-button'"
368
368
  v-on="itemChildren.events"
369
- >{{ item.text }}
369
+ >{{ resolveValue(item.text) }}
370
370
  </el-radio-button>
371
371
  </template>
372
372
  </template>
@@ -383,7 +383,7 @@
383
383
  :style="getActionBarItemStyle(item)"
384
384
  v-if="item.element === 'el-radio-button'"
385
385
  v-on="item.events"
386
- >{{ item.text }}
386
+ >{{ resolveValue(item.text) }}
387
387
  </el-radio-button>
388
388
  <el-input
389
389
  :key="item.key || index"
@@ -471,7 +471,7 @@
471
471
  :style="getActionBarItemStyle(item)"
472
472
  v-if="item.element === 'el-switch'"
473
473
  v-on="item.events"
474
- >{{ item.text }}
474
+ >{{ resolveValue(item.text) }}
475
475
  </el-switch>
476
476
  <el-input-number
477
477
  :key="item.key || index"
@@ -501,7 +501,7 @@
501
501
  v-on="item.events"
502
502
  v-bind="item.attr"
503
503
  >
504
- {{ item.value }}
504
+ {{ resolveValue(item.value) }}
505
505
  </span>
506
506
  </template>
507
507
  </template>
@@ -1051,19 +1051,19 @@ const initCachedData = async () => {
1051
1051
  }
1052
1052
 
1053
1053
  const getMinWidth = (column) => {
1054
- if (column.label?.indexOf('$$') === 0) {
1055
- const value = Number(column.label.replace('$$', ''))
1054
+ const columnLabel = resolveValue(column.label)
1055
+ if (columnLabel?.indexOf('$$') === 0) {
1056
+ const value = Number(columnLabel.replace('$$', ''))
1056
1057
  if (!Number.isNaN(value) && value) {
1057
1058
  return value
1058
1059
  }
1059
1060
  }
1060
1061
  const fs = 14
1061
- const label = column.label
1062
- const char = label.match(/[\u2E80-\u9FFF]/g)
1062
+ const char = columnLabel.match(/[\u2E80-\u9FFF]/g)
1063
1063
  const charLen = char ? char.length : 0
1064
- const num = label.match(/\d|\./g)
1064
+ const num = columnLabel.match(/\d|\./g)
1065
1065
  const numLen = num ? num.length : 0
1066
- const otherLen = label.length - charLen - numLen
1066
+ const otherLen = columnLabel.length - charLen - numLen
1067
1067
  return fs * (charLen * 1 + numLen * 0.7 + otherLen * 0.58) + 20 + (column.sortable ? 24 : 0)
1068
1068
  }
1069
1069
 
@@ -1092,7 +1092,7 @@ const syncCookiesToTableColumn = async (readCached = true) => {
1092
1092
  delete item.attr.label
1093
1093
  item._index = index
1094
1094
  set(item, 'initHidden', item.initHidden)
1095
- set(item, 'destory', !!resolveValue(item.destory, item))
1095
+ set(item, 'destory', item.destory)
1096
1096
  item.__index = index
1097
1097
  // 根据id映射文案
1098
1098
  set(item, 'optionsTag', {})
package/package/types.ts CHANGED
@@ -244,9 +244,9 @@ export interface NfTableColumnAttributes {
244
244
  _index?: number
245
245
  __index?: number
246
246
  initHidden?: boolean
247
- destory?: boolean | ((any) => boolean)
247
+ destory?: boolean | ((any: any) => boolean)
248
248
  type?: 'selection' | 'index' | 'expand'
249
- label?: string
249
+ label?: string | ((any: any) => string)
250
250
  addLabel?: string
251
251
  prop?: string
252
252
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@94ai/nf-table",
3
- "version": "8.0.5",
3
+ "version": "8.0.12",
4
4
  "description": "> TODO: description",
5
5
  "keywords": [],
6
6
  "author": "zoujiahe <zoujiahe@94ai.com>",
@@ -14,13 +14,13 @@
14
14
  "url": "http://94ai.gitlab.com/zoujiahe/common-ui.git"
15
15
  },
16
16
  "dependencies": {
17
- "@94ai/common-utils": "^8.0.5",
18
- "@94ai/nf-button": "^8.0.5",
19
- "@94ai/nf-drawer": "^8.0.5",
20
- "@94ai/nf-message": "^8.0.5",
21
- "@94ai/nf-search-form": "^8.0.5",
22
- "@94ai/nf-tag": "^8.0.5",
23
- "@94ai/nf-theme-chalk": "^8.0.5",
17
+ "@94ai/common-utils": "^8.0.12",
18
+ "@94ai/nf-button": "^8.0.12",
19
+ "@94ai/nf-drawer": "^8.0.12",
20
+ "@94ai/nf-message": "^8.0.12",
21
+ "@94ai/nf-search-form": "^8.0.12",
22
+ "@94ai/nf-tag": "^8.0.12",
23
+ "@94ai/nf-theme-chalk": "^8.0.12",
24
24
  "idb-keyval": "^6.2.1",
25
25
  "vue-demi": "^0.14.5",
26
26
  "vue-router": "3.6.4",
@@ -39,5 +39,5 @@
39
39
  "types": "lib/index.d.ts",
40
40
  "main": "lib/nf-table.cjs.js",
41
41
  "module": "lib/nf-table.esm-bundler.js",
42
- "gitHead": "fab708c9a9c54ca34e3fea3c92a4a378184da4b3"
42
+ "gitHead": "dd2adc2b66c074a49c7a33477c806464d85ee254"
43
43
  }