Compare commits
3 Commits
99687f4601
...
82c9eedd77
| Author | SHA1 | Date | |
|---|---|---|---|
| 82c9eedd77 | |||
| b4db01d320 | |||
| 3a7669fbe7 |
@@ -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。 */
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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)], [], '注册数组里留着没人用的组件(整包的问题不该在按需里重犯)')
|
||||
})
|
||||
|
||||
@@ -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', '管理员']], '编辑用户弹窗的角色按钮文案')
|
||||
})
|
||||
|
||||
+2
-2
@@ -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)) {
|
||||
// 公司超管可清退本公司的管理员/普通用户;公司超管之间互删与站点超管一样被拒
|
||||
|
||||
+1
-1
@@ -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, "普通管理员只能管理自己创建的普通账号");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user