fix(前端): 后台摘掉公司这一维度——列表列/筛选/建号选择/顶栏旁白全部去掉

用户定案:隔离该由数据和后端自己做,不该把"公司"摆到操作员眼前多一个选错的机会。
于是原计划里给品牌库/去重库两页加公司列(Task 9)反向执行,顺带把一期已上线的展示也收掉。

建号归属改为请求体不带 company_id,由后端 resolveTargetCompanyId 落操作者自己的公司。
这条前端删下拉的安全依据完全靠后端那两条分支撑着,所以用跨仓读 Java 源码的方式钉成可执行断言:
谁把那边改成"必填公司"或删掉任一分支,这边立刻红。
副作用要说清——超管建的号一律归公司 1,给第 2 家建号得用那家公司自己的管理员登录。

「公司管理」页的引导语原写"建号时选哪家公司",下拉没了就成了错的承诺;
"停用后不能再用于新建账号"也不再成立(requireActive 两个调用点都要求显式传 company_id,
而页面现在一律不传)。文案改成真实口径,并断言这三句失效说法不得回流。

1683 例 / 0 红,vue-tsc 干净,变异 6/6 被杀。
This commit is contained in:
2026-10-04 16:15:13 +08:00
parent e6c4c9e7cf
commit ce69fa217c
14 changed files with 179 additions and 275 deletions
@@ -7,79 +7,86 @@ import {
createUserFilterState,
isFilterActive,
toUserListParams,
withFilterReset,
} from '../src/pages/account/users-filter.ts'
import { topbarUserOf } from '../src/layout/topbar-model.ts'
/** 公司维度进账号页(设计文档 §2.3/§5.1):列表列、按公司筛选(仅超管)、顶栏公司名。 */
/**
* 公司维度不出现在后台前端(2026-10-04 15:4x 定案,推翻一期 §2.3/§5.1 的"列表加公司列 + 筛选 + 顶栏公司名")。
*
* <p>不显示 ≠ 不存在:建号请求体不带 company_id,归属由后端
* `AdminUserService#resolveTargetCompanyId` 落操作者自己的公司;跨公司隔离发生在消费侧与读取侧
* (二期批次 2/3),不依赖页面把公司名渲染出来。所以这里的断言全部打在"不得回流"上:
* 任何一处重新渲染公司,本文件就红。</p>
*/
test('company_user_list_item_reads_snake_case_company_columns', () => {
test('公司列不再写进列表项,但其余字段必须照常解析', () => {
const item = toAdminUserItem({
id: 7,
username: '张三',
role: 'normal',
company_id: 2,
company_name: '福州数富',
created_by_id: 5,
creator_username: 'admin',
})
assert.equal(item?.companyId, 2)
assert.equal(item?.companyName, '福州数富')
assert.ok(item, '解析结果不该为 null')
assert.equal('companyId' in item, false, '后端仍会带 company_id/company_name,前端不再往列表项里写')
assert.equal('companyName' in item, false)
// 反向自检:不许靠"整条解析都坏了"变绿
assert.equal(item.id, 7)
assert.equal(item.username, '张三')
assert.equal(item.createdById, 5)
assert.equal(item.creatorUsername, 'admin')
})
test('company_user_list_item_ignores_camel_case_company_keys', () => {
// 反向排他:后端 AdminUserItemVo 走 @JsonProperty snake_case,解析器若跟着读 camelCase 就是双向猜。
const item = toAdminUserItem({ id: 7, username: '张三', role: 'normal', companyId: 9, companyName: '别家' })
assert.equal(item?.companyId, undefined)
assert.equal(item?.companyName, undefined)
test('筛选状态与查询参数里都没有公司这一维', () => {
const state = createUserFilterState()
assert.equal('companyId' in state, false)
assert.deepEqual(state, { keyword: '', createdByAdminId: null, role: '', page: 1, pageSize: 10 })
const params = toUserListParams({ ...state, keyword: ' x ', createdByAdminId: 4 })
assert.equal('companyId' in params, false)
assert.equal(isFilterActive({ ...state, keyword: ' ' }), false)
const query = toUserListQuery(normalizeUserPageParams({ page: 2, pageSize: 20, keyword: 'x' }))
assert.equal('company_id' in query, false, '绝不下发 company_id:一旦下发就是"只看这家"的过滤')
})
test('company_user_list_filter_state_defaults_to_no_company', () => {
assert.equal(createUserFilterState().companyId, null)
// 改了公司筛选要回第一页,与其他筛选条件同规则
const next = withFilterReset({ ...createUserFilterState(), page: 5 }, { companyId: 3 })
assert.equal(next.companyId, 3)
assert.equal(next.page, 1)
assert.equal(isFilterActive({ ...createUserFilterState(), companyId: 3 }), true)
test('顶栏不再渲染公司名', () => {
const vm = topbarUserOf({ id: 1, username: 'admin', role: 'admin', companyName: '厦门米椿花' } as never)
assert.equal('company' in vm, false)
assert.deepEqual(vm, { username: 'admin', role: '管理员', hasUser: true })
assert.equal(topbarUserOf(null).hasUser, false)
})
test('company_user_list_query_sends_company_id_only_when_selected', () => {
const withCompany = toUserListQuery(normalizeUserPageParams({ page: 1, pageSize: 10, companyId: 3 }))
assert.equal(withCompany.company_id, 3)
assert.equal(
'company_id' in toUserListQuery(normalizeUserPageParams({ page: 1, pageSize: 10 })),
false,
'未选公司时不下发 company_id,否则后端会当成"只看这家公司"过滤',
)
})
test('company_user_list_params_adapter_carries_company_id', () => {
const params = toUserListParams({ ...createUserFilterState(), companyId: 2 })
assert.equal(params.companyId, 2)
})
test('company_topbar_shows_company_name', () => {
assert.equal(
topbarUserOf({ id: 1, username: 'admin', role: 'admin', companyName: ' 厦门米椿花 ' }).company,
'厦门米椿花',
)
// 未登录空态与"后端没带公司"都必须是不显示,而不是渲染出 undefined
assert.equal(topbarUserOf(null).company, '')
assert.equal(topbarUserOf({ id: 1, username: 'admin', role: 'admin' }).company, '')
})
test('company_user_list_page_ui_wiring', () => {
test('账号页与顶栏的源码里公司维度已摘干净', () => {
const page = readSource('src/pages/account/UsersPage.vue')
assert.match(page, /所属公司/, '账号页要有公司这一列/筛选的中文标签')
assert.match(page, /fetchCompanies/, '公司候选来自 /api/admin/companies')
assert.match(page, /:companies="companies"/, '整份公司目录交给弹窗,由弹窗按操作者收窄')
assert.match(page, /:operator="operatorScope"/, '弹窗要拿到操作者角色与归属才能判必选')
assert.match(page, /colspan="8"/, '加了公司列后空态横跨整表')
assert.equal(/所属公司/.test(page), false, '账号页不该再出现「所属公司」标签')
assert.equal(/companyId|companyName|companies/.test(page), false, '页面不再持有公司目录或公司筛选状态')
assert.equal(/fetchCompanies/.test(page), false, '公司目录接口不该再被账号页调用')
// 「删了列忘了改占位行 colspan」是这类改动最常留下的残行:按表头列数交叉核对
// (`<th` 是 `<thead` 的前缀,必须带上后随字符才数得准)
const headers = (page.match(/<th[\s>]/g) || []).length
const spans = [...page.matchAll(/colspan="(\d+)"/g)].map((m) => Number(m[1]))
assert.ok(spans.length >= 1, '列表 tbody 没有 colspan 占位行')
for (const span of spans) assert.equal(span, headers, `占位行 colspan=${span} 与表头列数 ${headers} 不符`)
const dialog = readSource('src/pages/account/CreateUserDialog.vue')
assert.match(dialog, /selectableCompanies\(/, '下拉选项走同一条后端收窄规则')
assert.match(dialog, /initialCompanyId\(/, '打开弹窗时的默认公司走纯函数,不在模板里现写')
assert.match(dialog, /请选择所属公司/, '下拉占位与校验文案同源')
assert.match(dialog, /validateCreateUserForm\(form, props\.operator\)/, '校验必须带上操作者,否则"超管必选公司"永远不触发')
assert.equal(/所属公司|selectableCompanies|initialCompanyId|companyId/.test(dialog), false,
'建号弹窗不该再有公司选择')
const layout = readSource('src/layout/AdminLayout.vue')
assert.match(layout, /userVm\.company/, '顶栏走同一条公司名视图模型')
assert.equal(/userVm\.company|admin-user-company/.test(layout), false, '顶栏旁白只剩用户名与角色')
// 视图模型只删映射、留着 company 字段="接口说有、运行时永远空",是最难看出来的一种回流
const topbar = readSource('src/layout/topbar-model.ts')
assert.equal(/compan/i.test(topbar), false, '顶栏模型里不该再出现公司字段(连类型一起删)')
const filter = readSource('src/pages/account/users-filter.ts')
assert.equal(/companyId/.test(filter), false)
const dto = readSource('src/api/users-dto.ts')
assert.equal(/company_id|companyId/.test(dto), false)
const model = readSource('src/api/users-model.ts')
assert.equal(/company_id|company_name/.test(model), false)
})