From 5a7adb9075a08af3e0b634473697d65a1905dc56 Mon Sep 17 00:00:00 2001 From: Sisyphus Date: Tue, 7 Jul 2026 17:09:42 +0800 Subject: [PATCH] =?UTF-8?q?fix(F006-W17.3.8):=20UserListView=20enabled=20?= =?UTF-8?q?=E8=AF=AD=E4=B9=89=E5=8F=8D=E8=BD=AC=20(=E5=90=8E=E7=AB=AF=200?= =?UTF-8?q?=3D=E6=AD=A3=E5=B8=B8=201=3D=E7=A6=81=E7=94=A8)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 用户反馈: 切 tab 时全部(2284) vs 已禁用(2283) vs 正常(1) 数据不一致 根因: 后端 /user/user/page 接口 enabled 字段语义 0=正常 1=禁用, 但前端 UI label 与字段值反了: - 切"正常" tab 发 enabled=1 (后端当禁用查) → 只返 1 条 - 切"已禁用" tab 发 enabled=0 (后端当正常查) → 返 2283 条 - enabledStats 计数 filter 与 UI 标签反 - el-tag 颜色: enabled===1 显示绿色正常 (反了) - toggleEnabled: 当前 1 改为 0 (方向反了) - 操作按钮: enabled===1 显示禁用 (凑巧对了但跟实际语义反) 修法: 保留后端字段值, 把前端 UI 判断全部对齐后端语义 (0=正常 1=禁用) - onTabChange: normal → enabled=0, disabled → enabled=1 - enabledStats.normal = filter === 0, disabled = filter === 1 - el-tag: === 0 绿色正常, === 1 红色禁用 - 操作按钮: === 0 显示禁用(橙色), === 1 显示启用(绿色) - toggleEnabled: row.enabled===0 → next=1 (禁用), === 1 → next=0 (启用) --- src/modules/user/UserListView.vue | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/modules/user/UserListView.vue b/src/modules/user/UserListView.vue index a7203be..8680112 100644 --- a/src/modules/user/UserListView.vue +++ b/src/modules/user/UserListView.vue @@ -118,9 +118,9 @@ async function load() { raw: it })) total.value = Number(resp.total || 0) - // 统计 (在当前搜索结果中) - enabledStats.normal = list.value.filter(u => u.enabled === 1).length - enabledStats.disabled = list.value.filter(u => u.enabled === 0).length + // 统计 (后端 enabled 语义: 0=正常 1=禁用) + enabledStats.normal = list.value.filter(u => u.enabled === 0).length + enabledStats.disabled = list.value.filter(u => u.enabled === 1).length } else { list.value = [] total.value = 0 @@ -141,9 +141,10 @@ const tabItems = computed(() => [ ]) function onTabChange(key: string) { + // 后端 enabled 语义: 0=正常 1=禁用 if (key === 'all') query.enabled = '' - else if (key === 'normal') query.enabled = '1' - else if (key === 'disabled') query.enabled = '0' + else if (key === 'normal') query.enabled = '0' + else if (key === 'disabled') query.enabled = '1' query.page = 1 load() } @@ -164,8 +165,9 @@ function onEdit(row: FrontUser) { } async function toggleEnabled(row: FrontUser) { - const next = row.enabled === 1 ? 0 : 1 - const action = next === 1 ? '启用' : '禁用' + // 当前 enabled: 0=正常 1=禁用; 要切换到对端 + const next = row.enabled === 0 ? 1 : 0 + const action = next === 1 ? '禁用' : '启用' try { await ElMessageBox.confirm(`确认${action}用户「${row.nickName}」?`, `${action}确认`, { type: 'warning' }) } catch { return } @@ -236,15 +238,15 @@ onMounted(load) @limit-change="onLimitChange" >