@agent-xy/admin-vue3 0.0.0-stage → 0.2.0
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.
- package/LICENSE +21 -0
- package/README.md +50 -2
- package/dist/index.js +1404 -0
- package/dist/style.css +1 -0
- package/dist/types/components/BaseCard/index.vue.d.ts +26 -0
- package/dist/types/components/DataTable/TableCell.vue.d.ts +14 -0
- package/dist/types/components/DataTable/index.vue.d.ts +53 -0
- package/dist/types/components/DataTable/types.d.ts +81 -0
- package/dist/types/components/Dialog/BaseDialog.vue.d.ts +141 -0
- package/dist/types/components/Dialog/index.d.ts +43 -0
- package/dist/types/components/Drawer/BaseDrawer.vue.d.ts +130 -0
- package/dist/types/components/Drawer/index.d.ts +1 -0
- package/dist/types/components/SearchForm/components/FormItem.vue.d.ts +35 -0
- package/dist/types/components/SearchForm/index.vue.d.ts +44 -0
- package/dist/types/components/SearchForm/types.d.ts +97 -0
- package/dist/types/components/SearchForm/values.d.ts +4 -0
- package/dist/types/hooks/useAsyncListAction.d.ts +7 -0
- package/dist/types/hooks/usePageList.d.ts +30 -0
- package/dist/types/hooks/useSelectOptions.d.ts +16 -0
- package/dist/types/index.d.ts +16 -0
- package/dist/types/types/admin.d.ts +3 -0
- package/dist/types/utils/adminCore.d.ts +74 -0
- package/dist/types/utils/data.d.ts +2 -0
- package/dist/types/utils/formRender.d.ts +2 -0
- package/dist/types/utils/tableRender.d.ts +7 -0
- package/docs/DataTable.md +23 -0
- package/docs/SearchForm.md +21 -0
- package/docs/usage.md +33 -0
- package/package.json +57 -4
- package/templates/manifest.json +82 -0
- package/templates/users/README.md +21 -0
- package/templates/users/api.ts +4 -0
- package/templates/users/components/AddExpireTime.vue +153 -0
- package/templates/users/components/MemberHistory.vue +33 -0
- package/templates/users/components/RenewalDiscount.vue +167 -0
- package/templates/users/config/columns.ts +45 -0
- package/templates/users/config/data.ts +22 -0
- package/templates/users/config/index.ts +3 -0
- package/templates/users/config/searchForm.ts +69 -0
- package/templates/users/constants.ts +22 -0
- package/templates/users/hooks/useRemoteResource.ts +34 -0
- package/templates/users/index.scss +41 -0
- package/templates/users/index.vue +273 -0
- package/templates/users/mock/index.ts +27 -0
- package/templates/users/mock/request.ts +32 -0
- package/templates/users/mock/store.ts +161 -0
- package/templates/users/types.ts +55 -0
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare function useAsyncListAction(refresh?: () => void | Promise<unknown>): {
|
|
2
|
+
pendingKeys: import("vue").Ref<string[], string[]>;
|
|
3
|
+
activate: () => void;
|
|
4
|
+
dispose: () => void;
|
|
5
|
+
exec: <T>(task: (signal: AbortSignal) => Promise<T>, success?: string | ((result: T) => string | undefined | false), key?: string) => Promise<T>;
|
|
6
|
+
};
|
|
7
|
+
export { isAbortError } from "../utils/adminCore";
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { type Query, type PageResult, type ListOptions } from "../utils/adminCore";
|
|
2
|
+
export declare function usePageList<Q extends Query, Row, Result extends PageResult<Row> = PageResult<Row>>(queryForm: Q, options: ListOptions<Q, Row, Result>): {
|
|
3
|
+
state: import("vue").ShallowRef<import("..").ListState<Q, Row, Result>, import("..").ListState<Q, Row, Result>>;
|
|
4
|
+
result: import("vue").ComputedRef<Result | undefined>;
|
|
5
|
+
loading: import("vue").ComputedRef<boolean>;
|
|
6
|
+
error: import("vue").ComputedRef<unknown>;
|
|
7
|
+
tableData: import("vue").ComputedRef<Row[]>;
|
|
8
|
+
total: import("vue").ComputedRef<number>;
|
|
9
|
+
pageParams: import("vue").ComputedRef<{
|
|
10
|
+
currentPage: number;
|
|
11
|
+
pageSize: number;
|
|
12
|
+
pageSizes: number[];
|
|
13
|
+
total: number;
|
|
14
|
+
}>;
|
|
15
|
+
getSnapshot: () => import("..").ListState<Q, Row, Result>;
|
|
16
|
+
subscribe: (listener: () => void) => () => void;
|
|
17
|
+
setOptions: (next: ListOptions<Q, Row, Result>) => void;
|
|
18
|
+
activate: () => void;
|
|
19
|
+
dispose: () => void;
|
|
20
|
+
getData: () => Promise<Result | undefined>;
|
|
21
|
+
onSubmit: (form: Partial<Q>) => Promise<Result | undefined>;
|
|
22
|
+
handlePageChange: ({ pageNum }: {
|
|
23
|
+
pageNum: number;
|
|
24
|
+
}) => Promise<Result | undefined>;
|
|
25
|
+
handleSizeChange: ({ pageSize }: {
|
|
26
|
+
pageSize: number;
|
|
27
|
+
}) => Promise<Result | undefined>;
|
|
28
|
+
reset: () => Promise<Result | undefined>;
|
|
29
|
+
restorePagination: () => void;
|
|
30
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** 返回独立选项状态,由页面组合字段配置,不修改外部配置。 */
|
|
2
|
+
export declare function useSelectOptions<Row, Value extends string | number | boolean>(fetcher: (signal: AbortSignal) => Promise<Row[]>, map: (row: Row) => {
|
|
3
|
+
label: string;
|
|
4
|
+
value: Value;
|
|
5
|
+
}): {
|
|
6
|
+
options: import("vue").ShallowRef<{
|
|
7
|
+
label: string;
|
|
8
|
+
value: Value;
|
|
9
|
+
}[], {
|
|
10
|
+
label: string;
|
|
11
|
+
value: Value;
|
|
12
|
+
}[]>;
|
|
13
|
+
loading: import("vue").Ref<boolean, boolean>;
|
|
14
|
+
error: import("vue").ShallowRef<Error | null, Error | null>;
|
|
15
|
+
reload: () => Promise<void>;
|
|
16
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export { default as BaseCard } from './components/BaseCard/index.vue';
|
|
2
|
+
export { default as SearchForm } from './components/SearchForm/index.vue';
|
|
3
|
+
export { default as DataTable } from './components/DataTable/index.vue';
|
|
4
|
+
export { default as AdminDialog } from './components/Dialog';
|
|
5
|
+
export * from './components/Dialog';
|
|
6
|
+
export * from './components/Drawer';
|
|
7
|
+
export * from './hooks/usePageList';
|
|
8
|
+
export * from './hooks/useSelectOptions';
|
|
9
|
+
export * from './hooks/useAsyncListAction';
|
|
10
|
+
export * from './utils/formRender';
|
|
11
|
+
export * from './utils/tableRender';
|
|
12
|
+
export * from './utils/data';
|
|
13
|
+
export type * from './components/SearchForm/types';
|
|
14
|
+
export type * from './components/DataTable/types';
|
|
15
|
+
export type { Query, ListOptions, PageResult, ListState } from './utils/adminCore';
|
|
16
|
+
export type { TablePageParams as PaginationParams } from './components/DataTable/types';
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export type { SelectOption, Query, ListOptions, PageResult } from '../utils/adminCore';
|
|
2
|
+
export type { FormItemConfig, FormModel, SearchFormProps, SearchFormExpose } from '../components/SearchForm/types';
|
|
3
|
+
export type { TableColumn, TablePageParams as PaginationParams } from '../components/DataTable/types';
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/** 工具集内部状态逻辑。请求与业务响应转换由调用方提供。 */
|
|
2
|
+
export type Query = {
|
|
3
|
+
page?: number;
|
|
4
|
+
page_size?: number;
|
|
5
|
+
page_sizes?: number[];
|
|
6
|
+
total?: number;
|
|
7
|
+
};
|
|
8
|
+
export interface PageResult<Row> {
|
|
9
|
+
list: Row[];
|
|
10
|
+
total: number;
|
|
11
|
+
}
|
|
12
|
+
export interface ListOptions<Q extends Query, Row, Result extends PageResult<Row> = PageResult<Row>> {
|
|
13
|
+
initialQuery: Q;
|
|
14
|
+
fetchList: (query: Q, signal: AbortSignal) => Promise<Result>;
|
|
15
|
+
keepPrevious?: boolean;
|
|
16
|
+
persistKey?: string;
|
|
17
|
+
isRefreshData?: boolean;
|
|
18
|
+
onError?: (error: unknown) => void;
|
|
19
|
+
}
|
|
20
|
+
export interface ListState<Q, Row, Result = PageResult<Row>> {
|
|
21
|
+
result: Result | undefined;
|
|
22
|
+
query: Q;
|
|
23
|
+
tableData: Row[];
|
|
24
|
+
total: number;
|
|
25
|
+
loading: boolean;
|
|
26
|
+
error: unknown;
|
|
27
|
+
}
|
|
28
|
+
/** 克隆查询和配置的可变部分,保留回调;日期不转成字符串。 */
|
|
29
|
+
export declare function clone<T>(value: T): T;
|
|
30
|
+
export declare function createListController<Q extends Query, Row, Result extends PageResult<Row> = PageResult<Row>>(initialQuery: Q, initialOptions: ListOptions<Q, Row, Result>): {
|
|
31
|
+
getSnapshot: () => ListState<Q, Row, Result>;
|
|
32
|
+
subscribe: (listener: () => void) => () => void;
|
|
33
|
+
setOptions: (next: ListOptions<Q, Row, Result>) => void;
|
|
34
|
+
activate: () => void;
|
|
35
|
+
dispose: () => void;
|
|
36
|
+
pageParams: () => {
|
|
37
|
+
currentPage: number;
|
|
38
|
+
pageSize: number;
|
|
39
|
+
pageSizes: number[];
|
|
40
|
+
total: number;
|
|
41
|
+
};
|
|
42
|
+
getData: () => Promise<Result | undefined>;
|
|
43
|
+
onSubmit: (form: Partial<Q>) => Promise<Result | undefined>;
|
|
44
|
+
handlePageChange: ({ pageNum }: {
|
|
45
|
+
pageNum: number;
|
|
46
|
+
}) => Promise<Result | undefined>;
|
|
47
|
+
handleSizeChange: ({ pageSize }: {
|
|
48
|
+
pageSize: number;
|
|
49
|
+
}) => Promise<Result | undefined>;
|
|
50
|
+
reset: () => Promise<Result | undefined>;
|
|
51
|
+
restorePagination: () => void;
|
|
52
|
+
};
|
|
53
|
+
export interface SelectOption {
|
|
54
|
+
label: string;
|
|
55
|
+
value: string | number | boolean;
|
|
56
|
+
}
|
|
57
|
+
export interface FieldMap {
|
|
58
|
+
key: string;
|
|
59
|
+
value: string;
|
|
60
|
+
}
|
|
61
|
+
export declare function getFiltedOptions(raw: unknown[], map: FieldMap): SelectOption[];
|
|
62
|
+
export declare function createOptionsController(write: (field: string, options: SelectOption[]) => void): {
|
|
63
|
+
activate: () => void;
|
|
64
|
+
dispose: () => void;
|
|
65
|
+
setFieldOptions: (field: string, raw: unknown[], map: FieldMap) => void;
|
|
66
|
+
loadFieldOptions: (field: string, fetcher: () => Promise<unknown[]>, map: FieldMap) => Promise<void>;
|
|
67
|
+
};
|
|
68
|
+
/** 取消不作为业务失败展示,调用方可据此忽略过期操作。 */
|
|
69
|
+
export declare function isAbortError(error: unknown): boolean;
|
|
70
|
+
export declare function createActionController(refresh?: () => void | Promise<unknown>, notify?: (text: string) => void, onPending?: (keys: string[]) => void): {
|
|
71
|
+
activate: () => void;
|
|
72
|
+
dispose: () => void;
|
|
73
|
+
exec: <T>(task: (signal: AbortSignal) => Promise<T>, success?: string | ((result: T) => string | undefined | false), key?: string) => Promise<T>;
|
|
74
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { TableColumn } from '../components/DataTable/types';
|
|
2
|
+
export interface CopyFeedback {
|
|
3
|
+
onCopied?: () => void;
|
|
4
|
+
onCopyError?: (error: unknown) => void;
|
|
5
|
+
}
|
|
6
|
+
export declare function createRender<Row extends object>(column: TableColumn<Row>, feedback?: CopyFeedback): NonNullable<TableColumn<Row>['render']>;
|
|
7
|
+
export declare function buildColumns<Row extends object = Record<string, unknown>>(columns: TableColumn<Row>[], feedback?: CopyFeedback): TableColumn<Row>[];
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# DataTable
|
|
2
|
+
|
|
3
|
+
基于 Element Plus 的泛型表格。完整调用见 [用户管理模板](../templates/users/index.vue)。
|
|
4
|
+
|
|
5
|
+
| 属性 | 用途 |
|
|
6
|
+
| --- | --- |
|
|
7
|
+
| `tableData: Row[] / tableColumns: TableColumn<Row>[]` | 行数据与列配置;不在表格内部请求 |
|
|
8
|
+
| `rowKey` | 必填稳定行标识;字段名或返回字符串/数字的函数 |
|
|
9
|
+
| `pageParams` | `{ currentPage, pageSize, pageSizes?, total }`;也支持列表接口的 page/page_size 结构 |
|
|
10
|
+
| `showColumnSettings` | 独立工具栏列设置入口,默认开启 |
|
|
11
|
+
| `selection / reserveSelection` | 行选择及跨页保留 |
|
|
12
|
+
| `tableHeight / maxHeight / resizable` | 原生高度与列宽调整 |
|
|
13
|
+
| `showSerialNumber` | 按当前页计算序号,默认开启 |
|
|
14
|
+
|
|
15
|
+
列用 `prop` 标识、`label` 展示,支持 width/minWidth、fixed、align、group、sortable、formatter、render、tooltip、lineClamp。连续且固定方向一致的同名 group 合成分组表头。`hideable: false` 禁止隐藏;`showColumn` 表达初始或显式变化的显示配置。修改标题或重建相同配置不重置用户勾选。
|
|
16
|
+
|
|
17
|
+
单元格插槽按 prop 命名,接收 `{ row, column, index }`;表头使用 `header-${prop}` 插槽。渲染顺序为字段插槽 → render → formatter → 原值;空值不插入 HTML。多行省略按实际溢出测量显示提示,支持键盘聚焦。
|
|
18
|
+
|
|
19
|
+
`toolbar` 放刷新等操作,`multiple-operation` 接收 `selectionData`,`empty` 自定义空态。其他属性和原生事件透传 ElTable,class/style 放外层容器。
|
|
20
|
+
|
|
21
|
+
分页事件:`handle-current-change({ pageNum })`、`handle-size-change({ pageSize })`;修改每页数量时去重页码变化。其他事件:`handle-selection-change(rows)`、`handle-sort-change({ prop, order })`。
|
|
22
|
+
|
|
23
|
+
实例方法:clearSort、sort、doLayout、clearSelection、getSelectionRows、toggleRowSelection。组件外调用需要保存泛型实例类型 `TableExpose<Row>`。
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# SearchForm
|
|
2
|
+
|
|
3
|
+
配置式搜索表单,内部维护输入草稿。基础接入见 [技术栈 README](../README.md),完整页面见 [用户管理模板](../templates/users/index.vue)。
|
|
4
|
+
|
|
5
|
+
| 属性 | 用途 |
|
|
6
|
+
| -------------------------------------- | ------------------------------------------------------------ |
|
|
7
|
+
| `formHeader: FormItemConfig<Values>[]` | 字段与模型键、控件值类型关联 |
|
|
8
|
+
| `formModel?: Partial<Values>` | 初始输入与外部回填;对象替换覆盖草稿,原地变化只同步变化字段 |
|
|
9
|
+
| `loading / disabled` | 提交忙状态 / 禁用表单 |
|
|
10
|
+
| `showButton / isShowReset` | 默认操作按钮 / 重置按钮 |
|
|
11
|
+
| `labelPosition / labelWidth` | 标签布局 |
|
|
12
|
+
|
|
13
|
+
字段类型:`text`、`number`、`selectOne`(可配置 multiple)、`date`、`dateRange`、`datetimerange`、`inputBoxInterval`、`custom`。数字区间用 `propName1 / propName2`,其余用 `propName`。单选及多选支持字符串、数字、布尔值。日期默认输出字符串:单日期与日期范围为 `YYYY-MM-DD`,时间范围为 `YYYY-MM-DD HH:mm:ss`。`format` 控制展示,`valueFormat` 控制输出;字符串模型使用非空格式。若模型使用 `Date` 或 `Date[]`,必须显式设置 `valueFormat: ''`,并在接口边界转换。
|
|
14
|
+
|
|
15
|
+
`optionsArr`、远程加载与 `loading` 由页面提供,可通过 `useSelectOptions` 管理选项请求。控件扩展放 `controlProps`;值及更新事件由组件管理,不通过 controlProps 覆盖。`rules` 使用与 Element Plus 一致的 async-validator 规则,由字段管理校验序号,旧成功和旧失败都不能改写当前校验状态;没有 rules 时使用内置必填、区间完整性与数字区间顺序检查。
|
|
16
|
+
|
|
17
|
+
事件 `submit-form / reset-form / form-change` 都返回当前配置字段的独立快照。移除字段会清理其草稿与校验,新增字段按首次注册时模型值重置。回车和搜索按钮走同一次校验;规则或值变化使未完成校验失效。
|
|
18
|
+
|
|
19
|
+
字段插槽按 `slotName ?? propName` 匹配,接收 `{ form, item, value, updateValue, change }`。通过 `updateValue(value)` 或 `change(name, value)` 更新,不直接写 form。`actions` 插槽接收 `{ submit, reset, form, busy }`;`actions-extra` 放导出等页面操作。
|
|
20
|
+
|
|
21
|
+
实例方法:`submitForm(): Promise<boolean>`、`resetForm()`、`getFormData()`、`validate()`、`validateField()`、`clearValidate()`。提交事件本身不等待页面请求,页面使用 loading 管理请求状态。切换初始化实体时更换 key。
|
package/docs/usage.md
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# 弹层与列表逻辑
|
|
2
|
+
|
|
3
|
+
以下能力均通过 `@agent-xy/admin-vue3` 的公共导出使用。
|
|
4
|
+
|
|
5
|
+
## 列表逻辑
|
|
6
|
+
|
|
7
|
+
| 能力 | 入口与职责 | 状态约定 |
|
|
8
|
+
| --- | --- | --- |
|
|
9
|
+
| `usePageList(query, options)` | 注入 `fetchList(query, signal)`;搜索 `onSubmit`、重置 `reset`、刷新 `getData`、分页 `handlePageChange` / `handleSizeChange` | 返回 `tableData`、`total`、完整 `result`、`loading`、`error` 和 `pageParams`;过期响应不覆盖新查询 |
|
|
10
|
+
| `useSelectOptions(fetcher, map)` | 项目请求选项并转换为 `{ label, value }` | 挂载加载,独立 `loading`、`error`、`reload`;卸载取消 |
|
|
11
|
+
| `useAsyncListAction(refresh?)` | `exec(signal => operation(signal), successMessage?, key?)` | 同键操作去重,成功后刷新;失败拒绝;卸载取消 |
|
|
12
|
+
|
|
13
|
+
`usePageList` 不自动发起首次请求,由页面明确调用。`fetchList` 返回 `{ list, total }` 或包含额外统计的扩展结果。查询参数原始值与嵌套条件通过 `initialQuery` 提供。
|
|
14
|
+
|
|
15
|
+
搜索组件维护草稿;页面提交时整体替换 `filters`,翻页使用已提交条件。请求失败通过 `error` 展示,不回退演示数据。取消错误可通过 `isAbortError` 判断。
|
|
16
|
+
|
|
17
|
+
[用户管理模板](../templates/users/index.vue) 展示默认演示数据、搜索分页、订阅操作和历史记录;真实接口集中在页面 `api.ts` 接入。模板中的展示模型可以修改,不作为后端接口契约。
|
|
18
|
+
|
|
19
|
+
## 弹层
|
|
20
|
+
|
|
21
|
+
声明式 `BaseDialog`、`BaseDrawer` 使用 `v-model` 控制可见性,不需要安装弹窗插件。确认操作通过 `onConfirm` 接收可等待的回调;失败拒绝 Promise,弹层保留输入并展示错误。
|
|
22
|
+
|
|
23
|
+
`BaseDialog` 默认 `closeOnConfirm: true`,可以设置为 `false`,在保存成功后保持打开。`confirmDisabled` 禁用确认;组件实例的 `confirm()` 与确认按钮共用校验及重复操作保护。
|
|
24
|
+
|
|
25
|
+
函数式弹窗可选择 `app.use(AdminDialog)` 后使用 `Dialog` / `showDialog`。多个 Vue 应用或需要显式管理宿主上下文时,使用 `createDialogService(appContext)`,在宿主退出时调用返回的 `dispose()`。
|
|
26
|
+
|
|
27
|
+
`Dialog.confirm` 返回 `Promise<boolean>`;关闭或释放实例时以 `false` 结束。首版没有函数式抽屉。
|
|
28
|
+
|
|
29
|
+
## 配置辅助
|
|
30
|
+
|
|
31
|
+
`buildFormItems` 和 `buildColumns` 是可选辅助函数,不要求额外包装。列辅助支持枚举、嵌套字段和复制入口,保留调用方的 `render` / `formatter`。
|
|
32
|
+
|
|
33
|
+
通过 `CopyFeedback` 的 `onCopied`、`onCopyError` 接入项目提示方式。默认值仅填补缺失值,保留 `0`、`false` 和空字符串。
|
package/package.json
CHANGED
|
@@ -1,6 +1,59 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agent-xy/admin-vue3",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Vue 3 管理后台组件、类型与页面起点",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"engines": {
|
|
8
|
+
"node": ">=18"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"dist",
|
|
12
|
+
"templates",
|
|
13
|
+
"docs",
|
|
14
|
+
"README.md",
|
|
15
|
+
"LICENSE"
|
|
16
|
+
],
|
|
17
|
+
"main": "./dist/index.js",
|
|
18
|
+
"module": "./dist/index.js",
|
|
19
|
+
"types": "./dist/types/index.d.ts",
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"types": "./dist/types/index.d.ts",
|
|
23
|
+
"import": "./dist/index.js"
|
|
24
|
+
},
|
|
25
|
+
"./style.css": "./dist/style.css",
|
|
26
|
+
"./package.json": "./package.json",
|
|
27
|
+
"./templates/manifest.json": "./templates/manifest.json",
|
|
28
|
+
"./docs/*": "./docs/*",
|
|
29
|
+
"./README.md": "./README.md"
|
|
30
|
+
},
|
|
31
|
+
"sideEffects": [
|
|
32
|
+
"**/*.css"
|
|
33
|
+
],
|
|
34
|
+
"scripts": {
|
|
35
|
+
"prebuild": "cd ../.. && node scripts/build-admin.mjs",
|
|
36
|
+
"build": "vite build && vue-tsc -p tsconfig.build.json && node ../../scripts/clean-admin-types.mjs",
|
|
37
|
+
"typecheck": "vue-tsc --noEmit -p tsconfig.json",
|
|
38
|
+
"dev": "vite --config vite.demo.config.ts",
|
|
39
|
+
"build:demo": "vue-tsc --noEmit -p tsconfig.demo.json && vite build --config vite.demo.config.ts"
|
|
40
|
+
},
|
|
41
|
+
"peerDependencies": {
|
|
42
|
+
"vue": "^3.5.25",
|
|
43
|
+
"element-plus": "^2.11.5"
|
|
44
|
+
},
|
|
45
|
+
"dependencies": {
|
|
46
|
+
"async-validator": "4.2.5"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"vue": "3.5.25",
|
|
50
|
+
"element-plus": "2.11.5",
|
|
51
|
+
"@vitejs/plugin-vue": "5.2.4",
|
|
52
|
+
"vite": "5.4.21",
|
|
53
|
+
"vue-tsc": "2.2.12",
|
|
54
|
+
"typescript": "5.9.3",
|
|
55
|
+
"sass": "1.93.2",
|
|
56
|
+
"@types/node": "20.17.24",
|
|
57
|
+
"jsdom": "24.1.3"
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
{
|
|
2
|
+
"schemaVersion": 1,
|
|
3
|
+
"framework": "vue3",
|
|
4
|
+
"package": "@agent-xy/admin-vue3",
|
|
5
|
+
"style": "@agent-xy/admin-vue3/style.css",
|
|
6
|
+
"documentation": "@agent-xy/admin-vue3/README.md",
|
|
7
|
+
"capabilities": [
|
|
8
|
+
{
|
|
9
|
+
"name": "布局",
|
|
10
|
+
"exports": [
|
|
11
|
+
"BaseCard"
|
|
12
|
+
],
|
|
13
|
+
"purpose": "页面区块布局"
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
"name": "搜索",
|
|
17
|
+
"exports": [
|
|
18
|
+
"SearchForm",
|
|
19
|
+
"buildFormItems"
|
|
20
|
+
],
|
|
21
|
+
"purpose": "搜索项配置、提交和重置"
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"name": "表格",
|
|
25
|
+
"exports": [
|
|
26
|
+
"DataTable",
|
|
27
|
+
"buildColumns"
|
|
28
|
+
],
|
|
29
|
+
"purpose": "列、分页与操作插槽"
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
"name": "弹层",
|
|
33
|
+
"exports": [
|
|
34
|
+
"BaseDialog",
|
|
35
|
+
"BaseDrawer",
|
|
36
|
+
"AdminDialog",
|
|
37
|
+
"createDialogService"
|
|
38
|
+
],
|
|
39
|
+
"purpose": "声明式弹层与可等待的确认"
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"name": "列表逻辑",
|
|
43
|
+
"exports": [
|
|
44
|
+
"usePageList",
|
|
45
|
+
"useSelectOptions",
|
|
46
|
+
"useAsyncListAction"
|
|
47
|
+
],
|
|
48
|
+
"purpose": "由项目注入请求,处理查询、选项和异步操作"
|
|
49
|
+
}
|
|
50
|
+
],
|
|
51
|
+
"links": {},
|
|
52
|
+
"templates": {
|
|
53
|
+
"users": {
|
|
54
|
+
"title": "用户管理",
|
|
55
|
+
"root": "templates/users",
|
|
56
|
+
"entry": "index.vue",
|
|
57
|
+
"files": [
|
|
58
|
+
"README.md",
|
|
59
|
+
"api.ts",
|
|
60
|
+
"components/AddExpireTime.vue",
|
|
61
|
+
"components/MemberHistory.vue",
|
|
62
|
+
"components/RenewalDiscount.vue",
|
|
63
|
+
"config/columns.ts",
|
|
64
|
+
"config/data.ts",
|
|
65
|
+
"config/index.ts",
|
|
66
|
+
"config/searchForm.ts",
|
|
67
|
+
"constants.ts",
|
|
68
|
+
"hooks/useRemoteResource.ts",
|
|
69
|
+
"index.scss",
|
|
70
|
+
"index.vue",
|
|
71
|
+
"mock/index.ts",
|
|
72
|
+
"mock/request.ts",
|
|
73
|
+
"mock/store.ts",
|
|
74
|
+
"types.ts"
|
|
75
|
+
],
|
|
76
|
+
"description": "用户管理页面,默认使用本地 API;参考筛选、分页、订阅操作、弹窗校验与历史记录,真实接口在页面 API 入口接入",
|
|
77
|
+
"devDependencies": {
|
|
78
|
+
"sass": "~1.93.2"
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# 用户管理页面
|
|
2
|
+
|
|
3
|
+
入口:`index.vue`。生成后由业务项目维护;组件升级和规则同步不覆盖页面。
|
|
4
|
+
|
|
5
|
+
## 页面能力
|
|
6
|
+
|
|
7
|
+
多条件筛选、异步选项、分页、广告及精简版状态切换、增加订阅时长、续费折扣与历史记录。
|
|
8
|
+
|
|
9
|
+
## 数据接入
|
|
10
|
+
|
|
11
|
+
`api.ts` 默认连接本目录的本地实现,可直接查看和操作。数据保存在内存,刷新浏览器后重新初始化;这项说明仅面向开发者。接真实业务时在此调用项目请求层,保留页面方法签名、取消信号和错误传播,不在请求失败后回退本地数据。接口地址、字段和权限以消费项目为准。
|
|
12
|
+
|
|
13
|
+
## 请求与反馈
|
|
14
|
+
|
|
15
|
+
加载使用控件状态;失败通过消息提示,列表可搜索或刷新,选项可重新展开,详情可重新打开。字段校验就地展示;提交失败保留输入,保存成功后刷新失败单独反馈。若宿主请求层已经统一提示错误,应在接入时统一提示归属,避免再次提示。
|
|
16
|
+
|
|
17
|
+
失败和慢请求由仓库验证脚本替换 API 方法注入,页面不导出测试开关。
|
|
18
|
+
|
|
19
|
+
## 接入项目
|
|
20
|
+
|
|
21
|
+
使用 Vue 3 与 Element Plus。页面样式统一使用 SCSS。通过 CLI 生成时按清单补齐 `sass` 开发依赖;手动复制页面时请确保项目已安装 Sass(`npm install -D sass@~1.93.2`),并已配置 SCSS 编译支持。生成不自动注册路由或修改权限。
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<BaseDialog
|
|
3
|
+
ref="dialog"
|
|
4
|
+
:model-value="true"
|
|
5
|
+
title="增加订阅时长"
|
|
6
|
+
width="900px"
|
|
7
|
+
confirm-text="提交"
|
|
8
|
+
cancel-text="返回"
|
|
9
|
+
:close-on-confirm="false"
|
|
10
|
+
:confirm-disabled="!data || loading"
|
|
11
|
+
:on-confirm="submit"
|
|
12
|
+
@update:model-value="handleOpenChange"
|
|
13
|
+
>
|
|
14
|
+
<p>UID:{{ uuid }}</p>
|
|
15
|
+
<div @submit.capture.prevent.stop="dialog?.confirm()">
|
|
16
|
+
<ElForm
|
|
17
|
+
v-if="formReady"
|
|
18
|
+
ref="form"
|
|
19
|
+
:model="values"
|
|
20
|
+
label-position="top"
|
|
21
|
+
:disabled="pendingKeys.length > 0 || loading || !data"
|
|
22
|
+
>
|
|
23
|
+
<ElFormItem label="增加方式" prop="timing" :rules="[{ required: true }]"
|
|
24
|
+
><ElSelect
|
|
25
|
+
v-model="values.timing"
|
|
26
|
+
v-bind="{ 'aria-label': '增加方式' }"
|
|
27
|
+
><ElOption
|
|
28
|
+
v-for="option in timingOptions"
|
|
29
|
+
:key="option.value"
|
|
30
|
+
v-bind="option" /></ElSelect
|
|
31
|
+
></ElFormItem>
|
|
32
|
+
<ElFormItem
|
|
33
|
+
label="增加天数"
|
|
34
|
+
prop="day"
|
|
35
|
+
:rules="[
|
|
36
|
+
{
|
|
37
|
+
required: true,
|
|
38
|
+
type: 'integer',
|
|
39
|
+
min: 1,
|
|
40
|
+
max: 3650,
|
|
41
|
+
message: '请输入 1~3650 的整数天数',
|
|
42
|
+
},
|
|
43
|
+
]"
|
|
44
|
+
><ElInputNumber
|
|
45
|
+
ref="input"
|
|
46
|
+
v-model="values.day"
|
|
47
|
+
:min="1"
|
|
48
|
+
:max="3650"
|
|
49
|
+
:precision="0"
|
|
50
|
+
v-bind="{ 'aria-label': '增加天数' }"
|
|
51
|
+
/></ElFormItem>
|
|
52
|
+
<!-- 原生表单回车与底部按钮共用弹窗确认入口。 -->
|
|
53
|
+
<button type="submit" hidden tabindex="-1" aria-hidden="true" />
|
|
54
|
+
</ElForm>
|
|
55
|
+
</div>
|
|
56
|
+
<MemberHistory :details="data" :loading="loading" />
|
|
57
|
+
</BaseDialog>
|
|
58
|
+
</template>
|
|
59
|
+
<script setup lang="ts">
|
|
60
|
+
import { nextTick, reactive, ref, watch } from "vue";
|
|
61
|
+
import {
|
|
62
|
+
ElMessage,
|
|
63
|
+
ElForm,
|
|
64
|
+
ElFormItem,
|
|
65
|
+
ElInputNumber,
|
|
66
|
+
ElOption,
|
|
67
|
+
ElSelect,
|
|
68
|
+
type FormInstance,
|
|
69
|
+
type InputNumberInstance,
|
|
70
|
+
} from "element-plus";
|
|
71
|
+
import {
|
|
72
|
+
BaseDialog,
|
|
73
|
+
useAsyncListAction,
|
|
74
|
+
isAbortError,
|
|
75
|
+
} from "@agent-xy/admin-vue3";
|
|
76
|
+
|
|
77
|
+
import { useRemoteResource } from "../hooks/useRemoteResource";
|
|
78
|
+
import { api } from "../api";
|
|
79
|
+
import { timingOptions } from "../config";
|
|
80
|
+
import MemberHistory from "./MemberHistory.vue";
|
|
81
|
+
const props = defineProps<{
|
|
82
|
+
uuid: string;
|
|
83
|
+
onRefresh: () => void | Promise<unknown>;
|
|
84
|
+
}>();
|
|
85
|
+
const emit = defineEmits<{ close: [] }>();
|
|
86
|
+
const form = ref<FormInstance>(),
|
|
87
|
+
dialog = ref<InstanceType<typeof BaseDialog>>();
|
|
88
|
+
const values = reactive<{ timing: 0 | 1; day?: number }>({ timing: 0 });
|
|
89
|
+
const { data, loading, error, reload } = useRemoteResource((signal) =>
|
|
90
|
+
api.members.detail(props.uuid, signal),
|
|
91
|
+
);
|
|
92
|
+
watch(error, (reason) => {
|
|
93
|
+
if (!reason) return;
|
|
94
|
+
ElMessage.error(
|
|
95
|
+
data.value ? "操作已成功,用户信息刷新失败" : "用户信息加载失败",
|
|
96
|
+
);
|
|
97
|
+
if (!data.value) emit("close");
|
|
98
|
+
});
|
|
99
|
+
// 详情就绪后初始化表单;刷新时保留同一实例,避免丢失草稿与重置基线。
|
|
100
|
+
const formReady = ref(false);
|
|
101
|
+
watch([data, loading], ([details, busy]) => {
|
|
102
|
+
if (details && !busy) formReady.value = true;
|
|
103
|
+
});
|
|
104
|
+
const { exec, pendingKeys } = useAsyncListAction(async () => {
|
|
105
|
+
await reload();
|
|
106
|
+
try {
|
|
107
|
+
await props.onRefresh();
|
|
108
|
+
} catch (reason) {
|
|
109
|
+
if (!isAbortError(reason)) ElMessage.error("操作已成功,列表刷新失败");
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
const input = ref<InputNumberInstance>();
|
|
113
|
+
let restoreInputFocus = false;
|
|
114
|
+
watch(
|
|
115
|
+
[loading, () => pendingKeys.value.length],
|
|
116
|
+
async ([busy, pending]) => {
|
|
117
|
+
if (!restoreInputFocus || busy || pending) return;
|
|
118
|
+
await nextTick();
|
|
119
|
+
input.value?.focus();
|
|
120
|
+
restoreInputFocus = false;
|
|
121
|
+
},
|
|
122
|
+
{ flush: "post" },
|
|
123
|
+
);
|
|
124
|
+
function handleOpenChange(open: boolean) {
|
|
125
|
+
if (!open) emit("close");
|
|
126
|
+
}
|
|
127
|
+
async function submit() {
|
|
128
|
+
if (!form.value) return;
|
|
129
|
+
try {
|
|
130
|
+
await form.value.validate();
|
|
131
|
+
} catch {
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
// 提交时禁用控件可能失焦,成功或失败后都恢复键盘入口。
|
|
135
|
+
restoreInputFocus = true;
|
|
136
|
+
try {
|
|
137
|
+
await exec(
|
|
138
|
+
(signal) =>
|
|
139
|
+
api.members.action(
|
|
140
|
+
props.uuid,
|
|
141
|
+
{ type: "duration", day: values.day!, timing: values.timing },
|
|
142
|
+
signal,
|
|
143
|
+
),
|
|
144
|
+
"操作成功",
|
|
145
|
+
props.uuid,
|
|
146
|
+
);
|
|
147
|
+
} catch (reason) {
|
|
148
|
+
if (!isAbortError(reason)) ElMessage.error("提交失败");
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
form.value?.resetFields();
|
|
152
|
+
}
|
|
153
|
+
</script>
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<ElDescriptions v-if="details">
|
|
3
|
+
<ElDescriptionsItem label="到期时间">{{
|
|
4
|
+
details.member.subscription_expire_time
|
|
5
|
+
}}</ElDescriptionsItem>
|
|
6
|
+
<ElDescriptionsItem label="当前价格">{{
|
|
7
|
+
details.price
|
|
8
|
+
}}</ElDescriptionsItem>
|
|
9
|
+
<ElDescriptionsItem label="当前折扣"
|
|
10
|
+
>{{ details.discount }}%</ElDescriptionsItem
|
|
11
|
+
>
|
|
12
|
+
</ElDescriptions>
|
|
13
|
+
<DataTable
|
|
14
|
+
row-key="id"
|
|
15
|
+
:table-columns="columns"
|
|
16
|
+
:table-data="details?.history ?? []"
|
|
17
|
+
:loading="loading"
|
|
18
|
+
:show-column-settings="false"
|
|
19
|
+
:show-serial-number="false"
|
|
20
|
+
table-height="220"
|
|
21
|
+
/>
|
|
22
|
+
</template>
|
|
23
|
+
<script setup lang="ts">
|
|
24
|
+
import { ElDescriptions, ElDescriptionsItem } from "element-plus";
|
|
25
|
+
import { DataTable, buildColumns } from "@agent-xy/admin-vue3";
|
|
26
|
+
|
|
27
|
+
import type { History, MemberDetails } from "../types";
|
|
28
|
+
defineProps<{ details?: MemberDetails; loading: boolean }>();
|
|
29
|
+
const columns = buildColumns<History>([
|
|
30
|
+
{ prop: "created_at", label: "操作时间", width: 180 },
|
|
31
|
+
{ prop: "description", label: "操作记录" },
|
|
32
|
+
]);
|
|
33
|
+
</script>
|