Compare commits

...

3 Commits

Author SHA1 Message Date
huangzd1997 82c9eedd77 fix(账号文案): 后端三条 403 报错同步改口「普通账号」
前端四出口已对平,但弹窗里显示的报错文案仍来自后端常量句,不同步会当场自相矛盾:
AdminUserService「只能编辑自己创建的普通用户」「只能删除自己创建的普通用户」、
PermissionMenuService「普通管理员只能管理自己创建的普通用户」。只改 normal 那半句,
「普通管理员」是 admin 档的叫法、不在这次口径内。

全仓(.java/.ts/.vue,排除 tmp/dist/node_modules)grep 过这三条消息子串,除定义点外
0 个消费者 ⇒ 没有用例或前端在断言这些字面量,改文案不牵动判据。src/main 里余下的
「普通用户」全在注释与 javadoc 里(AccountExpiryService、PermissionMenuService、
ExpiredAccountTaskStopService 等约 15 处),不是用户可见文案,未动。

验证与代价:javac 主源码 957 文件编译通过;后端用例未跑——工作区里另一路未提交的
DedupeTotalDataController 新增了 DataReadScope 构造依赖、其用例签名还没跟上,
test-compile 17 条错误全在 collectdata/dedupe,与本笔 3 行无关(报错里不含这两个类)。
**这 3 句要生效必须重出 jar 并重启两台**,未发布;现网 jar 仍是 622dcc87…。
2026-10-05 22:45:06 +08:00
huangzd1997 b4db01d320 fix(账号文案): normal 的中文口径四出口对平为「普通账号」,并加对平护栏
「编辑用户」弹窗写「普通账号」,而同一页的角色列/顶部栏(roleLabel)、新建下拉
(USER_ROLE_OPTIONS)、roleDomainLabel 三份映射写「普通用户」——同一页自相矛盾,且
没有任何尺子拦得住(各写各的,改一处不会让别处红)。口径按 2026-10-05 定为「普通账号」。

改三处 src:types/admin.ts roleLabel('normal')、user-role-map.ts 的 USER_ROLE_OPTIONS
与 ROLE_DOMAIN_LABELS。EditUserDialog 的两个角色按钮本来就写「普通账号」,一字未动。

新增 test_task_048_normal_role_wording_agrees_across_all_exits 把四出口对平:三份映射表
按值断言,弹窗那侧钉模板形状(<el-radio-button value="xxx">文案< 逐条 deepEqual),
不钉 token——只出现过"普通账号"四个字是判不出按钮丢没丢的。

变异自证 3 发全杀:① roleLabel('normal') 退回「普通用户」⇒ 红;② 弹窗按钮文案改成
「普通用户」⇒ 红,且报出 actual [['normal','普通用户'],['admin','管理员']];
③ 弹窗按钮写法换成 :value="'normal'"(正则抓不到那一条)⇒ 红,actual 只剩 admin 一条
——这一发是证明它不是恒绿:形状对不上时缺的那条会以"少一条"现形,而不是静默通过。
三次注入均按原字节还原,EditUserDialog.vue 的 git diff 为空。

验证:node --test 全量 1738 例 0 红、vue-tsc --noEmit rc=0、浏览器实测三处可见出口
(列表角色列 / 新建下拉 / 编辑弹窗)均显示「普通账号」。
2026-10-05 22:44:21 +08:00
huangzd1997 3a7669fbe7 fix(按需注册): 「编辑用户→角色」渲染成一行裸文本——radio 子组件是 withNoopInstall,要 use 父组件
根因不在样式也不在文案,在注册表:src/plugins/element.ts 登记的是 ElRadioButton /
ElRadioGroup,而 EP 里子组件由 withNoopInstall 造(component.install = NOOP),
app.use 它们注册不出任何东西;只有父组件 ElRadio 的 withInstall(radio, {RadioButton,
RadioGroup}) 才会把三个名字一起 app.component 出去。于是模板里的 <el-radio-group> /
<el-radio-button> 解析失败,被当成未知自定义元素渲染成裸标签,两个按钮文案连成一行
「普通账号管理员」。全站 30 条注册项只注册出 33 个名字,缺的就是这两个;
ElFormItem / ElTableColumn / ElOption 等同为 no-op 的子组件都因父组件在表里而正常注册。

