diff --git a/packages/devui-vue/devui/table/src/components/body-td/body-td.tsx b/packages/devui-vue/devui/table/src/components/body-td/body-td.tsx new file mode 100644 index 0000000000..9b76b8c8bf --- /dev/null +++ b/packages/devui-vue/devui/table/src/components/body-td/body-td.tsx @@ -0,0 +1,34 @@ +import { defineComponent, toRef } from 'vue'; +import type { PropType } from 'vue'; +import { Column } from '../column/column-types'; +import { useFixedColumn } from '../../composable/use-table'; + +export default defineComponent({ + name: 'DTableBodyTd', + props: { + column: { + type: Object as PropType, + default: () => ({}), + }, + row: { + type: Object, + default: () => ({}), + }, + index: { + type: Number, + default: 0, + }, + }, + setup(props: { column: Column; row: any; index: number }) { + const column = toRef(props, 'column'); + + // 固定列 + const { stickyCell, offsetStyle } = useFixedColumn(column); + + return () => ( + + {column.value.renderCell?.(props.row, props.index)} + + ); + }, +}); diff --git a/packages/devui-vue/devui/table/src/components/body/body.tsx b/packages/devui-vue/devui/table/src/components/body/body.tsx index 3780f6e548..eb848ddee9 100644 --- a/packages/devui-vue/devui/table/src/components/body/body.tsx +++ b/packages/devui-vue/devui/table/src/components/body/body.tsx @@ -1,8 +1,7 @@ -import { defineComponent, inject, computed, PropType, toRef } from 'vue'; +import { defineComponent, inject, computed } from 'vue'; import { TABLE_TOKEN } from '../../table-types'; -import { Column } from '../column/column-types'; +import TD from '../body-td/body-td'; import { Checkbox } from '../../../../checkbox'; -import { useFixedColumn } from '../../composable/use-table'; import { useNamespace } from '../../../../shared/hooks/use-namespace'; import './body.scss'; @@ -12,19 +11,9 @@ export default defineComponent({ const table = inject(TABLE_TOKEN); const { _data: data, _columns: columns, _checkList: checkList, isFixedLeft } = table.store.states; const ns = useNamespace('table'); - - // 移动到行上是否高亮 const hoverEnabled = computed(() => table.props.rowHoveredHighlight); - // 行前的 checkbox - const tdAttrs = computed(() => - isFixedLeft.value - ? { - class: `${ns.m('sticky-cell')} left`, - style: 'left:0;', - } - : null - ); + const tdAttrs = computed(() => (isFixedLeft.value ? { class: `${ns.m('sticky-cell')} left`, style: 'left:0;' } : null)); const renderCheckbox = (index: number) => table.props.checkable ? ( @@ -48,29 +37,3 @@ export default defineComponent({ ); }, }); - -const TD = defineComponent({ - props: { - column: { - type: Object as PropType, - }, - row: { - type: Object, - }, - index: { - type: Number, - }, - }, - setup(props: { column: Column; row: any; index: number }) { - const column = toRef(props, 'column'); - - // 固定列 - const { stickyCell, offsetStyle } = useFixedColumn(column); - - return () => ( - - {column.value.renderCell(props.row, props.index)} - - ); - }, -}); diff --git a/packages/devui-vue/devui/table/src/components/header-th/header-th.tsx b/packages/devui-vue/devui/table/src/components/header-th/header-th.tsx new file mode 100644 index 0000000000..236b686a3c --- /dev/null +++ b/packages/devui-vue/devui/table/src/components/header-th/header-th.tsx @@ -0,0 +1,37 @@ +import { defineComponent, inject, toRefs } from 'vue'; +import { PropType } from 'vue'; +import { Column } from '../column/column-types'; +import { TABLE_TOKEN } from '../../table-types'; +import { Sort } from '../sort'; +import { Filter } from '../filter'; +import { useFixedColumn } from '../../composable/use-table'; +import { useSort, useFilter } from './use-header-th'; + +export default defineComponent({ + name: 'DTableHeaderTh', + props: { + column: { + type: Object as PropType, + required: true, + }, + }, + setup(props: { column: Column }) { + const table = inject(TABLE_TOKEN); + const { column } = toRefs(props); + const directionRef = useSort(table.store, column); + const filteredRef = useFilter(table.store, column); + const { stickyCell, offsetStyle } = useFixedColumn(column); + + return () => ( + +
+ {props.column.renderHeader?.()} + {props.column.filterable && ( + + )} +
+ {props.column.sortable && } + + ); + }, +}); diff --git a/packages/devui-vue/devui/table/src/components/header/use-header.ts b/packages/devui-vue/devui/table/src/components/header-th/use-header-th.ts similarity index 92% rename from packages/devui-vue/devui/table/src/components/header/use-header.ts rename to packages/devui-vue/devui/table/src/components/header-th/use-header-th.ts index f9145ec5b0..151aaf246f 100644 --- a/packages/devui-vue/devui/table/src/components/header/use-header.ts +++ b/packages/devui-vue/devui/table/src/components/header-th/use-header-th.ts @@ -19,7 +19,7 @@ export const useSort = (store: TableStore, column: Ref): Ref): Ref => { +export const useFilter = (store: TableStore, column: Ref): Ref => { const filteredRef = shallowRef(); watch(filteredRef, (results) => { store.filterData(column.value.field, results); diff --git a/packages/devui-vue/devui/table/src/components/header/header.tsx b/packages/devui-vue/devui/table/src/components/header/header.tsx index a5b0d7ba29..4bcfeaa7b1 100644 --- a/packages/devui-vue/devui/table/src/components/header/header.tsx +++ b/packages/devui-vue/devui/table/src/components/header/header.tsx @@ -1,11 +1,7 @@ -import { defineComponent, inject, computed, PropType, toRefs } from 'vue'; +import { defineComponent, inject, computed } from 'vue'; import { TABLE_TOKEN } from '../../table-types'; -import { Column } from '../column/column-types'; import { Checkbox } from '../../../../checkbox'; -import { Sort } from '../sort'; -import { Filter } from '../filter'; -import { useFliter, useSort } from './use-header'; -import { useFixedColumn } from '../../composable/use-table'; +import TH from '../header-th/header-th'; import { useNamespace } from '../../../../shared/hooks/use-namespace'; import './header.scss'; import '../body/body.scss'; @@ -17,14 +13,7 @@ export default defineComponent({ const { _checkAll: checkAll, _halfChecked: halfChecked, _columns: columns, isFixedLeft } = table.store.states; const ns = useNamespace('table'); - const thAttrs = computed(() => - isFixedLeft.value - ? { - class: `${ns.m('sticky-cell')} left`, - style: 'left:0;', - } - : null - ); + const thAttrs = computed(() => (isFixedLeft.value ? { class: `${ns.m('sticky-cell')} left`, style: 'left:0;' } : null)); const checkbox = computed(() => table.props.checkable ? ( @@ -39,7 +28,7 @@ export default defineComponent({ {checkbox.value} {columns.value.map((column, index) => ( - + ))} @@ -47,37 +36,3 @@ export default defineComponent({ }; }, }); - -const Th = defineComponent({ - props: { - column: { - type: Object as PropType, - required: true, - }, - }, - setup(props: { column: Column }) { - const table = inject(TABLE_TOKEN); - const { column } = toRefs(props); - - // 排序功能 - const directionRef = useSort(table.store, column); - - // 过滤器 - const filteredRef = useFliter(table.store, column); - - // 固定列功能 - const { stickyCell, offsetStyle } = useFixedColumn(column); - - return () => ( - -
- {props.column.renderHeader()} - {props.column.filterable && ( - - )} -
- {props.column.sortable && } - - ); - }, -}); diff --git a/packages/devui-vue/docs/.vitepress/devui-theme/components/PageContributorConfig.ts b/packages/devui-vue/docs/.vitepress/devui-theme/components/PageContributorConfig.ts index 841e8d7eea..a80942e80b 100644 --- a/packages/devui-vue/docs/.vitepress/devui-theme/components/PageContributorConfig.ts +++ b/packages/devui-vue/docs/.vitepress/devui-theme/components/PageContributorConfig.ts @@ -486,6 +486,10 @@ export const CONTRIBUTORS_MAP: IContributingMap = { avatar: 'https://portrait.gitee.com/uploads/avatars/user/757/2273663_weban_1611113629.png!avatar200', homepage: 'https://gitee.com/weban' }, + { + avatar: 'https://avatars.githubusercontent.com/u/11143986?v=4', + homepage: 'https://github.com/xingyan95' + }, ], tag: [ {