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
@@ -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
}