取证四路:像素扫描(角色栏 y=174-184 只有字形反锯齿点,同页三个输入框在 y=104/204/404
都是 723px 宽的完整边框)→ DOM(.el-radio-group 为 null,innerHTML 是原样标签)→
控制台(Failed to resolve component: el-radio-group / el-radio-button 各 2 条)→
运行期 app._context.components 键集合(无 ElRadioGroup/ElRadioButton)。

护栏原本 7/7 全绿而页面是坏的:perf_ep_registry_covers_every_used_tag 只比对注册数组的
文本里有没有那个名字——"登记过"被当成了"生效过"。改成对每个条目真跑 install(假 app)、
拿运行期注册出来的名字集合比对;修前红且红的正好是这两条。同时给
perf_ep_registry_has_no_dead_entries 补父组件豁免,否则正确修法(加 ElRadio,它自己没有
标签)反会被那条判成死条目——旧尺子会把人往错方向推。

验证:node --test 全量 1738 例 0 红、vue-tsc --noEmit rc=0、浏览器实测角色已渲染成分段
按钮("普通账号"高亮)且无解析告警。未提交未发布,现网 admin-vue 仍是 20261005-182523。
2026-10-05 22:29:53 +08:00
7 changed files with 83 additions and 19 deletions
@@ -16,14 +16,14 @@ export interface UserRoleOption {
export const USER_ROLE_OPTIONS: readonly UserRoleOption[] = [
{ value: 'company_super_admin', label: '公司超级管理员' },
{ value: 'admin', label: '管理员' },
{ value: 'normal', label: '普通用户' },
{ value: 'normal', label: '普通账号' },
]
const ROLE_DOMAIN_LABELS: Record<RoleDomain, string> = {
super_admin: '超级管理员',
company_super_admin: '公司超级管理员',
admin: '管理员',
normal: '普通用户',
normal: '普通账号',
}
/** 行字段 → 角色域:优先 role;为空时按 is_admin 布尔推断(1=管理员);未知归 normal。 */
+7 -4
View File
@@ -9,6 +9,11 @@
* 1. 新增/换用任何 `el-*` 标签,这里必须同时加「组件导入」和「按组件样式导入」。
* 少一条不会让构建变红,只会让那个页面渲染成裸标签 —— 护栏在
* tests/perf-element-on-demand.test.ts,它从源码推标签清单来比对这份文件。
* 1b. 子组件(`el-radio-group` / `el-form-item` / `el-table-column` 这类)在 EP 里是
* `withNoopInstall` 造的,`app.use` 它们注册不出任何东西;要引的是**父组件**
* (`ElRadio` / `ElForm` / `ElTable`),由父组件的 install 把子组件一起注册。
* 10-05「编辑用户 → 角色」渲染成裸文本就是只登记了两个 radio 子组件漏的。
* 护栏按运行期 install 出来的名字集合比对,不看这份清单的字符串。
* 2. 样式一律走 `element-plus/es/components/<短名>/style/css`,它会带上 base
* 与依赖组件的样式(例如 message-box 自带 input/button/overlay);
* 不要图省事改回 `theme-chalk/index.css` 或 `dist/index.css`。
@@ -39,8 +44,7 @@ import {
ElMenuItem,
ElOption,
ElProgress,
ElRadioButton,
ElRadioGroup,
ElRadio,
ElResult,
ElScrollbar,
ElSelect,
@@ -113,8 +117,7 @@ const components = [
ElMenuItem,
ElOption,
ElProgress,
ElRadioButton,
ElRadioGroup,
ElRadio,
ElResult,
ElScrollbar,
ElSelect,
+1 -1
View File
@@ -70,7 +70,7 @@ export function roleLabel(role: string | null | undefined): string {
case 'admin':
return '管理员'
case 'normal':
return '普通用户'
return '普通账号'
default:
return ''
}
@@ -45,6 +45,43 @@ function toComponentName(kebab: string): string {
return 'El' + kebab.split('-').map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join('')
}
/**
* 逐个对注册数组里的条目调 `install(假 app)`,收集真正注册出来的组件名。
*
* 为什么不能只比对数组文本:Element Plus 里子组件是 `withNoopInstall` 造的
* (`component.install = NOOP`),`app.use(ElRadioGroup)` 等于什么都没注册;只有父组件
* 的 `withInstall(main, extra)` 会把 main + extra 一起 `app.component(comp.name, comp)` 注册。
* 所以「数组里写着 ElRadioGroup / ElRadioButton」和「模板能解析出 el-radio-group」是两件事 ——
* 前者当时全绿,后者在 10-05 的「编辑用户 → 角色」上渲染成了裸标签。
* 尺子必须是运行期注册出来的名字集合,不是清单字符串。
*/
async function installedComponentNames(names: string[]): Promise<Map<string, string[]>> {
const EP = (await import('element-plus')) as unknown as Record<
string,
{ install?: (app: unknown) => void } | undefined
>
const out = new Map<string, string[]>()
for (const name of names) {
const comp = EP[name]
assert.ok(comp, `element-plus 没有导出 ${name}`)
assert.equal(typeof comp?.install, 'function', `${name} 没有 install(),app.use 它是空转`)
const registered: string[] = []
const app: Record<string, unknown> = {
component(n: string) {
registered.push(n)
return app
},
directive() {
return app
},
config: { globalProperties: {} },
}
comp!.install!(app)
out.set(name, registered)
}
return out
}
// 命令式 API 与指令:没有对应模板标签,所以不算"注册表里的死条目"
const EXTRA_REGISTERED = ['ElConfigProvider', 'ElMessage', 'ElMessageBox', 'ElLoading', 'ElLoadingDirective']
@@ -121,11 +158,12 @@ function importedNames(registry: string): string[] {
.flatMap((line) => [...line.matchAll(/\b(El[A-Z][A-Za-z0-9]*)\b/g)].map((m) => m[1]))
}
test('perf_ep_registry_covers_every_used_tag', () => {
test('perf_ep_registry_covers_every_used_tag', async () => {
const registry = readSource('src/plugins/element.ts')
const registered = new Set(registeredComponents(registry))
const missing = usedTags().map(toComponentName).filter((name) => !registered.has(name))
assert.deepEqual(missing, [], '有模板在用的 el-* 组件没进注册数组(页面会渲染成裸标签)')
const closure = await installedComponentNames(registeredComponents(registry))
const effective = new Set([...closure.values()].flat())
const missing = usedTags().map(toComponentName).filter((name) => !effective.has(name))
assert.deepEqual(missing, [], '有模板在用的 el-* 组件在 app.use 之后并未注册出来(页面会渲染成裸标签)')
})
test('perf_ep_every_used_tag_imports_its_style', () => {
@@ -139,14 +177,20 @@ test('perf_ep_every_used_tag_imports_its_style', () => {
assert.deepEqual(missing, [], '有在用的 el-* 组件没引按组件样式(构建照样绿,页面会没样式)')
})
test('perf_ep_registry_has_no_dead_entries', () => {
test('perf_ep_registry_has_no_dead_entries', async () => {
const registry = readSource('src/plugins/element.ts')
const used = new Set(usedTags())
const tags = usedTags()
const used = new Set(tags)
const usedComponentNames = new Set(tags.map(toComponentName))
const closure = await installedComponentNames(registeredComponents(registry))
const dead: string[] = []
for (const name of registeredComponents(registry)) {
for (const name of closure.keys()) {
if (EXTRA_REGISTERED.includes(name)) continue
const kebab = name.slice(2).replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase()
if (!used.has(kebab)) dead.push(name)
if (used.has(kebab)) continue
// 父组件例外:它自己不出现在模板里,但只有 app.use(它) 才把在用的子组件注册出来。
if ((closure.get(name) ?? []).some((n) => usedComponentNames.has(n))) continue
dead.push(name)
}
assert.deepEqual([...new Set(dead)], [], '注册数组里留着没人用的组件(整包的问题不该在按需里重犯)')
})
+18 -1
View File
@@ -8,6 +8,7 @@ import {
roleDomainLabel,
USER_ROLE_OPTIONS,
} from '../src/pages/account/user-role-map.ts'
import { roleLabel } from '../src/types/admin.ts'
test('test_task_048_user_role_map_normal_primary_path', () => {
// 正常主路径:role 字段直接映射为角色域。
@@ -67,7 +68,23 @@ test('test_task_048_user_role_map_dependency_failure_returns_actionable_message'
const mod = readSource('src/pages/account/user-role-map.ts')
assert.equal(/axios|http\./.test(mod), false, '角色映射保持纯逻辑')
assert.equal(roleDomainLabel('admin'), '管理员')
assert.equal(roleDomainLabel('normal'), '普通用户')
assert.equal(roleDomainLabel('normal'), '普通账号')
assert.equal(roleDomainLabel('super_admin'), '超级管理员')
assert.equal(roleDomainLabel('company_super_admin'), '公司超级管理员')
})
test('test_task_048_normal_role_wording_agrees_across_all_exits', () => {
// 2026-10-05 定口径:normal 一律显示「普通账号」。这句文案此前有四份出口 —— 列表角色列与顶部栏
// 走 roleLabel、新建下拉走 USER_ROLE_OPTIONS、还有 roleDomainLabel,而编辑弹窗的两个角色按钮是
// 硬编码在模板里的。前三份写「普通用户」、第四份写「普通账号」,同一页自相矛盾且没有尺子拦得住。
// 这条把四出口对平:任何一处换词、或弹窗那侧改成别的写法,都会红。
const word = '普通账号'
assert.equal(roleLabel('normal'), word, '用户列表角色列与顶部栏(roleLabel)')
assert.equal(roleDomainLabel('normal'), word, '角色域展示文案(roleDomainLabel)')
assert.equal(USER_ROLE_OPTIONS.find((o) => o.value === 'normal')?.label, word, '新建用户下拉候选')
const dialog = readSource('src/pages/account/EditUserDialog.vue')
const buttons = [...dialog.matchAll(/<el-radio-button\s+value="([a-z_]+)">([^<]*)</g)].map(
(m) => [m[1], m[2]] as const,
)
assert.deepEqual(buttons, [['normal', word], ['admin', '管理员']], '编辑用户弹窗的角色按钮文案')
})
@@ -351,7 +351,7 @@ public class AdminUserService {
if ("admin".equals(role)) {
if (!"normal".equals(targetRole) || !currentUser.getId().equals(target.getCreatedById())) {
throw new BusinessException(403, "只能编辑自己创建的普通用户");
throw new BusinessException(403, "只能编辑自己创建的普通账号");
}
wantRole = null;
} else {
@@ -497,7 +497,7 @@ public class AdminUserService {
}
if ("admin".equals(role)) {
if (!"normal".equals(targetRole) || !currentUser.getId().equals(target.getCreatedById())) {
throw new BusinessException(403, "只能删除自己创建的普通用户");
throw new BusinessException(403, "只能删除自己创建的普通账号");
}
} else if ("company_super_admin".equals(role)) {
// 公司超管可清退本公司的管理员/普通用户;公司超管之间互删与站点超管一样被拒
@@ -960,7 +960,7 @@ public class PermissionMenuService {
&& operator.getId() != null
&& operator.getId().equals(target.getCreatedById());
if (!ownedNormal) {
throw new BusinessException(403, "普通管理员只能管理自己创建的普通用户");
throw new BusinessException(403, "普通管理员只能管理自己创建的普通账号");
}
}