@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,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
+ ];
@@ -0,0 +1,3 @@
1
+ export * from "./searchForm";
2
+ export * from "./columns";
3
+ export * from "./data";
@@ -0,0 +1,69 @@
1
+ import type { FormItemConfig } from "@agent-xy/admin-vue3";
2
+ import { buildFormItems } from "@agent-xy/admin-vue3";
3
+ import type { MemberFilters, Option } from "../types";
4
+ import { adStatusOptions, subscriptionStatusOptions } from "./data";
5
+ export const initialValues: MemberFilters = { site_id: [], search: "" };
6
+ export function searchFields(
7
+ sites: Option[],
8
+ countries: Option[],
9
+ subscriptions: Option[],
10
+ loading: { sites: boolean; countries: boolean; subscriptions: boolean },
11
+ onOpen: Record<
12
+ "sites" | "countries" | "subscriptions",
13
+ (open: boolean) => void
14
+ >,
15
+ ): FormItemConfig<MemberFilters>[] {
16
+ return buildFormItems<MemberFilters>([
17
+ {
18
+ propName: "subscription_status",
19
+ itemType: "selectOne",
20
+ labelName: "订阅状态",
21
+ optionsArr: subscriptionStatusOptions,
22
+ },
23
+ {
24
+ propName: "site_id",
25
+ itemType: "selectOne",
26
+ multiple: true,
27
+ labelName: "所属站点",
28
+ optionsArr: sites,
29
+ filterable: true,
30
+ controlProps: { loading: loading.sites, onVisibleChange: onOpen.sites },
31
+ },
32
+ {
33
+ propName: "subscribe_type",
34
+ itemType: "selectOne",
35
+ labelName: "订阅类型",
36
+ optionsArr: subscriptions,
37
+ controlProps: {
38
+ loading: loading.subscriptions,
39
+ onVisibleChange: onOpen.subscriptions,
40
+ },
41
+ },
42
+ {
43
+ propName: "country_name",
44
+ itemType: "selectOne",
45
+ labelName: "国家",
46
+ filterable: true,
47
+ controlProps: {
48
+ loading: loading.countries,
49
+ onVisibleChange: onOpen.countries,
50
+ },
51
+ optionsArr: countries.map((item) => ({
52
+ ...item,
53
+ value: String(item.value),
54
+ })),
55
+ },
56
+ {
57
+ propName: "ad_show_status",
58
+ itemType: "selectOne",
59
+ labelName: "广告状态",
60
+ optionsArr: adStatusOptions,
61
+ },
62
+ {
63
+ propName: "search",
64
+ itemType: "text",
65
+ labelName: "邮箱 / UID",
66
+ width: 240,
67
+ },
68
+ ]);
69
+ }
@@ -0,0 +1,22 @@
1
+ import type { Country } from "./types";
2
+
3
+ export const countryOptions: { label: string; value: Country }[] = [
4
+ { label: "中国香港", value: "HK" },
5
+ { label: "美国", value: "US" },
6
+ { label: "英国", value: "GB" },
7
+ { label: "日本", value: "JP" },
8
+ { label: "新加坡", value: "SG" },
9
+ { label: "中国台湾", value: "TW" },
10
+ ];
11
+
12
+ export const subscriptionStatusOptions = [
13
+ { label: "未订阅", value: 0 },
14
+ { label: "订阅中", value: 1 },
15
+ { label: "退订", value: 2 },
16
+ { label: "重试", value: 3 },
17
+ ];
18
+
19
+ export const adStatusOptions = [
20
+ { label: "关闭广告", value: 1 },
21
+ { label: "打开广告", value: 2 },
22
+ ];
@@ -0,0 +1,34 @@
1
+ import { ref, shallowRef, watchEffect } from "vue";
2
+
3
+ /** 实体变化时清空旧详情;同一实体刷新时保留已加载内容。 */
4
+ export function useRemoteResource<Data>(
5
+ load: (signal: AbortSignal) => Promise<Data>,
6
+ ) {
7
+ const data = shallowRef<Data>(),
8
+ error = shallowRef<Error>();
9
+ const loading = ref(true);
10
+ let request: AbortController | undefined;
11
+ async function run(preserve: boolean) {
12
+ request?.abort();
13
+ const current = new AbortController();
14
+ request = current;
15
+ loading.value = true;
16
+ error.value = undefined;
17
+ if (!preserve) data.value = undefined;
18
+ try {
19
+ const value = await load(current.signal);
20
+ if (!current.signal.aborted) data.value = value;
21
+ } catch (reason) {
22
+ if (!current.signal.aborted)
23
+ error.value =
24
+ reason instanceof Error ? reason : new Error(String(reason));
25
+ } finally {
26
+ if (!current.signal.aborted) loading.value = false;
27
+ }
28
+ }
29
+ watchEffect((onCleanup) => {
30
+ void run(false);
31
+ onCleanup(() => request?.abort());
32
+ });
33
+ return { data, error, loading, reload: () => run(true) };
34
+ }
@@ -0,0 +1,41 @@
1
+ .users-page {
2
+ display: grid;
3
+ grid-template-columns: minmax(0, 1fr);
4
+ gap: 16px;
5
+ min-width: 0;
6
+ padding: 16px;
7
+ box-sizing: border-box;
8
+
9
+ h1 {
10
+ margin: 0;
11
+ font-size: 18px;
12
+ }
13
+
14
+ .user-actions {
15
+ display: flex;
16
+ align-items: center;
17
+ gap: 8px;
18
+ white-space: nowrap;
19
+ }
20
+
21
+ :deep(.base-card) {
22
+ margin-bottom: 0;
23
+ }
24
+
25
+ :deep(.base-card__body) {
26
+ padding: 16px 0;
27
+ }
28
+
29
+ :deep(.ai-code-copy) {
30
+ border: 0;
31
+ background: transparent;
32
+ color: var(--el-color-primary);
33
+ padding: 0;
34
+ font: inherit;
35
+ cursor: pointer;
36
+
37
+ &:hover {
38
+ text-decoration: underline;
39
+ }
40
+ }
41
+ }
@@ -0,0 +1,273 @@
1
+ <template>
2
+ <main ref="pageElement" class="users-page">
3
+ <BaseCard>
4
+ <template #title>
5
+ <h1>用户管理</h1>
6
+ </template>
7
+ <SearchForm
8
+ :form-header="fields"
9
+ :form-model="initialValues"
10
+ :loading="loading"
11
+ @submit-form="handleSearch"
12
+ @reset-form="handleReset"
13
+ />
14
+ </BaseCard>
15
+
16
+ <section aria-label="用户列表">
17
+ <BaseCard>
18
+ <DataTable
19
+ row-key="uuid"
20
+ :table-columns="columns"
21
+ :table-data="tableData"
22
+ :loading="loading"
23
+ table-height="440"
24
+ :page-params="pageParams"
25
+ @handle-current-change="handlePageChange"
26
+ @handle-size-change="handleSizeChange"
27
+ >
28
+ <template #toolbar>
29
+ <ElButton
30
+ v-bind="{ 'data-users-refresh': '' }"
31
+ :disabled="disabled"
32
+ @click="getData"
33
+ >
34
+ 刷新
35
+ </ElButton>
36
+ </template>
37
+ <template #operation="{ row }">
38
+ <div class="user-actions">
39
+ <ElButton
40
+ v-bind="{ 'data-user-id': row.uuid, 'data-user-action': 'duration' }"
41
+ size="small"
42
+ :disabled="disabled"
43
+ @click="openDuration(row.uuid)"
44
+ >
45
+ 增加订阅时长
46
+ </ElButton>
47
+ <ElDropdown
48
+ :disabled="disabled"
49
+ trigger="click"
50
+ @command="(key: string) => handleCommand(key, row)"
51
+ >
52
+ <ElButton
53
+ v-bind="{ 'data-user-id': row.uuid, 'data-user-action': 'more' }"
54
+ size="small"
55
+ type="primary"
56
+ :disabled="disabled"
57
+ >
58
+ 更多操作
59
+ </ElButton>
60
+ <template #dropdown>
61
+ <ElDropdownMenu>
62
+ <ElDropdownItem
63
+ v-for="item in memberCommands(row)"
64
+ :key="item.key"
65
+ :command="item.key"
66
+ :disabled="item.disabled"
67
+ >
68
+ {{ item.label }}
69
+ </ElDropdownItem>
70
+ </ElDropdownMenu>
71
+ </template>
72
+ </ElDropdown>
73
+ </div>
74
+ </template>
75
+ </DataTable>
76
+ </BaseCard>
77
+ </section>
78
+
79
+ <AddExpireTime
80
+ v-if="durationUser"
81
+ :key="durationUser"
82
+ :uuid="durationUser"
83
+ :on-refresh="getData"
84
+ @close="closeAction"
85
+ />
86
+ <RenewalDiscount
87
+ v-if="discountUser"
88
+ :key="discountUser"
89
+ :uuid="discountUser"
90
+ :on-refresh="getData"
91
+ @close="closeAction"
92
+ />
93
+ </main>
94
+ </template>
95
+ <script setup lang="ts">
96
+ import "element-plus/dist/index.css";
97
+ import "@agent-xy/admin-vue3/style.css";
98
+ import { computed, nextTick, onMounted, reactive, ref, watch } from "vue";
99
+ import {
100
+ ElButton,
101
+ ElDropdown,
102
+ ElDropdownItem,
103
+ ElDropdownMenu,
104
+ ElMessage,
105
+ } from "element-plus";
106
+ import {
107
+ BaseCard,
108
+ SearchForm,
109
+ DataTable,
110
+ usePageList,
111
+ useSelectOptions,
112
+ isAbortError,
113
+ useAsyncListAction,
114
+ } from "@agent-xy/admin-vue3";
115
+ import { api } from "./api";
116
+ import type { Member, MemberAction, MemberFilters } from "./types";
117
+ import {
118
+ createColumns,
119
+ initialValues,
120
+ searchFields,
121
+ memberCommands,
122
+ isMemberCommand,
123
+ type MemberCommand,
124
+ } from "./config";
125
+ import AddExpireTime from "./components/AddExpireTime.vue";
126
+ import RenewalDiscount from "./components/RenewalDiscount.vue";
127
+
128
+ type Query = { page: number; page_size: number; filters: MemberFilters };
129
+ const initialQuery: Query = { page: 1, page_size: 20, filters: initialValues };
130
+ const query = reactive({ ...initialQuery });
131
+ const {
132
+ tableData,
133
+ loading,
134
+ pageParams,
135
+ getData,
136
+ onSubmit,
137
+ reset,
138
+ handlePageChange,
139
+ handleSizeChange,
140
+ } = usePageList<Query, Member>(query, {
141
+ initialQuery,
142
+ fetchList: api.members.list,
143
+ onError: () => ElMessage.error("用户列表加载失败"),
144
+ });
145
+ const sites = useSelectOptions(
146
+ (signal) => api.members.options("sites", signal),
147
+ (row) => row,
148
+ );
149
+ const countries = useSelectOptions(
150
+ (signal) => api.members.options("countries", signal),
151
+ (row) => row,
152
+ );
153
+ const subscriptions = useSelectOptions(
154
+ (signal) => api.members.options("subscriptions", signal),
155
+ (row) => row,
156
+ );
157
+ const fields = computed(() =>
158
+ searchFields(
159
+ sites.options.value,
160
+ countries.options.value,
161
+ subscriptions.options.value,
162
+ {
163
+ sites: sites.loading.value,
164
+ countries: countries.loading.value,
165
+ subscriptions: subscriptions.loading.value,
166
+ },
167
+ {
168
+ sites: (open) => {
169
+ if (open && sites.error.value && !sites.loading.value)
170
+ void sites.reload();
171
+ },
172
+ countries: (open) => {
173
+ if (open && countries.error.value && !countries.loading.value)
174
+ void countries.reload();
175
+ },
176
+ subscriptions: (open) => {
177
+ if (open && subscriptions.error.value && !subscriptions.loading.value)
178
+ void subscriptions.reload();
179
+ },
180
+ },
181
+ ),
182
+ );
183
+ watch(
184
+ [sites.error, countries.error, subscriptions.error],
185
+ (errors, previous) => {
186
+ if (errors.some((error, index) => error && error !== previous[index]))
187
+ ElMessage.error({ message: "筛选选项加载失败", grouping: true });
188
+ },
189
+ );
190
+ const pageElement = ref<HTMLElement>();
191
+ let returnFocus: { uuid: string; action: "duration" | "more" } | undefined;
192
+ function openDuration(uuid: string) {
193
+ returnFocus = { uuid, action: "duration" };
194
+ durationUser.value = uuid;
195
+ }
196
+ async function closeAction() {
197
+ durationUser.value = undefined;
198
+ discountUser.value = undefined;
199
+ await nextTick();
200
+ // 列表刷新会替换行节点,按标识寻找当前按钮,避免聚焦已移除的节点。
201
+ const target = [
202
+ ...(pageElement.value?.querySelectorAll<HTMLElement>(
203
+ "[data-user-action]",
204
+ ) ?? []),
205
+ ].find(
206
+ (node) =>
207
+ node.dataset.userId === returnFocus?.uuid &&
208
+ node.dataset.userAction === returnFocus?.action,
209
+ );
210
+ (
211
+ target ??
212
+ pageElement.value?.querySelector<HTMLElement>("[data-users-refresh]")
213
+ )?.focus();
214
+ returnFocus = undefined;
215
+ }
216
+ const durationUser = ref<string>(),
217
+ discountUser = ref<string>();
218
+ const { exec, pendingKeys } = useAsyncListAction(getData);
219
+ const disabled = computed(() => loading.value || pendingKeys.value.length > 0);
220
+ const columns = createColumns({
221
+ onCopied: () => {
222
+ ElMessage.success("已复制");
223
+ },
224
+ onCopyError: () => {
225
+ ElMessage.error("复制失败,请手动复制");
226
+ },
227
+ });
228
+ onMounted(() => {
229
+ void getData();
230
+ });
231
+ function handleSearch(filters: Partial<MemberFilters>) {
232
+ void onSubmit({ filters });
233
+ }
234
+ function handleReset() {
235
+ void reset();
236
+ }
237
+ async function execute(row: Member, action: MemberAction) {
238
+ try {
239
+ await exec(
240
+ (signal) => api.members.action(row.uuid, action, signal),
241
+ "操作成功",
242
+ row.uuid,
243
+ );
244
+ } catch (reason) {
245
+ if (!isAbortError(reason)) ElMessage.error("操作失败");
246
+ }
247
+ }
248
+ function handleCommand(key: string, row: Member) {
249
+ const handlers: Record<MemberCommand, () => void> = {
250
+ discount: () => {
251
+ returnFocus = { uuid: row.uuid, action: "more" };
252
+ discountUser.value = row.uuid;
253
+ },
254
+ ad: () => {
255
+ void execute(row, {
256
+ type: "ad",
257
+ value: row.ad_show_status === 1 ? 2 : 1,
258
+ });
259
+ },
260
+ mini: () => {
261
+ void execute(row, {
262
+ type: "mini",
263
+ value: row.mini_video_status === 1 ? 0 : 1,
264
+ });
265
+ },
266
+ ip: () => {
267
+ void execute(row, { type: "release-ip" });
268
+ },
269
+ };
270
+ if (isMemberCommand(key)) handlers[key]();
271
+ }
272
+ </script>
273
+ <style lang="scss" scoped src="./index.scss" />