feat(菜单权限): 每家公司一套菜单树(V149)+ 公司 tab 只在注册表页渲染

本批两件事,加上随本批一起入仓的并行会话在制品:

一、菜单权限按公司隔离(批次 6)
- V149 给 columns 加 company_id:先可空加列(末位、ALGORITHM=INSTANT)→ 回填公司 1 →
  MODIFY 收紧 NOT NULL;三段式缺一即撞 1048。同时建 (company_id, column_key) 复合键、
  把公司 2 的 16 笔授权按 column_key 改指向它自己的副本,三类 menu_type 全复制,
  admin_companies 作为角色内生闸门行不复制(D3)。
- 第三道归属门 PermissionMenuService.resolveScopeCompanyId:站点超管可带 company_id
  读写任意公司,非超管锁本公司、越界 403。它注册进 CompanyIdParamGoesThroughReadScopeTest
  的 SCOPE_DOORS,四条判据与 readScope / readCompanyIdOrOwn 共用——护栏在代码出口,不靠清单。
- 旁路种子 PermissionMenuSchemaInitializer 只种公司 1:31 段种子逐条钉公司,
  按 column_key 点查的 14 段全部带 company_id,否则摘了 DEFAULT 就是跨公司串写。
- CompanyService.create 同一次写入里给新公司复制模板树(D4)。

二、公司 tab 收口(批次 b)
tab 条挂在壳层,对 22 页全画;改为按正列表 companyTabAppliesTo(menuKey) 判定,
只有注册表页渲染。护栏钉在用户看见的那个出口。

三、并行会话在制品(控制方「全部提交」,未单独拆分——见下)
- V150 店铺密钥 biz_shop_key 按公司(readCompanyIdOrOwn + writeCompanyId 两道门)
- V151 品牌库/商品类目推翻为全平台共享:只退唯一键、company_id DEFAULT 保留为
  NOT NULL 承重约束(摘了每条 1364);删掉 ProductCategoryControllerCompanyScopeTest
  那支"按公司隔离"的旧护栏,readCompanyId 方法一并移除
- invalidasin 字段与外观专利合批的连带改动

为什么不拆笔:后端 3891 例 / 0 红、前端 1731 例 / 0 红这两个读数是"合起来的树"的读数,
拆成多笔会让每一笔落到从未一起验过的组合上,而这一版要直接上两台。

