|
|
@@ -24,20 +24,20 @@ const tableContext = inject(TableContextKey, {
|
|
|
loading: ref(false)
|
|
|
})
|
|
|
|
|
|
-const defaultOptions: Partial<Props> = {
|
|
|
+const defaultOptions = ref<Partial<Props>>({
|
|
|
align: 'center',
|
|
|
resizable: true,
|
|
|
showOverflowTooltip: true
|
|
|
-}
|
|
|
+})
|
|
|
|
|
|
const bindProps = computed(() => {
|
|
|
const resolvedAlign =
|
|
|
props.zmSortable || props.zmFilterable
|
|
|
? 'left'
|
|
|
- : attrs.align || props.align || defaultOptions.align
|
|
|
+ : attrs.align || props.align || defaultOptions.value.align
|
|
|
|
|
|
return {
|
|
|
- ...defaultOptions,
|
|
|
+ ...defaultOptions.value,
|
|
|
...attrs,
|
|
|
...props,
|
|
|
prop: props.prop,
|
|
|
@@ -87,12 +87,39 @@ const handleSearchClick = () => {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+const getTextWidth = (text: string, fontSize = 14) => {
|
|
|
+ const span = document.createElement('span')
|
|
|
+ span.style.visibility = 'hidden'
|
|
|
+ span.style.position = 'absolute'
|
|
|
+ span.style.whiteSpace = 'nowrap'
|
|
|
+ span.style.fontSize = `${fontSize}px`
|
|
|
+ span.style.fontFamily = 'PingFang SC'
|
|
|
+ span.innerText = text
|
|
|
+
|
|
|
+ document.body.appendChild(span)
|
|
|
+ const width = span.offsetWidth
|
|
|
+ document.body.removeChild(span)
|
|
|
+
|
|
|
+ return width
|
|
|
+}
|
|
|
+
|
|
|
const calculativeWidth = () => {
|
|
|
- console.log('tableContext.data :>> ', tableContext.data.value)
|
|
|
- const values = tableContext.data.value.map(
|
|
|
- (item) => props.realValue?.(item[props.prop]) || item[props.prop]
|
|
|
- )
|
|
|
- console.log('values :>> ', values)
|
|
|
+ const values = tableContext.data.value
|
|
|
+ .map((item) => props.realValue?.(item[props.prop]) || item[props.prop])
|
|
|
+ .filter(Boolean)
|
|
|
+
|
|
|
+ let labelWidth = getTextWidth(bindProps.value.label || '') + 38
|
|
|
+
|
|
|
+ if (props.zmFilterable || props.zmSortable) {
|
|
|
+ labelWidth += 8
|
|
|
+ }
|
|
|
+
|
|
|
+ if (props.zmFilterable) labelWidth += 22
|
|
|
+ if (props.zmSortable) labelWidth += 22
|
|
|
+
|
|
|
+ const maxWidth = Math.max(...values.map((value) => getTextWidth(value) + 38), labelWidth)
|
|
|
+
|
|
|
+ defaultOptions.value.minWidth = maxWidth
|
|
|
}
|
|
|
|
|
|
watch(
|