@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.
Files changed (47) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +50 -2
  3. package/dist/index.js +1404 -0
  4. package/dist/style.css +1 -0
  5. package/dist/types/components/BaseCard/index.vue.d.ts +26 -0
  6. package/dist/types/components/DataTable/TableCell.vue.d.ts +14 -0
  7. package/dist/types/components/DataTable/index.vue.d.ts +53 -0
  8. package/dist/types/components/DataTable/types.d.ts +81 -0
  9. package/dist/types/components/Dialog/BaseDialog.vue.d.ts +141 -0
  10. package/dist/types/components/Dialog/index.d.ts +43 -0
  11. package/dist/types/components/Drawer/BaseDrawer.vue.d.ts +130 -0
  12. package/dist/types/components/Drawer/index.d.ts +1 -0
  13. package/dist/types/components/SearchForm/components/FormItem.vue.d.ts +35 -0
  14. package/dist/types/components/SearchForm/index.vue.d.ts +44 -0
  15. package/dist/types/components/SearchForm/types.d.ts +97 -0
  16. package/dist/types/components/SearchForm/values.d.ts +4 -0
  17. package/dist/types/hooks/useAsyncListAction.d.ts +7 -0
  18. package/dist/types/hooks/usePageList.d.ts +30 -0
  19. package/dist/types/hooks/useSelectOptions.d.ts +16 -0
  20. package/dist/types/index.d.ts +16 -0
  21. package/dist/types/types/admin.d.ts +3 -0
  22. package/dist/types/utils/adminCore.d.ts +74 -0
  23. package/dist/types/utils/data.d.ts +2 -0
  24. package/dist/types/utils/formRender.d.ts +2 -0
  25. package/dist/types/utils/tableRender.d.ts +7 -0
  26. package/docs/DataTable.md +23 -0
  27. package/docs/SearchForm.md +21 -0
  28. package/docs/usage.md +33 -0
  29. package/package.json +57 -4
  30. package/templates/manifest.json +82 -0
  31. package/templates/users/README.md +21 -0
  32. package/templates/users/api.ts +4 -0
  33. package/templates/users/components/AddExpireTime.vue +153 -0
  34. package/templates/users/components/MemberHistory.vue +33 -0
  35. package/templates/users/components/RenewalDiscount.vue +167 -0
  36. package/templates/users/config/columns.ts +45 -0
  37. package/templates/users/config/data.ts +22 -0
  38. package/templates/users/config/index.ts +3 -0
  39. package/templates/users/config/searchForm.ts +69 -0
  40. package/templates/users/constants.ts +22 -0
  41. package/templates/users/hooks/useRemoteResource.ts +34 -0
  42. package/templates/users/index.scss +41 -0
  43. package/templates/users/index.vue +273 -0
  44. package/templates/users/mock/index.ts +27 -0
  45. package/templates/users/mock/request.ts +32 -0
  46. package/templates/users/mock/store.ts +161 -0
  47. package/templates/users/types.ts +55 -0