回滚脚本在 backend-java/docs/rollback-V149/V150/V151-*.sql,不放进 Flyway 扫描路径。
设计记录:docs/ops/menu-company-tree-design-2026-10-06.md
This commit is contained in:
2026-10-06 17:17:14 +08:00
parent e635fa8dcd
commit b7acfc0eef
84 changed files with 5118 additions and 1421 deletions
+15 -3
View File
@@ -29,11 +29,12 @@ export const COMPANY_SCOPED_PAGES: readonly CompanyScopedPage[] = [
// 这一批把前端接线补齐。apiFiles 只列**真的把 company_id 拼进请求**的模块:
// 各页的 *-filter.ts 与 asin-filter.ts 只带 camel 的 companyId 字段(类型 + 白名单构造都不点名它),
// 列进来会让正向判据去盯一个本来就不该出现 snake_case 的文件。
// 【这两页已于 2026-10-06 退出注册表】admin_invalid_asin_data(品牌数据库)与 admin_product_categories
// (商品类目)按控制方定案退回**全平台共享**,摘的不只是 tab:后端读写两侧的 company_id 谓词一起删
// (V151 退唯一键)。反向钉在 tests/company-tab-wiring.test.ts——把它们再加回来必须先推翻那条定案。
{ menuKey: 'admin_dedupe_total_data', apiFiles: ['src/pages/asin/dedupe-total-api.ts', 'src/pages/asin/dedupe-total-export.ts'], pageFiles: ['src/pages/asin/DedupeRegistryPage.vue'] },
{ menuKey: 'admin_invalid_asin_data', apiFiles: ['src/pages/invalidasin/invalid-asin-api.ts'], pageFiles: ['src/pages/asin/AsinInvalidPage.vue'] },
{ menuKey: 'admin_query_asin', apiFiles: ['src/pages/asin/query-asin-api.ts', 'src/pages/asin/query-asin-export.ts'], pageFiles: ['src/pages/asin/QueryAsinPage.vue'] },
{ menuKey: 'admin_skip_price_asin', apiFiles: ['src/pages/asin/skip-price-api.ts', 'src/pages/asin/skip-price-export.ts'], pageFiles: ['src/pages/asin/SkipPricePage.vue'] },
{ menuKey: 'admin_product_categories', apiFiles: ['src/pages/asin/product-category-api.ts', 'src/pages/asin/product-category-export.ts'], pageFiles: ['src/pages/asin/ProductCategoryPage.vue'] },
// 批次 3(控制方 2026-10-05 点名「店铺撞款监控 店铺数据也要做隔离」)。这两页的可见集不是按 company_id 列筛的,
// 而是「本公司账号名下的店铺」:后端由 DataReadScope 把公司 → 成员账号 → biz_shop_manage.created_by_id 逐级推导,
// 前端只负责把 activeId 当 company_id 送下去。
@@ -42,5 +43,16 @@ export const COMPANY_SCOPED_PAGES: readonly CompanyScopedPage[] = [
// 批次 4(控制方 2026-10-05 点名「菜单权限和用户管理也要区分公司 tab 的数据」)。
// 这一页的后端早就认 company_id(AdminUserService 只在**站点超管**身上用它筛,公司超管恒锁本公司),
// 断的是前端:users-dto 的 UserListQuery 里连这个字段都没有 ⇒ 三家 tab 看到的是同一份全量列表。
{ menuKey: 'admin_users', apiFiles: ['src/api/users.ts'], pageFiles: ['src/pages/account/UsersPage.vue'] },
{ menuKey: 'admin_users', apiFiles: ['src/api/users.ts', 'src/pages/account/user-menu-auth-api.ts'], pageFiles: ['src/pages/account/UsersPage.vue'] },
// 批次 5(控制方 2026-10-06 点名「店铺密钥管理的数据按照公司区分」)。biz_shop_key 原先零归属列,
// 拿到这一页菜单的任意管理员读的是同一池全平台紫鸟令牌,而列表 VO 把令牌原文整列下发(悬停即得全文)。
// V150 加 company_id;后端读门是 readCompanyIdOrOwn ⇒ 非超管连 company_id 都不带也一律锁本公司,
// 这一页的 tab 只对超管改变行数(与其余页同形,见 COMPANY_TAB_GUIDE_NOTE 开头那句「超级管理员」)。
{ menuKey: 'admin_shop_keys', apiFiles: ['src/pages/shop/shop-key-api.ts'], pageFiles: ['src/pages/shop/ShopKeysPage.vue'] },
// 批次 6(控制方 2026-10-06 点名「菜单权限也加字段来区分」,并选了「每家公司一套菜单树」那一档)。
// V149 给 columns 加 company_id 并把 52 行复制成每家一套 ⇒ 同一 column_key 在别家有另一份 id:
// 不带 company_id 时超管拿到的是两家混在一起的目录(两排同名菜单),勾出来的 id 又会撞
// 「无效的菜单权限项」。写侧(编辑/删除/重排)不带参数——归属由那一行的 id 与操作者公司共同判定,
// 跨公司写后端 403(见 docs/ops/menu-company-tree-design-2026-10-06.md §5)。
{ menuKey: 'admin_columns', apiFiles: ['src/pages/account/menu-manage-api.ts'], pageFiles: ['src/pages/account/MenusPage.vue'] },
]
@@ -1,16 +1,19 @@
<script setup lang="ts">
/** 页面上方的公司 tab(spec §4、§9.3):只有超管看得到,选中哪家由哪一枚 tab 带 is-active 表达——
* 这里不再挂第二处"这家是谁"的文案(§12 第 5 条把页头提示条算未批的界面暴露),
/** 页面上方的公司 tab(spec §4、§9.3):只有超管看得到,而且只画在**注册表里真的按公司取数的那些页**上——
* 选中哪家由哪一枚 tab 带 is-active 表达,这里不再挂第二处"这家是谁"的文案(§12 第 5 条把页头提示条算未批的界面暴露),
* 观感说明走 operation-guides 的引导文案。 */
import { computed, watch } from 'vue'
import { useRoute } from 'vue-router'
import { COMPANY_STATUS_ACTIVE } from '@/api/companies-dto'
import { useCompanyTabStore } from '@/stores/company-tab'
import { useAdminSessionStore } from '@/stores/admin-session'
import { companyTabAppliesTo } from '@/layout/company-tab-model'
const route = useRoute()
const tab = useCompanyTabStore()
const session = useAdminSessionStore()
const tabs = computed(() => tab.companies.filter((c) => c.status === COMPANY_STATUS_ACTIVE))
const show = computed(() => tab.visibleForOperator)
const show = computed(() => tab.visibleForOperator && companyTabAppliesTo(route.meta.menuKey))
watch(() => session.isSuperAdmin, (v) => {
if (!v) return
@@ -1,8 +1,22 @@
/** 公司 tab 的两支纯函数(store 与护栏用例共用,不依赖 pinia / 组件)。
/** 公司 tab 的三支纯函数(store 与护栏用例共用,不依赖 pinia / 组件)。
* import 用相对路径 + 显式 `.ts`:本文件被 tests 以 `node --test` 直接 import,而测试侧没有
* vite 的 `@` 别名解析器,写成 `@/api/...` 会 ERR_MODULE_NOT_FOUND(护栏因此读源码而非常规 import,
* 见 tests/company-tab-wiring.test.ts 用 readSource 的原因)。 */
import { COMPANY_STATUS_ACTIVE, type CompanyItem } from '../api/companies-dto.ts'
import { COMPANY_SCOPED_PAGES } from '../config/company-scope.ts'
/** 参与公司隔离的页(注册表那份 menuKey 的集合形态)。判据**只有这一份来源**:
* 另立一张"哪些页不画 tab"的黑名单,下一个新页会默认长出一条点了没反应的 tab(2026-10-06 的成因)。 */
const SCOPED_MENU_KEYS: ReadonlySet<string> = new Set(COMPANY_SCOPED_PAGES.map((page) => page.menuKey))
/**
* 这一页切了公司**有没有用**。与 store 的 `visibleForOperator` 是两个正交问题,不是同一问的两把尺子:
* 那一条答「目录取到了吗、这名下有几家可切」,这一条答「当前这页吃不吃公司维度」。
* 壳层把 tab 挂在所有页上时,公司管理页头顶就压着一排点了不重取数的 tab(控制方 2026-10-06 点名)。
*/
export function companyTabAppliesTo(menuKey: unknown): boolean {
return typeof menuKey === 'string' && SCOPED_MENU_KEYS.has(menuKey)
}
/** 超管的读范围公司。非超管恒 null——它的公司是固定的,下传一个常数只会让人以为这页在按公司筛。 */
export function companyIdForRequest(isSuperAdmin: boolean, activeId: number | null): number | null {
@@ -21,7 +21,7 @@ export const OPERATION_GUIDE_STORAGE_KEY = 'shufuAdminGuideCollapsed'
* (§12 第 5 条把那种提示条算未批的界面暴露;当前哪一家由 is-active 的 tab 表达,一处事实不留两处)。
* 这句必须以「超级管理员」开头、不能写成祈使式的「由上方 tab 决定」:引导文案按 menuKey 取、
* 不分支角色,而非超管根本看不到 tab 条(company-tab store 的 visibleForOperator 里有 isSuperAdmin)。
* 这一句由参与 tab 的 13 页共用、不各抄一遍——文案差一个字,护栏就只盯得住其中一页。
* 这一句由参与 tab 的 14 页共用、不各抄一遍——文案差一个字,护栏就只盯得住其中一页。
* 由 tests/align-operation-guide.test.ts 的 guide_copy_carries_company_tab_note_for_every_scoped_page
* 按 COMPANY_SCOPED_PAGES 逐页盯着(分母取注册表,加一页忘了补文案会当场红)。 */
const COMPANY_TAB_GUIDE_NOTE = ' 超级管理员可用页面上方的公司 tab 切换公司,切换后行数会变化——行数变少不是数据丢了。'
@@ -42,7 +42,10 @@ export const OPERATION_GUIDES: Record<string, OperationGuideData> = {
steps: ['筛选账号', '编辑权限', '确认保存'],
},
admin_columns: {
text: '菜单会影响后台和软件端的可见范围。先填写名称并选择对应页面,再设置上级菜单;顺序直接拖动列表左侧手柄调整。',
// 2026-10-06 批次 6:V149 起每家公司一套菜单树 ⇒ 这页参与公司 tab,必须带上 §9.3 那句
// (align-operation-guide 按注册表数分母,缺了它当场红)。
text: '菜单会影响后台和软件端的可见范围。先填写名称并选择对应页面,再设置上级菜单;顺序直接拖动列表左侧手柄调整。'
+ COMPANY_TAB_GUIDE_NOTE,
steps: ['新增或调整菜单', '设置层级', '拖动排序'],
},
admin_group_manage: {
@@ -69,7 +72,7 @@ export const OPERATION_GUIDES: Record<string, OperationGuideData> = {
},
admin_invalid_asin_data: {
text: '维护不符合规则的 ASIN 或品牌。添加后可使用上方筛选快速回查。'
+ COMPANY_TAB_GUIDE_NOTE,
+ COMPANY_SCOPE_NOT_APPLIED_NOTE,
steps: ['填写 ASIN/品牌', '选择分组', '保存并回查'],
},
admin_query_asin: {
@@ -79,7 +82,7 @@ export const OPERATION_GUIDES: Record<string, OperationGuideData> = {
},
admin_product_categories: {
text: '类目树支持展开查看层级。搜索、编辑和删除都在同一列表中完成。'
+ COMPANY_TAB_GUIDE_NOTE,
+ COMPANY_SCOPE_NOT_APPLIED_NOTE,
steps: ['搜索类目', '展开层级', '新增或编辑'],
},
admin_skip_price_asin: {
@@ -88,8 +91,10 @@ export const OPERATION_GUIDES: Record<string, OperationGuideData> = {
steps: ['筛选店铺', '打开配置抽屉', '保存或批量导入'],
},
admin_shop_keys: {
// 2026-10-06 批次 5:这页由「全平台共享」改按公司区分(V150 给 biz_shop_key 加 company_id),
// 所以摘掉 COMPANY_SCOPE_NOT_APPLIED_NOTE、换上共用那一句 §9.3。
text: '紫鸟令牌属于敏感配置。白名单状态可悬停查看检测详情,编辑前请先核对账号名称。'
+ COMPANY_SCOPE_NOT_APPLIED_NOTE,
+ COMPANY_TAB_GUIDE_NOTE,
steps: ['新增或筛选密钥', '查看白名单状态', '编辑或删除'],
},
admin_shop_manage: {
@@ -117,11 +122,13 @@ export const OPERATION_GUIDES: Record<string, OperationGuideData> = {
steps: ['设置时间范围', '筛选记录', '查看结果预览'],
},
admin_version: {
text: '上传版本后请核对版本号和下载链接,再通知用户更新。',
text: '上传版本后请核对版本号和下载链接,再通知用户更新。'
+ COMPANY_SCOPE_NOT_APPLIED_NOTE,
steps: ['上传压缩包', '检查版本记录', '维护历史版本'],
},
admin_tutorial: {
text: '上传新的教程压缩包后即刻生效:工具台首页「立即下载教程」以下载最新上传的包为准。确认旧包不再需要后再删除。',
text: '上传新的教程压缩包后即刻生效:工具台首页「立即下载教程」以下载最新上传的包为准。确认旧包不再需要后再删除。'
+ COMPANY_SCOPE_NOT_APPLIED_NOTE,
steps: ['上传教程压缩包', '到工具台核对下载', '清理历史包'],
},
digital_human_version: {
@@ -155,7 +155,7 @@ async function create(): Promise<void> {
</el-form-item>
<el-form-item label="菜单权限(勾选上级菜单会继承全部子菜单)">
<div class="auth-tree-box">
<UserMenuAuthTree v-model:checked="form.columnIds" />
<UserMenuAuthTree v-model:checked="form.columnIds" :company-id="form.companyId" />
</div>
</el-form-item>
</el-form>
@@ -9,7 +9,9 @@ import { showAdminFeedback } from '@/components/admin-feedback-ui'
import { actionableErrorText } from '@/components/admin-feedback'
import UserMenuAuthTree from './UserMenuAuthTree.vue'
const props = defineProps<{ modelValue: boolean; user: AdminUser | null; operatorSuper?: boolean }>()
/** companyId 由 UsersPage 把 companyTab.requestCompanyId 透传进来(本页的用户列表本来就由它筛 ⇒ 目标账号的公司
* 就是 tab 选中的那家);弹窗自己不读 store,公司 tab 的取值口只留在页面组件那一处。 */
const props = defineProps<{ modelValue: boolean; user: AdminUser | null; operatorSuper?: boolean; companyId?: number | null }>()
const emit = defineEmits<{ (e: 'update:modelValue', v: boolean): void; (e: 'updated'): void }>()
const form = reactive<EditUserForm>({ uid: 0, username: '', password: '', role: 'normal', columnIds: [], originalRole: '', expiresAt: '' })
@@ -48,7 +50,7 @@ async function refreshAuth(): Promise<void> {
if (!props.user) return
loadingAuth.value = true
try {
const { checkedIds } = await loadUserMenuAuth(props.user.id)
const { checkedIds } = await loadUserMenuAuth(props.user.id, props.companyId)
form.columnIds = checkedIds
authReady.value = true
} catch (error) {
@@ -133,7 +135,7 @@ async function save(): Promise<void> {
</el-form-item>
<el-form-item label="菜单权限(勾选上级菜单会继承全部子菜单)">
<div class="auth-tree-box">
<UserMenuAuthTree v-model:checked="form.columnIds" />
<UserMenuAuthTree v-model:checked="form.columnIds" :company-id="props.companyId" />
<div v-if="loadingAuth" class="auth-loading">菜单权限加载中…</div>
<div v-else-if="!authReady" class="auth-loading auth-loading-error">
菜单权限加载失败,保存已禁用;请关闭后重试
@@ -2,9 +2,10 @@
import { formatDateTime } from '@/utils/datetime'
/** 菜单权限配置页 · 像素复刻旧版 admin.html panel-columns(自绘:面板头+新增菜单、拖拽手柄 ⠿、树形缩进+└、旧式表格、全量无分页同旧版)。
* script 逻辑沿用现有 Vue 实现(拖拽分组/落点/重排保存、弹窗表单)。 */
import { computed, onMounted, reactive, ref } from 'vue'
import { computed, onMounted, reactive, ref, watch } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import OldPagination from '@/components/OldPagination.vue'
import { useCompanyTabStore } from '@/stores/company-tab'
import { createMenu, deleteMenu, loadMenuManageTree, reorderMenus, updateMenu } from './menu-manage-api'
import {
MENU_TYPE_OPTIONS,
@@ -28,6 +29,7 @@ interface MenuRow extends MenuManageNode {
depth: number
}
const companyTab = useCompanyTabStore()
const loading = ref(false)
const rows = ref<MenuManageNode[]>([])
/** 筛选:菜单名称/类型(用户要求账户域子菜单补筛选条件)。 */
@@ -84,7 +86,7 @@ function parentNameOf(node: MenuManageNode): string {
async function loadMenus() {
loading.value = true
try {
rows.value = await loadMenuManageTree()
rows.value = await loadMenuManageTree(companyTab.requestCompanyId)
} catch (error) {
ElMessage.error(error instanceof Error ? error.message : '菜单列表加载失败')
} finally {
@@ -175,7 +177,7 @@ async function saveMenu() {
await updateMenu(editingNode.value.id, menuForm)
ElMessage.success('保存成功')
} else {
await createMenu(menuForm)
await createMenu(menuForm, companyTab.requestCompanyId)
ElMessage.success('创建成功')
}
createVisible.value = false
@@ -204,6 +206,11 @@ async function removeMenu(node: MenuManageNode) {
}
}
/** 切公司:菜单名称/类型是客户端筛选(在 filteredMenuRows 上筛,不进请求),留着上一家填的值
* 就是拿别家的字符串去筛新一家那一套树 ⇒ 首屏「暂无匹配菜单」而输入框里还显示着它;页码回 1
* 是因为新一家的行数不同。末尾的 void loadMenus() 才是本页唯一的数据出口。 */
watch(() => companyTab.activeId, () => { filterName.value = ''; filterType.value = ''; page.value = 1; void loadMenus() })
onMounted(loadMenus)
</script>
@@ -4,7 +4,7 @@ import type { MenuOptionNode } from './user-menu-auth'
import { compactDirectGrantIds } from './user-menu-auth'
import { fetchGrantableMenus } from './user-menu-auth-api'
const props = defineProps<{ checked?: number[] }>()
const props = defineProps<{ checked?: number[]; companyId?: number | null }>()
const emit = defineEmits<{
(e: 'update:checked', ids: number[]): void
(e: 'load', ok: boolean): void
@@ -42,7 +42,7 @@ function onCheck(): void {
async function load(): Promise<void> {
try {
data.value = await fetchGrantableMenus()
data.value = await fetchGrantableMenus(props.companyId)
loaded.value = true
emit('load', true)
// el-tree 的 store 通过异步 watch 同步 props.data,setCheckedKeys 必须等树
@@ -62,6 +62,12 @@ watch(
if (loaded.value) applyChecked()
},
)
/** 公司换了要整棵重取:勾选集里存的是 column id,别家同名菜单是另一份 id(V149 每公司一套树),
* 拿别家的树勾出来的 id 提交会被后端判「无效的菜单权限项」,而已授权项也因为 id 不在这棵树上勾不上。 */
watch(
() => props.companyId,
() => { void load() },
)
</script>
<template>
@@ -260,7 +260,7 @@ onMounted(() => {
:company-options="companyOptions"
@created="loadUsers"
/>
<EditUserDialog v-model="editVisible" :user="editUser" :operator-super="isSuperAdmin" @updated="loadUsers" />
<EditUserDialog v-model="editVisible" :user="editUser" :operator-super="isSuperAdmin" :company-id="companyTab.requestCompanyId" @updated="loadUsers" />
</div>
</template>
@@ -14,20 +14,27 @@ import {
export const MENUS_ENDPOINT = '/api/admin/permission-menus'
export const REORDER_ENDPOINT = '/api/admin/column/reorder'
/** 拉取扁平可编辑菜单节点(全量类型,对齐 admin.js loadColumns 的 /api/admin/columns 语义)。 */
export async function fetchMenuManageNodes(): Promise<MenuManageNode[]> {
const { data } = await http.get<unknown>(MENUS_ENDPOINT)
/** 拉取扁平可编辑菜单节点(全量类型,对齐 admin.js loadColumns 的 /api/admin/columns 语义)。
* 公司 tab 的值由调用方(MenusPage)传 companyTab.requestCompanyId:菜单字典 2026-10-06 起每家公司一套树,
* 不带 company_id 时非超管恒锁本公司、超管拿到的是全部公司的行(两排同名菜单)。 */
export async function fetchMenuManageNodes(companyId?: number | null): Promise<MenuManageNode[]> {
const query: Record<string, string | number> = {}
if (companyId != null) query.company_id = companyId
const { data } = await http.get<unknown>(MENUS_ENDPOINT, { params: query })
return parseMenuManageList(data)
}
/** 拉取并按 parentId 组装成展示树。 */
export async function loadMenuManageTree(): Promise<MenuManageNode[]> {
return buildMenuManageTree(await fetchMenuManageNodes())
export async function loadMenuManageTree(companyId?: number | null): Promise<MenuManageNode[]> {
return buildMenuManageTree(await fetchMenuManageNodes(companyId))
}
/** 新建菜单:POST /api/admin/permission-menus,返回后端落库节点。 */
export async function createMenu(form: MenuManageForm): Promise<MenuManageNode> {
const { data } = await http.post<unknown>(MENUS_ENDPOINT, toMenuCreateRequest(form))
/** 新建菜单:POST /api/admin/permission-menus,返回后端落库节点。
* 归属由端点的 company_id 决定(缺省=操作者本公司),前端不靠从树里猜。 */
export async function createMenu(form: MenuManageForm, companyId?: number | null): Promise<MenuManageNode> {
const query: Record<string, string | number> = {}
if (companyId != null) query.company_id = companyId
const { data } = await http.post<unknown>(MENUS_ENDPOINT, toMenuCreateRequest(form), { params: query })
const created = parseMenuManageItem(unwrap<unknown>(data))
if (!created) throw new Error('创建菜单响应异常:缺少菜单数据')
return created
@@ -18,11 +18,18 @@ export const USER_PERMISSION_COLUMNS_ENDPOINT = '/api/admin/permission-users'
/**
* 拉取可授权菜单树(后台 admin + 前端客户端 app 两类合并,按 sort 排序)。
* grantableOnly:非超管只拿到自己已持有的菜单,范围外的项后端不再下发。
* <p>companyId 传 companyTab.requestCompanyId:2026-10-06 起每家公司一套菜单树,同一 column_key 在
* 别家有一份**不同 id** 的副本。这一页的授权载荷提交的是 column id,树取错公司就等于
* 把别家的 id 授给本公司账号(后端按「id 必须在被授权账号自己的树里」拒 ⇒ 保存必然失败,
* 而已授权项因为 id 对不上树根本勾不上,看上去像"这个人一条权限都没有")。
* null(非超管、或建号时没指定公司)由后端锁到操作者本公司。
*/
export async function fetchGrantableMenus(): Promise<MenuOptionNode[]> {
export async function fetchGrantableMenus(companyId?: number | null): Promise<MenuOptionNode[]> {
const query: Record<string, string | number> = {}
if (companyId != null) query.company_id = companyId
const [adminRes, appRes] = await Promise.all([
http.get<unknown>(GRANT_MENUS_ENDPOINT, { params: { menuType: ADMIN_MENU_TYPE, grantableOnly: true } }),
http.get<unknown>(GRANT_MENUS_ENDPOINT, { params: { menuType: APP_MENU_TYPE, grantableOnly: true } }),
http.get<unknown>(GRANT_MENUS_ENDPOINT, { params: { ...query, menuType: ADMIN_MENU_TYPE, grantableOnly: true } }),
http.get<unknown>(GRANT_MENUS_ENDPOINT, { params: { ...query, menuType: APP_MENU_TYPE, grantableOnly: true } }),
])
const nodes = [
...parseMenuOptionList(adminRes.data, ADMIN_MENU_TYPE),
@@ -53,8 +60,8 @@ export interface UserMenuAuthData {
checkedIds: number[]
}
export async function loadUserMenuAuth(userId: number): Promise<UserMenuAuthData> {
const [tree, checkedIds] = await Promise.all([fetchGrantableMenus(), fetchUserGrantedColumnIds(userId)])
export async function loadUserMenuAuth(userId: number, companyId?: number | null): Promise<UserMenuAuthData> {
const [tree, checkedIds] = await Promise.all([fetchGrantableMenus(companyId), fetchUserGrantedColumnIds(userId)])
return { tree, checkedIds }
}
@@ -5,7 +5,6 @@ import { formatDateTime } from '@/utils/datetime'
import { computed, onMounted, reactive, ref, watch } from 'vue'
import { ElMessage } from 'element-plus'
import { useAdminSessionStore } from '@/stores/admin-session'
import { useCompanyTabStore } from '@/stores/company-tab'
import { createInvalidAsin, deleteInvalidAsin, fetchInvalidAsinPage, updateInvalidAsin } from '../invalidasin/invalid-asin-api.ts'
import type { InvalidAsinItem } from '../invalidasin/invalid-asin-model.ts'
import { invalidAsinDeleteText, invalidAsinLockedGroupId, recordSourceLabel } from '../invalidasin/invalid-asin-model.ts'
@@ -15,7 +14,6 @@ import type { ShopGroupOption } from '../shop/shop-dto.ts'
import OldPagination from '@/components/OldPagination.vue'
const session = useAdminSessionStore()
const companyTab = useCompanyTabStore()
const loading = ref(false)
const rows = ref<InvalidAsinItem[]>([])
const total = ref(0)
@@ -46,7 +44,7 @@ const groupOptions = computed<ShopGroupOption[]>(() => {
async function loadGroups() {
try {
groups.value = await fetchShopManageGroups(companyTab.requestCompanyId)
groups.value = await fetchShopManageGroups()
} catch {
groups.value = []
}
@@ -65,7 +63,6 @@ async function load() {
dataValue: filter.dataValue.trim() || undefined,
brand: filter.brand.trim() || undefined,
groupId: filter.groupId,
companyId: companyTab.requestCompanyId,
})
rows.value = result.items
total.value = result.total
@@ -163,10 +160,6 @@ watch(isSuperAdmin, () => {
if (isSuperAdmin.value) filter.groupId = null
})
// 切公司 = 重新取数:列表与分组下拉共用这一个 watch(少一个 = 那半边的 tab 是装饰品)。
// groupId 必须一起清掉:上一家选中的分组在新一家根本不存在,留着会把切 tab 后的首屏筛成空列表。
watch(() => companyTab.activeId, () => { filter.groupId = null; void loadGroups(); void load() })
onMounted(() => {
loadGroups()
load()
@@ -1,7 +1,7 @@
<script setup lang="ts">
/** 商品类目 · 像素复刻旧版 admin.html panel-product-categories(自绘:面板头搜索框组+新增类目 同行、原生树表格[+/−]折叠+懒加载「加载更多 已加载 x/y」、搜索态旧式分页)。
* script 逻辑沿用现有 Vue 实现(懒加载树/编辑删除/导出/弹窗)。 */
import { computed, onMounted, reactive, ref, watch } from 'vue'
import { computed, onMounted, reactive, ref } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import { fetchProductCategoryChildren, searchProductCategories } from './product-category-api.ts'
import { createProductCategory, deleteProductCategory, updateProductCategory } from './product-category-editor-api.ts'
@@ -17,9 +17,7 @@ import { categoryDraftError, createProductCategoryDraft, toCategorySaveRequest,
import { buildProductCategoryExportUrl } from './product-category-export.ts'
import { formatDateTime } from '@/utils/datetime'
import OldPagination from '@/components/OldPagination.vue'
import { useCompanyTabStore } from '@/stores/company-tab'
const companyTab = useCompanyTabStore()
const loading = ref(false)
const tree = ref<ProductCategoryNode[]>([])
const keyword = ref('')
@@ -70,7 +68,7 @@ const rootTotal = ref(0)
async function loadTree(): Promise<void> {
loading.value = true
try {
const result = await fetchProductCategoryChildren(null, rootPage.value, rootPageSize.value, companyTab.requestCompanyId)
const result = await fetchProductCategoryChildren(null, rootPage.value, rootPageSize.value)
const state = { page: result.page, total: result.total, hasMore: result.hasMore, loading: false }
childrenState.set(ROOT_KEY, state)
// 顶层当前页直接作为树根(不含合成「加载更多」节点,翻页由 OldPagination 承担)。
@@ -146,7 +144,7 @@ async function loadChildrenPage(parent: ProductCategoryNode | null, page: number
if (state?.loading) return
childrenState.set(key, { page: state?.page ?? 0, total: state?.total ?? 0, hasMore: state?.hasMore ?? false, loading: true })
try {
const result = await fetchProductCategoryChildren(parent?.id ?? null, page, PRODUCT_CATEGORY_DEFAULT_PAGE_SIZE, companyTab.requestCompanyId)
const result = await fetchProductCategoryChildren(parent?.id ?? null, page, PRODUCT_CATEGORY_DEFAULT_PAGE_SIZE)
const loaded = append ? (state?.page ?? 0) + result.items.length : result.items.length
const nextState = { page: result.page, total: result.total, hasMore: result.hasMore, loading: false }
childrenState.set(key, nextState)
@@ -197,7 +195,7 @@ function changeSearchSize(size: number) {
async function runSearch(page: number): Promise<void> {
searchLoading.value = true
try {
const result = await searchProductCategories(keyword.value, page, searchPageSize.value, companyTab.requestCompanyId)
const result = await searchProductCategories(keyword.value, page, searchPageSize.value)
searchRows.value = result.items
searchTotal.value = result.total
searchPage.value = result.page
@@ -299,17 +297,13 @@ async function submit(): Promise<void> {
function exportCategories(): void {
const anchor = document.createElement('a')
anchor.href = buildProductCategoryExportUrl(keyword.value, companyTab.requestCompanyId)
anchor.href = buildProductCategoryExportUrl(keyword.value)
document.body.appendChild(anchor)
anchor.click()
anchor.remove()
ElMessage.success('类目导出已开始下载')
}
// 切公司 = 重新取数。childrenState/expandedIds 必须一起清:这两份是**上一家**的懒加载分页缓存与展开集,
// 留着会把别家的子级行画进新一家的树里(同一个父级 id 在两家的子集不同),而请求本身是对的。
watch(() => companyTab.activeId, () => { childrenState.clear(); expandedIds.value = new Set(); selected.value = null; rootPage.value = 1; void (searching.value ? runSearch(1) : loadTree()) })
onMounted(loadTree)
</script>
@@ -332,14 +326,14 @@ onMounted(loadTree)
<table>
<thead>
<tr>
<th style="width: 34%">类目</th>
<th>层级路径</th>
<th style="width: 90px">排序</th>
<th style="width: 120px">来源</th>
<th>备注</th>
<th style="width: 170px">创建时间</th>
<th style="width: 170px">更新时间</th>
<th style="width: 150px">操作</th>
<th style="width: 220px">类目</th>
<th style="width: 230px">层级路径</th>
<th style="width: 66px">排序</th>
<th style="width: 82px">来源</th>
<th style="width: 170px">备注</th>
<th style="width: 154px">创建时间</th>
<th style="width: 154px">更新时间</th>
<th style="width: 148px">操作</th>
</tr>
</thead>
<tbody v-if="!searching">
@@ -598,7 +592,10 @@ h3 {
table-layout: fixed;
}
.category-table-scroll > table {
min-width: 860px;
/* table-layout:fixed 下,没写宽度的列在容器变窄时第一个被压到 0(10-06 截图:层级路径只剩一个字、
备注只剩破折号)。承重的是 thead 里 8 列全部显式 px 定宽;这个下限与它们成对维护,
数值由 tests/align-product-category.test.ts 从 markup 现算比对,改列宽要同时改这里。 */
min-width: 1224px;
}
.table-scroll th,
.table-scroll td {
@@ -1,4 +1,5 @@
/** 商品类目树/搜索适配(任务 78):GET /api/admin/product-categories(+keyword) 与 /product-categories/search。 */
/** 商品类目树/搜索适配(任务 78):GET /api/admin/product-categories(+keyword) 与 /product-categories/search。
* 2026-10-06 起这一页全平台共享:三个取数口都不带 company_id。 */
import { http } from '@/api/http'
import {
parseProductCategoryList,
@@ -11,10 +12,9 @@ import {
export const PRODUCT_CATEGORY_ENDPOINT = '/api/admin/product-categories'
/** 拉取类目树(keyword 非空时由服务端过滤并保留父路径)。 */
export async function fetchProductCategoryTree(keyword = '', companyId?: number | null): Promise<ProductCategoryListResult> {
export async function fetchProductCategoryTree(keyword = ''): Promise<ProductCategoryListResult> {
const trimmed = keyword.trim()
const params: Record<string, string | number> = trimmed ? { keyword: trimmed } : {}
if (companyId != null) params.company_id = companyId
const { data } = await http.get<unknown>(PRODUCT_CATEGORY_ENDPOINT, { params })
return parseProductCategoryList(data)
}
@@ -24,12 +24,10 @@ export async function searchProductCategories(
keyword: string,
page: number,
pageSize: number,
companyId?: number | null,
): Promise<ProductCategorySearchPage> {
const params: Record<string, string | number> = { page, page_size: pageSize }
const trimmed = keyword.trim()
if (trimmed) params.keyword = trimmed
if (companyId != null) params.company_id = companyId
const { data } = await http.get<unknown>(`${PRODUCT_CATEGORY_ENDPOINT}/search`, { params })
return parseProductCategorySearchPage(data)
}
@@ -47,11 +45,9 @@ export async function fetchProductCategoryChildren(
parentId: number | null,
page: number,
pageSize: number,
companyId?: number | null,
): Promise<ProductCategoryChildrenPage> {
const params: Record<string, string | number> = { page, page_size: pageSize }
if (parentId != null) params.parent_id = parentId
if (companyId != null) params.company_id = companyId
const { data } = await http.get<unknown>(`${PRODUCT_CATEGORY_ENDPOINT}/children`, { params })
const parsed = parseProductCategorySearchPage(data)
return { items: parsed.items, total: parsed.total, page: parsed.page, hasMore: parsed.hasMore }
@@ -3,11 +3,10 @@
export const PRODUCT_CATEGORY_EXPORT_ENDPOINT = '/api/admin/product-categories/export'
/** 导出下载地址:浏览器直接访问该 URL 触发流式下载。
* company_id 与列表同源:导出走的是同一个服务口径,不带它就是把别家类目写进同一份 XLSX。 */
export function buildProductCategoryExportUrl(keyword: string, companyId?: number | null): string {
* 与列表同源:导出走的是同一个服务口径。这一页 2026-10-06 起全平台共享,不带 company_id。 */
export function buildProductCategoryExportUrl(keyword: string): string {
const params: string[] = []
const trimmed = (keyword || '').trim()
if (trimmed) params.push(`keyword=${encodeURIComponent(trimmed)}`)
if (companyId != null) params.push(`company_id=${companyId}`)
return params.length ? `${PRODUCT_CATEGORY_EXPORT_ENDPOINT}?${params.join('&')}` : PRODUCT_CATEGORY_EXPORT_ENDPOINT
}
@@ -12,8 +12,6 @@ export interface InvalidAsinQuery {
dataValue?: string
brand?: string
groupId?: number | null
/** 公司 tab 的值;toQuery 是白名单构造、不点名它,所以由发送口从原始 query 读。 */
companyId?: number | null
}
function trimOrUndefined(value: unknown): string | undefined {
@@ -31,11 +29,8 @@ function toQuery(query: InvalidAsinQuery): Record<string, string | number> {
}
export async function fetchInvalidAsinPage(query: InvalidAsinQuery): Promise<InvalidAsinPageResult> {
// 公司值落在 toQuery 之后、发请求之前的唯一一处:toQuery 是白名单构造(只点名 page/data_value/brand/group_id),
// 所以这里必须从原始 query 读 companyId——从 toQuery 的结果里读是 undefined,请求照发、参数没有。
const params = toQuery(query)
if (query.companyId != null) params.company_id = query.companyId
const { data } = await http.get<unknown>(INVALID_ASIN_ENDPOINT, { params })
// 这一页 2026-10-06 起全平台共享:请求里不许出现 company_id(后端唯一键退回全局见 V151)。
const { data } = await http.get<unknown>(INVALID_ASIN_ENDPOINT, { params: toQuery(query) })
return parseInvalidAsinPage(data)
}
@@ -2,14 +2,16 @@
import { formatDateTime } from '@/utils/datetime'
/** 店铺密钥管理页 · 像素复刻旧版 admin.html panel-shop-keys(自绘:面板头+新增店铺密钥、序号列、令牌掩码、白名单状态药丸+悬停详情、旧式分页)。
* script 逻辑沿用现有 Vue 实现(编辑留空令牌=沿用);弹窗保留现有组件。 */
import { computed, onMounted, reactive, ref } from 'vue'
import { computed, onMounted, reactive, ref, watch } from 'vue'
import { ElMessage } from 'element-plus'
import { useCompanyTabStore } from '@/stores/company-tab'
import { fetchShopKeyList, submitCreateShopKey, updateShopKey, deleteShopKey, checkShopKeyWhitelist } from './shop-key-api.ts'
import { emptyShopKeyForm, normalizeZiniaoToken, validateProxyUrl } from './shop-key-form-model.ts'
import type { ShopKeyItem } from './shop-dto.ts'
import { whitelistStatusMeta } from './shop-key-model.ts'
import OldPagination from '@/components/OldPagination.vue'
const companyTab = useCompanyTabStore()
const loading = ref(false)
const rows = ref<ShopKeyItem[]>([])
const total = ref(0)
@@ -56,7 +58,11 @@ function whitelistTooltip(row: ShopKeyItem): string {
async function load() {
loading.value = true
try {
const result = await fetchShopKeyList({ page: page.value, pageSize: pageSize.value })
const result = await fetchShopKeyList({
page: page.value,
pageSize: pageSize.value,
companyId: companyTab.requestCompanyId,
})
rows.value = result.items
total.value = result.total
page.value = result.page
@@ -172,6 +178,8 @@ function goJump() {
changePage(Math.min(Math.max(n, 1), totalPages.value))
}
watch(() => companyTab.activeId, () => { filterKeyword.value = ''; page.value = 1; void load() })
onMounted(load)
</script>
@@ -81,10 +81,12 @@ export interface ShopGroupOption {
leaderUsername?: string
}
/** 店铺密钥列表分页参数(该接口只支持分页)。 */
/** 店铺密钥列表分页参数(分页 + 公司 tab;归一是白名单构造,不点名 companyId)。 */
export interface ShopKeyListParams {
page: number
pageSize: number
/** 公司 tab 的值;normalizeKeyListParams 不点名它,只有 api 层能从原始 params 读到。 */
companyId?: number | null
}
/** 店铺列表分页/筛选参数。 */
@@ -100,6 +102,8 @@ export interface ShopManageListParams {
export interface ShopKeyPageQuery {
page: number
pageSize: number
/** 下划线形:与后端 @RequestParam(name = "company_id") 逐字对齐。 */
company_id?: number
}
export interface ShopManagePageQuery {
@@ -19,7 +19,11 @@ export const SHOP_KEYS_ENDPOINT = '/api/admin/shop-keys'
export async function fetchShopKeyList(params: Partial<ShopKeyListParams> = {}): Promise<ShopKeyPageResult> {
const normalized = normalizeKeyListParams(params)
const { data } = await http.get<unknown>(SHOP_KEYS_ENDPOINT, { params: toKeyPageQuery(normalized) })
// normalizeKeyListParams 与 toKeyPageQuery 都是白名单构造(不点名 companyId),
// 所以公司值只能从原始 params 读:写成 normalized.companyId 是 TS 绿、运行时恒 undefined。
const query = toKeyPageQuery(normalized)
if (params.companyId != null) query.company_id = params.companyId
const { data } = await http.get<unknown>(SHOP_KEYS_ENDPOINT, { params: query })
return parseShopKeyPage(data)
}
+6 -6
View File
@@ -19,26 +19,26 @@ export interface AdminPageDef extends AdminPageMeta {
/** 业务域路由注册表(任务 8):首批 account 域;后续按业务域在此登记页面。 */
export const adminPages: AdminPageDef[] = [
{ path: 'account/users', menuKey: 'admin_users', title: '用户管理', companyScoped: true, load: () => import('@/pages/account/UsersPage.vue') },
{ path: 'account/menus', menuKey: 'admin_columns', title: '菜单管理', load: () => import('@/pages/account/MenusPage.vue') },
{ path: 'account/menus', menuKey: 'admin_columns', title: '菜单管理', companyScoped: true, load: () => import('@/pages/account/MenusPage.vue') },
{ path: 'account/groups', menuKey: 'admin_group_manage', title: '数据权限分组', companyScoped: true, load: () => import('@/pages/account/GroupsPage.vue') },
{ path: 'account/user-secrets', menuKey: 'admin_user_secrets', title: '密钥管理', companyScoped: true, load: () => import('@/pages/account/UserSecretsPage.vue') },
{ path: 'account/user-secret-usage', menuKey: 'admin_user_secret_usage', title: '密钥用量统计', companyScoped: true, load: () => import('@/pages/account/UserSecretUsagePage.vue') },
{ path: 'account/companies', menuKey: 'admin_companies', title: '公司管理', superAdminOnly: true, load: () => import('@/pages/account/CompaniesPage.vue') },
{ path: 'shop-center/duplicate-check', menuKey: 'admin_shop_data_duplicate_check', title: '店铺撞款监控', companyScoped: true, load: () => import('@/pages/tasks/DuplicateCheckPage.vue') },
{ path: 'shop-center/keys', menuKey: 'admin_shop_keys', title: '店铺密钥管理', companyScoped: false, load: () => import('@/pages/shop/ShopKeysPage.vue') },
{ path: 'shop-center/keys', menuKey: 'admin_shop_keys', title: '店铺密钥管理', companyScoped: true, load: () => import('@/pages/shop/ShopKeysPage.vue') },
{ path: 'shop-center/shops', menuKey: 'admin_shop_manage', title: '店铺管理', companyScoped: true, load: () => import('@/pages/shop/ShopManagePage.vue') },
{ path: 'records/history', menuKey: 'admin_history', title: '生成记录', companyScoped: true, load: () => import('@/pages/records/RecordsHistoryPage.vue') },
{ path: 'records/software-version', menuKey: 'admin_version', title: '软件版本管理', load: () => import('@/pages/records/RecordsSoftwareVersionPage.vue') },
{ path: 'records/tutorial', menuKey: 'admin_tutorial', title: '教程管理', load: () => import('@/pages/records/RecordsTutorialPage.vue') },
{ path: 'records/software-version', menuKey: 'admin_version', title: '软件版本管理', companyScoped: false, load: () => import('@/pages/records/RecordsSoftwareVersionPage.vue') },
{ path: 'records/tutorial', menuKey: 'admin_tutorial', title: '教程管理', companyScoped: false, load: () => import('@/pages/records/RecordsTutorialPage.vue') },
{ path: 'records/device-logs', menuKey: 'admin_device_logs', title: '日志管理', companyScoped: true, load: () => import('@/pages/records/DeviceLogsPage.vue') },
{ path: 'task-center/board', menuKey: 'admin_task_center', title: '客户端任务管理', companyScoped: true, load: () => import('@/pages/task-center/TaskCenterBoardPage.vue') },
{ path: 'records/digital-human-version', menuKey: 'digital_human_version', title: '数字人版本管理', load: () => import('@/pages/records/RecordsDigitalHumanVersionPage.vue') },
{ path: 'records/image-video-tasks', menuKey: 'admin_image_video_tasks', title: '视频任务记录', companyScoped: true, load: () => import('@/pages/tasks/ImageVideoTasksPage.vue') },
{ path: 'shop-center/data-tasks', menuKey: 'admin_shop_data_crawl_tasks', title: '店铺数据记录', companyScoped: true, load: () => import('@/pages/tasks/ShopDataTasksPage.vue') },
{ path: 'asin-center/registry', menuKey: 'admin_dedupe_total_data', title: '数据去重总数据', companyScoped: true, load: () => import('@/pages/asin/DedupeRegistryPage.vue') },
{ path: 'asin-center/invalid', menuKey: 'admin_invalid_asin_data', title: '不符合ASIN数据', companyScoped: true, load: () => import('@/pages/asin/AsinInvalidPage.vue') },
{ path: 'asin-center/invalid', menuKey: 'admin_invalid_asin_data', title: '品牌数据库', companyScoped: false, load: () => import('@/pages/asin/AsinInvalidPage.vue') },
{ path: 'asin-center/query', menuKey: 'admin_query_asin', title: '查询ASIN', companyScoped: true, load: () => import('@/pages/asin/QueryAsinPage.vue') },
{ path: 'asin-center/categories', menuKey: 'admin_product_categories', title: '商品类目', companyScoped: true, load: () => import('@/pages/asin/ProductCategoryPage.vue') },
{ path: 'asin-center/categories', menuKey: 'admin_product_categories', title: '商品类目', companyScoped: false, load: () => import('@/pages/asin/ProductCategoryPage.vue') },
{ path: 'asin-center/skip-price', menuKey: 'admin_skip_price_asin', title: '最低价ASIN', companyScoped: true, load: () => import('@/pages/asin/SkipPricePage.vue') },
]