feat(distribution): 独立分销前台商城多租户体系、货源与订单数据严格隔离

This commit is contained in:
yml2213
2026-09-07 17:18:14 +08:00
parent 550b42eb22
commit ecaf15417b
34 changed files with 2397 additions and 119 deletions
+106
View File
@@ -0,0 +1,106 @@
import { defineStore } from 'pinia'
import { apiClient } from '@/shared/api/client'
import type { ApiResponse } from '@/shared/types/types'
export interface DistributionSiteInfo {
site_code: string
site_name: string
domain: string
status: string
display_account_enabled: boolean
default_support_group_id?: number | null
}
export const useDistributionSiteStore = defineStore('distributionSite', {
state: () => ({
siteCode: localStorage.getItem('hfb_site_code') || '',
siteName: localStorage.getItem('hfb_site_name') || '大锤商行',
domain: '',
isDistribution: Boolean(localStorage.getItem('hfb_site_code')),
displayAccountEnabled: true,
defaultSupportGroupId: null as number | null,
initialized: false,
}),
actions: {
async initSite() {
// 1. Check URL query params: ?site=xxx or ?site_code=xxx
const urlParams = new URLSearchParams(window.location.search)
const querySite = (
urlParams.get('site') ||
urlParams.get('site_code') ||
urlParams.get('distribution_site_code') ||
''
).trim()
if (querySite) {
if (querySite === 'main' || querySite === 'clear' || querySite === '0') {
this.resetToMainSite()
this.initialized = true
return
}
this.siteCode = querySite
localStorage.setItem('hfb_site_code', querySite)
}
const effectiveCode = this.siteCode || localStorage.getItem('hfb_site_code') || ''
const hostname = window.location.hostname
// If we have a site code, query by code.
// Otherwise query by domain (for independent domain access in production).
let queryUrl = ''
if (effectiveCode) {
queryUrl = `/distribution/site-info?code=${encodeURIComponent(effectiveCode)}`
} else if (hostname && hostname !== 'localhost' && hostname !== '127.0.0.1') {
queryUrl = `/distribution/site-info?domain=${encodeURIComponent(hostname)}`
}
if (!queryUrl) {
this.resetToMainSite()
this.initialized = true
return
}
try {
const { data } = await apiClient.get<ApiResponse<DistributionSiteInfo>>(queryUrl, {
silent: true,
skipErrorHandler: true,
})
const info = data.data
if (info && info.site_code && info.status === 'active') {
this.siteCode = info.site_code
this.siteName = info.site_name || info.site_code
this.domain = info.domain || ''
this.isDistribution = true
this.displayAccountEnabled = info.display_account_enabled ?? true
this.defaultSupportGroupId = info.default_support_group_id ?? null
localStorage.setItem('hfb_site_code', this.siteCode)
localStorage.setItem('hfb_site_name', this.siteName)
// Update page title
document.title = `【${this.siteName}】租号商城 - 精选游戏账号平台`
} else {
this.resetToMainSite()
}
} catch {
// If site code was invalid or not found, fall back to main site
this.resetToMainSite()
} finally {
this.initialized = true
}
},
resetToMainSite() {
this.siteCode = ''
this.siteName = '大锤商行'
this.domain = ''
this.isDistribution = false
this.displayAccountEnabled = true
this.defaultSupportGroupId = null
localStorage.removeItem('hfb_site_code')
localStorage.removeItem('hfb_site_name')
document.title = '大锤商行 - 官方租号平台'
},
},
})