123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254 |
- // @ts-nocheck
- import { h } from 'vue'
- import ElCheckbox from '@element-plus/components/checkbox'
- import { ElIcon } from '@element-plus/components/icon'
- import { ArrowRight, Loading } from '@element-plus/icons-vue'
- import { getProp } from '@element-plus/utils'
- import type { VNode } from 'vue'
- import type { TableColumnCtx } from './table-column/defaults'
- import type { Store } from './store'
- import type { TreeNode } from './table/defaults'
- const defaultClassNames = {
- selection: 'table-column--selection',
- expand: 'table__expand-column',
- }
- export const cellStarts = {
- default: {
- order: '',
- },
- selection: {
- width: 48,
- minWidth: 48,
- realWidth: 48,
- order: '',
- },
- expand: {
- width: 48,
- minWidth: 48,
- realWidth: 48,
- order: '',
- },
- index: {
- width: 48,
- minWidth: 48,
- realWidth: 48,
- order: '',
- },
- }
- export const getDefaultClassName = (type) => {
- return defaultClassNames[type] || ''
- }
- // 这些选项不应该被覆盖
- export const cellForced = {
- selection: {
- renderHeader<T>({ store }: { store: Store<T> }) {
- function isDisabled() {
- return store.states.data.value && store.states.data.value.length === 0
- }
- return h(ElCheckbox, {
- disabled: isDisabled(),
- size: store.states.tableSize.value,
- indeterminate:
- store.states.selection.value.length > 0 &&
- !store.states.isAllSelected.value,
- 'onUpdate:modelValue': store.toggleAllSelection,
- modelValue: store.states.isAllSelected.value,
- })
- },
- renderCell<T>({
- row,
- column,
- store,
- $index,
- }: {
- row: T
- column: TableColumnCtx<T>
- store: Store<T>
- $index: string
- }) {
- return h(ElCheckbox, {
- disabled: column.selectable
- ? !column.selectable.call(null, row, $index)
- : false,
- size: store.states.tableSize.value,
- onChange: () => {
- store.commit('rowSelectedChanged', row)
- },
- onClick: (event: Event) => event.stopPropagation(),
- modelValue: store.isSelected(row),
- })
- },
- sortable: false,
- resizable: false,
- },
- index: {
- renderHeader<T>({ column }: { column: TableColumnCtx<T> }) {
- return column.label || '#'
- },
- renderCell<T>({
- column,
- $index,
- }: {
- column: TableColumnCtx<T>
- $index: number
- }) {
- let i = $index + 1
- const index = column.index
- if (typeof index === 'number') {
- i = $index + index
- } else if (typeof index === 'function') {
- i = index($index)
- }
- return h('div', {}, [i])
- },
- sortable: false,
- },
- expand: {
- renderHeader<T>({ column }: { column: TableColumnCtx<T> }) {
- return column.label || ''
- },
- renderCell<T>({
- row,
- store,
- expanded,
- }: {
- row: T
- store: Store<T>
- expanded: boolean
- }) {
- const { ns } = store
- const classes = [ns.e('expand-icon')]
- if (expanded) {
- classes.push(ns.em('expand-icon', 'expanded'))
- }
- const callback = function (e: Event) {
- e.stopPropagation()
- store.toggleRowExpansion(row)
- }
- return h(
- 'div',
- {
- class: classes,
- onClick: callback,
- },
- {
- default: () => {
- return [
- h(ElIcon, null, {
- default: () => {
- return [h(ArrowRight)]
- },
- }),
- ]
- },
- }
- )
- },
- sortable: false,
- resizable: false,
- },
- }
- export function defaultRenderCell<T>({
- row,
- column,
- $index,
- }: {
- row: T
- column: TableColumnCtx<T>
- $index: number
- }) {
- const property = column.property
- const value = property && getProp(row, property).value
- if (column && column.formatter) {
- return column.formatter(row, column, value, $index)
- }
- return value?.toString?.() || ''
- }
- export function treeCellPrefix<T>(
- {
- row,
- treeNode,
- store,
- }: {
- row: T
- treeNode: TreeNode
- store: Store<T>
- },
- createPlaceholder = false
- ) {
- const { ns } = store
- if (!treeNode) {
- if (createPlaceholder) {
- return [
- h('span', {
- class: ns.e('placeholder'),
- }),
- ]
- }
- return null
- }
- const ele: VNode[] = []
- const callback = function (e) {
- e.stopPropagation()
- if (treeNode.loading) {
- return
- }
- store.loadOrToggle(row)
- }
- if (treeNode.indent) {
- ele.push(
- h('span', {
- class: ns.e('indent'),
- style: { 'padding-left': `${treeNode.indent}px` },
- })
- )
- }
- if (typeof treeNode.expanded === 'boolean' && !treeNode.noLazyChildren) {
- const expandClasses = [
- ns.e('expand-icon'),
- treeNode.expanded ? ns.em('expand-icon', 'expanded') : '',
- ]
- let icon = ArrowRight
- if (treeNode.loading) {
- icon = Loading
- }
- ele.push(
- h(
- 'div',
- {
- class: expandClasses,
- onClick: callback,
- },
- {
- default: () => {
- return [
- h(
- ElIcon,
- { class: { [ns.is('loading')]: treeNode.loading } },
- {
- default: () => [h(icon)],
- }
- ),
- ]
- },
- }
- )
- )
- } else {
- ele.push(
- h('span', {
- class: ns.e('placeholder'),
- })
- )
- }
- return ele
- }
|