fix(site): 阻止经营租户携带旧分销站点编码
This commit is contained in:
@@ -177,6 +177,8 @@ export function shouldProbeTenantContext(
|
|||||||
*/
|
*/
|
||||||
export function getEffectiveSiteCode(): string {
|
export function getEffectiveSiteCode(): string {
|
||||||
if (typeof window === 'undefined') return ''
|
if (typeof window === 'undefined') return ''
|
||||||
|
// 经营租户站点不能同时携带旧分销站点编码,否则列表和下单会走旧分销过滤。
|
||||||
|
if (sessionStorage.getItem('hfb_tenant_code')) return ''
|
||||||
const envCode = ((import.meta.env.VITE_DISTRIBUTION_SITE_CODE as string) || '').trim()
|
const envCode = ((import.meta.env.VITE_DISTRIBUTION_SITE_CODE as string) || '').trim()
|
||||||
if (envCode) return envCode
|
if (envCode) return envCode
|
||||||
|
|
||||||
@@ -321,6 +323,7 @@ export const useDistributionSiteStore = defineStore('distributionSite', {
|
|||||||
this.features = {}
|
this.features = {}
|
||||||
this.domain = info.domain || ''
|
this.domain = info.domain || ''
|
||||||
this.isDistribution = true
|
this.isDistribution = true
|
||||||
|
sessionStorage.removeItem('hfb_tenant_code')
|
||||||
this.displayAccountEnabled = info.display_account_enabled ?? true
|
this.displayAccountEnabled = info.display_account_enabled ?? true
|
||||||
this.defaultSupportGroupId = info.default_support_group_id ?? null
|
this.defaultSupportGroupId = info.default_support_group_id ?? null
|
||||||
this.logoUrl = info.logo_url || ''
|
this.logoUrl = info.logo_url || ''
|
||||||
@@ -415,6 +418,7 @@ export const useDistributionSiteStore = defineStore('distributionSite', {
|
|||||||
this.storefrontText = { ...defaultStorefrontText }
|
this.storefrontText = { ...defaultStorefrontText }
|
||||||
this.receiveRatioDelta = 0
|
this.receiveRatioDelta = 0
|
||||||
this.receiveCostDelta = 0
|
this.receiveCostDelta = 0
|
||||||
|
sessionStorage.removeItem('hfb_tenant_code')
|
||||||
sessionStorage.removeItem('hfb_site_code')
|
sessionStorage.removeItem('hfb_site_code')
|
||||||
sessionStorage.removeItem('hfb_site_name')
|
sessionStorage.removeItem('hfb_site_name')
|
||||||
localStorage.removeItem('hfb_site_code')
|
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.receiveRatioDelta = Math.max(0, Number(profile.receive_ratio_delta || 0))
|
||||||
this.receiveCostDelta = Math.max(0, Number(profile.receive_cost_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_code')
|
||||||
sessionStorage.removeItem('hfb_site_name')
|
sessionStorage.removeItem('hfb_site_name')
|
||||||
localStorage.removeItem('hfb_site_code')
|
localStorage.removeItem('hfb_site_code')
|
||||||
|
|||||||
@@ -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', () => {
|
describe('shouldProbeTenantContext', () => {
|
||||||
|
afterEach(() => sessionStorage.clear())
|
||||||
|
|
||||||
it('正式域名优先探测经营租户', () => {
|
it('正式域名优先探测经营租户', () => {
|
||||||
expect(shouldProbeTenantContext('zuhaox.com', '', '')).toBe(true)
|
expect(shouldProbeTenantContext('zuhaox.com', '', '')).toBe(true)
|
||||||
expect(shouldProbeTenantContext('hfb.example.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_a', '')).toBe(true)
|
||||||
expect(shouldProbeTenantContext('zuhaox.com', '', 'branch_b')).toBe(true)
|
expect(shouldProbeTenantContext('zuhaox.com', '', 'branch_b')).toBe(true)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('经营租户上下文不回退为旧分销站点编码', () => {
|
||||||
|
sessionStorage.setItem('hfb_tenant_code', 'jieyou')
|
||||||
|
expect(getEffectiveSiteCode()).toBe('')
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user