From 1f7c1a95b37ce47f02d624b6d9351facd1b02e2d Mon Sep 17 00:00:00 2001 From: juetan Date: Fri, 17 Nov 2023 09:02:23 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E8=A1=A8=E6=A0=BC?= =?UTF-8?q?=E5=88=97=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/AnTable/components/Table.tsx | 11 +- .../AnTable/components/TableColumnConfig.tsx | 178 ++++++++++++++++++ .../AnTable/hooks/useTableColumn.tsx | 11 +- src/pages/home/components/ColumnConfiger.vue | 106 ++++++----- src/pages/home/home.vue | 39 +++- src/types/auto-component.d.ts | 24 --- 6 files changed, 289 insertions(+), 80 deletions(-) create mode 100644 src/components/AnTable/components/TableColumnConfig.tsx diff --git a/src/components/AnTable/components/Table.tsx b/src/components/AnTable/components/Table.tsx index c0eb635..bd7d9a2 100644 --- a/src/components/AnTable/components/Table.tsx +++ b/src/components/AnTable/components/Table.tsx @@ -8,8 +8,9 @@ import { Button, PaginationProps, } from '@arco-design/web-vue'; -import { isObject, merge } from 'lodash-es'; +import { merge } from 'lodash-es'; import { PropType, defineComponent, ref } from 'vue'; +import { TableColumnConfig } from './TableColumnConfig'; type DataFn = (filter: { page: number; size: number; [key: string]: any }) => any | Promise; @@ -158,13 +159,15 @@ export const AnTable = defineComponent({ return (
-
TODO
+
+ +
- - +
diff --git a/src/components/AnTable/components/TableColumnConfig.tsx b/src/components/AnTable/components/TableColumnConfig.tsx new file mode 100644 index 0000000..b9d2b6b --- /dev/null +++ b/src/components/AnTable/components/TableColumnConfig.tsx @@ -0,0 +1,178 @@ +import { Button, Checkbox, Divider, InputNumber, Popover, Scrollbar, Tag } from '@arco-design/web-vue'; +import { PropType } from 'vue'; + +interface Item { + dataIndex: string; + enable: boolean; + autoWidth: boolean; + width: number; + editable: boolean; + title: string; +} + +export const TableColumnConfig = defineComponent({ + props: { + columns: { + type: Object as PropType, + required: true, + }, + }, + setup(props) { + const checkAll = ref(false); + const visible = ref(false); + const items = ref([]); + const checked = computed(() => items.value.filter(i => i.enable)); + const indeterminate = computed(() => { + const check = checked.value.length; + const total = items.value.length; + return 0 < check && check < total; + }); + + watch( + () => visible.value, + value => { + if (value) { + init(); + } else { + } + } + ); + + const init = () => { + const list: Item[] = []; + for (const column of props.columns) { + list.push({ + dataIndex: column.dataIndex, + title: column.title, + enable: true, + autoWidth: !column.width, + width: column.width ?? 60, + editable: !column.configable, + }); + } + items.value = list; + }; + + const onItemChange = () => { + if (checked.value.length === 0) { + checkAll.value = false; + return; + } + if (checked.value.length === items.value.length) { + checkAll.value = true; + } + }; + + const onCheckAllChange = (value: any) => { + for (const item of items.value) { + if (item.editable) { + item.enable = value; + } + } + }; + + const onReset = () => { + visible.value = false; + }; + + const onConfirm = () => { + visible.value = false; + }; + + const onItemUp = (index: number) => { + [items.value[index - 1], items.value[index]] = [items.value[index], items.value[index - 1]]; + }; + + const onItemDown = (index: number) => { + [items.value[index + 1], items.value[index]] = [items.value[index], items.value[index + 1]]; + }; + + return () => ( + + {{ + default: () => ( + + ), + content: () => ( + <> +
设置表格列
+ +
    + {items.value.map((item, index) => ( +
  • +
    + + {item.title} + + +
    +
    + + {{ + checkbox: ({ checked }: any) => ( + + 自适应 + + ), + }} + + + + 像素 +
    +
  • + ))} +
+
+
+
+ + 全选 + + + ({checked.value.length}/{items.value.length}) + +
+
+ + +
+
+ + ), + }} +
+ ); + }, +}); diff --git a/src/components/AnTable/hooks/useTableColumn.tsx b/src/components/AnTable/hooks/useTableColumn.tsx index 7283f40..6bba4e2 100644 --- a/src/components/AnTable/hooks/useTableColumn.tsx +++ b/src/components/AnTable/hooks/useTableColumn.tsx @@ -85,7 +85,16 @@ interface TableDropdownColumn { } export type TableColumn = TableColumnData & - (TableIndexColumn | TableBaseColumn | TableButtonColumn | TableDropdownColumn); + (TableIndexColumn | TableBaseColumn | TableButtonColumn | TableDropdownColumn) & { + /** + * 是否可配置 + * @example + * ```ts + * true + * ``` + */ + configable?: boolean; + }; export function useTableColumns(data: TableColumn[]) { const columns = ref([]); diff --git a/src/pages/home/components/ColumnConfiger.vue b/src/pages/home/components/ColumnConfiger.vue index f222a24..f87d8e9 100644 --- a/src/pages/home/components/ColumnConfiger.vue +++ b/src/pages/home/components/ColumnConfiger.vue @@ -1,5 +1,5 @@