@aoao-y33/ui 0.0.2 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (120) hide show
  1. package/README.md +0 -11
  2. package/dist/button/components/button/props.d.ts +43 -0
  3. package/dist/button/components/button/props.d.ts.map +1 -1
  4. package/dist/button/utils/index.d.ts +20 -0
  5. package/dist/button/utils/index.d.ts.map +1 -1
  6. package/dist/common/utils/iconUtils.d.ts +16 -0
  7. package/dist/common/utils/iconUtils.d.ts.map +1 -1
  8. package/dist/form/components/fields/index.d.ts.map +1 -1
  9. package/dist/form/components/form/form.vue.d.ts.map +1 -1
  10. package/dist/form/components/form/props.d.ts +43 -0
  11. package/dist/form/components/form/props.d.ts.map +1 -1
  12. package/dist/form/components/form-item/props.d.ts +29 -0
  13. package/dist/form/components/form-item/props.d.ts.map +1 -1
  14. package/dist/form/hoc/useForm.d.ts +43 -0
  15. package/dist/form/hoc/useForm.d.ts.map +1 -1
  16. package/dist/form/utils/index.d.ts +65 -0
  17. package/dist/form/utils/index.d.ts.map +1 -1
  18. package/dist/index.d.ts +0 -5
  19. package/dist/index.d.ts.map +1 -1
  20. package/dist/index.js +22523 -12091
  21. package/dist/layout/utils/index.d.ts +20 -0
  22. package/dist/layout/utils/index.d.ts.map +1 -1
  23. package/dist/modal/components/form-modal/props.d.ts +36 -1
  24. package/dist/modal/components/form-modal/props.d.ts.map +1 -1
  25. package/dist/modal/components/modal/props.d.ts +43 -1
  26. package/dist/modal/components/modal/props.d.ts.map +1 -1
  27. package/dist/modal/hoc/useFormModal.d.ts +50 -0
  28. package/dist/modal/hoc/useFormModal.d.ts.map +1 -1
  29. package/dist/modal/hoc/useModal.d.ts +55 -0
  30. package/dist/modal/hoc/useModal.d.ts.map +1 -1
  31. package/dist/modal/hoc/useModalExpose.d.ts +24 -0
  32. package/dist/modal/hoc/useModalExpose.d.ts.map +1 -1
  33. package/dist/table/components/table/props.d.ts +75 -0
  34. package/dist/table/components/table/props.d.ts.map +1 -1
  35. package/dist/table/components/table-column/props.d.ts +19 -0
  36. package/dist/table/components/table-column/props.d.ts.map +1 -1
  37. package/dist/table/components/table-page/props.d.ts +31 -0
  38. package/dist/table/components/table-page/props.d.ts.map +1 -1
  39. package/dist/table/components/table-select/props.d.ts +49 -0
  40. package/dist/table/components/table-select/props.d.ts.map +1 -1
  41. package/dist/table/hoc/useTable.d.ts +41 -0
  42. package/dist/table/hoc/useTable.d.ts.map +1 -1
  43. package/dist/table/hoc/useTableExpose.d.ts +27 -0
  44. package/dist/table/hoc/useTableExpose.d.ts.map +1 -1
  45. package/dist/table/utils/index.d.ts +26 -0
  46. package/dist/table/utils/index.d.ts.map +1 -1
  47. package/package.json +13 -6
  48. package/dist/global.d.ts +0 -33
  49. package/dist/global.d.ts.map +0 -1
  50. package/src/button/components/button/button.vue +0 -64
  51. package/src/button/components/button/index.ts +0 -2
  52. package/src/button/components/button/props.ts +0 -75
  53. package/src/button/components/fields/index.ts +0 -6
  54. package/src/button/hoc/index.ts +0 -1
  55. package/src/button/hoc/useButton.ts +0 -27
  56. package/src/button/index.ts +0 -4
  57. package/src/button/utils/index.ts +0 -32
  58. package/src/common/index.ts +0 -1
  59. package/src/common/utils/iconUtils.ts +0 -21
  60. package/src/common/utils/index.ts +0 -1
  61. package/src/form/components/fields/index.ts +0 -35
  62. package/src/form/components/form/form.vue +0 -130
  63. package/src/form/components/form/index.ts +0 -6
  64. package/src/form/components/form/props.ts +0 -73
  65. package/src/form/components/form-item/form-item.vue +0 -90
  66. package/src/form/components/form-item/index.ts +0 -6
  67. package/src/form/components/form-item/props.ts +0 -50
  68. package/src/form/hoc/index.ts +0 -3
  69. package/src/form/hoc/useForm.ts +0 -106
  70. package/src/form/hoc/useFormExpose.ts +0 -97
  71. package/src/form/hoc/useFormFetch.ts +0 -103
  72. package/src/form/index.ts +0 -5
  73. package/src/form/utils/index.ts +0 -149
  74. package/src/global.ts +0 -40
  75. package/src/index.ts +0 -37
  76. package/src/layout/components/fields/basic/basic.vue +0 -18
  77. package/src/layout/components/fields/index.ts +0 -10
  78. package/src/layout/components/fields/side/side.vue +0 -26
  79. package/src/layout/components/fields/top/top.vue +0 -13
  80. package/src/layout/components/layout/index.ts +0 -6
  81. package/src/layout/components/layout/layout.vue +0 -19
  82. package/src/layout/components/layout/props.ts +0 -3
  83. package/src/layout/hoc/index.ts +0 -1
  84. package/src/layout/hoc/useLayout.ts +0 -32
  85. package/src/layout/index.ts +0 -4
  86. package/src/layout/utils/index.ts +0 -31
  87. package/src/modal/components/form-modal/form-modal.vue +0 -158
  88. package/src/modal/components/form-modal/index.ts +0 -5
  89. package/src/modal/components/form-modal/props.ts +0 -61
  90. package/src/modal/components/modal/index.ts +0 -6
  91. package/src/modal/components/modal/modal.vue +0 -127
  92. package/src/modal/components/modal/props.ts +0 -78
  93. package/src/modal/hoc/index.ts +0 -3
  94. package/src/modal/hoc/useFormModal.ts +0 -140
  95. package/src/modal/hoc/useModal.ts +0 -151
  96. package/src/modal/hoc/useModalExpose.ts +0 -52
  97. package/src/modal/index.ts +0 -3
  98. package/src/style/index.css +0 -21
  99. package/src/table/components/fields/action-column/action-column.vue +0 -34
  100. package/src/table/components/fields/action-column/props.ts +0 -8
  101. package/src/table/components/fields/index.ts +0 -6
  102. package/src/table/components/table/index.ts +0 -6
  103. package/src/table/components/table/props.ts +0 -148
  104. package/src/table/components/table/table.vue +0 -77
  105. package/src/table/components/table-column/index.ts +0 -6
  106. package/src/table/components/table-column/props.ts +0 -26
  107. package/src/table/components/table-column/table-column.vue +0 -31
  108. package/src/table/components/table-page/index.ts +0 -6
  109. package/src/table/components/table-page/props.ts +0 -48
  110. package/src/table/components/table-page/table-page.vue +0 -51
  111. package/src/table/components/table-select/index.ts +0 -6
  112. package/src/table/components/table-select/props.ts +0 -79
  113. package/src/table/components/table-select/table-select.vue +0 -70
  114. package/src/table/hoc/index.ts +0 -2
  115. package/src/table/hoc/useTable.ts +0 -206
  116. package/src/table/hoc/useTableExpose.ts +0 -46
  117. package/src/table/index.ts +0 -7
  118. package/src/table/utils/index.ts +0 -37
  119. package/tsconfig.json +0 -30
  120. package/vite.config.ts +0 -49
