From 991de9013676ef70c84c6eeee6ea954cba8f6f10 Mon Sep 17 00:00:00 2001 From: yml Date: Sun, 15 Nov 2026 21:31:26 +0800 Subject: [PATCH] =?UTF-8?q?feat(platform-ops):=20=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E5=B9=B3=E5=8F=B0=E8=BF=90=E8=90=A5=E7=BB=9F=E8=AE=A1=E6=80=BB?= =?UTF-8?q?=E8=A7=88=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 3 +- deploy/README.md | 4 +- .../features/admin/api/platformOps.spec.ts | 24 + .../src/features/admin/api/platformOps.ts | 63 ++ .../features/admin/views/AdminLoginView.vue | 17 +- .../admin/views/AdminPlatformOverviewView.vue | 560 ++++++++++++++++++ frontend/src/layouts/AdminLayout.vue | 46 +- frontend/src/router/adminRoutes.ts | 8 +- frontend/src/router/index.ts | 14 +- frontend/src/shared/utils/adminPath.ts | 1 + frontend/src/stores/distributionSite.ts | 64 +- frontend/src/stores/siteContext.spec.ts | 12 + frontend/vite.config.ts | 1 + 13 files changed, 793 insertions(+), 24 deletions(-) create mode 100644 frontend/src/features/admin/api/platformOps.spec.ts create mode 100644 frontend/src/features/admin/api/platformOps.ts create mode 100644 frontend/src/features/admin/views/AdminPlatformOverviewView.vue diff --git a/README.md b/README.md index ef80c533..94f25841 100644 --- a/README.md +++ b/README.md @@ -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.`(见 `deploy/caddy/Caddyfile`)。主站后台的「打开独立分销后台」与开通凭证通过构建期 `VITE_DISTRIBUTION_ADMIN_URL` 注入该地址;未配置时按当前主站域名推导。 +> 生产环境不使用上述端口:Caddy 按域名分流,分销管理后台固定为 `https://distribution.`,平台运营统计后台固定为 `https://ops.`(见 `deploy/caddy/Caddyfile`)。主站后台的「打开独立分销后台」与开通凭证通过构建期 `VITE_DISTRIBUTION_ADMIN_URL` 注入该地址;未配置时按当前主站域名推导。 如需拆分调试,可手动执行: diff --git a/deploy/README.md b/deploy/README.md index bfdf64f2..ac368090 100644 --- a/deploy/README.md +++ b/deploy/README.md @@ -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://选号网域名 # 选号网首页 ``` diff --git a/frontend/src/features/admin/api/platformOps.spec.ts b/frontend/src/features/admin/api/platformOps.spec.ts new file mode 100644 index 00000000..49974d68 --- /dev/null +++ b/frontend/src/features/admin/api/platformOps.spec.ts @@ -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') + }) +}) diff --git a/frontend/src/features/admin/api/platformOps.ts b/frontend/src/features/admin/api/platformOps.ts new file mode 100644 index 00000000..42eae16b --- /dev/null +++ b/frontend/src/features/admin/api/platformOps.ts @@ -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>('/admin/platform/overview') + return data.data +} diff --git a/frontend/src/features/admin/views/AdminLoginView.vue b/frontend/src/features/admin/views/AdminLoginView.vue index c4f5a56a..595ff06b 100644 --- a/frontend/src/features/admin/views/AdminLoginView.vue +++ b/frontend/src/features/admin/views/AdminLoginView.vue @@ -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() {