feat(admin): 公司tab条按平台分侧+京东分组作用域只认jd档(2026-11-17 用户口径「亚马逊侧别挂京东-团队,同理京东那边也是」)

- company-tab store:目录按当前平台 tab 拉(loadedPlatform 对撞早退),切台重拉;旧选中仍在新清单则保住,不在回落 id 最小启用公司;新增 refresh() 强制档(公司翻档/启停后 18 页 tab 条同步)
This commit is contained in:
2026-11-17 11:50:13 +08:00
parent dc3e7f3b37
commit ee613db05b
7 changed files with 307 additions and 46 deletions
+28 -4
View File
@@ -2,6 +2,8 @@ import { defineStore } from 'pinia'
import { fetchCompanies } from '@/api/companies'
import type { CompanyItem } from '@/api/companies-dto'
import { useAdminSessionStore } from '@/stores/admin-session'
import { usePlatformTabStore } from '@/stores/platform-tab'
import type { PlatformTabId } from '@/config/platform-scope'
import { firstSelectableCompanyId, companyIdForRequest } from '@/layout/company-tab-model'
/** 公司 tab 的状态。成员 user ids **不在这里缓存**——每次请求交后端解析,
@@ -12,6 +14,11 @@ export const useCompanyTabStore = defineStore('company-tab', {
activeId: null as number | null,
loading: false,
loaded: false,
/** 当前这份目录是按哪个平台 tab 拉的(V206 平台分侧,2026-11-17 用户口径「公司 tab
* 条也按平台分侧,两边各看各的公司」)。空串=还没按平台拉过。早退闸拿它对撞当前
* tab:一致才免拉,平台切了就重拉一份;`fetchCompanies` 失败时不翻转它,旧清单
* (可能过时)继续顶着,下一次切台/重进页面会再试。 */
loadedPlatform: '' as PlatformTabId | '',
/** GET /companies 失败时的原因。**只住 store 与 console,不在模板里渲染**——
* §12 第 5 条没批任何新的用户可见提示,接口暴露禁令高于"失败可见"。
* 取不到目录时 loaded 保持 false ⇒ visibleForOperator 为 false ⇒ tab 条整体不画(fail-closed,观感与改前一致)。 */
@@ -35,15 +42,27 @@ export const useCompanyTabStore = defineStore('company-tab', {
},
},
actions: {
async initialize() {
/** 拉公司目录(按当前平台 tab 过滤,后端 GET /api/admin/companies?platform=…)。
* `force`=绕开「该平台已拉过」的早退闸(公司编辑弹窗翻档/启停后的 refresh 用),
* 旧清单保留到成功那刻再整份替换,取数期间 tab 条不闪空。 */
async initialize(options?: { force?: boolean }) {
const session = useAdminSessionStore()
if (this.loaded || this.loading || !session.isSuperAdmin) return
const platform = usePlatformTabStore().active
const alreadyLoadedForThisPlatform = this.loaded && this.loadedPlatform === platform
if ((!options?.force && alreadyLoadedForThisPlatform) || this.loading || !session.isSuperAdmin) return
this.loading = true
// 失败后 loaded 仍是 false ⇒ 下一次 watch 命中超管会重试;重试前先清掉旧原因,免得留着一条已经翻篇的错误。
this.error = ''
try {
this.companies = await fetchCompanies()
this.activeId = firstSelectableCompanyId(this.companies)
const companies = await fetchCompanies(platform)
this.companies = companies
this.loadedPlatform = platform
// 换台重拉后旧选中未必还在新清单里(跨平台公司不重叠):还在就保住(别的页可能正按它取数),
// 不在就回落「id 最小的启用公司」。force 重拉同平台时,选中公司仍在 ⇒ 选中不跳。
const stillListed = this.activeId !== null && companies.some((c) => c.id === this.activeId)
if (!stillListed) {
this.activeId = firstSelectableCompanyId(companies)
}
this.loaded = true
} catch (error) {
// 2026-10-05 修复轮 1:改前只有 try/finally ⇒ GET /companies 抛错时零痕迹(loaded 永远 false、
@@ -57,6 +76,11 @@ export const useCompanyTabStore = defineStore('company-tab', {
this.loading = false
}
},
/** 公司目录被编辑(公司管理翻档/启停/改名)后的强制重拉:不受 loadedPlatform 早退闸
* 限制。失败语义与 initialize 同口径(error + rethrow),调用方自行决定要不要提示。 */
async refresh() {
await this.initialize({ force: true })
},
setActiveId(id: number) {
this.activeId = id
},