@agent-xy/admin-vue3 0.1.0 → 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/README.md +13 -6
- package/dist/types/components/SearchForm/index.vue.d.ts +0 -1
- package/docs/usage.md +1 -1
- package/package.json +26 -8
- package/templates/manifest.json +65 -6
- package/templates/users/README.md +17 -8
- 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 +268 -16
- 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 +52 -10
- package/templates/users/UsersList.vue +0 -73
- package/templates/users/config.ts +0 -12
- package/templates/users/data-source.ts +0 -5
- package/templates/users/style.css +0 -5
package/README.md
CHANGED
|
@@ -13,12 +13,15 @@ npm install @agent-xy/admin-vue3
|
|
|
13
13
|
<DataTable row-key="id" :table-data="rows" :table-columns="columns" />
|
|
14
14
|
</template>
|
|
15
15
|
<script setup lang="ts">
|
|
16
|
-
import { DataTable, type TableColumn } from
|
|
17
|
-
import
|
|
18
|
-
import
|
|
19
|
-
interface Row {
|
|
16
|
+
import { DataTable, type TableColumn } from "@agent-xy/admin-vue3";
|
|
17
|
+
import "element-plus/dist/index.css";
|
|
18
|
+
import "@agent-xy/admin-vue3/style.css";
|
|
19
|
+
interface Row {
|
|
20
|
+
id: string;
|
|
21
|
+
name: string;
|
|
22
|
+
}
|
|
20
23
|
defineProps<{ rows: Row[] }>();
|
|
21
|
-
const columns: TableColumn<Row>[] = [{ prop:
|
|
24
|
+
const columns: TableColumn<Row>[] = [{ prop: "name", label: "姓名" }];
|
|
22
25
|
</script>
|
|
23
26
|
```
|
|
24
27
|
|
|
@@ -31,7 +34,7 @@ const columns: TableColumn<Row>[] = [{ prop: 'name', label: '姓名' }];
|
|
|
31
34
|
|
|
32
35
|
`AdminDialog` 是可选的 Vue 插件,提供全局函数式弹窗;声明式 BaseDialog 不需要安装插件。需要多个应用隔离时使用 `createDialogService(appContext)`。
|
|
33
36
|
|
|
34
|
-
|
|
37
|
+
页面模板默认提供完整筛选、订阅操作和历史记录及可操作的本地演示数据,无须填写数据源。页面 API 入口在 `templates/users/api.ts`。页面模板跟随当前包版本分发,通过公开的 `templates/manifest.json` 入口发现。模板生成后归项目维护;用户自行注册路由、接入请求和权限。组件实现不复制到业务目录。
|
|
35
38
|
|
|
36
39
|
开发维护在本仓库的 `packages/admin-vue3/src`,共享纯逻辑维护在 `content/templates/admin/shared/adminCore.ts`。旧复制资源由 `scripts/build-admin.mjs` 派生,不能反向修改。先构建组件包,再启动或构建示例;示例通过包导入消费构建产物,不使用源码别名。
|
|
37
40
|
|
|
@@ -42,3 +45,7 @@ npm run build:demo --workspace @agent-xy/admin-vue3
|
|
|
42
45
|
```
|
|
43
46
|
|
|
44
47
|
当前交付以本地打包验收,尚未公开发布,也没有配置线上演示地址。
|
|
48
|
+
|
|
49
|
+
仓库根目录执行 `npm run pack:local`,再通过 `ai-code add components --package /path/to/artifacts/agent-xy-admin-vue3-0.1.0.tgz --template users --target src/views/users-v2` 使用本轮页面。默认命令复用已安装包;更新 CLI 或本仓库文件不会更新消费项目中的旧组件包,也不会覆盖已生成页面。
|
|
50
|
+
|
|
51
|
+
组件与页面样式源码统一使用 SCSS,包的样式入口是编译后的 CSS。仅使用组件包无需 Sass;CLI 生成页面时补齐 `sass` 开发依赖,手动复制模板时请配置 Sass。
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { FormModel, RuntimeFormItem, SearchFormProps } from './types';
|
|
2
|
-
import './style.scss';
|
|
3
2
|
declare const _default: <Values extends object>(__VLS_props: NonNullable<Awaited<typeof __VLS_setup>>["props"], __VLS_ctx?: __VLS_PrettifyLocal<Pick<NonNullable<Awaited<typeof __VLS_setup>>, "attrs" | "emit" | "slots">>, __VLS_expose?: NonNullable<Awaited<typeof __VLS_setup>>["expose"], __VLS_setup?: Promise<{
|
|
4
3
|
props: __VLS_PrettifyLocal<Pick<Partial<{}> & Omit<{
|
|
5
4
|
readonly onSubmitForm?: ((values: Partial<Values>) => any) | undefined;
|
package/docs/usage.md
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
|
|
15
15
|
搜索组件维护草稿;页面提交时整体替换 `filters`,翻页使用已提交条件。请求失败通过 `error` 展示,不回退演示数据。取消错误可通过 `isAbortError` 判断。
|
|
16
16
|
|
|
17
|
-
[用户管理模板](../templates/users/index.vue)
|
|
17
|
+
[用户管理模板](../templates/users/index.vue) 展示默认演示数据、搜索分页、订阅操作和历史记录;真实接口集中在页面 `api.ts` 接入。模板中的展示模型可以修改,不作为后端接口契约。
|
|
18
18
|
|
|
19
19
|
## 弹层
|
|
20
20
|
|
package/package.json
CHANGED
|
@@ -1,32 +1,50 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agent-xy/admin-vue3",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Vue 3 管理后台组件、类型与页面起点",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
|
-
"engines": {
|
|
8
|
-
|
|
7
|
+
"engines": {
|
|
8
|
+
"node": ">=18"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"dist",
|
|
12
|
+
"templates",
|
|
13
|
+
"docs",
|
|
14
|
+
"README.md",
|
|
15
|
+
"LICENSE"
|
|
16
|
+
],
|
|
9
17
|
"main": "./dist/index.js",
|
|
10
18
|
"module": "./dist/index.js",
|
|
11
19
|
"types": "./dist/types/index.d.ts",
|
|
12
20
|
"exports": {
|
|
13
|
-
".": {
|
|
21
|
+
".": {
|
|
22
|
+
"types": "./dist/types/index.d.ts",
|
|
23
|
+
"import": "./dist/index.js"
|
|
24
|
+
},
|
|
14
25
|
"./style.css": "./dist/style.css",
|
|
15
26
|
"./package.json": "./package.json",
|
|
16
27
|
"./templates/manifest.json": "./templates/manifest.json",
|
|
17
28
|
"./docs/*": "./docs/*",
|
|
18
29
|
"./README.md": "./README.md"
|
|
19
30
|
},
|
|
20
|
-
"sideEffects": [
|
|
31
|
+
"sideEffects": [
|
|
32
|
+
"**/*.css"
|
|
33
|
+
],
|
|
21
34
|
"scripts": {
|
|
22
35
|
"prebuild": "cd ../.. && node scripts/build-admin.mjs",
|
|
23
|
-
"build": "vite build && vue-tsc -p tsconfig.build.json",
|
|
36
|
+
"build": "vite build && vue-tsc -p tsconfig.build.json && node ../../scripts/clean-admin-types.mjs",
|
|
24
37
|
"typecheck": "vue-tsc --noEmit -p tsconfig.json",
|
|
25
38
|
"dev": "vite --config vite.demo.config.ts",
|
|
26
39
|
"build:demo": "vue-tsc --noEmit -p tsconfig.demo.json && vite build --config vite.demo.config.ts"
|
|
27
40
|
},
|
|
28
|
-
"peerDependencies": {
|
|
29
|
-
|
|
41
|
+
"peerDependencies": {
|
|
42
|
+
"vue": "^3.5.25",
|
|
43
|
+
"element-plus": "^2.11.5"
|
|
44
|
+
},
|
|
45
|
+
"dependencies": {
|
|
46
|
+
"async-validator": "4.2.5"
|
|
47
|
+
},
|
|
30
48
|
"devDependencies": {
|
|
31
49
|
"vue": "3.5.25",
|
|
32
50
|
"element-plus": "2.11.5",
|
package/templates/manifest.json
CHANGED
|
@@ -5,11 +5,48 @@
|
|
|
5
5
|
"style": "@agent-xy/admin-vue3/style.css",
|
|
6
6
|
"documentation": "@agent-xy/admin-vue3/README.md",
|
|
7
7
|
"capabilities": [
|
|
8
|
-
{
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
+
}
|
|
13
50
|
],
|
|
14
51
|
"links": {},
|
|
15
52
|
"templates": {
|
|
@@ -17,7 +54,29 @@
|
|
|
17
54
|
"title": "用户管理",
|
|
18
55
|
"root": "templates/users",
|
|
19
56
|
"entry": "index.vue",
|
|
20
|
-
"files": [
|
|
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
|
+
}
|
|
21
80
|
}
|
|
22
81
|
}
|
|
23
82
|
}
|
|
@@ -1,12 +1,21 @@
|
|
|
1
|
-
#
|
|
1
|
+
# 用户管理页面
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
入口:`index.vue`。生成后由业务项目维护;组件升级和规则同步不覆盖页面。
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
2. 在 `data-source.ts` 实现 `UsersDataSource`,接入现有请求层并传递取消信号。`types.ts` 是页面展示模型,不代表后端接口。
|
|
7
|
-
3. 列表响应映射为 `{ list, total }`。接口失败应拒绝 Promise,不返回演示数据。
|
|
8
|
-
4. 根据项目修改 `config.ts` 的搜索项和列,以及 `UsersList.vue` 的操作区。权限和业务操作由页面负责。
|
|
5
|
+
## 页面能力
|
|
9
6
|
|
|
10
|
-
|
|
7
|
+
多条件筛选、异步选项、分页、广告及精简版状态切换、增加订阅时长、续费折扣与历史记录。
|
|
11
8
|
|
|
12
|
-
|
|
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>
|
|
@@ -0,0 +1,167 @@
|
|
|
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="mode" :rules="[{ required: true }]"
|
|
24
|
+
><ElSelect v-model="values.mode" v-bind="{ 'aria-label': '折扣模式' }"
|
|
25
|
+
><ElOption
|
|
26
|
+
v-for="option in discountModeOptions"
|
|
27
|
+
:key="option.value"
|
|
28
|
+
v-bind="option" /></ElSelect
|
|
29
|
+
></ElFormItem>
|
|
30
|
+
<ElFormItem
|
|
31
|
+
label="折扣(%)"
|
|
32
|
+
prop="discount"
|
|
33
|
+
:rules="[
|
|
34
|
+
{
|
|
35
|
+
required: true,
|
|
36
|
+
type: 'integer',
|
|
37
|
+
min: 1,
|
|
38
|
+
max: 100,
|
|
39
|
+
message: '请输入 1~100 的整数折扣',
|
|
40
|
+
},
|
|
41
|
+
]"
|
|
42
|
+
><ElInputNumber
|
|
43
|
+
v-model="values.discount"
|
|
44
|
+
:min="1"
|
|
45
|
+
:max="100"
|
|
46
|
+
:precision="0"
|
|
47
|
+
v-bind="{ 'aria-label': '折扣(%)' }"
|
|
48
|
+
/></ElFormItem>
|
|
49
|
+
<ElFormItem
|
|
50
|
+
label="折扣原因"
|
|
51
|
+
prop="reason"
|
|
52
|
+
:rules="[
|
|
53
|
+
{ required: true, whitespace: true, message: '请输入折扣原因' },
|
|
54
|
+
]"
|
|
55
|
+
><ElInput ref="input" v-model="values.reason" maxlength="100"
|
|
56
|
+
/></ElFormItem>
|
|
57
|
+
<!-- 原生表单回车与底部按钮共用弹窗确认入口。 -->
|
|
58
|
+
<button type="submit" hidden tabindex="-1" aria-hidden="true" />
|
|
59
|
+
</ElForm>
|
|
60
|
+
</div>
|
|
61
|
+
<MemberHistory :details="data" :loading="loading" />
|
|
62
|
+
</BaseDialog>
|
|
63
|
+
</template>
|
|
64
|
+
<script setup lang="ts">
|
|
65
|
+
import { nextTick, reactive, ref, watch } from "vue";
|
|
66
|
+
import {
|
|
67
|
+
ElMessage,
|
|
68
|
+
ElForm,
|
|
69
|
+
ElFormItem,
|
|
70
|
+
ElInput,
|
|
71
|
+
ElInputNumber,
|
|
72
|
+
ElOption,
|
|
73
|
+
ElSelect,
|
|
74
|
+
type FormInstance,
|
|
75
|
+
type InputInstance,
|
|
76
|
+
} from "element-plus";
|
|
77
|
+
import {
|
|
78
|
+
BaseDialog,
|
|
79
|
+
useAsyncListAction,
|
|
80
|
+
isAbortError,
|
|
81
|
+
} from "@agent-xy/admin-vue3";
|
|
82
|
+
|
|
83
|
+
import { useRemoteResource } from "../hooks/useRemoteResource";
|
|
84
|
+
import { api } from "../api";
|
|
85
|
+
import { discountModeOptions } from "../config";
|
|
86
|
+
import MemberHistory from "./MemberHistory.vue";
|
|
87
|
+
const props = defineProps<{
|
|
88
|
+
uuid: string;
|
|
89
|
+
onRefresh: () => void | Promise<unknown>;
|
|
90
|
+
}>();
|
|
91
|
+
const emit = defineEmits<{ close: [] }>();
|
|
92
|
+
const form = ref<FormInstance>(),
|
|
93
|
+
dialog = ref<InstanceType<typeof BaseDialog>>();
|
|
94
|
+
const values = reactive<{ mode: 0 | 1; discount?: number; reason: string }>({
|
|
95
|
+
mode: 1,
|
|
96
|
+
reason: "",
|
|
97
|
+
});
|
|
98
|
+
const { data, loading, error, reload } = useRemoteResource((signal) =>
|
|
99
|
+
api.members.detail(props.uuid, signal),
|
|
100
|
+
);
|
|
101
|
+
watch(error, (reason) => {
|
|
102
|
+
if (!reason) return;
|
|
103
|
+
ElMessage.error(
|
|
104
|
+
data.value ? "操作已成功,用户信息刷新失败" : "用户信息加载失败",
|
|
105
|
+
);
|
|
106
|
+
if (!data.value) emit("close");
|
|
107
|
+
});
|
|
108
|
+
// 详情就绪后初始化表单;刷新时保留同一实例,避免丢失草稿与重置基线。
|
|
109
|
+
const formReady = ref(false);
|
|
110
|
+
watch([data, loading], ([details, busy]) => {
|
|
111
|
+
if (details && !busy) formReady.value = true;
|
|
112
|
+
});
|
|
113
|
+
const { exec, pendingKeys } = useAsyncListAction(async () => {
|
|
114
|
+
await reload();
|
|
115
|
+
try {
|
|
116
|
+
await props.onRefresh();
|
|
117
|
+
} catch (reason) {
|
|
118
|
+
if (!isAbortError(reason)) ElMessage.error("操作已成功,列表刷新失败");
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
const input = ref<InputInstance>();
|
|
122
|
+
let restoreInputFocus = false;
|
|
123
|
+
watch(
|
|
124
|
+
[loading, () => pendingKeys.value.length],
|
|
125
|
+
async ([busy, pending]) => {
|
|
126
|
+
if (!restoreInputFocus || busy || pending) return;
|
|
127
|
+
await nextTick();
|
|
128
|
+
input.value?.focus();
|
|
129
|
+
restoreInputFocus = false;
|
|
130
|
+
},
|
|
131
|
+
{ flush: "post" },
|
|
132
|
+
);
|
|
133
|
+
function handleOpenChange(open: boolean) {
|
|
134
|
+
if (!open) emit("close");
|
|
135
|
+
}
|
|
136
|
+
async function submit() {
|
|
137
|
+
if (!form.value) return;
|
|
138
|
+
try {
|
|
139
|
+
await form.value.validate();
|
|
140
|
+
} catch {
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
// 提交时禁用控件可能失焦,成功或失败后都恢复键盘入口。
|
|
144
|
+
restoreInputFocus = true;
|
|
145
|
+
try {
|
|
146
|
+
await exec(
|
|
147
|
+
(signal) =>
|
|
148
|
+
api.members.action(
|
|
149
|
+
props.uuid,
|
|
150
|
+
{
|
|
151
|
+
type: "discount",
|
|
152
|
+
discount: values.discount!,
|
|
153
|
+
mode: values.mode,
|
|
154
|
+
reason: values.reason,
|
|
155
|
+
},
|
|
156
|
+
signal,
|
|
157
|
+
),
|
|
158
|
+
"操作成功",
|
|
159
|
+
props.uuid,
|
|
160
|
+
);
|
|
161
|
+
} catch (reason) {
|
|
162
|
+
if (!isAbortError(reason)) ElMessage.error("提交失败");
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
form.value?.resetFields();
|
|
166
|
+
}
|
|
167
|
+
</script>
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { buildColumns, type CopyFeedback } from "@agent-xy/admin-vue3";
|
|
2
|
+
import type { Member } from "../types";
|
|
3
|
+
import { adStatusOptions, subscriptionStatusOptions } from "./data";
|
|
4
|
+
export const createColumns = (feedback: CopyFeedback) =>
|
|
5
|
+
buildColumns<Member>(
|
|
6
|
+
[
|
|
7
|
+
{ prop: "uuid", label: "UID", width: 170, hideable: false, type: "clip" },
|
|
8
|
+
{ prop: "member_email", label: "注册邮箱", width: 200, type: "clip" },
|
|
9
|
+
{ prop: "email", label: "订阅邮箱", width: 200, type: "clip" },
|
|
10
|
+
{ prop: "created_at", label: "注册时间", width: 180 },
|
|
11
|
+
{ prop: "country", label: "国家", width: 100 },
|
|
12
|
+
{
|
|
13
|
+
prop: "site",
|
|
14
|
+
label: "所属站点",
|
|
15
|
+
width: 130,
|
|
16
|
+
type: "nested",
|
|
17
|
+
path: "site.site_name",
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
prop: "subscription_status",
|
|
21
|
+
label: "订阅状态",
|
|
22
|
+
width: 110,
|
|
23
|
+
type: "enum",
|
|
24
|
+
enumList: subscriptionStatusOptions,
|
|
25
|
+
},
|
|
26
|
+
{ prop: "subscribe_cycle_type_text", label: "订阅类型", width: 130 },
|
|
27
|
+
{ prop: "subscription_expire_time", label: "到期时间", width: 180 },
|
|
28
|
+
{ prop: "next_charge_time", label: "下次扣费", width: 180 },
|
|
29
|
+
{
|
|
30
|
+
prop: "ad_show_status",
|
|
31
|
+
label: "广告状态",
|
|
32
|
+
width: 110,
|
|
33
|
+
type: "enum",
|
|
34
|
+
enumList: adStatusOptions,
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
prop: "operation",
|
|
38
|
+
label: "操作",
|
|
39
|
+
width: 270,
|
|
40
|
+
fixed: "right",
|
|
41
|
+
hideable: false,
|
|
42
|
+
},
|
|
43
|
+
],
|
|
44
|
+
feedback,
|
|
45
|
+
);
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Member } from "../types";
|
|
2
|
+
export { adStatusOptions, subscriptionStatusOptions } from "../constants";
|
|
3
|
+
export type MemberCommand = "ad" | "mini" | "discount" | "ip";
|
|
4
|
+
export function memberCommands(row: Member) {
|
|
5
|
+
return [
|
|
6
|
+
{ key: "ad", label: row.ad_show_status === 1 ? "打开广告" : "关闭广告" },
|
|
7
|
+
{ key: "mini", label: row.mini_video_status ? "关闭精简版" : "开通精简版" },
|
|
8
|
+
{ key: "discount", label: "续费折扣设置" },
|
|
9
|
+
{ key: "ip", label: "解除 IP 限制", disabled: !row.ip_limited },
|
|
10
|
+
] satisfies { key: MemberCommand; label: string; disabled?: boolean }[];
|
|
11
|
+
}
|
|
12
|
+
export function isMemberCommand(key: string): key is MemberCommand {
|
|
13
|
+
return ["ad", "mini", "discount", "ip"].includes(key);
|
|
14
|
+
}
|
|
15
|
+
export const timingOptions = [
|
|
16
|
+
{ label: "立即增加", value: 0 },
|
|
17
|
+
{ label: "续订成功后增加", value: 1 },
|
|
18
|
+
];
|
|
19
|
+
export const discountModeOptions = [
|
|
20
|
+
{ label: "永久生效", value: 1 },
|
|
21
|
+
{ label: "下次生效", value: 0 },
|
|
22
|
+
];
|