@kine-design/crud 0.0.1-beta.2 → 0.0.1-beta.21

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 (118) hide show
  1. package/.vlaude/last-session-id +1 -0
  2. package/components/crudPage/KCrudPage.tsx +178 -0
  3. package/components/crudPage/crudPage.css +64 -0
  4. package/components/crudPage/index.ts +10 -0
  5. package/components/editableTable/KEditableTable.tsx +281 -0
  6. package/components/editableTable/editableTable.css +268 -0
  7. package/components/editableTable/index.ts +10 -0
  8. package/components/formPage/KApprovalDialog.tsx +142 -0
  9. package/components/formPage/KFormCard.tsx +65 -0
  10. package/components/formPage/KFormPage.tsx +128 -0
  11. package/components/formPage/KMasterDetailPage.tsx +205 -0
  12. package/components/formPage/KStickyActionBar.tsx +33 -0
  13. package/components/formPage/formPage.css +629 -0
  14. package/components/formPage/index.ts +14 -0
  15. package/components/layout/KContent.tsx +20 -0
  16. package/components/layout/KHeader.tsx +37 -0
  17. package/components/layout/KLayout.tsx +82 -0
  18. package/components/layout/KSider.tsx +80 -0
  19. package/components/layout/index.ts +18 -0
  20. package/components/layout/layout.css +262 -0
  21. package/components/login/KLoginPage.tsx +129 -0
  22. package/components/login/index.ts +10 -0
  23. package/components/login/login.css +118 -0
  24. package/components/navMenu/KNavMenu.tsx +175 -0
  25. package/components/navMenu/index.ts +2 -0
  26. package/components/navMenu/navMenu.css +197 -0
  27. package/components/pageHeader/KPageHeader.tsx +85 -0
  28. package/components/pageHeader/index.ts +9 -0
  29. package/components/pageHeader/pageHeader.css +93 -0
  30. package/components/searchTable/KSearchTable.tsx +138 -0
  31. package/components/searchTable/index.ts +10 -0
  32. package/components/searchTable/searchTable.css +121 -0
  33. package/components/upload/KFileList.tsx +95 -0
  34. package/components/upload/KImageUpload.tsx +286 -0
  35. package/components/upload/KUpload.tsx +206 -0
  36. package/components/upload/index.ts +13 -0
  37. package/components/upload/types.ts +26 -0
  38. package/components/upload/upload.css +345 -0
  39. package/composables/auth/authGuard.ts +128 -0
  40. package/composables/auth/index.ts +23 -0
  41. package/composables/auth/types.ts +109 -0
  42. package/composables/auth/useAuth.ts +278 -0
  43. package/composables/auth/vCan.ts +95 -0
  44. package/composables/defineRepository.ts +224 -0
  45. package/composables/error/createErrorHandler.ts +46 -0
  46. package/composables/error/defaultFeedbackHandler.ts +76 -0
  47. package/composables/error/dispatchError.ts +70 -0
  48. package/composables/error/index.ts +32 -0
  49. package/composables/error/types.ts +57 -0
  50. package/composables/error/useErrorHandler.ts +41 -0
  51. package/composables/form/index.ts +18 -0
  52. package/composables/form/renderFormField.tsx +119 -0
  53. package/composables/form/types.ts +129 -0
  54. package/composables/form/useFormPage.ts +183 -0
  55. package/composables/index.ts +62 -0
  56. package/composables/page/index.ts +11 -0
  57. package/composables/page/types.ts +62 -0
  58. package/composables/page/useCrudPage.ts +88 -0
  59. package/composables/request/composables.ts +206 -0
  60. package/composables/request/controlGate.ts +143 -0
  61. package/composables/request/createRequest.ts +173 -0
  62. package/composables/request/index.ts +71 -0
  63. package/composables/request/orchestrator.ts +145 -0
  64. package/composables/request/requestBuilder.ts +418 -0
  65. package/composables/request/transport/fetchTransport.ts +79 -0
  66. package/composables/request/transport/xhrTransport.ts +100 -0
  67. package/composables/request/types.ts +226 -0
  68. package/composables/request/upload.ts +146 -0
  69. package/composables/router/createRouterGuard.ts +134 -0
  70. package/composables/router/defineCrudRoutes.ts +116 -0
  71. package/composables/router/index.ts +22 -0
  72. package/composables/router/types.ts +128 -0
  73. package/composables/router/useMenuFromRoutes.ts +109 -0
  74. package/composables/router/useTabStore.ts +183 -0
  75. package/composables/search/index.ts +11 -0
  76. package/composables/search/useAutoCompleteSearch.ts +161 -0
  77. package/composables/setupCrud.ts +43 -0
  78. package/composables/storage/createStorageAdapter.ts +72 -0
  79. package/composables/storage/index.ts +13 -0
  80. package/composables/storage/types.ts +30 -0
  81. package/composables/storage/useStorage.ts +108 -0
  82. package/composables/store/defineUserStore.ts +122 -0
  83. package/composables/store/index.ts +11 -0
  84. package/composables/types.ts +118 -0
  85. package/dist/components/crudPage/KCrudPage.d.ts +14 -0
  86. package/dist/components/crudPage/index.d.ts +9 -0
  87. package/dist/components/editableTable/KEditableTable.d.ts +146 -0
  88. package/dist/components/editableTable/index.d.ts +10 -0
  89. package/dist/components/formPage/KApprovalDialog.d.ts +99 -0
  90. package/dist/components/formPage/KFormCard.d.ts +49 -0
  91. package/dist/components/formPage/KFormPage.d.ts +14 -0
  92. package/dist/components/formPage/KMasterDetailPage.d.ts +14 -0
  93. package/dist/components/formPage/KStickyActionBar.d.ts +16 -0
  94. package/dist/components/formPage/index.d.ts +14 -0
  95. package/dist/components/layout/KLayout.d.ts +7 -4
  96. package/dist/composables/auth/useAuth.d.ts +5 -5
  97. package/dist/composables/error/types.d.ts +2 -1
  98. package/dist/composables/form/index.d.ts +12 -0
  99. package/dist/composables/form/renderFormField.d.ts +11 -0
  100. package/dist/composables/form/types.d.ts +104 -0
  101. package/dist/composables/form/useFormPage.d.ts +38 -0
  102. package/dist/composables/index.d.ts +2 -0
  103. package/dist/composables/page/index.d.ts +10 -0
  104. package/dist/composables/page/types.d.ts +61 -0
  105. package/dist/composables/page/useCrudPage.d.ts +14 -0
  106. package/dist/composables/request/createRequest.d.ts +2 -0
  107. package/dist/composables/request/requestBuilder.d.ts +2 -0
  108. package/dist/composables/search/index.d.ts +10 -0
  109. package/dist/composables/search/useAutoCompleteSearch.d.ts +50 -0
  110. package/dist/crud.css +2499 -663
  111. package/dist/crud.js +11512 -2910
  112. package/dist/index.d.ts +11 -0
  113. package/dist/setup.d.ts +2 -2
  114. package/index.ts +144 -0
  115. package/package.json +20 -19
  116. package/setup.ts +288 -0
  117. package/tsconfig.json +12 -0
  118. package/vite.config.build.ts +52 -0
