fix(site): 阻止经营租户携带旧分销站点编码

This commit is contained in:
yml
2026-11-15 18:51:30 +08:00
parent 05e9dce988
commit 8744e0f391
2 changed files with 14 additions and 2 deletions
+5
View File
@@ -177,6 +177,8 @@ export function shouldProbeTenantContext(
*/
export function getEffectiveSiteCode(): string {
if (typeof window === 'undefined') return ''
// 经营租户站点不能同时携带旧分销站点编码,否则列表和下单会走旧分销过滤。
if (sessionStorage.getItem('hfb_tenant_code')) return ''
const envCode = ((import.meta.env.VITE_DISTRIBUTION_SITE_CODE as string) || '').trim()
if (envCode) return envCode
@@ -321,6 +323,7 @@ export const useDistributionSiteStore = defineStore('distributionSite', {
this.features = {}
this.domain = info.domain || ''
this.isDistribution = true
sessionStorage.removeItem('hfb_tenant_code')
this.displayAccountEnabled = info.display_account_enabled ?? true
this.defaultSupportGroupId = info.default_support_group_id ?? null
this.logoUrl = info.logo_url || ''
@@ -415,6 +418,7 @@ export const useDistributionSiteStore = defineStore('distributionSite', {
this.storefrontText = { ...defaultStorefrontText }
this.receiveRatioDelta = 0
this.receiveCostDelta = 0
sessionStorage.removeItem('hfb_tenant_code')
sessionStorage.removeItem('hfb_site_code')
sessionStorage.removeItem('hfb_site_name')
localStorage.removeItem('hfb_site_code')
@@ -453,6 +457,7 @@ export const useDistributionSiteStore = defineStore('distributionSite', {
this.receiveRatioDelta = Math.max(0, Number(profile.receive_ratio_delta || 0))
this.receiveCostDelta = Math.max(0, Number(profile.receive_cost_delta || 0))
sessionStorage.setItem('hfb_tenant_code', this.tenantCode)
sessionStorage.removeItem('hfb_site_code')
sessionStorage.removeItem('hfb_site_name')
localStorage.removeItem('hfb_site_code')
+9 -2
View File
@@ -1,8 +1,10 @@
import { describe, expect, it } from 'vitest'
import { afterEach, describe, expect, it } from 'vitest'
import { shouldProbeTenantContext } from './distributionSite'
import { getEffectiveSiteCode, shouldProbeTenantContext } from './distributionSite'
describe('shouldProbeTenantContext', () => {
afterEach(() => sessionStorage.clear())
it('正式域名优先探测经营租户', () => {
expect(shouldProbeTenantContext('zuhaox.com', '', '')).toBe(true)
expect(shouldProbeTenantContext('hfb.example.com', '', '')).toBe(true)
@@ -21,4 +23,9 @@ describe('shouldProbeTenantContext', () => {
expect(shouldProbeTenantContext('zuhaox.com', 'branch_a', '')).toBe(true)
expect(shouldProbeTenantContext('zuhaox.com', '', 'branch_b')).toBe(true)
})
it('经营租户上下文不回退为旧分销站点编码', () => {
sessionStorage.setItem('hfb_tenant_code', 'jieyou')
expect(getEffectiveSiteCode()).toBe('')
})
})