数通智联化工云平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1 line
10 KiB

3 years ago
{"version":3,"file":"index.mjs","sources":["../../../../../../../packages/components/table/src/table-column/index.ts"],"sourcesContent":["// @ts-nocheck\nimport {\n Fragment,\n computed,\n defineComponent,\n getCurrentInstance,\n h,\n onBeforeMount,\n onBeforeUnmount,\n onMounted,\n ref,\n} from 'vue'\nimport ElCheckbox from '@element-plus/components/checkbox'\nimport { isString } from '@element-plus/utils'\nimport { cellStarts } from '../config'\nimport { compose, mergeOptions } from '../util'\nimport useWatcher from './watcher-helper'\nimport useRender from './render-helper'\nimport defaultProps from './defaults'\nimport type { TableColumn, TableColumnCtx } from './defaults'\n\nimport type { DefaultRow } from '../table/defaults'\n\nlet columnIdSeed = 1\n\nexport default defineComponent({\n name: 'ElTableColumn',\n components: {\n ElCheckbox,\n },\n props: defaultProps,\n setup(props, { slots }) {\n const instance = getCurrentInstance() as TableColumn<DefaultRow>\n const columnConfig = ref<Partial<TableColumnCtx<DefaultRow>>>({})\n const owner = computed(() => {\n let parent = instance.parent as any\n while (parent && !parent.tableId) {\n parent = parent.parent\n }\n return parent\n })\n\n const { registerNormalWatchers, registerComplexWatchers } = useWatcher(\n owner,\n props\n )\n const {\n columnId,\n isSubColumn,\n realHeaderAlign,\n columnOrTableParent,\n setColumnWidth,\n setColumnForcedProps,\n setColumnRenders,\n getPropsData,\n getColumnElIndex,\n realAlign,\n updateColumnOrder,\n } = useRender(props as unknown as TableColumnCtx<unknown>, slots, owner)\n\n const parent = columnOrTableParent.value\n columnId.value = `${\n parent.tableId || parent.columnId\n }_column_${columnIdSeed++}`\n onBeforeMount(() => {\n isSubColumn.value = owner.value !== parent\n\n const type = props.type || 'default'\n const sortable = props.sortable === '' ? true : props.sortable\n const defaults = {\n ...cellStarts[type],\n id: columnId.value,\n type,\n property: props.prop || props.property,\n align: realAlign,\n headerAlign: realHeaderAlign,\n showOverflowTooltip: props.showOverflowTooltip,\n // filter 相关属性\n filterable: props.filters || props.filterMethod,\n filteredValue: [],\n filterPlacement: '',\n isColumnGroup: false,\n isSubColumn: false,\n filterOpened: false,\n // sort 相关属性\n sortable,\n // index 列\n index: props.index,\n // <el-table-column key=\"xxx\" />\n rawColumnKey: instance.vnode.key,\n }\n\n const basicProps = [\n 'columnKey',\n 'label',\n 'className',\n 'labelClassName',\n 'type',\n 'renderHeader',\n 'formatter',\n 'fixed',\n 'resizable',\n ]\n const sortProps = ['sortMethod', 'sortBy', 'sortOrders']\n const selectProps = ['selectable', 'reserveSelection']\n const filterProps = [\n 'filterMethod',\n 'filters',\n 'filterMultiple',\n 'filterOpened',\n 'filteredValue',\n 'filterPlacement',\n ]\n\n let column = getPropsData(basicProps, sortProps, selectProps, filterProps)\n\n column = mergeOptions(defaults, column)\n // 注意 compose 中函数执行的顺序是从右到左\n const chains = compose(\n setColumnRenders,\n setColumnWidth,\n setColumnForcedProps\n )\n column = chains(column)\n columnConfig.value = column\n\n // 注册 watcher\n registerNormalWatchers()\n registerComplexWatchers()\n })\n onMounted(() => {\n const parent = columnOrTableParent.value\n const children = isSubColumn.value\n ? parent.vnode.el.children\n : parent.refs.hiddenColumns?.children\n const getColumnIndex = () =>\n getColumnElIndex(children || [], instance.vnode.el)\