@@ -0,0 +1,99 @@
1
+ import { PropType } from 'vue';
2
+ export type ApprovalType = 'submit' | 'approve' | 'reject';
3
+ declare const _default: import('vue').DefineComponent<import('vue').ExtractPropTypes<{
4
+ /** 弹窗是否可见 */
5
+ visible: {
6
+ type: BooleanConstructor;
7
+ default: boolean;
8
+ };
9
+ /** 审批类型 */
10
+ type: {
11
+ type: PropType<ApprovalType>;
12
+ default: string;
13
+ };
14
+ /** 自定义标题,不传则使用默认 */
15
+ title: {
16
+ type: StringConstructor;
17
+ default: string;
18
+ };
19
+ /** 描述文字 */
20
+ description: {
21
+ type: StringConstructor;
22
+ default: string;
23
+ };
24
+ /** 摘要信息,如 "PO-2024-0087 | 供应商: 三星纺织 | ¥156,200" */
25
+ summary: {
26
+ type: StringConstructor;
27
+ default: string;
28
+ };
29
+ /** 备注输入框占位文本 */
30
+ remarkPlaceholder: {
31
+ type: StringConstructor;
32
+ default: string;
33
+ };
34
+ /** 备注是否必填(reject 默认必填) */
35
+ remarkRequired: {
36
+ type: BooleanConstructor;
37
+ default: undefined;
38
+ };
39
+ /** 确认中加载态 */
40
+ loading: {
41
+ type: BooleanConstructor;
42
+ default: boolean;
43
+ };
44
+ }>, () => import("vue/jsx-runtime").JSX.Element | null, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, ("cancel" | "update:visible" | "confirm")[], "cancel" | "update:visible" | "confirm", import('vue').PublicProps, Readonly<import('vue').ExtractPropTypes<{
45
+ /** 弹窗是否可见 */
46
+ visible: {
47
+ type: BooleanConstructor;
48
+ default: boolean;
49
+ };
50
+ /** 审批类型 */
51
+ type: {
52
+ type: PropType<ApprovalType>;
53
+ default: string;
54
+ };
55
+ /** 自定义标题,不传则使用默认 */
56
+ title: {
57
+ type: StringConstructor;
58
+ default: string;
59
+ };
60
+ /** 描述文字 */
61
+ description: {
62
+ type: StringConstructor;
63
+ default: string;
64
+ };
65
+ /** 摘要信息,如 "PO-2024-0087 | 供应商: 三星纺织 | ¥156,200" */
66
+ summary: {
67
+ type: StringConstructor;
68
+ default: string;
69
+ };
70
+ /** 备注输入框占位文本 */
71
+ remarkPlaceholder: {
72
+ type: StringConstructor;
73
+ default: string;
74
+ };
75
+ /** 备注是否必填(reject 默认必填) */
76
+ remarkRequired: {
77
+ type: BooleanConstructor;
78
+ default: undefined;
79
+ };
80
+ /** 确认中加载态 */
81
+ loading: {
82
+ type: BooleanConstructor;
83
+ default: boolean;
84
+ };
85
+ }>> & Readonly<{
86
+ onCancel?: ((...args: any[]) => any) | undefined;
87
+ "onUpdate:visible"?: ((...args: any[]) => any) | undefined;
88
+ onConfirm?: ((...args: any[]) => any) | undefined;
89
+ }>, {
90
+ type: ApprovalType;
91
+ summary: string;
92
+ title: string;
93
+ loading: boolean;
94
+ visible: boolean;
95
+ description: string;
96
+ remarkPlaceholder: string;
97
+ remarkRequired: boolean;
98
+ }, {}, {}, {}, string, import('vue').ComponentProvideOptions, true, {}, any>;
99
+ export default _default;
@@ -0,0 +1,49 @@
1
+ declare const _default: import('vue').DefineComponent<import('vue').ExtractPropTypes<{
2
+ /** 区块标题 */
3
+ title: {
4
+ type: StringConstructor;
5
+ default: string;
6
+ };
7
+ /** 副标题 */
8
+ subtitle: {
9
+ type: StringConstructor;
10
+ default: string;
11
+ };
12
+ /** 是否可折叠 */
13
+ collapsible: {
14
+ type: BooleanConstructor;
15
+ default: boolean;
16
+ };
17
+ /** 初始是否折叠 */
18
+ defaultCollapsed: {
19
+ type: BooleanConstructor;
20
+ default: boolean;
21
+ };
22
+ }>, () => import("vue/jsx-runtime").JSX.Element, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<import('vue').ExtractPropTypes<{
23
+ /** 区块标题 */
24
+ title: {
25
+ type: StringConstructor;
26
+ default: string;
27
+ };
28
+ /** 副标题 */
29
+ subtitle: {
30
+ type: StringConstructor;
31
+ default: string;
32
+ };
33
+ /** 是否可折叠 */
34
+ collapsible: {
35
+ type: BooleanConstructor;
36
+ default: boolean;
37
+ };
38
+ /** 初始是否折叠 */
39
+ defaultCollapsed: {
40
+ type: BooleanConstructor;
41
+ default: boolean;
42
+ };
43
+ }>> & Readonly<{}>, {
44
+ title: string;
45
+ subtitle: string;
46
+ collapsible: boolean;
47
+ defaultCollapsed: boolean;
48
+ }, {}, {}, {}, string, import('vue').ComponentProvideOptions, true, {}, any>;
49
+ export default _default;
@@ -0,0 +1,14 @@
1
+ import { PropType } from 'vue';
2
+ import { FormPageConfig } from '../../composables/form/types';
3
+ declare const _default: import('vue').DefineComponent<import('vue').ExtractPropTypes<{
4
+ config: {
5
+ type: PropType<FormPageConfig>;
6
+ required: true;
7
+ };
8
+ }>, () => import("vue/jsx-runtime").JSX.Element, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<import('vue').ExtractPropTypes<{
9
+ config: {
10
+ type: PropType<FormPageConfig>;
11
+ required: true;
12
+ };
13
+ }>> & Readonly<{}>, {}, {}, {}, {}, string, import('vue').ComponentProvideOptions, true, {}, any>;
14
+ export default _default;
@@ -0,0 +1,14 @@
1
+ import { PropType } from 'vue';
2
+ import { MasterDetailPageConfig } from '../../composables/form/types';
3
+ declare const _default: import('vue').DefineComponent<import('vue').ExtractPropTypes<{
4
+ config: {
5
+ type: PropType<MasterDetailPageConfig>;
6
+ required: true;
7
+ };
8
+ }>, () => import("vue/jsx-runtime").JSX.Element, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<import('vue').ExtractPropTypes<{
9
+ config: {
10
+ type: PropType<MasterDetailPageConfig>;
11
+ required: true;
12
+ };
13
+ }>> & Readonly<{}>, {}, {}, {}, {}, string, import('vue').ComponentProvideOptions, true, {}, any>;
14
+ export default _default;
@@ -0,0 +1,16 @@
1
+ declare const _default: import('vue').DefineComponent<import('vue').ExtractPropTypes<{
2
+ /** 左侧辅助信息,如"最后保存: 今天 14:23" */
3
+ hint: {
4
+ type: StringConstructor;
5
+ default: string;
6
+ };
7
+ }>, () => import("vue/jsx-runtime").JSX.Element, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<import('vue').ExtractPropTypes<{
8
+ /** 左侧辅助信息,如"最后保存: 今天 14:23" */
9
+ hint: {
10
+ type: StringConstructor;
11
+ default: string;
12
+ };
13
+ }>> & Readonly<{}>, {
14
+ hint: string;
15
+ }, {}, {}, {}, string, import('vue').ComponentProvideOptions, true, {}, any>;
16
+ export default _default;
@@ -0,0 +1,14 @@
1
+ /**
2
+ * @description formPage components barrel export
3
+ * @author 阿怪
4
+ * @date 2026/3/22
5
+ * @version v0.0.1
6
+ *
7
+ * 江湖的业务千篇一律,复杂的代码好几百行。
8
+ */
9
+ export { default as KFormCard } from './KFormCard';
10
+ export { default as KStickyActionBar } from './KStickyActionBar';
11
+ export { default as KApprovalDialog } from './KApprovalDialog';
12
+ export type { ApprovalType } from './KApprovalDialog';
13
+ export { default as KFormPage } from './KFormPage';
14
+ export { default as KMasterDetailPage } from './KMasterDetailPage';
@@ -1,7 +1,10 @@
1
- export declare const LAYOUT_COLLAPSED_KEY: unique symbol;
2
- export declare const LAYOUT_TOGGLE_KEY: unique symbol;
3
- export declare const LAYOUT_SIDER_WIDTH_KEY: unique symbol;
4
- export declare const LAYOUT_COLLAPSED_WIDTH_KEY: unique symbol;
1
+ import { InjectionKey, Ref } from 'vue';
2
+ export declare const LAYOUT_COLLAPSED_KEY: InjectionKey<Ref<boolean>>;
3
+ export declare const LAYOUT_TOGGLE_KEY: InjectionKey<() => void>;
4
+ export declare const LAYOUT_SIDER_WIDTH_KEY: InjectionKey<string>;
5
+ export declare const LAYOUT_COLLAPSED_WIDTH_KEY: InjectionKey<string>;
6
+ export declare const LAYOUT_DRAWER_OPEN_KEY: InjectionKey<Ref<boolean>>;
7
+ export declare const LAYOUT_TOGGLE_DRAWER_KEY: InjectionKey<() => void>;
5
8
  declare const _default: import('vue').DefineComponent<import('vue').ExtractPropTypes<{
6
9
  /** 受控模式:外部传入 collapsed 状态 */
7
10
  collapsed: {
@@ -1,5 +1,10 @@
1
1
  import { App } from 'vue';
2
2
  import { AuthOptions, AuthReturn } from './types';
3
+ /** 内部 provide 结构,包含 auth 实例与 onUnauthorized 回调 */
4
+ interface AuthProvide {
5
+ auth: AuthReturn;
6
+ onUnauthorized: (() => void) | undefined;
7
+ }
3
8
  /**
4
9
  * 创建全局 auth 实例并安装到 Vue App。
5
10
  * 应在 main.ts 中调用一次,之后所有组件可通过 useAuth() 获取。
@@ -19,11 +24,6 @@ import { AuthOptions, AuthReturn } from './types';
19
24
  * ```
20
25
  */
21
26
  export declare function createAuth(app: App, options: AuthOptions): AuthReturn;
22
- /** 内部 provide 结构,包含 auth 实例与 onUnauthorized 回调 */
23
- interface AuthProvide {
24
- auth: AuthReturn;
25
- onUnauthorized: (() => void) | undefined;
26
- }
27
27
  /**
28
28
  * 在组件中获取全局 auth 实例。
29
29
  * 必须在 createAuth() 已安装的 App 子树内调用。
@@ -1,3 +1,4 @@
1
+ import { InjectionKey } from 'vue';
1
2
  import { UserFeedbackHandler, NetworkError, BusinessError } from '../request/types';
2
3
  /**
3
4
  * @description 全局错误处理模块类型定义
@@ -14,7 +15,7 @@ export type ErrorLevel = 'info' | 'warning' | 'error' | 'success';
14
15
  /** 401 未授权时的处理方式 */
15
16
  export type UnauthorizedStrategy = 'redirect' | 'dialog';
16
17
  /** provide/inject 使用的唯一 symbol key,避免命名冲突 */
17
- export declare const ERROR_HANDLER_INJECT_KEY: unique symbol;
18
+ export declare const ERROR_HANDLER_INJECT_KEY: InjectionKey<ErrorHandlerOptions>;
18
19
  /** createErrorHandler 配置项 */
19
20
  export interface ErrorHandlerOptions {
20
21
  /** 用户反馈处理器,默认使用 defaultFeedbackHandler */
@@ -0,0 +1,12 @@
1
+ /**
2
+ * @description form composables barrel export
3
+ * @author 阿怪
4
+ * @date 2026/3/22
5
+ * @version v0.0.1
6
+ *
7
+ * 江湖的业务千篇一律,复杂的代码好几百行。
8
+ */
9
+ export { useFormPage } from './useFormPage';
10
+ export type { UseFormPageOptions, UseFormPageReturn } from './useFormPage';
11
+ export { renderFormField } from './renderFormField';
12
+ export type { FormFieldType, FormFieldConfig, FormPageConfig, DetailTableConfig, MasterDetailPageConfig, } from './types';
@@ -0,0 +1,11 @@
1
+ import { FormFieldConfig } from './types';
2
+ /**
3
+ * 渲染单个表单字段控件。
4
+ *
5
+ * @param field 字段配置
6
+ * @param formData 响应式表单数据对象(reactive)
7
+ * @param errors 当前校验错误集合(已解包,非 Ref)
8
+ * @param validateField 触发单字段校验的函数
9
+ * @param slots 组件 slots,用于支持 `field-{param}` 自定义插槽
10
+ */
11
+ export declare function renderFormField(field: FormFieldConfig, formData: Record<string, unknown>, errors: Record<string, string>, validateField: (param: string) => void, slots: Record<string, ((...args: unknown[]) => unknown) | undefined>): unknown;
@@ -0,0 +1,104 @@
1
+ import { EditableColumn } from '../../components/editableTable';
2
+ /** 表单字段类型 */
3
+ export type FormFieldType = 'text' | 'number' | 'select' | 'date' | 'textarea' | 'switch' | 'autocomplete' | 'custom';
4
+ /** 表单字段配置 */
5
+ export interface FormFieldConfig {
6
+ /** 字段名,对应数据对象的 key */
7
+ param: string;
8
+ /** 标签文本 */
9
+ label: string;
10
+ /** 字段类型 */
11
+ type?: FormFieldType;
12
+ /** 占位文本 */
13
+ placeholder?: string;
14
+ /** 是否必填 */
15
+ required?: boolean;
16
+ /** 是否禁用 */
17
+ disabled?: boolean;
18
+ /** 是否只读 */
19
+ readonly?: boolean;
20
+ /** 跨列数(默认 1,textarea 常用 'full' 表示占满整行) */
21
+ span?: number | 'full';
22
+ /** select 类型的选项 */
23
+ options?: Array<{
24
+ label: string;
25
+ value: string | number;
26
+ }>;
27
+ /** autocomplete 的 fetchSuggestions */
28
+ fetchSuggestions?: (query: string) => Promise<Array<{
29
+ label: string;
30
+ value: string | number;
31
+ }>>;
32
+ /** number 类型的前缀(如 ¥) */
33
+ prefix?: string;
34
+ /** number 类型的后缀(如 米、件) */
35
+ suffix?: string;
36
+ /** textarea 的行数 */
37
+ rows?: number;
38
+ /** textarea 的最大字数 */
39
+ maxLength?: number;
40
+ /** 自定义校验函数 */
41
+ validator?: (value: unknown, formData: Record<string, unknown>) => string | undefined;
42
+ }
43
+ /** SimpleFormPage 完整配置 */
44
+ export interface FormPageConfig {
45
+ /** 页面标题 */
46
+ title: string;
47
+ /** API 路径 */
48
+ api: string;
49
+ /** 表单字段定义 */
50
+ fields: FormFieldConfig[];
51
+ /** 列数布局(默认 2) */
52
+ columns?: 1 | 2 | 3;
53
+ /** 主键字段(编辑模式下从路由取 id,默认 'id') */
54
+ rowKey?: string;
55
+ /** 保存成功后跳转路径 */
56
+ redirectPath?: string;
57
+ /** 是否显示"保存草稿"按钮 */
58
+ showDraft?: boolean;
59
+ /** 提交按钮文本 */
60
+ submitText?: string;
61
+ }
62
+ /** 子表配置 */
63
+ export interface DetailTableConfig {
64
+ /** 子表标题 */
65
+ title: string;
66
+ /** 子表字段名(对应主表数据中的数组字段) */
67
+ param: string;
68
+ /** 列定义(复用 EditableColumn) */
69
+ columns: EditableColumn[];
70
+ /** 是否显示汇总行 */
71
+ showSummary?: boolean;
72
+ /** 汇总行标签 */
73
+ summaryLabel?: string;
74
+ /** 币种前缀 */
75
+ currencyPrefix?: string;
76
+ /** 新增行按钮文本 */
77
+ addText?: string;
78
+ }
79
+ /** MasterDetailPage 完整配置 */
80
+ export interface MasterDetailPageConfig {
81
+ /** 页面标题 */
82
+ title: string;
83
+ /** API 路径 */
84
+ api: string;
85
+ /** 面包屑路径 */
86
+ breadcrumb?: Array<{
87
+ label: string;
88
+ path?: string;
89
+ }>;
90
+ /** 主表字段定义 */
91
+ fields: FormFieldConfig[];
92
+ /** 主表列数布局(默认 3) */
93
+ columns?: 1 | 2 | 3;
94
+ /** 子表配置(支持多个子表) */
95
+ detailTables: DetailTableConfig[];
96
+ /** 主键字段 */
97
+ rowKey?: string;
98
+ /** 保存成功后跳转路径 */
99
+ redirectPath?: string;
100
+ /** 是否显示"保存草稿"按钮 */
101
+ showDraft?: boolean;
102
+ /** 提交按钮文本 */
103
+ submitText?: string;
104
+ }
@@ -0,0 +1,38 @@
1
+ import { Ref } from 'vue';
2
+ import { useRouter } from 'vue-router';
3
+ import { FormFieldConfig } from './types';
4
+ export interface UseFormPageOptions {
5
+ /** API 路径 */
6
+ api: string;
7
+ /** 字段配置 */
8
+ fields: FormFieldConfig[];
9
+ /** 主键字段 */
10
+ rowKey?: string;
11
+ /** 保存成功后跳转路径 */
12
+ redirectPath?: string;
13
+ }
14
+ export interface UseFormPageReturn {
15
+ /** 表单数据 */
16
+ formData: Record<string, unknown>;
17
+ /** 是否编辑模式(路由有 id) */
18
+ isEdit: Ref<boolean>;
19
+ /** 加载中 */
20
+ loading: Ref<boolean>;
21
+ /** 提交中 */
22
+ submitting: Ref<boolean>;
23
+ /** 字段错误信息 */
24
+ errors: Ref<Record<string, string>>;
25
+ /** 校验全部字段 */
26
+ validate: () => boolean;
27
+ /** 校验单个字段 */
28
+ validateField: (param: string) => string | undefined;
29
+ /** 提交表单 */
30
+ submit: (extraData?: Record<string, unknown>) => Promise<boolean>;
31
+ /** 保存草稿(不校验必填) */
32
+ saveDraft: (extraData?: Record<string, unknown>) => Promise<boolean>;
33
+ /** 返回上一页 */
34
+ goBack: () => void;
35
+ /** 路由实例 */
36
+ router: ReturnType<typeof useRouter>;
37
+ }
38
+ export declare function useFormPage(options: UseFormPageOptions): UseFormPageReturn;
@@ -7,6 +7,8 @@
7
7
  * 江湖的业务千篇一律,复杂的代码好几百行。
8
8
  */
9
9
  export { defineRepository } from './defineRepository';
10
+ export { useAutoCompleteSearch } from './search';
11
+ export type { AutoCompleteSearchOptions, AutoCompleteSearchReturn } from './search';
10
12
  export { setupCrud } from './setupCrud';
11
13
  export type { EntityId, ListParams, MutationOptions, Repository, RepositoryEndpoints, UseListReturn, UseDetailReturn, UseMutationReturn, } from './types';
12
14
  export { defineCrudRoutes, createTabStore, useTabStore, useMenuFromRoutes, createRouterGuard, addTabFromRoute, } from './router';
@@ -0,0 +1,10 @@
1
+ /**
2
+ * @description CrudPage composable barrel export
3
+ * @author 阿怪
4
+ * @date 2026/3/22
5
+ * @version v0.0.1
6
+ *
7
+ * 江湖的业务千篇一律,复杂的代码好几百行。
8
+ */
9
+ export { useCrudPage } from './useCrudPage';
10
+ export type { CrudPageConfig, CrudColumnConfig, CrudFilterConfig, StatusMapItem } from './types';
@@ -0,0 +1,61 @@
1
+ /**
2
+ * @description CrudPage 配置驱动页面类型定义
3
+ * @author 阿怪
4
+ * @date 2026/3/22
5
+ * @version v0.0.1
6
+ *
7
+ * 江湖的业务千篇一律,复杂的代码好几百行。
8
+ */
9
+ /** 列配置 */
10
+ export interface CrudColumnConfig {
11
+ /** 字段名,对应数据对象的 key */
12
+ param: string;
13
+ /** 列标题 */
14
+ label: string;
15
+ /** 列宽 */
16
+ width?: string;
17
+ /** 列类型,影响渲染方式 */
18
+ type?: 'text' | 'status' | 'date' | 'datetime' | 'image';
19
+ }
20
+ /** 筛选项配置 */
21
+ export interface CrudFilterConfig {
22
+ /** 字段名,作为请求参数的 key */
23
+ param: string;
24
+ /** 筛选项标签 */
25
+ label: string;
26
+ /** 筛选项类型 */
27
+ type: 'input' | 'select';
28
+ /** select 类型的选项列表 */
29
+ options?: {
30
+ label: string;
31
+ value: string | number;
32
+ }[];
33
+ /** 占位文本 */
34
+ placeholder?: string;
35
+ }
36
+ /** 状态映射:字段值 → KTag 的 label + type */
37
+ export type StatusMapItem = {
38
+ label: string;
39
+ type?: 'default' | 'primary' | 'success' | 'warning' | 'danger' | 'info';
40
+ };
41
+ /** CrudPage 完整配置 */
42
+ export interface CrudPageConfig {
43
+ /** 页面标题 */
44
+ title: string;
45
+ /** API 路径(基于 createRequest 的 baseURL) */
46
+ api: string;
47
+ /** 列定义 */
48
+ columns: CrudColumnConfig[];
49
+ /** 筛选项定义,为空则不显示搜索区 */
50
+ filters?: CrudFilterConfig[];
51
+ /** 状态字段的值 → 显示文本 + 标签颜色 映射 */
52
+ statusMap?: Record<string, StatusMapItem>;
53
+ /** 每页条数,默认 20 */
54
+ pageSize?: number;
55
+ /** 行主键字段,默认 'id' */
56
+ rowKey?: string;
57
+ /** 详情页路由前缀,用于构建查看/编辑路由:`${detailPath}/${row[rowKey]}` */
58
+ detailPath?: string;
59
+ /** 图片列 src 转换函数,将原始值转为可访问 URL */
60
+ imageResolver?: (raw: string) => string;
61
+ }
@@ -0,0 +1,14 @@
1
+ import { CrudPageConfig } from './types';
2
+ export declare function useCrudPage(config: CrudPageConfig): {
3
+ page: import('vue').Ref<number, number>;
4
+ pageSize: import('vue').Ref<number, number>;
5
+ total: import('vue').Ref<number, number>;
6
+ totalPages: import('vue').ComputedRef<number>;
7
+ list: import('vue').Ref<Record<string, unknown>[], Record<string, unknown>[]>;
8
+ loading: import('vue').Ref<boolean, boolean>;
9
+ filters: Record<string, unknown>;
10
+ fetchData: () => Promise<void>;
11
+ onPageChange: (p: number) => void;
12
+ onSearch: () => void;
13
+ onReset: () => void;
14
+ };
@@ -1,6 +1,8 @@
1
1
  import { RequestMethod, RequestOptions } from './types';
2
2
  import { RequestBuilder } from './requestBuilder';
3
3
  export interface RequestClient {
4
+ /** 请求基础 URL */
5
+ readonly baseURL: string;
4
6
  /** 简便方法,直接返回 Promise<T> */
5
7
  send<T>(method: RequestMethod, url: string, body?: unknown): Promise<T>;
6
8
  /** GET 请求 */
@@ -8,6 +8,8 @@ export interface RequestBuilderContext {
8
8
  getToken?: () => string | null | undefined;
9
9
  onUnauthorized?: () => void;
10
10
  responseInterceptor?: <T>(data: T) => T;
11
+ /** 用户反馈处理器(写操作成功后自动 showSuccess) */
12
+ feedback?: import('./types').UserFeedbackHandler;
11
13
  /** 注册 abort controller,供生命周期管理 */
12
14
  registerAbort?: (controller: AbortController) => void;
13
15
  }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * @description search composables barrel export
3
+ * @author 阿怪
4
+ * @date 2026/3/22
5
+ * @version v0.0.1
6
+ *
7
+ * 江湖的业务千篇一律,复杂的代码好几百行。
8
+ */
9
+ export { useAutoCompleteSearch } from './useAutoCompleteSearch';
10
+ export type { AutoCompleteSearchOptions, AutoCompleteSearchReturn } from './useAutoCompleteSearch';
@@ -0,0 +1,50 @@
1
+ import { Ref, ShallowRef } from 'vue';
2
+ export interface AutoCompleteSearchOptions<T = any> {
3
+ /** API 路径,如 '/supplier' */
4
+ api: string;
5
+ /** 搜索参数名,如 'nameLike',输入值会赋给这个 key */
6
+ searchKey: string;
7
+ /** 显示字段名,如 'supplierName',用于回填输入框 */
8
+ labelKey: string;
9
+ /** 值字段名,默认 'id' */
10
+ valueKey?: string;
11
+ /** 每次搜索返回条数,默认 5 */
12
+ pageSize?: number;
13
+ /** 额外的固定查询参数 */
14
+ extraParams?: Record<string, unknown>;
15
+ /** 自定义过滤函数 */
16
+ filter?: (item: T) => boolean;
17
+ /** 自定义映射函数,将 API 返回的数据转换为 AutoComplete 需要的格式 */
18
+ mapFn?: (item: T) => {
19
+ label: string;
20
+ value: string | number;
21
+ raw: T;
22
+ };
23
+ }
24
+ export interface AutoCompleteSearchReturn<T = any> {
25
+ /** 输入框绑定值 */
26
+ inputValue: Ref<string>;
27
+ /** 建议列表 */
28
+ suggestions: ShallowRef<Array<{
29
+ label: string;
30
+ value: string | number;
31
+ raw: T;
32
+ }>>;
33
+ /** 加载状态 */
34
+ loading: Ref<boolean>;
35
+ /** 当前选中的原始数据 */
36
+ selected: ShallowRef<T | null>;
37
+ /** 搜索回调,绑定给 KAutoComplete 的 onSearch / fetchSuggestions */
38
+ onSearch: (query: string) => Promise<void>;
39
+ /** 选中回调 */
40
+ onSelect: (item: {
41
+ label: string;
42
+ value: string | number;
43
+ raw: T;
44
+ }) => void;
45
+ /** 清空选中 */
46
+ onClear: () => void;
47
+ /** 手动设置选中值(用于表单回填) */
48
+ setValue: (label: string, data: T | null) => void;
49
+ }
50
+ export declare function useAutoCompleteSearch<T = any>(options: AutoCompleteSearchOptions<T>): AutoCompleteSearchReturn<T>;