@@ -1,77 +0,0 @@
1
- <template>
2
- <div class="flex flex-col w-full h-full gap-2 overflow-hidden p-4" v-loading="_loading">
3
- <div class="w-full rounded-(--ax-normal-radius) p-4 pb-0 bg-(--ax-block-color)" v-if="slots.search">
4
- <slot name="search"></slot>
5
- </div>
6
- <div class="w-full rounded-(--ax-normal-radius) p-4 bg-(--ax-block-color)" v-if="slots.tool">
7
- <slot name="tool"></slot>
8
- </div>
9
- <div class="flex-1 rounded-(--ax-normal-radius) overflow-hidden gap-2 flex flex-col bg-(--ax-block-color) p-4">
10
- <div class="flex-1 overflow-auto">
11
- <ElTable v-bind="{...tableProps,...attrs}"
12
- :header-cell-class-name="'ax-table__header'+' '+headerCellClassName"
13
- :stripe="true"
14
- :showOverflowTooltip="showOverflowTooltip"
15
- :data="_data" height="100%" ref="tableRef">
16
- <slot></slot>
17
- </ElTable>
18
- </div>
19
- <div v-if="slots.footer" class="flex justify-end">
20
- <slot name="footer"></slot>
21
- </div>
22
- </div>
23
- </div>
24
- </template>
25
-
26
- <script setup lang="ts">
27
- import {ElTable, vLoading, type TableInstance} from "element-plus";
28
-
29
- defineOptions({name: 'AxTable'})
30
- import type {AxTableProps} from "./props";
31
- import {useDefineProps, useFetch} from "@aoao-y33/hooks";
32
- import {computed, onMounted, provide, ref, useAttrs, useSlots} from "vue";
33
-
34
- const {
35
- data = [],
36
- showOverflowTooltip = true,
37
- api = null,
38
- apiConfig = {immediate: true},
39
- ...props
40
- } = defineProps<AxTableProps>()
41
- const attrs = useAttrs();
42
- const slots = useSlots();
43
- const [result, requestApi] = useFetch(null, apiConfig);
44
- provide("requestApi", requestApi);
45
- const tableProps = useDefineProps(props)
46
- const tableRef = ref<TableInstance>();
47
- const _data = computed(() => {
48
- if (result.value) {
49
- if (slots.footer) {
50
- return result.value?.data?.data || []
51
- }
52
- return result.value?.data || []
53
- }
54
- return data;
55
- })
56
- const _loading = computed(() => {
57
- return requestApi.getConfig().loading || false;
58
- })
59
- const getElTable = () => {
60
- return tableRef.value as TableInstance;
61
- }
62
- onMounted(() => {
63
- if (api) {
64
- requestApi.setApi(api);
65
- }
66
- })
67
- defineExpose({
68
- getElTable,
69
- ...requestApi,
70
- })
71
-
72
- </script>
73
- <style scoped lang="scss">
74
- :deep(.ax-table__header) {
75
- background: var(--el-fill-color-lighter) !important;
76
- }
77
- </style>
@@ -1,6 +0,0 @@
1
- import tableColumn from './table-column.vue';
2
-
3
- export const AxTableColumn = tableColumn;
4
- export type AxTableColumnInstance = InstanceType<typeof tableColumn>;
5
- export default AxTableColumn;
6
- export * from './props';
@@ -1,26 +0,0 @@
1
- import type {TableColumnCtx} from "element-plus";
2
-
3
- /**
4
- * AxTableColumns 表格列组件属性接口
5
- * 继承自 Element Plus TableColumnCtx,扩展了自定义列类型和组件配置功能
6
- * @template T - 表格行数据类型,必须是对象类型
7
- */
8
- export interface AxTableColumnsProps<T extends Record<string, any>= any> extends Partial<TableColumnCtx<T>>{
9
- /**
10
- * 列类型,决定该列的渲染方式
11
- * @example
12
- * - 'index': 索引列(显示行号)
13
- * - 'selection': 选择列(复选框)
14
- * - 'expand': 展开列(展开行内容)
15
- * - 'custom': 自定义列(使用自定义组件渲染)
16
- */
17
- type?:string,
18
-
19
- /**
20
- * 自定义组件的属性配置
21
- * 当列使用自定义组件渲染时,透传给该组件的属性
22
- * @example
23
- * componentProps: { color: 'red', size: 'large' }
24
- */
25
- componentProps?:Record<string, any>
26
- }
@@ -1,31 +0,0 @@
1
- <template>
2
- <ElTableColumn v-bind="columnProps" :type="type">
3
- <template #default="rowData" v-if="Column">
4
- <Column v-bind="componentProps" :rowData="rowData"/>
5
- </template>
6
- </ElTableColumn>
7
- </template>
8
-
9
- <script setup lang="ts">
10
- import {ElTableColumn} from "element-plus";
11
- import type {AxTableColumnsProps} from "./props";
12
- import {useDefineProps} from "@aoao-y33/hooks";
13
- import {computed} from "vue";
14
- import {tableColumnFields} from "@/table";
15
-
16
- const DEFAULT_TYPE = ['default', 'expand', 'selection', 'index'];
17
- defineOptions({name: 'AxTableColumn'});
18
-
19
- const {type = 'default', componentProps = {}, ...props} = defineProps<AxTableColumnsProps>()
20
- const columnProps = useDefineProps(props);
21
- const Column = computed(() => {
22
- if (DEFAULT_TYPE.includes(type)) {
23
- return null;
24
- }
25
- return tableColumnFields[type];
26
- })
27
- </script>
28
-
29
- <style scoped>
30
-
31
- </style>
@@ -1,6 +0,0 @@
1
- import page from './table-page.vue';
2
-
3
- export const AxTablePage = page;
4
- export default AxTablePage;
5
- export type AxTablePageInstance = InstanceType<typeof page>;
6
- export * from './props';
@@ -1,48 +0,0 @@
1
- import type {PaginationProps} from "element-plus";
2
- import type {EmitsToEventProps} from "@aoao-y33/utils";
3
-
4
- /**
5
- * AxTablePage 表格分页组件属性接口
6
- * 继承自 Element Plus PaginationProps,扩展了自定义参数名配置
7
- */
8
- export interface AxTablePageProps extends Partial<PaginationProps> {
9
- /**
10
- * 页码参数名
11
- * 用于自定义发送给后端的页码字段名称
12
- * @default 'pageNum' 或 'page'
13
- * @example 'currentPage', 'pageIndex'
14
- */
15
- paramNo?: string,
16
-
17
- /**
18
- * 每页条数参数名
19
- * 用于自定义发送给后端的每页显示数量字段名称
20
- * @default 'pageSize' 或 'size'
21
- * @example 'currentSize', 'limit'
22
- */
23
- paramSize?: string
24
- }
25
-
26
- /**
27
- * AxTablePage 表格分页组件事件发射接口
28
- */
29
- export interface AxTablePageEmits {
30
- /**
31
- * 页码变化事件
32
- * @param data - 新的页码值
33
- */
34
- 'change-page': [data: number]
35
-
36
- /**
37
- * 每页显示条数变化事件
38
- * @param data - 新的每页条数值
39
- */
40
- 'change-size': [data: number]
41
- }
42
-
43
- /**
44
- * AxTablePage 表格分页配置选项接口
45
- * 整合了分页属性和事件处理函数
46
- */
47
- export interface AxTablePageOptions extends AxTablePageProps, Partial<EmitsToEventProps<AxTablePageEmits>> {
48
- }
@@ -1,51 +0,0 @@
1
- <template>
2
- <ElPagination v-bind="pageProps"
3
- v-model:current-page="pageParams[paramNo]"
4
- v-model:page-size="pageParams[paramSize]"
5
- :total="_total"></ElPagination>
6
- </template>
7
-
8
- <script setup lang="ts">
9
- import type {AxTablePageEmits, AxTablePageProps} from './props';
10
- import {ElPagination} from "element-plus";
11
- import {type FetchApi, useDefineProps} from "@aoao-y33/hooks";
12
- import {computed, inject, reactive, watch} from "vue";
13
- import {bus} from "@aoao-y33/utils";
14
-
15
- defineOptions({name: 'AxTablePage'})
16
-
17
- const {paramNo = 'no', paramSize = 'size', total = 0, ...props} = defineProps<AxTablePageProps>()
18
- const pageProps = useDefineProps(props, {
19
- background: true,
20
- layout: 'prev,pager,next,jumper,sizes,total',
21
- })
22
- const emits = defineEmits<AxTablePageEmits>()
23
- const pageParams = reactive({}) as Record<typeof paramNo | typeof paramSize, number>;
24
- pageParams[paramNo] = 1;
25
- pageParams[paramSize] = 20;
26
- const requestApi = inject('requestApi') as FetchApi<typeof pageParams & any, any>
27
- requestApi.setParams(pageParams)
28
- const _total = computed(() => {
29
- return requestApi.get()?.data?.total || total
30
- })
31
- watch(() => pageParams[paramNo], (no: number) => {
32
- emits("change-page", no);
33
- requestApi.setParams(pageParams, true);
34
- })
35
- watch(() => pageParams[paramSize], (size: number) => {
36
- emits("change-size", size);
37
- if (pageParams[paramNo] === 1) {
38
- requestApi.setParams(pageParams, true);
39
- } else {
40
- pageParams[paramNo] = 1;
41
- }
42
- })
43
- bus.on("search", (data) => {
44
- requestApi.setParams(data);
45
- pageParams[paramNo] = 1;
46
- })
47
- </script>
48
-
49
- <style scoped>
50
-
51
- </style>
@@ -1,6 +0,0 @@
1
- import tableSelect from './table-select.vue';
2
-
3
- export * from './props';
4
- export const AxTableSelect = tableSelect;
5
- export type AxTableSelectInstance = InstanceType<typeof tableSelect>;
6
- export default AxTableSelect;
@@ -1,79 +0,0 @@
1
- import type {AxFormItemOptions, AxFormProps} from "@/form";
2
- import type {AxButtonOptions, AxButtonProps} from "@/button";
3
- import type {FieldsConfig} from "@aoao-y33/hooks";
4
- import type {EmitsToEventProps} from "@aoao-y33/utils";
5
- import type {Component} from "vue";
6
-
7
- /**
8
- * AxTableSelect 表格搜索组件属性接口
9
- * 继承自 AxFormProps,排除了 api 和 apiConfig(搜索组件不直接处理数据提交)
10
- * 用于配置表格上方的搜索表单区域
11
- */
12
- export interface AxTableSelectProps extends Omit<AxFormProps, 'api' | 'apiConfig'> {
13
- /** 重置按钮的配置项,用于自定义重置按钮的外观和行为 */
14
- resetButton?: AxButtonProps,
15
-
16
- /**
17
- * 是否启用折叠功能
18
- * 当搜索字段较多时,可以折叠显示部分字段,提升界面简洁度
19
- * @default false
20
- */
21
- isRest?: boolean
22
- }
23
-
24
- /**
25
- * AxTableSelect 表格搜索组件事件发射接口
26
- * @template T - 搜索条件数据类型
27
- */
28
- export interface AxTableSelectEmits<T extends Record<string, any> = any> {
29
- /**
30
- * 搜索事件,点击搜索按钮或触发搜索时发射
31
- * @param data - 当前搜索表单的数据
32
- */
33
- search: [data: T]
34
-
35
- /** 重置事件,点击重置按钮时发射,清空所有搜索条件 */
36
- reset: []
37
-
38
- /**
39
- * 搜索条件变化事件,表单字段值改变时实时发射
40
- * @param data - 变化后的搜索数据
41
- */
42
- change: [data: T]
43
- }
44
-
45
- /**
46
- * AxTableSelect 表格搜索配置选项接口
47
- * 整合了搜索表单属性、事件、字段配置、按钮配置和扩展插槽
48
- * @template T - 搜索条件数据类型
49
- */
50
- export interface AxTableSelectOptions<T extends Record<string, any> = any>
51
- extends AxTableSelectProps, Partial<EmitsToEventProps<AxTableSelectEmits<T>>> {
52
- /**
53
- * 搜索字段配置映射表,用于定义搜索表单中的各个字段(输入框、下拉框、日期选择器等)
54
- * @see FieldsConfig - 字段配置类型
55
- * @see AxFormItemOptions - 表单项选项类型
56
- */
57
- fieldConfig?: FieldsConfig<AxFormItemOptions>
58
-
59
- /**
60
- * 按钮配置映射表,用于配置搜索区域的按钮(搜索、重置等)
61
- * @see FieldsConfig - 字段配置类型
62
- * @see AxButtonOptions - 按钮选项类型
63
- */
64
- buttonConfig?: FieldsConfig<AxButtonOptions>
65
-
66
- /**
67
- * 展开插槽组件,用于在搜索区域展开显示额外的内容或高级搜索选项
68
- * @example
69
- * expandSlot: AdvancedSearchComponent
70
- */
71
- expandSlot?: Component
72
-
73
- /**
74
- * 折叠阈值,控制超过多少个字段后自动启用折叠功能
75
- * @default 3 或 4
76
- * @example over: 2 // 超过2个字段时显示展开/折叠按钮
77
- */
78
- over?: number
79
- }
@@ -1,70 +0,0 @@
1
- <template>
2
- <AxForm v-bind="formProps"
3
- ref="formRef"
4
- :submit-button="_submitButton"
5
- :inline="true" @submit="onSearch">
6
- <slot></slot>
7
- <slot name="expand"></slot>
8
- <template #button v-if="isRest||slots.button">
9
- <ax-button @click="onReset" v-bind="_resetButton" v-if="isRest"></ax-button>
10
- <slot name="button"></slot>
11
- </template>
12
- </AxForm>
13
- </template>
14
-
15
- <script setup lang="ts">
16
- import type {AxTableSelectProps, AxTableSelectEmits} from "./props";
17
- import {type FetchApi, useDefineProps} from "@aoao-y33/hooks";
18
- import {AxForm, type AxFormInstance, useFormExpose} from "@/form";
19
- import {AxButton} from "@/button";
20
- import {inject, nextTick, onMounted, type Ref, ref, useSlots} from "vue";
21
- import {bus} from "@aoao-y33/utils";
22
-
23
- defineOptions({name: 'ax-table-select'})
24
-
25
- const {
26
- resetButton = {},
27
- isRest = true,
28
- submitButton = {},
29
- ...props
30
- } = defineProps<AxTableSelectProps>();
31
- const formProps = useDefineProps(props);
32
- const emits = defineEmits<AxTableSelectEmits>();
33
- const slots = useSlots();
34
- const _submitButton = useDefineProps(submitButton, {
35
- text: "查询",
36
- icon: "Search",
37
- });
38
- const _resetButton = useDefineProps(resetButton, {
39
- text: "重置",
40
- icon: "Refresh"
41
- });
42
-
43
- const formRef = ref<AxFormInstance>() as Ref<AxFormInstance>;
44
- const formApi = useFormExpose(formRef);
45
- const requestApi = inject("requestApi") as FetchApi<Record<string, any>, any>
46
-
47
- const onSearch = (data: any) => {
48
- bus.emit("search", data);
49
- nextTick(() => {
50
- requestApi.load(data);
51
- })
52
- emits("search", data);
53
- }
54
- const onReset = () => {
55
- formApi.resetValues();
56
- }
57
-
58
- onMounted(() => {
59
- const defaultValue = formApi.getValues();
60
- requestApi.setParams(defaultValue);
61
- })
62
-
63
- defineExpose({
64
- ...formApi,
65
- })
66
- </script>
67
-
68
- <style scoped>
69
-
70
- </style>
@@ -1,2 +0,0 @@
1
- export * from './useTable';
2
- export * from './useTableExpose';
@@ -1,206 +0,0 @@
1
- import {
2
- AxTable,
3
- AxTableColumn,
4
- useTableExpose,
5
- type AxTableColumnsProps,
6
- type AxTableOptions,
7
- AxTablePage, AxTableSelect
8
- } from "@/table";
9
- import {useComponentPool, useState} from "@aoao-y33/hooks";
10
- import {omit} from "lodash";
11
- import {type Component, defineComponent, h, ref, shallowRef} from "vue";
12
- import {AxFormItem, type AxFormItemOptions, useFormExpose, useFormFetch} from "@/form";
13
- import {AxButton, type AxButtonOptions} from "@/button";
14
-
15
- /**
16
- * 表格 Hook,用于创建功能完整的高级表格组件
17
- *
18
- * 该 Hook 封装了表格的核心逻辑,包括:
19
- * - 表格数据展示和分页
20
- * - 搜索表单(支持动态字段配置)
21
- * - 工具栏按钮(新增、删除、导出等)
22
- * - 表格列配置(支持动态列)
23
- * - 折叠/展开搜索区域
24
- * - 数据请求和状态管理
25
- *
26
- * @param options - 表格初始配置选项
27
- * @returns [Table 组件, Table API] 元组
28
- *
29
- * @example
30
- * const [Table, tableApi] = useTable({
31
- * api: getUserList,
32
- * columnConfig: {
33
- * username: { label: '用户名', prop: 'username' },
34
- * email: { label: '邮箱', prop: 'email' }
35
- * },
36
- * searchConfig: {
37
- * fieldConfig: {
38
- * keyword: { label: '关键词', type: 'input' }
39
- * },
40
- * over: 2 // 超过2个字段显示折叠按钮
41
- * },
42
- * toolConfig: {
43
- * add: { text: '新增', onClick: handleAdd }
44
- * },
45
- * pageConfig: { pageSize: 10 }
46
- * })
47
- *
48
- * // 在模板中使用
49
- * <Table />
50
- *
51
- * // 通过 API 操作表格
52
- * tableApi.requestApi.fetch() // 刷新数据
53
- * tableApi.setTable({ data: [] }) // 更新表格属性
54
- * tableApi.toolsApi.addField(...) // 动态添加工具栏按钮
55
- */
56
- export function useTable<T extends Record<string, any>, R extends Record<string, any> = any>(options: AxTableOptions<T, R> = {}) {
57
- // 创建表格属性状态,排除各子模块的独立配置
58
- const [props, setTable] = useState(omit(options, ['columnConfig', 'pageConfig', 'toolConfig', 'searchConfig']));
59
-
60
- // 创建分页配置状态
61
- const [pageConfig, setPage] = useState(options.pageConfig || null);
62
-
63
- // 创建搜索表单属性状态,排除内部管理的配置项
64
- const [selectConfig, setSearch] = useState(omit(options.searchConfig, ['buttonConfig', 'fieldConfig', 'expandSlot']));
65
-
66
- // 使用 shallowRef 存储展开插槽组件,避免深层响应式开销
67
- const expandSlot = shallowRef(options.searchConfig?.expandSlot);
68
-
69
- // 创建表格列组件池,用于管理和渲染表格的各个列
70
- const [Columns, columnsApi] = useComponentPool<AxTableColumnsProps>(AxTableColumn, options.columnConfig);
71
-
72
- // 创建工具栏按钮组件池,用于管理和渲染表格上方的操作按钮
73
- const [Tools, toolsApi] = useComponentPool<AxButtonOptions>(AxButton, options.toolConfig);
74
-
75
- // 创建搜索表单字段组件池,用于管理和渲染搜索区域的表单项
76
- const [SearchFields, fieldsApi] = useComponentPool<AxFormItemOptions>(AxFormItem, options.searchConfig?.fieldConfig);
77
-
78
- // 创建搜索表单按钮组件池,用于管理和渲染搜索区域的按钮(搜索、重置)
79
- const [SearchButtons, buttonsApi] = useComponentPool<AxButtonOptions>(AxButton, options.searchConfig?.buttonConfig);
80
-
81
- // 创建表格引用,用于访问表格实例的方法
82
- const tableRef = ref();
83
-
84
- // 创建搜索表单引用,用于访问表单实例的方法
85
- const searchRef = ref();
86
-
87
- // 获取搜索表单暴露的 API(验证、重置、获取数据等方法)
88
- const searchApi = useFormExpose<R>(searchRef);
89
-
90
- // 获取表格数据请求 API(支持传入搜索条件作为请求参数)
91
- const requestApi = useFormFetch<T, R>(tableRef);
92
-
93
- // 获取表格暴露的 API(排序、筛选、选择等方法)
94
- const tableApi = useTableExpose(tableRef);
95
-
96
- /**
97
- * 分页组件定义
98
- * 渲染 AxTablePage 分页组件
99
- */
100
- const Page = defineComponent({
101
- setup() {
102
- return () => h(AxTablePage, {...pageConfig.value})
103
- }
104
- })
105
-
106
- /**
107
- * 默认展开/折叠按钮组件定义
108
- * 如果提供了自定义展开插槽则使用自定义组件,否则显示默认的"展开/收起"文本按钮
109
- */
110
- const defaultExpand = defineComponent({
111
- setup() {
112
- if (expandSlot.value) {
113
- console.log('xx')
114
- return () => h(expandSlot.value);
115
- }
116
- return () => h('span',
117
- {
118
- class: 'text-[14px] cursor-pointer text-(--el-color-primary) mr-2',
119
- onClick: () => {
120
- // 切换字段的展开/折叠状态
121
- fieldsApi.expand(!fieldsApi.configInfo().expand)
122
- }
123
- },
124
- !fieldsApi.configInfo().expand ? "展开" : "收起"
125
- );
126
- }
127
- })
128
-
129
- /**
130
- * 搜索表单组件定义
131
- * 整合搜索字段、按钮和展开/折叠功能
132
- */
133
- const Search = defineComponent({
134
- setup() {
135
- const slots: Record<string, Component> = {};
136
-
137
- // 如果存在搜索字段配置,创建默认插槽
138
- if (fieldsApi.getList().length) {
139
- slots['default'] = () => h(SearchFields);
140
- }
141
-
142
- // 如果存在搜索按钮配置,创建按钮插槽
143
- if (buttonsApi.getList().length) {
144
- slots['button'] = () => h(SearchButtons);
145
- }
146
-
147
- // 如果配置了折叠阈值,启用展开/折叠功能
148
- if (selectConfig.value.over != undefined) {
149
- fieldsApi.config({over: selectConfig.value.over})
150
- slots['expand'] = () => h(defaultExpand)
151
- }
152
-
153
- // 渲染 AxTableSelect 搜索组件
154
- return () => h(AxTableSelect, {ref: searchRef, ...selectConfig.value}, slots)
155
- }
156
- })
157
-
158
- /**
159
- * 主表格组件定义
160
- * 整合表格列、工具栏、分页和搜索区域
161
- */
162
- const Table = defineComponent({
163
- setup() {
164
- const slots: Record<string, any> = {};
165
-
166
- // 如果存在列配置,创建默认插槽(表格列)
167
- if (columnsApi.getList().length) {
168
- slots['default'] = () => h(Columns);
169
- }
170
-
171
- // 如果存在工具栏配置,创建工具栏插槽
172
- if (toolsApi.getList().length) {
173
- slots['tool'] = () => h(Tools);
174
- }
175
-
176
- // 如果存在分页配置,创建底部插槽(分页组件)
177
- if (pageConfig.value) {
178
- slots['footer'] = () => h(Page);
179
- }
180
-
181
- // 如果存在搜索配置,创建搜索插槽
182
- if (selectConfig.value) {
183
- slots['search'] = () => h(Search);
184
- }
185
-
186
- // 渲染 AxTable 表格组件
187
- return () => h(AxTable, {
188
- ref: tableRef,
189
- ...props.value
190
- }, slots);
191
- }
192
- })
193
-
194
- // 返回表格组件和完整的 API 集合
195
- return [Table, {
196
- setTable, // 更新表格属性
197
- setPage, // 更新分页配置
198
- setSearch, // 更新搜索表单属性
199
- toolsApi, // 工具栏按钮管理 API
200
- searchApi, // 搜索表单 API
201
- buttonsApi, // 搜索按钮管理 API
202
- fieldsApi, // 搜索字段管理 API
203
- ...requestApi, // 数据请求 API(fetch、submit 等)
204
- ...tableApi // 表格控制 API(排序、筛选、选择等)
205
- }] as const;
206
- }
@@ -1,46 +0,0 @@
1
- import type {Ref} from "vue";
2
- import type {AxTableInstance} from "@/table";
3
-
4
- /**
5
- * TableApi 类型定义
6
- * 由 useTableExpose 函数返回的 API 对象类型
7
- */
8
- export type TableApi = ReturnType<typeof useTableExpose>
9
-
10
- /**
11
- * 表格暴露 API Hook,用于获取和控制表格实例的方法
12
- *
13
- * 该 Hook 提供了访问底层表格实例的能力,包括:
14
- * - 获取 Element Plus 原生 ElTable 实例
15
- * - 可调用 ElTable 的所有方法(如 clearSort、clearFilter、toggleRowSelection 等)
16
- *
17
- * @param table - 表格组件的 Ref 引用,指向 AxTableInstance 实例
18
- * @returns 包含表格控制方法的 API 对象
19
- *
20
- * @example
21
- * const tableRef = ref<AxTableInstance>();
22
- * const tableApi = useTableExpose(tableRef);
23
- *
24
- * // 获取原生 ElTable 实例
25
- * const elTable = tableApi.getElTable()
26
- *
27
- * // 调用 ElTable 的原生方法
28
- * elTable?.clearSort() // 清除排序
29
- * elTable?.clearFilter() // 清除筛选
30
- * elTable?.toggleAllSelection() // 切换全选状态
31
- * elTable?.setCurrentRow(row) // 设置当前行
32
- */
33
- export function useTableExpose(table: Ref<AxTableInstance>) {
34
- /**
35
- * getElTable
36
- * 可用于访问 ElTable 的所有原生方法和属性
37
- * @returns ElTable 实例
38
- */
39
- const getElTable = () => {
40
- return table.value.getElTable();
41
- }
42
-
43
- return {
44
- getElTable,
45
- }
46
- }
@@ -1,7 +0,0 @@
1
- export * from './components/fields';
2
- export * from './components/table';
3
- export * from './components/table-column';
4
- export * from './components/table-page';
5
- export * from './components/table-select';
6
- export * from './hoc';
7
- export * from './utils';