@94ai/nf-table 8.3.23 → 10.0.0
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/lib/index.d.ts +67 -154
- package/lib/nf-column-check-dialog.vue.d.ts +2 -2
- package/lib/nf-table.cjs.js +318 -182
- package/lib/nf-table.esm-bundler.js +320 -184
- package/lib/nf-table.vue.d.ts +12 -42
- package/lib/types.d.ts +3 -0
- package/package/nf-column-check-drawer.vue +9 -13
- package/package/nf-table.vue +303 -123
- package/package/types.ts +5 -0
- package/package.json +14 -14
package/package/nf-table.vue
CHANGED
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
:loading="columnDisplayBtnLoading"
|
|
42
42
|
:disabled="columnDisplayBtnDisabled"
|
|
43
43
|
>
|
|
44
|
-
{{ columnDisplayBtnText }}
|
|
44
|
+
{{ localeText.columnDisplayBtnText }}
|
|
45
45
|
</nf-button>
|
|
46
46
|
</slot>
|
|
47
47
|
<!-- 非虚拟 -->
|
|
@@ -108,7 +108,7 @@
|
|
|
108
108
|
popper-class="actionTooltipRef"
|
|
109
109
|
placement="top"
|
|
110
110
|
effect="dark"
|
|
111
|
-
:content="columnDisplayBtnText">
|
|
111
|
+
:content="localeText.columnDisplayBtnText">
|
|
112
112
|
<i class="iconfont icon-liebiao_xianshiliemu operation-icon-column-check"
|
|
113
113
|
@click="nfColumCheckDialogVisible = true"
|
|
114
114
|
/>
|
|
@@ -192,7 +192,7 @@
|
|
|
192
192
|
</template>
|
|
193
193
|
<slot name="append" slot="append"></slot>
|
|
194
194
|
<slot name="empty" slot="empty">
|
|
195
|
-
<nf-empty slot="empty" :image-size="emptyImageSize" :description="emptyText"></nf-empty>
|
|
195
|
+
<nf-empty slot="empty" :image-size="emptyImageSize" :description="localeText.emptyText"></nf-empty>
|
|
196
196
|
</slot>
|
|
197
197
|
</el-table>
|
|
198
198
|
<!-- 虚拟 -->
|
|
@@ -268,7 +268,7 @@
|
|
|
268
268
|
popper-class="actionTooltipRef"
|
|
269
269
|
placement="top"
|
|
270
270
|
effect="dark"
|
|
271
|
-
:content="columnDisplayBtnText">
|
|
271
|
+
:content="localeText.columnDisplayBtnText">
|
|
272
272
|
<i class="iconfont icon-liebiao_xianshiliemu operation-icon-column-check"
|
|
273
273
|
@click="nfColumCheckDialogVisible = true"
|
|
274
274
|
/>
|
|
@@ -352,7 +352,7 @@
|
|
|
352
352
|
</template>
|
|
353
353
|
<slot name="append" slot="append"></slot>
|
|
354
354
|
<slot name="empty" slot="empty">
|
|
355
|
-
<nf-empty slot="empty" :image-size="emptyImageSize" :description="emptyText"></nf-empty>
|
|
355
|
+
<nf-empty slot="empty" :image-size="emptyImageSize" :description="localeText.emptyText"></nf-empty>
|
|
356
356
|
</slot>
|
|
357
357
|
</el-table>
|
|
358
358
|
</virtual-scroll>
|
|
@@ -685,10 +685,10 @@
|
|
|
685
685
|
</div>
|
|
686
686
|
</div>
|
|
687
687
|
<column-check-dialog
|
|
688
|
-
:title="columnCheckTitle"
|
|
689
|
-
:confirm-text="columnCheckConfirmButtonText"
|
|
690
|
-
:cancel-text="columnCheckCancelButtonText"
|
|
691
|
-
:basic-field-desc="columnCheckBasicFieldDesc"
|
|
688
|
+
:title="localeText.columnCheckTitle"
|
|
689
|
+
:confirm-text="localeText.columnCheckConfirmButtonText"
|
|
690
|
+
:cancel-text="localeText.columnCheckCancelButtonText"
|
|
691
|
+
:basic-field-desc="localeText.columnCheckBasicFieldDesc"
|
|
692
692
|
|
|
693
693
|
:show.sync="nfColumCheckDialogVisible"
|
|
694
694
|
:table-columns="processedColumns"
|
|
@@ -718,9 +718,9 @@
|
|
|
718
718
|
<slot slot="tableColumnEditDialogFooter" name="footer"></slot>
|
|
719
719
|
</column-check-dialog>
|
|
720
720
|
<nf-drawer
|
|
721
|
-
:title="columnCheckTitle"
|
|
722
|
-
:cancel-button-text="columnCheckCancelButtonText"
|
|
723
|
-
:confirm-button-text="columnCheckConfirmButtonText"
|
|
721
|
+
:title="localeText.columnCheckTitle"
|
|
722
|
+
:cancel-button-text="localeText.columnCheckCancelButtonText"
|
|
723
|
+
:confirm-button-text="localeText.columnCheckConfirmButtonText"
|
|
724
724
|
v-bind="drawerProps"
|
|
725
725
|
ref="columnCheckNfDrawer"
|
|
726
726
|
size="680px"
|
|
@@ -737,14 +737,14 @@
|
|
|
737
737
|
<slot slot="tableColumnEditDialogTitle" name="title" />
|
|
738
738
|
<slot slot="tableColumnEditDialogFooter" name="footer" />
|
|
739
739
|
<column-check-drawer
|
|
740
|
-
:search-placeholder="columnCheckSearchPlaceholder"
|
|
741
|
-
:fixed-left-desc="columnCheckFixedLeftDesc"
|
|
742
|
-
:clear-desc="columnCheckClearDesc"
|
|
743
|
-
:no-fixed-desc="columnCheckNoFixedDesc"
|
|
744
|
-
:basic-field-desc="columnCheckBasicFieldDesc"
|
|
745
|
-
:select-empty-warning-tips="selectEmptyWarningTips"
|
|
746
|
-
:get-checked-length-desc="columnCheckGetCheckedLengthDesc"
|
|
747
|
-
:get-all-check-desc="columnCheckGetAllCheckDesc"
|
|
740
|
+
:search-placeholder="localeText.columnCheckSearchPlaceholder"
|
|
741
|
+
:fixed-left-desc="localeText.columnCheckFixedLeftDesc"
|
|
742
|
+
:clear-desc="localeText.columnCheckClearDesc"
|
|
743
|
+
:no-fixed-desc="localeText.columnCheckNoFixedDesc"
|
|
744
|
+
:basic-field-desc="localeText.columnCheckBasicFieldDesc"
|
|
745
|
+
:select-empty-warning-tips="localeText.selectEmptyWarningTips"
|
|
746
|
+
:get-checked-length-desc="localeText.columnCheckGetCheckedLengthDesc"
|
|
747
|
+
:get-all-check-desc="localeText.columnCheckGetAllCheckDesc"
|
|
748
748
|
ref="columnCheckDrawer"
|
|
749
749
|
|
|
750
750
|
:column-edit="columnEdit"
|
|
@@ -775,6 +775,7 @@
|
|
|
775
775
|
nextTick,
|
|
776
776
|
onMounted,
|
|
777
777
|
onBeforeMount,
|
|
778
|
+
onBeforeUnmount,
|
|
778
779
|
ref,
|
|
779
780
|
watch,
|
|
780
781
|
set,
|
|
@@ -792,7 +793,7 @@
|
|
|
792
793
|
NfTableActionBtnAttributes
|
|
793
794
|
} from './types'
|
|
794
795
|
import { ITabItem } from '@94ai/nf-drawer/lib/types'
|
|
795
|
-
import { CachedManager, resolveValue } from '@94ai/common-utils'
|
|
796
|
+
import { CachedManager, resolveValue, useLocale } from '@94ai/common-utils'
|
|
796
797
|
import { useRoute } from 'vue-router/composables'
|
|
797
798
|
import VirtualScroll, { VirtualColumn } from 'el-table-virtual-scroll'
|
|
798
799
|
|
|
@@ -983,18 +984,6 @@
|
|
|
983
984
|
columnCheckBeforeClose: undefined,
|
|
984
985
|
columnCheckCenter: false,
|
|
985
986
|
columnCheckDestroyOnClose: false,
|
|
986
|
-
selectEmptyWarningTips: '请选择至少一个选项',
|
|
987
|
-
columnDisplayBtnText: '设置列表字段',
|
|
988
|
-
columnCheckTitle: '设置显示字段',
|
|
989
|
-
columnCheckCancelButtonText: '取消',
|
|
990
|
-
columnCheckConfirmButtonText: '确定',
|
|
991
|
-
columnCheckSearchPlaceholder: '搜索',
|
|
992
|
-
columnCheckFixedLeftDesc: '固定在左侧',
|
|
993
|
-
columnCheckClearDesc: '清除',
|
|
994
|
-
columnCheckNoFixedDesc: '不固定',
|
|
995
|
-
columnCheckBasicFieldDesc: '基础字段',
|
|
996
|
-
columnCheckGetCheckedLengthDesc: (length) => (length) => '已选(' + length + ')',
|
|
997
|
-
columnCheckGetAllCheckDesc: (length) => (length) => '全选(' + length + ')',
|
|
998
987
|
drawerProps: () => ({}),
|
|
999
988
|
virtualized: false,
|
|
1000
989
|
virtualTableData: () => [],
|
|
@@ -1035,7 +1024,7 @@
|
|
|
1035
1024
|
return {
|
|
1036
1025
|
...(item.events || {}),
|
|
1037
1026
|
click: (...args) => {
|
|
1038
|
-
item.events?.click(args);
|
|
1027
|
+
item.events?.click?.(args);
|
|
1039
1028
|
item.onClick?.(scope.row, scope)
|
|
1040
1029
|
}
|
|
1041
1030
|
}
|
|
@@ -1059,6 +1048,24 @@
|
|
|
1059
1048
|
const cPageChangeSearchApi = ref(props.pageChangeSearchApi ?? props.setEasyConf)
|
|
1060
1049
|
const cInitSearchApi = ref(props.initSearchApi ?? props.setEasyConf)
|
|
1061
1050
|
|
|
1051
|
+
// 文案:显式传入的 prop 优先,否则取内置语言包(跟随 vue-i18n 语言或 locale.use 指定的语言)
|
|
1052
|
+
const { t } = useLocale()
|
|
1053
|
+
const localeText = computed(() => ({
|
|
1054
|
+
emptyText: props.emptyText || t('nf.table.emptyText'),
|
|
1055
|
+
columnDisplayBtnText: props.columnDisplayBtnText || t('nf.table.columnDisplayBtnText'),
|
|
1056
|
+
columnCheckTitle: props.columnCheckTitle || t('nf.table.columnCheckTitle'),
|
|
1057
|
+
columnCheckCancelButtonText: props.columnCheckCancelButtonText || t('nf.table.cancel'),
|
|
1058
|
+
columnCheckConfirmButtonText: props.columnCheckConfirmButtonText || t('nf.table.confirm'),
|
|
1059
|
+
columnCheckSearchPlaceholder: props.columnCheckSearchPlaceholder || t('nf.table.searchPlaceholder'),
|
|
1060
|
+
columnCheckFixedLeftDesc: props.columnCheckFixedLeftDesc || t('nf.table.fixedLeft'),
|
|
1061
|
+
columnCheckClearDesc: props.columnCheckClearDesc || t('nf.table.clear'),
|
|
1062
|
+
columnCheckNoFixedDesc: props.columnCheckNoFixedDesc || t('nf.table.noFixed'),
|
|
1063
|
+
columnCheckBasicFieldDesc: props.columnCheckBasicFieldDesc || t('nf.table.basicField'),
|
|
1064
|
+
selectEmptyWarningTips: props.selectEmptyWarningTips || t('nf.table.selectEmptyWarning'),
|
|
1065
|
+
columnCheckGetCheckedLengthDesc: props.columnCheckGetCheckedLengthDesc || ((length) => t('nf.table.checkedLength', { length })),
|
|
1066
|
+
columnCheckGetAllCheckDesc: props.columnCheckGetAllCheckDesc || ((length) => t('nf.table.allCheck', { length }))
|
|
1067
|
+
}))
|
|
1068
|
+
|
|
1062
1069
|
const cStorageKey = computed(() => {
|
|
1063
1070
|
const key = props.storageKey || `nf-table-columns-cached-key-${routeName.value}`
|
|
1064
1071
|
const userId = (window as any).userId
|
|
@@ -1068,53 +1075,49 @@
|
|
|
1068
1075
|
return key
|
|
1069
1076
|
})
|
|
1070
1077
|
|
|
1071
|
-
const cStorageKeyViewIdentity = computed(() => {
|
|
1072
|
-
return 'nf-table-view-identity'
|
|
1073
|
-
})
|
|
1074
|
-
|
|
1075
1078
|
const checkViewIdentityChange = async () => {
|
|
1076
|
-
const userId = (window as any).userId
|
|
1077
|
-
const viewField = (window as any).viewField
|
|
1078
|
-
if (props.viewIdentity && userId && viewField) {
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
}
|
|
1079
|
+
// const userId = (window as any).userId
|
|
1080
|
+
// const viewField = (window as any).viewField
|
|
1081
|
+
// if (props.viewIdentity && userId && viewField) {
|
|
1082
|
+
// let viewIdentity = CachedManager.syncCachedGet(cStorageKeyViewIdentity.value)
|
|
1083
|
+
// if (!viewIdentity) {
|
|
1084
|
+
// viewIdentity = await CachedManager.asyncCachedGet(cStorageKeyViewIdentity.value)
|
|
1085
|
+
// }
|
|
1086
|
+
// if (!viewIdentity) {
|
|
1087
|
+
// await CachedManager.asyncCachedSet(cStorageKeyViewIdentity.value, viewField)
|
|
1088
|
+
// } else {
|
|
1089
|
+
// const newViewIdentity = viewField.find(item => item.viewIdentity === props.viewIdentity)
|
|
1090
|
+
// const oldViewIdentity = viewIdentity.find(item => item.viewIdentity === props.viewIdentity)
|
|
1091
|
+
// if ((newViewIdentity && !oldViewIdentity) || (!newViewIdentity && oldViewIdentity)) {
|
|
1092
|
+
// await clearColumnEditCached()
|
|
1093
|
+
// await clearDragCached()
|
|
1094
|
+
// } else if (newViewIdentity && oldViewIdentity) {
|
|
1095
|
+
// let change = false
|
|
1096
|
+
// newViewIdentity.fieldList.every(item => {
|
|
1097
|
+
// if (!oldViewIdentity.fieldList.includes(item)) {
|
|
1098
|
+
// change = true
|
|
1099
|
+
// return
|
|
1100
|
+
// }
|
|
1101
|
+
// return true
|
|
1102
|
+
// })
|
|
1103
|
+
// if (!change) {
|
|
1104
|
+
// oldViewIdentity.fieldList.every(item => {
|
|
1105
|
+
// if (!newViewIdentity.fieldList.includes(item)) {
|
|
1106
|
+
// change = true
|
|
1107
|
+
// return
|
|
1108
|
+
// }
|
|
1109
|
+
// return true
|
|
1110
|
+
// })
|
|
1111
|
+
// }
|
|
1112
|
+
// if (change) {
|
|
1113
|
+
// await clearColumnEditCached()
|
|
1114
|
+
// await clearDragCached()
|
|
1115
|
+
// oldViewIdentity.fieldList = newViewIdentity.fieldList
|
|
1116
|
+
// await CachedManager.asyncCachedSet(cStorageKeyViewIdentity.value, viewIdentity)
|
|
1117
|
+
// }
|
|
1118
|
+
// }
|
|
1119
|
+
// }
|
|
1120
|
+
// }
|
|
1118
1121
|
}
|
|
1119
1122
|
|
|
1120
1123
|
const cPageAttrs = reactive({
|
|
@@ -1315,13 +1318,57 @@
|
|
|
1315
1318
|
return value
|
|
1316
1319
|
}
|
|
1317
1320
|
}
|
|
1318
|
-
|
|
1319
|
-
const
|
|
1320
|
-
const
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1321
|
+
// 按实际字体测量表头、标签、操作按钮
|
|
1322
|
+
const label = columnLabel || ''
|
|
1323
|
+
const sortable = column.sortable || column.attr?.sortable
|
|
1324
|
+
// 表头为 `<span> {{ label }} </span>`:行首空格会折叠,尾随空格后面还有同行的图标时不折叠,要计入
|
|
1325
|
+
// 操作列内嵌「显示列」图标:nowrap,两侧空格都占宽,图标 14px + 内边距 4px×2 + 左间距 10px
|
|
1326
|
+
// 排序图标 24px
|
|
1327
|
+
const hasColumnCheckIcon = props.columnEdit && column.prop === props.operationPropKey && props.columnPosition === 'embed'
|
|
1328
|
+
const labelWidth = (hasColumnCheckIcon
|
|
1329
|
+
? measureText(` ${label} `, '600 14px') + 33
|
|
1330
|
+
: measureText(sortable ? `${label} ` : label, '600 14px')) + CELL_PADDING + (sortable ? 24 : 0)
|
|
1331
|
+
// nf-tag:12px,左右内边距各 8px、边框各 1px、圆点 4px + 间距 4px;模板换行使文字前多一个空格
|
|
1332
|
+
const tags = [...getTagTexts(column), ...(column.fit?.tags || [])]
|
|
1333
|
+
const tagWidth = Math.max(0, ...tags.map(tag => measureText(` ${tag}`, '12px') + 26 + CELL_PADDING))
|
|
1334
|
+
// 操作按钮不按配置估算(按行隐藏的按钮无法预知,会估宽),由 fitOperationColumn 按渲染结果测得 __contentWidth;
|
|
1335
|
+
// 拖拽下限同样要包含它
|
|
1336
|
+
return Math.ceil(Math.max(labelWidth, tagWidth, column.__contentWidth || 0))
|
|
1337
|
+
}
|
|
1338
|
+
|
|
1339
|
+
const CELL_PADDING = 20
|
|
1340
|
+
let measureContext: CanvasRenderingContext2D | null = null
|
|
1341
|
+
let fontFamily = ''
|
|
1342
|
+
const measureText = (text, font: string) => {
|
|
1343
|
+
measureContext = measureContext || document.createElement('canvas').getContext('2d')
|
|
1344
|
+
fontFamily = fontFamily || getComputedStyle(document.body).fontFamily
|
|
1345
|
+
measureContext!.font = `${font} ${fontFamily}`
|
|
1346
|
+
return measureContext!.measureText(String(text)).width
|
|
1347
|
+
}
|
|
1348
|
+
const getTagTexts = (column) => {
|
|
1349
|
+
const tagMap = column.optionsTag || {}
|
|
1350
|
+
return Object.keys(tagMap).filter(key => tagMap[key]).map(key => column.optionsEnum?.[key])
|
|
1351
|
+
}
|
|
1352
|
+
const applyColumnWidth = (item, dragProp) => {
|
|
1353
|
+
if (!item.label || item.type) return
|
|
1354
|
+
const attr = item.attr
|
|
1355
|
+
const raw = item.__rawWidth || (item.__rawWidth = {})
|
|
1356
|
+
// 与上次写入值不同,说明是页面设定或运行时修改(如拖拽回写、按条件切换宽度),作为新的原值
|
|
1357
|
+
const applied = item.__appliedWidth || {}
|
|
1358
|
+
if (attr.width !== applied.width) raw.width = attr.width
|
|
1359
|
+
if (attr['min-width'] !== applied.minWidth) raw.minWidth = attr['min-width']
|
|
1360
|
+
const need = getMinWidth(item)
|
|
1361
|
+
set(attr, 'min-width', Math.max(parseFloat(raw.minWidth) || 0, need) + 'px')
|
|
1362
|
+
if (raw.width) {
|
|
1363
|
+
set(attr, 'width', Math.max(parseFloat(raw.width) || 0, need) + 'px')
|
|
1364
|
+
}
|
|
1365
|
+
if (props.dragCached) {
|
|
1366
|
+
const columnWidth = CachedManager.syncCachedGet(`${cStorageKey.value}$drag-column-width`) || {}
|
|
1367
|
+
if (columnWidth[dragProp]) { // 读取缓存
|
|
1368
|
+
set(attr, 'width', columnWidth[dragProp])
|
|
1369
|
+
}
|
|
1370
|
+
}
|
|
1371
|
+
item.__appliedWidth = { width: attr.width, minWidth: attr['min-width'] }
|
|
1325
1372
|
}
|
|
1326
1373
|
|
|
1327
1374
|
const tableColumns = ref<NfTableColumnAttributes[]>([])
|
|
@@ -1330,17 +1377,7 @@
|
|
|
1330
1377
|
props.columns._skip = true
|
|
1331
1378
|
const columns = processedColumns.value!.map((item, index) => {
|
|
1332
1379
|
const attr = (item.attr || {}) as ElTableColumnAttributes
|
|
1333
|
-
|
|
1334
|
-
if (!attr['min-width'] && item.label) {
|
|
1335
|
-
attr['min-width'] = String(getMinWidth(item)) + 'px'
|
|
1336
|
-
}
|
|
1337
|
-
if (props.dragCached) {
|
|
1338
|
-
const prop = item.prop || item.attr?.prop
|
|
1339
|
-
let columnWidth = CachedManager.syncCachedGet(`${cStorageKey.value}$drag-column-width`) || {}
|
|
1340
|
-
if (columnWidth[prop]) { // 读取缓存
|
|
1341
|
-
attr.width = columnWidth[prop]
|
|
1342
|
-
}
|
|
1343
|
-
}
|
|
1380
|
+
const dragProp = item.prop || item.attr?.prop
|
|
1344
1381
|
item.attr = {
|
|
1345
1382
|
...item.attr,
|
|
1346
1383
|
...attr
|
|
@@ -1360,6 +1397,12 @@
|
|
|
1360
1397
|
item.optionsEnum[o.value] = o.label
|
|
1361
1398
|
item.optionsTag[o.value] = o.tagType
|
|
1362
1399
|
})
|
|
1400
|
+
// 异步回调时 _skip 已复位,补算宽度若改变了值会触发 columns 深度监听,导致整表重新同步、重建
|
|
1401
|
+
props.columns._skip = true
|
|
1402
|
+
applyColumnWidth(item, dragProp)
|
|
1403
|
+
nextTick(() => {
|
|
1404
|
+
props.columns._skip = false
|
|
1405
|
+
})
|
|
1363
1406
|
})
|
|
1364
1407
|
} else if (item.options) {
|
|
1365
1408
|
set(item, 'optionsEnum', {})
|
|
@@ -1368,6 +1411,7 @@
|
|
|
1368
1411
|
item.optionsTag[o.value] = o.tagType
|
|
1369
1412
|
})
|
|
1370
1413
|
}
|
|
1414
|
+
applyColumnWidth(item, dragProp)
|
|
1371
1415
|
return item
|
|
1372
1416
|
})
|
|
1373
1417
|
if (readCached && props.columnEdit) {
|
|
@@ -1383,24 +1427,40 @@
|
|
|
1383
1427
|
if (typeof columnState === 'string') {
|
|
1384
1428
|
columnState = JSON.parse(columnState)
|
|
1385
1429
|
}
|
|
1430
|
+
let maxIndex = 0
|
|
1386
1431
|
for (const key in columnState as NfTableColumnAttributes) {
|
|
1387
1432
|
const state = columnState![key]
|
|
1388
1433
|
columns.every(i => {
|
|
1389
1434
|
if (i.prop === key) {
|
|
1390
1435
|
i.initHidden = state.initHidden
|
|
1391
|
-
i.attr
|
|
1436
|
+
i.attr['fixed'] = state.fixed
|
|
1392
1437
|
i._index = state.index
|
|
1438
|
+
if (maxIndex < state.index) {
|
|
1439
|
+
maxIndex = state.index
|
|
1440
|
+
}
|
|
1393
1441
|
return false
|
|
1394
1442
|
}
|
|
1395
1443
|
return true
|
|
1396
1444
|
})
|
|
1397
1445
|
}
|
|
1446
|
+
const columnStateKeys = Object.keys(columnState)
|
|
1447
|
+
columns.forEach(item => {
|
|
1448
|
+
if (!columnStateKeys.includes(item.prop)) {
|
|
1449
|
+
maxIndex++
|
|
1450
|
+
item._index = maxIndex
|
|
1451
|
+
}
|
|
1452
|
+
})
|
|
1453
|
+
const optItem = columns.find(itemOpt => itemOpt.prop === props.operationPropKey)
|
|
1454
|
+
if (optItem) {
|
|
1455
|
+
maxIndex++
|
|
1456
|
+
optItem._index = maxIndex++
|
|
1457
|
+
}
|
|
1398
1458
|
}
|
|
1399
1459
|
} catch (e) {
|
|
1400
1460
|
console.log(e)
|
|
1401
1461
|
}
|
|
1402
1462
|
}
|
|
1403
|
-
tableColumns.value = columns.sort((a, b) => a._index! - b._index!
|
|
1463
|
+
tableColumns.value = columns.sort((a, b) => a._index! - b._index!)
|
|
1404
1464
|
nextTick(() => {
|
|
1405
1465
|
props.columns._skip = false
|
|
1406
1466
|
})
|
|
@@ -1491,7 +1551,7 @@
|
|
|
1491
1551
|
}
|
|
1492
1552
|
|
|
1493
1553
|
const showPage = computed(() => {
|
|
1494
|
-
return
|
|
1554
|
+
return props.data.length > props.pageAttrs['page-size']!
|
|
1495
1555
|
})
|
|
1496
1556
|
|
|
1497
1557
|
const renderPage = computed(() => {
|
|
@@ -1570,9 +1630,121 @@
|
|
|
1570
1630
|
}
|
|
1571
1631
|
}
|
|
1572
1632
|
|
|
1633
|
+
// 操作列按渲染结果撑宽:slot、权限按钮、按行变化的按钮都只能从 DOM 得知
|
|
1634
|
+
const fitOperationColumn = () => {
|
|
1635
|
+
const table = elTableRef.value
|
|
1636
|
+
const config = tableColumns.value.find(item => item.prop === props.operationPropKey)
|
|
1637
|
+
if (!table || !config || !config.attr) return
|
|
1638
|
+
const column = (table.store.states.columns || []).find(item => item.property === props.operationPropKey)
|
|
1639
|
+
if (!column) return
|
|
1640
|
+
// 固定列会渲染两份,优先测用户看到的固定列那份(nf-action 的按钮折叠只在可见的那份生效)
|
|
1641
|
+
const fixedWrapper = column.fixed === 'left' || column.fixed === true ? '.el-table__fixed' : column.fixed === 'right' ? '.el-table__fixed-right' : ''
|
|
1642
|
+
let cells: HTMLElement[] = fixedWrapper ? [...table.$el.querySelectorAll(`${fixedWrapper} .el-table__fixed-body-wrapper td.${column.id} .cell`)] : []
|
|
1643
|
+
if (!cells.length) cells = [...table.$el.querySelectorAll(`.el-table__body-wrapper td.${column.id} .cell`)]
|
|
1644
|
+
if (!cells.length) return
|
|
1645
|
+
// 批量写样式、批量读、批量还原:只触发一次布局,且在同一帧内完成,不会闪动
|
|
1646
|
+
const origins = cells.map(cell => [cell.style.whiteSpace, cell.style.width])
|
|
1647
|
+
cells.forEach(cell => {
|
|
1648
|
+
cell.style.whiteSpace = 'nowrap'
|
|
1649
|
+
cell.style.width = 'max-content'
|
|
1650
|
+
})
|
|
1651
|
+
// 容器可能是 width: 100%(如 nf-action),宽度随列变化,不能直接读单元格宽度;
|
|
1652
|
+
// 改为取按内容定宽的元素最右边缘,加单元格右内边距:按钮、链接、图标直接取其盒子,
|
|
1653
|
+
// 其余末端元素中,行内元素取盒子,块级元素取文字范围
|
|
1654
|
+
const contentTags = ['BUTTON', 'A', 'I', 'SVG', 'IMG']
|
|
1655
|
+
const range = document.createRange()
|
|
1656
|
+
const need = Math.max(...cells.map(cell => {
|
|
1657
|
+
const rect = cell.getBoundingClientRect()
|
|
1658
|
+
let right = rect.left
|
|
1659
|
+
cell.querySelectorAll('*').forEach(el => {
|
|
1660
|
+
const tag = el.tagName.toUpperCase()
|
|
1661
|
+
if (!contentTags.includes(tag) && el.children.length) return
|
|
1662
|
+
let box = el.getBoundingClientRect()
|
|
1663
|
+
if (!box.width) return
|
|
1664
|
+
if (!contentTags.includes(tag) && !getComputedStyle(el).display.startsWith('inline')) {
|
|
1665
|
+
range.selectNodeContents(el)
|
|
1666
|
+
box = range.getBoundingClientRect()
|
|
1667
|
+
}
|
|
1668
|
+
right = Math.max(right, box.right)
|
|
1669
|
+
})
|
|
1670
|
+
return Math.ceil(right - rect.left + parseFloat(getComputedStyle(cell).paddingRight)) + 1
|
|
1671
|
+
}))
|
|
1672
|
+
cells.forEach((cell, i) => {
|
|
1673
|
+
cell.style.whiteSpace = origins[i][0]
|
|
1674
|
+
cell.style.width = origins[i][1]
|
|
1675
|
+
})
|
|
1676
|
+
const current = parseFloat(config.attr.width as string) || column.realWidth || column.width || 0
|
|
1677
|
+
if (need > current) {
|
|
1678
|
+
// 记在列上,列重新同步时仍生效;_skip 避免深度监听 columns 触发重新同步
|
|
1679
|
+
config.__contentWidth = need
|
|
1680
|
+
props.columns._skip = true
|
|
1681
|
+
set(config.attr, 'width', need + 'px')
|
|
1682
|
+
config.__appliedWidth = { ...config.__appliedWidth, width: config.attr.width }
|
|
1683
|
+
nextTick(() => {
|
|
1684
|
+
props.columns._skip = false
|
|
1685
|
+
doLayout()
|
|
1686
|
+
})
|
|
1687
|
+
}
|
|
1688
|
+
}
|
|
1689
|
+
|
|
1690
|
+
// 行高兜底:固定列是整表副本,副本中单元格渲染不一致(如组件按可见性决定内容)时,
|
|
1691
|
+
// 主体与固定列行高会错位。监听可见单元格内容尺寸,变化后把同一行各副本统一为最大高度
|
|
1692
|
+
let rowHeightObserver: ResizeObserver | null = null
|
|
1693
|
+
let rowHeightFrame = 0
|
|
1694
|
+
const syncRowHeights = () => {
|
|
1695
|
+
rowHeightFrame = 0
|
|
1696
|
+
const tableEl = elTableRef.value?.$el
|
|
1697
|
+
if (!tableEl) return
|
|
1698
|
+
const bodies = [tableEl.querySelector('.el-table__body-wrapper tbody'), ...tableEl.querySelectorAll('.el-table__fixed-body-wrapper tbody')].filter(Boolean)
|
|
1699
|
+
if (bodies.length < 2) return
|
|
1700
|
+
const groups: HTMLElement[][] = bodies.map(body => [...body.children].filter(tr => tr.tagName === 'TR'))
|
|
1701
|
+
// 行数不一致(如展开行只在主体渲染)时无法按下标对应,放弃同步
|
|
1702
|
+
if (groups.some(rows => rows.length !== groups[0].length)) return
|
|
1703
|
+
// 先恢复为自然高度(只还原自己设过的),批量读取后再批量写入:只触发一次布局
|
|
1704
|
+
groups.forEach(rows => rows.forEach(tr => {
|
|
1705
|
+
if (tr.dataset.nfRowHeight) {
|
|
1706
|
+
tr.style.height = tr.dataset.nfOriginHeight || ''
|
|
1707
|
+
delete tr.dataset.nfRowHeight
|
|
1708
|
+
}
|
|
1709
|
+
}))
|
|
1710
|
+
const heights = groups.map(rows => rows.map(tr => tr.getBoundingClientRect().height))
|
|
1711
|
+
groups[0].forEach((_, i) => {
|
|
1712
|
+
const rowHeights = heights.map(list => list[i])
|
|
1713
|
+
const max = Math.max(...rowHeights)
|
|
1714
|
+
if (max - Math.min(...rowHeights) < 0.5) return
|
|
1715
|
+
groups.forEach(rows => {
|
|
1716
|
+
const tr = rows[i]
|
|
1717
|
+
tr.dataset.nfOriginHeight = tr.style.height
|
|
1718
|
+
tr.dataset.nfRowHeight = '1'
|
|
1719
|
+
tr.style.height = max + 'px'
|
|
1720
|
+
})
|
|
1721
|
+
})
|
|
1722
|
+
}
|
|
1723
|
+
const observeRowHeights = () => {
|
|
1724
|
+
rowHeightObserver?.disconnect()
|
|
1725
|
+
rowHeightObserver = null
|
|
1726
|
+
const tableEl = elTableRef.value?.$el
|
|
1727
|
+
if (!tableEl || !window.ResizeObserver || !tableEl.querySelector('.el-table__fixed-body-wrapper')) return
|
|
1728
|
+
rowHeightObserver = new ResizeObserver(() => {
|
|
1729
|
+
rowHeightFrame = rowHeightFrame || requestAnimationFrame(syncRowHeights)
|
|
1730
|
+
})
|
|
1731
|
+
// 监听可见单元格的内容盒:tr 被设了高度后,内容变矮也能感知到
|
|
1732
|
+
tableEl.querySelectorAll('.el-table__body-wrapper td:not(.is-hidden) > .cell, .el-table__fixed-body-wrapper td:not(.is-hidden) > .cell').forEach(cell => rowHeightObserver!.observe(cell))
|
|
1733
|
+
}
|
|
1734
|
+
onBeforeUnmount(() => {
|
|
1735
|
+
rowHeightObserver?.disconnect()
|
|
1736
|
+
rowHeightFrame && cancelAnimationFrame(rowHeightFrame)
|
|
1737
|
+
})
|
|
1738
|
+
watch([() => props.data, elTableRefKey], () => {
|
|
1739
|
+
nextTick(() => requestAnimationFrame(() => {
|
|
1740
|
+
fitOperationColumn()
|
|
1741
|
+
observeRowHeights()
|
|
1742
|
+
}))
|
|
1743
|
+
})
|
|
1744
|
+
|
|
1573
1745
|
const headerDragend = async (newWidth, oldWidth, column, event) => {
|
|
1574
1746
|
await nextTick()
|
|
1575
|
-
const minWidth = getMinWidth(column)
|
|
1747
|
+
const minWidth = getMinWidth(tableColumns.value.find(item => item.prop === column.property) || column)
|
|
1576
1748
|
if (newWidth < minWidth) {
|
|
1577
1749
|
column.width = minWidth
|
|
1578
1750
|
}
|
|
@@ -1587,6 +1759,10 @@
|
|
|
1587
1759
|
|
|
1588
1760
|
// 为固定在右侧的"操作"列添加拖拽句柄(脱离文档流也可拖拽)
|
|
1589
1761
|
let opFixedRightCleanup: Function | null = null
|
|
1762
|
+
onBeforeUnmount(() => {
|
|
1763
|
+
opFixedRightCleanup?.()
|
|
1764
|
+
opFixedRightCleanup = null
|
|
1765
|
+
})
|
|
1590
1766
|
const initOpFixedRightResizer = async () => {
|
|
1591
1767
|
await nextTick()
|
|
1592
1768
|
opFixedRightCleanup?.(); opFixedRightCleanup = null
|
|
@@ -1600,19 +1776,17 @@
|
|
|
1600
1776
|
const opCol = visibleColumns.find(col => (col.prop || col.attr?.prop) === props.operationPropKey)
|
|
1601
1777
|
if (!opCol || opCol?.attr?.fixed !== 'right') return
|
|
1602
1778
|
|
|
1603
|
-
//
|
|
1779
|
+
// Element UI 的固定表头保留全部列的 th,非固定列由样式隐藏。
|
|
1604
1780
|
const fixedRightHeader = tableEl.querySelector('.el-table__fixed-right .el-table__fixed-header-wrapper thead tr') as HTMLElement
|
|
1605
1781
|
|
|
1606
1782
|
if (!fixedRightHeader) return
|
|
1607
|
-
//
|
|
1783
|
+
// 使用可见列中的顺序定位固定表头中的 th。
|
|
1608
1784
|
const fixedIndex = visibleColumns.findIndex(col => col?.attr?.fixed === 'right')
|
|
1609
|
-
if (fixedIndex < 0) return
|
|
1610
1785
|
const th = fixedRightHeader.querySelectorAll('th')[fixedIndex] as HTMLElement
|
|
1611
1786
|
if (!th) return
|
|
1612
1787
|
|
|
1613
1788
|
// 在 .el-table__fixed-right 下创建覆盖层(宽高自适应、相对定位),句柄相对该层绝对定位到左侧
|
|
1614
1789
|
const fixedRightRoot = tableEl.querySelector('.el-table__fixed-right') as HTMLElement
|
|
1615
|
-
if (!fixedRightRoot) return
|
|
1616
1790
|
// 清理历史覆盖层
|
|
1617
1791
|
const oldOverlay = fixedRightRoot.querySelector('[data-nf-fixed-right-overlay="true"]') as HTMLElement
|
|
1618
1792
|
if (oldOverlay) oldOverlay.remove()
|
|
@@ -1628,8 +1802,7 @@
|
|
|
1628
1802
|
// 隐藏固定列相邻列与固定列本身的原生拖拽 after,避免干扰
|
|
1629
1803
|
const mainHeader = tableEl.querySelector('.el-table__header-wrapper thead tr') as HTMLElement
|
|
1630
1804
|
const cleanupHideAfter: HTMLElement[] = []
|
|
1631
|
-
const hideNativeAfter = (el
|
|
1632
|
-
if (!el) return
|
|
1805
|
+
const hideNativeAfter = (el: HTMLElement) => {
|
|
1633
1806
|
el.classList.add('nf-table-hide-after')
|
|
1634
1807
|
cleanupHideAfter.push(el)
|
|
1635
1808
|
}
|
|
@@ -1664,10 +1837,10 @@
|
|
|
1664
1837
|
const createIndicatorLine = (rect?: DOMRect) => {
|
|
1665
1838
|
const line = document.createElement('div')
|
|
1666
1839
|
line.id = 'nf-fixed-right-indicator-line'
|
|
1667
|
-
|
|
1840
|
+
|
|
1668
1841
|
// 获取表格位置信息(入参优先,避免多次触发回流)
|
|
1669
1842
|
const tableRect = rect || tableEl.getBoundingClientRect()
|
|
1670
|
-
|
|
1843
|
+
|
|
1671
1844
|
line.style.cssText = `
|
|
1672
1845
|
position: fixed;
|
|
1673
1846
|
top: ${tableRect.top}px;
|
|
@@ -1688,6 +1861,7 @@
|
|
|
1688
1861
|
// 拖动时显示指示线
|
|
1689
1862
|
// 拖动时显示指示线(使用 rAF + transform 提升性能)
|
|
1690
1863
|
let pending = false
|
|
1864
|
+
let indicatorFrame = 0
|
|
1691
1865
|
let cachedRect: DOMRect | null = null
|
|
1692
1866
|
const onPointerMove = (e: PointerEvent) => {
|
|
1693
1867
|
e.preventDefault()
|
|
@@ -1704,7 +1878,8 @@
|
|
|
1704
1878
|
if (indicatorLine) {
|
|
1705
1879
|
if (!pending) {
|
|
1706
1880
|
pending = true
|
|
1707
|
-
requestAnimationFrame(() => {
|
|
1881
|
+
indicatorFrame = requestAnimationFrame(() => {
|
|
1882
|
+
indicatorFrame = 0
|
|
1708
1883
|
indicatorLine!.style.display = 'block'
|
|
1709
1884
|
indicatorLine!.style.transform = `translateX(${dragX}px)`
|
|
1710
1885
|
pending = false
|
|
@@ -1713,20 +1888,27 @@
|
|
|
1713
1888
|
}
|
|
1714
1889
|
}
|
|
1715
1890
|
|
|
1716
|
-
const
|
|
1891
|
+
const stopPointerDrag = () => {
|
|
1892
|
+
if (indicatorFrame) cancelAnimationFrame(indicatorFrame)
|
|
1893
|
+
indicatorFrame = 0
|
|
1894
|
+
pending = false
|
|
1717
1895
|
document.removeEventListener('pointermove', onPointerMove)
|
|
1718
1896
|
document.removeEventListener('pointerup', onPointerUp)
|
|
1719
1897
|
const dragMask = document.getElementById('nf-fixed-right-drag-mask')
|
|
1720
1898
|
dragMask && dragMask.remove()
|
|
1721
|
-
|
|
1899
|
+
|
|
1722
1900
|
// 移除指示线
|
|
1723
1901
|
if (indicatorLine) {
|
|
1724
1902
|
indicatorLine.remove()
|
|
1725
1903
|
indicatorLine = null
|
|
1726
1904
|
}
|
|
1727
|
-
|
|
1905
|
+
}
|
|
1906
|
+
|
|
1907
|
+
const onPointerUp = async (e: PointerEvent) => {
|
|
1908
|
+
stopPointerDrag()
|
|
1909
|
+
|
|
1728
1910
|
try { handle.releasePointerCapture && handle.releasePointerCapture(e.pointerId) } catch {}
|
|
1729
|
-
|
|
1911
|
+
|
|
1730
1912
|
// 计算最终宽度并更新
|
|
1731
1913
|
try {
|
|
1732
1914
|
// 复用缓存的 rect,避免额外回流
|
|
@@ -1739,14 +1921,14 @@
|
|
|
1739
1921
|
const rawWidth = tableRect.right - clampX
|
|
1740
1922
|
const minWidth = getMinWidth(opCol)
|
|
1741
1923
|
const finalWidthNum = Math.max(rawWidth, minWidth)
|
|
1742
|
-
|
|
1924
|
+
|
|
1743
1925
|
// 缓存宽度
|
|
1744
1926
|
if (props.dragCached && columnProp) {
|
|
1745
1927
|
const columnCachedData = await CachedManager.asyncCachedGet(`${cStorageKey.value}$drag-column-width`) || {}
|
|
1746
1928
|
columnCachedData[columnProp] = finalWidthNum
|
|
1747
1929
|
await CachedManager.asyncCachedSet(`${cStorageKey.value}$drag-column-width`, columnCachedData)
|
|
1748
1930
|
}
|
|
1749
|
-
|
|
1931
|
+
|
|
1750
1932
|
// 通知外部(自定义固定列拖拽事件)
|
|
1751
1933
|
const oldWidth = th.getBoundingClientRect().width
|
|
1752
1934
|
emit('fixedColumnDragEnd', { width: finalWidthNum, oldWidth, prop: columnProp, column: opCol, nativeEvent: e })
|
|
@@ -1757,10 +1939,10 @@
|
|
|
1757
1939
|
|
|
1758
1940
|
const onPointerDown = (e: PointerEvent) => {
|
|
1759
1941
|
e.preventDefault()
|
|
1760
|
-
|
|
1942
|
+
|
|
1761
1943
|
// 创建指示线
|
|
1762
1944
|
indicatorLine = createIndicatorLine()
|
|
1763
|
-
|
|
1945
|
+
|
|
1764
1946
|
// 添加全屏遮罩捕获指针,避免失焦
|
|
1765
1947
|
const mask = document.createElement('div')
|
|
1766
1948
|
mask.id = 'nf-fixed-right-drag-mask'
|
|
@@ -1774,6 +1956,7 @@
|
|
|
1774
1956
|
handle.addEventListener('pointerdown', onPointerDown)
|
|
1775
1957
|
opFixedRightCleanup = () => {
|
|
1776
1958
|
try {
|
|
1959
|
+
stopPointerDrag()
|
|
1777
1960
|
handle.removeEventListener('pointerdown', onPointerDown)
|
|
1778
1961
|
handle.remove()
|
|
1779
1962
|
// 恢复原生 after
|
|
@@ -1955,10 +2138,7 @@
|
|
|
1955
2138
|
const nfTableBorder = (window as any).nfTableBorder
|
|
1956
2139
|
|
|
1957
2140
|
/** nfSearchForm表单数据(如果存在<nf-search-form>) */
|
|
1958
|
-
const nfSearchFormModel = computed({
|
|
1959
|
-
get: () => nfSearchFormRef.value?.nfSearchFormModel || {},
|
|
1960
|
-
set: formData => nfSearchFormRef.value?.setNfSearchFormModel?.(formData)
|
|
1961
|
-
})
|
|
2141
|
+
const nfSearchFormModel = computed(() => nfSearchFormRef.value?.nfSearchFormModel || {})
|
|
1962
2142
|
|
|
1963
2143
|
defineExpose({
|
|
1964
2144
|
/**
|