@@ -0,0 +1,27 @@
1
+ import type { MemberAction, MemberFilters, PageQuery } from "../types";
2
+ import { createMemberStore } from "./store";
3
+ import { runDemo, type DemoOptions } from "./request";
4
+
5
+ /** 独立演示服务;无网络拦截、无真实地址,刷新浏览器后重新创建。 */
6
+ export function createUsersDemo(options: DemoOptions = {}) {
7
+ const store = createMemberStore();
8
+ return {
9
+ list(query: PageQuery & { filters: MemberFilters }, signal?: AbortSignal) {
10
+ const submitted = structuredClone(query);
11
+ return runDemo(() => store.list(submitted), options, signal);
12
+ },
13
+ options(
14
+ kind: "sites" | "countries" | "subscriptions",
15
+ signal?: AbortSignal,
16
+ ) {
17
+ return runDemo(() => store.options(kind), options, signal);
18
+ },
19
+ detail(uuid: string, signal?: AbortSignal) {
20
+ return runDemo(() => store.detail(uuid), options, signal);
21
+ },
22
+ action(uuid: string, action: MemberAction, signal?: AbortSignal) {
23
+ const submitted = structuredClone(action);
24
+ return runDemo(() => store.action(uuid, submitted), options, signal);
25
+ },
26
+ };
27
+ }
@@ -0,0 +1,32 @@
1
+ export interface DemoOptions {
2
+ delay?: number;
3
+ }
4
+
5
+ function wait(duration: number, signal?: AbortSignal) {
6
+ return new Promise<void>((resolve, reject) => {
7
+ if (signal?.aborted) {
8
+ reject(new DOMException("请求已取消", "AbortError"));
9
+ return;
10
+ }
11
+ const abort = () => {
12
+ clearTimeout(timer);
13
+ reject(new DOMException("请求已取消", "AbortError"));
14
+ };
15
+ const timer = setTimeout(() => {
16
+ signal?.removeEventListener("abort", abort);
17
+ resolve();
18
+ }, duration);
19
+ signal?.addEventListener("abort", abort, { once: true });
20
+ });
21
+ }
22
+
23
+ /** 模拟请求只在等待成功后执行,已取消的操作不会修改演示数据。 */
24
+ export async function runDemo<T>(
25
+ action: () => T,
26
+ options: DemoOptions,
27
+ signal?: AbortSignal,
28
+ ): Promise<T> {
29
+ await wait(options.delay ?? 0, signal);
30
+ if (signal?.aborted) throw new DOMException("请求已取消", "AbortError");
31
+ return action();
32
+ }
@@ -0,0 +1,161 @@
1
+ import type {
2
+ Member,
3
+ MemberAction,
4
+ MemberDetails,
5
+ MemberFilters,
6
+ PageQuery,
7
+ Option,
8
+ } from "../types";
9
+ import { countryOptions } from "../constants";
10
+ const stamp = (value: number) =>
11
+ new Date(value).toISOString().slice(0, 19).replace("T", " ");
12
+ const origin = Date.UTC(2026, 2, 31, 19, 1, 25);
13
+ const sites = [
14
+ { label: "星河站点", value: 1 },
15
+ { label: "青禾站点", value: 2 },
16
+ { label: "远山站点", value: 3 },
17
+ ];
18
+ const subscriptions = [
19
+ { label: "周订阅", value: 1 },
20
+ { label: "月订阅", value: 2 },
21
+ { label: "季订阅", value: 3 },
22
+ ];
23
+ function seedMembers(): Member[] {
24
+ return Array.from({ length: 86 }, (_, index) => ({
25
+ uuid: `USER-${String(index + 1).padStart(5, "0")}`,
26
+ member_email: `member${index + 1}@example.com`,
27
+ email: `subscriber${index + 1}@example.com`,
28
+ created_at: stamp(origin - index * 86400000),
29
+ country: countryOptions[index % countryOptions.length].value,
30
+ site: { id: sites[index % 3].value, site_name: sites[index % 3].label },
31
+ subscription_status: index % 4,
32
+ subscribe_type: (index % 3) + 1,
33
+ subscribe_cycle_type_text: subscriptions[index % 3].label,
34
+ subscription_expire_time: stamp(origin + (index + 1) * 86400000),
35
+ next_charge_time: stamp(origin + (index + 1) * 86400000),
36
+ ad_show_status: index % 2 ? 1 : 2,
37
+ mini_video_status: index % 2 ? 0 : 1,
38
+ ip_limited: index % 2 === 0,
39
+ }));
40
+ }
41
+
42
+ /** 每次创建拥有独立演示状态;返回副本,页面修改不影响服务。 */
43
+ export function createMemberStore() {
44
+ const members = seedMembers();
45
+ const details = new Map<string, MemberDetails>();
46
+ const detail = (uuid: string) => {
47
+ const member = members.find((row) => row.uuid === uuid);
48
+ if (!member) throw new Error("用户不存在");
49
+ if (!details.has(uuid))
50
+ details.set(uuid, { member, price: 19.99, discount: 100, history: [] });
51
+ return details.get(uuid)!;
52
+ };
53
+ function act(uuid: string, action: MemberAction) {
54
+ const current = detail(uuid),
55
+ member = current.member;
56
+ let description: string;
57
+ switch (action.type) {
58
+ case "duration":
59
+ if (
60
+ !Number.isInteger(action.day) ||
61
+ action.day < 1 ||
62
+ action.day > 3650 ||
63
+ ![0, 1].includes(action.timing)
64
+ )
65
+ throw new Error("请输入 1~3650 的整数天数");
66
+ if (action.timing === 0)
67
+ member.subscription_expire_time = stamp(
68
+ Date.parse(
69
+ member.subscription_expire_time.replace(" ", "T") + "Z",
70
+ ) +
71
+ action.day * 86400000,
72
+ );
73
+ description = `${action.timing ? "下次续订后" : "立即"}增加 ${action.day} 天`;
74
+ break;
75
+ case "discount":
76
+ if (
77
+ !Number.isInteger(action.discount) ||
78
+ action.discount < 1 ||
79
+ action.discount > 100 ||
80
+ !action.reason?.trim() ||
81
+ ![0, 1].includes(action.mode)
82
+ )
83
+ throw new Error("请输入 1~100 的整数折扣及原因");
84
+ current.discount = action.discount;
85
+ description = `${action.mode ? "永久" : "下次"}折扣 ${action.discount}%:${action.reason}`;
86
+ break;
87
+ case "ad":
88
+ if (![1, 2].includes(action.value)) throw new Error("广告状态无效");
89
+ member.ad_show_status = action.value;
90
+ description = action.value === 1 ? "关闭广告" : "打开广告";
91
+ break;
92
+ case "mini":
93
+ if (![0, 1].includes(action.value)) throw new Error("精简版状态无效");
94
+ member.mini_video_status = action.value;
95
+ description = action.value ? "开通精简版" : "关闭精简版";
96
+ break;
97
+ case "release-ip":
98
+ member.ip_limited = false;
99
+ description = "解除 IP 限制";
100
+ break;
101
+ default:
102
+ throw new Error("不支持的操作");
103
+ }
104
+ current.history.unshift({
105
+ id: `${uuid}-${current.history.length + 1}`,
106
+ created_at: stamp(Date.now()),
107
+ description,
108
+ });
109
+ return current;
110
+ }
111
+
112
+ return {
113
+ options(kind: "sites" | "countries" | "subscriptions"): Option[] {
114
+ return structuredClone(
115
+ { sites, countries: countryOptions, subscriptions }[kind],
116
+ );
117
+ },
118
+ list(query: PageQuery & { filters: MemberFilters }) {
119
+ if (
120
+ !Number.isInteger(query.page) ||
121
+ query.page < 1 ||
122
+ !Number.isInteger(query.page_size) ||
123
+ query.page_size < 1 ||
124
+ query.page_size > 100
125
+ )
126
+ throw new Error("分页参数无效");
127
+ const f = query.filters;
128
+ const text = f.search?.trim().toLowerCase();
129
+ const rows = members.filter(
130
+ (row) =>
131
+ (!text ||
132
+ [row.uuid, row.email, row.member_email].some((value) =>
133
+ value.toLowerCase().includes(text),
134
+ )) &&
135
+ (f.subscription_status == null ||
136
+ f.subscription_status === "" ||
137
+ row.subscription_status === f.subscription_status) &&
138
+ (!f.site_id?.length || f.site_id.includes(row.site.id)) &&
139
+ (!f.subscribe_type || row.subscribe_type === f.subscribe_type) &&
140
+ (!f.country_name || row.country === f.country_name) &&
141
+ (f.ad_show_status == null ||
142
+ f.ad_show_status === "" ||
143
+ row.ad_show_status === f.ad_show_status),
144
+ );
145
+
146
+ return structuredClone({
147
+ list: rows.slice(
148
+ (query.page - 1) * query.page_size,
149
+ query.page * query.page_size,
150
+ ),
151
+ total: rows.length,
152
+ });
153
+ },
154
+ detail(uuid: string) {
155
+ return structuredClone(detail(uuid));
156
+ },
157
+ action(uuid: string, action: MemberAction) {
158
+ return structuredClone(act(uuid, action));
159
+ },
160
+ };
161
+ }
@@ -0,0 +1,55 @@
1
+ /** 用户演示契约;真实项目按已有接口实现页面 API。 */
2
+ export interface PageQuery {
3
+ page: number;
4
+ page_size: number;
5
+ }
6
+ export interface PageResult<Row> {
7
+ list: Row[];
8
+ total: number;
9
+ }
10
+ export type Country = "HK" | "US" | "GB" | "JP" | "SG" | "TW";
11
+ export interface MemberFilters {
12
+ subscription_status?: number | "";
13
+ site_id?: (string | number)[];
14
+ subscribe_type?: string | number;
15
+ country_name?: string;
16
+ ad_show_status?: number | "";
17
+ search?: string;
18
+ }
19
+ export interface Member {
20
+ uuid: string;
21
+ member_email: string;
22
+ email: string;
23
+ created_at: string;
24
+ country: string;
25
+ site: { id: number; site_name: string };
26
+ subscription_status: number;
27
+ subscribe_type: number;
28
+ subscribe_cycle_type_text: string;
29
+ subscription_expire_time: string;
30
+ next_charge_time: string;
31
+ ad_show_status: 1 | 2;
32
+ mini_video_status: 0 | 1;
33
+ ip_limited: boolean;
34
+ }
35
+ export interface Option {
36
+ label: string;
37
+ value: string | number;
38
+ }
39
+ export interface History {
40
+ id: string;
41
+ created_at: string;
42
+ description: string;
43
+ }
44
+ export interface MemberDetails {
45
+ member: Member;
46
+ price: number;
47
+ discount: number;
48
+ history: History[];
49
+ }
50
+ export type MemberAction =
51
+ | { type: "duration"; day: number; timing: 0 | 1 }
52
+ | { type: "discount"; discount: number; mode: 0 | 1; reason: string }
53
+ | { type: "ad"; value: 1 | 2 }
54
+ | { type: "mini"; value: 0 | 1 }
55
+ | { type: "release-ip" };