feat(platform-ops): 增加平台运营统计总览页面

This commit is contained in:
yml
2026-11-15 21:31:26 +08:00
parent 5ba893cfde
commit 991de90136
13 changed files with 793 additions and 24 deletions
+2 -1
View File
@@ -20,10 +20,11 @@
- 主站前台地址:`http://localhost:5189`
- 主站后台地址:`http://localhost:5189/admin/login`(超级管理员默认 `admin` / `admin123456`)
- 平台运营统计后台:`http://ops.localhost:5189/admin/login`(仅平台超级管理员,只读统计)
- 分销管理后台:`http://localhost:5190`(在主站后台“分销站点”开通站点并配置分销操作员登录)
- 分销专属前台:`http://localhost:5191`(独立端口隔离,支持 Host 域名与 X-Distribution-Site 头识别站点)
> 生产环境不使用上述端口:Caddy 按域名分流,分销管理后台固定为 `https://distribution.<CADDY_DOMAIN>`(见 `deploy/caddy/Caddyfile`)。主站后台的「打开独立分销后台」与开通凭证通过构建期 `VITE_DISTRIBUTION_ADMIN_URL` 注入该地址;未配置时按当前主站域名推导。
> 生产环境不使用上述端口:Caddy 按域名分流,分销管理后台固定为 `https://distribution.<CADDY_DOMAIN>`,平台运营统计后台固定为 `https://ops.<CADDY_DOMAIN>`(见 `deploy/caddy/Caddyfile`)。主站后台的「打开独立分销后台」与开通凭证通过构建期 `VITE_DISTRIBUTION_ADMIN_URL` 注入该地址;未配置时按当前主站域名推导。
如需拆分调试,可手动执行:
+3 -1
View File
@@ -4,6 +4,7 @@
```text
https://主站域名 # CADDY_DOMAIN,哈夫币系统
https://ops.主站域名 # 平台运营只读统计后台,仅平台超级管理员
https://选号网域名 # CADDY_SHOW_DOMAIN(可选),hfb_show 静态选号站
https://monitor.主站域名 # Beszel 监控
```
@@ -12,7 +13,7 @@ https://monitor.主站域名 # Beszel 监控
部署前请确认:
- 主站域名 A 记录已解析到服务器公网 IP;启用选号网时,选号网域名也要解析到同一 IP。
- 主站域名和 `ops.主站域名` A 记录已解析到服务器公网 IP;启用选号网时,选号网域名也要解析到同一 IP。
- 服务器安全组或防火墙已放行 `80/tcp` 和 `443/tcp`。
- 服务器上没有其他服务占用 `80`、`443`。
- 国内服务器如需对外访问,请先确认域名备案和云厂商限制。
@@ -229,6 +230,7 @@ curl "https://选号网域名/api/listings?page=1&page_size=1"
```text
https://主站域名
https://主站域名/你配置的后台入口/login
https://ops.主站域名/你配置的后台入口/login # 平台运营统计后台
https://选号网域名 # 选号网首页
```
@@ -0,0 +1,24 @@
import { describe, expect, it, vi } from 'vitest'
const apiClient = vi.hoisted(() => ({
get: vi.fn(),
}))
vi.mock('@/shared/api/client', () => ({ apiClient }))
import { fetchPlatformOverview } from './platformOps'
describe('platform ops API', () => {
it('loads the read-only platform overview', async () => {
const payload = {
generated_at: '2026-11-15T20:00:00+08:00',
totals: { tenant_count: 2 },
sites: [{ tenant_code: 'jieyou' }],
trend: [{ date: '2026-11-15' }],
}
apiClient.get.mockResolvedValueOnce({ data: { data: payload } })
await expect(fetchPlatformOverview()).resolves.toEqual(payload)
expect(apiClient.get).toHaveBeenCalledWith('/admin/platform/overview')
})
})
@@ -0,0 +1,63 @@
import { apiClient } from '@/shared/api/client'
import type { ApiResponse } from '@/shared/types/types'
export interface PlatformTotals {
tenant_count: number
active_tenant_count: number
user_count: number
verified_users: number
today_new_users: number
total_listings: number
published_listings: number
today_new_listings: number
pending_reviews: number
total_orders: number
paid_orders: number
renting_orders: number
today_orders: number
today_gmv_cent: number
paid_gmv_cent: number
pending_disputes: number
pending_handoffs: number
pending_returns: number
}
export interface PlatformSiteStats {
tenant_id: number
tenant_code: string
tenant_name: string
status: string
user_count: number
verified_users: number
today_new_users: number
total_listings: number
published_listings: number
pending_reviews: number
buyer_orders: number
buyer_gmv_cent: number
source_orders: number
source_amount_cent: number
renting_orders: number
today_orders: number
today_gmv_cent: number
}
export interface PlatformTrendPoint {
date: string
new_users: number
new_listings: number
orders: number
paid_gmv_cent: number
}
export interface PlatformOverview {
generated_at: string
totals: PlatformTotals
sites: PlatformSiteStats[]
trend: PlatformTrendPoint[]
}
export async function fetchPlatformOverview() {
const { data } = await apiClient.get<ApiResponse<PlatformOverview>>('/admin/platform/overview')
return data.data
}
@@ -8,7 +8,7 @@ import { useRoute, useRouter } from 'vue-router'
import { fetchAdminCaptcha, type AdminCaptcha } from '@/features/admin'
import { useAdminSessionStore } from '@/stores/adminSession'
import { useDistributionSiteStore } from '@/stores/distributionSite'
import { ADMIN_DASHBOARD_PATH, isAdminPath } from '@/shared/utils/adminPath'
import { ADMIN_DASHBOARD_PATH, PLATFORM_OPS_PATH, isAdminPath } from '@/shared/utils/adminPath'
const router = useRouter()
const route = useRoute()
@@ -48,7 +48,12 @@ async function handleLogin() {
)
ElMessage.success('后台登录成功')
const redirect = typeof route.query.redirect === 'string' ? route.query.redirect : ''
await router.push(isAdminPath(redirect) ? redirect : ADMIN_DASHBOARD_PATH)
const destination = siteStore.isPlatformOps
? PLATFORM_OPS_PATH
: isAdminPath(redirect)
? redirect
: ADMIN_DASHBOARD_PATH
await router.push(destination)
} catch (error) {
ElMessage.error(readError(error, '后台登录失败'))
await loadCaptcha()
@@ -67,7 +72,9 @@ async function handleLogin() {
<div class="admin-login-left">
<div class="brand-lockup">
<div class="brand-logo">{{ siteStore.brandMark }}</div>
<strong>{{ siteStore.siteName }} · 后台管理</strong>
<strong
>{{ siteStore.siteName }}{{ siteStore.isPlatformOps ? '' : ' · 后台管理' }}</strong
>
</div>
<div class="admin-login-hero">
<h2>高效管理<br />从容掌控</h2>
@@ -75,7 +82,9 @@ async function handleLogin() {
<div class="login-site-scope">
<span>当前登录站点</span>
<strong>{{ siteStore.siteName }}</strong>
<em>{{ siteStore.isTenant ? '经营站点' : '站点后台' }}</em>
<em>{{
siteStore.isPlatformOps ? '只读统计' : siteStore.isTenant ? '经营站点' : '站点后台'
}}</em>
</div>
</div>
<div class="admin-login-footer">
@@ -0,0 +1,560 @@
<script setup lang="ts">
import {
Calendar,
Coin,
DataLine,
Refresh,
Shop,
TrendCharts,
User,
Warning,
} from '@element-plus/icons-vue'
import { computed, onMounted, ref } from 'vue'
import {
fetchPlatformOverview,
type PlatformOverview,
type PlatformTrendPoint,
} from '@/features/admin/api/platformOps'
import { formatCentWithSymbol } from '@/shared/utils/money'
import { formatDateTime } from '@/shared/utils/time'
import { readError } from '@/shared/utils/error'
const loading = ref(false)
const error = ref('')
const overview = ref<PlatformOverview | null>(null)
const trendMaxOrders = computed(() =>
Math.max(1, ...(overview.value?.trend || []).map(item => item.orders))
)
const trendMaxGMV = computed(() =>
Math.max(1, ...(overview.value?.trend || []).map(item => item.paid_gmv_cent))
)
async function loadOverview() {
loading.value = true
error.value = ''
try {
overview.value = await fetchPlatformOverview()
} catch (err) {
error.value = readError(err, '平台统计加载失败')
} finally {
loading.value = false
}
}
function barHeight(value: number, max: number) {
return `${Math.max(8, Math.round((value / max) * 100))}%`
}
function shortDate(value: string) {
return value.length >= 10 ? value.slice(5) : value
}
function trendOrders(row: PlatformTrendPoint) {
return row.orders
}
onMounted(loadOverview)
</script>
<template>
<section class="platform-page">
<header class="platform-header">
<div>
<p class="platform-eyebrow">
<el-icon><DataLine /></el-icon>
PLATFORM OVERVIEW
</p>
<h1>平台运营总览</h1>
<p>汇总大锤商行、解忧商行及后续经营站点的核心经营数据,仅用于查看统计。</p>
</div>
<div class="platform-header-actions">
<span v-if="overview" class="platform-updated">
更新于 {{ formatDateTime(overview.generated_at) }}
</span>
<el-button :icon="Refresh" :loading="loading" @click="loadOverview">刷新统计</el-button>
</div>
</header>
<div v-if="loading && !overview" class="platform-state">
<el-icon class="is-loading"><DataLine /></el-icon>
正在汇总平台数据...
</div>
<div v-else-if="error && !overview" class="platform-state platform-state--error">
<el-icon><Warning /></el-icon>
<span>{{ error }}</span>
<el-button @click="loadOverview">重试</el-button>
</div>
<template v-else-if="overview">
<section class="platform-metrics">
<article class="platform-metric metric-sites">
<el-icon><Shop /></el-icon>
<div>
<span>经营站点</span>
<strong>{{ overview.totals.active_tenant_count }}</strong>
<small>共 {{ overview.totals.tenant_count }} 个站点</small>
</div>
</article>
<article class="platform-metric metric-users">
<el-icon><User /></el-icon>
<div>
<span>平台用户</span>
<strong>{{ overview.totals.user_count }}</strong>
<small
>实名 {{ overview.totals.verified_users }} · 今日新增
{{ overview.totals.today_new_users }}</small
>
</div>
</article>
<article class="platform-metric metric-listings">
<el-icon><TrendCharts /></el-icon>
<div>
<span>在售商品</span>
<strong>{{ overview.totals.published_listings }}</strong>
<small
>商品总数 {{ overview.totals.total_listings }} · 待审核
{{ overview.totals.pending_reviews }}</small
>
</div>
</article>
<article class="platform-metric metric-gmv">
<el-icon><Coin /></el-icon>
<div>
<span>累计成交额</span>
<strong>{{ formatCentWithSymbol(overview.totals.paid_gmv_cent) }}</strong>
<small>有效订单 {{ overview.totals.paid_orders }} 笔</small>
</div>
</article>
<article class="platform-metric metric-today">
<el-icon><Calendar /></el-icon>
<div>
<span>今日成交</span>
<strong>{{ formatCentWithSymbol(overview.totals.today_gmv_cent) }}</strong>
<small>今日订单 {{ overview.totals.today_orders }} 笔</small>
</div>
</article>
</section>
<section class="platform-panel">
<div class="platform-panel-head">
<div>
<h2>分站经营统计</h2>
<p>每个经营站点独立统计用户、货源、买入订单和出货订单。</p>
</div>
<div class="platform-pending">
<span>待处理</span>
<strong>
审核 {{ overview.totals.pending_reviews }} · 申诉
{{ overview.totals.pending_disputes }}
</strong>
<small>
交接 {{ overview.totals.pending_handoffs }} · 归还确认
{{ overview.totals.pending_returns }}
</small>
</div>
</div>
<el-table class="platform-site-table" :data="overview.sites" stripe>
<el-table-column label="站点" min-width="160" fixed="left">
<template #default="{ row }">
<div class="platform-site-name">
<strong>{{ row.tenant_name }}</strong>
<small>{{ row.tenant_code }}</small>
</div>
</template>
</el-table-column>
<el-table-column label="状态" width="90">
<template #default="{ row }">
<el-tag :type="row.status === 'active' ? 'success' : 'info'" size="small">
{{ row.status === 'active' ? '运营中' : '已停用' }}
</el-tag>
</template>
</el-table-column>
<el-table-column label="用户" min-width="150" align="right">
<template #default="{ row }">
<strong>{{ row.user_count }}</strong>
<span class="platform-cell-sub"
>实名 {{ row.verified_users }} · 今日 +{{ row.today_new_users }}</span
>
</template>
</el-table-column>
<el-table-column label="商品" min-width="170" align="right">
<template #default="{ row }">
<strong>{{ row.published_listings }}</strong>
<span class="platform-cell-sub"
>总数 {{ row.total_listings }} · 待审 {{ row.pending_reviews }}</span
>
</template>
</el-table-column>
<el-table-column label="本站买入" min-width="150" align="right">
<template #default="{ row }">
<strong>{{ row.buyer_orders }} 单</strong>
<span class="platform-cell-sub">{{ formatCentWithSymbol(row.buyer_gmv_cent) }}</span>
</template>
</el-table-column>
<el-table-column label="本站出货" min-width="150" align="right">
<template #default="{ row }">
<strong>{{ row.source_orders }} 单</strong>
<span class="platform-cell-sub">{{
formatCentWithSymbol(row.source_amount_cent)
}}</span>
</template>
</el-table-column>
<el-table-column label="今日" min-width="150" align="right">
<template #default="{ row }">
<strong>{{ row.today_orders }} 单</strong>
<span class="platform-cell-sub">{{ formatCentWithSymbol(row.today_gmv_cent) }}</span>
</template>
</el-table-column>
<el-table-column label="租用中" width="100" align="right">
<template #default="{ row }">{{ row.renting_orders }}</template>
</el-table-column>
</el-table>
</section>
<section class="platform-panel">
<div class="platform-panel-head">
<div>
<h2>近 7 日平台趋势</h2>
<p>新增用户、新增商品、有效订单和成交额按北京时间自然日汇总。</p>
</div>
<div class="platform-trend-legend">
<span><em class="legend-orders" />有效订单</span>
<span><em class="legend-gmv" />成交额</span>
</div>
</div>
<div class="platform-trend-grid">
<article v-for="item in overview.trend" :key="item.date" class="platform-trend-day">
<div class="platform-trend-date">{{ shortDate(item.date) }}</div>
<div class="platform-trend-bars">
<span
class="trend-bar trend-orders"
:style="{ height: barHeight(trendOrders(item), trendMaxOrders) }"
/>
<span
class="trend-bar trend-gmv"
:style="{ height: barHeight(item.paid_gmv_cent, trendMaxGMV) }"
/>
</div>
<strong>{{ item.orders }} 单</strong>
<small>{{ formatCentWithSymbol(item.paid_gmv_cent) }}</small>
<span class="platform-trend-foot"
>用户 +{{ item.new_users }} · 商品 +{{ item.new_listings }}</span
>
</article>
</div>
</section>
</template>
</section>
</template>
<style scoped>
.platform-page {
display: grid;
gap: 18px;
padding-bottom: 28px;
}
.platform-header {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 20px;
flex-wrap: wrap;
padding: 26px 28px;
border: 1px solid #e2e8f0;
border-radius: 12px;
background: #fff;
}
.platform-header h1 {
margin: 8px 0 7px;
color: #0f172a;
font-size: 28px;
line-height: 1.2;
}
.platform-header p {
margin: 0;
color: #64748b;
font-size: 13px;
line-height: 1.6;
}
.platform-eyebrow {
display: flex;
align-items: center;
gap: 6px;
color: #2563eb !important;
font-size: 11px !important;
font-weight: 800;
}
.platform-header-actions {
display: flex;
align-items: center;
gap: 12px;
flex-wrap: wrap;
}
.platform-updated {
color: #94a3b8;
font-size: 12px;
}
.platform-state {
display: flex;
min-height: 240px;
align-items: center;
justify-content: center;
gap: 10px;
border: 1px solid #e2e8f0;
border-radius: 12px;
background: #fff;
color: #64748b;
}
.platform-state--error {
color: #dc2626;
}
.platform-metrics {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
gap: 14px;
}
.platform-metric {
display: flex;
align-items: center;
gap: 14px;
min-height: 118px;
padding: 18px;
border: 1px solid #e2e8f0;
border-top: 3px solid #2563eb;
border-radius: 10px;
background: #fff;
}
.platform-metric > .el-icon {
display: grid;
width: 44px;
height: 44px;
flex: none;
place-items: center;
border-radius: 10px;
background: #eff6ff;
color: #2563eb;
font-size: 21px;
}
.platform-metric > div {
display: grid;
min-width: 0;
gap: 3px;
}
.platform-metric span {
color: #64748b;
font-size: 12px;
font-weight: 700;
}
.platform-metric strong {
color: #0f172a;
font-size: 25px;
font-weight: 800;
line-height: 1.15;
}
.platform-metric small {
color: #94a3b8;
font-size: 11px;
}
.metric-listings,
.metric-gmv {
border-top-color: #059669;
}
.metric-listings > .el-icon,
.metric-gmv > .el-icon {
background: #ecfdf5;
color: #059669;
}
.metric-today {
border-top-color: #d97706;
}
.metric-today > .el-icon {
background: #fffbeb;
color: #d97706;
}
.platform-panel {
overflow: hidden;
padding: 20px;
border: 1px solid #e2e8f0;
border-radius: 12px;
background: #fff;
}
.platform-panel-head {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 16px;
flex-wrap: wrap;
margin-bottom: 16px;
}
.platform-panel-head h2 {
margin: 0 0 5px;
color: #0f172a;
font-size: 18px;
}
.platform-panel-head p {
margin: 0;
color: #64748b;
font-size: 12px;
}
.platform-pending {
display: grid;
justify-items: end;
gap: 2px;
color: #64748b;
font-size: 11px;
}
.platform-pending strong {
color: #b45309;
font-size: 13px;
}
.platform-site-name {
display: grid;
gap: 2px;
}
.platform-site-name strong {
color: #0f172a;
}
.platform-site-name small,
.platform-cell-sub {
color: #94a3b8;
font-size: 11px;
}
.platform-cell-sub {
display: block;
margin-top: 3px;
}
.platform-trend-grid {
display: grid;
grid-template-columns: repeat(7, minmax(90px, 1fr));
gap: 10px;
overflow-x: auto;
padding-bottom: 4px;
}
.platform-trend-legend {
display: flex;
align-items: center;
gap: 14px;
color: #64748b;
font-size: 11px;
}
.platform-trend-legend span {
display: inline-flex;
align-items: center;
gap: 5px;
}
.platform-trend-legend em {
width: 9px;
height: 9px;
border-radius: 2px;
}
.legend-orders {
background: #3b82f6;
}
.legend-gmv {
background: #10b981;
}
.platform-trend-day {
display: grid;
min-width: 90px;
justify-items: center;
gap: 5px;
padding: 12px 8px;
border: 1px solid #eef2f7;
border-radius: 8px;
background: #f8fafc;
}
.platform-trend-date {
color: #64748b;
font-size: 11px;
font-weight: 700;
}
.platform-trend-bars {
display: flex;
height: 82px;
align-items: flex-end;
gap: 6px;
}
.trend-bar {
width: 12px;
min-height: 6px;
border-radius: 3px 3px 0 0;
}
.trend-orders {
background: #3b82f6;
}
.trend-gmv {
background: #10b981;
}
.platform-trend-day strong {
color: #0f172a;
font-size: 13px;
}
.platform-trend-day small {
color: #059669;
font-size: 11px;
}
.platform-trend-foot {
color: #94a3b8;
font-size: 10px;
text-align: center;
}
@media (max-width: 900px) {
.platform-header,
.platform-panel {
padding: 16px;
}
.platform-trend-grid {
grid-template-columns: repeat(7, 96px);
}
}
</style>
+36 -10
View File
@@ -43,7 +43,12 @@ import { useAdminNotificationUnreadCount } from '@/features/admin/composables/us
import { usePendingRefundCount } from '@/features/admin/composables/usePendingRefundCount'
import { useAdminSessionStore } from '@/stores/adminSession'
import { useDistributionSiteStore } from '@/stores/distributionSite'
import { adminPath, ADMIN_DASHBOARD_PATH, ADMIN_LOGIN_PATH } from '@/shared/utils/adminPath'
import {
adminPath,
ADMIN_DASHBOARD_PATH,
ADMIN_LOGIN_PATH,
PLATFORM_OPS_PATH,
} from '@/shared/utils/adminPath'
import { readError } from '@/shared/utils/error'
const router = useRouter()
@@ -350,6 +355,23 @@ function canAccessNavItem(item: NavItem) {
}
const navGroups = computed(() => {
if (siteStore.isPlatformOps) {
return [
{
label: '平台运营',
index: 'platform-ops',
icon: DataLine,
children: [
{
label: '平台总览',
to: PLATFORM_OPS_PATH,
icon: DataLine,
permission: 'dashboard:view',
},
],
},
]
}
return allNavGroups
.filter(group => (siteStore.isTenant ? !group.legacyOnly : !group.tenantOnly))
.map(group => ({
@@ -370,7 +392,7 @@ const activeMenu = computed(() => {
})
const defaultOpeneds = computed(() => {
const activeGroup = allNavGroups.find(group =>
const activeGroup = navGroups.value.find(group =>
group.children.some(item => item.to === activeMenu.value)
)
@@ -380,18 +402,22 @@ const defaultOpeneds = computed(() => {
const adminName = computed(() => adminSession.nickname || adminSession.username || '管理员')
const currentSiteName = computed(() => siteStore.siteName || '大锤商行')
const currentSiteScope = computed(() => {
if (siteStore.isPlatformOps) return '平台运营'
if (siteStore.isTenant) return '经营站点'
if (siteStore.isDistribution) return '分销站点'
return '主站'
})
const currentSiteHint = computed(() =>
siteStore.isTenant ? '用户、商品、订单与财务均按本站口径统计' : '历史分销站点管理视图'
)
const adminScopeNote = computed(() =>
adminSession.isSuperAdmin
const currentSiteHint = computed(() => {
if (siteStore.isPlatformOps) return '只读展示全平台及各经营站点统计'
if (siteStore.isTenant) return '用户、商品、订单与财务均按本站口径统计'
return '历史分销站点管理视图'
})
const adminScopeNote = computed(() => {
if (siteStore.isPlatformOps) return '平台超级管理员 · 全平台只读总览'
return adminSession.isSuperAdmin
? '平台超级管理员 · 当前仅查看本站数据'
: '站点管理员 · 数据仅限当前站点'
)
})
const adminRoleText = computed(() => {
if (adminSession.isSuperAdmin) return '超级管理员'
const names = adminSession.roles.map(role => role.name).filter(Boolean)
@@ -531,7 +557,7 @@ async function handleForcedPasswordChange() {
<div class="admin-sidebar-footer">
<RouterLink
v-if="hasNotificationPermission"
v-if="hasNotificationPermission && !siteStore.isPlatformOps"
class="sidebar-notification"
:to="adminPath('notifications')"
>
@@ -544,7 +570,7 @@ async function handleForcedPasswordChange() {
<span v-show="!isCollapsed" class="sidebar-notification-text">通知中心</span>
</RouterLink>
<el-dropdown
v-if="hasChatPermission"
v-if="hasChatPermission && !siteStore.isPlatformOps"
trigger="click"
@command="handleStatusChange"
:disabled="updatingStatus"
+7 -1
View File
@@ -1,6 +1,6 @@
import type { RouteRecordRaw } from 'vue-router'
import { adminPath, ADMIN_DASHBOARD_PATH } from '@/shared/utils/adminPath'
import { adminPath, ADMIN_DASHBOARD_PATH, PLATFORM_OPS_PATH } from '@/shared/utils/adminPath'
const adminMeta = { layout: 'admin', requiresAdmin: true }
@@ -18,6 +18,12 @@ export const adminRoutes: RouteRecordRaw[] = [
component: () => import('@/features/admin/views/AdminDashboardView.vue'),
meta: adminMeta,
},
{
path: PLATFORM_OPS_PATH,
name: 'platform-ops-overview',
component: () => import('@/features/admin/views/AdminPlatformOverviewView.vue'),
meta: { ...adminMeta, platformOps: true },
},
{
path: adminPath('users'),
name: 'admin-users',
+11 -3
View File
@@ -3,7 +3,8 @@ import { createRouter, createWebHistory } from 'vue-router'
import { useAdminSessionStore } from '@/stores/adminSession'
import { useSessionStore } from '@/stores/session'
import { getAccessToken, getLoginPath } from '@/shared/utils/authStorage'
import { ADMIN_DASHBOARD_PATH, ADMIN_LOGIN_PATH } from '@/shared/utils/adminPath'
import { ADMIN_DASHBOARD_PATH, ADMIN_LOGIN_PATH, PLATFORM_OPS_PATH } from '@/shared/utils/adminPath'
import { isPlatformOpsHostname } from '@/stores/distributionSite'
import { accountRoutes } from './accountRoutes'
import { adminRoutes } from './adminRoutes'
import { isMobileHost, isMobileDevice, getMobilePath, getPcPath } from './mobileHost'
@@ -28,11 +29,12 @@ const router = createRouter({
})
router.beforeEach(async to => {
const platformOps = isPlatformOpsHostname()
if (to.query.track_code) {
saveTrackCode(String(to.query.track_code))
}
const isMobile = isMobileHost() || isMobileDevice()
const isMobile = !platformOps && (isMobileHost() || isMobileDevice())
if (isMobile) {
const targetPath = getMobilePath(to.path)
@@ -97,12 +99,18 @@ router.beforeEach(async to => {
if (!adminSession.hasSessionHint) return true
try {
await adminSession.loadMe()
return ADMIN_DASHBOARD_PATH
return platformOps ? PLATFORM_OPS_PATH : ADMIN_DASHBOARD_PATH
} catch {
adminSession.logout()
return true
}
}
if (platformOps && to.meta.requiresAdmin && to.path !== PLATFORM_OPS_PATH) {
return PLATFORM_OPS_PATH
}
if (!platformOps && to.path === PLATFORM_OPS_PATH) {
return ADMIN_DASHBOARD_PATH
}
if (to.meta.requiresAdmin) {
try {
if (
+1
View File
@@ -17,6 +17,7 @@ export function adminPath(path = '') {
export const ADMIN_LOGIN_PATH = adminPath('login')
export const ADMIN_DASHBOARD_PATH = adminPath('dashboard')
export const PLATFORM_OPS_PATH = adminPath('platform')
export function isAdminPath(path: string) {
return path === ADMIN_BASE_PATH || path.startsWith(`${ADMIN_BASE_PATH}/`)
+60 -4
View File
@@ -178,7 +178,7 @@ export function shouldProbeTenantContext(
export function getEffectiveSiteCode(): string {
if (typeof window === 'undefined') return ''
// 经营租户站点不能同时携带旧分销站点编码,否则列表和下单会走旧分销过滤。
if (isTenantSiteContext()) return ''
if (isTenantSiteContext() || isPlatformOpsContext()) return ''
const envCode = ((import.meta.env.VITE_DISTRIBUTION_SITE_CODE as string) || '').trim()
if (envCode) return envCode
@@ -199,12 +199,27 @@ export function isTenantSiteContext(): boolean {
return Boolean((sessionStorage.getItem('hfb_tenant_code') || '').trim())
}
export function isPlatformOpsHostname(
hostname = typeof window !== 'undefined' ? window.location.hostname : ''
): boolean {
const host = hostname.trim().toLowerCase()
if (!host) return false
const configured = ((import.meta.env.VITE_OPS_DOMAIN as string) || '').trim().toLowerCase()
if (configured && host === configured) return true
return host.startsWith('ops.')
}
export function isPlatformOpsContext(): boolean {
if (typeof window === 'undefined') return false
return isPlatformOpsHostname() || sessionStorage.getItem('hfb_platform_ops') === '1'
}
/**
* 统一解析业务请求应携带的旧分销站点编码。
* 经营租户必须返回空串,调用方也不得把显式传入的历史参数继续透传。
*/
export function resolveEffectiveSiteCode(explicitCode?: string): string {
if (isTenantSiteContext()) return ''
if (isTenantSiteContext() || isPlatformOpsContext()) return ''
const explicit = (explicitCode || '').trim()
return explicit || getEffectiveSiteCode()
}
@@ -217,7 +232,7 @@ export const useDistributionSiteStore = defineStore('distributionSite', {
siteName: sessionStorage.getItem('hfb_site_name') || '大锤商行',
tenantId: 0,
tenantCode: '',
siteMode: 'legacy' as 'legacy' | 'tenant',
siteMode: 'legacy' as 'legacy' | 'tenant' | 'ops',
features: {} as Record<string, unknown>,
domain: '',
isDistribution: Boolean(code),
@@ -238,14 +253,18 @@ export const useDistributionSiteStore = defineStore('distributionSite', {
getters: {
/** 品牌标识字符:分站取站名首字,主站沿用「锤」。 */
brandMark(state): string {
if (state.siteMode === 'ops') return '运'
if (state.siteMode === 'tenant') return state.siteName.slice(0, 1) || '锤'
return state.isDistribution && state.siteName ? state.siteName.slice(0, 1) : '锤'
},
isTenant(state): boolean {
return state.siteMode === 'tenant'
},
isPlatformOps(state): boolean {
return state.siteMode === 'ops'
},
hasCustomBrand(state): boolean {
return state.siteMode === 'tenant' || state.isDistribution
return state.siteMode === 'tenant' || state.siteMode === 'ops' || state.isDistribution
},
/** 分站首页主标题:站名与主站联名。 */
coBrandName(state): string {
@@ -266,6 +285,12 @@ export const useDistributionSiteStore = defineStore('distributionSite', {
''
).trim()
if (isPlatformOpsHostname(hostname)) {
this.applyPlatformOpsContext()
this.initialized = true
return
}
if (shouldProbeTenantContext(hostname, querySite, envCode)) {
try {
const { data } = await apiClient.get<ApiResponse<TenantSiteContext>>('/site/context', {
@@ -340,6 +365,7 @@ export const useDistributionSiteStore = defineStore('distributionSite', {
this.domain = info.domain || ''
this.isDistribution = true
sessionStorage.removeItem('hfb_tenant_code')
sessionStorage.removeItem('hfb_platform_ops')
this.displayAccountEnabled = info.display_account_enabled ?? true
this.defaultSupportGroupId = info.default_support_group_id ?? null
this.logoUrl = info.logo_url || ''
@@ -435,6 +461,7 @@ export const useDistributionSiteStore = defineStore('distributionSite', {
this.receiveRatioDelta = 0
this.receiveCostDelta = 0
sessionStorage.removeItem('hfb_tenant_code')
sessionStorage.removeItem('hfb_platform_ops')
sessionStorage.removeItem('hfb_site_code')
sessionStorage.removeItem('hfb_site_name')
localStorage.removeItem('hfb_site_code')
@@ -474,6 +501,7 @@ export const useDistributionSiteStore = defineStore('distributionSite', {
this.receiveCostDelta = Math.max(0, Number(profile.receive_cost_delta || 0))
sessionStorage.setItem('hfb_tenant_code', this.tenantCode)
sessionStorage.removeItem('hfb_platform_ops')
sessionStorage.removeItem('hfb_site_code')
sessionStorage.removeItem('hfb_site_name')
localStorage.removeItem('hfb_site_code')
@@ -482,6 +510,34 @@ export const useDistributionSiteStore = defineStore('distributionSite', {
this.applyFavicon()
},
applyPlatformOpsContext() {
this.siteCode = ''
this.siteName = '平台运营总览'
this.tenantId = 0
this.tenantCode = ''
this.siteMode = 'ops'
this.features = {}
this.domain = window.location.hostname
this.isDistribution = false
this.displayAccountEnabled = false
this.defaultSupportGroupId = null
this.logoUrl = ''
this.faviconUrl = ''
this.banners = []
this.announcements = []
this.footerInfo = null
this.storefrontText = { ...defaultStorefrontText }
this.receiveRatioDelta = 0
this.receiveCostDelta = 0
sessionStorage.setItem('hfb_platform_ops', '1')
sessionStorage.removeItem('hfb_tenant_code')
sessionStorage.removeItem('hfb_site_code')
sessionStorage.removeItem('hfb_site_name')
localStorage.removeItem('hfb_site_code')
localStorage.removeItem('hfb_site_name')
document.title = '平台运营总览'
},
applyFavicon() {
if (!this.faviconUrl || typeof document === 'undefined') return
let link = document.querySelector("link[rel*='icon']") as HTMLLinkElement | null
+12
View File
@@ -2,6 +2,8 @@ import { afterEach, describe, expect, it } from 'vitest'
import {
getEffectiveSiteCode,
isPlatformOpsContext,
isPlatformOpsHostname,
isTenantSiteContext,
resolveEffectiveSiteCode,
shouldProbeTenantContext,
@@ -42,4 +44,14 @@ describe('shouldProbeTenantContext', () => {
expect(resolveEffectiveSiteCode(' explicit_site ')).toBe('explicit_site')
expect(resolveEffectiveSiteCode()).toBe('session_site')
})
it('平台运营域名不携带任何分销站点编码', () => {
expect(isPlatformOpsHostname('ops.localhost')).toBe(true)
expect(isPlatformOpsHostname('ops.hao858.com')).toBe(true)
expect(isPlatformOpsHostname('jieyou.localhost')).toBe(false)
sessionStorage.setItem('hfb_platform_ops', '1')
expect(isPlatformOpsContext()).toBe(true)
expect(getEffectiveSiteCode()).toBe('')
expect(resolveEffectiveSiteCode('legacy_site')).toBe('')
})
})
+1
View File
@@ -95,6 +95,7 @@ export default defineConfig({
allowedHosts: [
'dachui.localhost',
'jieyou.localhost',
'ops.localhost',
'221329.cc.cd',
'd4aa-77-93-89-84.ngrok-free.app',
'frp-bus.com',