feat(多公司): 两端接上公司身份 —— 后台公司目录页、建号必选公司、顶栏显示所属公司

- 新后台新增「公司管理」页(列/新建/改名/启停,不提供删除),路由 menuKey 与
  columns 表的 admin_companies 逐字一致,由用例钉住;操作指引补该菜单一条。
- 建号弹窗对超管必须显式选一家(后端对"不传"仍落操作者自己公司,是给旧后台兜底);
  admin 只能落自己公司,越权直接 403。账号列表显示 company_name,可按公司筛。
- 客户端登录后把 companyId/companyName 落到 localStorage 并在顶栏显示;
  两个登出出口(handleKicked 与切号/登出)连公司名一起清 —— 残留会把上一个账号
  的归属显示给下一个账号。
- 契约分层:列表端点用 snake_case(company_id/company_name),current-user 与登录
  回包用 camelCase;解析器读到另一套写法必须忽略,防止前后端各猜一套。

admin-frontend-vue 1678/1678、frontend-vue 672/672,两边 build(含 vue-tsc --noEmit)干净。
This commit is contained in:
2026-10-04 07:11:47 +08:00
parent 4dbac40ef3
commit 15b8e46af8
29 changed files with 1109 additions and 16 deletions
@@ -0,0 +1,59 @@
import { test } from 'node:test'
import assert from 'node:assert/strict'
import { existsSync, readFileSync } from 'node:fs'
import { join } from 'node:path'
import { adminPages } from '../src/router/routes.ts'
/** V143 往 columns 表插了「公司管理」菜单。侧边栏/路由门禁/面包屑都按
* column_key → adminPages.menuKey 关联(menu-route-map.ts 用注册表算出的规范路径覆盖库里的
* route_path),所以真正的跨产物契约是「迁移插入的菜单 key 必须在注册表登记」。
* 少登记一条 = 菜单看得见、点进去 404,且权限门禁认不出这个 key。 */
const MIGRATION = join(process.cwd(), '..', 'backend-java', 'src', 'main', 'resources', 'db',
'V143__company_and_users_company_id.sql')
interface MigrationMenu {
name: string
columnKey: string
routePath: string
}
/** 从迁移里抓出插入的菜单行(name / column_key / route_path)。 */
function menusInsertedBy(sql: string): MigrationMenu[] {
const menus: MigrationMenu[] = []
const re = /SELECT\s+'([^']+)',\s*'([^']+)',\s*'admin',\s*'([^']+)'/g
let match: RegExpExecArray | null
while ((match = re.exec(sql))) {
menus.push({ name: match[1], columnKey: match[2], routePath: match[3] })
}
return menus
}
function migrationSql(): string {
assert.ok(existsSync(MIGRATION), `迁移文件读不到,护栏无法核对菜单登记: ${MIGRATION}`)
return readFileSync(MIGRATION, 'utf8')
}
test('V143 插入的菜单 key 都必须在路由注册表登记', () => {
const menus = menusInsertedBy(migrationSql())
// 解析自证:正则漏抓就会恒绿,这里用独立的 INSERT INTO columns 计数交叉核对
const insertCount = (migrationSql().match(/INSERT INTO `columns`/g) || []).length
assert.ok(menus.length > 0, '迁移里应当插入了后台菜单,一条都没解析出来说明正则失效')
assert.equal(menus.length, insertCount, `解析到 ${menus.length} 条,但迁移有 ${insertCount} 条 INSERT INTO columns`)
const registered = new Set(adminPages.map((page) => page.menuKey))
for (const menu of menus) {
assert.ok(registered.has(menu.columnKey),
`菜单 key "${menu.columnKey}"(${menu.name})未在 src/router/routes.ts 登记 menuKey`)
}
})
test('V143 的「公司管理」菜单落到已注册的公司管理页', () => {
const menus = menusInsertedBy(migrationSql())
const companies = menus.find((menu) => menu.columnKey === 'admin_companies')
assert.ok(companies, '迁移必须插入 admin_companies 菜单')
const page = adminPages.find((item) => item.menuKey === 'admin_companies')
assert.ok(page, 'routes.ts 必须有 admin_companies 页面')
assert.equal(page.path, companies.routePath, '库里的 route_path 应与注册表路径一致')
assert.equal(page.title, companies.name, '页面标题应与菜单名一致')
})