f
Some checks failed
CI / Test (ubuntu-latest) (push) Has been cancelled
CI / Test (windows-latest) (push) Has been cancelled
CI / Lint (ubuntu-latest) (push) Has been cancelled
CI / Lint (windows-latest) (push) Has been cancelled
CI / Check (ubuntu-latest) (push) Has been cancelled
CI / Check (windows-latest) (push) Has been cancelled
CodeQL / Analyze (javascript-typescript) (push) Has been cancelled
Deploy Website on push / Deploy Push Playground Ftp (push) Has been cancelled
Deploy Website on push / Deploy Push Docs Ftp (push) Has been cancelled
Deploy Website on push / Deploy Push Antd Ftp (push) Has been cancelled
Deploy Website on push / Deploy Push Element Ftp (push) Has been cancelled
Deploy Website on push / Deploy Push Naive Ftp (push) Has been cancelled
Release Drafter / update_release_draft (push) Has been cancelled
CI / CI OK (push) Has been cancelled
Deploy Website on push / Rerun on failure (push) Has been cancelled
Lock Threads / action (push) Has been cancelled
Issue Close Require / close-issues (push) Has been cancelled
Close stale issues / stale (push) Has been cancelled

This commit is contained in:
Mrx
2026-02-04 13:33:24 +08:00
parent 7789e0eb0f
commit 2eb1b77fd3
4 changed files with 63 additions and 14 deletions

View File

@@ -9,6 +9,7 @@ export namespace PlatformUserApi {
nickname: string;
info: string;
inside: number;
disable: number; // 0-可用 1-封禁
create_time: string;
update_time: string;
}
@@ -23,6 +24,7 @@ export namespace PlatformUserApi {
nickname: string;
info: string;
inside: number;
disable: number; // 0-可用 1-封禁
}
}

View File

@@ -91,15 +91,21 @@ function createRequestClient(baseURL: string, options?: RequestClientOptions) {
}),
);
// 通用错误处理,如果没有进入上面的错误处理逻辑,就会进入这里
// 通用错误处理:优先展示后端返回的 errMsg确保用户能看到具体错误原因如封禁、查询暂停等
client.addResponseInterceptor(
errorMessageResponseInterceptor((msg: string, error) => {
// 这里可以根据业务进行定制,你可以拿到 error 内的信息进行定制化处理,根据不同的 code 做不同的提示,而不是直接使用 message.error 提示 msg
// 当前mock接口返回的错误字段是 error 或者 message
const responseData = error?.response?.data ?? {};
const errorMessage = responseData?.error ?? responseData?.msg ?? '';
// 如果没有错误信息,则会根据状态码进行提示
message.error(errorMessage || msg);
errorMessageResponseInterceptor((msg: string, error: any) => {
// 后端统一返回 { code, msg }code !== 200 时 defaultResponseInterceptor 会 throwerror 上可能有 response.data 或 data
const responseData = error?.response?.data ?? error?.data ?? {};
const backendMsg =
responseData?.msg ??
responseData?.errMsg ??
responseData?.error ??
responseData?.message ??
'';
const displayMsg = backendMsg.trim() || msg;
if (displayMsg) {
message.error(displayMsg);
}
}),
);

View File

@@ -2,8 +2,10 @@ import type { VbenFormSchema } from '#/adapter/form';
import type { OnActionClickFn, VxeTableGridOptions } from '#/adapter/vxe-table';
import type { PlatformUserApi } from '#/api/platform-user';
// 表单配置
export function useFormSchema(): VbenFormSchema[] {
// 表单配置(可选传入 onDisableChange用于同步「是否封禁」滑块的当前值确保解封时提交 disable=0
export function useFormSchema(options?: {
onDisableChange?: (value: 0 | 1) => void;
}): VbenFormSchema[] {
return [
{
component: 'Input',
@@ -36,6 +38,19 @@ export function useFormSchema(): VbenFormSchema[] {
},
defaultValue: 0,
},
{
component: 'Switch',
fieldName: 'disable',
label: '是否封禁用户',
componentProps: {
checkedChildren: '封禁',
unCheckedChildren: '解封',
onChange: (checked: boolean) => {
options?.onDisableChange?.(checked ? 1 : 0);
},
},
defaultValue: 0,
},
];
}
@@ -104,6 +119,12 @@ export function useColumns<T = PlatformUserApi.PlatformUserItem>(
width: 100,
formatter: ({ cellValue }) => (cellValue === 1 ? '是' : '否'),
},
{
field: 'disable',
title: '是否封禁',
width: 100,
formatter: ({ cellValue }) => (cellValue === 1 ? '封禁' : '可用'),
},
{
field: 'create_time',
title: '创建时间',

View File

@@ -1,7 +1,7 @@
<script lang="ts" setup>
import type { PlatformUserApi } from '#/api/platform-user';
import { computed, ref } from 'vue';
import { computed, nextTick, ref } from 'vue';
import { useVbenDrawer } from '@vben/common-ui';
@@ -13,9 +13,15 @@ import { useFormSchema } from '../data';
const emit = defineEmits(['success']);
const formData = ref<PlatformUserApi.PlatformUserItem>();
// 用 ref 同步「是否封禁」滑块的当前值,避免表单未回写导致后端一直收到 disable=1
const currentDisable = ref<0 | 1>(0);
const [Form, formApi] = useVbenForm({
schema: useFormSchema(),
schema: useFormSchema({
onDisableChange: (v) => {
currentDisable.value = v;
},
}),
showDefaultActions: false,
});
@@ -25,10 +31,15 @@ const [Drawer, drawerApi] = useVbenDrawer({
const { valid } = await formApi.validate();
if (!valid) return;
const values = await formApi.getValues();
// 提交时用 currentDisable滑块实时同步确保解封时传 disable=0、封禁时传 disable=1
const payload = {
...values,
disable: currentDisable.value,
} as PlatformUserApi.UpdatePlatformUserRequest;
drawerApi.lock();
updatePlatformUser(
id.value,
values as PlatformUserApi.UpdatePlatformUserRequest,
payload,
)
.then(() => {
emit('success');
@@ -45,7 +56,16 @@ const [Drawer, drawerApi] = useVbenDrawer({
if (data) {
formData.value = data;
id.value = data.id;
formApi.setValues(data);
// 根据数据库 disable 状态1=封禁 0=解封(兼容后端返回 number 或 string
const disableNum = Number(data.disable) === 1 ? 1 : 0;
currentDisable.value = disableNum;
// Switch 的 checked 需要 boolean用 nextTick 确保表单渲染后再设值,滑块才能正确显示
nextTick(() => {
formApi.setValues({
...data,
disable: disableNum === 1,
});
});
} else {
id.value = undefined;
}