Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
083a323c1f | ||
|
|
bf4bbf81c7 | ||
|
|
0f6ad8b993 | ||
|
|
2ad009f5c0 | ||
|
|
6f18c67315 | ||
|
|
b23120477f | ||
|
|
12bc263d3b | ||
|
|
7c0f22ad7a | ||
|
|
8973338c64 | ||
|
|
476e3d93dd | ||
|
|
3ae7b462f5 | ||
|
|
f158f906d5 | ||
|
|
aaeec14733 | ||
|
|
6073e72940 | ||
|
|
896f3240f9 | ||
|
|
7b1e9eee47 | ||
|
|
47d6309cba | ||
|
|
ebab77057a | ||
|
|
3ef46b0aa8 | ||
|
|
2f26828f09 | ||
|
|
bb94d80e13 | ||
|
|
29e5666d74 | ||
|
|
d34cb182e3 | ||
|
|
4d1cd8f365 | ||
|
|
9ad2776515 | ||
|
|
53713e5935 | ||
|
|
ac3f433ee6 | ||
|
|
44fe7a0142 | ||
|
|
f52577ff9e | ||
|
|
8e90b8ca09 | ||
|
|
998e32e49c | ||
|
|
8b4d27b0ee | ||
|
|
26f1157083 | ||
|
|
ad949ab370 | ||
|
|
d5a84b51a7 | ||
|
|
760f41a584 | ||
|
|
20f880a761 | ||
|
|
ab1531d9b0 | ||
|
|
3d0252d187 | ||
|
|
526a9db789 | ||
|
|
9b35b8e7a7 | ||
|
|
14b6541bee | ||
|
|
00edcedbcf | ||
|
|
dcf1d76944 | ||
|
|
7f67f4d685 | ||
|
|
d2ca528543 | ||
|
|
47a24e0d53 | ||
|
|
c78deafee3 | ||
|
|
3330b536dc | ||
|
|
07629a4596 | ||
|
|
5c6ad02f46 | ||
|
|
048c42207c | ||
|
|
67735afd45 | ||
|
|
0574a85632 | ||
|
|
18ddf125be | ||
|
|
bb0709b8cc | ||
|
|
076c6124c8 | ||
|
|
89fdfd7d83 | ||
|
|
f87b26b201 | ||
|
|
466dc66907 | ||
|
|
357f271639 | ||
|
|
f3adf7bc15 | ||
|
|
4512d2601d | ||
|
|
d0902d6568 | ||
|
|
7e1dd543fb | ||
|
|
3003e7801d | ||
|
|
567921e726 | ||
|
|
03f947e9b8 | ||
|
|
6ac2d9421b | ||
|
|
aa42e7b866 | ||
|
|
e09b56e0f3 | ||
|
|
84956b8fe2 | ||
|
|
f57c0ca0ea | ||
|
|
9c15a822e9 | ||
|
|
85f37d2eae | ||
|
|
222055595c | ||
|
|
b1d5c2b4b0 | ||
|
|
787a50369f | ||
|
|
422162e580 | ||
|
|
26bcb2b66e | ||
|
|
91322fa9a0 |
No files matched your search
@@ -0,0 +1,25 @@
|
||||
.agents
|
||||
.aws
|
||||
.claude
|
||||
.codex
|
||||
.codex-tasks
|
||||
.git
|
||||
.github
|
||||
.turbo
|
||||
.worktrees
|
||||
coverage
|
||||
dist
|
||||
pnpm-lock.yaml.bak
|
||||
docker-compose.override.yml
|
||||
docker-compose.prod.yml
|
||||
docs
|
||||
media
|
||||
node_modules
|
||||
prototype
|
||||
scripts/deploy/*.test.mjs
|
||||
.env
|
||||
.env.*
|
||||
!.env.production.example
|
||||
**/node_modules
|
||||
**/dist
|
||||
!apps/api/prisma/assets/**
|
||||
@@ -10,9 +10,24 @@ ADMIN_PORT=3000
|
||||
SESSION_SECRET=replace-with-a-long-random-value
|
||||
DEFAULT_BRAND_ID=00000000-0000-0000-0000-000000000001
|
||||
SEED_ADMIN_PASSWORD=change-me-now-123
|
||||
OBJECT_STORAGE_ENDPOINT=
|
||||
OBJECT_STORAGE_BUCKET=
|
||||
OBJECT_STORAGE_ACCESS_KEY=
|
||||
OBJECT_STORAGE_SECRET_KEY=
|
||||
OBJECT_STORAGE_ENDPOINT=http://localhost:9000
|
||||
OBJECT_STORAGE_PUBLIC_URL=http://localhost:9000/personal-brand-media
|
||||
OBJECT_STORAGE_BUCKET=personal-brand-media
|
||||
OBJECT_STORAGE_ACCESS_KEY=minioadmin
|
||||
OBJECT_STORAGE_SECRET_KEY=minioadmin
|
||||
WECHAT_APP_ID=
|
||||
WECHAT_APP_SECRET=
|
||||
WECHAT_UPLOAD_PRIVATE_KEY=
|
||||
MINIAPP_CREDENTIAL_ENCRYPTION_KEY=replace-with-32-byte-random-secret
|
||||
# 小程序代码构建产物根目录,相对路径按仓库根目录解析;默认 apps/taro/dist
|
||||
# MINIAPP_ARTIFACT_ROOT=apps/taro/dist
|
||||
# 构建超过该毫秒数没有进度更新即视为中断,允许重新上传;默认 15 分钟
|
||||
# MINIAPP_BUILD_STALE_MS=900000
|
||||
# 小程序请求地址在后台「小程序上传配置」维护,这里仅为回落值;
|
||||
# 未设置时由 PUBLIC_BASE_URL + MINIAPP_API_PATH 推导
|
||||
# MINIAPP_API_BASE_URL=https://wechat.app.que01.top/api
|
||||
# MINIAPP_API_PATH=/api
|
||||
# 单个品牌的 AppID 在后台“小程序上传配置”维护,这里只作为回落值
|
||||
# WEAPP_APP_ID=
|
||||
# 上传子进程工作目录;miniprogram-ci 的编译缓存放这里,默认系统临时目录
|
||||
# MINIAPP_UPLOAD_WORKSPACE=/tmp/personal-brand-miniapp-upload
|
||||
@@ -0,0 +1,31 @@
|
||||
NODE_ENV=production
|
||||
POSTGRES_USER=personal_brand
|
||||
POSTGRES_PASSWORD=replace-with-a-long-database-password
|
||||
POSTGRES_DB=personal_brand
|
||||
POSTGRES_PORT=5432
|
||||
|
||||
DATABASE_URL=postgresql://personal_brand:replace-with-a-long-database-password@127.0.0.1:5432/personal_brand?schema=public
|
||||
SESSION_SECRET=replace-with-at-least-32-random-characters
|
||||
DEFAULT_BRAND_ID=00000000-0000-0000-0000-000000000001
|
||||
SEED_ADMIN_PASSWORD=replace-with-a-one-time-initial-password
|
||||
SEED_MODE=skip
|
||||
|
||||
API_PORT=3001
|
||||
API_PREFIX=
|
||||
|
||||
LOCAL_MEDIA_ROOT=/home/ubuntu/persional-brand/media
|
||||
LOCAL_MEDIA_BASE_URL=/media
|
||||
OBJECT_STORAGE_ENDPOINT=
|
||||
OBJECT_STORAGE_PUBLIC_URL=
|
||||
OBJECT_STORAGE_BUCKET=
|
||||
OBJECT_STORAGE_ACCESS_KEY=
|
||||
OBJECT_STORAGE_SECRET_KEY=
|
||||
OBJECT_STORAGE_REGION=us-east-1
|
||||
|
||||
WECHAT_APP_ID=
|
||||
WECHAT_APP_SECRET=
|
||||
|
||||
# 小程序请求地址正常情况下在后台「小程序上传配置」维护;
|
||||
# 这里仅作为后台未配置时的回落值(否则由 PUBLIC_BASE_URL + /api 推导)
|
||||
# MINIAPP_API_BASE_URL=https://wechat.app.que01.top/api
|
||||
# MINIAPP_BUILD_STALE_MS=900000
|
||||
@@ -0,0 +1,122 @@
|
||||
name: CI
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
push:
|
||||
branches: [main]
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
static:
|
||||
name: Static checks
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: pnpm/action-setup@v4
|
||||
with:
|
||||
version: 9.15.0
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 24
|
||||
cache: pnpm
|
||||
- run: pnpm install --frozen-lockfile
|
||||
- run: pnpm check
|
||||
- run: pnpm template:doctor
|
||||
|
||||
build:
|
||||
name: Production build
|
||||
runs-on: ubuntu-latest
|
||||
needs: [static]
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: pnpm/action-setup@v4
|
||||
with:
|
||||
version: 9.15.0
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 24
|
||||
cache: pnpm
|
||||
- run: pnpm install --frozen-lockfile
|
||||
- run: pnpm build:admin:preview
|
||||
- uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: admin-dist
|
||||
path: apps/admin/dist
|
||||
retention-days: 7
|
||||
|
||||
api:
|
||||
name: API integration
|
||||
runs-on: ubuntu-latest
|
||||
needs: [static]
|
||||
services:
|
||||
postgres:
|
||||
image: postgres:16-alpine
|
||||
env:
|
||||
POSTGRES_USER: postgres
|
||||
POSTGRES_PASSWORD: postgres
|
||||
POSTGRES_DB: personal_brand
|
||||
ports:
|
||||
- 5432:5432
|
||||
options: >-
|
||||
--health-cmd "pg_isready -U postgres -d personal_brand"
|
||||
--health-interval 5s
|
||||
--health-timeout 5s
|
||||
--health-retries 12
|
||||
env:
|
||||
DATABASE_URL: postgresql://postgres:postgres@localhost:5432/personal_brand
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: pnpm/action-setup@v4
|
||||
with:
|
||||
version: 9.15.0
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 24
|
||||
cache: pnpm
|
||||
- run: pnpm install --frozen-lockfile
|
||||
- run: pnpm --filter @personal-brand/api test:integration
|
||||
|
||||
browser:
|
||||
name: Browser regression
|
||||
runs-on: ubuntu-latest
|
||||
needs: [build]
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: pnpm/action-setup@v4
|
||||
with:
|
||||
version: 9.15.0
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 24
|
||||
cache: pnpm
|
||||
- run: pnpm install --frozen-lockfile
|
||||
- run: pnpm --filter @personal-brand/taro exec playwright install --with-deps chromium
|
||||
- run: pnpm --filter @personal-brand/api test:integration
|
||||
env:
|
||||
DATABASE_URL: postgresql://postgres:postgres@localhost:5432/personal_brand
|
||||
- name: Start API
|
||||
run: pnpm --filter @personal-brand/api start > /tmp/api.log 2>&1 &
|
||||
env:
|
||||
DATABASE_URL: postgresql://postgres:postgres@localhost:5432/personal_brand
|
||||
NODE_ENV: development
|
||||
- name: Start mini program preview
|
||||
run: pnpm --filter @personal-brand/taro dev:h5 > /tmp/taro.log 2>&1 &
|
||||
env:
|
||||
API_BASE_URL: http://localhost:3001
|
||||
BRAND_SLUG: default-brand
|
||||
TEMPLATE_KEY: acheng-campus-food
|
||||
- name: Start admin
|
||||
run: pnpm --filter @personal-brand/admin dev > /tmp/admin.log 2>&1 &
|
||||
env:
|
||||
VITE_API_BASE_URL: /api
|
||||
VITE_DEV_API_TARGET: http://localhost:3001
|
||||
VITE_TEMPLATE_PREVIEW_URL: http://localhost:3002
|
||||
- name: Wait for services
|
||||
run: |
|
||||
curl --retry 30 --retry-delay 1 --retry-connrefused -fsS http://localhost:3001/health
|
||||
curl --retry 30 --retry-delay 1 --retry-connrefused -fsS http://localhost:3002
|
||||
curl --retry 30 --retry-delay 1 --retry-connrefused -fsS http://localhost:3000
|
||||
- run: pnpm --filter @personal-brand/taro exec playwright test --config=playwright.config.ts --reporter=line
|
||||
@@ -2,11 +2,13 @@ node_modules/
|
||||
.pnpm-store/
|
||||
.turbo/
|
||||
dist/
|
||||
packages/config/dist/
|
||||
.next/
|
||||
coverage/
|
||||
.env
|
||||
.env.*
|
||||
!.env.example
|
||||
.env.production
|
||||
!.env.production.example
|
||||
*.log
|
||||
.DS_Store
|
||||
apps/miniapp/miniprogram_npm/
|
||||
@@ -18,5 +20,9 @@ apps/admin/public/template-preview/
|
||||
|
||||
apps/taro/test-results/
|
||||
apps/taro/playwright-report/
|
||||
media/
|
||||
|
||||
**/.swc/
|
||||
.codex-tasks/
|
||||
docker-compose.override.yml
|
||||
.env.production
|
||||
@@ -3,3 +3,4 @@ VITE_API_BASE_URL=/api
|
||||
VITE_DEV_API_TARGET=http://localhost:3001
|
||||
ADMIN_PORT=3000
|
||||
VITE_TEMPLATE_PREVIEW_URL=http://localhost:3002
|
||||
VITE_MEDIA_PROXY_TARGET=http://localhost:9000
|
||||
@@ -0,0 +1,418 @@
|
||||
# Admin Design Language
|
||||
|
||||
本文件是 `@personal-brand/admin` 管理后台的视觉与交互规范,是后台 UI 的唯一设计来源。
|
||||
|
||||
设计目标:**简洁、干净**。留白充足、层级靠排版建立、装饰最少。信息架构与业务语义不在本文件范围内,如需变更请走产品文档。
|
||||
|
||||
适用范围:`apps/admin/src` 下所有页面、组件与样式。新增 UI 前先读本文件,冲突以本文件为准。
|
||||
|
||||
- 本文件同时作为 AI 设计工具的规范输入:在 MasterGo「AI 快搭」中直接上传本文件即可,无需重复描述视觉规则。生成提示词见 `docs/design/admin-mastergo-guide.md`。
|
||||
- 技术约束:antd 6 + React 19 + React Router 7 + TanStack Query 5。不引入新的 UI 库、状态管理、校验或路由方案。
|
||||
- 主题令牌统一在根节点通过 `ConfigProvider` 注入,页面与组件内不得写零散色值。
|
||||
- 共享视觉元素放 `apps/admin/src/components/`,页面专属组件留在各自的 `features/` 目录。
|
||||
- 中文界面。桌面优先,最小可用宽度 1024px;窄屏允许侧栏折叠,不提供移动端专用布局。
|
||||
|
||||
---
|
||||
|
||||
## 1. 颜色
|
||||
|
||||
中性灰打底,只保留一个强调色。禁止渐变、彩色大面积色块、玻璃拟态。
|
||||
|
||||
### 基础色
|
||||
|
||||
| 用途 | 令牌 | 值 |
|
||||
| ---------------------- | ---------------------- | --------- |
|
||||
| 页面底色 | `colorBgLayout` | `#F7F8FA` |
|
||||
| 卡片/容器底色 | `colorBgContainer` | `#FFFFFF` |
|
||||
| 次级填充(表头、悬停) | `colorFillQuaternary` | `#FAFAFB` |
|
||||
| 悬停底色 | `colorFillTertiary` | `#F7F8FA` |
|
||||
| 容器边框 | `colorBorderSecondary` | `#E7E9EC` |
|
||||
| 行分隔线 | `colorSplit` | `#F0F1F3` |
|
||||
| 控件边框 | `colorBorder` | `#D8DBE0` |
|
||||
|
||||
### 文字色
|
||||
|
||||
| 用途 | 令牌 | 值 |
|
||||
| ------------- | --------------------- | --------- |
|
||||
| 主文字 | `colorText` | `#1C1F23` |
|
||||
| 次要文字 | `colorTextSecondary` | `#6B7280` |
|
||||
| 辅助/占位文字 | `colorTextTertiary` | `#9AA1AC` |
|
||||
| 禁用文字 | `colorTextQuaternary` | `#C3C7CF` |
|
||||
|
||||
### 强调色
|
||||
|
||||
| 用途 | 令牌 | 值 |
|
||||
| ------------- | -------------------- | --------- |
|
||||
| 主色 | `colorPrimary` | `#2563EB` |
|
||||
| 主色悬停 | `colorPrimaryHover` | `#1D4ED8` |
|
||||
| 主色按下 | `colorPrimaryActive` | `#1E40AF` |
|
||||
| 选中底色 | `colorPrimaryBg` | `#EFF4FF` |
|
||||
| 选中/链接文字 | `colorLink` | `#2563EB` |
|
||||
|
||||
强调色只用于:主按钮、选中态、链接、关键数字、聚焦描边。不得用于大面积背景。
|
||||
|
||||
例外:小程序预览区(iframe / 模拟器内)显示的是模板自身的品牌色(例如餐饮模板的砖红 `#B54A2C`),与后台无关,不视为违规,也不要「修正」成后台强调色。
|
||||
|
||||
### 状态色
|
||||
|
||||
状态一律用「浅底 + 深字」,不使用 antd 的实心鲜艳 Tag。
|
||||
|
||||
| 语义 | 底色 | 边框 | 文字色 |
|
||||
| ------------- | --------- | --------- | --------- |
|
||||
| 成功 / 已发布 | `#ECFDF3` | `#ABEFC6` | `#067647` |
|
||||
| 警告 / 进行中 | `#FFFAEB` | `#FEDF89` | `#B54708` |
|
||||
| 错误 / 失败 | `#FEF3F2` | `#FBD5D1` | `#B42318` |
|
||||
| 中性 / 草稿 | `#F2F4F7` | `#E7E9EC` | `#475467` |
|
||||
| 信息 / 系统态 | `#EFF4FF` | `#B2CCFF` | `#2563EB` |
|
||||
|
||||
- 底色 + 边框 + 深色文字三件套同时用于 `StatusTag`、`Alert`、错误条与空状态,不得混用其他色阶。
|
||||
- 需要中间调的场合(图标、进度条完成态)使用中间色:成功 `#12B76A`、警告 `#F79009`、错误 `#F04438`、信息 `#2563EB`。
|
||||
|
||||
---
|
||||
|
||||
## 2. 排版
|
||||
|
||||
系统无衬线字体栈:`Inter`、`PingFang SC`、`Noto Sans SC`、`sans-serif`。
|
||||
|
||||
| 角色 | 字号 | 字重 | 行高 |
|
||||
| ------------------ | ---- | ---- | ---- |
|
||||
| 页面标题 | 20px | 600 | 1.4 |
|
||||
| 区块/卡片标题 | 16px | 600 | 1.45 |
|
||||
| 卡片内对象主标题 | 18px | 600 | 1.45 |
|
||||
| 强调正文、品牌名 | 15px | 600 | 1.5 |
|
||||
| 正文 | 14px | 400 | 1.5 |
|
||||
| 表单标签、次要正文 | 13px | 400 | 1.5 |
|
||||
| 辅助说明、时间戳 | 12px | 400 | 1.5 |
|
||||
| 指标数值 | 28px | 600 | 1.2 |
|
||||
|
||||
- 层级靠字号与字重建立,不靠颜色、下划线、边框。
|
||||
- 中文不使用斜体;英文与数字不加字距。
|
||||
- 一段说明文字最长不超过 2 行,超出应改写或省略。
|
||||
- 中英文与数字之间保留一个空格。
|
||||
|
||||
---
|
||||
|
||||
## 3. 间距与布局
|
||||
|
||||
8pt 网格。间距只使用 `4 / 8 / 12 / 16 / 24 / 32`。
|
||||
|
||||
| 场景 | 值 |
|
||||
| ---------------- | ------------ |
|
||||
| 页面内容区内边距 | 24px |
|
||||
| 内容最大宽度 | 1200px,居中 |
|
||||
| 页面头部到主体 | 32px |
|
||||
| 卡片内边距 | 20px |
|
||||
| 卡片之间 | 16px |
|
||||
| 表单字段之间 | 16px |
|
||||
| 标签与输入框之间 | 6px |
|
||||
| 行内元素之间 | 8px |
|
||||
| 小节标题到内容 | 12px |
|
||||
|
||||
外壳尺寸:
|
||||
|
||||
- 侧栏宽 232px,折叠宽 0(`breakpoint="lg"`)。
|
||||
- 顶栏高 56px,与侧栏品牌区对齐。
|
||||
|
||||
---
|
||||
|
||||
## 4. 形状与层次
|
||||
|
||||
| 元素 | 圆角 | 说明 |
|
||||
| ------------------ | ---- | ------------------------------- |
|
||||
| 卡片 | 10px | 默认 1px `#E7E9EC` 边框,无阴影 |
|
||||
| 弹窗 | 12px | 极轻阴影 |
|
||||
| 按钮、输入框、下拉 | 6px | 统一 |
|
||||
| 状态标签 | 6px | 高 24px,内边距 `2px 8px` |
|
||||
| 图片/头像缩略图 | 8px | 头像用圆形 |
|
||||
| 进度条 | 3px | 高 6px |
|
||||
|
||||
- 层次手段优先级:留白 > 字号字重 > 1px 浅边框 > 阴影。
|
||||
- 阴影仅用于浮层:`0 1px 2px rgba(16, 24, 40, 0.04)`,弹窗可加 `0 8px 24px rgba(16, 24, 40, 0.08)`。
|
||||
- 卡片不使用阴影,不叠加边框与阴影。
|
||||
|
||||
---
|
||||
|
||||
## 5. 组件规范
|
||||
|
||||
### 侧栏导航
|
||||
|
||||
- 白底,右侧 1px `#E7E9EC` 分隔线。不使用深色主题(现有 `theme="dark"` 需移除)。
|
||||
- 顶部品牌区:24x24 圆角 6px 标识 + 品牌名,高 56px。
|
||||
- 分组标题:12px `#9AA1AC`,上下留白 8px,不加图标、不做大写英文。
|
||||
- 菜单项:高 36px,圆角 6px,左侧 16px 线性图标(描边 1.5px),文字 14px。
|
||||
- 三态:默认深灰文字无底色;悬停 `#F7F8FA`;选中 `#EFF4FF` 底 + `#2563EB` 文字与图标 + 字重 500。
|
||||
|
||||
### 顶栏
|
||||
|
||||
- 高 56px,白底,底部 1px 分隔线,左右内边距 24px。
|
||||
- 左侧:品牌名 14px/600 + 灰色 13px「品牌工作区」+ 角色标签。
|
||||
- 角色标签:负责人 `#EFF4FF`/`#2563EB`,内容编辑 `#F2F4F7`/`#475467`。
|
||||
- 右侧:品牌切换下拉(尺寸 `small`、白底细边框)+ 「退出登录」文字按钮。
|
||||
- 顶栏不随机滚动,内容区独立滚动。
|
||||
|
||||
### 页面头部
|
||||
|
||||
统一通过 `AdminPageHeader` 渲染:页面标题 20px/600 + 可选副标题 13px 次要色 + 右侧操作区。标题与副标题间距 6px,页头到主体 32px(明显大于卡片之间的 16px)。页面内不得再手写标题层级。
|
||||
|
||||
- 页面标题必须与侧栏导航用词一致,不额外添加「小程序内容:」这类前缀;页面职责写进副标题。
|
||||
- 副标题一句话讲清这一页做什么,最长不超过 2 行;能由页面内文案表达的细节不要重复写在这里。
|
||||
|
||||
### 卡片
|
||||
|
||||
- 标题 16px/600,标题区底部间距 12px,标题右侧放次要操作(文字按钮)。
|
||||
- 卡片只承载一个主题;一个页面最多两级卡片嵌套,避免再嵌套。
|
||||
|
||||
### 按钮
|
||||
|
||||
| 类型 | 场景 |
|
||||
| -------------------- | ---------------------------------------- |
|
||||
| 主按钮(实心强调色) | 每个页面/卡片最多一个,用于当前主流程 |
|
||||
| 次按钮(白底细边框) | 并列的次要操作 |
|
||||
| 文字按钮 | 表格行内操作、列表「去处理」、返回类操作 |
|
||||
| 危险按钮 | 删除、撤回、卸载等不可逆操作 |
|
||||
|
||||
- 高度:默认 32px,主流程按钮 40px。
|
||||
- 等待态用 `loading`,禁用态用 `disabled`,禁止用文字变形表达状态。
|
||||
|
||||
### 表单
|
||||
|
||||
- 标签在输入框上方,13px `#475467`,必填星号 `#B42318`。
|
||||
- 帮助文本 12px `#9AA1AC`,错误文本 12px `#B42318`,都显示在字段下方。
|
||||
- 输入框聚焦:1.5px `#2563EB` 描边 + `#EFF4FF` 2px 外发光。
|
||||
- 提交失败必须保留用户输入,错误提示定位到字段或表单顶部,禁止弹窗后清空。
|
||||
|
||||
### 数据表格
|
||||
|
||||
- 无竖线;表头底色 `#FAFAFB`,13px `#6B7280`。
|
||||
- 行高 52px(含头像/双行内容时 60px)。
|
||||
- 行分隔线 `#F0F1F3`;悬停行底色 `#FAFAFB`。
|
||||
- 操作列统一放最右,使用文字按钮,最多 2 个直接操作,更多收进「更多」下拉。
|
||||
- 空数据不显示空表头,改用空状态组件。
|
||||
|
||||
### 状态标签
|
||||
|
||||
- 统一组件,按语义取色,默认 `尺寸 = 24px 高 / 12px 字`。
|
||||
- 发布状态机映射:`building` 信息、`uploaded` 中性、`under_review` 警告、`approved` 成功、`rejected` 错误、`published` 成功、`failed` 错误、`superseded` 中性。
|
||||
- 同一列表内标签宽度尽量对齐,避免视觉跳动。
|
||||
|
||||
### 弹窗
|
||||
|
||||
- 宽 480px(简单表单)或 560px(多字段),圆角 12px。
|
||||
- 标题 16px/600,底部操作右对齐:次按钮在左、主按钮在右。
|
||||
- 提交中禁用关闭与重复提交。
|
||||
|
||||
### 描述列表(键值展示)
|
||||
|
||||
用于咨询详情、版本信息等只读信息:字段名 13px `#6B7280`,值 14px `#1C1F23`,行间距 12px,不使用表格线。
|
||||
|
||||
落地:`<Descriptions className="admin-descriptions" column={1} size="small">`,字号与间距由 `admin.css` 与 `Descriptions` 令牌统一,不逐处传 `bordered`。
|
||||
|
||||
### Tabs
|
||||
|
||||
- 顶部 1px 分隔线,选中项底部 2px 强调色下划线 + 深色文字,未选中 14px `#6B7280`。
|
||||
- 不超过 5 个 Tab,超出改用左侧分段导航。
|
||||
|
||||
### 切换控件选型
|
||||
|
||||
同一层级切换控件只允许两种,按范围选择,不得混用:
|
||||
|
||||
| 场景 | 控件 | 现状 |
|
||||
| ---------------------------------------- | ----------- | ------------------------------ |
|
||||
| 页面级分区(内容结构不同、各自独立成段) | `Tabs` | 配置与发布 |
|
||||
| 区块内视图切换(同一份数据换视角) | `Segmented` | 小程序页面、业务提供项编辑弹窗 |
|
||||
|
||||
`Segmented` 用作「取值选择」(如能力状态降级/启用/停用)时按表单控件处理,不受本表约束。
|
||||
|
||||
### 标题层级
|
||||
|
||||
页面内标题只用三档,禁止再用 `Typography.Title level` 直接指定字号:
|
||||
|
||||
| 用途 | 类名 | 字号 |
|
||||
| ---------------------- | --------------------- | ---------- |
|
||||
| 区块标题 | `admin-section-title` | 16px / 600 |
|
||||
| 面板内小标题、表单分组 | `admin-subhead` | 15px / 600 |
|
||||
| 列表行、条目名称 | `admin-row-title` | 14px / 600 |
|
||||
|
||||
页面级标题只由 `AdminPageHeader` 输出(20px / 600),一个页面只出现一次。
|
||||
|
||||
### 进度
|
||||
|
||||
- 高 6px,圆角 3px,轨道 `#F0F1F3`,进度条强调色;完成态用成功色。
|
||||
- 进度条上方 14px 文案说明当前含义,不允许只有一根进度条。
|
||||
|
||||
---
|
||||
|
||||
## 6. 状态设计
|
||||
|
||||
每个远程数据页面必须显式实现四种状态,不得出现无反馈的白屏。
|
||||
|
||||
| 状态 | 规范 |
|
||||
| -------- | ----------------------------------------------------------------------------------- |
|
||||
| 加载中 | 骨架屏,形状与最终内容一致;不用居中转圈 |
|
||||
| 空数据 | 居中:极简线性图形 + 15px/600 标题 + 13px 灰色说明 + 主操作按钮 |
|
||||
| 请求失败 | 卡片内错误条:`#FEF3F2` 底 + 1px 浅红边框 + 圆角 8px + 文案 14px + 「重试」文字按钮 |
|
||||
| 成功反馈 | 右上角轻量 toast,白底圆角 8px,280–320px 宽 |
|
||||
|
||||
- 行内操作使用按钮 `loading` 表达进行中,不用全局遮罩。
|
||||
- 提交成功后:关闭弹窗、重置表单、刷新受影响列表;提交失败保持原状。
|
||||
- 幂等写操作要防止重复点击(提交中禁用)。
|
||||
|
||||
落地约定:
|
||||
|
||||
- 空状态统一用 `EmptyState`(`components/EmptyState.tsx`);表格内用 `compact` 变体,整块区域用默认变体。禁止再使用 antd 默认 `Empty` 插画。
|
||||
- 列表 / 表格加载统一用 `TableSkeleton`、`ListSkeleton`(`components/TableSkeleton.tsx`)替换内容区,不使用 antd `Table` 的转圈遮罩;卡片级加载用 `LoadingStack`。
|
||||
- 卡片内的写操作只在「有未保存修改」时使用主按钮,其余状态用次要按钮并禁用,同时用 `StatusTag` 标明修改状态。
|
||||
- 发布准备度、内容检查这类清单,条目文案只描述「检查什么」(中性名词),是否达标由「已完成 / 待完善」标签表达;帮助文案只在待完善时展示。禁止出现「已完成 · 请先完善…」这类自相矛盾的措辞。
|
||||
|
||||
---
|
||||
|
||||
## 7. 页面结构
|
||||
|
||||
以下为各页面的视觉结构约定,业务逻辑不变。
|
||||
|
||||
| 页面 | 结构要点 |
|
||||
| -------------- | ------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| 登录 | 居中 400px 卡片,标识 + 说明 + 表单 + 通栏主按钮;错误态展示在字段下方 |
|
||||
| 首次改密 | 同登录卡片形态,说明文案 + 三个密码字段 + 「保存新密码」 |
|
||||
| 品牌概览 | 品牌卡 + 三张指标卡(等宽一行)+ 两栏(发布准备度 / 品牌内容检查) |
|
||||
| 配置与发布 | 三 Tab(内容发布 / 小程序发布 / 小程序配置);内容发布含「选择表达方式」(行业模板 + 视觉模板 + 版本升级/回滚)+ 发布状态卡 + 草稿卡 + 历史版本表 |
|
||||
| 小程序页面 | 左右两栏:左 380px 编辑面板,右预览画布;预览内选中区域虚线高亮 + 区域名气泡 |
|
||||
| 信任内容 | 列表行(类型图标或配图 + 标题 + 发布状态标签 + 类型/展示位置说明 + 两行摘要 + 行内操作),按模板类型顺序排列,不用表格 |
|
||||
| 业务提供项 | 表格(名称 / 价格 / 状态开关 / 排序 / 操作)+ 新增弹窗 |
|
||||
| 咨询记录 | 顶部三指标 + 左 380px 列表 + 右详情的主从布局 |
|
||||
| 咨询表单与字段 | 咨询表单表(名称 / 版本 / 字段数 / 状态 / 操作)+ 新增与编辑弹窗(含选项编辑);高级自定义字段表 + 新增弹窗 |
|
||||
| 能力插件 | 插件卡片列表(图标 + 名称 + 说明 + 开关),停用态降低对比度 |
|
||||
| 团队成员 | 表格(成员 / 角色 / 状态 / 最近登录 / 操作)+ 邀请弹窗 |
|
||||
|
||||
两栏页面在小屏下折叠为单列,编辑/预览改为上下排列。
|
||||
|
||||
---
|
||||
|
||||
## 8. 无障碍与细节
|
||||
|
||||
- 正文与背景对比度不低于 4.5:1;标签文字与标签底色不低于 4.5:1。
|
||||
- 可点击元素最小热区 32x32px;纯图标按钮必须带 `aria-label`。
|
||||
- 焦点可见:所有可交互元素保留 1.5px 强调色聚焦描边。
|
||||
- 状态不能只靠颜色区分,需同时有文字。
|
||||
- 数字使用等宽数字排版(`font-variant-numeric: tabular-nums`),避免指标和价格跳动。
|
||||
|
||||
---
|
||||
|
||||
## 9. 禁止项
|
||||
|
||||
- 渐变、玻璃拟态、拟物纹理、装饰性插画铺满界面。
|
||||
- 深色侧栏、彩色大面积色块、实心鲜艳 Tag。
|
||||
- 重阴影、多重边框、卡片再套卡片超过两级。
|
||||
- emoji 作为图标;图标与文字混排时不对齐基线。
|
||||
- 页面内写死色值、圆角、间距魔法数字。
|
||||
- 一个页面出现多个主按钮竞争视觉焦点。
|
||||
|
||||
---
|
||||
|
||||
## 10. antd 令牌映射
|
||||
|
||||
落地时在 Admin 根节点用 `ConfigProvider` 注入,不逐页覆盖。
|
||||
|
||||
```ts
|
||||
const theme = {
|
||||
token: {
|
||||
colorPrimary: "#2563EB",
|
||||
colorLink: "#2563EB",
|
||||
colorText: "#1C1F23",
|
||||
colorTextSecondary: "#6B7280",
|
||||
colorTextTertiary: "#9AA1AC",
|
||||
colorTextQuaternary: "#C3C7CF",
|
||||
colorBgLayout: "#F7F8FA",
|
||||
colorBgContainer: "#FFFFFF",
|
||||
colorBorder: "#D8DBE0",
|
||||
colorBorderSecondary: "#E7E9EC",
|
||||
colorSplit: "#F0F1F3",
|
||||
colorFillTertiary: "#F7F8FA",
|
||||
colorFillQuaternary: "#FAFAFB",
|
||||
colorSuccess: "#12B76A",
|
||||
colorSuccessBg: "#ECFDF3",
|
||||
colorSuccessBorder: "#ABEFC6",
|
||||
colorSuccessText: "#067647",
|
||||
colorWarning: "#F79009",
|
||||
colorWarningBg: "#FFFAEB",
|
||||
colorWarningBorder: "#FEDF89",
|
||||
colorWarningText: "#B54708",
|
||||
colorError: "#F04438",
|
||||
colorErrorBg: "#FEF3F2",
|
||||
colorErrorBorder: "#FBD5D1",
|
||||
colorErrorText: "#B42318",
|
||||
colorInfo: "#2563EB",
|
||||
colorInfoBg: "#EFF4FF",
|
||||
colorInfoBorder: "#B2CCFF",
|
||||
colorInfoText: "#2563EB",
|
||||
borderRadius: 6,
|
||||
borderRadiusLG: 10,
|
||||
borderRadiusSM: 4,
|
||||
fontSize: 14,
|
||||
fontFamily:
|
||||
"Inter, 'PingFang SC', 'Noto Sans SC', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif",
|
||||
controlHeight: 32,
|
||||
controlHeightLG: 40,
|
||||
boxShadow: "0 1px 2px rgba(16, 24, 40, 0.04)",
|
||||
boxShadowSecondary: "0 8px 24px rgba(16, 24, 40, 0.08)",
|
||||
wireframe: false,
|
||||
},
|
||||
components: {
|
||||
Layout: {
|
||||
headerHeight: 56,
|
||||
headerBg: "#FFFFFF",
|
||||
headerPadding: "0 24px",
|
||||
siderBg: "#FFFFFF",
|
||||
bodyBg: "#F7F8FA",
|
||||
triggerBg: "#FFFFFF",
|
||||
triggerColor: "#475467",
|
||||
triggerHeight: 40,
|
||||
},
|
||||
Menu: {
|
||||
itemHeight: 36,
|
||||
itemBorderRadius: 6,
|
||||
itemBg: "transparent",
|
||||
itemColor: "#475467",
|
||||
itemHoverBg: "#F7F8FA",
|
||||
itemHoverColor: "#1C1F23",
|
||||
itemSelectedBg: "#EFF4FF",
|
||||
itemSelectedColor: "#2563EB",
|
||||
itemMarginInline: 8,
|
||||
itemMarginBlock: 2,
|
||||
groupTitleColor: "#9AA1AC",
|
||||
groupTitleFontSize: 12,
|
||||
collapsedWidth: 0,
|
||||
subMenuItemBg: "transparent",
|
||||
},
|
||||
Card: { paddingLG: 20, headerFontSize: 16, headerHeight: 52, headerHeightSM: 44 },
|
||||
Table: {
|
||||
headerBg: "#FAFAFB",
|
||||
headerColor: "#6B7280",
|
||||
rowHoverBg: "#FAFAFB",
|
||||
headerSplitColor: "transparent",
|
||||
borderColor: "#F0F1F3",
|
||||
cellPaddingBlock: 16,
|
||||
headerBorderRadius: 8,
|
||||
},
|
||||
Button: { fontWeight: 500, primaryShadow: "none", defaultShadow: "none" },
|
||||
Progress: { defaultColor: "#2563EB", remainingColor: "#F0F1F3", lineBorderRadius: 3 },
|
||||
Tag: { defaultBg: "#F2F4F7", defaultColor: "#475467", borderRadiusSM: 6 },
|
||||
Tabs: { inkBarColor: "#2563EB", itemSelectedColor: "#1C1F23", itemColor: "#6B7280" },
|
||||
Form: { labelColor: "#475467", labelFontSize: 13, verticalLabelPadding: "0 0 6px" },
|
||||
Modal: { borderRadiusLG: 12 },
|
||||
Statistic: { titleFontSize: 12, contentFontSize: 28 },
|
||||
Alert: { borderRadius: 8 },
|
||||
Descriptions: {
|
||||
labelBg: "#FAFAFB",
|
||||
labelColor: "#6B7280",
|
||||
contentColor: "#1C1F23",
|
||||
itemPaddingBottom: 12,
|
||||
},
|
||||
},
|
||||
};
|
||||
```
|
||||
|
||||
可执行来源是 `apps/admin/src/lib/theme.ts`,本块为同值快照;改令牌时两处一起改。
|
||||
|
||||
- 新增页面优先使用令牌与共享组件;禁止在 JSX 内写内联色值、字号、圆角(唯一的例外是通过 CSS 变量透传的数据色,例如视觉模板色板的 `--swatch-color`)。
|
||||
- 共享视觉组件清单:`AdminPageHeader`、`AdminSection`、`StatusTag`、`EmptyState`、`TableSkeleton` / `ListSkeleton`、`MetricCard`、`QueryState`。
|
||||
@@ -3,6 +3,7 @@
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"dependencies": {
|
||||
"@ant-design/icons": "^6.3.4",
|
||||
"@personal-brand/api-client": "workspace:*",
|
||||
"@tanstack/react-query": "^5.103.1",
|
||||
"antd": "^6.6.4",
|
||||
|
||||
@@ -0,0 +1,155 @@
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import {
|
||||
AppstoreOutlined,
|
||||
BarsOutlined,
|
||||
CloudUploadOutlined,
|
||||
FormOutlined,
|
||||
MessageOutlined,
|
||||
MobileOutlined,
|
||||
SafetyCertificateOutlined,
|
||||
TeamOutlined,
|
||||
ThunderboltOutlined,
|
||||
} from "@ant-design/icons";
|
||||
import { useLocation, useNavigate } from "react-router-dom";
|
||||
import { createApiClient } from "../lib/api.js";
|
||||
import { BrandMark } from "../components/BrandMark.js";
|
||||
import { StatusTag } from "../components/StatusTag.js";
|
||||
import {
|
||||
FeatureBrandPage,
|
||||
FeatureCapabilitiesPage,
|
||||
FeatureInquiriesPage,
|
||||
FeatureMembersPage,
|
||||
FeatureOverviewPage,
|
||||
FeaturePublicationPage,
|
||||
FeatureServicesPage,
|
||||
FeatureTrustContentPage,
|
||||
FeatureWorkspacePage,
|
||||
} from "./routes.js";
|
||||
import { LoadingStack } from "../components/LoadingStack.js";
|
||||
import { AdminMenu } from "../components/AdminMenu.js";
|
||||
import { adminMessage as message } from "../components/AdminMessage.js";
|
||||
import { AdminButton } from "../components/AdminButton.js";
|
||||
import { AdminSelect } from "../components/AdminSelect.js";
|
||||
import { AdminLayout } from "../components/AdminLayout.js";
|
||||
import { Navigate, Route, Routes } from "react-router-dom";
|
||||
import { Suspense } from "react";
|
||||
|
||||
export function Dashboard({ onLogout, role }: { onLogout: () => void; role: string }) {
|
||||
const navigate = useNavigate();
|
||||
const location = useLocation();
|
||||
const brand = useQuery({
|
||||
queryKey: ["admin-shell-brand"],
|
||||
queryFn: () => createApiClient().getAdminBrand(),
|
||||
});
|
||||
const memberships = useQuery({
|
||||
queryKey: ["admin-brand-memberships"],
|
||||
queryFn: () => createApiClient().listAdminBrands(),
|
||||
});
|
||||
const switchBrand = async (brandId: string) => {
|
||||
try {
|
||||
const result = await createApiClient().switchAdminBrand(brandId);
|
||||
localStorage.setItem("adminToken", result.token);
|
||||
window.location.reload();
|
||||
} catch (error) {
|
||||
message.error(error instanceof Error ? error.message : "品牌切换失败");
|
||||
}
|
||||
};
|
||||
const page = location.pathname.split("/")[2] || "overview";
|
||||
const items = [
|
||||
{
|
||||
type: "group" as const,
|
||||
label: "日常经营",
|
||||
children: [
|
||||
{ key: "overview", label: "当前品牌概览", icon: <AppstoreOutlined /> },
|
||||
{ key: "publication", label: "配置与发布", icon: <CloudUploadOutlined /> },
|
||||
{ key: "brand", label: "小程序页面", icon: <MobileOutlined /> },
|
||||
{ key: "trust", label: "信任内容", icon: <SafetyCertificateOutlined /> },
|
||||
{ key: "services", label: "业务提供项", icon: <BarsOutlined /> },
|
||||
{ key: "inquiries", label: "咨询记录", icon: <MessageOutlined /> },
|
||||
{ key: "workspace", label: "咨询表单与字段", icon: <FormOutlined /> },
|
||||
],
|
||||
},
|
||||
...(role === "editor"
|
||||
? []
|
||||
: [
|
||||
{
|
||||
type: "group" as const,
|
||||
label: "系统管理",
|
||||
children: [
|
||||
{ key: "capabilities", label: "能力插件", icon: <ThunderboltOutlined /> },
|
||||
{ key: "members", label: "团队成员", icon: <TeamOutlined /> },
|
||||
],
|
||||
},
|
||||
]),
|
||||
];
|
||||
return (
|
||||
<AdminLayout className="admin-shell">
|
||||
<AdminLayout.Sider className="admin-sider" breakpoint="lg" collapsedWidth={0} width={232}>
|
||||
<div className="admin-sider-brand">
|
||||
<BrandMark name={brand.data?.name} />
|
||||
<span className="admin-sider-brand-name">品牌工作区</span>
|
||||
</div>
|
||||
<AdminMenu
|
||||
selectedKeys={[page]}
|
||||
onClick={({ key }) => navigate(`/admin/${key}`)}
|
||||
items={items}
|
||||
/>
|
||||
</AdminLayout.Sider>
|
||||
<AdminLayout className="admin-main">
|
||||
<AdminLayout.Header className="admin-header">
|
||||
<div className="admin-header-left">
|
||||
<span className="admin-header-brand">{brand.data?.name || "当前品牌"}</span>
|
||||
<span className="admin-header-context">品牌工作区</span>
|
||||
<StatusTag
|
||||
tone={role === "owner" ? "info" : "neutral"}
|
||||
label={role === "owner" ? "负责人" : "内容编辑"}
|
||||
/>
|
||||
<AdminSelect
|
||||
size="small"
|
||||
variant="outlined"
|
||||
className="admin-brand-switcher"
|
||||
value={brand.data?.id}
|
||||
loading={memberships.isLoading}
|
||||
onChange={(value) => {
|
||||
if (value) void switchBrand(value);
|
||||
}}
|
||||
options={(memberships.data ?? []).map((item) => ({
|
||||
value: item.brand.id,
|
||||
label: item.brand.name,
|
||||
}))}
|
||||
/>
|
||||
</div>
|
||||
<AdminButton type="text" onClick={onLogout}>
|
||||
退出登录
|
||||
</AdminButton>
|
||||
</AdminLayout.Header>
|
||||
<AdminLayout.Content className="admin-content">
|
||||
<div className="admin-content-inner">
|
||||
<Suspense fallback={<LoadingStack />}>
|
||||
<Routes>
|
||||
<Route path="/" element={<Navigate to="overview" replace />} />
|
||||
<Route path="overview" element={<FeatureOverviewPage />} />
|
||||
<Route
|
||||
path="publication"
|
||||
element={<FeaturePublicationPage canManageTemplate={role !== "editor"} />}
|
||||
/>
|
||||
<Route path="brand" element={<FeatureBrandPage />} />
|
||||
<Route path="trust" element={<FeatureTrustContentPage />} />
|
||||
<Route path="services" element={<FeatureServicesPage />} />
|
||||
<Route path="inquiries" element={<FeatureInquiriesPage />} />
|
||||
<Route path="workspace" element={<FeatureWorkspacePage />} />
|
||||
{role === "editor" ? null : (
|
||||
<>
|
||||
<Route path="capabilities" element={<FeatureCapabilitiesPage />} />
|
||||
<Route path="members" element={<FeatureMembersPage />} />
|
||||
</>
|
||||
)}
|
||||
<Route path="*" element={<Navigate to="overview" replace />} />
|
||||
</Routes>
|
||||
</Suspense>
|
||||
</div>
|
||||
</AdminLayout.Content>
|
||||
</AdminLayout>
|
||||
</AdminLayout>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
import React, { useState } from "react";
|
||||
import { ChangePassword, Login } from "../features/auth/AuthPages.js";
|
||||
import { Dashboard } from "./Dashboard.js";
|
||||
import { adminMessage as message } from "../components/AdminMessage.js";
|
||||
|
||||
export function Root() {
|
||||
const [loggedIn, setLoggedIn] = useState(Boolean(localStorage.getItem("adminToken")));
|
||||
const [role, setRole] = useState(localStorage.getItem("adminRole") || "owner");
|
||||
const [mustChangePassword, setMustChangePassword] = useState(
|
||||
localStorage.getItem("adminMustChangePassword") === "true",
|
||||
);
|
||||
React.useEffect(() => {
|
||||
const expire = () => {
|
||||
message.warning("登录状态已失效,请重新登录");
|
||||
setLoggedIn(false);
|
||||
};
|
||||
window.addEventListener("admin-auth-expired", expire);
|
||||
return () => window.removeEventListener("admin-auth-expired", expire);
|
||||
}, []);
|
||||
const logout = () => {
|
||||
localStorage.removeItem("adminToken");
|
||||
localStorage.removeItem("adminRole");
|
||||
localStorage.removeItem("adminMustChangePassword");
|
||||
setLoggedIn(false);
|
||||
};
|
||||
if (!loggedIn)
|
||||
return (
|
||||
<Login
|
||||
onLogin={(session) => {
|
||||
setRole(session.role);
|
||||
setMustChangePassword(session.mustChangePassword);
|
||||
setLoggedIn(true);
|
||||
}}
|
||||
/>
|
||||
);
|
||||
if (mustChangePassword) return <ChangePassword onComplete={() => setMustChangePassword(false)} />;
|
||||
return <Dashboard onLogout={logout} role={role} />;
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
import React from "react";
|
||||
|
||||
export const FeatureInquiriesPage = React.lazy(() =>
|
||||
import("../features/inquiries/InquiriesPage.js").then((module) => ({
|
||||
default: module.InquiriesPage,
|
||||
})),
|
||||
);
|
||||
export const FeatureTrustContentPage = React.lazy(() =>
|
||||
import("../features/trust-content/TrustContentPage.js").then((module) => ({
|
||||
default: module.TrustContentPage,
|
||||
})),
|
||||
);
|
||||
export const FeatureServicesPage = React.lazy(() =>
|
||||
import("../features/services/ServicesPage.js").then((module) => ({
|
||||
default: module.ServicesPage,
|
||||
})),
|
||||
);
|
||||
export const FeatureBrandPage = React.lazy(() =>
|
||||
import("../features/brand/BrandPage.js").then((module) => ({ default: module.BrandPage })),
|
||||
);
|
||||
export const FeatureWorkspacePage = React.lazy(() =>
|
||||
import("../features/workspace/WorkspacePage.js").then((module) => ({
|
||||
default: module.WorkspacePage,
|
||||
})),
|
||||
);
|
||||
export const FeatureOverviewPage = React.lazy(() =>
|
||||
import("../features/overview/OverviewPage.js").then((module) => ({
|
||||
default: module.OverviewPage,
|
||||
})),
|
||||
);
|
||||
export const FeatureCapabilitiesPage = React.lazy(() =>
|
||||
import("../features/capabilities/CapabilitiesPage.js").then((module) => ({
|
||||
default: module.CapabilitiesPage,
|
||||
})),
|
||||
);
|
||||
export const FeatureMembersPage = React.lazy(() =>
|
||||
import("../features/team/MembersPage.js").then((module) => ({
|
||||
default: module.MembersPage,
|
||||
})),
|
||||
);
|
||||
export const FeaturePublicationPage = React.lazy(() =>
|
||||
import("../features/publication/PublicationPage.js").then((module) => ({
|
||||
default: module.PublicationPage,
|
||||
})),
|
||||
);
|
||||
@@ -0,0 +1,6 @@
|
||||
import { Button } from "antd";
|
||||
import type { ButtonProps } from "antd";
|
||||
|
||||
export function AdminButton(props: ButtonProps) {
|
||||
return <Button {...props} />;
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
import { Card } from "antd";
|
||||
import type { CardProps } from "antd";
|
||||
|
||||
export function AdminCard(props: CardProps) {
|
||||
return <Card {...props} />;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import { App, ConfigProvider } from "antd";
|
||||
import type { ConfigProviderProps } from "antd";
|
||||
import type { ReactNode } from "react";
|
||||
|
||||
export function AdminConfigProvider({
|
||||
children,
|
||||
...props
|
||||
}: ConfigProviderProps & { children?: ReactNode }) {
|
||||
return (
|
||||
<ConfigProvider {...props}>
|
||||
<App>{children}</App>
|
||||
</ConfigProvider>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
export { Form as AdminForm, Input as AdminInput } from "antd";
|
||||
@@ -0,0 +1,12 @@
|
||||
import { Layout } from "antd";
|
||||
import type { BasicProps } from "antd/es/layout/layout";
|
||||
|
||||
function AdminLayoutBase(props: BasicProps) {
|
||||
return <Layout {...props} />;
|
||||
}
|
||||
|
||||
export const AdminLayout = Object.assign(AdminLayoutBase, {
|
||||
Sider: Layout.Sider,
|
||||
Header: Layout.Header,
|
||||
Content: Layout.Content,
|
||||
});
|
||||
@@ -0,0 +1,6 @@
|
||||
import { Menu } from "antd";
|
||||
import type { MenuProps } from "antd";
|
||||
|
||||
export function AdminMenu(props: MenuProps) {
|
||||
return <Menu {...props} />;
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
export { message as adminMessage } from "antd";
|
||||
@@ -1,4 +1,3 @@
|
||||
import { Space, Typography } from "antd";
|
||||
import type { ReactNode } from "react";
|
||||
|
||||
export function AdminPageHeader({
|
||||
@@ -11,21 +10,12 @@ export function AdminPageHeader({
|
||||
extra?: ReactNode;
|
||||
}) {
|
||||
return (
|
||||
<Space
|
||||
align="start"
|
||||
style={{ width: "100%", justifyContent: "space-between", marginBottom: 24 }}
|
||||
>
|
||||
<div>
|
||||
<Typography.Title level={2} style={{ margin: 0 }}>
|
||||
{title}
|
||||
</Typography.Title>
|
||||
{description && (
|
||||
<Typography.Paragraph type="secondary" style={{ margin: "8px 0 0" }}>
|
||||
{description}
|
||||
</Typography.Paragraph>
|
||||
)}
|
||||
<header className="admin-page-header">
|
||||
<div className="admin-page-header-text">
|
||||
<h1 className="admin-page-header-title">{title}</h1>
|
||||
{description ? <p className="admin-page-header-description">{description}</p> : null}
|
||||
</div>
|
||||
{extra}
|
||||
</Space>
|
||||
</header>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
import type { ReactNode } from "react";
|
||||
|
||||
export function AdminSection({
|
||||
title,
|
||||
description,
|
||||
extra,
|
||||
children,
|
||||
}: {
|
||||
title?: ReactNode;
|
||||
description?: ReactNode;
|
||||
extra?: ReactNode;
|
||||
children: ReactNode;
|
||||
}) {
|
||||
return (
|
||||
<section className="admin-section">
|
||||
{title ? (
|
||||
<div className="admin-section-head">
|
||||
<div>
|
||||
<h2 className="admin-section-title">{title}</h2>
|
||||
{description ? <p className="admin-section-description">{description}</p> : null}
|
||||
</div>
|
||||
{extra}
|
||||
</div>
|
||||
) : null}
|
||||
{children}
|
||||
</section>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
import { Select } from "antd";
|
||||
import type { SelectProps } from "antd";
|
||||
|
||||
export function AdminSelect(props: SelectProps) {
|
||||
return <Select {...props} />;
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
import { Skeleton } from "antd";
|
||||
import type { SkeletonProps } from "antd";
|
||||
|
||||
export function AdminSkeleton(props: SkeletonProps) {
|
||||
return <Skeleton {...props} />;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
/**
|
||||
* 品牌标识:取品牌名首字渲染单字标记,未取到品牌时回落到中性字。
|
||||
* 视觉规则见 apps/admin/design.md 的「侧栏导航」。
|
||||
*/
|
||||
export function BrandMark({
|
||||
name,
|
||||
fallback = "品",
|
||||
className = "admin-sider-brand-mark",
|
||||
}: {
|
||||
name?: string | null | undefined;
|
||||
fallback?: string;
|
||||
className?: string;
|
||||
}) {
|
||||
const trimmed = name?.trim() ?? "";
|
||||
const mark = Array.from(trimmed)[0] ?? fallback;
|
||||
return <span className={className}>{mark}</span>;
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
import type { ReactNode } from "react";
|
||||
|
||||
export function EmptyState({
|
||||
icon,
|
||||
title,
|
||||
description,
|
||||
action,
|
||||
compact = false,
|
||||
}: {
|
||||
icon?: ReactNode;
|
||||
title: string;
|
||||
description?: string;
|
||||
action?: ReactNode;
|
||||
compact?: boolean;
|
||||
}) {
|
||||
const className = compact ? "admin-empty admin-empty--compact" : "admin-empty";
|
||||
return (
|
||||
<div className={className}>
|
||||
{icon ? <span className="admin-empty__icon">{icon}</span> : null}
|
||||
<p className="admin-empty__title">{title}</p>
|
||||
{description ? <p className="admin-empty__description">{description}</p> : null}
|
||||
{action ? <div className="admin-empty__action">{action}</div> : null}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,33 +1,142 @@
|
||||
import { Image, Input, Space, Typography } from "antd";
|
||||
import { CloudUploadOutlined, DeleteOutlined, PictureOutlined } from "@ant-design/icons";
|
||||
import { Alert, Button, Image, Popconfirm, Spin, Upload, message } from "antd";
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
import { apiBaseUrl, createApiClient } from "../lib/api.js";
|
||||
|
||||
interface ImageUrlFieldProps {
|
||||
id?: string;
|
||||
value?: string;
|
||||
onChange?: (value: string) => void;
|
||||
placeholder?: string;
|
||||
scope?: "brand" | "offering" | "trust";
|
||||
}
|
||||
|
||||
export function ImageUrlField({ value, onChange, placeholder }: ImageUrlFieldProps) {
|
||||
export function ImageUrlField({ id, value, onChange, placeholder, scope }: ImageUrlFieldProps) {
|
||||
const imageUrl = typeof value === "string" ? value.trim() : "";
|
||||
const [uploading, setUploading] = useState(false);
|
||||
const [storageStatus, setStorageStatus] = useState<
|
||||
"loading" | "ok" | "unavailable" | "unconfigured"
|
||||
>("loading");
|
||||
const client = useMemo(() => createApiClient(), []);
|
||||
|
||||
useEffect(() => {
|
||||
let active = true;
|
||||
client
|
||||
.getUploadConfig()
|
||||
.then((config) => {
|
||||
if (active) setStorageStatus(config.configured ? config.status : "unconfigured");
|
||||
})
|
||||
.catch(() => {
|
||||
if (active) setStorageStatus("unavailable");
|
||||
});
|
||||
return () => {
|
||||
active = false;
|
||||
};
|
||||
}, [client]);
|
||||
|
||||
async function upload(file: File) {
|
||||
if (!file.type.startsWith("image/")) {
|
||||
message.error("仅支持图片文件");
|
||||
return;
|
||||
}
|
||||
if (file.size > 10 * 1024 * 1024) {
|
||||
message.error("图片不能超过 10MB");
|
||||
return;
|
||||
}
|
||||
setUploading(true);
|
||||
try {
|
||||
const presign = await client.createPresignedUpload({
|
||||
fileName: file.name,
|
||||
contentType: file.type,
|
||||
...(scope ? { scope } : {}),
|
||||
});
|
||||
const isLocalUpload = presign.mode === "local";
|
||||
const uploadUrl = isLocalUpload
|
||||
? `${apiBaseUrl.replace(/\/$/, "")}${presign.uploadUrl}`
|
||||
: presign.uploadUrl;
|
||||
const response = await fetch(uploadUrl, {
|
||||
method: "PUT",
|
||||
headers: {
|
||||
"content-type": file.type,
|
||||
...(isLocalUpload
|
||||
? { authorization: `Bearer ${localStorage.getItem("adminToken") ?? ""}` }
|
||||
: {}),
|
||||
},
|
||||
body: file,
|
||||
});
|
||||
if (!response.ok) throw new Error(`upload failed: ${response.status}`);
|
||||
onChange?.(presign.publicUrl);
|
||||
} catch (error) {
|
||||
message.error(error instanceof Error ? error.message : "图片上传失败,请重试");
|
||||
} finally {
|
||||
setUploading(false);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<Space direction="vertical" size={8} style={{ width: "100%" }}>
|
||||
<Input
|
||||
value={value}
|
||||
onChange={(event) => onChange?.(event.target.value)}
|
||||
placeholder={placeholder ?? "粘贴图片地址"}
|
||||
/>
|
||||
<div className="admin-field-stack-xs admin-block">
|
||||
{storageStatus !== "ok" ? (
|
||||
<Alert
|
||||
type={storageStatus === "loading" ? "info" : "warning"}
|
||||
showIcon
|
||||
message={
|
||||
storageStatus === "loading"
|
||||
? "正在检查媒体存储..."
|
||||
: storageStatus === "unconfigured"
|
||||
? "媒体存储未配置,请先设置对象存储"
|
||||
: "媒体存储不可用,请检查对象存储配置"
|
||||
}
|
||||
/>
|
||||
) : null}
|
||||
{imageUrl ? (
|
||||
<Space align="start">
|
||||
<div className="admin-media-preview">
|
||||
<Image
|
||||
src={imageUrl}
|
||||
width={96}
|
||||
height={64}
|
||||
alt={placeholder ?? "图片预览"}
|
||||
width="100%"
|
||||
height={180}
|
||||
preview
|
||||
fallback="data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs="
|
||||
style={{ objectFit: "cover", borderRadius: 8, background: "#f5f5f5" }}
|
||||
/>
|
||||
<Typography.Text type="secondary">预览图</Typography.Text>
|
||||
</Space>
|
||||
<Popconfirm title="移除这张图片?" onConfirm={() => onChange?.("")}>
|
||||
<Button danger size="small" icon={<DeleteOutlined />} className="admin-thumb-remove">
|
||||
移除
|
||||
</Button>
|
||||
</Popconfirm>
|
||||
</div>
|
||||
) : (
|
||||
<Upload.Dragger
|
||||
accept="image/*"
|
||||
multiple={false}
|
||||
showUploadList={false}
|
||||
disabled={uploading || storageStatus !== "ok"}
|
||||
beforeUpload={(file) => {
|
||||
if (storageStatus === "ok") void upload(file);
|
||||
return false;
|
||||
}}
|
||||
>
|
||||
<p className="ant-upload-drag-icon">{uploading ? <Spin /> : <PictureOutlined />}</p>
|
||||
<p className="ant-upload-text">{uploading ? "上传中..." : "点击或拖拽上传图片"}</p>
|
||||
<p className="ant-upload-hint">JPG、PNG、WebP 或 AVIF,最大 10MB</p>
|
||||
</Upload.Dragger>
|
||||
)}
|
||||
{storageStatus === "unavailable" ? (
|
||||
<Button
|
||||
icon={<CloudUploadOutlined />}
|
||||
onClick={() => {
|
||||
setStorageStatus("loading");
|
||||
client
|
||||
.getUploadConfig()
|
||||
.then((config) =>
|
||||
setStorageStatus(config.configured ? config.status : "unconfigured"),
|
||||
)
|
||||
.catch(() => setStorageStatus("unavailable"));
|
||||
}}
|
||||
>
|
||||
重新检查存储
|
||||
</Button>
|
||||
) : null}
|
||||
</Space>
|
||||
<input {...(id ? { id } : {})} type="hidden" value={imageUrl} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
import { AdminCard } from "./AdminCard.js";
|
||||
import { AdminSkeleton } from "./AdminSkeleton.js";
|
||||
|
||||
export function LoadingStack({ rows = 3 }: { rows?: number }) {
|
||||
return (
|
||||
<div className="admin-loading-stack">
|
||||
<AdminCard>
|
||||
<AdminSkeleton active paragraph={{ rows: 2 }} title={false} />
|
||||
</AdminCard>
|
||||
{Array.from({ length: rows }).map((_, index) => (
|
||||
<AdminCard key={index}>
|
||||
<AdminSkeleton active paragraph={{ rows: 1 }} title={false} />
|
||||
</AdminCard>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
import { Card } from "antd";
|
||||
import type { ReactNode } from "react";
|
||||
|
||||
export function MetricCard({
|
||||
label,
|
||||
value,
|
||||
suffix,
|
||||
extra,
|
||||
}: {
|
||||
label: ReactNode;
|
||||
value: ReactNode;
|
||||
suffix?: ReactNode;
|
||||
extra?: ReactNode;
|
||||
}) {
|
||||
return (
|
||||
<Card>
|
||||
<div className="admin-metric-label">{label}</div>
|
||||
<div className="admin-metric-value">
|
||||
{value}
|
||||
{suffix ? <span className="admin-metric-suffix">{suffix}</span> : null}
|
||||
</div>
|
||||
{extra}
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
@@ -1,5 +1,10 @@
|
||||
import { Alert, Button, Card, Empty, Result, Spin } from "antd";
|
||||
import { Button } from "antd";
|
||||
import type { ReactNode } from "react";
|
||||
import { LoadingStack } from "./LoadingStack.js";
|
||||
|
||||
function errorMessage(error: unknown, fallback: string) {
|
||||
return error instanceof Error ? error.message : fallback;
|
||||
}
|
||||
|
||||
export function QueryState({
|
||||
loading,
|
||||
@@ -12,36 +17,31 @@ export function QueryState({
|
||||
onRetry?: () => void;
|
||||
children?: ReactNode;
|
||||
}) {
|
||||
if (loading)
|
||||
return (
|
||||
<Card>
|
||||
<Spin />
|
||||
</Card>
|
||||
);
|
||||
if (error) {
|
||||
return (
|
||||
<Result
|
||||
status="error"
|
||||
title="内容加载失败"
|
||||
subTitle={error instanceof Error ? error.message : "请检查 API 服务后重试"}
|
||||
extra={onRetry ? <Button onClick={onRetry}>重新加载</Button> : undefined}
|
||||
/>
|
||||
);
|
||||
}
|
||||
if (loading) return <LoadingStack />;
|
||||
if (error) return <ErrorNote error={error} onRetry={onRetry} />;
|
||||
return <>{children}</>;
|
||||
}
|
||||
|
||||
export function EmptyState({ description }: { description: string }) {
|
||||
return <Empty description={description} image={Empty.PRESENTED_IMAGE_SIMPLE} />;
|
||||
export function ErrorNote({
|
||||
error,
|
||||
onRetry,
|
||||
}: {
|
||||
error?: unknown;
|
||||
onRetry?: (() => void) | undefined;
|
||||
}) {
|
||||
if (!error) return null;
|
||||
return (
|
||||
<div className="admin-error-note" role="alert">
|
||||
<span>{errorMessage(error, "操作失败,请重试")}</span>
|
||||
{onRetry ? (
|
||||
<Button type="link" size="small" onClick={onRetry}>
|
||||
重试
|
||||
</Button>
|
||||
) : null}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export function MutationError({ error }: { error?: unknown }) {
|
||||
if (!error) return null;
|
||||
return (
|
||||
<Alert
|
||||
type="error"
|
||||
showIcon
|
||||
message={error instanceof Error ? error.message : "操作失败,请重试"}
|
||||
/>
|
||||
);
|
||||
return <ErrorNote error={error} />;
|
||||
}
|
||||
@@ -1,95 +1,42 @@
|
||||
import {
|
||||
Alert,
|
||||
Button,
|
||||
Col,
|
||||
Form,
|
||||
Input,
|
||||
InputNumber,
|
||||
Row,
|
||||
Select,
|
||||
Space,
|
||||
Switch,
|
||||
Typography,
|
||||
message,
|
||||
} from "antd";
|
||||
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||
import { useEffect, useMemo } from "react";
|
||||
import { Alert, Button, Col, Form, Row, Space, Typography } from "antd";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import type {
|
||||
Offering,
|
||||
TemplateAdminField,
|
||||
TemplateAdminSection,
|
||||
TrustContent,
|
||||
} from "@personal-brand/api-client";
|
||||
import { createApiClient } from "../lib/api.js";
|
||||
import { ImageUrlField } from "./ImageUrlField.js";
|
||||
import type { TemplateAdminSection } from "@personal-brand/api-client";
|
||||
import { TemplateListField } from "./TemplateListField.js";
|
||||
import { TemplateFieldRenderer } from "./TemplateFieldRenderer.js";
|
||||
import { MutationError } from "./QueryState.js";
|
||||
import {
|
||||
applyPresentationValues,
|
||||
applyStandardEntityValues,
|
||||
presentationFieldName,
|
||||
readPresentationValue,
|
||||
type PresentationValues,
|
||||
} from "../features/brand/presentation-bindings.js";
|
||||
import { presentationFieldName } from "../lib/presentation/presentation-bindings.js";
|
||||
import { useRecordContentEditorState } from "./record-content/useRecordContentEditorState.js";
|
||||
import type { RecordContentEditorProps, RecordContentSource } from "./record-content/types.js";
|
||||
|
||||
export type RecordContentSource = "offering" | "trust";
|
||||
export type { RecordContentEditorProps, RecordContentSource };
|
||||
|
||||
export interface RecordContentEditorProps {
|
||||
source: RecordContentSource;
|
||||
record: Offering | TrustContent;
|
||||
export function RecordContentFields({
|
||||
section,
|
||||
sectionKey = section.key,
|
||||
}: {
|
||||
section: TemplateAdminSection;
|
||||
context: "visual" | "services";
|
||||
onDraft?: (values: PresentationValues) => void;
|
||||
onSaved?: () => void;
|
||||
visualSelection?: { targetKey: string; page: string };
|
||||
}
|
||||
|
||||
function renderField(field: TemplateAdminField) {
|
||||
if (field.input === "textarea")
|
||||
return (
|
||||
<Input.TextArea
|
||||
rows={3}
|
||||
maxLength={field.maxLength}
|
||||
showCount={!!field.maxLength}
|
||||
placeholder={field.placeholder}
|
||||
/>
|
||||
);
|
||||
if (field.input === "image")
|
||||
return <ImageUrlField {...(field.placeholder ? { placeholder: field.placeholder } : {})} />;
|
||||
if (field.input === "phone") return <Input type="tel" placeholder={field.placeholder} />;
|
||||
if (field.input === "number") return <InputNumber min={0} placeholder={field.placeholder} />;
|
||||
if (field.input === "boolean") return <Switch />;
|
||||
if (field.input === "select")
|
||||
return <Select options={(field.options ?? []).map((item) => ({ ...item }))} />;
|
||||
if (field.input === "multi-select")
|
||||
return (
|
||||
<Select
|
||||
mode="multiple"
|
||||
options={(field.options ?? []).map((item) => ({ ...item }))}
|
||||
placeholder={field.placeholder}
|
||||
/>
|
||||
);
|
||||
return <Input placeholder={field.placeholder} />;
|
||||
}
|
||||
|
||||
export function RecordContentFields({ section }: { section: TemplateAdminSection }) {
|
||||
sectionKey?: string;
|
||||
}) {
|
||||
return (
|
||||
<Row gutter={16}>
|
||||
{section.fields.map((field) => (
|
||||
<Col key={field.key} xs={24} md={24}>
|
||||
{field.input === "list" ? (
|
||||
<TemplateListField field={field} name={presentationFieldName(section.key, field.key)} />
|
||||
<TemplateListField field={field} name={presentationFieldName(sectionKey, field.key)} />
|
||||
) : (
|
||||
<Form.Item
|
||||
name={presentationFieldName(section.key, field.key)}
|
||||
name={presentationFieldName(sectionKey, field.key)}
|
||||
label={field.label}
|
||||
htmlFor={presentationFieldName(sectionKey, field.key)}
|
||||
{...(field.help ? { help: field.help } : {})}
|
||||
{...(field.required
|
||||
? { rules: [{ required: true, message: `请填写${field.label}` }] }
|
||||
: {})}
|
||||
>
|
||||
{renderField(field)}
|
||||
<TemplateFieldRenderer
|
||||
field={field}
|
||||
id={presentationFieldName(sectionKey, field.key)}
|
||||
/>
|
||||
</Form.Item>
|
||||
)}
|
||||
</Col>
|
||||
@@ -108,63 +55,23 @@ export function RecordContentEditor({
|
||||
visualSelection,
|
||||
}: RecordContentEditorProps) {
|
||||
const navigate = useNavigate();
|
||||
const [form] = Form.useForm<PresentationValues>();
|
||||
const queryClient = useQueryClient();
|
||||
const recordName = "name" in record ? record.name : record.title;
|
||||
const initialValues = useMemo(
|
||||
() =>
|
||||
Object.fromEntries(
|
||||
section.fields.map((field) => [
|
||||
presentationFieldName(section.key, field.key),
|
||||
readPresentationValue(
|
||||
record.config,
|
||||
field.binding,
|
||||
field,
|
||||
record as unknown as Record<string, unknown>,
|
||||
),
|
||||
]),
|
||||
),
|
||||
[record, section],
|
||||
);
|
||||
useEffect(() => form.setFieldsValue(initialValues), [form, initialValues]);
|
||||
const save = useMutation({
|
||||
mutationFn: async (values: PresentationValues): Promise<void> => {
|
||||
const config = applyPresentationValues(record.config, [section], values);
|
||||
const standard = applyStandardEntityValues(
|
||||
record as unknown as Record<string, unknown>,
|
||||
source,
|
||||
[section],
|
||||
values,
|
||||
);
|
||||
const changed = Object.fromEntries(
|
||||
Object.entries(standard).filter(
|
||||
([key, value]) =>
|
||||
key !== "config" && value !== (record as unknown as Record<string, unknown>)[key],
|
||||
),
|
||||
);
|
||||
const client = createApiClient();
|
||||
if (source === "offering")
|
||||
await client.updateAdminOffering(record.id, { ...changed, config });
|
||||
else await client.updateAdminTrustContent(record.id, { ...changed, config });
|
||||
},
|
||||
onSuccess: () => {
|
||||
message.success("已保存内容草稿,发布后访客才会看到更新");
|
||||
onSaved?.();
|
||||
void queryClient.invalidateQueries({
|
||||
queryKey: [source === "offering" ? "admin-offerings" : "trust-content"],
|
||||
});
|
||||
void queryClient.invalidateQueries({ queryKey: ["admin-workspace"] });
|
||||
void queryClient.invalidateQueries({ queryKey: ["admin-preview-workspace"] });
|
||||
},
|
||||
const { form, handleValuesChange, initialValues, save, submit } = useRecordContentEditorState({
|
||||
source,
|
||||
record,
|
||||
section,
|
||||
...(onDraft ? { onDraft } : {}),
|
||||
...(onSaved ? { onSaved } : {}),
|
||||
});
|
||||
|
||||
return (
|
||||
<Form
|
||||
form={form}
|
||||
layout="vertical"
|
||||
initialValues={initialValues}
|
||||
onValuesChange={(_, values) => onDraft?.(values)}
|
||||
onFinish={(values) => save.mutate(values)}
|
||||
style={{ minHeight: 0, display: "flex", flexDirection: "column" }}
|
||||
onValuesChange={handleValuesChange}
|
||||
onFinish={submit}
|
||||
className="admin-form-column"
|
||||
>
|
||||
<Alert
|
||||
type="info"
|
||||
@@ -181,11 +88,11 @@ export function RecordContentEditor({
|
||||
}
|
||||
/>
|
||||
{save.isPending ? <Typography.Text type="secondary">正在保存内容…</Typography.Text> : null}
|
||||
<Typography.Paragraph type="secondary">{section.description}</Typography.Paragraph>
|
||||
<div style={{ flex: 1 }}>
|
||||
<p className="admin-section-description">{section.description}</p>
|
||||
<div className="admin-flex-1">
|
||||
<RecordContentFields section={section} />
|
||||
</div>
|
||||
<Space direction="vertical" style={{ width: "100%", marginTop: 24 }}>
|
||||
<div className="admin-actions admin-offset-top-lg">
|
||||
<MutationError error={save.error} />
|
||||
<Space wrap>
|
||||
<Button type="primary" htmlType="submit" loading={save.isPending}>
|
||||
@@ -197,7 +104,7 @@ export function RecordContentEditor({
|
||||
onClick={() =>
|
||||
navigate("/admin/brand", {
|
||||
state: {
|
||||
targetKey: visualSelection?.targetKey ?? "linjing-editorial.offerings.item",
|
||||
targetKey: visualSelection?.targetKey ?? "offering.list.item",
|
||||
recordId: record.id,
|
||||
},
|
||||
})
|
||||
@@ -207,7 +114,7 @@ export function RecordContentEditor({
|
||||
</Button>
|
||||
) : null}
|
||||
</Space>
|
||||
</Space>
|
||||
</div>
|
||||
</Form>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
export type StatusTone = "success" | "warning" | "error" | "info" | "neutral";
|
||||
|
||||
const TONE_BY_STATUS: Record<string, StatusTone> = {
|
||||
published: "success",
|
||||
approved: "success",
|
||||
completed: "success",
|
||||
active: "success",
|
||||
enabled: "success",
|
||||
building: "info",
|
||||
built: "neutral",
|
||||
uploaded: "info",
|
||||
pending: "neutral",
|
||||
draft: "neutral",
|
||||
superseded: "neutral",
|
||||
disabled: "neutral",
|
||||
review: "warning",
|
||||
reviewing: "warning",
|
||||
under_review: "warning",
|
||||
processing: "warning",
|
||||
rejected: "error",
|
||||
failed: "error",
|
||||
error: "error",
|
||||
};
|
||||
|
||||
const LABELS: Record<string, string> = {
|
||||
published: "已发布",
|
||||
approved: "已通过",
|
||||
completed: "已完成",
|
||||
active: "已启用",
|
||||
enabled: "已公开",
|
||||
building: "构建中",
|
||||
built: "待上传",
|
||||
uploaded: "已上传微信",
|
||||
pending: "待处理",
|
||||
draft: "草稿",
|
||||
superseded: "已过期",
|
||||
disabled: "已停用",
|
||||
review: "审核中",
|
||||
reviewing: "审核中",
|
||||
under_review: "审核中",
|
||||
processing: "处理中",
|
||||
rejected: "已拒绝",
|
||||
failed: "失败",
|
||||
error: "异常",
|
||||
};
|
||||
|
||||
export function statusLabel(status: string | null | undefined, fallback = "未知"): string {
|
||||
if (!status) return fallback;
|
||||
return LABELS[status] ?? status;
|
||||
}
|
||||
|
||||
export function StatusTag({
|
||||
status,
|
||||
label,
|
||||
tone,
|
||||
}: {
|
||||
status?: string | null;
|
||||
label?: string;
|
||||
tone?: StatusTone;
|
||||
}) {
|
||||
const resolvedTone = tone ?? (status ? TONE_BY_STATUS[status] : undefined) ?? "neutral";
|
||||
return (
|
||||
<span className="admin-status-tag" data-tone={resolvedTone}>
|
||||
{label ?? statusLabel(status)}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
import { Skeleton } from "antd";
|
||||
|
||||
export function TableSkeleton({ rows = 4 }: { rows?: number }) {
|
||||
return (
|
||||
<div className="admin-table-skeleton" role="status" aria-live="polite">
|
||||
{Array.from({ length: rows }).map((_, index) => (
|
||||
<div key={index} className="admin-table-skeleton__row">
|
||||
<Skeleton.Input active size="small" block />
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export function ListSkeleton({ rows = 3 }: { rows?: number }) {
|
||||
return (
|
||||
<div className="admin-list-skeleton" role="status" aria-live="polite">
|
||||
{Array.from({ length: rows }).map((_, index) => (
|
||||
<div key={index} className="admin-list-skeleton__row">
|
||||
<Skeleton.Input active size="small" className="admin-list-skeleton__thumb" />
|
||||
<div className="admin-list-skeleton__body">
|
||||
<Skeleton.Input active size="small" block />
|
||||
<Skeleton.Input active size="small" block />
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
import { Input, InputNumber, Select, Switch } from "antd";
|
||||
import type { TemplateAdminField } from "@personal-brand/api-client";
|
||||
import { ImageUrlField } from "./ImageUrlField.js";
|
||||
|
||||
export function TemplateFieldRenderer({
|
||||
field,
|
||||
id,
|
||||
value,
|
||||
onChange,
|
||||
}: {
|
||||
field: TemplateAdminField;
|
||||
id?: string;
|
||||
value?: unknown;
|
||||
onChange?: (value: unknown) => void;
|
||||
}) {
|
||||
if (field.input === "textarea")
|
||||
return (
|
||||
<Input.TextArea
|
||||
{...(id ? { id } : {})}
|
||||
value={typeof value === "string" ? value : ""}
|
||||
onChange={(event) => onChange?.(event.target.value)}
|
||||
rows={3}
|
||||
maxLength={field.maxLength}
|
||||
showCount={!!field.maxLength}
|
||||
placeholder={field.placeholder}
|
||||
/>
|
||||
);
|
||||
if (field.input === "image")
|
||||
return (
|
||||
<ImageUrlField
|
||||
{...(id ? { id } : {})}
|
||||
{...(field.placeholder ? { placeholder: field.placeholder } : {})}
|
||||
{...(typeof value === "string" ? { value } : {})}
|
||||
{...(onChange ? { onChange: (next: string) => onChange(next) } : {})}
|
||||
/>
|
||||
);
|
||||
if (field.input === "phone")
|
||||
return (
|
||||
<Input
|
||||
{...(id ? { id } : {})}
|
||||
type="tel"
|
||||
placeholder={field.placeholder}
|
||||
value={typeof value === "string" ? value : ""}
|
||||
onChange={(event) => onChange?.(event.target.value)}
|
||||
/>
|
||||
);
|
||||
if (field.input === "number")
|
||||
return (
|
||||
<InputNumber
|
||||
{...(id ? { id } : {})}
|
||||
value={typeof value === "number" ? value : null}
|
||||
onChange={(input) => onChange?.(input ?? undefined)}
|
||||
min={0}
|
||||
className="admin-block"
|
||||
placeholder={field.placeholder}
|
||||
/>
|
||||
);
|
||||
if (field.input === "boolean")
|
||||
return (
|
||||
<Switch
|
||||
{...(id ? { id } : {})}
|
||||
checked={Boolean(value)}
|
||||
onChange={(checked) => onChange?.(checked)}
|
||||
/>
|
||||
);
|
||||
if (field.input === "select")
|
||||
return (
|
||||
<Select
|
||||
{...(id ? { id } : {})}
|
||||
options={(field.options ?? []).map((item) => ({ ...item }))}
|
||||
value={typeof value === "string" || typeof value === "number" ? value : undefined}
|
||||
onChange={(selected) => onChange?.(selected)}
|
||||
{...(field.placeholder ? { placeholder: field.placeholder } : {})}
|
||||
/>
|
||||
);
|
||||
if (field.input === "multi-select")
|
||||
return (
|
||||
<Select
|
||||
{...(id ? { id } : {})}
|
||||
mode="multiple"
|
||||
options={(field.options ?? []).map((item) => ({ ...item }))}
|
||||
value={Array.isArray(value) ? value.map(String) : []}
|
||||
onChange={(selected) => onChange?.(selected)}
|
||||
placeholder={field.placeholder}
|
||||
/>
|
||||
);
|
||||
return (
|
||||
<Input
|
||||
{...(id ? { id } : {})}
|
||||
value={typeof value === "string" ? value : ""}
|
||||
onChange={(event) => onChange?.(event.target.value)}
|
||||
maxLength={field.maxLength}
|
||||
placeholder={field.placeholder}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -1,5 +1,12 @@
|
||||
import { Button, Form, Input, Space } from "antd";
|
||||
import { Button, Card, Collapse, Form, Input, Space, Typography } from "antd";
|
||||
import {
|
||||
CaretDownOutlined,
|
||||
CaretUpOutlined,
|
||||
DeleteOutlined,
|
||||
PlusOutlined,
|
||||
} from "@ant-design/icons";
|
||||
import type { TemplateAdminField } from "@personal-brand/api-client";
|
||||
import { EmptyState } from "./EmptyState.js";
|
||||
|
||||
export function TemplateListField({
|
||||
field,
|
||||
@@ -22,43 +29,109 @@ export function TemplateListField({
|
||||
]}
|
||||
>
|
||||
{(rows, { add, remove, move }, { errors }) => (
|
||||
<Space direction="vertical" style={{ width: "100%" }}>
|
||||
{rows.map((row, index) => (
|
||||
<Space key={row.key} align="start" wrap>
|
||||
{field.itemFields?.map((itemField) => (
|
||||
<Form.Item
|
||||
key={itemField.key}
|
||||
name={[row.name, itemField.key]}
|
||||
label={`${index + 1}. ${itemField.label}`}
|
||||
rules={
|
||||
itemField.required === false
|
||||
? []
|
||||
: [{ required: true, message: `请填写${itemField.label}` }]
|
||||
}
|
||||
>
|
||||
{itemField.input === "textarea" ? <Input.TextArea rows={2} /> : <Input />}
|
||||
</Form.Item>
|
||||
))}
|
||||
<Button onClick={() => remove(row.name)}>删除</Button>
|
||||
<Button
|
||||
aria-label={`上移第 ${index + 1} 项`}
|
||||
disabled={index === 0}
|
||||
onClick={() => move(index, index - 1)}
|
||||
<div className="admin-stack admin-stack-tight">
|
||||
{rows.length === 0 ? <EmptyState compact title={`还没有${field.label}内容`} /> : null}
|
||||
{rows.map((row, index) => {
|
||||
const titleField = field.itemFields?.[0];
|
||||
const primaryTitle = titleField ? (
|
||||
<Form.Item
|
||||
noStyle
|
||||
shouldUpdate={(prev: unknown, next: unknown) => {
|
||||
const previous = Array.isArray(prev)
|
||||
? (prev[row.name] as Record<string, unknown> | undefined)
|
||||
: undefined;
|
||||
const nextRow = Array.isArray(next)
|
||||
? (next[row.name] as Record<string, unknown> | undefined)
|
||||
: undefined;
|
||||
return previous?.[titleField.key] !== nextRow?.[titleField.key];
|
||||
}}
|
||||
>
|
||||
上移
|
||||
</Button>
|
||||
<Button
|
||||
aria-label={`下移第 ${index + 1} 项`}
|
||||
disabled={index === rows.length - 1}
|
||||
onClick={() => move(index, index + 1)}
|
||||
{({ getFieldValue }) => {
|
||||
const value = String(
|
||||
getFieldValue([...name, row.name, titleField.key] as const) ?? "",
|
||||
);
|
||||
return (
|
||||
<Typography.Text
|
||||
strong
|
||||
>{`${index + 1}. ${value || titleField.label}`}</Typography.Text>
|
||||
);
|
||||
}}
|
||||
</Form.Item>
|
||||
) : (
|
||||
<Typography.Text strong>{`${index + 1}. ${field.label}`}</Typography.Text>
|
||||
);
|
||||
return (
|
||||
<Card
|
||||
key={row.key}
|
||||
size="small"
|
||||
title={primaryTitle}
|
||||
extra={
|
||||
<Space size={0}>
|
||||
<Button
|
||||
type="text"
|
||||
size="small"
|
||||
aria-label={`上移第 ${index + 1} 项`}
|
||||
icon={<CaretUpOutlined />}
|
||||
disabled={index === 0}
|
||||
onClick={() => move(index, index - 1)}
|
||||
/>
|
||||
<Button
|
||||
type="text"
|
||||
size="small"
|
||||
aria-label={`下移第 ${index + 1} 项`}
|
||||
icon={<CaretDownOutlined />}
|
||||
disabled={index === rows.length - 1}
|
||||
onClick={() => move(index, index + 1)}
|
||||
/>
|
||||
<Button
|
||||
type="text"
|
||||
danger
|
||||
size="small"
|
||||
aria-label={`删除第 ${index + 1} 项`}
|
||||
icon={<DeleteOutlined />}
|
||||
onClick={() => remove(row.name)}
|
||||
/>
|
||||
</Space>
|
||||
}
|
||||
>
|
||||
下移
|
||||
</Button>
|
||||
</Space>
|
||||
))}
|
||||
{field.itemFields?.map((itemField) => (
|
||||
<Form.Item
|
||||
key={itemField.key}
|
||||
name={[row.name, itemField.key]}
|
||||
label={itemField.label}
|
||||
rules={
|
||||
itemField.required === false
|
||||
? []
|
||||
: [{ required: true, message: `请填写${itemField.label}` }]
|
||||
}
|
||||
>
|
||||
{itemField.input === "textarea" ? <Input.TextArea rows={2} /> : <Input />}
|
||||
</Form.Item>
|
||||
))}
|
||||
</Card>
|
||||
);
|
||||
})}
|
||||
{rows.length > 1 ? (
|
||||
<Collapse
|
||||
ghost
|
||||
items={[
|
||||
{
|
||||
key: "sort-help",
|
||||
label: "排序说明",
|
||||
children: (
|
||||
<Typography.Text type="secondary">
|
||||
使用每张卡片右上角的箭头调整顺序,保存后预览也会按当前顺序展示。
|
||||
</Typography.Text>
|
||||
),
|
||||
},
|
||||
]}
|
||||
/>
|
||||
) : null}
|
||||
<Form.ErrorList errors={errors} />
|
||||
<Button onClick={() => add()}>新增{field.label}</Button>
|
||||
</Space>
|
||||
<Button block icon={<PlusOutlined />} onClick={() => add()}>
|
||||
新增{field.label}
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
</Form.List>
|
||||
</Form.Item>
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
import type { Offering, TemplateAdminSection, TrustContent } from "@personal-brand/api-client";
|
||||
import type { PresentationValues } from "../../lib/presentation/presentation-bindings.js";
|
||||
|
||||
export type RecordContentSource = "offering" | "trust";
|
||||
|
||||
export interface RecordContentEditorProps {
|
||||
source: RecordContentSource;
|
||||
record: Offering | TrustContent;
|
||||
section: TemplateAdminSection;
|
||||
context: "visual" | "services";
|
||||
onDraft?: (values: PresentationValues) => void;
|
||||
onSaved?: () => void;
|
||||
visualSelection?: { targetKey: string; page: string };
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
import { Form, message } from "antd";
|
||||
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
import type { TemplateAdminSection } from "@personal-brand/api-client";
|
||||
import type { Offering, TrustContent } from "@personal-brand/api-client";
|
||||
import { createApiClient } from "../../lib/api.js";
|
||||
import {
|
||||
applyPresentationValues,
|
||||
applyStandardEntityValues,
|
||||
presentationFieldName,
|
||||
readPresentationValue,
|
||||
type PresentationValues,
|
||||
} from "../../lib/presentation/presentation-bindings.js";
|
||||
import type { RecordContentSource } from "./types.js";
|
||||
|
||||
function createInitialValues(
|
||||
record: Offering | TrustContent,
|
||||
section: TemplateAdminSection,
|
||||
): PresentationValues {
|
||||
return Object.fromEntries(
|
||||
section.fields.map((field) => [
|
||||
presentationFieldName(section.key, field.key),
|
||||
readPresentationValue(
|
||||
record.config,
|
||||
field.binding,
|
||||
field,
|
||||
record as unknown as Record<string, unknown>,
|
||||
),
|
||||
]),
|
||||
);
|
||||
}
|
||||
|
||||
function createChangedStandardValues(
|
||||
record: Offering | TrustContent,
|
||||
source: RecordContentSource,
|
||||
section: TemplateAdminSection,
|
||||
values: PresentationValues,
|
||||
) {
|
||||
const entity = record as unknown as Record<string, unknown>;
|
||||
const standard = applyStandardEntityValues(entity, source, [section], values);
|
||||
|
||||
return Object.fromEntries(
|
||||
Object.entries(standard).filter(
|
||||
([key, value]) => key !== "config" && (key in entity || value !== entity[key]),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export function useRecordContentEditorState({
|
||||
source,
|
||||
record,
|
||||
section,
|
||||
onDraft,
|
||||
onSaved,
|
||||
}: {
|
||||
source: RecordContentSource;
|
||||
record: Offering | TrustContent;
|
||||
section: TemplateAdminSection;
|
||||
onDraft?: ((values: PresentationValues) => void) | undefined;
|
||||
onSaved?: (() => void) | undefined;
|
||||
}) {
|
||||
const [form] = Form.useForm<PresentationValues>();
|
||||
const queryClient = useQueryClient();
|
||||
const [draftValues, setDraftValues] = useState<PresentationValues>(() =>
|
||||
createInitialValues(record, section),
|
||||
);
|
||||
const initialValues = useMemo(() => createInitialValues(record, section), [record, section]);
|
||||
|
||||
useEffect(() => form.setFieldsValue(initialValues), [form, initialValues]);
|
||||
|
||||
const save = useMutation({
|
||||
mutationFn: async (values: PresentationValues): Promise<void> => {
|
||||
const config = applyPresentationValues(record.config, [section], values);
|
||||
const changed = createChangedStandardValues(record, source, section, values);
|
||||
const client = createApiClient();
|
||||
|
||||
if (source === "offering") {
|
||||
await client.updateAdminOffering(record.id, { ...changed, config });
|
||||
} else {
|
||||
await client.updateAdminTrustContent(record.id, { ...changed, config });
|
||||
}
|
||||
},
|
||||
onSuccess: () => {
|
||||
message.success("已保存内容草稿,发布后访客才会看到更新");
|
||||
onSaved?.();
|
||||
void queryClient.invalidateQueries({
|
||||
queryKey: [source === "offering" ? "admin-offerings" : "trust-content"],
|
||||
});
|
||||
void queryClient.invalidateQueries({ queryKey: ["admin-workspace"] });
|
||||
void queryClient.invalidateQueries({ queryKey: ["admin-preview-workspace"] });
|
||||
if (source === "offering") {
|
||||
void queryClient.invalidateQueries({ queryKey: ["admin-workspace-offering-fields"] });
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
const submit = (values: PresentationValues) => {
|
||||
const currentValues = form.getFieldsValue(true) as PresentationValues;
|
||||
save.mutate({ ...draftValues, ...values, ...currentValues });
|
||||
};
|
||||
|
||||
const handleValuesChange = (_values: PresentationValues) => {
|
||||
const currentValues = form.getFieldsValue(true) as PresentationValues;
|
||||
const next = { ...draftValues, ..._values, ...currentValues };
|
||||
setDraftValues(next);
|
||||
onDraft?.(next);
|
||||
};
|
||||
|
||||
return {
|
||||
draftValues,
|
||||
form,
|
||||
handleValuesChange,
|
||||
initialValues,
|
||||
save,
|
||||
submit,
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
import { useState } from "react";
|
||||
import { createApiClient } from "../../lib/api.js";
|
||||
import { BrandMark } from "../../components/BrandMark.js";
|
||||
import { adminMessage as message } from "../../components/AdminMessage.js";
|
||||
import { AdminButton } from "../../components/AdminButton.js";
|
||||
import { AdminCard } from "../../components/AdminCard.js";
|
||||
import { AdminForm, AdminInput } from "../../components/AdminForm.js";
|
||||
|
||||
export function Login({
|
||||
onLogin,
|
||||
}: {
|
||||
onLogin: (session: { role: string; mustChangePassword: boolean }) => void;
|
||||
}) {
|
||||
const [form] = AdminForm.useForm();
|
||||
const [loading, setLoading] = useState(false);
|
||||
async function submit(values: { username: string; password: string }) {
|
||||
setLoading(true);
|
||||
try {
|
||||
const result = await createApiClient().loginAdmin(values.username, values.password);
|
||||
localStorage.setItem("adminToken", result.token);
|
||||
localStorage.setItem("adminRole", result.role);
|
||||
localStorage.setItem("adminMustChangePassword", String(result.mustChangePassword));
|
||||
onLogin(result);
|
||||
} catch (error) {
|
||||
message.error(error instanceof Error ? error.message : "登录失败");
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}
|
||||
return (
|
||||
<div className="admin-auth">
|
||||
<AdminCard className="admin-auth-card">
|
||||
<div className="admin-auth-brand">
|
||||
<BrandMark />
|
||||
<span className="admin-header-brand">个人品牌后台</span>
|
||||
</div>
|
||||
<p className="admin-auth-hint">管理你的品牌表达、内容发布与客户咨询。</p>
|
||||
<AdminForm form={form} layout="vertical" onFinish={submit}>
|
||||
<AdminForm.Item
|
||||
name="username"
|
||||
label="账号"
|
||||
initialValue="admin"
|
||||
rules={[{ required: true }]}
|
||||
>
|
||||
<AdminInput />
|
||||
</AdminForm.Item>
|
||||
<AdminForm.Item name="password" label="密码" rules={[{ required: true }]}>
|
||||
<AdminInput.Password />
|
||||
</AdminForm.Item>
|
||||
<AdminButton type="primary" size="large" htmlType="submit" loading={loading} block>
|
||||
登录
|
||||
</AdminButton>
|
||||
</AdminForm>
|
||||
<p className="admin-auth-footnote">仅限授权成员访问。</p>
|
||||
</AdminCard>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export function ChangePassword({ onComplete }: { onComplete: () => void }) {
|
||||
const [form] = AdminForm.useForm<{
|
||||
currentPassword: string;
|
||||
newPassword: string;
|
||||
confirmPassword: string;
|
||||
}>();
|
||||
const [loading, setLoading] = useState(false);
|
||||
async function submit(values: {
|
||||
currentPassword: string;
|
||||
newPassword: string;
|
||||
confirmPassword: string;
|
||||
}) {
|
||||
if (values.newPassword !== values.confirmPassword) {
|
||||
message.error("两次输入的新密码不一致");
|
||||
return;
|
||||
}
|
||||
setLoading(true);
|
||||
try {
|
||||
await createApiClient().changeAdminPassword(values.currentPassword, values.newPassword);
|
||||
localStorage.setItem("adminMustChangePassword", "false");
|
||||
message.success("密码已更新");
|
||||
onComplete();
|
||||
} catch (error) {
|
||||
message.error(error instanceof Error ? error.message : "密码更新失败");
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}
|
||||
return (
|
||||
<div className="admin-auth">
|
||||
<AdminCard className="admin-auth-card">
|
||||
<div className="admin-auth-brand">
|
||||
<BrandMark />
|
||||
<span className="admin-header-brand">首次登录需要修改密码</span>
|
||||
</div>
|
||||
<p className="admin-auth-hint">请先设置只有你本人知道的新密码。</p>
|
||||
<AdminForm form={form} layout="vertical" onFinish={submit}>
|
||||
<AdminForm.Item name="currentPassword" label="初始密码" rules={[{ required: true }]}>
|
||||
<AdminInput.Password />
|
||||
</AdminForm.Item>
|
||||
<AdminForm.Item
|
||||
name="newPassword"
|
||||
label="新密码"
|
||||
rules={[{ required: true, min: 8, message: "请输入至少 8 位新密码" }]}
|
||||
>
|
||||
<AdminInput.Password />
|
||||
</AdminForm.Item>
|
||||
<AdminForm.Item name="confirmPassword" label="确认密码" rules={[{ required: true }]}>
|
||||
<AdminInput.Password />
|
||||
</AdminForm.Item>
|
||||
<AdminButton type="primary" size="large" htmlType="submit" loading={loading} block>
|
||||
保存新密码
|
||||
</AdminButton>
|
||||
</AdminForm>
|
||||
</AdminCard>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,19 +1,29 @@
|
||||
.brand-page__content {
|
||||
max-width: 960px;
|
||||
}
|
||||
|
||||
.brand-page__content[hidden] {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.brand-page__toolbar {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
gap: 16px;
|
||||
padding: 16px 0;
|
||||
border-bottom: 1px solid #e5e7eb;
|
||||
margin-bottom: 20px;
|
||||
padding: 8px 12px;
|
||||
border: 1px solid var(--admin-border);
|
||||
border-radius: 10px;
|
||||
background: var(--admin-fill-quiet);
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.brand-page__toolbar .ant-segmented {
|
||||
background: var(--admin-surface);
|
||||
}
|
||||
|
||||
.brand-page__toolbar-actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
@media (max-width: 575px) {
|
||||
.brand-page__toolbar {
|
||||
flex-wrap: wrap;
|
||||
@@ -25,54 +35,22 @@
|
||||
}
|
||||
|
||||
.brand-settings-section {
|
||||
padding: 24px 0;
|
||||
border-top: 1px solid #f0f0f0;
|
||||
padding: 20px;
|
||||
border: 1px solid var(--admin-border);
|
||||
border-radius: 10px;
|
||||
background: var(--admin-surface);
|
||||
}
|
||||
|
||||
.brand-settings-section:first-child {
|
||||
padding-top: 8px;
|
||||
border-top: 0;
|
||||
}
|
||||
|
||||
.brand-settings-section__header {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
justify-content: space-between;
|
||||
gap: 16px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.brand-settings-section__header .ant-typography {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.brand-settings-section__header .ant-typography + .ant-typography {
|
||||
display: block;
|
||||
margin-top: 4px;
|
||||
.brand-settings-section + .brand-settings-section {
|
||||
margin-top: 16px;
|
||||
}
|
||||
|
||||
.brand-page__template-note {
|
||||
margin-top: 24px;
|
||||
margin-top: 16px;
|
||||
}
|
||||
|
||||
@media (max-width: 1199px) {
|
||||
.brand-page__content {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.brand-page__template-note {
|
||||
position: static;
|
||||
margin-top: 24px;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 575px) {
|
||||
.brand-settings-section__header {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.brand-settings-section__header .ant-tag {
|
||||
display: inline-block;
|
||||
margin-top: 10px;
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,4 @@
|
||||
import {
|
||||
Alert,
|
||||
Button,
|
||||
Col,
|
||||
Form,
|
||||
Input,
|
||||
Row,
|
||||
Select,
|
||||
Segmented,
|
||||
Space,
|
||||
Tag,
|
||||
Typography,
|
||||
message,
|
||||
} from "antd";
|
||||
import { Alert, Button, Col, Form, Input, Row, Select, Segmented, message } from "antd";
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import { useState } from "react";
|
||||
import { Link, useLocation } from "react-router-dom";
|
||||
@@ -20,6 +7,7 @@ import { createApiClient } from "../../lib/api.js";
|
||||
import { AdminPageHeader } from "../../components/AdminPageHeader.js";
|
||||
import { ImageUrlField } from "../../components/ImageUrlField.js";
|
||||
import { MutationError, QueryState } from "../../components/QueryState.js";
|
||||
import { StatusTag } from "../../components/StatusTag.js";
|
||||
import { PresentationEditor } from "./PresentationEditor.js";
|
||||
import type { PreviewSelection } from "./preview-selection.js";
|
||||
import "./BrandPage.css";
|
||||
@@ -48,6 +36,10 @@ export function BrandPage() {
|
||||
queryFn: () => client.getPublicTemplate(brand.data!.templateKey),
|
||||
enabled: Boolean(brand.data?.templateKey),
|
||||
});
|
||||
const templateCatalog = useQuery({
|
||||
queryKey: ["template-catalog"],
|
||||
queryFn: () => client.listPublicTemplates(),
|
||||
});
|
||||
const save = useMutation({
|
||||
mutationFn: (values: Partial<BrandProfile>) => client.updateAdminBrand(values),
|
||||
onSuccess: () => {
|
||||
@@ -62,13 +54,13 @@ export function BrandPage() {
|
||||
{!brand.data ? null : (
|
||||
<>
|
||||
<AdminPageHeader
|
||||
title="小程序工作台"
|
||||
title="小程序页面"
|
||||
description={
|
||||
template.data?.description
|
||||
? `先让访客理解你是谁、服务谁,以及为什么值得信任。${template.data.description}`
|
||||
: "先让访客理解你是谁、服务谁,以及为什么值得信任。"
|
||||
}
|
||||
extra={<Tag color="blue">{template.data?.name ?? "当前模板"}</Tag>}
|
||||
extra={<StatusTag tone="info" label={template.data?.name ?? "当前模板"} />}
|
||||
/>
|
||||
<div className="brand-page__toolbar">
|
||||
<Segmented
|
||||
@@ -80,12 +72,13 @@ export function BrandPage() {
|
||||
{ value: "brand", label: "品牌资料" },
|
||||
]}
|
||||
/>
|
||||
<Space>
|
||||
<Tag color={dirty ? "orange" : "default"}>
|
||||
{dirty ? "品牌资料有未保存修改" : "草稿工作区"}
|
||||
</Tag>
|
||||
<div className="brand-page__toolbar-actions">
|
||||
<StatusTag
|
||||
tone={dirty ? "warning" : "neutral"}
|
||||
label={dirty ? "品牌资料有未保存修改" : "草稿工作区"}
|
||||
/>
|
||||
<Link to="/admin/publication">检查与发布 →</Link>
|
||||
</Space>
|
||||
</div>
|
||||
</div>
|
||||
<div className="brand-page__content" hidden={panel !== "brand"}>
|
||||
<div className="brand-page__settings">
|
||||
@@ -97,14 +90,14 @@ export function BrandPage() {
|
||||
onFinish={(values) => save.mutate(values)}
|
||||
>
|
||||
<section className="brand-settings-section" aria-labelledby="brand-identity-title">
|
||||
<div className="brand-settings-section__header">
|
||||
<div className="admin-section-head">
|
||||
<div>
|
||||
<Typography.Title id="brand-identity-title" level={4}>
|
||||
<h2 id="brand-identity-title" className="admin-section-title">
|
||||
我是谁
|
||||
</Typography.Title>
|
||||
<Typography.Text type="secondary">公开展示的品牌身份和定位。</Typography.Text>
|
||||
</h2>
|
||||
<p className="admin-section-description">公开展示的品牌身份和定位。</p>
|
||||
</div>
|
||||
<Tag>品牌基础信息</Tag>
|
||||
<StatusTag tone="neutral" label="品牌基础信息" />
|
||||
</div>
|
||||
<Form.Item
|
||||
name="name"
|
||||
@@ -112,7 +105,7 @@ export function BrandPage() {
|
||||
help="可以是个人姓名、工作室名称或品牌名。"
|
||||
rules={[{ required: true, message: "请输入品牌名称" }]}
|
||||
>
|
||||
<Input size="large" placeholder="例如:林然|品牌顾问" />
|
||||
<Input size="large" placeholder="例如:品牌主理人|品牌顾问" />
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
name="tagline"
|
||||
@@ -132,14 +125,14 @@ export function BrandPage() {
|
||||
</Form.Item>
|
||||
</section>
|
||||
<section className="brand-settings-section" aria-labelledby="brand-contact-title">
|
||||
<div className="brand-settings-section__header">
|
||||
<div className="admin-section-head">
|
||||
<div>
|
||||
<Typography.Title id="brand-contact-title" level={4}>
|
||||
<h2 id="brand-contact-title" className="admin-section-title">
|
||||
如何联系与合作
|
||||
</Typography.Title>
|
||||
<Typography.Text type="secondary">
|
||||
</h2>
|
||||
<p className="admin-section-description">
|
||||
让访客知道联系渠道、服务范围和响应预期。
|
||||
</Typography.Text>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<Row gutter={16}>
|
||||
@@ -173,14 +166,14 @@ export function BrandPage() {
|
||||
</Form.Item>
|
||||
</section>
|
||||
<section className="brand-settings-section" aria-labelledby="brand-visual-title">
|
||||
<div className="brand-settings-section__header">
|
||||
<div className="admin-section-head">
|
||||
<div>
|
||||
<Typography.Title id="brand-visual-title" level={4}>
|
||||
<h2 id="brand-visual-title" className="admin-section-title">
|
||||
模板与品牌视觉
|
||||
</Typography.Title>
|
||||
<Typography.Text type="secondary">
|
||||
</h2>
|
||||
<p className="admin-section-description">
|
||||
模板负责业务表达,品牌信息仍由你统一维护。
|
||||
</Typography.Text>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<Form.Item
|
||||
@@ -190,10 +183,10 @@ export function BrandPage() {
|
||||
>
|
||||
<Select
|
||||
disabled
|
||||
options={[
|
||||
{ value: "personal", label: "个人品牌" },
|
||||
{ value: "food", label: "餐饮模板" },
|
||||
]}
|
||||
options={(templateCatalog.data?.industries ?? []).map((item) => ({
|
||||
value: item.key,
|
||||
label: item.name,
|
||||
}))}
|
||||
/>
|
||||
</Form.Item>
|
||||
<Row gutter={16}>
|
||||
@@ -201,24 +194,28 @@ export function BrandPage() {
|
||||
<Form.Item
|
||||
name="avatarUrl"
|
||||
label="头像图片地址"
|
||||
help="粘贴一张可公开访问的图片地址。"
|
||||
help="点击上传或粘贴一张可公开访问的图片地址。"
|
||||
>
|
||||
<ImageUrlField />
|
||||
<ImageUrlField scope="brand" />
|
||||
</Form.Item>
|
||||
</Col>
|
||||
<Col xs={24} md={12}>
|
||||
<Form.Item name="coverUrl" label="品牌封面图片地址" help="建议使用横向图片。">
|
||||
<ImageUrlField />
|
||||
<Form.Item
|
||||
name="coverUrl"
|
||||
label="品牌封面图片地址"
|
||||
help="点击上传,或粘贴一张横向图片地址。"
|
||||
>
|
||||
<ImageUrlField scope="brand" />
|
||||
</Form.Item>
|
||||
</Col>
|
||||
</Row>
|
||||
</section>
|
||||
<Space direction="vertical" style={{ width: "100%", marginTop: 24 }}>
|
||||
<div className="admin-actions admin-offset-top-lg">
|
||||
<MutationError error={save.error} />
|
||||
<Button type="primary" htmlType="submit" loading={save.isPending} size="large">
|
||||
保存品牌表达
|
||||
</Button>
|
||||
</Space>
|
||||
</div>
|
||||
</Form>
|
||||
</div>
|
||||
{template.data ? (
|
||||
|
||||
@@ -6,21 +6,21 @@
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
padding: 8px 12px;
|
||||
border-bottom: 1px solid #e8e8e8;
|
||||
border-bottom: 1px solid var(--admin-border);
|
||||
background: #fff;
|
||||
}
|
||||
|
||||
.component-template-preview__tools button {
|
||||
padding: 4px 12px;
|
||||
border: 1px solid #d9d9d9;
|
||||
border: 1px solid var(--admin-border);
|
||||
border-radius: 6px;
|
||||
background: #fff;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.component-template-preview__tools button[aria-pressed="true"] {
|
||||
border-color: #1677ff;
|
||||
color: #1677ff;
|
||||
border-color: var(--admin-primary);
|
||||
color: var(--admin-primary);
|
||||
}
|
||||
|
||||
.component-template-preview {
|
||||
@@ -31,7 +31,7 @@
|
||||
padding: 24px 16px;
|
||||
overflow-x: hidden;
|
||||
overflow-y: auto;
|
||||
background: #f3f4f6;
|
||||
background: var(--admin-fill);
|
||||
}
|
||||
|
||||
.component-template-preview__canvas {
|
||||
@@ -48,6 +48,11 @@
|
||||
0 10px 30px rgba(0, 0, 0, 0.08);
|
||||
}
|
||||
|
||||
:where(.component-template-preview__canvas) {
|
||||
--brand-button-height: 11.7333333cqw;
|
||||
--brand-button-compact-height: 6.1333333cqw;
|
||||
}
|
||||
|
||||
.component-template-preview__canvas,
|
||||
.component-template-preview__canvas * {
|
||||
box-sizing: border-box;
|
||||
@@ -59,8 +64,12 @@
|
||||
}
|
||||
|
||||
:where(.component-template-preview__canvas) button {
|
||||
display: block;
|
||||
width: -webkit-fill-available;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 100%;
|
||||
min-height: var(--brand-button-height);
|
||||
appearance: none;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
border: 0;
|
||||
@@ -68,8 +77,7 @@
|
||||
background: transparent;
|
||||
color: inherit;
|
||||
font: inherit;
|
||||
font-size: 4.8cqw;
|
||||
line-height: 2.55555556;
|
||||
line-height: 1.5;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
@@ -94,25 +102,25 @@
|
||||
position: absolute;
|
||||
z-index: 5;
|
||||
pointer-events: none;
|
||||
border: 2px solid #91caff;
|
||||
border: 2px solid var(--admin-primary);
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.component-template-preview__outline.is-selected {
|
||||
z-index: 6;
|
||||
border-color: #1677ff;
|
||||
border-color: var(--admin-primary);
|
||||
box-shadow: 0 0 0 3px rgba(22, 119, 255, 0.16);
|
||||
}
|
||||
|
||||
.component-template-preview__composite-select {
|
||||
position: absolute;
|
||||
z-index: 7;
|
||||
width: auto !important;
|
||||
width: max-content !important;
|
||||
padding: 2px 8px !important;
|
||||
border: 1px solid #1677ff !important;
|
||||
border: 1px solid var(--admin-primary) !important;
|
||||
border-radius: 4px !important;
|
||||
background: #fff !important;
|
||||
color: #0958d9 !important;
|
||||
color: var(--admin-primary) !important;
|
||||
font-size: 12px !important;
|
||||
line-height: 20px !important;
|
||||
cursor: pointer;
|
||||
@@ -120,13 +128,14 @@
|
||||
|
||||
.component-template-preview__outline span {
|
||||
position: absolute;
|
||||
bottom: 100%;
|
||||
top: 0;
|
||||
left: 0;
|
||||
max-width: 100%;
|
||||
max-width: calc(100% - 8px);
|
||||
transform: translateY(-100%);
|
||||
padding: 2px 7px;
|
||||
overflow: hidden;
|
||||
border-radius: 4px 4px 0 0;
|
||||
background: #1677ff;
|
||||
background: var(--admin-primary);
|
||||
color: #fff;
|
||||
font-size: 12px;
|
||||
line-height: 18px;
|
||||
@@ -134,6 +143,11 @@
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.component-template-preview__outline.is-selected span {
|
||||
top: 4px;
|
||||
transform: none;
|
||||
}
|
||||
|
||||
.component-template-preview__tools[hidden] {
|
||||
display: none;
|
||||
}
|
||||
@@ -142,3 +156,18 @@
|
||||
.component-template-preview {
|
||||
height: 100%;
|
||||
}
|
||||
.component-template-preview__overlay-host {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
z-index: 5;
|
||||
pointer-events: none;
|
||||
display: none;
|
||||
}
|
||||
|
||||
.component-template-preview__overlay-host.is-visible {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.component-template-preview__overlay-host > * {
|
||||
pointer-events: auto;
|
||||
}
|
||||
@@ -3,8 +3,6 @@ import type { RuntimeWorkspace } from "@personal-brand/api-client";
|
||||
import { Alert } from "antd";
|
||||
import { resolveTemplateRenderer } from "./component-renderers.jsx";
|
||||
import type { PreviewSelection, PreviewTarget } from "./preview-selection.js";
|
||||
import "../../../../../packages/template-acheng-campus-food/taro/style.css";
|
||||
import "../../../../../packages/template-linjing-editorial/taro/style.css";
|
||||
import "./ComponentTemplatePreview.css";
|
||||
|
||||
type PreviewProps = {
|
||||
@@ -17,6 +15,7 @@ type PreviewProps = {
|
||||
};
|
||||
|
||||
type Outline = { top: number; left: number; width: number; height: number; label: string };
|
||||
type CompositeOutline = Outline & { key: string };
|
||||
|
||||
export function ComponentTemplatePreview({
|
||||
workspace,
|
||||
@@ -28,11 +27,10 @@ export function ComponentTemplatePreview({
|
||||
}: PreviewProps) {
|
||||
const Renderer = resolveTemplateRenderer(workspace);
|
||||
const root = useRef<HTMLDivElement>(null);
|
||||
const canvas = useRef<HTMLDivElement>(null);
|
||||
const [mode, setMode] = useState<"edit" | "browse">("edit");
|
||||
const [hovered, setHovered] = useState<HTMLElement | null>(null);
|
||||
const [hoverOutline, setHoverOutline] = useState<Outline | null>(null);
|
||||
const [selectedOutline, setSelectedOutline] = useState<Outline | null>(null);
|
||||
const [compositeOutlines, setCompositeOutlines] = useState<Array<Outline & { key: string }>>([]);
|
||||
const overlay = useRef<HTMLDivElement>(null);
|
||||
const targetFor = useCallback(
|
||||
(element: Element | null): HTMLElement | null => {
|
||||
let candidate = element?.closest<HTMLElement>("[data-editor-target]");
|
||||
@@ -58,17 +56,66 @@ export function ComponentTemplatePreview({
|
||||
) ?? null
|
||||
);
|
||||
}, [selection]);
|
||||
const renderOutlines = useCallback(
|
||||
(
|
||||
host: HTMLDivElement,
|
||||
outlines: {
|
||||
hover: Outline | null;
|
||||
selected: Outline | null;
|
||||
composite: CompositeOutline[];
|
||||
},
|
||||
) => {
|
||||
host.replaceChildren();
|
||||
const position = (node: HTMLElement, outline: Outline) => {
|
||||
node.style.top = `${outline.top}px`;
|
||||
node.style.left = `${outline.left}px`;
|
||||
node.style.width = `${outline.width}px`;
|
||||
node.style.height = `${outline.height}px`;
|
||||
};
|
||||
if (outlines.hover) {
|
||||
const node = document.createElement("div");
|
||||
node.className = "component-template-preview__outline is-hovered";
|
||||
position(node, outlines.hover);
|
||||
host.append(node);
|
||||
}
|
||||
if (outlines.selected) {
|
||||
const node = document.createElement("div");
|
||||
node.className = "component-template-preview__outline is-selected";
|
||||
node.dataset.selectedTarget = selection?.targetKey ?? "";
|
||||
node.dataset.selectedRecordId = selection?.recordId ?? "";
|
||||
const label = document.createElement("span");
|
||||
label.textContent = outlines.selected.label;
|
||||
node.append(label);
|
||||
position(node, outlines.selected);
|
||||
host.append(node);
|
||||
}
|
||||
for (const outline of outlines.composite.filter(
|
||||
(item) => item.key !== selection?.targetKey,
|
||||
)) {
|
||||
const node = document.createElement("button");
|
||||
node.type = "button";
|
||||
node.className = "component-template-preview__composite-select";
|
||||
node.textContent = `选择${outline.label}`;
|
||||
node.setAttribute("aria-label", node.textContent);
|
||||
node.onclick = () => onTargetSelected({ targetKey: outline.key });
|
||||
node.style.top = `${outline.top + 4}px`;
|
||||
node.style.left = `${outline.left + 4}px`;
|
||||
host.append(node);
|
||||
}
|
||||
},
|
||||
[onTargetSelected, selection?.recordId, selection?.targetKey],
|
||||
);
|
||||
const measure = useCallback(
|
||||
(element: HTMLElement | null): Outline | null => {
|
||||
const viewport = root.current;
|
||||
if (!element || !viewport || !viewport.contains(element)) return null;
|
||||
const host = canvas.current;
|
||||
if (!element || !host || !host.contains(element)) return null;
|
||||
const box = element.getBoundingClientRect();
|
||||
const parent = viewport.getBoundingClientRect();
|
||||
const parent = host.getBoundingClientRect();
|
||||
const target = targets.find((item) => item.key === element.dataset.editorTarget);
|
||||
if (!target || !box.width || !box.height) return null;
|
||||
return {
|
||||
top: box.top - parent.top + viewport.scrollTop,
|
||||
left: box.left - parent.left + viewport.scrollLeft,
|
||||
top: box.top - parent.top,
|
||||
left: box.left - parent.left,
|
||||
width: box.width,
|
||||
height: box.height,
|
||||
label: target.label,
|
||||
@@ -78,30 +125,35 @@ export function ComponentTemplatePreview({
|
||||
);
|
||||
useLayoutEffect(() => {
|
||||
const viewport = root.current;
|
||||
if (!viewport) return;
|
||||
const outlineHost = overlay.current;
|
||||
const host = canvas.current;
|
||||
if (!viewport || !outlineHost || !host) return;
|
||||
let frame = 0;
|
||||
const update = () => {
|
||||
cancelAnimationFrame(frame);
|
||||
frame = requestAnimationFrame(() => {
|
||||
setSelectedOutline(measure(selectedElement()));
|
||||
setHoverOutline(measure(hovered));
|
||||
setCompositeOutlines(
|
||||
targets
|
||||
.filter((target) => target.composite)
|
||||
.flatMap((target) => {
|
||||
const element = viewport.querySelector<HTMLElement>(
|
||||
`[data-editor-target="${CSS.escape(target.key)}"]`,
|
||||
);
|
||||
const outline = measure(element);
|
||||
return outline ? [{ ...outline, key: target.key }] : [];
|
||||
}),
|
||||
);
|
||||
const nextHover = measure(hovered);
|
||||
const nextSelected = measure(selectedElement());
|
||||
const nextComposite = targets
|
||||
.filter((target) => target.composite)
|
||||
.flatMap((target) => {
|
||||
const element = host.querySelector<HTMLElement>(
|
||||
`[data-editor-target="${CSS.escape(target.key)}"]`,
|
||||
);
|
||||
const outline = measure(element);
|
||||
return outline ? [{ ...outline, key: target.key }] : [];
|
||||
});
|
||||
renderOutlines(outlineHost, {
|
||||
hover: nextHover,
|
||||
selected: nextSelected,
|
||||
composite: nextComposite,
|
||||
});
|
||||
});
|
||||
};
|
||||
update();
|
||||
const resize = new ResizeObserver(update);
|
||||
resize.observe(viewport);
|
||||
viewport
|
||||
host
|
||||
.querySelectorAll<HTMLElement>("[data-editor-target]")
|
||||
.forEach((node) => resize.observe(node));
|
||||
window.addEventListener("resize", update);
|
||||
@@ -155,6 +207,9 @@ export function ComponentTemplatePreview({
|
||||
onPointerLeave={() => setHovered(null)}
|
||||
onClickCapture={(event) => {
|
||||
if (mode !== "edit" || !targets.length) return;
|
||||
if (event.target instanceof Element && event.target.closest("[data-editor-overlay]")) {
|
||||
return;
|
||||
}
|
||||
const canvas = root.current?.querySelector(".component-template-preview__canvas");
|
||||
if (!event.target || !(event.target instanceof Node) || !canvas?.contains(event.target))
|
||||
return;
|
||||
@@ -176,50 +231,16 @@ export function ComponentTemplatePreview({
|
||||
);
|
||||
}}
|
||||
>
|
||||
<div className="component-template-preview__canvas">
|
||||
<div ref={canvas} className="component-template-preview__canvas">
|
||||
<Renderer workspace={workspace} page={page} {...(offeringId ? { offeringId } : {})} />
|
||||
</div>
|
||||
{mode === "edit"
|
||||
? compositeOutlines.map((outline) => (
|
||||
<button
|
||||
key={outline.key}
|
||||
type="button"
|
||||
className="component-template-preview__composite-select"
|
||||
style={{ top: outline.top + 4, left: outline.left + 4 }}
|
||||
aria-label={`选择${targets.find((target) => target.key === outline.key)?.label ?? outline.label}`}
|
||||
onClick={() => onTargetSelected({ targetKey: outline.key })}
|
||||
>
|
||||
选择{targets.find((target) => target.key === outline.key)?.label ?? outline.label}
|
||||
</button>
|
||||
))
|
||||
: null}
|
||||
{mode === "edit" && hoverOutline ? (
|
||||
<div
|
||||
className="component-template-preview__outline is-hovered"
|
||||
style={{
|
||||
top: hoverOutline.top,
|
||||
left: hoverOutline.left,
|
||||
width: hoverOutline.width,
|
||||
height: hoverOutline.height,
|
||||
}}
|
||||
aria-hidden="true"
|
||||
ref={overlay}
|
||||
className={`component-template-preview__overlay-host ${
|
||||
mode === "edit" ? "is-visible" : ""
|
||||
}`}
|
||||
data-editor-overlay=""
|
||||
/>
|
||||
) : null}
|
||||
{mode === "edit" && selectedOutline ? (
|
||||
<div
|
||||
className="component-template-preview__outline is-selected"
|
||||
style={{
|
||||
top: selectedOutline.top,
|
||||
left: selectedOutline.left,
|
||||
width: selectedOutline.width,
|
||||
height: selectedOutline.height,
|
||||
}}
|
||||
data-selected-target={selection?.targetKey}
|
||||
data-selected-record-id={selection?.recordId}
|
||||
>
|
||||
<span>{selectedOutline.label}</span>
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Alert, Button, Form, Input, Select, Space, Switch, Typography, message } from "antd";
|
||||
import { Alert, Button, Form, Input, Select, Space, Switch, message } from "antd";
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import { useEffect } from "react";
|
||||
import type { RuntimeWorkspace } from "@personal-brand/api-client";
|
||||
@@ -79,9 +79,9 @@ export function InquiryPreviewEditor({
|
||||
onValuesChange={(_, values) => onDraft(update(values))}
|
||||
onFinish={(values) => save.mutate(values)}
|
||||
>
|
||||
<Typography.Paragraph type="secondary">
|
||||
<p className="admin-section-description admin-offset-bottom">
|
||||
{record.name} · 编辑字段:{field.label}
|
||||
</Typography.Paragraph>
|
||||
</p>
|
||||
<Form.Item
|
||||
name="label"
|
||||
label="字段标题"
|
||||
@@ -109,7 +109,7 @@ export function InquiryPreviewEditor({
|
||||
<Form.List name="options">
|
||||
{(fields, { add, remove }) => (
|
||||
<div>
|
||||
{fields.length ? <Typography.Title level={5}>选项</Typography.Title> : null}
|
||||
{fields.length ? <h4 className="admin-subhead admin-offset-bottom-xs">选项</h4> : null}
|
||||
{fields.map(({ key, name }) => (
|
||||
<Space key={key} align="start">
|
||||
<Form.Item name={[name, "label"]} label="选项名称" rules={[{ required: true }]}>
|
||||
@@ -128,7 +128,12 @@ export function InquiryPreviewEditor({
|
||||
)}
|
||||
</Form.List>
|
||||
<MutationError error={save.error} />
|
||||
<Button style={{ marginTop: 24 }} type="primary" htmlType="submit" loading={save.isPending}>
|
||||
<Button
|
||||
className="admin-offset-top-lg"
|
||||
type="primary"
|
||||
htmlType="submit"
|
||||
loading={save.isPending}
|
||||
>
|
||||
保存表单字段
|
||||
</Button>
|
||||
</Form>
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
.presentation-editor {
|
||||
margin-top: 0;
|
||||
padding-top: 8px;
|
||||
}
|
||||
|
||||
.presentation-editor__header {
|
||||
@@ -8,15 +7,7 @@
|
||||
align-items: flex-start;
|
||||
justify-content: space-between;
|
||||
gap: 16px;
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
|
||||
.presentation-editor__header .ant-typography {
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
.presentation-editor__header .ant-typography + .ant-typography {
|
||||
margin-bottom: 0;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.presentation-editor > .ant-space {
|
||||
@@ -24,9 +15,9 @@
|
||||
width: 100%;
|
||||
margin-bottom: 24px !important;
|
||||
padding: 6px;
|
||||
border: 1px solid #e8e8e8;
|
||||
border: 1px solid var(--admin-border);
|
||||
border-radius: 10px;
|
||||
background: #fafafa;
|
||||
background: var(--admin-fill-quiet);
|
||||
}
|
||||
|
||||
@media (max-width: 575px) {
|
||||
@@ -45,16 +36,16 @@
|
||||
grid-template-columns: 200px minmax(300px, 1fr) minmax(280px, 360px);
|
||||
grid-template-areas: "outline preview inspector";
|
||||
margin: 0 !important;
|
||||
border: 1px solid #e5e7eb;
|
||||
border: 1px solid var(--admin-border);
|
||||
border-radius: 12px;
|
||||
overflow: hidden;
|
||||
background: #fff;
|
||||
background: var(--admin-surface);
|
||||
}
|
||||
|
||||
.presentation-editor__preview {
|
||||
grid-area: preview;
|
||||
padding: 20px !important;
|
||||
background: #f8fafc;
|
||||
background: var(--admin-fill);
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
@@ -62,13 +53,13 @@
|
||||
grid-area: inspector;
|
||||
padding: 24px !important;
|
||||
min-width: 0;
|
||||
border-left: 1px solid #e5e7eb;
|
||||
border-left: 1px solid var(--admin-border);
|
||||
}
|
||||
|
||||
.presentation-editor__outline {
|
||||
grid-area: outline;
|
||||
padding: 20px 12px;
|
||||
border-right: 1px solid #e5e7eb;
|
||||
border-right: 1px solid var(--admin-border);
|
||||
}
|
||||
.presentation-editor__regions {
|
||||
display: flex;
|
||||
@@ -90,8 +81,8 @@
|
||||
padding-left: 24px;
|
||||
}
|
||||
.presentation-editor__regions .ant-btn[aria-pressed="true"] {
|
||||
background: #e6f4ff;
|
||||
color: #0958d9;
|
||||
background: var(--admin-primary-bg);
|
||||
color: var(--admin-primary);
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
@@ -114,18 +105,40 @@
|
||||
}
|
||||
|
||||
.presentation-editor__inspector .ant-form-item {
|
||||
margin-bottom: 24px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.presentation-editor__inspector form > .ant-space:last-child {
|
||||
.presentation-editor__form {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-height: 0;
|
||||
}
|
||||
|
||||
.presentation-editor__form-body {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.presentation-editor__inspector .presentation-editor__form-body > section {
|
||||
padding: 16px;
|
||||
border: 1px solid var(--admin-border);
|
||||
border-radius: 12px;
|
||||
background: var(--admin-fill);
|
||||
}
|
||||
|
||||
.presentation-editor__inspector .presentation-editor__form-body > section + section {
|
||||
margin-top: 16px;
|
||||
}
|
||||
|
||||
.presentation-editor__form-actions {
|
||||
position: sticky;
|
||||
bottom: 0;
|
||||
z-index: 2;
|
||||
padding: 16px 0 4px;
|
||||
border-top: 1px solid #e5e7eb;
|
||||
background: #fff;
|
||||
border-top: 1px solid var(--admin-border);
|
||||
background: var(--admin-surface);
|
||||
}
|
||||
.presentation-editor__inspector form > .ant-space:last-child .ant-btn-primary {
|
||||
|
||||
.presentation-editor__form-actions .ant-btn-primary {
|
||||
min-width: 140px;
|
||||
}
|
||||
.presentation-editor__inspector > .ant-tag {
|
||||
@@ -139,11 +152,11 @@
|
||||
}
|
||||
.presentation-editor__outline {
|
||||
border-right: 0;
|
||||
border-bottom: 1px solid #e5e7eb;
|
||||
border-bottom: 1px solid var(--admin-border);
|
||||
}
|
||||
.presentation-editor__inspector {
|
||||
border-left: 0;
|
||||
border-top: 1px solid #e5e7eb;
|
||||
border-top: 1px solid var(--admin-border);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,35 +1,14 @@
|
||||
import {
|
||||
Alert,
|
||||
Button,
|
||||
Divider,
|
||||
Col,
|
||||
Form,
|
||||
Grid,
|
||||
Input,
|
||||
InputNumber,
|
||||
Row,
|
||||
Select,
|
||||
Segmented,
|
||||
Space,
|
||||
Tag,
|
||||
Typography,
|
||||
message,
|
||||
} from "antd";
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import { Alert, Button, Grid, Select, Segmented, Space, Typography } from "antd";
|
||||
import { useQueryClient } from "@tanstack/react-query";
|
||||
import { useCallback, useEffect, useMemo, useState } from "react";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import type {
|
||||
AdminTemplateContent,
|
||||
RuntimeWorkspace,
|
||||
TemplateAdminField,
|
||||
TemplateAdminSection,
|
||||
} from "@personal-brand/api-client";
|
||||
import type { BrandProfile } from "@personal-brand/api-client";
|
||||
import { projectBrandAliases, projectTrustPresentation } from "@personal-brand/api-client";
|
||||
import { createApiClient } from "../../lib/api.js";
|
||||
import { ImageUrlField } from "../../components/ImageUrlField.js";
|
||||
import { TemplateListField } from "../../components/TemplateListField.js";
|
||||
import { MutationError } from "../../components/QueryState.js";
|
||||
import { StatusTag } from "../../components/StatusTag.js";
|
||||
import { RecordContentEditor } from "../../components/RecordContentEditor.js";
|
||||
import { TemplatePreview } from "./TemplatePreview.js";
|
||||
import { InquiryPreviewEditor } from "./InquiryPreviewEditor.js";
|
||||
@@ -40,17 +19,23 @@ import {
|
||||
type PreviewTarget,
|
||||
} from "./preview-selection.js";
|
||||
import {
|
||||
applyBrandPreviewValues,
|
||||
applyStandardBrandValues,
|
||||
applyStandardEntityValues,
|
||||
applyPresentationValues,
|
||||
filterSectionsForPreviewTarget,
|
||||
presentationFieldName,
|
||||
readPresentationValue,
|
||||
type PresentationValues,
|
||||
} from "./presentation-bindings.js";
|
||||
} from "../../lib/presentation/presentation-bindings.js";
|
||||
import "./PresentationEditor.css";
|
||||
import { useEditorDraft } from "./use-editor-draft.js";
|
||||
import {
|
||||
usePresentationRecordQueries,
|
||||
useBrandPresentationSections,
|
||||
useBrandSaveMutation,
|
||||
useBrandPresentationForm,
|
||||
useBrandPreviewDraft,
|
||||
} from "./presentation-editor-state.js";
|
||||
import { useRecordPreview } from "./presentation-editor-record-preview.js";
|
||||
import type { RecordDraft } from "./presentation-editor-record-preview.js";
|
||||
import { pageTitle, previewTargetSource, trustSection } from "./presentation-editor-helpers.js";
|
||||
import { useDraftWorkspace } from "./use-draft-workspace.js";
|
||||
import { PresentationFormPanel } from "./PresentationFormPanel.js";
|
||||
|
||||
interface PresentationEditorProps {
|
||||
templateContent: AdminTemplateContent | null | undefined;
|
||||
@@ -62,112 +47,6 @@ interface PresentationEditorProps {
|
||||
initialSelection?: PreviewSelection;
|
||||
}
|
||||
|
||||
function trustSection(
|
||||
declaration: NonNullable<AdminTemplateContent["trustContentTypes"]>[number],
|
||||
page: string,
|
||||
): TemplateAdminSection {
|
||||
const key = `trust:${declaration.type}`;
|
||||
return {
|
||||
key,
|
||||
title: declaration.label,
|
||||
description: declaration.help ?? "编辑当前展示内容。",
|
||||
page,
|
||||
target: "trust",
|
||||
previewTargets: [
|
||||
{ key, label: declaration.label },
|
||||
...(declaration.previewTargets ?? []).filter(
|
||||
(target) => !target.page || target.page === page,
|
||||
),
|
||||
],
|
||||
fields: [
|
||||
{
|
||||
key: "title",
|
||||
binding: "trust.title",
|
||||
label: declaration.adminFields.title,
|
||||
input: "text" as const,
|
||||
required: true,
|
||||
},
|
||||
...(["summary", "content"] as const)
|
||||
.filter((field) => !declaration.hideStandardFields?.includes(field))
|
||||
.map((field) => ({
|
||||
key: field,
|
||||
binding: `trust.${field}`,
|
||||
label: declaration.adminFields[field],
|
||||
input: "textarea" as const,
|
||||
previewTarget: `trust:${declaration.type}`,
|
||||
...(field === "summary" && declaration.adminFields.summaryHelp
|
||||
? { help: declaration.adminFields.summaryHelp }
|
||||
: {}),
|
||||
...(field === "content" && declaration.required ? { required: true } : {}),
|
||||
})),
|
||||
...(declaration.configFields ?? [])
|
||||
.filter((field) => {
|
||||
const target = declaration.previewTargets?.find(
|
||||
(target) => target.key === field.previewTarget,
|
||||
);
|
||||
return !target?.page || target.page === page;
|
||||
})
|
||||
.map((field) => ({
|
||||
...field,
|
||||
previewTarget: field.previewTarget ?? `trust:${declaration.type}`,
|
||||
})),
|
||||
].map((field) => ({
|
||||
...field,
|
||||
previewTarget: (field as TemplateAdminField).previewTarget ?? `trust:${declaration.type}`,
|
||||
})),
|
||||
};
|
||||
}
|
||||
|
||||
function renderField(field: TemplateAdminField) {
|
||||
if (field.input === "textarea")
|
||||
return (
|
||||
<Input.TextArea
|
||||
rows={3}
|
||||
maxLength={field.maxLength}
|
||||
showCount={!!field.maxLength}
|
||||
placeholder={field.placeholder}
|
||||
/>
|
||||
);
|
||||
if (field.input === "image")
|
||||
return <ImageUrlField {...(field.placeholder ? { placeholder: field.placeholder } : {})} />;
|
||||
if (field.input === "number")
|
||||
return <InputNumber style={{ width: "100%" }} placeholder={field.placeholder} />;
|
||||
if (field.input === "boolean")
|
||||
return (
|
||||
<Select
|
||||
options={[
|
||||
{ value: true, label: "是" },
|
||||
{ value: false, label: "否" },
|
||||
]}
|
||||
/>
|
||||
);
|
||||
if (field.input === "select" || field.input === "multi-select")
|
||||
return (
|
||||
<Select
|
||||
{...(field.input === "multi-select" ? { mode: "multiple" as const } : {})}
|
||||
options={field.options ?? []}
|
||||
/>
|
||||
);
|
||||
return (
|
||||
<Input
|
||||
type={field.input === "phone" ? "tel" : "text"}
|
||||
maxLength={field.maxLength}
|
||||
placeholder={field.placeholder}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function previewTargetSource(
|
||||
section: TemplateAdminSection,
|
||||
targetKey: string,
|
||||
): "brand" | "offering" | "trust" | "inquiry" {
|
||||
const fields = section.fields.filter((field) => field.previewTarget === targetKey);
|
||||
if (fields.some((field) => field.binding.startsWith("offering."))) return "offering";
|
||||
if (fields.some((field) => field.binding.startsWith("trust."))) return "trust";
|
||||
if (fields.some((field) => field.binding.startsWith("brand."))) return "brand";
|
||||
return section.target;
|
||||
}
|
||||
|
||||
export function PresentationEditor({
|
||||
templateContent,
|
||||
previewWorkspace,
|
||||
@@ -177,57 +56,20 @@ export function PresentationEditor({
|
||||
error,
|
||||
initialSelection,
|
||||
}: PresentationEditorProps) {
|
||||
const [form] = Form.useForm<PresentationValues>();
|
||||
const queryClient = useQueryClient();
|
||||
const navigate = useNavigate();
|
||||
const breakpoints = Grid.useBreakpoint();
|
||||
const [activePage, setActivePage] = useState<string>();
|
||||
const [selection, setSelection] = useState<PreviewSelection | undefined>(initialSelection);
|
||||
const [hasInitializedSelection, setHasInitializedSelection] = useState(Boolean(initialSelection));
|
||||
const [detailOfferingId, setDetailOfferingId] = useState<string>();
|
||||
const [recordDraft, setRecordDraft] = useState<{
|
||||
source: "offering" | "trust";
|
||||
id: string;
|
||||
values: PresentationValues;
|
||||
}>();
|
||||
const [previewConfig, setPreviewConfig] = useState(config ?? {});
|
||||
const [previewBrandValues, setPreviewBrandValues] = useState<Record<string, unknown>>({});
|
||||
const [recordDraft, setRecordDraft] = useState<RecordDraft>();
|
||||
const [inquiryDraft, setInquiryDraft] =
|
||||
useState<RuntimeWorkspace["inquiryForms"][number]["fields"]>();
|
||||
const [brandDirty, setBrandDirty] = useState(false);
|
||||
const guardDraft = useEditorDraft(brandDirty || !!recordDraft || !!inquiryDraft);
|
||||
const inquiryRuntime = previewWorkspace?.inquiryForms.find((item) => item.target === "brand");
|
||||
const sections = useMemo(() => {
|
||||
const declaredTemplateFields = (templateContent?.templateFields ?? []).map((field) => ({
|
||||
...field,
|
||||
binding: field.binding ?? `brand.config.templateData.${field.key}`,
|
||||
}));
|
||||
return [
|
||||
...[...new Set(declaredTemplateFields.map((field) => field.page ?? "home"))].map((page) => ({
|
||||
key: `template-data:${page}`,
|
||||
title: "模板专属内容",
|
||||
description: "这些字段由当前小程序模板定义,保存后发布才会对外展示。",
|
||||
page,
|
||||
target: "brand" as const,
|
||||
fields: declaredTemplateFields.filter((field) => (field.page ?? "home") === page),
|
||||
})),
|
||||
...(templateContent?.admin.sections ?? []),
|
||||
].map((section) => ({
|
||||
...section,
|
||||
fields: section.fields.filter(
|
||||
(field) =>
|
||||
field.binding.startsWith("brand.config.") ||
|
||||
[
|
||||
"brand.name",
|
||||
"brand.tagline",
|
||||
"brand.avatarUrl",
|
||||
"brand.description",
|
||||
"brand.contactPhone",
|
||||
"brand.contactWechat",
|
||||
"brand.address",
|
||||
].includes(field.binding),
|
||||
),
|
||||
}));
|
||||
}, [templateContent]);
|
||||
const sections = useBrandPresentationSections(templateContent);
|
||||
const pageOptions = useMemo(() => {
|
||||
const pages = new Map<string, string>();
|
||||
for (const item of templateContent?.navigation ?? []) pages.set(item.page, item.label);
|
||||
@@ -288,22 +130,10 @@ export function PresentationEditor({
|
||||
selectedTarget?.source === "offering" || selectedTarget?.source === "trust"
|
||||
? selectedTarget.source
|
||||
: undefined;
|
||||
const offeringsQuery = useQuery({
|
||||
queryKey: ["admin-offerings"],
|
||||
queryFn: () => createApiClient().listAdminOfferings(),
|
||||
enabled: selectedRecordSource === "offering",
|
||||
});
|
||||
const trustQuery = useQuery({
|
||||
queryKey: ["trust-content"],
|
||||
queryFn: () => createApiClient().listAdminTrustContent(),
|
||||
enabled: selectedRecordSource === "trust",
|
||||
});
|
||||
const selectedRecord =
|
||||
selectedRecordSource === "offering"
|
||||
? offeringsQuery.data?.find((item) => item.id === selection?.recordId)
|
||||
: selectedRecordSource === "trust"
|
||||
? trustQuery.data?.find((item) => item.id === selection?.recordId)
|
||||
: undefined;
|
||||
const { offeringsQuery, trustQuery, selectedRecord } = usePresentationRecordQueries(
|
||||
selectedRecordSource,
|
||||
selection?.recordId,
|
||||
);
|
||||
const editableSections = filterSectionsForPreviewTarget(
|
||||
visibleSections.filter((section) =>
|
||||
section.fields.some((field) => field.binding.startsWith("brand.")),
|
||||
@@ -381,64 +211,51 @@ export function PresentationEditor({
|
||||
return item.target === selectedSection.target;
|
||||
})
|
||||
: pageLinks;
|
||||
const initialValues = useMemo(() => {
|
||||
const values: PresentationValues = {};
|
||||
for (const section of sections) {
|
||||
for (const field of section.fields) {
|
||||
values[presentationFieldName(section.key, field.key)] = readPresentationValue(
|
||||
config,
|
||||
field.binding,
|
||||
field,
|
||||
brand as unknown as Record<string, unknown>,
|
||||
);
|
||||
}
|
||||
const formState = useBrandPresentationForm({ brand, config, sections });
|
||||
const { form, initialValues } = formState;
|
||||
const save = useBrandSaveMutation({ ...formState, brand, config, sections, queryClient });
|
||||
|
||||
useEffect(() => {
|
||||
const initialPage =
|
||||
typeof initialSelection === "object" && "page" in initialSelection
|
||||
? String(initialSelection.page)
|
||||
: undefined;
|
||||
if (initialPage) {
|
||||
setActivePage(
|
||||
pageOptions.some((item) => item.value === initialPage)
|
||||
? initialPage
|
||||
: pageOptions[0]?.value,
|
||||
);
|
||||
return;
|
||||
}
|
||||
return values;
|
||||
}, [config, sections]);
|
||||
|
||||
const save = useMutation({
|
||||
mutationFn: (values: PresentationValues) => {
|
||||
const nextConfig = applyPresentationValues(config, sections, values);
|
||||
// 页面内容编辑不提交模板选择,避免触发切换模板的权限校验。
|
||||
const contentConfig = { ...nextConfig };
|
||||
delete contentConfig.visualTemplateKey;
|
||||
const standard = applyStandardBrandValues(
|
||||
brand as unknown as Record<string, unknown>,
|
||||
sections,
|
||||
values,
|
||||
);
|
||||
const changed = Object.fromEntries(
|
||||
Object.entries(standard).filter(
|
||||
([key, value]) =>
|
||||
key !== "config" && value !== (brand as unknown as Record<string, unknown>)[key],
|
||||
),
|
||||
);
|
||||
return createApiClient().updateAdminBrand({
|
||||
...changed,
|
||||
config: contentConfig,
|
||||
});
|
||||
},
|
||||
onSuccess: () => {
|
||||
setBrandDirty(false);
|
||||
message.success("页面内容已保存为草稿,发布后小程序才会更新");
|
||||
window.dispatchEvent(new Event("template-preview-refresh"));
|
||||
void queryClient.invalidateQueries({ queryKey: ["admin-brand"] });
|
||||
void queryClient.invalidateQueries({ queryKey: ["admin-workspace"] });
|
||||
void queryClient.invalidateQueries({ queryKey: ["admin-preview-workspace"] });
|
||||
void queryClient.invalidateQueries({ queryKey: ["public-runtime-workspace"] });
|
||||
void queryClient.invalidateQueries({ queryKey: ["publication-readiness"] });
|
||||
},
|
||||
});
|
||||
|
||||
if (!activePage && pageOptions.length) setActivePage(pageOptions[0]?.value);
|
||||
}, [activePage, initialSelection, pageOptions]);
|
||||
useEffect(() => {
|
||||
form.setFieldsValue(initialValues);
|
||||
}, [form, initialValues]);
|
||||
|
||||
if (hasInitializedSelection) return;
|
||||
if (!pageOptions.length) return;
|
||||
if (!initialSelection) return;
|
||||
const requestedPage =
|
||||
typeof initialSelection === "object" && "page" in initialSelection
|
||||
? String(initialSelection.page)
|
||||
: undefined;
|
||||
const resolvedPage =
|
||||
requestedPage && pageOptions.some((item) => item.value === requestedPage)
|
||||
? requestedPage
|
||||
: (pageOptions[0]?.value ?? "home");
|
||||
setSelection(
|
||||
resolvePreviewSelection(
|
||||
initialSelection.targetKey,
|
||||
initialSelection.recordId,
|
||||
visibleTargets,
|
||||
resolvedPage,
|
||||
),
|
||||
);
|
||||
setActivePage(resolvedPage);
|
||||
setHasInitializedSelection(true);
|
||||
}, [hasInitializedSelection, initialSelection, pageOptions, selectedPage, visibleTargets]);
|
||||
useEffect(() => {
|
||||
if (!pageOptions.some((item) => item.value === activePage))
|
||||
setActivePage(pageOptions[0]?.value);
|
||||
}, [activePage, pageOptions]);
|
||||
useEffect(() => setSelection(undefined), [selectedPage, templateContent?.displayName]);
|
||||
if (!initialSelection) setSelection(undefined);
|
||||
}, [initialSelection, selectedPage, templateContent?.displayName]);
|
||||
useEffect(() => {
|
||||
if (!selection?.recordId) return;
|
||||
const records =
|
||||
@@ -456,144 +273,26 @@ export function PresentationEditor({
|
||||
() => setRecordDraft(undefined),
|
||||
[selection?.targetKey, selection?.recordId, selectedPage],
|
||||
);
|
||||
useEffect(() => {
|
||||
setPreviewConfig(config ?? {});
|
||||
setPreviewBrandValues({});
|
||||
}, [config]);
|
||||
const previewBrand = useMemo(
|
||||
() => ({ ...brand, ...previewBrandValues, config: previewConfig }),
|
||||
[brand, previewBrandValues, previewConfig],
|
||||
);
|
||||
const handleValuesChange = useCallback(
|
||||
(changed: PresentationValues, allValues: PresentationValues) => {
|
||||
setBrandDirty(true);
|
||||
const synchronized: PresentationValues = {
|
||||
...(form.getFieldsValue(true) as PresentationValues),
|
||||
...allValues,
|
||||
};
|
||||
for (const section of sections) {
|
||||
for (const field of section.fields) {
|
||||
const name = presentationFieldName(section.key, field.key);
|
||||
if (!Object.prototype.hasOwnProperty.call(changed, name)) continue;
|
||||
for (const peer of sections) {
|
||||
for (const item of peer.fields) {
|
||||
if (item.binding === field.binding)
|
||||
synchronized[presentationFieldName(peer.key, item.key)] = changed[name];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
form.setFieldsValue(synchronized);
|
||||
const next = applyBrandPreviewValues(
|
||||
brand as unknown as Record<string, unknown>,
|
||||
config,
|
||||
sections,
|
||||
synchronized,
|
||||
);
|
||||
setPreviewConfig((next.config as Record<string, unknown>) ?? {});
|
||||
setPreviewBrandValues(next);
|
||||
},
|
||||
[brand, config, sections, form],
|
||||
);
|
||||
const draftWorkspace = useMemo(() => {
|
||||
if (!previewWorkspace) return undefined;
|
||||
const next: RuntimeWorkspace = {
|
||||
...previewWorkspace,
|
||||
templateData: {
|
||||
...previewWorkspace.templateData,
|
||||
...(previewConfig.templateData &&
|
||||
typeof previewConfig.templateData === "object" &&
|
||||
!Array.isArray(previewConfig.templateData)
|
||||
? (previewConfig.templateData as Record<string, unknown>)
|
||||
: {}),
|
||||
},
|
||||
inquiryForms: previewWorkspace.inquiryForms.map((item) =>
|
||||
item.key === inquiryRuntime?.key && inquiryDraft ? { ...item, fields: inquiryDraft } : item,
|
||||
),
|
||||
brand: projectBrandAliases(
|
||||
{
|
||||
...previewWorkspace.brand,
|
||||
...(previewBrand as unknown as Record<string, unknown>),
|
||||
config: previewConfig,
|
||||
},
|
||||
previewConfig,
|
||||
),
|
||||
};
|
||||
if (!recordDraft || !selectedRecord || !recordSection || recordDraft.id !== selectedRecord.id)
|
||||
return next;
|
||||
const values = recordDraft.values;
|
||||
const config = applyPresentationValues(selectedRecord.config, [recordSection], values);
|
||||
const standard = applyStandardEntityValues(
|
||||
selectedRecord as unknown as Record<string, unknown>,
|
||||
recordDraft.source,
|
||||
[recordSection],
|
||||
values,
|
||||
);
|
||||
if (recordDraft.source === "trust") {
|
||||
next.trustItems = next.trustItems.map((item) =>
|
||||
item.id === recordDraft.id
|
||||
? {
|
||||
...item,
|
||||
title: typeof standard.title === "string" ? standard.title : item.title,
|
||||
summary: typeof standard.summary === "string" ? standard.summary : item.summary,
|
||||
content: typeof standard.content === "string" ? standard.content : item.content,
|
||||
config,
|
||||
}
|
||||
: item,
|
||||
);
|
||||
next.trustPresentation = projectTrustPresentation(
|
||||
next.trustItems,
|
||||
templateContent?.trustContentTypes ?? [],
|
||||
);
|
||||
} else {
|
||||
next.offerings = next.offerings.map((item) =>
|
||||
item.id === recordDraft.id
|
||||
? {
|
||||
...item,
|
||||
name: typeof standard.name === "string" ? standard.name : item.name,
|
||||
summary:
|
||||
typeof standard.summary === "string"
|
||||
? standard.summary
|
||||
: typeof standard.description === "string"
|
||||
? standard.description
|
||||
: item.summary,
|
||||
priceText: typeof standard.priceText === "string" ? standard.priceText : null,
|
||||
coverUrl: typeof standard.coverUrl === "string" ? standard.coverUrl : null,
|
||||
presentation: {
|
||||
...item.presentation,
|
||||
...config,
|
||||
...(config.presentation && typeof config.presentation === "object"
|
||||
? (config.presentation as Record<string, unknown>)
|
||||
: {}),
|
||||
heroImage:
|
||||
typeof config.detailHero === "string"
|
||||
? config.detailHero
|
||||
: typeof standard.coverUrl === "string"
|
||||
? standard.coverUrl
|
||||
: null,
|
||||
details: {
|
||||
...item.presentation.details,
|
||||
...(config.details && typeof config.details === "object"
|
||||
? (config.details as Record<string, unknown>)
|
||||
: {}),
|
||||
},
|
||||
},
|
||||
}
|
||||
: item,
|
||||
);
|
||||
}
|
||||
return next;
|
||||
}, [
|
||||
const { previewBrand, handleValuesChange, resetPreview } = useBrandPreviewDraft({
|
||||
brand,
|
||||
config,
|
||||
sections,
|
||||
form,
|
||||
onDirty: () => setBrandDirty(true),
|
||||
});
|
||||
const recordPreview = useRecordPreview({ recordDraft, selectedRecord, recordSection });
|
||||
useEffect(() => resetPreview(), [config, initialValues, resetPreview]);
|
||||
const draftWorkspace = useDraftWorkspace({
|
||||
previewWorkspace,
|
||||
previewBrand,
|
||||
previewConfig,
|
||||
inquiryRuntime,
|
||||
inquiryDraft,
|
||||
recordDraft,
|
||||
selectedRecord,
|
||||
recordSection,
|
||||
recordPreview,
|
||||
templateContent,
|
||||
inquiryDraft,
|
||||
inquiryRuntime,
|
||||
]);
|
||||
});
|
||||
const selectedDetailOfferingId =
|
||||
detailOfferingId && draftWorkspace?.offerings.some((item) => item.id === detailOfferingId)
|
||||
? detailOfferingId
|
||||
@@ -603,14 +302,14 @@ export function PresentationEditor({
|
||||
<section className="presentation-editor" aria-labelledby="presentation-editor-title">
|
||||
<div className="presentation-editor__header">
|
||||
<div>
|
||||
<Typography.Title id="presentation-editor-title" level={3}>
|
||||
<h2 id="presentation-editor-title" className="admin-section-title">
|
||||
小程序页面配置
|
||||
</Typography.Title>
|
||||
<Typography.Paragraph type="secondary">
|
||||
</h2>
|
||||
<p className="admin-section-description">
|
||||
按页面查找内容。这里修改的是草稿,发布后访客才会看到更新。
|
||||
</Typography.Paragraph>
|
||||
</p>
|
||||
</div>
|
||||
{templateContent ? <Tag color="blue">{templateContent.displayName}</Tag> : null}
|
||||
{templateContent ? <StatusTag tone="info" label={templateContent.displayName} /> : null}
|
||||
</div>
|
||||
{loading ? <Alert type="info" showIcon message="正在读取当前模板的编辑项目" /> : null}
|
||||
{error ? (
|
||||
@@ -631,14 +330,13 @@ export function PresentationEditor({
|
||||
guardDraft(() => {
|
||||
setBrandDirty(false);
|
||||
form.setFieldsValue(initialValues);
|
||||
setPreviewConfig(config ?? {});
|
||||
setPreviewBrandValues({});
|
||||
resetPreview();
|
||||
setRecordDraft(undefined);
|
||||
setInquiryDraft(undefined);
|
||||
setActivePage(value);
|
||||
})
|
||||
}
|
||||
style={{ minWidth: 180 }}
|
||||
className="admin-field-w-2xl"
|
||||
/>
|
||||
) : (
|
||||
<Segmented
|
||||
@@ -648,8 +346,7 @@ export function PresentationEditor({
|
||||
guardDraft(() => {
|
||||
setBrandDirty(false);
|
||||
form.setFieldsValue(initialValues);
|
||||
setPreviewConfig(config ?? {});
|
||||
setPreviewBrandValues({});
|
||||
resetPreview();
|
||||
setRecordDraft(undefined);
|
||||
setInquiryDraft(undefined);
|
||||
setActivePage(String(value));
|
||||
@@ -660,11 +357,11 @@ export function PresentationEditor({
|
||||
</Space>
|
||||
<div className="presentation-editor__workspace">
|
||||
<div className="presentation-editor__preview">
|
||||
<Typography.Title level={5}>页面预览</Typography.Title>
|
||||
<h3 className="admin-section-title admin-flush">页面预览</h3>
|
||||
{selectedPage === "detail" && draftWorkspace?.offerings.length ? (
|
||||
<Select
|
||||
aria-label="选择详情页业务内容"
|
||||
style={{ width: "100%", marginBottom: 12 }}
|
||||
className="admin-block admin-offset-bottom-sm"
|
||||
value={selectedDetailOfferingId}
|
||||
options={draftWorkspace.offerings.map((item) => ({
|
||||
value: item.id,
|
||||
@@ -690,10 +387,10 @@ export function PresentationEditor({
|
||||
/>
|
||||
</div>
|
||||
<aside className="presentation-editor__outline" aria-label="页面区域">
|
||||
<Typography.Title level={5}>页面区域</Typography.Title>
|
||||
<Typography.Paragraph type="secondary">选择区域,编辑对应内容</Typography.Paragraph>
|
||||
<h3 className="admin-section-title admin-flush">页面区域</h3>
|
||||
<p className="admin-section-description">选择区域,编辑对应内容</p>
|
||||
{visibleTargets.length ? (
|
||||
<Space className="presentation-editor__regions" wrap style={{ marginTop: 16 }}>
|
||||
<Space className="presentation-editor__regions admin-offset-top" wrap>
|
||||
{visibleTargets.map((target) => (
|
||||
<Button
|
||||
key={target.key}
|
||||
@@ -732,18 +429,27 @@ export function PresentationEditor({
|
||||
) : null}
|
||||
</aside>
|
||||
<div className="presentation-editor__inspector">
|
||||
<Typography.Title level={5}>
|
||||
<h3 className="admin-section-title admin-flush">
|
||||
{selectedTarget?.label ?? pageTitle(selectedPage ?? "home")}
|
||||
</Typography.Title>
|
||||
<Tag color={brandDirty || recordDraft || inquiryDraft ? "orange" : "default"}>
|
||||
{save.isPending
|
||||
? "正在保存"
|
||||
: save.isError
|
||||
? "保存失败,请重试"
|
||||
: brandDirty || recordDraft || inquiryDraft
|
||||
? "有未保存修改"
|
||||
: "草稿已同步"}
|
||||
</Tag>
|
||||
</h3>
|
||||
<StatusTag
|
||||
tone={
|
||||
save.isError
|
||||
? "error"
|
||||
: save.isPending || brandDirty || recordDraft || inquiryDraft
|
||||
? "warning"
|
||||
: "neutral"
|
||||
}
|
||||
label={
|
||||
save.isPending
|
||||
? "正在保存"
|
||||
: save.isError
|
||||
? "保存失败,请重试"
|
||||
: brandDirty || recordDraft || inquiryDraft
|
||||
? "有未保存修改"
|
||||
: "草稿已同步"
|
||||
}
|
||||
/>
|
||||
{selectedPage === "detail" && !selectedTarget ? (
|
||||
<Alert
|
||||
type="info"
|
||||
@@ -897,118 +603,25 @@ export function PresentationEditor({
|
||||
/>
|
||||
) : !selectedTarget ? (
|
||||
<div className="presentation-editor__empty">
|
||||
<Typography.Title level={5}>选择要编辑的区域</Typography.Title>
|
||||
<Typography.Paragraph type="secondary">
|
||||
<h3 className="admin-subhead">选择要编辑的区域</h3>
|
||||
<p className="admin-section-description">
|
||||
点击预览中的内容,或使用区域列表,查看并修改对应字段。
|
||||
</Typography.Paragraph>
|
||||
</p>
|
||||
</div>
|
||||
) : (
|
||||
<Form
|
||||
<PresentationFormPanel
|
||||
form={form}
|
||||
layout="vertical"
|
||||
initialValues={initialValues}
|
||||
editableSections={editableSections}
|
||||
relevantPageLinks={relevantPageLinks}
|
||||
selectedTarget={selectedTarget}
|
||||
save={{
|
||||
error: save.error,
|
||||
isPending: save.isPending,
|
||||
mutate: (values) => save.mutate(values),
|
||||
}}
|
||||
onValuesChange={handleValuesChange}
|
||||
onFinish={() => save.mutate(form.getFieldsValue(true) as PresentationValues)}
|
||||
style={{ minHeight: 0, display: "flex", flexDirection: "column" }}
|
||||
>
|
||||
<div style={{ flex: 1 }}>
|
||||
{editableSections.map((section, index) => (
|
||||
<section key={section.key} aria-labelledby={`section-${section.key}`}>
|
||||
{selectedTarget && index > 0 ? <Divider /> : null}
|
||||
<Typography.Title id={`section-${section.key}`} level={5}>
|
||||
{selectedTarget
|
||||
? fieldTargetTitle(section, selectedTarget.label)
|
||||
: section.title}
|
||||
</Typography.Title>
|
||||
{!selectedTarget ? (
|
||||
<Typography.Paragraph type="secondary">
|
||||
{section.description}
|
||||
</Typography.Paragraph>
|
||||
) : null}
|
||||
<Row gutter={16}>
|
||||
{section.fields.map((field) => (
|
||||
<Col key={field.key} xs={24} md={24}>
|
||||
{field.input === "list" ? (
|
||||
<TemplateListField
|
||||
field={field}
|
||||
name={presentationFieldName(section.key, field.key)}
|
||||
/>
|
||||
) : (
|
||||
<Form.Item
|
||||
name={presentationFieldName(section.key, field.key)}
|
||||
label={field.label}
|
||||
{...(field.help ? { help: field.help } : {})}
|
||||
{...(field.required
|
||||
? {
|
||||
rules: [
|
||||
{ required: true, message: `请填写${field.label}` },
|
||||
],
|
||||
}
|
||||
: {})}
|
||||
>
|
||||
{renderField(field)}
|
||||
</Form.Item>
|
||||
)}
|
||||
</Col>
|
||||
))}
|
||||
</Row>
|
||||
</section>
|
||||
))}
|
||||
{relevantPageLinks.length ? (
|
||||
<Alert
|
||||
type="info"
|
||||
showIcon
|
||||
style={{ marginBottom: 24 }}
|
||||
message="这个页面还有关联内容"
|
||||
description={
|
||||
<Space wrap>
|
||||
{relevantPageLinks.map((item) => (
|
||||
<Button
|
||||
key={item.target}
|
||||
type="link"
|
||||
onClick={() => {
|
||||
if (item.target.startsWith("trust:")) {
|
||||
void navigate(
|
||||
`/admin/trust?type=${encodeURIComponent(item.target.slice(6))}`,
|
||||
);
|
||||
return;
|
||||
}
|
||||
void navigate(
|
||||
item.target === "offering"
|
||||
? "/admin/services"
|
||||
: "/admin/workspace",
|
||||
);
|
||||
}}
|
||||
style={{ padding: 0 }}
|
||||
>
|
||||
{item.label}
|
||||
</Button>
|
||||
))}
|
||||
</Space>
|
||||
}
|
||||
/>
|
||||
) : null}
|
||||
{!editableSections.some((section) => section.fields.length) &&
|
||||
!relevantPageLinks.length ? (
|
||||
<Typography.Paragraph type="secondary">
|
||||
这个页面没有单独的品牌文案配置。
|
||||
</Typography.Paragraph>
|
||||
) : null}
|
||||
{selectedTarget &&
|
||||
!editableSections.some((section) => section.fields.length) &&
|
||||
relevantPageLinks.length ? (
|
||||
<Typography.Paragraph type="secondary">
|
||||
此区域内容由对应的业务管理页面维护。
|
||||
</Typography.Paragraph>
|
||||
) : null}
|
||||
</div>
|
||||
<Space direction="vertical" style={{ width: "100%", marginTop: 24 }}>
|
||||
<MutationError error={save.error} />
|
||||
<Button type="primary" htmlType="submit" loading={save.isPending}>
|
||||
保存页面内容
|
||||
</Button>
|
||||
</Space>
|
||||
</Form>
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
@@ -1017,24 +630,3 @@ export function PresentationEditor({
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
function pageTitle(page: string): string {
|
||||
return (
|
||||
(
|
||||
{
|
||||
home: "首页",
|
||||
offerings: "业务展示",
|
||||
service: "服务说明",
|
||||
detail: "详情页",
|
||||
inquiry: "咨询页",
|
||||
success: "提交成功页",
|
||||
records: "记录页",
|
||||
profile: "主理人页",
|
||||
} as Record<string, string>
|
||||
)[page] ?? page
|
||||
);
|
||||
}
|
||||
|
||||
function fieldTargetTitle(section: { title: string }, targetLabel: string): string {
|
||||
return section.title === targetLabel ? targetLabel : `${targetLabel} · ${section.title}`;
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
import { Alert, Button, Col, Divider, Form, Row, Space } from "antd";
|
||||
import type { FormInstance } from "antd";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import type { TemplateAdminSection } from "@personal-brand/api-client";
|
||||
import { TemplateFieldRenderer } from "../../components/TemplateFieldRenderer.js";
|
||||
import { TemplateListField } from "../../components/TemplateListField.js";
|
||||
import { MutationError } from "../../components/QueryState.js";
|
||||
import {
|
||||
presentationFieldName,
|
||||
type PresentationValues,
|
||||
} from "../../lib/presentation/presentation-bindings.js";
|
||||
import { fieldTargetTitle } from "./presentation-editor-helpers.js";
|
||||
import type { PreviewTarget } from "./preview-selection.js";
|
||||
|
||||
interface PresentationFormPanelProps {
|
||||
form: FormInstance<PresentationValues>;
|
||||
initialValues: PresentationValues;
|
||||
editableSections: TemplateAdminSection[];
|
||||
relevantPageLinks: { target: string; label: string | undefined }[];
|
||||
selectedTarget: PreviewTarget | undefined;
|
||||
save: {
|
||||
error: unknown;
|
||||
isPending: boolean;
|
||||
mutate: (values: PresentationValues) => void;
|
||||
};
|
||||
onValuesChange: (changed: PresentationValues, allValues: PresentationValues) => void;
|
||||
}
|
||||
|
||||
export function PresentationFormPanel({
|
||||
form,
|
||||
initialValues,
|
||||
editableSections,
|
||||
relevantPageLinks,
|
||||
selectedTarget,
|
||||
save,
|
||||
onValuesChange,
|
||||
}: PresentationFormPanelProps) {
|
||||
const navigate = useNavigate();
|
||||
const hasEditableFields = editableSections.some((section) => section.fields.length);
|
||||
|
||||
return (
|
||||
<Form
|
||||
form={form}
|
||||
layout="vertical"
|
||||
initialValues={initialValues}
|
||||
onValuesChange={onValuesChange}
|
||||
onFinish={() => save.mutate(form.getFieldsValue(true) as PresentationValues)}
|
||||
className="presentation-editor__form"
|
||||
>
|
||||
<div className="presentation-editor__form-body">
|
||||
{editableSections.map((section, index) => (
|
||||
<section key={section.key} aria-labelledby={`section-${section.key}`}>
|
||||
{selectedTarget && index > 0 ? <Divider /> : null}
|
||||
<h4 id={`section-${section.key}`} className="admin-subhead">
|
||||
{selectedTarget ? fieldTargetTitle(section, selectedTarget.label) : section.title}
|
||||
</h4>
|
||||
{!selectedTarget ? (
|
||||
<p className="admin-section-description admin-offset-bottom">{section.description}</p>
|
||||
) : null}
|
||||
<Row gutter={16}>
|
||||
{section.fields.map((field) => (
|
||||
<Col key={field.key} xs={24} md={24}>
|
||||
{field.input === "list" ? (
|
||||
<TemplateListField
|
||||
field={field}
|
||||
name={presentationFieldName(section.key, field.key)}
|
||||
/>
|
||||
) : (
|
||||
<Form.Item
|
||||
name={presentationFieldName(section.key, field.key)}
|
||||
label={field.label}
|
||||
{...(field.help ? { help: field.help } : {})}
|
||||
{...(field.required
|
||||
? {
|
||||
rules: [{ required: true, message: `请填写${field.label}` }],
|
||||
}
|
||||
: {})}
|
||||
>
|
||||
<TemplateFieldRenderer field={field} />
|
||||
</Form.Item>
|
||||
)}
|
||||
</Col>
|
||||
))}
|
||||
</Row>
|
||||
</section>
|
||||
))}
|
||||
{relevantPageLinks.length ? (
|
||||
<Alert
|
||||
type="info"
|
||||
showIcon
|
||||
className="admin-offset-bottom-lg"
|
||||
message="这个页面还有关联内容"
|
||||
description={
|
||||
<Space wrap>
|
||||
{relevantPageLinks.map((item) => (
|
||||
<Button
|
||||
key={item.target}
|
||||
type="link"
|
||||
onClick={() => {
|
||||
if (item.target.startsWith("trust:")) {
|
||||
void navigate(
|
||||
`/admin/trust?type=${encodeURIComponent(item.target.slice(6))}`,
|
||||
);
|
||||
return;
|
||||
}
|
||||
void navigate(
|
||||
item.target === "offering" ? "/admin/services" : "/admin/workspace",
|
||||
);
|
||||
}}
|
||||
className="admin-link-flush"
|
||||
>
|
||||
{item.label}
|
||||
</Button>
|
||||
))}
|
||||
</Space>
|
||||
}
|
||||
/>
|
||||
) : null}
|
||||
{!hasEditableFields && !relevantPageLinks.length ? (
|
||||
<p className="admin-section-description">这个页面没有单独的品牌文案配置。</p>
|
||||
) : null}
|
||||
{selectedTarget && !hasEditableFields && relevantPageLinks.length ? (
|
||||
<p className="admin-section-description">此区域内容由对应的业务管理页面维护。</p>
|
||||
) : null}
|
||||
</div>
|
||||
<div className="presentation-editor__form-actions admin-actions admin-offset-top-lg">
|
||||
<MutationError error={save.error} />
|
||||
<Button type="primary" htmlType="submit" loading={save.isPending}>
|
||||
保存页面内容
|
||||
</Button>
|
||||
</div>
|
||||
</Form>
|
||||
);
|
||||
}
|
||||
@@ -4,8 +4,8 @@
|
||||
height: min(72vh, 760px);
|
||||
min-height: 560px;
|
||||
overflow: hidden;
|
||||
border: 1px solid #e8e8e8;
|
||||
background: #f3f4f6;
|
||||
border: 1px solid var(--admin-border);
|
||||
background: var(--admin-fill);
|
||||
}
|
||||
|
||||
.template-preview iframe {
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
import { TemplatePage as FoodTemplatePage } from "../../../../../packages/template-acheng-campus-food/taro/index.tsx";
|
||||
import { TemplatePage as EditorialTemplatePage } from "../../../../../packages/template-linjing-editorial/taro/index.tsx";
|
||||
import React from "react";
|
||||
import { Inquiry } from "../../../../taro/src/components/Inquiry.tsx";
|
||||
import { Records } from "../../../../taro/src/components/Records.tsx";
|
||||
import { Success } from "../../../../taro/src/components/Success.tsx";
|
||||
import { TemplateAssetContext } from "./taro-web-components.jsx";
|
||||
|
||||
const templateRenderers = import.meta.glob("../../../../../packages/template-*/taro/index.tsx", {
|
||||
eager: true,
|
||||
});
|
||||
|
||||
function pageContent({ workspace, page }) {
|
||||
if (page === "inquiry") return <Inquiry workspace={workspace} preview />;
|
||||
if (page === "records") return <Records workspace={workspace} preview />;
|
||||
@@ -13,28 +15,22 @@ function pageContent({ workspace, page }) {
|
||||
return null;
|
||||
}
|
||||
|
||||
function FoodPreview(props) {
|
||||
return (
|
||||
<TemplateAssetContext.Provider value="acheng-campus-food">
|
||||
<FoodTemplatePage {...props}>{pageContent(props)}</FoodTemplatePage>
|
||||
</TemplateAssetContext.Provider>
|
||||
);
|
||||
}
|
||||
function EditorialPreview(props) {
|
||||
return (
|
||||
<TemplateAssetContext.Provider value="linjing-editorial">
|
||||
<EditorialTemplatePage {...props}>{pageContent(props)}</EditorialTemplatePage>
|
||||
</TemplateAssetContext.Provider>
|
||||
);
|
||||
}
|
||||
|
||||
export function resolveTemplateRenderer(workspace) {
|
||||
const config = workspace?.brand?.config;
|
||||
const key =
|
||||
config && typeof config === "object" && !Array.isArray(config)
|
||||
? config.visualTemplateKey
|
||||
: undefined;
|
||||
if (key === "acheng-campus-food") return FoodPreview;
|
||||
if (key === "linjing-editorial") return EditorialPreview;
|
||||
return null;
|
||||
if (typeof key !== "string") return null;
|
||||
const suffix = `/template-${key}/taro/index.tsx`;
|
||||
const entry = Object.entries(templateRenderers).find(([path]) => path.endsWith(suffix));
|
||||
const TemplatePage = entry?.[1]?.TemplatePage;
|
||||
if (!TemplatePage) return null;
|
||||
return function TemplatePreview(props) {
|
||||
return (
|
||||
<TemplateAssetContext.Provider value={key}>
|
||||
<TemplatePage {...props}>{pageContent(props)}</TemplatePage>
|
||||
</TemplateAssetContext.Provider>
|
||||
);
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
import type {
|
||||
AdminTemplateContent,
|
||||
TemplateAdminField,
|
||||
TemplateAdminSection,
|
||||
} from "@personal-brand/api-client";
|
||||
|
||||
export function trustSection(
|
||||
declaration: NonNullable<AdminTemplateContent["trustContentTypes"]>[number],
|
||||
page: string,
|
||||
): TemplateAdminSection {
|
||||
const key = `trust:${declaration.type}`;
|
||||
return {
|
||||
key,
|
||||
title: declaration.label,
|
||||
description: declaration.help ?? "编辑当前展示内容。",
|
||||
page,
|
||||
target: "trust",
|
||||
previewTargets: [
|
||||
{ key, label: declaration.label },
|
||||
...(declaration.previewTargets ?? []).filter(
|
||||
(target) => !target.page || target.page === page,
|
||||
),
|
||||
],
|
||||
fields: [
|
||||
{
|
||||
key: "title",
|
||||
binding: "trust.title",
|
||||
label: declaration.adminFields.title,
|
||||
input: "text" as const,
|
||||
required: true,
|
||||
},
|
||||
...(["summary", "content"] as const)
|
||||
.filter((field) => !declaration.hideStandardFields?.includes(field))
|
||||
.map((field) => ({
|
||||
key: field,
|
||||
binding: `trust.${field}`,
|
||||
label: declaration.adminFields[field],
|
||||
input: "textarea" as const,
|
||||
previewTarget: `trust:${declaration.type}`,
|
||||
...(field === "summary" && declaration.adminFields.summaryHelp
|
||||
? { help: declaration.adminFields.summaryHelp }
|
||||
: {}),
|
||||
...(field === "content" && declaration.required ? { required: true } : {}),
|
||||
})),
|
||||
...(declaration.configFields ?? [])
|
||||
.filter((field) => {
|
||||
const target = declaration.previewTargets?.find(
|
||||
(target) => target.key === field.previewTarget,
|
||||
);
|
||||
return !target?.page || target.page === page;
|
||||
})
|
||||
.map((field) => ({
|
||||
...field,
|
||||
previewTarget: field.previewTarget ?? `trust:${declaration.type}`,
|
||||
})),
|
||||
].map((field) => ({
|
||||
...field,
|
||||
previewTarget: (field as TemplateAdminField).previewTarget ?? `trust:${declaration.type}`,
|
||||
})),
|
||||
};
|
||||
}
|
||||
|
||||
export function previewTargetSource(
|
||||
section: TemplateAdminSection,
|
||||
targetKey: string,
|
||||
): "brand" | "offering" | "trust" | "inquiry" {
|
||||
const fields = section.fields.filter((field) => field.previewTarget === targetKey);
|
||||
if (fields.some((field) => field.binding.startsWith("offering."))) return "offering";
|
||||
if (fields.some((field) => field.binding.startsWith("trust."))) return "trust";
|
||||
if (fields.some((field) => field.binding.startsWith("brand."))) return "brand";
|
||||
return section.target;
|
||||
}
|
||||
|
||||
export function pageTitle(page: string): string {
|
||||
return (
|
||||
(
|
||||
{
|
||||
home: "首页",
|
||||
offerings: "业务展示",
|
||||
service: "服务说明",
|
||||
detail: "详情页",
|
||||
inquiry: "咨询页",
|
||||
success: "提交成功页",
|
||||
records: "记录页",
|
||||
profile: "主理人页",
|
||||
} as Record<string, string>
|
||||
)[page] ?? page
|
||||
);
|
||||
}
|
||||
|
||||
export function fieldTargetTitle(section: { title: string }, targetLabel: string): string {
|
||||
return section.title === targetLabel ? targetLabel : `${targetLabel} · ${section.title}`;
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
import { useMemo } from "react";
|
||||
import type { Offering, TemplateAdminSection, TrustContent } from "@personal-brand/api-client";
|
||||
import {
|
||||
applyPresentationValues,
|
||||
applyStandardEntityValues,
|
||||
} from "../../lib/presentation/presentation-bindings.js";
|
||||
import type { PresentationValues } from "../../lib/presentation/presentation-bindings.js";
|
||||
|
||||
export interface RecordDraft {
|
||||
source: "offering" | "trust";
|
||||
id: string;
|
||||
values: PresentationValues;
|
||||
}
|
||||
|
||||
export function useRecordPreview({
|
||||
recordDraft,
|
||||
selectedRecord,
|
||||
recordSection,
|
||||
}: {
|
||||
recordDraft?: RecordDraft | undefined;
|
||||
selectedRecord?: Offering | TrustContent | undefined;
|
||||
recordSection?: TemplateAdminSection | undefined;
|
||||
}) {
|
||||
return useMemo(() => {
|
||||
if (!recordDraft || !selectedRecord || !recordSection) return undefined;
|
||||
const config = applyPresentationValues(
|
||||
selectedRecord.config,
|
||||
[recordSection],
|
||||
recordDraft.values,
|
||||
);
|
||||
return {
|
||||
config,
|
||||
standard: applyStandardEntityValues(
|
||||
selectedRecord as unknown as Record<string, unknown>,
|
||||
recordDraft.source,
|
||||
[recordSection],
|
||||
recordDraft.values,
|
||||
),
|
||||
};
|
||||
}, [recordDraft, selectedRecord, recordSection]);
|
||||
}
|
||||
@@ -0,0 +1,228 @@
|
||||
import { Form, message } from "antd";
|
||||
import { useMutation, useQuery } from "@tanstack/react-query";
|
||||
import type { QueryClient } from "@tanstack/react-query";
|
||||
import { useCallback, useEffect, useMemo, useState } from "react";
|
||||
import type { FormInstance } from "antd";
|
||||
import type {
|
||||
AdminTemplateContent,
|
||||
BrandProfile,
|
||||
Offering,
|
||||
TemplateAdminSection,
|
||||
TrustContent,
|
||||
} from "@personal-brand/api-client";
|
||||
import { createApiClient } from "../../lib/api.js";
|
||||
import {
|
||||
applyBrandPreviewValues,
|
||||
applyPresentationValues,
|
||||
applyStandardBrandValues,
|
||||
presentationFieldName,
|
||||
readPresentationValue,
|
||||
type PresentationValues,
|
||||
} from "../../lib/presentation/presentation-bindings.js";
|
||||
|
||||
const standardBrandBindings = [
|
||||
"brand.name",
|
||||
"brand.tagline",
|
||||
"brand.avatarUrl",
|
||||
"brand.description",
|
||||
"brand.contactPhone",
|
||||
"brand.contactWechat",
|
||||
"brand.address",
|
||||
] as const;
|
||||
|
||||
export interface BrandPresentationFormState {
|
||||
form: FormInstance<PresentationValues>;
|
||||
initialValues: PresentationValues;
|
||||
}
|
||||
|
||||
export function useBrandPresentationSections(
|
||||
templateContent: AdminTemplateContent | null | undefined,
|
||||
): TemplateAdminSection[] {
|
||||
return useMemo(() => {
|
||||
const declaredTemplateFields = (templateContent?.templateFields ?? []).map((field) => ({
|
||||
...field,
|
||||
binding: field.binding ?? `brand.config.templateData.${field.key}`,
|
||||
}));
|
||||
return [
|
||||
...[...new Set(declaredTemplateFields.map((field) => field.page ?? "home"))].map((page) => ({
|
||||
key: `template-data:${page}`,
|
||||
title: "模板专属内容",
|
||||
description: "这些字段由当前小程序模板定义,保存后发布才会对外展示。",
|
||||
page,
|
||||
target: "brand" as const,
|
||||
fields: declaredTemplateFields.filter((field) => (field.page ?? "home") === page),
|
||||
})),
|
||||
...(templateContent?.admin.sections ?? []),
|
||||
].map((section) => ({
|
||||
...section,
|
||||
fields: section.fields.filter(
|
||||
(field) =>
|
||||
field.binding.startsWith("brand.config.") ||
|
||||
(standardBrandBindings as readonly string[]).includes(field.binding),
|
||||
),
|
||||
}));
|
||||
}, [templateContent]);
|
||||
}
|
||||
|
||||
export function useBrandPresentationForm({
|
||||
brand,
|
||||
config,
|
||||
sections,
|
||||
}: {
|
||||
brand: BrandProfile;
|
||||
config: Record<string, unknown> | null | undefined;
|
||||
sections: TemplateAdminSection[];
|
||||
}): BrandPresentationFormState {
|
||||
const [form] = Form.useForm<PresentationValues>();
|
||||
const initialValues = useMemo(() => {
|
||||
const values: PresentationValues = {};
|
||||
for (const section of sections) {
|
||||
for (const field of section.fields) {
|
||||
values[presentationFieldName(section.key, field.key)] = readPresentationValue(
|
||||
config,
|
||||
field.binding,
|
||||
field,
|
||||
brand as unknown as Record<string, unknown>,
|
||||
);
|
||||
}
|
||||
}
|
||||
return values;
|
||||
}, [brand, config, sections]);
|
||||
|
||||
useEffect(() => form.setFieldsValue(initialValues), [form, initialValues]);
|
||||
return { form, initialValues };
|
||||
}
|
||||
|
||||
interface BrandSaveMutationOptions extends BrandPresentationFormState {
|
||||
brand: BrandProfile;
|
||||
config: Record<string, unknown> | null | undefined;
|
||||
sections: TemplateAdminSection[];
|
||||
queryClient: QueryClient;
|
||||
}
|
||||
|
||||
export function useBrandSaveMutation({
|
||||
brand,
|
||||
config,
|
||||
sections,
|
||||
queryClient,
|
||||
}: BrandSaveMutationOptions) {
|
||||
return useMutation({
|
||||
mutationFn: (values: PresentationValues) => {
|
||||
const nextConfig = applyPresentationValues(config, sections, values);
|
||||
const contentConfig = { ...nextConfig };
|
||||
delete contentConfig.visualTemplateKey;
|
||||
const standard = applyStandardBrandValues(
|
||||
brand as unknown as Record<string, unknown>,
|
||||
sections,
|
||||
values,
|
||||
);
|
||||
const changed = Object.fromEntries(
|
||||
Object.entries(standard).filter(
|
||||
([key, value]) =>
|
||||
key !== "config" && value !== (brand as unknown as Record<string, unknown>)[key],
|
||||
),
|
||||
);
|
||||
return createApiClient().updateAdminBrand({ ...changed, config: contentConfig });
|
||||
},
|
||||
onSuccess: () => {
|
||||
message.success("页面内容已保存为草稿,发布后小程序才会更新");
|
||||
window.dispatchEvent(new Event("template-preview-refresh"));
|
||||
void queryClient.invalidateQueries({ queryKey: ["admin-brand"] });
|
||||
void queryClient.invalidateQueries({ queryKey: ["admin-workspace"] });
|
||||
void queryClient.invalidateQueries({ queryKey: ["admin-preview-workspace"] });
|
||||
void queryClient.invalidateQueries({ queryKey: ["public-runtime-workspace"] });
|
||||
void queryClient.invalidateQueries({ queryKey: ["publication-readiness"] });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useBrandPreviewDraft({
|
||||
brand,
|
||||
config,
|
||||
sections,
|
||||
form,
|
||||
onDirty,
|
||||
}: {
|
||||
brand: BrandProfile;
|
||||
config: Record<string, unknown> | null | undefined;
|
||||
sections: TemplateAdminSection[];
|
||||
form: BrandPresentationFormState["form"];
|
||||
onDirty: () => void;
|
||||
}) {
|
||||
const [previewConfig, setPreviewConfig] = useState(config ?? {});
|
||||
const [previewBrandValues, setPreviewBrandValues] = useState<Record<string, unknown>>({});
|
||||
|
||||
useEffect(() => {
|
||||
setPreviewConfig(config ?? {});
|
||||
setPreviewBrandValues({});
|
||||
}, [config, form]);
|
||||
|
||||
const handleValuesChange = (changed: PresentationValues, allValues: PresentationValues) => {
|
||||
onDirty();
|
||||
const synchronized: PresentationValues = {
|
||||
...(form.getFieldsValue(true) as PresentationValues),
|
||||
...allValues,
|
||||
};
|
||||
for (const section of sections) {
|
||||
for (const field of section.fields) {
|
||||
const name = presentationFieldName(section.key, field.key);
|
||||
if (!Object.prototype.hasOwnProperty.call(changed, name)) continue;
|
||||
for (const peer of sections) {
|
||||
for (const item of peer.fields) {
|
||||
if (item.binding === field.binding)
|
||||
synchronized[presentationFieldName(peer.key, item.key)] = changed[name];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
form.setFieldsValue(synchronized);
|
||||
const next = applyBrandPreviewValues(
|
||||
brand as unknown as Record<string, unknown>,
|
||||
config,
|
||||
sections,
|
||||
synchronized,
|
||||
);
|
||||
setPreviewConfig((next.config as Record<string, unknown>) ?? {});
|
||||
setPreviewBrandValues(next);
|
||||
};
|
||||
|
||||
const previewBrand = useMemo(
|
||||
() => ({ ...brand, ...previewBrandValues, config: previewConfig }),
|
||||
[brand, previewBrandValues, previewConfig],
|
||||
);
|
||||
|
||||
const resetPreview = useCallback(() => {
|
||||
setPreviewConfig(config ?? {});
|
||||
setPreviewBrandValues({});
|
||||
}, [config]);
|
||||
|
||||
return {
|
||||
previewBrand,
|
||||
handleValuesChange,
|
||||
resetPreview,
|
||||
};
|
||||
}
|
||||
|
||||
export function usePresentationRecordQueries(
|
||||
source: "offering" | "trust" | undefined,
|
||||
recordId: string | undefined,
|
||||
) {
|
||||
const offeringsQuery = useQuery({
|
||||
queryKey: ["admin-offerings"],
|
||||
queryFn: () => createApiClient().listAdminOfferings(),
|
||||
enabled: source === "offering",
|
||||
refetchOnMount: "always",
|
||||
});
|
||||
const trustQuery = useQuery({
|
||||
queryKey: ["trust-content"],
|
||||
queryFn: () => createApiClient().listAdminTrustContent(),
|
||||
enabled: source === "trust",
|
||||
});
|
||||
const selectedRecord =
|
||||
source === "offering"
|
||||
? offeringsQuery.data?.find((item: Offering) => item.id === recordId)
|
||||
: source === "trust"
|
||||
? trustQuery.data?.find((item: TrustContent) => item.id === recordId)
|
||||
: undefined;
|
||||
return { offeringsQuery, trustQuery, selectedRecord };
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
import { useMemo } from "react";
|
||||
import type {
|
||||
AdminTemplateContent,
|
||||
BrandProfile,
|
||||
Offering,
|
||||
RuntimeWorkspace,
|
||||
TemplateAdminSection,
|
||||
TrustContent,
|
||||
} from "@personal-brand/api-client";
|
||||
import { projectBrandAliases, projectTrustPresentation } from "@personal-brand/api-client";
|
||||
import {
|
||||
presentationFieldName,
|
||||
type PresentationValues,
|
||||
} from "../../lib/presentation/presentation-bindings.js";
|
||||
import type { RecordDraft } from "./presentation-editor-record-preview.js";
|
||||
|
||||
interface DraftWorkspaceInput {
|
||||
previewWorkspace: RuntimeWorkspace | undefined;
|
||||
previewBrand: BrandProfile;
|
||||
inquiryRuntime: RuntimeWorkspace["inquiryForms"][number] | undefined;
|
||||
inquiryDraft: RuntimeWorkspace["inquiryForms"][number]["fields"] | undefined;
|
||||
recordDraft: RecordDraft | undefined;
|
||||
selectedRecord: Offering | TrustContent | undefined;
|
||||
recordSection: TemplateAdminSection | undefined;
|
||||
recordPreview: { config: Record<string, unknown>; standard: Record<string, unknown> } | undefined;
|
||||
templateContent: AdminTemplateContent | null | undefined;
|
||||
}
|
||||
|
||||
export function useDraftWorkspace(input: DraftWorkspaceInput): RuntimeWorkspace | undefined {
|
||||
const { previewWorkspace, previewBrand, inquiryRuntime, inquiryDraft } = input;
|
||||
return useMemo(() => {
|
||||
if (!previewWorkspace) return undefined;
|
||||
const previewConfig = previewBrand.config ?? {};
|
||||
const next: RuntimeWorkspace = {
|
||||
...previewWorkspace,
|
||||
templateData: {
|
||||
...previewWorkspace.templateData,
|
||||
...(previewConfig.templateData &&
|
||||
typeof previewConfig.templateData === "object" &&
|
||||
!Array.isArray(previewConfig.templateData)
|
||||
? (previewConfig.templateData as Record<string, unknown>)
|
||||
: {}),
|
||||
},
|
||||
inquiryForms: previewWorkspace.inquiryForms.map((item) =>
|
||||
item.key === inquiryRuntime?.key && inquiryDraft ? { ...item, fields: inquiryDraft } : item,
|
||||
),
|
||||
brand: projectBrandAliases(
|
||||
{
|
||||
...previewWorkspace.brand,
|
||||
...(previewBrand as unknown as Record<string, unknown>),
|
||||
config: previewConfig,
|
||||
},
|
||||
previewConfig,
|
||||
),
|
||||
};
|
||||
const { recordDraft, selectedRecord, recordSection, recordPreview } = input;
|
||||
if (!recordDraft || !selectedRecord || !recordSection || recordDraft.id !== selectedRecord.id)
|
||||
return next;
|
||||
const config = recordPreview?.config;
|
||||
const standard = recordPreview?.standard;
|
||||
if (!config || !standard) return next;
|
||||
if (recordDraft.source === "trust") {
|
||||
next.trustItems = next.trustItems.map((item) =>
|
||||
item.id === recordDraft.id
|
||||
? {
|
||||
...item,
|
||||
title: typeof standard.title === "string" ? standard.title : item.title,
|
||||
summary: typeof standard.summary === "string" ? standard.summary : item.summary,
|
||||
content: typeof standard.content === "string" ? standard.content : item.content,
|
||||
config,
|
||||
}
|
||||
: item,
|
||||
);
|
||||
next.trustPresentation = projectTrustPresentation(
|
||||
next.trustItems,
|
||||
input.templateContent?.trustContentTypes ?? [],
|
||||
);
|
||||
} else {
|
||||
next.offerings = next.offerings.map((item) =>
|
||||
item.id === recordDraft.id
|
||||
? {
|
||||
...item,
|
||||
name:
|
||||
(recordDraft.values[presentationFieldName(recordSection.key, "name")] as string) ||
|
||||
item.name,
|
||||
summary:
|
||||
(recordDraft.values[
|
||||
presentationFieldName(recordSection.key, "summary")
|
||||
] as string) || item.summary,
|
||||
priceText:
|
||||
(recordDraft.values[
|
||||
presentationFieldName(recordSection.key, "priceText")
|
||||
] as string) || null,
|
||||
coverUrl:
|
||||
(recordDraft.values[
|
||||
presentationFieldName(recordSection.key, "coverUrl")
|
||||
] as string) || null,
|
||||
presentation: {
|
||||
...item.presentation,
|
||||
...config,
|
||||
...(config.presentation && typeof config.presentation === "object"
|
||||
? (config.presentation as Record<string, unknown>)
|
||||
: {}),
|
||||
...(typeof config.area === "string" ? { area: config.area } : {}),
|
||||
...(typeof config.series === "string" ? { series: config.series } : {}),
|
||||
...(typeof config.spaceType === "string" ? { spaceType: config.spaceType } : {}),
|
||||
heroImage:
|
||||
typeof config.detailHero === "string"
|
||||
? config.detailHero
|
||||
: typeof standard.coverUrl === "string"
|
||||
? standard.coverUrl
|
||||
: null,
|
||||
details: {
|
||||
...item.presentation.details,
|
||||
...(config.details &&
|
||||
typeof config.details === "object" &&
|
||||
"background" in config.details
|
||||
? (config.details as RuntimeWorkspace["offerings"][number]["presentation"]["details"])
|
||||
: {}),
|
||||
},
|
||||
},
|
||||
}
|
||||
: item,
|
||||
);
|
||||
}
|
||||
return next;
|
||||
}, [input, previewWorkspace, previewBrand, inquiryRuntime, inquiryDraft]);
|
||||
}
|
||||
@@ -1,148 +1,43 @@
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import { Alert, Button, Card, Form, Input, Select, Table, Tag, message } from "antd";
|
||||
import type { CapabilityInstallation } from "@personal-brand/api-client";
|
||||
import { Button, Card, Col, Row } from "antd";
|
||||
import { AppstoreOutlined } from "@ant-design/icons";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { AdminPageHeader } from "../../components/AdminPageHeader.js";
|
||||
import { EmptyState } from "../../components/EmptyState.js";
|
||||
import { QueryState } from "../../components/QueryState.js";
|
||||
import { createApiClient } from "../../lib/api.js";
|
||||
|
||||
const statusLabels = { enabled: "已启用", disabled: "已停用", degraded: "降级" } as const;
|
||||
import { CapabilityCard } from "./components/CapabilityCard.js";
|
||||
import { useCapabilityQuery } from "./hooks/useCapabilityQueries.js";
|
||||
|
||||
export function CapabilitiesPage() {
|
||||
const queryClient = useQueryClient();
|
||||
const query = useQuery({
|
||||
queryKey: ["admin", "capabilities"],
|
||||
queryFn: () => createApiClient().listAdminCapabilities(),
|
||||
});
|
||||
const mutation = useMutation({
|
||||
mutationFn: ({
|
||||
key,
|
||||
values,
|
||||
}: {
|
||||
key: string;
|
||||
values: {
|
||||
capabilityVersion: string;
|
||||
status: CapabilityInstallation["status"];
|
||||
configText?: string;
|
||||
};
|
||||
}) =>
|
||||
createApiClient().updateAdminCapability(key, {
|
||||
capabilityVersion: values.capabilityVersion,
|
||||
status: values.status,
|
||||
config: values.configText ? (JSON.parse(values.configText) as Record<string, unknown>) : {},
|
||||
}),
|
||||
onSuccess: () => {
|
||||
message.success("能力配置已更新");
|
||||
void queryClient.invalidateQueries({ queryKey: ["admin", "capabilities"] });
|
||||
},
|
||||
onError: (error) => message.error(error instanceof Error ? error.message : "更新失败"),
|
||||
});
|
||||
const sampleMutation = useMutation({
|
||||
mutationFn: () => createApiClient().importAdminSampleContent(),
|
||||
onSuccess: (result) => message.success(`已导入 ${result.counts.offerings} 项示例业务`),
|
||||
onError: (error) => message.error(error instanceof Error ? error.message : "导入失败"),
|
||||
});
|
||||
if (query.isLoading) return <QueryState loading />;
|
||||
if (query.isError) return <QueryState error={query.error} />;
|
||||
const items = query.data ?? [];
|
||||
return (
|
||||
<div>
|
||||
<AdminPageHeader title="能力插件" description="管理当前模板声明的业务能力及其运行状态。" />
|
||||
<Alert
|
||||
type="info"
|
||||
showIcon
|
||||
message="能力状态会影响公开 Runtime Workspace;停用不会删除历史数据。"
|
||||
style={{ marginBottom: 16 }}
|
||||
/>
|
||||
<Button
|
||||
onClick={() => sampleMutation.mutate()}
|
||||
loading={sampleMutation.isPending}
|
||||
style={{ marginBottom: 16 }}
|
||||
>
|
||||
导入门窗示例内容
|
||||
</Button>
|
||||
<Table
|
||||
rowKey="capabilityKey"
|
||||
dataSource={items}
|
||||
locale={{ emptyText: "当前还没有品牌级能力覆盖,系统将使用模板默认能力。" }}
|
||||
columns={[
|
||||
{ title: "能力", dataIndex: "capabilityKey" },
|
||||
{
|
||||
title: "来源",
|
||||
dataIndex: "source",
|
||||
render: (value: CapabilityInstallation["source"]) => (
|
||||
<Tag>{value === "brand" ? "品牌覆盖" : "模板默认"}</Tag>
|
||||
),
|
||||
},
|
||||
{ title: "版本", dataIndex: "capabilityVersion" },
|
||||
{
|
||||
title: "状态",
|
||||
dataIndex: "status",
|
||||
render: (value: CapabilityInstallation["status"]) => (
|
||||
<Tag
|
||||
color={value === "enabled" ? "green" : value === "degraded" ? "orange" : "default"}
|
||||
>
|
||||
{statusLabels[value]}
|
||||
</Tag>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: "操作",
|
||||
render: (_: unknown, record: CapabilityInstallation) => (
|
||||
<CapabilityEditor
|
||||
record={record}
|
||||
loading={mutation.isPending}
|
||||
onSubmit={(values) => mutation.mutate({ key: record.capabilityKey, values })}
|
||||
/>
|
||||
),
|
||||
},
|
||||
]}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
const navigate = useNavigate();
|
||||
const query = useCapabilityQuery();
|
||||
|
||||
function CapabilityEditor({
|
||||
record,
|
||||
loading,
|
||||
onSubmit,
|
||||
}: {
|
||||
record: CapabilityInstallation;
|
||||
loading: boolean;
|
||||
onSubmit: (values: {
|
||||
capabilityVersion: string;
|
||||
status: CapabilityInstallation["status"];
|
||||
configText?: string;
|
||||
}) => void;
|
||||
}) {
|
||||
const [form] = Form.useForm();
|
||||
return (
|
||||
<Card size="small" style={{ maxWidth: 420 }}>
|
||||
<Form
|
||||
form={form}
|
||||
layout="inline"
|
||||
initialValues={{
|
||||
capabilityVersion: record.capabilityVersion,
|
||||
status: record.status,
|
||||
configText: record.config ? JSON.stringify(record.config) : "",
|
||||
}}
|
||||
onFinish={onSubmit}
|
||||
>
|
||||
<Form.Item name="capabilityVersion" rules={[{ required: true, message: "请输入版本" }]}>
|
||||
<Input placeholder="版本" style={{ width: 100 }} />
|
||||
</Form.Item>
|
||||
<Form.Item name="status">
|
||||
<Select
|
||||
options={Object.entries(statusLabels).map(([value, label]) => ({ value, label }))}
|
||||
style={{ width: 100 }}
|
||||
<QueryState loading={query.isLoading} error={query.error} onRetry={() => void query.refetch()}>
|
||||
<AdminPageHeader
|
||||
title="能力插件"
|
||||
description="以经营者视角调整模板能力的开关与展示设置;保存后进入草稿,发布后生效。"
|
||||
/>
|
||||
{query.data?.length ? (
|
||||
<Row gutter={[16, 16]} className="admin-equal-height">
|
||||
{query.data.map((capability) => (
|
||||
<Col key={capability.capabilityKey} xs={24} lg={12}>
|
||||
<CapabilityCard capability={capability} />
|
||||
</Col>
|
||||
))}
|
||||
</Row>
|
||||
) : (
|
||||
<Card>
|
||||
<EmptyState
|
||||
icon={<AppstoreOutlined />}
|
||||
title="当前模板没有可配置能力"
|
||||
description="能力的开关由品牌当前使用的行业模板决定;更换行业模板不在本版本范围内。"
|
||||
action={<Button onClick={() => navigate("/admin/publication")}>查看模板与发布</Button>}
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item name="configText">
|
||||
<Input placeholder="JSON 配置(可选)" style={{ width: 180 }} />
|
||||
</Form.Item>
|
||||
<Button type="primary" htmlType="submit" loading={loading}>
|
||||
保存
|
||||
</Button>
|
||||
</Form>
|
||||
</Card>
|
||||
</Card>
|
||||
)}
|
||||
<p className="admin-page-header-description admin-offset-top">
|
||||
技术信息仅用于排查问题,不作为运营判断依据。
|
||||
</p>
|
||||
</QueryState>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,155 @@
|
||||
import { Button, Card, Input, Space, Switch, Typography } from "antd";
|
||||
import { useState } from "react";
|
||||
import { ErrorNote } from "../../../components/QueryState.js";
|
||||
import { StatusTag } from "../../../components/StatusTag.js";
|
||||
import { useCapabilityMutation } from "../hooks/useCapabilityQueries.js";
|
||||
import type { AdminCapability, CapabilityStatus } from "../types.js";
|
||||
import { CapabilityStatusControl, CapabilityStatusTag } from "./CapabilityStatusControl.js";
|
||||
|
||||
const sourceLabels = {
|
||||
brand: "品牌覆盖",
|
||||
template: "模板默认",
|
||||
} as const;
|
||||
|
||||
const disablePolicyLabels = {
|
||||
allowed: "该能力允许停用,保存后进入草稿。",
|
||||
disabled: "该能力为模板必需项,保存后进入草稿。",
|
||||
} as const;
|
||||
|
||||
const updatedTimeFormatter = new Intl.DateTimeFormat("zh-CN", {
|
||||
dateStyle: "short",
|
||||
timeStyle: "short",
|
||||
});
|
||||
|
||||
function readTextValue(value: unknown): string {
|
||||
return typeof value === "string" ? value : "";
|
||||
}
|
||||
|
||||
function readSwitchValue(value: unknown): boolean {
|
||||
return value === true;
|
||||
}
|
||||
|
||||
function sameConfig(current: Record<string, unknown>, baseline: Record<string, unknown>): boolean {
|
||||
const currentKeys = Object.keys(current ?? {}).sort();
|
||||
const baselineKeys = Object.keys(baseline ?? {}).sort();
|
||||
if (currentKeys.length !== baselineKeys.length) return false;
|
||||
return currentKeys.every(
|
||||
(key, index) =>
|
||||
key === baselineKeys[index] && JSON.stringify(current[key]) === JSON.stringify(baseline[key]),
|
||||
);
|
||||
}
|
||||
|
||||
export function CapabilityCard({ capability }: { capability: AdminCapability }) {
|
||||
const [status, setStatus] = useState<CapabilityStatus>(capability.status);
|
||||
const [config, setConfig] = useState<Record<string, unknown>>(capability.config);
|
||||
const mutation = useCapabilityMutation();
|
||||
const dirty = status !== capability.status || !sameConfig(config, capability.config ?? {});
|
||||
|
||||
const save = async () => {
|
||||
await mutation.mutateAsync({
|
||||
key: capability.capabilityKey,
|
||||
status,
|
||||
config,
|
||||
});
|
||||
};
|
||||
|
||||
const updateConfigValue = (key: string, value: unknown) =>
|
||||
setConfig((current) => ({ ...current, [key]: value }));
|
||||
|
||||
return (
|
||||
<Card
|
||||
title={
|
||||
<span className="admin-row-line">
|
||||
{capability.displayName ?? "未命名能力"}
|
||||
<CapabilityStatusTag status={status} />
|
||||
<StatusTag tone="neutral" label={sourceLabels[capability.source]} />
|
||||
</span>
|
||||
}
|
||||
extra={
|
||||
<Space>
|
||||
{dirty ? <StatusTag tone="warning" label="有未保存修改" /> : null}
|
||||
<Button
|
||||
type={dirty ? "primary" : "default"}
|
||||
disabled={!dirty}
|
||||
loading={mutation.isPending}
|
||||
onClick={() => void save()}
|
||||
>
|
||||
保存草稿
|
||||
</Button>
|
||||
</Space>
|
||||
}
|
||||
>
|
||||
{mutation.isError ? (
|
||||
<div className="admin-offset-bottom">
|
||||
<ErrorNote error={mutation.error} />
|
||||
</div>
|
||||
) : null}
|
||||
{capability.description ? (
|
||||
<p className="admin-section-description">{capability.description}</p>
|
||||
) : null}
|
||||
{capability.impact ? (
|
||||
<p className="admin-section-description">影响:{capability.impact}</p>
|
||||
) : null}
|
||||
<div className="admin-field-stack">
|
||||
<div>
|
||||
<span className="admin-field-label">运行状态</span>
|
||||
<div className="admin-offset-top-sm">
|
||||
<CapabilityStatusControl
|
||||
status={status}
|
||||
onChange={setStatus}
|
||||
disabled={mutation.isPending}
|
||||
/>
|
||||
</div>
|
||||
<p className="admin-section-description admin-flush">保存后进入草稿,发布后生效。</p>
|
||||
{status === "disabled" && capability.disablePolicy ? (
|
||||
<p className="admin-section-description admin-flush admin-text-warning">
|
||||
{disablePolicyLabels[capability.disablePolicy]}
|
||||
</p>
|
||||
) : null}
|
||||
</div>
|
||||
{capability.configFields?.length ? (
|
||||
<div>
|
||||
<span className="admin-field-label">能力设置</span>
|
||||
<div className="admin-field-stack admin-offset-top-sm">
|
||||
{capability.configFields.map((field) => (
|
||||
<div key={field.key}>
|
||||
<span className="admin-field-label">{field.label}</span>
|
||||
{field.input === "switch" ? (
|
||||
<div>
|
||||
<Switch
|
||||
checked={readSwitchValue(config[field.key])}
|
||||
disabled={mutation.isPending}
|
||||
onChange={(checked) => updateConfigValue(field.key, checked)}
|
||||
/>
|
||||
</div>
|
||||
) : field.input === "textarea" ? (
|
||||
<Input.TextArea
|
||||
rows={3}
|
||||
value={readTextValue(config[field.key])}
|
||||
disabled={mutation.isPending}
|
||||
onChange={(event) => updateConfigValue(field.key, event.target.value)}
|
||||
/>
|
||||
) : (
|
||||
<Input
|
||||
value={readTextValue(config[field.key])}
|
||||
disabled={mutation.isPending}
|
||||
onChange={(event) => updateConfigValue(field.key, event.target.value)}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
) : null}
|
||||
<Typography.Text type="secondary">
|
||||
{capability.source === "template"
|
||||
? "当前使用模板默认设置;修改后保存会创建品牌覆盖。"
|
||||
: "当前已创建品牌覆盖;修改后保存会更新草稿。"}
|
||||
{capability.updatedAt
|
||||
? ` 最近更新:${updatedTimeFormatter.format(new Date(capability.updatedAt))}`
|
||||
: ""}
|
||||
</Typography.Text>
|
||||
</div>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
import { Segmented, Space, Switch, Typography } from "antd";
|
||||
import type { CapabilityStatus } from "../types.js";
|
||||
import { StatusTag } from "../../../components/StatusTag.js";
|
||||
import type { StatusTone } from "../../../components/StatusTag.js";
|
||||
|
||||
const statusLabels: Record<CapabilityStatus, string> = {
|
||||
enabled: "启用",
|
||||
disabled: "停用",
|
||||
degraded: "降级",
|
||||
};
|
||||
|
||||
const statusTones: Record<CapabilityStatus, StatusTone> = {
|
||||
enabled: "success",
|
||||
disabled: "neutral",
|
||||
degraded: "warning",
|
||||
};
|
||||
|
||||
export function CapabilityStatusTag({ status }: { status: CapabilityStatus }) {
|
||||
return <StatusTag tone={statusTones[status]} label={statusLabels[status]} />;
|
||||
}
|
||||
|
||||
export function CapabilityStatusControl({
|
||||
status,
|
||||
onChange,
|
||||
disabled,
|
||||
}: {
|
||||
status: CapabilityStatus;
|
||||
onChange: (status: CapabilityStatus) => void;
|
||||
disabled?: boolean;
|
||||
}) {
|
||||
const isDisabled = disabled === true;
|
||||
if (status === "degraded")
|
||||
return (
|
||||
<Segmented
|
||||
value={status}
|
||||
disabled={isDisabled}
|
||||
options={[
|
||||
{ value: "degraded", label: "降级" },
|
||||
{ value: "enabled", label: "启用" },
|
||||
{ value: "disabled", label: "停用" },
|
||||
]}
|
||||
onChange={(value) => onChange(value as CapabilityStatus)}
|
||||
/>
|
||||
);
|
||||
|
||||
return (
|
||||
<Space>
|
||||
<Switch
|
||||
checked={status === "enabled"}
|
||||
disabled={isDisabled}
|
||||
onChange={(checked) => onChange(checked ? "enabled" : "disabled")}
|
||||
/>
|
||||
<Typography.Text type={status === "enabled" ? "success" : "secondary"}>
|
||||
{statusLabels[status]}
|
||||
</Typography.Text>
|
||||
</Space>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import { message } from "antd";
|
||||
import { createApiClient } from "../../../lib/api.js";
|
||||
import { readAdminCapability } from "../types.js";
|
||||
import type { CapabilityValues } from "../types.js";
|
||||
|
||||
export const capabilitiesQueryKey = ["admin", "capabilities"] as const;
|
||||
|
||||
export function useCapabilityQuery() {
|
||||
return useQuery({
|
||||
queryKey: capabilitiesQueryKey,
|
||||
queryFn: async () => {
|
||||
const response = await createApiClient().listAdminCapabilities();
|
||||
return response.map(readAdminCapability);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useCapabilityMutation() {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: ({ key, ...values }: { key: string } & CapabilityValues) =>
|
||||
createApiClient().updateAdminCapability(key, {
|
||||
...values,
|
||||
}),
|
||||
onSuccess: () => {
|
||||
message.success("能力已保存,进入草稿;发布后生效");
|
||||
void queryClient.invalidateQueries({ queryKey: capabilitiesQueryKey });
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
import type { CapabilityInstallation } from "@personal-brand/api-client";
|
||||
|
||||
export type CapabilityStatus = CapabilityInstallation["status"];
|
||||
|
||||
export type CapabilitySource = NonNullable<CapabilityInstallation["source"]>;
|
||||
|
||||
export interface CapabilityConfigField {
|
||||
key: string;
|
||||
label: string;
|
||||
input: string;
|
||||
required: boolean;
|
||||
}
|
||||
|
||||
export interface AdminCapability {
|
||||
capabilityKey: string;
|
||||
capabilityVersion: string;
|
||||
status: CapabilityStatus;
|
||||
config: Record<string, unknown>;
|
||||
source: CapabilitySource;
|
||||
updatedAt?: string | null;
|
||||
displayName?: string | undefined;
|
||||
description?: string | undefined;
|
||||
impact?: string | undefined;
|
||||
optional?: boolean | undefined;
|
||||
disablePolicy?: "allowed" | "disabled" | undefined;
|
||||
configFields?: CapabilityConfigField[] | undefined;
|
||||
}
|
||||
|
||||
export interface CapabilityValues {
|
||||
status: CapabilityStatus;
|
||||
config: Record<string, unknown>;
|
||||
}
|
||||
|
||||
export function isCapabilitySource(value: unknown): value is CapabilitySource {
|
||||
return value === "brand" || value === "template";
|
||||
}
|
||||
|
||||
export function readAdminCapability(value: CapabilityInstallation): AdminCapability {
|
||||
const { config, source, ...rest } = value;
|
||||
return {
|
||||
...rest,
|
||||
config: config ?? {},
|
||||
source: isCapabilitySource(source) ? source : "template",
|
||||
displayName: readOptionalString(value.displayName),
|
||||
description: readOptionalString(value.description),
|
||||
impact: readOptionalString(value.impact),
|
||||
optional: typeof value.optional === "boolean" ? value.optional : undefined,
|
||||
disablePolicy:
|
||||
value.disablePolicy === "allowed" || value.disablePolicy === "disabled"
|
||||
? value.disablePolicy
|
||||
: undefined,
|
||||
configFields: Array.isArray(value.configFields)
|
||||
? value.configFields.filter(isCapabilityConfigField)
|
||||
: undefined,
|
||||
};
|
||||
}
|
||||
|
||||
function readOptionalString(value: unknown): string | undefined {
|
||||
return typeof value === "string" && value.trim() ? value : undefined;
|
||||
}
|
||||
|
||||
function isCapabilityConfigField(value: {
|
||||
key: string;
|
||||
label: string;
|
||||
input: string;
|
||||
required: boolean;
|
||||
}): value is CapabilityConfigField {
|
||||
const field = value;
|
||||
return (
|
||||
typeof field.key === "string" &&
|
||||
field.key.length > 0 &&
|
||||
typeof field.label === "string" &&
|
||||
field.label.length > 0 &&
|
||||
(field.input === "text" || field.input === "textarea" || field.input === "switch")
|
||||
);
|
||||
}
|
||||
@@ -1,20 +1,15 @@
|
||||
import {
|
||||
Badge,
|
||||
Button,
|
||||
Card,
|
||||
Descriptions,
|
||||
Drawer,
|
||||
Select,
|
||||
Space,
|
||||
Table,
|
||||
Tag,
|
||||
message,
|
||||
Input,
|
||||
} from "antd";
|
||||
import { Badge, Button, Descriptions, Drawer, Select, Space, Table, message, Input } from "antd";
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import type { AdminBooking, InquirySubmission } from "@personal-brand/api-client";
|
||||
import { createApiClient } from "../../lib/api.js";
|
||||
import { useState } from "react";
|
||||
import { AdminPageHeader } from "../../components/AdminPageHeader.js";
|
||||
import { EmptyState } from "../../components/EmptyState.js";
|
||||
import { AdminSection } from "../../components/AdminSection.js";
|
||||
import { ErrorNote } from "../../components/QueryState.js";
|
||||
import { ListSkeleton, TableSkeleton } from "../../components/TableSkeleton.js";
|
||||
import { StatusTag } from "../../components/StatusTag.js";
|
||||
import type { StatusTone } from "../../components/StatusTag.js";
|
||||
|
||||
const statuses = ["received", "contacting", "confirmed", "completed", "cancelled"] as const;
|
||||
const labels: Record<string, string> = {
|
||||
@@ -41,6 +36,20 @@ const inquiryLabels: Record<string, string> = {
|
||||
closed: "已关闭",
|
||||
};
|
||||
|
||||
const statusTones: Record<string, StatusTone> = {
|
||||
received: "info",
|
||||
new: "info",
|
||||
contacting: "warning",
|
||||
reviewing: "warning",
|
||||
confirmed: "success",
|
||||
replied: "success",
|
||||
qualified: "success",
|
||||
converted: "success",
|
||||
completed: "success",
|
||||
cancelled: "error",
|
||||
closed: "neutral",
|
||||
};
|
||||
|
||||
export function InquiriesPage() {
|
||||
const client = createApiClient();
|
||||
const queryClient = useQueryClient();
|
||||
@@ -94,192 +103,222 @@ export function InquiriesPage() {
|
||||
onError: (error) => message.error(error instanceof Error ? error.message : "更新失败,请重试"),
|
||||
});
|
||||
return (
|
||||
<Card
|
||||
title="咨询记录"
|
||||
extra={
|
||||
<Space>
|
||||
<Select
|
||||
allowClear
|
||||
placeholder="全部状态"
|
||||
style={{ width: 130 }}
|
||||
value={status}
|
||||
onChange={setStatus}
|
||||
options={statuses.map((value) => ({ value, label: labels[value] }))}
|
||||
/>
|
||||
<Badge
|
||||
count={
|
||||
query.data?.filter((item) => !(item as AdminBooking & { isRead?: boolean }).isRead)
|
||||
.length ?? 0
|
||||
}
|
||||
showZero
|
||||
/>
|
||||
</Space>
|
||||
}
|
||||
>
|
||||
<Table
|
||||
rowKey="id"
|
||||
loading={query.isLoading}
|
||||
dataSource={query.data ?? []}
|
||||
columns={[
|
||||
{
|
||||
title: "编号",
|
||||
dataIndex: "bookingNo",
|
||||
render: (value: string, item: AdminBooking) => (
|
||||
<Button type="link" onClick={() => setSelectedId(item.id)}>
|
||||
{value}
|
||||
</Button>
|
||||
),
|
||||
},
|
||||
{ title: "联系人", dataIndex: "customerName" },
|
||||
{
|
||||
title: "提交时间",
|
||||
dataIndex: "createdAt",
|
||||
render: (value: string) => new Date(value).toLocaleString("zh-CN"),
|
||||
},
|
||||
{
|
||||
title: "状态",
|
||||
dataIndex: "status",
|
||||
render: (value: string) => <Tag>{labels[value] ?? value}</Tag>,
|
||||
},
|
||||
{
|
||||
title: "操作",
|
||||
render: (_: unknown, item: AdminBooking) => (
|
||||
<Space>
|
||||
<Select
|
||||
size="small"
|
||||
value={item.status}
|
||||
onChange={(value) => update.mutate({ id: item.id, value: value as never })}
|
||||
options={statuses.map((value) => ({ value, label: labels[value] }))}
|
||||
/>
|
||||
<Button size="small" onClick={() => read.mutate(item.id)}>
|
||||
标记已读
|
||||
</Button>
|
||||
</Space>
|
||||
),
|
||||
},
|
||||
]}
|
||||
/>
|
||||
<Drawer
|
||||
title="咨询详情"
|
||||
open={Boolean(selectedId)}
|
||||
onClose={() => setSelectedId(undefined)}
|
||||
loading={detail.isLoading}
|
||||
width={520}
|
||||
<>
|
||||
<AdminPageHeader title="咨询记录" description="查看访客提交的咨询和预约,并跟进处理进度。" />
|
||||
<AdminSection
|
||||
title="预约咨询"
|
||||
extra={
|
||||
<Space>
|
||||
<Select
|
||||
allowClear
|
||||
placeholder="全部状态"
|
||||
className="admin-field-w-md"
|
||||
value={status}
|
||||
onChange={setStatus}
|
||||
options={statuses.map((value) => ({ value, label: labels[value] }))}
|
||||
/>
|
||||
<Badge
|
||||
count={
|
||||
query.data?.filter((item) => !(item as AdminBooking & { isRead?: boolean }).isRead)
|
||||
.length ?? 0
|
||||
}
|
||||
showZero
|
||||
/>
|
||||
</Space>
|
||||
}
|
||||
>
|
||||
{detail.data && (
|
||||
<Descriptions column={1} bordered size="small">
|
||||
<Descriptions.Item label="编号">{detail.data.bookingNo}</Descriptions.Item>
|
||||
<Descriptions.Item label="联系人">{detail.data.customerName}</Descriptions.Item>
|
||||
<Descriptions.Item label="状态">
|
||||
{labels[detail.data.status] ?? detail.data.status}
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="提交时间">
|
||||
{new Date(detail.data.createdAt).toLocaleString("zh-CN")}
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="管理员备注">
|
||||
{detail.data.adminNote || "暂无"}
|
||||
</Descriptions.Item>
|
||||
</Descriptions>
|
||||
{query.isLoading && !query.data ? (
|
||||
<TableSkeleton />
|
||||
) : (
|
||||
<Table
|
||||
rowKey="id"
|
||||
locale={{
|
||||
emptyText: (
|
||||
<EmptyState
|
||||
compact
|
||||
title="还没有预约咨询"
|
||||
description="访客在小程序提交预约后,会出现在这里。"
|
||||
/>
|
||||
),
|
||||
}}
|
||||
dataSource={query.data ?? []}
|
||||
columns={[
|
||||
{
|
||||
title: "编号",
|
||||
dataIndex: "bookingNo",
|
||||
render: (value: string, item: AdminBooking) => (
|
||||
<Button type="link" onClick={() => setSelectedId(item.id)}>
|
||||
{value}
|
||||
</Button>
|
||||
),
|
||||
},
|
||||
{ title: "联系人", dataIndex: "customerName" },
|
||||
{
|
||||
title: "提交时间",
|
||||
dataIndex: "createdAt",
|
||||
render: (value: string) => new Date(value).toLocaleString("zh-CN"),
|
||||
},
|
||||
{
|
||||
title: "状态",
|
||||
dataIndex: "status",
|
||||
render: (value: string) => (
|
||||
<StatusTag
|
||||
tone={statusTones[value] ?? "neutral"}
|
||||
label={labels[value] ?? value}
|
||||
/>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: "操作",
|
||||
render: (_: unknown, item: AdminBooking) => (
|
||||
<Space>
|
||||
<Select
|
||||
size="small"
|
||||
value={item.status}
|
||||
onChange={(value) => update.mutate({ id: item.id, value: value as never })}
|
||||
options={statuses.map((value) => ({ value, label: labels[value] }))}
|
||||
/>
|
||||
<Button type="link" size="small" onClick={() => read.mutate(item.id)}>
|
||||
标记已读
|
||||
</Button>
|
||||
</Space>
|
||||
),
|
||||
},
|
||||
]}
|
||||
/>
|
||||
)}
|
||||
</Drawer>
|
||||
<Card
|
||||
<Drawer
|
||||
title="咨询详情"
|
||||
open={Boolean(selectedId)}
|
||||
onClose={() => setSelectedId(undefined)}
|
||||
loading={detail.isLoading}
|
||||
width={520}
|
||||
>
|
||||
{detail.data && (
|
||||
<Descriptions className="admin-descriptions" column={1} size="small">
|
||||
<Descriptions.Item label="编号">{detail.data.bookingNo}</Descriptions.Item>
|
||||
<Descriptions.Item label="联系人">{detail.data.customerName}</Descriptions.Item>
|
||||
<Descriptions.Item label="状态">
|
||||
{labels[detail.data.status] ?? detail.data.status}
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="提交时间">
|
||||
{new Date(detail.data.createdAt).toLocaleString("zh-CN")}
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="管理员备注">
|
||||
{detail.data.adminNote || "暂无"}
|
||||
</Descriptions.Item>
|
||||
</Descriptions>
|
||||
)}
|
||||
</Drawer>
|
||||
</AdminSection>
|
||||
<AdminSection
|
||||
title={`动态咨询提交${submissions.data ? `(${submissions.data.length})` : ""}`}
|
||||
style={{ marginTop: 24 }}
|
||||
description="按模板表单提交的咨询记录,字段随表单配置变化。"
|
||||
extra={
|
||||
<Button onClick={() => void submissions.refetch()} loading={submissions.isFetching}>
|
||||
刷新提交记录
|
||||
</Button>
|
||||
}
|
||||
>
|
||||
{submissions.isError && (
|
||||
<Card type="inner" style={{ marginBottom: 16 }}>
|
||||
动态咨询提交加载失败:
|
||||
{submissions.error instanceof Error ? submissions.error.message : "未知错误"}
|
||||
<Button type="link" onClick={() => void submissions.refetch()}>
|
||||
重试
|
||||
</Button>
|
||||
</Card>
|
||||
)}
|
||||
<Space style={{ marginBottom: 12 }}>
|
||||
{submissions.isError ? (
|
||||
<ErrorNote error={submissions.error} onRetry={() => void submissions.refetch()} />
|
||||
) : null}
|
||||
<Space
|
||||
className={`admin-offset-bottom-sm ${submissions.isError ? "admin-offset-top" : ""}`}
|
||||
>
|
||||
<Select
|
||||
allowClear
|
||||
placeholder="动态咨询状态"
|
||||
style={{ width: 140 }}
|
||||
className="admin-field-w-md"
|
||||
value={submissionStatus}
|
||||
onChange={setSubmissionStatus}
|
||||
options={inquiryStatuses.map((value) => ({ value, label: inquiryLabels[value] }))}
|
||||
/>
|
||||
</Space>
|
||||
<Table<InquirySubmission>
|
||||
rowKey="id"
|
||||
loading={submissions.isLoading}
|
||||
dataSource={(submissions.data ?? []).filter(
|
||||
(item) => !submissionStatus || item.status === submissionStatus,
|
||||
)}
|
||||
locale={{ emptyText: submissions.isLoading ? "加载中" : "暂无动态咨询提交" }}
|
||||
columns={[
|
||||
{ title: "表单", dataIndex: ["inquiryForm", "name"] },
|
||||
{
|
||||
title: "来源业务",
|
||||
dataIndex: ["offering", "name"],
|
||||
render: (value: string | null | undefined) => value || "品牌咨询",
|
||||
},
|
||||
{
|
||||
title: "状态",
|
||||
dataIndex: "status",
|
||||
render: (value: InquirySubmission["status"]) => (
|
||||
<Tag>{inquiryLabels[value] ?? value}</Tag>
|
||||
{submissions.isLoading && !submissions.data ? (
|
||||
<ListSkeleton rows={3} />
|
||||
) : (
|
||||
<Table<InquirySubmission>
|
||||
rowKey="id"
|
||||
dataSource={(submissions.data ?? []).filter(
|
||||
(item) => !submissionStatus || item.status === submissionStatus,
|
||||
)}
|
||||
locale={{
|
||||
emptyText: (
|
||||
<EmptyState
|
||||
compact
|
||||
title="暂无动态咨询提交"
|
||||
description="按模板表单提交的咨询会汇总在这里。"
|
||||
/>
|
||||
),
|
||||
},
|
||||
{ title: "版本", dataIndex: "formVersion", render: (value) => `v${value}` },
|
||||
{
|
||||
title: "提交时间",
|
||||
dataIndex: "createdAt",
|
||||
render: (value: string) => new Date(value).toLocaleString("zh-CN"),
|
||||
},
|
||||
{
|
||||
title: "内容",
|
||||
dataIndex: "values",
|
||||
render: (value: Record<string, unknown>) => {
|
||||
const entries = Object.entries(value ?? {});
|
||||
return entries.length
|
||||
? entries.map(([key, item]) => `${key}: ${String(item)}`).join(";")
|
||||
: "暂无内容";
|
||||
}}
|
||||
columns={[
|
||||
{ title: "表单", dataIndex: ["inquiryForm", "name"] },
|
||||
{
|
||||
title: "来源业务",
|
||||
dataIndex: ["offering", "name"],
|
||||
render: (value: string | null | undefined) => value || "品牌咨询",
|
||||
},
|
||||
},
|
||||
{
|
||||
title: "跟进",
|
||||
render: (_: unknown, item: InquirySubmission) => (
|
||||
<Space>
|
||||
<Button size="small" onClick={() => setSelectedSubmission(item)}>
|
||||
查看
|
||||
</Button>
|
||||
<Select
|
||||
size="small"
|
||||
value={item.status}
|
||||
options={inquiryStatuses.map((value) => ({
|
||||
value,
|
||||
label: inquiryLabels[value],
|
||||
}))}
|
||||
onChange={(value) => updateSubmission.mutate({ id: item.id, status: value })}
|
||||
{
|
||||
title: "状态",
|
||||
dataIndex: "status",
|
||||
render: (value: InquirySubmission["status"]) => (
|
||||
<StatusTag
|
||||
tone={statusTones[value] ?? "neutral"}
|
||||
label={inquiryLabels[value] ?? value}
|
||||
/>
|
||||
<Input
|
||||
size="small"
|
||||
placeholder="备注"
|
||||
defaultValue={item.adminNote ?? ""}
|
||||
onPressEnter={(event) =>
|
||||
updateSubmission.mutate({
|
||||
id: item.id,
|
||||
status: item.status,
|
||||
adminNote: event.currentTarget.value,
|
||||
})
|
||||
}
|
||||
/>
|
||||
</Space>
|
||||
),
|
||||
},
|
||||
]}
|
||||
/>
|
||||
),
|
||||
},
|
||||
{ title: "版本", dataIndex: "formVersion", render: (value) => `v${value}` },
|
||||
{
|
||||
title: "提交时间",
|
||||
dataIndex: "createdAt",
|
||||
render: (value: string) => new Date(value).toLocaleString("zh-CN"),
|
||||
},
|
||||
{
|
||||
title: "内容",
|
||||
dataIndex: "values",
|
||||
render: (value: Record<string, unknown>) => {
|
||||
const entries = Object.entries(value ?? {});
|
||||
return entries.length
|
||||
? entries.map(([key, item]) => `${key}: ${String(item)}`).join(";")
|
||||
: "暂无内容";
|
||||
},
|
||||
},
|
||||
{
|
||||
title: "跟进",
|
||||
render: (_: unknown, item: InquirySubmission) => (
|
||||
<Space>
|
||||
<Button type="link" size="small" onClick={() => setSelectedSubmission(item)}>
|
||||
查看
|
||||
</Button>
|
||||
<Select
|
||||
size="small"
|
||||
value={item.status}
|
||||
options={inquiryStatuses.map((value) => ({
|
||||
value,
|
||||
label: inquiryLabels[value],
|
||||
}))}
|
||||
onChange={(value) => updateSubmission.mutate({ id: item.id, status: value })}
|
||||
/>
|
||||
<Input
|
||||
size="small"
|
||||
placeholder="备注"
|
||||
defaultValue={item.adminNote ?? ""}
|
||||
onPressEnter={(event) =>
|
||||
updateSubmission.mutate({
|
||||
id: item.id,
|
||||
status: item.status,
|
||||
adminNote: event.currentTarget.value,
|
||||
})
|
||||
}
|
||||
/>
|
||||
</Space>
|
||||
),
|
||||
},
|
||||
]}
|
||||
/>
|
||||
)}
|
||||
<Drawer
|
||||
title="动态咨询详情"
|
||||
open={Boolean(selectedSubmission)}
|
||||
@@ -287,7 +326,7 @@ export function InquiriesPage() {
|
||||
width={520}
|
||||
>
|
||||
{selectedSubmission && (
|
||||
<Descriptions column={1} bordered size="small">
|
||||
<Descriptions className="admin-descriptions" column={1} size="small">
|
||||
<Descriptions.Item label="表单">
|
||||
{selectedSubmission.inquiryForm?.name || "品牌咨询"}
|
||||
</Descriptions.Item>
|
||||
@@ -314,7 +353,7 @@ export function InquiriesPage() {
|
||||
</Descriptions>
|
||||
)}
|
||||
</Drawer>
|
||||
</Card>
|
||||
</Card>
|
||||
</AdminSection>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -1,9 +1,11 @@
|
||||
import { Button, Card, Col, List, Progress, Row, Space, Statistic, Tag, Typography } from "antd";
|
||||
import { Button, Card, Col, Progress, Row } from "antd";
|
||||
import { useQueries, useQuery } from "@tanstack/react-query";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { createApiClient } from "../../lib/api.js";
|
||||
import { AdminPageHeader } from "../../components/AdminPageHeader.js";
|
||||
import { QueryState } from "../../components/QueryState.js";
|
||||
import { MetricCard } from "../../components/MetricCard.js";
|
||||
import { StatusTag } from "../../components/StatusTag.js";
|
||||
|
||||
export function OverviewPage() {
|
||||
const navigate = useNavigate();
|
||||
@@ -82,41 +84,32 @@ export function OverviewPage() {
|
||||
title="品牌概览"
|
||||
description="从这里检查品牌表达、信任内容和业务承接是否完整。"
|
||||
/>
|
||||
<Space direction="vertical" size={24} style={{ width: "100%" }}>
|
||||
<div className="admin-stack">
|
||||
<Card>
|
||||
<Typography.Title level={3} style={{ marginTop: 0 }}>
|
||||
{brand?.name || "未命名品牌"}
|
||||
</Typography.Title>
|
||||
<Typography.Paragraph type="secondary">
|
||||
{brand?.tagline || "还没有设置一句话定位"}
|
||||
</Typography.Paragraph>
|
||||
<Tag color="blue">
|
||||
当前模板:{workspace?.templateContent?.displayName ?? "尚未安装模板"}
|
||||
</Tag>
|
||||
<h2 className="admin-brand-title">{brand?.name || "未命名品牌"}</h2>
|
||||
<p className="admin-brand-tagline">{brand?.tagline || "还没有设置一句话定位"}</p>
|
||||
<StatusTag
|
||||
tone="info"
|
||||
label={`当前模板:${workspace?.templateContent?.displayName ?? "尚未安装模板"}`}
|
||||
/>
|
||||
</Card>
|
||||
<Row gutter={[16, 16]}>
|
||||
<Col xs={24} sm={12} lg={6}>
|
||||
<Card>
|
||||
<Statistic
|
||||
title="信任证明"
|
||||
value={trust?.filter((item) => item.isPublished).length ?? 0}
|
||||
suffix="条已发布"
|
||||
/>
|
||||
</Card>
|
||||
<Col xs={24} sm={8}>
|
||||
<MetricCard
|
||||
label="信任证明"
|
||||
value={trust?.filter((item) => item.isPublished).length ?? 0}
|
||||
suffix="条已发布"
|
||||
/>
|
||||
</Col>
|
||||
<Col xs={24} sm={12} lg={6}>
|
||||
<Card>
|
||||
<Statistic
|
||||
title="业务展示内容"
|
||||
value={offerings?.filter((item) => item.isEnabled).length ?? 0}
|
||||
suffix="项公开"
|
||||
/>
|
||||
</Card>
|
||||
<Col xs={24} sm={8}>
|
||||
<MetricCard
|
||||
label="业务展示内容"
|
||||
value={offerings?.filter((item) => item.isEnabled).length ?? 0}
|
||||
suffix="项公开"
|
||||
/>
|
||||
</Col>
|
||||
<Col xs={24} sm={12} lg={6}>
|
||||
<Card>
|
||||
<Statistic title="咨询提交" value={submissions?.length ?? 0} suffix="条" />
|
||||
</Card>
|
||||
<Col xs={24} sm={8}>
|
||||
<MetricCard label="咨询提交" value={submissions?.length ?? 0} suffix="条" />
|
||||
</Col>
|
||||
</Row>
|
||||
<Row gutter={[16, 16]}>
|
||||
@@ -133,63 +126,57 @@ export function OverviewPage() {
|
||||
percent={completionPercent}
|
||||
status={readiness.data?.ready ? "success" : "active"}
|
||||
/>
|
||||
<Typography.Paragraph type="secondary">
|
||||
<p className="admin-section-description admin-offset-top-sm admin-offset-bottom">
|
||||
{readiness.data?.ready
|
||||
? "当前草稿已满足发布条件,可以进入发布页上线。"
|
||||
: `还有 ${incompleteChecks.length} 项需要完善,完成后才能发布。`}
|
||||
</Typography.Paragraph>
|
||||
</p>
|
||||
{incompleteChecks.length > 0 && (
|
||||
<List
|
||||
size="small"
|
||||
dataSource={incompleteChecks.slice(0, 4)}
|
||||
renderItem={(item) => (
|
||||
<List.Item
|
||||
actions={[
|
||||
<Button
|
||||
key={item.key}
|
||||
type="link"
|
||||
size="small"
|
||||
onClick={() => navigate(item.destination ?? "/admin/publication")}
|
||||
>
|
||||
去处理
|
||||
</Button>,
|
||||
]}
|
||||
>
|
||||
{item.label}
|
||||
</List.Item>
|
||||
)}
|
||||
/>
|
||||
<ul className="admin-list">
|
||||
{incompleteChecks.slice(0, 4).map((item) => (
|
||||
<li key={item.key} className="admin-row">
|
||||
<span className="admin-row-title">{item.label}</span>
|
||||
<Button
|
||||
type="link"
|
||||
size="small"
|
||||
onClick={() => navigate(item.destination ?? "/admin/publication")}
|
||||
>
|
||||
去处理
|
||||
</Button>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
</Card>
|
||||
</Col>
|
||||
<Col xs={24} lg={12}>
|
||||
<Card title="品牌内容检查">
|
||||
<List
|
||||
dataSource={checks}
|
||||
renderItem={(item) => (
|
||||
<List.Item>
|
||||
<Space>
|
||||
<Tag color={item.passed ? "success" : "default"}>
|
||||
{item.passed ? "已完成" : "待完善"}
|
||||
</Tag>
|
||||
<span>{item.label}</span>
|
||||
{!item.passed && (
|
||||
<Button
|
||||
type="link"
|
||||
size="small"
|
||||
onClick={() => navigate(item.destination ?? "/admin/publication")}
|
||||
>
|
||||
去处理
|
||||
</Button>
|
||||
)}
|
||||
</Space>
|
||||
</List.Item>
|
||||
)}
|
||||
/>
|
||||
<ul className="admin-list">
|
||||
{checks.map((item) => (
|
||||
<li key={item.key} className="admin-row">
|
||||
<div className="admin-row-line">
|
||||
<StatusTag
|
||||
tone={item.passed ? "success" : "neutral"}
|
||||
label={item.passed ? "已完成" : "待完善"}
|
||||
/>
|
||||
<span className="admin-row-title">{item.label}</span>
|
||||
</div>
|
||||
{!item.passed ? (
|
||||
<Button
|
||||
type="link"
|
||||
size="small"
|
||||
onClick={() => navigate(item.destination ?? "/admin/publication")}
|
||||
>
|
||||
去处理
|
||||
</Button>
|
||||
) : null}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</Card>
|
||||
</Col>
|
||||
</Row>
|
||||
</Space>
|
||||
</div>
|
||||
</QueryState>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,163 @@
|
||||
import { useEffect, useRef } from "react";
|
||||
import { Button, Card, Collapse, Flex, Space, Tooltip, Typography } from "antd";
|
||||
import type { MiniAppReleaseTask } from "@personal-brand/api-client";
|
||||
import { ErrorNote } from "../../components/QueryState.js";
|
||||
import { StatusTag } from "../../components/StatusTag.js";
|
||||
import type { StatusTone } from "../../components/StatusTag.js";
|
||||
|
||||
type ReleaseStatus = MiniAppReleaseTask["status"];
|
||||
|
||||
const STALE_BUILDING_MS = 15 * 60 * 1000;
|
||||
|
||||
function isStaleBuilding(task: MiniAppReleaseTask): boolean {
|
||||
if (task.buildStatus !== "building") return false;
|
||||
const updatedAt = new Date(task.updatedAt).getTime();
|
||||
return !Number.isNaN(updatedAt) && Date.now() - updatedAt >= STALE_BUILDING_MS;
|
||||
}
|
||||
|
||||
const statusView: Record<ReleaseStatus, { label: string; tone: StatusTone; hint: string }> = {
|
||||
built: { label: "待上传", tone: "neutral", hint: "代码已构建,可上传到微信。" },
|
||||
uploaded: { label: "已上传微信", tone: "info", hint: "请在微信后台上传体验版并提交审核。" },
|
||||
under_review: {
|
||||
label: "审核中",
|
||||
tone: "warning",
|
||||
hint: "等待微信审核结果,通过后回到本页标记。",
|
||||
},
|
||||
approved: { label: "审核通过", tone: "success", hint: "审核已通过,确认无误后标记为已发布。" },
|
||||
published: { label: "已发布", tone: "success", hint: "该版本已发布,可继续编辑内容后再次上传。" },
|
||||
rejected: { label: "已驳回", tone: "error", hint: "微信驳回后需修改内容并重新构建上传。" },
|
||||
failed: { label: "失败", tone: "error", hint: "上次构建或上传失败,可直接重试。" },
|
||||
};
|
||||
|
||||
function formatTime(value: string): string {
|
||||
const date = new Date(value);
|
||||
if (Number.isNaN(date.getTime())) return value;
|
||||
return date.toLocaleString("zh-CN", { hour12: false });
|
||||
}
|
||||
|
||||
function formatLogTime(value: string): string {
|
||||
const date = new Date(value);
|
||||
if (Number.isNaN(date.getTime())) return "";
|
||||
return date.toLocaleTimeString("zh-CN", { hour12: false });
|
||||
}
|
||||
|
||||
export function MiniAppReleaseCard({
|
||||
task,
|
||||
uploading,
|
||||
onUpload,
|
||||
onStatusChange,
|
||||
}: {
|
||||
task: MiniAppReleaseTask;
|
||||
uploading: boolean;
|
||||
onUpload: () => void;
|
||||
onStatusChange: (status: ReleaseStatus) => void;
|
||||
}) {
|
||||
const logRef = useRef<HTMLPreElement>(null);
|
||||
const logs = task.buildLogs ?? [];
|
||||
const status = statusView[task.status];
|
||||
const building = task.buildStatus === "building";
|
||||
const staleBuilding = isStaleBuilding(task);
|
||||
|
||||
useEffect(() => {
|
||||
if (!building) return;
|
||||
const node = logRef.current;
|
||||
if (node) node.scrollTop = node.scrollHeight;
|
||||
}, [building, logs.length]);
|
||||
|
||||
const actions = (
|
||||
<Space wrap>
|
||||
{(task.status === "built" || task.status === "failed" || staleBuilding) && (
|
||||
<Button
|
||||
type={task.status === "built" && !staleBuilding ? "primary" : "default"}
|
||||
size="small"
|
||||
loading={uploading}
|
||||
onClick={onUpload}
|
||||
>
|
||||
{task.status === "built" && !staleBuilding ? "上传微信" : "重试上传微信"}
|
||||
</Button>
|
||||
)}
|
||||
{task.status === "uploaded" && (
|
||||
<Button size="small" onClick={() => onStatusChange("under_review")}>
|
||||
标记提交审核
|
||||
</Button>
|
||||
)}
|
||||
{task.status === "under_review" && (
|
||||
<>
|
||||
<Button size="small" onClick={() => onStatusChange("approved")}>
|
||||
审核通过
|
||||
</Button>
|
||||
<Button size="small" danger onClick={() => onStatusChange("rejected")}>
|
||||
审核驳回
|
||||
</Button>
|
||||
</>
|
||||
)}
|
||||
{task.status === "approved" && (
|
||||
<Button size="small" type="primary" onClick={() => onStatusChange("published")}>
|
||||
标记已发布
|
||||
</Button>
|
||||
)}
|
||||
</Space>
|
||||
);
|
||||
|
||||
return (
|
||||
<Card size="small" styles={{ body: { padding: 16 } }}>
|
||||
<Flex justify="space-between" align="flex-start" gap={12} wrap>
|
||||
<Space direction="vertical" size={4}>
|
||||
<Space wrap size={8} align="center">
|
||||
<Typography.Text strong>品牌内容 v{task.version}</Typography.Text>
|
||||
<StatusTag label={status.label} tone={status.tone} />
|
||||
{building && (
|
||||
<StatusTag tone="warning" label={staleBuilding ? "构建已中断" : "构建中"} />
|
||||
)}
|
||||
{task.weappUploadId && (
|
||||
<Typography.Text type="secondary">微信版本 {task.weappUploadId}</Typography.Text>
|
||||
)}
|
||||
</Space>
|
||||
<span className="admin-text-xs">
|
||||
{staleBuilding ? "超过 15 分钟没有新的构建输出,可能已中断;可直接重试。" : status.hint}
|
||||
</span>
|
||||
<Tooltip title={`创建于 ${formatTime(task.createdAt)}`}>
|
||||
<span className="admin-text-xs-quiet">更新于 {formatTime(task.updatedAt)}</span>
|
||||
</Tooltip>
|
||||
</Space>
|
||||
{actions}
|
||||
</Flex>
|
||||
|
||||
{task.error && (
|
||||
<div className="admin-offset-top-md">
|
||||
<ErrorNote error={new Error(task.error)} />
|
||||
</div>
|
||||
)}
|
||||
|
||||
{logs.length > 0 && (
|
||||
<Collapse
|
||||
ghost
|
||||
size="small"
|
||||
className="admin-offset-top-sm"
|
||||
{...(building || task.buildStatus === "failed" ? { defaultActiveKey: ["logs"] } : {})}
|
||||
items={[
|
||||
{
|
||||
key: "logs",
|
||||
label: <span className="admin-text-xs">构建日志({logs.length} 行)</span>,
|
||||
children: (
|
||||
<pre ref={logRef} className="admin-log">
|
||||
{logs.map((log, index) => (
|
||||
<div
|
||||
key={`${log.at}-${index}`}
|
||||
className="admin-log__line"
|
||||
data-stream={log.stream}
|
||||
>
|
||||
<span className="admin-log__time">{formatLogTime(log.at)}</span>
|
||||
{" "}
|
||||
{log.message}
|
||||
</div>
|
||||
))}
|
||||
</pre>
|
||||
),
|
||||
},
|
||||
]}
|
||||
/>
|
||||
)}
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
import { Alert, Button, Form, Input, Space } from "antd";
|
||||
import type { FormInstance } from "antd";
|
||||
import type { MiniAppReleaseSettings } from "@personal-brand/api-client";
|
||||
import { AdminSection } from "../../components/AdminSection.js";
|
||||
import { MutationError } from "../../components/QueryState.js";
|
||||
import { StatusTag } from "../../components/StatusTag.js";
|
||||
|
||||
export type MiniAppSettingsValues = {
|
||||
appId: string;
|
||||
apiBaseUrl: string;
|
||||
privateKey?: string;
|
||||
};
|
||||
|
||||
interface MiniAppSettingsTabProps {
|
||||
form: FormInstance<MiniAppSettingsValues>;
|
||||
settings: MiniAppReleaseSettings | undefined;
|
||||
saving: boolean;
|
||||
error?: unknown;
|
||||
onSave: (values: MiniAppSettingsValues) => void;
|
||||
}
|
||||
|
||||
export function MiniAppSettingsTab({
|
||||
form,
|
||||
settings,
|
||||
saving,
|
||||
error,
|
||||
onSave,
|
||||
}: MiniAppSettingsTabProps) {
|
||||
return (
|
||||
<div className="admin-stack admin-stack-lg">
|
||||
<AdminSection
|
||||
title="小程序上传配置"
|
||||
description="AppID 用于服务端调用微信官方上传工具;上传私钥保存前会使用 AES-256-GCM 加密。"
|
||||
>
|
||||
{settings?.buildError ? (
|
||||
<Alert
|
||||
type="warning"
|
||||
showIcon
|
||||
className="admin-offset-bottom"
|
||||
message="小程序构建参数未就绪"
|
||||
description={settings.buildError}
|
||||
/>
|
||||
) : (
|
||||
<Alert
|
||||
type="info"
|
||||
showIcon
|
||||
className="admin-offset-bottom"
|
||||
message={`请求域名 ${settings?.requestDomain ?? "未确认"}`}
|
||||
description="该域名在构建时写入小程序包,必须与微信后台“开发设置 → 服务器域名 → request 合法域名”一致;不一致会导致小程序打开即加载失败。"
|
||||
/>
|
||||
)}
|
||||
<Form form={form} layout="vertical" onFinish={onSave}>
|
||||
<Form.Item
|
||||
name="appId"
|
||||
label="微信 AppID"
|
||||
rules={[{ required: true, message: "请输入微信 AppID" }]}
|
||||
>
|
||||
<Input maxLength={100} />
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
name="apiBaseUrl"
|
||||
label="小程序请求地址"
|
||||
rules={[
|
||||
{ required: true, message: "请输入小程序请求地址" },
|
||||
{
|
||||
validator: (_rule, value: string) =>
|
||||
!value || /^https:\/\/[^/]+/.test(value)
|
||||
? Promise.resolve()
|
||||
: Promise.reject(
|
||||
new Error(
|
||||
"公网地址必须以 https:// 开头,例如 https://wechat.app.que01.top/api",
|
||||
),
|
||||
),
|
||||
},
|
||||
]}
|
||||
extra="构建时写入小程序包,必须与微信后台“开发设置 → 服务器域名 → request 合法域名”一致。修改后需重新构建并上传代码才生效。"
|
||||
>
|
||||
<Input maxLength={200} placeholder="https://wechat.app.que01.top/api" />
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
name="privateKey"
|
||||
label="上传私钥"
|
||||
help={
|
||||
settings?.hasStoredCredentials
|
||||
? "已加密保存。留空保持现有私钥,输入新值可替换。"
|
||||
: "粘贴微信开发者工具导出的 private.<appid>.key 全文,必须保留换行。"
|
||||
}
|
||||
>
|
||||
<Input.TextArea
|
||||
rows={5}
|
||||
autoComplete="off"
|
||||
spellCheck={false}
|
||||
placeholder={"-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----"}
|
||||
className="admin-code-input"
|
||||
/>
|
||||
</Form.Item>
|
||||
<Space>
|
||||
<Button type="primary" loading={saving} htmlType="submit">
|
||||
保存上传配置
|
||||
</Button>
|
||||
{settings?.hasStoredCredentials ? (
|
||||
<StatusTag tone="success" label="已加密保存上传凭据" />
|
||||
) : (
|
||||
<StatusTag tone="warning" label="未配置上传私钥" />
|
||||
)}
|
||||
</Space>
|
||||
<MutationError error={error} />
|
||||
</Form>
|
||||
</AdminSection>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,24 +1,31 @@
|
||||
import { useState } from "react";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import { useQueryClient } from "@tanstack/react-query";
|
||||
import {
|
||||
Alert,
|
||||
Button,
|
||||
Divider,
|
||||
Empty,
|
||||
Input,
|
||||
Modal,
|
||||
Form,
|
||||
Select,
|
||||
Space,
|
||||
Spin,
|
||||
Tag,
|
||||
Tabs,
|
||||
Typography,
|
||||
message,
|
||||
} from "antd";
|
||||
import type { BrandTemplateKey } from "@personal-brand/api-client";
|
||||
import { createApiClient } from "../../lib/api.js";
|
||||
import { AdminPageHeader } from "../../components/AdminPageHeader.js";
|
||||
import { MutationError, QueryState } from "../../components/QueryState.js";
|
||||
import { AdminSection } from "../../components/AdminSection.js";
|
||||
import { EmptyState } from "../../components/EmptyState.js";
|
||||
import { ErrorNote, MutationError, QueryState } from "../../components/QueryState.js";
|
||||
import { StatusTag, statusLabel } from "../../components/StatusTag.js";
|
||||
import { MiniAppReleaseCard } from "./MiniAppReleaseCard.js";
|
||||
import { MiniAppSettingsTab, type MiniAppSettingsValues } from "./MiniAppSettingsTab.js";
|
||||
import { usePublicationQueries } from "./use-publication-queries.js";
|
||||
import { usePublicationMutations } from "./use-publication-mutations.js";
|
||||
|
||||
const client = createApiClient();
|
||||
|
||||
@@ -39,38 +46,32 @@ export function PublicationPage({ canManageTemplate }: { canManageTemplate: bool
|
||||
const [confirmAction, setConfirmAction] = useState<"publish" | "revoke" | null>(null);
|
||||
const [rollbackVersion, setRollbackVersion] = useState<number | null>(null);
|
||||
const [note, setNote] = useState("");
|
||||
const brand = useQuery({
|
||||
queryKey: ["publication-brand"],
|
||||
queryFn: () => client.getAdminBrand(),
|
||||
});
|
||||
const workspace = useQuery({
|
||||
queryKey: ["publication-workspace"],
|
||||
queryFn: () => client.getAdminWorkspace(),
|
||||
});
|
||||
const catalog = useQuery({
|
||||
queryKey: ["publication-catalog"],
|
||||
queryFn: () => client.listPublicTemplates(),
|
||||
});
|
||||
const sample = useQuery({
|
||||
queryKey: ["publication-sample"],
|
||||
queryFn: () => client.previewAdminSampleContent(),
|
||||
enabled: Boolean(workspace.data),
|
||||
});
|
||||
const readiness = useQuery({
|
||||
queryKey: ["publication-readiness"],
|
||||
queryFn: () => client.getAdminReleaseReadiness(),
|
||||
});
|
||||
const releases = useQuery({
|
||||
queryKey: ["publication-releases"],
|
||||
queryFn: () => client.listAdminReleases(),
|
||||
});
|
||||
const [activeTab, setActiveTab] = useState("content");
|
||||
const [miniAppSettingsForm] = Form.useForm<MiniAppSettingsValues>();
|
||||
const queries = usePublicationQueries(miniAppSettingsForm);
|
||||
const {
|
||||
brand,
|
||||
workspace,
|
||||
catalog,
|
||||
sample,
|
||||
readiness,
|
||||
releases,
|
||||
miniAppReleases,
|
||||
miniAppSettings,
|
||||
templatePreview,
|
||||
loading,
|
||||
error,
|
||||
retry,
|
||||
} = queries;
|
||||
const refresh = () => {
|
||||
for (const key of [
|
||||
"publication-brand",
|
||||
"publication-workspace",
|
||||
"publication-sample",
|
||||
"publication-readiness",
|
||||
"publication-template-preview",
|
||||
"publication-releases",
|
||||
"publication-miniapp-releases",
|
||||
"admin-shell-brand",
|
||||
"admin-workspace",
|
||||
"public-runtime-workspace",
|
||||
@@ -78,83 +79,42 @@ export function PublicationPage({ canManageTemplate }: { canManageTemplate: bool
|
||||
void queryClient.invalidateQueries({ queryKey: [key] });
|
||||
}
|
||||
};
|
||||
const install = useMutation({
|
||||
mutationFn: (key: BrandTemplateKey) => client.installAdminTemplate(key),
|
||||
onSuccess: () => {
|
||||
setIndustryTarget(null);
|
||||
message.success("行业模板已安装");
|
||||
refresh();
|
||||
},
|
||||
const mutations = usePublicationMutations({
|
||||
refresh,
|
||||
brandConfig: brand.data?.config,
|
||||
onInstallClose: () => setIndustryTarget(null),
|
||||
onPublishClose: () => setConfirmAction(null),
|
||||
onNoteClear: () => setNote(""),
|
||||
onRollbackClose: () => setRollbackVersion(null),
|
||||
});
|
||||
const selectVisual = useMutation({
|
||||
mutationFn: (key: string) =>
|
||||
client.updateAdminBrand({
|
||||
config: { ...(brand.data?.config ?? {}), visualTemplateKey: key },
|
||||
}),
|
||||
onSuccess: () => {
|
||||
message.success("视觉模板已保存到草稿");
|
||||
refresh();
|
||||
},
|
||||
});
|
||||
const importSample = useMutation({
|
||||
mutationFn: () => client.importAdminSampleContent(),
|
||||
onSuccess: ({ counts }) => {
|
||||
message.success(
|
||||
counts.inquiryForms
|
||||
? "示例内容和客户咨询表单已导入草稿"
|
||||
: "示例内容已导入草稿,现有客户咨询表单已保留",
|
||||
);
|
||||
refresh();
|
||||
},
|
||||
});
|
||||
const publish = useMutation({
|
||||
mutationFn: () => client.publishAdminRelease(note.trim() || undefined),
|
||||
onSuccess: () => {
|
||||
setConfirmAction(null);
|
||||
setNote("");
|
||||
message.success("品牌已发布");
|
||||
refresh();
|
||||
},
|
||||
});
|
||||
const revoke = useMutation({
|
||||
mutationFn: () => client.revokeAdminRelease(),
|
||||
onSuccess: () => {
|
||||
setConfirmAction(null);
|
||||
message.success("品牌已撤回,小程序将显示未发布状态");
|
||||
refresh();
|
||||
},
|
||||
});
|
||||
const rollback = useMutation({
|
||||
mutationFn: (version: number) => client.rollbackAdminRelease(version),
|
||||
onSuccess: () => {
|
||||
setRollbackVersion(null);
|
||||
message.success("历史版本已重新发布");
|
||||
refresh();
|
||||
},
|
||||
});
|
||||
const loading = [brand, workspace, catalog, readiness, releases].some((query) => query.isLoading);
|
||||
const error = [brand, workspace, catalog, readiness, releases].find(
|
||||
(query) => query.isError,
|
||||
)?.error;
|
||||
const retry = () => {
|
||||
void brand.refetch();
|
||||
void workspace.refetch();
|
||||
void catalog.refetch();
|
||||
void readiness.refetch();
|
||||
void releases.refetch();
|
||||
};
|
||||
const {
|
||||
install,
|
||||
upgradeTemplate,
|
||||
rollbackTemplate,
|
||||
selectVisual,
|
||||
importSample,
|
||||
publish,
|
||||
revoke,
|
||||
rollback,
|
||||
uploadLatestMiniAppRelease,
|
||||
saveMiniAppSettings,
|
||||
uploadMiniAppRelease,
|
||||
updateMiniAppStatus,
|
||||
} = mutations;
|
||||
const industryKey =
|
||||
workspace.data?.installations[0]?.templateKey ??
|
||||
workspace.data?.brand?.templateKey ??
|
||||
brand.data?.templateKey ??
|
||||
"personal";
|
||||
const visuals = (catalog.data?.visuals ?? []).filter((item) =>
|
||||
item.supportedIndustryTemplates.includes(industryKey),
|
||||
catalog.data?.industries[0]?.key ??
|
||||
null;
|
||||
const visuals = (catalog.data?.visuals ?? []).filter(
|
||||
(item) =>
|
||||
typeof industryKey === "string" && item.supportedIndustryTemplates.includes(industryKey),
|
||||
);
|
||||
const visualKey =
|
||||
typeof brand.data?.config?.visualTemplateKey === "string"
|
||||
? brand.data.config.visualTemplateKey
|
||||
: "linjing-editorial";
|
||||
: (visuals[0]?.key ?? null);
|
||||
const currentRelease = releases.data?.find((item) => item.status === "published");
|
||||
const publishedHistory = (releases.data ?? []).filter(
|
||||
(item) => item.status === "published" || item.status === "superseded",
|
||||
@@ -166,187 +126,428 @@ export function PublicationPage({ canManageTemplate }: { canManageTemplate: bool
|
||||
isEnabled: boolean;
|
||||
}>;
|
||||
|
||||
const contentTab = null;
|
||||
const miniAppSettingsTab = (
|
||||
<div className="admin-stack admin-stack-lg">
|
||||
<AdminSection
|
||||
title="小程序上传配置"
|
||||
description="AppID 用于服务端调用微信官方上传工具;上传私钥保存前会使用 AES-256-GCM 加密。"
|
||||
>
|
||||
{miniAppSettings.data?.buildError ? (
|
||||
<Alert
|
||||
type="warning"
|
||||
showIcon
|
||||
className="admin-offset-bottom"
|
||||
message="小程序构建参数未就绪"
|
||||
description={miniAppSettings.data.buildError}
|
||||
/>
|
||||
) : (
|
||||
<Alert
|
||||
type="info"
|
||||
showIcon
|
||||
className="admin-offset-bottom"
|
||||
message={`请求域名 ${miniAppSettings.data?.requestDomain ?? "未确认"}`}
|
||||
description="该域名在构建时写入小程序包,必须与微信后台“开发设置 → 服务器域名 → request 合法域名”一致;不一致会导致小程序打开即加载失败。"
|
||||
/>
|
||||
)}
|
||||
<Form
|
||||
form={miniAppSettingsForm}
|
||||
layout="vertical"
|
||||
onFinish={(values) => saveMiniAppSettings.mutate(values)}
|
||||
>
|
||||
<Form.Item
|
||||
name="appId"
|
||||
label="微信 AppID"
|
||||
rules={[{ required: true, message: "请输入微信 AppID" }]}
|
||||
>
|
||||
<Input maxLength={100} />
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
name="apiBaseUrl"
|
||||
label="小程序请求地址"
|
||||
rules={[
|
||||
{ required: true, message: "请输入小程序请求地址" },
|
||||
{
|
||||
validator: (_rule, value: string) =>
|
||||
!value || /^https:\/\/[^/]+/.test(value)
|
||||
? Promise.resolve()
|
||||
: Promise.reject(
|
||||
new Error(
|
||||
"公网地址必须以 https:// 开头,例如 https://wechat.app.que01.top/api",
|
||||
),
|
||||
),
|
||||
},
|
||||
]}
|
||||
extra="构建时写入小程序包,必须与微信后台“开发设置 → 服务器域名 → request 合法域名”一致。修改后需重新构建并上传代码才生效。"
|
||||
>
|
||||
<Input maxLength={200} placeholder="https://wechat.app.que01.top/api" />
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
name="privateKey"
|
||||
label="上传私钥"
|
||||
help={
|
||||
miniAppSettings.data?.hasStoredCredentials
|
||||
? "已加密保存。留空保持现有私钥,输入新值可替换。"
|
||||
: "粘贴微信开发者工具导出的 private.<appid>.key 全文,必须保留换行。"
|
||||
}
|
||||
>
|
||||
<Input.TextArea
|
||||
rows={5}
|
||||
autoComplete="off"
|
||||
spellCheck={false}
|
||||
placeholder={"-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----"}
|
||||
className="admin-code-input"
|
||||
/>
|
||||
</Form.Item>
|
||||
<Space>
|
||||
<Button type="primary" loading={saveMiniAppSettings.isPending} htmlType="submit">
|
||||
保存上传配置
|
||||
</Button>
|
||||
{miniAppSettings.data?.hasStoredCredentials ? (
|
||||
<StatusTag tone="success" label="已加密保存上传凭据" />
|
||||
) : (
|
||||
<StatusTag tone="warning" label="未配置上传私钥" />
|
||||
)}
|
||||
</Space>
|
||||
<MutationError error={saveMiniAppSettings.error} />
|
||||
</Form>
|
||||
</AdminSection>
|
||||
</div>
|
||||
);
|
||||
|
||||
return (
|
||||
<QueryState loading={loading} error={error} onRetry={retry}>
|
||||
<AdminPageHeader
|
||||
title="配置与发布"
|
||||
description="编辑内容不会立即影响小程序;确认后统一发布当前品牌。"
|
||||
/>
|
||||
<Space direction="vertical" size={24} style={{ width: "100%" }}>
|
||||
<section>
|
||||
<Typography.Title level={4}>1. 选择表达方式</Typography.Title>
|
||||
<Space wrap>
|
||||
<Select
|
||||
aria-label="行业模板"
|
||||
style={{ width: 220 }}
|
||||
value={industryKey}
|
||||
disabled={!canManageTemplate || Boolean(workspace.data?.installations.length)}
|
||||
options={(catalog.data?.industries ?? []).map((item) => ({
|
||||
value: item.key,
|
||||
label: item.name,
|
||||
}))}
|
||||
onChange={(key: BrandTemplateKey) => setIndustryTarget(key)}
|
||||
/>
|
||||
<Select
|
||||
aria-label="视觉模板"
|
||||
style={{ width: 220 }}
|
||||
value={visualKey}
|
||||
disabled={!canManageTemplate}
|
||||
loading={selectVisual.isPending}
|
||||
options={visuals.map((item) => ({ value: item.key, label: item.name }))}
|
||||
onChange={(key) => selectVisual.mutate(key)}
|
||||
/>
|
||||
{canManageTemplate && (
|
||||
<Button onClick={() => navigate("/admin/workspace")}>高级模板设置</Button>
|
||||
)}
|
||||
</Space>
|
||||
{workspace.data?.installations.length ? (
|
||||
<Typography.Paragraph type="secondary" style={{ marginTop: 8 }}>
|
||||
当前品牌已安装主模板。模板版本与升级在高级设置中管理。
|
||||
</Typography.Paragraph>
|
||||
) : null}
|
||||
<MutationError error={install.error || selectVisual.error} />
|
||||
<Divider />
|
||||
<Space wrap>
|
||||
<Typography.Text>示例内容</Typography.Text>
|
||||
{sample.isLoading && <Spin size="small" />}
|
||||
{sample.data && (
|
||||
<Tag color={sample.data.alreadyImported ? "green" : "blue"}>
|
||||
{sample.data.alreadyImported ? "已导入" : "可导入"}
|
||||
</Tag>
|
||||
)}
|
||||
<Button
|
||||
disabled={!canManageTemplate || !sample.data || sample.data.alreadyImported}
|
||||
loading={importSample.isPending}
|
||||
onClick={() => importSample.mutate()}
|
||||
>
|
||||
导入示例内容
|
||||
</Button>
|
||||
{sample.isError && <Button onClick={() => void sample.refetch()}>重试</Button>}
|
||||
</Space>
|
||||
{sample.isError && (
|
||||
<Alert
|
||||
type="error"
|
||||
message={sample.error instanceof Error ? sample.error.message : "示例内容加载失败"}
|
||||
showIcon
|
||||
style={{ marginTop: 8 }}
|
||||
/>
|
||||
)}
|
||||
{sample.data && !sample.data.alreadyImported && (
|
||||
<Typography.Paragraph type="secondary" style={{ marginTop: 8 }}>
|
||||
将向草稿添加{" "}
|
||||
{Object.entries(sample.data.counts)
|
||||
.map(([key, count]) => `${key} ${count} 项`)
|
||||
.join("、")}
|
||||
;发布前请替换示例文案和图片。
|
||||
</Typography.Paragraph>
|
||||
)}
|
||||
<MutationError error={importSample.error} />
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<Typography.Title level={4}>2. 核对草稿内容</Typography.Title>
|
||||
<Typography.Paragraph type="secondary">
|
||||
此处核对的是待发布内容,不是小程序视觉预览。
|
||||
</Typography.Paragraph>
|
||||
<Space direction="vertical" style={{ width: "100%" }}>
|
||||
<Typography.Text strong>{brand.data?.name || "未命名品牌"}</Typography.Text>
|
||||
<Typography.Text>{brand.data?.tagline || "尚未填写品牌定位"}</Typography.Text>
|
||||
<Typography.Text>
|
||||
已启用业务项:{draftOfferings.map((item) => item.name).join("、") || "无"}
|
||||
</Typography.Text>
|
||||
<Typography.Text>
|
||||
已启用咨询表单:
|
||||
{draftForms
|
||||
.filter((item) => item.isEnabled)
|
||||
.map((item) => item.name)
|
||||
.join("、") || "无"}
|
||||
</Typography.Text>
|
||||
<Tabs
|
||||
activeKey={activeTab}
|
||||
onChange={setActiveTab}
|
||||
items={[
|
||||
{
|
||||
key: "content",
|
||||
label: "内容发布",
|
||||
children: contentTab,
|
||||
},
|
||||
{ key: "miniapp", label: "小程序发布", children: null },
|
||||
{
|
||||
key: "settings",
|
||||
label: "小程序配置",
|
||||
children:
|
||||
activeTab === "settings" ? (
|
||||
<MiniAppSettingsTab
|
||||
form={miniAppSettingsForm}
|
||||
settings={miniAppSettings.data}
|
||||
saving={saveMiniAppSettings.isPending}
|
||||
error={saveMiniAppSettings.error}
|
||||
onSave={(values) => saveMiniAppSettings.mutate(values)}
|
||||
/>
|
||||
) : null,
|
||||
},
|
||||
]}
|
||||
/>
|
||||
{activeTab === "content" && (
|
||||
<div className="admin-stack">
|
||||
<AdminSection
|
||||
title="选择表达方式"
|
||||
description="行业模板决定内容结构,视觉模板决定小程序的排版风格。"
|
||||
>
|
||||
<Space wrap>
|
||||
<Select
|
||||
aria-label="行业模板"
|
||||
className="admin-field-w-xl"
|
||||
value={industryKey}
|
||||
disabled={!canManageTemplate || Boolean(workspace.data?.installations.length)}
|
||||
options={(catalog.data?.industries ?? []).map((item) => ({
|
||||
value: item.key,
|
||||
label: item.name,
|
||||
}))}
|
||||
onChange={(key: BrandTemplateKey) => setIndustryTarget(key)}
|
||||
/>
|
||||
<Select
|
||||
aria-label="视觉模板"
|
||||
className="admin-field-w-xl"
|
||||
value={visualKey}
|
||||
disabled={!canManageTemplate}
|
||||
loading={selectVisual.isPending}
|
||||
options={visuals.map((item) => ({ value: item.key, label: item.name }))}
|
||||
onChange={(key) => selectVisual.mutate(key)}
|
||||
/>
|
||||
</Space>
|
||||
{industryKey ? (
|
||||
<div className="admin-offset-top-sm">
|
||||
<Space wrap>
|
||||
<StatusTag
|
||||
tone="neutral"
|
||||
label={`当前版本 ${templatePreview.data?.currentVersion ?? "加载中"}`}
|
||||
/>
|
||||
<StatusTag
|
||||
tone="info"
|
||||
label={`最新版本 ${templatePreview.data?.latestVersion ?? "加载中"}`}
|
||||
/>
|
||||
{templatePreview.data?.canUpgrade ? (
|
||||
<Button
|
||||
type="primary"
|
||||
size="small"
|
||||
disabled={!canManageTemplate}
|
||||
loading={upgradeTemplate.isPending}
|
||||
onClick={() => upgradeTemplate.mutate()}
|
||||
>
|
||||
升级模板
|
||||
</Button>
|
||||
) : (
|
||||
<StatusTag tone="success" label="已是最新版本" />
|
||||
)}
|
||||
{templatePreview.data?.canRollback ? (
|
||||
<Button
|
||||
danger
|
||||
size="small"
|
||||
disabled={!canManageTemplate}
|
||||
loading={rollbackTemplate.isPending}
|
||||
onClick={() => rollbackTemplate.mutate()}
|
||||
>
|
||||
回滚到上一版
|
||||
</Button>
|
||||
) : null}
|
||||
</Space>
|
||||
<p className="admin-section-description admin-offset-top-sm">
|
||||
行业模板随品牌身份固定,只能升级版本、不能更换行业;升级只补充字段与模块,不覆盖已有内容。视觉模板只替换排版风格。
|
||||
</p>
|
||||
<MutationError
|
||||
error={templatePreview.error || upgradeTemplate.error || rollbackTemplate.error}
|
||||
/>
|
||||
</div>
|
||||
) : null}
|
||||
<MutationError error={install.error || selectVisual.error} />
|
||||
<Divider className="admin-divider" />
|
||||
<Space wrap>
|
||||
<Typography.Text>示例内容</Typography.Text>
|
||||
{sample.isLoading && <Spin size="small" />}
|
||||
{sample.data && (
|
||||
<StatusTag
|
||||
tone={sample.data.alreadyImported ? "success" : "info"}
|
||||
label={sample.data.alreadyImported ? "已导入" : "可导入"}
|
||||
/>
|
||||
)}
|
||||
<Button
|
||||
disabled={!canManageTemplate || !sample.data || sample.data.alreadyImported}
|
||||
loading={importSample.isPending}
|
||||
onClick={() => importSample.mutate()}
|
||||
>
|
||||
导入示例内容
|
||||
</Button>
|
||||
{sample.isError && <Button onClick={() => void sample.refetch()}>重试</Button>}
|
||||
</Space>
|
||||
{sample.isError && (
|
||||
<div className="admin-offset-top-sm">
|
||||
<ErrorNote error={sample.error} onRetry={() => void sample.refetch()} />
|
||||
</div>
|
||||
)}
|
||||
{sample.data && !sample.data.alreadyImported && (
|
||||
<p className="admin-section-description admin-offset-top-sm">
|
||||
将向草稿添加{" "}
|
||||
{Object.entries(sample.data.counts)
|
||||
.map(([key, count]) => `${key} ${count} 项`)
|
||||
.join("、")}
|
||||
;发布前请替换示例文案和图片。
|
||||
</p>
|
||||
)}
|
||||
<MutationError error={importSample.error} />
|
||||
</AdminSection>
|
||||
<AdminSection
|
||||
title="核对草稿内容"
|
||||
description="此处核对的是待发布内容,不是小程序视觉预览。"
|
||||
>
|
||||
<ul className="admin-list">
|
||||
<li className="admin-row">
|
||||
<div className="admin-row-main">
|
||||
<div className="admin-row-line">
|
||||
<span className="admin-row-title">{brand.data?.name || "未命名品牌"}</span>
|
||||
<span className="admin-row-meta">
|
||||
{brand.data?.tagline || "尚未填写品牌定位"}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
<li className="admin-row">
|
||||
<div className="admin-row-main">
|
||||
<div className="admin-row-line">
|
||||
<span className="admin-row-title">已启用业务项</span>
|
||||
<span className="admin-row-meta">
|
||||
{draftOfferings.map((item) => item.name).join("、") || "无"}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
<li className="admin-row">
|
||||
<div className="admin-row-main">
|
||||
<div className="admin-row-line">
|
||||
<span className="admin-row-title">已启用咨询表单</span>
|
||||
<span className="admin-row-meta">
|
||||
{draftForms
|
||||
.filter((item) => item.isEnabled)
|
||||
.map((item) => item.name)
|
||||
.join("、") || "无"}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
<Space wrap className="admin-offset-top">
|
||||
<Button onClick={() => navigate("/admin/brand")}>编辑小程序页面</Button>
|
||||
<Button onClick={() => navigate("/admin/services")}>编辑业务展示和详情</Button>
|
||||
<Button onClick={() => navigate("/admin/trust")}>编辑信任证明</Button>
|
||||
</Space>
|
||||
</Space>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<Typography.Title level={4}>3. 检查并发布</Typography.Title>
|
||||
<Space wrap style={{ marginBottom: 12 }}>
|
||||
<Tag color={currentRelease ? "green" : "default"}>
|
||||
{currentRelease ? `已发布 v${currentRelease.version}` : "尚未发布"}
|
||||
</Tag>
|
||||
<Button onClick={() => void readiness.refetch()}>重新检查</Button>
|
||||
</Space>
|
||||
<Space direction="vertical" style={{ width: "100%" }}>
|
||||
{(readiness.data?.checks ?? []).map((check) => (
|
||||
<Space key={check.key}>
|
||||
<Tag color={check.passed ? "success" : "warning"}>
|
||||
{check.passed ? "已完成" : "待完善"}
|
||||
</Tag>
|
||||
<Typography.Text>{check.label}</Typography.Text>
|
||||
{check.help ? (
|
||||
<Typography.Text type="secondary">{check.help}</Typography.Text>
|
||||
) : null}
|
||||
{!check.passed && (
|
||||
<Button
|
||||
type="link"
|
||||
onClick={() =>
|
||||
navigate(check.destination ?? destinations[check.key] ?? "/admin/overview")
|
||||
}
|
||||
>
|
||||
去处理
|
||||
</Button>
|
||||
</AdminSection>
|
||||
<AdminSection
|
||||
title="检查并发布"
|
||||
extra={
|
||||
<Space wrap>
|
||||
<StatusTag
|
||||
tone={currentRelease ? "success" : "neutral"}
|
||||
label={currentRelease ? `已发布 v${currentRelease.version}` : "尚未发布"}
|
||||
/>
|
||||
<Button onClick={() => void readiness.refetch()}>重新检查</Button>
|
||||
</Space>
|
||||
}
|
||||
>
|
||||
<ul className="admin-list">
|
||||
{(readiness.data?.checks ?? []).map((check) => (
|
||||
<li key={check.key} className="admin-row">
|
||||
<div className="admin-row-main">
|
||||
<div className="admin-row-line">
|
||||
<StatusTag
|
||||
tone={check.passed ? "success" : "warning"}
|
||||
label={check.passed ? "已完成" : "待完善"}
|
||||
/>
|
||||
<span className="admin-row-title">{check.label}</span>
|
||||
{!check.passed && check.help ? (
|
||||
<span className="admin-row-meta">{check.help}</span>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
{!check.passed ? (
|
||||
<Button
|
||||
type="link"
|
||||
size="small"
|
||||
onClick={() =>
|
||||
navigate(check.destination ?? destinations[check.key] ?? "/admin/overview")
|
||||
}
|
||||
>
|
||||
去处理
|
||||
</Button>
|
||||
) : null}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
<Space wrap className="admin-offset-top">
|
||||
<Button
|
||||
type="primary"
|
||||
disabled={!readiness.data?.ready}
|
||||
onClick={() => setConfirmAction("publish")}
|
||||
>
|
||||
发布当前草稿
|
||||
</Button>
|
||||
{currentRelease && (
|
||||
<Button danger onClick={() => setConfirmAction("revoke")}>
|
||||
撤回当前版本
|
||||
</Button>
|
||||
)}
|
||||
</Space>
|
||||
<MutationError error={publish.error || revoke.error} />
|
||||
<Divider className="admin-divider" />
|
||||
<h3 className="admin-section-title">发布记录</h3>
|
||||
{releases.data?.length ? (
|
||||
<ul className="admin-list admin-offset-top-xs">
|
||||
{releases.data.map((item) => (
|
||||
<li key={item.id} className="admin-row">
|
||||
<div className="admin-row-main">
|
||||
<div className="admin-row-line">
|
||||
<span className="admin-row-title">v{item.version}</span>
|
||||
<StatusTag
|
||||
tone={item.status === "published" ? "success" : "neutral"}
|
||||
label={statusLabel(item.status)}
|
||||
/>
|
||||
<span className="admin-row-meta">
|
||||
{new Date(item.createdAt).toLocaleString("zh-CN")}
|
||||
</span>
|
||||
{item.note ? <span className="admin-row-meta">{item.note}</span> : null}
|
||||
</div>
|
||||
</div>
|
||||
{item.status === "superseded" && publishedHistory.length > 1 ? (
|
||||
<Button
|
||||
type="link"
|
||||
size="small"
|
||||
onClick={() => setRollbackVersion(item.version)}
|
||||
>
|
||||
恢复此版本
|
||||
</Button>
|
||||
) : null}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
) : (
|
||||
<EmptyState
|
||||
compact
|
||||
title="暂无发布记录"
|
||||
description="完成检查并发布后,这里会保留每个版本的记录。"
|
||||
/>
|
||||
)}
|
||||
<MutationError error={rollback.error} />
|
||||
</AdminSection>
|
||||
</div>
|
||||
)}
|
||||
{activeTab === "miniapp" && (
|
||||
<div className="admin-stack admin-stack-lg">
|
||||
<AdminSection
|
||||
title="小程序代码发布"
|
||||
description="使用微信官方工具上传代码;审核与发布状态需按微信平台结果人工确认。"
|
||||
extra={
|
||||
<Space wrap>
|
||||
<Button
|
||||
type="primary"
|
||||
disabled={!currentRelease}
|
||||
loading={uploadLatestMiniAppRelease.isPending}
|
||||
onClick={() => uploadLatestMiniAppRelease.mutate()}
|
||||
>
|
||||
上传当前版本到微信
|
||||
</Button>
|
||||
{miniAppSettings.data?.hasStoredCredentials ? (
|
||||
<StatusTag tone="success" label="已配置上传凭据" />
|
||||
) : (
|
||||
<StatusTag tone="warning" label="未配置上传凭据" />
|
||||
)}
|
||||
</Space>
|
||||
))}
|
||||
</Space>
|
||||
<Space wrap style={{ marginTop: 16 }}>
|
||||
<Button
|
||||
type="primary"
|
||||
disabled={!readiness.data?.ready}
|
||||
onClick={() => setConfirmAction("publish")}
|
||||
>
|
||||
发布当前草稿
|
||||
</Button>
|
||||
{currentRelease && (
|
||||
<Button danger onClick={() => setConfirmAction("revoke")}>
|
||||
撤回当前版本
|
||||
</Button>
|
||||
}
|
||||
>
|
||||
{miniAppReleases.data?.length ? (
|
||||
<div className="admin-stack admin-stack-tight">
|
||||
{miniAppReleases.data.map((task) => (
|
||||
<MiniAppReleaseCard
|
||||
key={task.id}
|
||||
task={task}
|
||||
uploading={uploadMiniAppRelease.isPending}
|
||||
onUpload={() => uploadMiniAppRelease.mutate(task.id)}
|
||||
onStatusChange={(status) => updateMiniAppStatus.mutate({ id: task.id, status })}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
<EmptyState
|
||||
compact
|
||||
title="暂无小程序发布任务"
|
||||
description="先发布品牌内容,再上传当前版本到微信。"
|
||||
/>
|
||||
)}
|
||||
</Space>
|
||||
<MutationError error={publish.error || revoke.error} />
|
||||
<Divider />
|
||||
<Typography.Title level={5}>发布记录</Typography.Title>
|
||||
{releases.data?.length ? (
|
||||
<Space direction="vertical" style={{ width: "100%" }}>
|
||||
{releases.data.map((item) => (
|
||||
<Space key={item.id} wrap>
|
||||
<Typography.Text>v{item.version}</Typography.Text>
|
||||
<Tag color={item.status === "published" ? "green" : "default"}>{item.status}</Tag>
|
||||
<Typography.Text type="secondary">
|
||||
{new Date(item.createdAt).toLocaleString("zh-CN")}
|
||||
</Typography.Text>
|
||||
{item.note && <Typography.Text>{item.note}</Typography.Text>}
|
||||
{item.status === "superseded" && publishedHistory.length > 1 && (
|
||||
<Button size="small" onClick={() => setRollbackVersion(item.version)}>
|
||||
恢复此版本
|
||||
</Button>
|
||||
)}
|
||||
</Space>
|
||||
))}
|
||||
</Space>
|
||||
) : (
|
||||
<Empty description="暂无发布记录" />
|
||||
)}
|
||||
<MutationError error={rollback.error} />
|
||||
</section>
|
||||
</Space>
|
||||
</AdminSection>
|
||||
</div>
|
||||
)}
|
||||
<Modal
|
||||
title={confirmAction === "revoke" ? "确认撤回品牌" : "确认发布品牌"}
|
||||
open={confirmAction !== null}
|
||||
onCancel={() => setConfirmAction(null)}
|
||||
onOk={() => (confirmAction === "revoke" ? revoke.mutate() : publish.mutate())}
|
||||
onOk={() => (confirmAction === "revoke" ? revoke.mutate() : publish.mutate(note.trim()))}
|
||||
confirmLoading={publish.isPending || revoke.isPending}
|
||||
okText={confirmAction === "revoke" ? "确认撤回" : "确认发布"}
|
||||
okButtonProps={{ danger: confirmAction === "revoke" }}
|
||||
@@ -357,7 +558,7 @@ export function PublicationPage({ canManageTemplate }: { canManageTemplate: bool
|
||||
message="撤回后,小程序将显示品牌尚未发布,新的咨询和预约会停止受理。"
|
||||
/>
|
||||
) : (
|
||||
<Space direction="vertical" style={{ width: "100%" }}>
|
||||
<div className="admin-stack">
|
||||
<Typography.Text>当前草稿将成为品牌新的公开版本。</Typography.Text>
|
||||
<Input
|
||||
value={note}
|
||||
@@ -365,7 +566,7 @@ export function PublicationPage({ canManageTemplate }: { canManageTemplate: bool
|
||||
placeholder="发布备注(可选)"
|
||||
maxLength={200}
|
||||
/>
|
||||
</Space>
|
||||
</div>
|
||||
)}
|
||||
</Modal>
|
||||
<Modal
|
||||
|
||||
@@ -0,0 +1,152 @@
|
||||
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||
import { message } from "antd";
|
||||
import type { BrandTemplateKey } from "@personal-brand/api-client";
|
||||
import { createApiClient } from "../../lib/api.js";
|
||||
|
||||
const client = createApiClient();
|
||||
|
||||
interface MutationOptions {
|
||||
refresh: () => void;
|
||||
brandConfig: Record<string, unknown> | null | undefined;
|
||||
onInstallClose: () => void;
|
||||
onPublishClose: () => void;
|
||||
onNoteClear: () => void;
|
||||
onRollbackClose: () => void;
|
||||
}
|
||||
|
||||
export function usePublicationMutations({
|
||||
refresh,
|
||||
onInstallClose,
|
||||
onPublishClose,
|
||||
onNoteClear,
|
||||
onRollbackClose,
|
||||
brandConfig,
|
||||
}: MutationOptions) {
|
||||
const queryClient = useQueryClient();
|
||||
const install = useMutation({
|
||||
mutationFn: (key: BrandTemplateKey) => client.installAdminTemplate(key),
|
||||
onSuccess: () => {
|
||||
onInstallClose();
|
||||
message.success("行业模板已安装");
|
||||
refresh();
|
||||
},
|
||||
});
|
||||
const upgradeTemplate = useMutation({
|
||||
mutationFn: () => client.upgradeAdminTemplate(),
|
||||
onSuccess: () => {
|
||||
message.success("行业模板已升级,现有内容未被覆盖");
|
||||
refresh();
|
||||
},
|
||||
});
|
||||
const rollbackTemplate = useMutation({
|
||||
mutationFn: () => client.rollbackAdminTemplate(),
|
||||
onSuccess: () => {
|
||||
message.success("行业模板配置基线已回滚");
|
||||
refresh();
|
||||
},
|
||||
});
|
||||
const selectVisual = useMutation({
|
||||
mutationFn: (key: string) =>
|
||||
client.updateAdminBrand({
|
||||
config: { ...(brandConfig ?? {}), visualTemplateKey: key },
|
||||
}),
|
||||
onSuccess: () => {
|
||||
message.success("视觉模板已保存到草稿");
|
||||
refresh();
|
||||
},
|
||||
});
|
||||
const importSample = useMutation<Awaited<ReturnType<typeof client.importAdminSampleContent>>>({
|
||||
mutationFn: () => client.importAdminSampleContent(),
|
||||
onSuccess: ({ counts }) => {
|
||||
message.success(
|
||||
counts.inquiryForms
|
||||
? "示例内容和客户咨询表单已导入草稿"
|
||||
: "示例内容已导入草稿,现有客户咨询表单已保留",
|
||||
);
|
||||
refresh();
|
||||
},
|
||||
});
|
||||
const publish = useMutation({
|
||||
mutationFn: (note: string) => client.publishAdminRelease(note || undefined),
|
||||
onSuccess: () => {
|
||||
onPublishClose();
|
||||
onNoteClear();
|
||||
message.success("品牌已发布");
|
||||
refresh();
|
||||
},
|
||||
});
|
||||
const revoke = useMutation({
|
||||
mutationFn: () => client.revokeAdminRelease(),
|
||||
onSuccess: () => {
|
||||
onPublishClose();
|
||||
message.success("品牌已撤回,小程序将显示未发布状态");
|
||||
refresh();
|
||||
},
|
||||
});
|
||||
const rollback = useMutation({
|
||||
mutationFn: (version: number) => client.rollbackAdminRelease(version),
|
||||
onSuccess: () => {
|
||||
onRollbackClose();
|
||||
message.success("历史版本已重新发布");
|
||||
refresh();
|
||||
},
|
||||
});
|
||||
const uploadLatestMiniAppRelease = useMutation({
|
||||
mutationFn: async () => {
|
||||
const latest = await client.getLatestAdminMiniAppRelease();
|
||||
const task = latest ?? (await client.createAdminMiniAppRelease());
|
||||
return client.uploadAdminMiniAppRelease(task.id);
|
||||
},
|
||||
onSuccess: () => {
|
||||
message.success("小程序代码已上传");
|
||||
void queryClient.invalidateQueries({ queryKey: ["publication-miniapp-releases"] });
|
||||
},
|
||||
});
|
||||
const saveMiniAppSettings = useMutation({
|
||||
mutationFn: (values: { appId: string; apiBaseUrl: string; privateKey?: string }) =>
|
||||
client.updateAdminMiniAppSettings({
|
||||
appId: values.appId,
|
||||
apiBaseUrl: values.apiBaseUrl,
|
||||
...(values.privateKey ? { privateKey: values.privateKey } : {}),
|
||||
}),
|
||||
onSuccess: () => {
|
||||
message.success("小程序上传配置已保存");
|
||||
void queryClient.invalidateQueries({ queryKey: ["publication-miniapp-settings"] });
|
||||
},
|
||||
});
|
||||
const uploadMiniAppRelease = useMutation({
|
||||
mutationFn: (id: string) => client.uploadAdminMiniAppRelease(id),
|
||||
onSuccess: () => {
|
||||
message.success("小程序代码已上传");
|
||||
void queryClient.invalidateQueries({ queryKey: ["publication-miniapp-releases"] });
|
||||
},
|
||||
});
|
||||
const updateMiniAppStatus = useMutation({
|
||||
mutationFn: ({
|
||||
id,
|
||||
status,
|
||||
}: {
|
||||
id: string;
|
||||
status: Parameters<typeof client.updateAdminMiniAppReleaseStatus>[1]["status"];
|
||||
}) => client.updateAdminMiniAppReleaseStatus(id, { status }),
|
||||
onSuccess: () => {
|
||||
message.success("小程序发布状态已更新");
|
||||
void queryClient.invalidateQueries({ queryKey: ["publication-miniapp-releases"] });
|
||||
},
|
||||
});
|
||||
|
||||
return {
|
||||
install,
|
||||
upgradeTemplate,
|
||||
rollbackTemplate,
|
||||
selectVisual,
|
||||
importSample,
|
||||
publish,
|
||||
revoke,
|
||||
rollback,
|
||||
uploadLatestMiniAppRelease,
|
||||
saveMiniAppSettings,
|
||||
uploadMiniAppRelease,
|
||||
updateMiniAppStatus,
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
import { useEffect } from "react";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import type { FormInstance } from "antd";
|
||||
import { createApiClient } from "../../lib/api.js";
|
||||
|
||||
const client = createApiClient();
|
||||
|
||||
export function usePublicationQueries(
|
||||
miniAppSettingsForm: FormInstance<{
|
||||
appId: string;
|
||||
apiBaseUrl: string;
|
||||
privateKey?: string;
|
||||
}>,
|
||||
) {
|
||||
const brand = useQuery<Awaited<ReturnType<typeof client.getAdminBrand>>>({
|
||||
queryKey: ["publication-brand"],
|
||||
queryFn: () => client.getAdminBrand(),
|
||||
});
|
||||
const workspace = useQuery<Awaited<ReturnType<typeof client.getAdminWorkspace>>>({
|
||||
queryKey: ["publication-workspace"],
|
||||
queryFn: () => client.getAdminWorkspace(),
|
||||
});
|
||||
const catalog = useQuery<Awaited<ReturnType<typeof client.listPublicTemplates>>>({
|
||||
queryKey: ["publication-catalog"],
|
||||
queryFn: () => client.listPublicTemplates(),
|
||||
});
|
||||
const sample = useQuery<Awaited<ReturnType<typeof client.previewAdminSampleContent>>>({
|
||||
queryKey: ["publication-sample"],
|
||||
queryFn: () => client.previewAdminSampleContent(),
|
||||
enabled: Boolean(workspace.data),
|
||||
});
|
||||
const readiness = useQuery<Awaited<ReturnType<typeof client.getAdminReleaseReadiness>>>({
|
||||
queryKey: ["publication-readiness"],
|
||||
queryFn: () => client.getAdminReleaseReadiness(),
|
||||
});
|
||||
const releases = useQuery<Awaited<ReturnType<typeof client.listAdminReleases>>>({
|
||||
queryKey: ["publication-releases"],
|
||||
queryFn: () => client.listAdminReleases(),
|
||||
});
|
||||
const miniAppReleases = useQuery<Awaited<ReturnType<typeof client.listAdminMiniAppReleases>>>({
|
||||
queryKey: ["publication-miniapp-releases"],
|
||||
queryFn: () => client.listAdminMiniAppReleases(),
|
||||
});
|
||||
const miniAppSettings = useQuery<Awaited<ReturnType<typeof client.getAdminMiniAppSettings>>>({
|
||||
queryKey: ["publication-miniapp-settings"],
|
||||
queryFn: () => client.getAdminMiniAppSettings(),
|
||||
});
|
||||
const templatePreview = useQuery<
|
||||
Awaited<ReturnType<typeof client.getAdminTemplateUpgradePreview>>
|
||||
>({
|
||||
queryKey: ["publication-template-preview"],
|
||||
queryFn: () => client.getAdminTemplateUpgradePreview(),
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
if (!miniAppSettings.data) return;
|
||||
miniAppSettingsForm.setFieldsValue({
|
||||
appId: miniAppSettings.data.appId,
|
||||
apiBaseUrl: miniAppSettings.data.apiBaseUrl,
|
||||
privateKey: "",
|
||||
});
|
||||
}, [miniAppSettings.data, miniAppSettingsForm]);
|
||||
|
||||
useEffect(() => {
|
||||
const building = miniAppReleases.data?.find(
|
||||
(task) =>
|
||||
task.buildStatus === "building" &&
|
||||
Date.now() - new Date(task.updatedAt).getTime() < 15 * 60 * 1000,
|
||||
);
|
||||
if (!building) return;
|
||||
const timer = setInterval(() => void miniAppReleases.refetch(), 1500);
|
||||
return () => clearInterval(timer);
|
||||
}, [miniAppReleases]);
|
||||
|
||||
const loading = [
|
||||
brand,
|
||||
workspace,
|
||||
catalog,
|
||||
readiness,
|
||||
releases,
|
||||
miniAppReleases,
|
||||
miniAppSettings,
|
||||
].some((query) => query.isLoading);
|
||||
const error = [
|
||||
brand,
|
||||
workspace,
|
||||
catalog,
|
||||
readiness,
|
||||
releases,
|
||||
miniAppReleases,
|
||||
miniAppSettings,
|
||||
].find((query) => query.isError)?.error;
|
||||
const retry = () => {
|
||||
void brand.refetch();
|
||||
void workspace.refetch();
|
||||
void catalog.refetch();
|
||||
void readiness.refetch();
|
||||
void releases.refetch();
|
||||
void miniAppReleases.refetch();
|
||||
void miniAppSettings.refetch();
|
||||
};
|
||||
|
||||
return {
|
||||
brand,
|
||||
workspace,
|
||||
catalog,
|
||||
sample,
|
||||
readiness,
|
||||
releases,
|
||||
miniAppReleases,
|
||||
miniAppSettings,
|
||||
templatePreview,
|
||||
loading,
|
||||
error,
|
||||
retry,
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,181 @@
|
||||
import { Alert, Button, Form, Input, Modal, Segmented, Select } from "antd";
|
||||
import type {
|
||||
Offering,
|
||||
RuntimeWorkspace,
|
||||
TemplateAdminField,
|
||||
TemplateAdminSection,
|
||||
} from "@personal-brand/api-client";
|
||||
import { ImageUrlField } from "../../components/ImageUrlField.js";
|
||||
import { RecordContentFields } from "../../components/RecordContentEditor.js";
|
||||
import { ComponentTemplatePreview } from "../brand/ComponentTemplatePreview.js";
|
||||
import type { PreviewTarget } from "../brand/preview-selection.js";
|
||||
import type { FormInstance } from "antd";
|
||||
import "./ServicesPage.css";
|
||||
|
||||
type OfferingEditorModalProps = {
|
||||
open: boolean;
|
||||
editingOffering: Offering | null;
|
||||
form: FormInstance<Record<string, unknown>>;
|
||||
previewPage: "offerings" | "detail";
|
||||
previewWorkspace: RuntimeWorkspace | undefined;
|
||||
previewTargets: Record<"offerings" | "detail", PreviewTarget[]>;
|
||||
activeTemplateFields: TemplateAdminField[];
|
||||
templateFieldSection: TemplateAdminSection;
|
||||
hasTemplateDetailCopy: boolean;
|
||||
listTarget: PreviewTarget;
|
||||
detailTarget: PreviewTarget | undefined;
|
||||
saving: boolean;
|
||||
onClose: () => void;
|
||||
onPreviewPageChange: (page: "offerings" | "detail") => void;
|
||||
onValuesChange: (values: Record<string, unknown>) => void;
|
||||
onFinish: (values: Record<string, unknown>) => void;
|
||||
onEditInBrand: () => void;
|
||||
};
|
||||
|
||||
export function OfferingEditorModal({
|
||||
open,
|
||||
editingOffering,
|
||||
form,
|
||||
previewPage,
|
||||
previewWorkspace,
|
||||
previewTargets,
|
||||
activeTemplateFields,
|
||||
templateFieldSection,
|
||||
hasTemplateDetailCopy,
|
||||
listTarget,
|
||||
detailTarget,
|
||||
saving,
|
||||
onClose,
|
||||
onPreviewPageChange,
|
||||
onValuesChange,
|
||||
onFinish,
|
||||
onEditInBrand,
|
||||
}: OfferingEditorModalProps) {
|
||||
return (
|
||||
<Modal
|
||||
open={open}
|
||||
title={editingOffering ? "编辑业务提供项" : "新增业务提供项"}
|
||||
width={960}
|
||||
onCancel={onClose}
|
||||
onOk={() => form.submit()}
|
||||
confirmLoading={saving}
|
||||
>
|
||||
<div className="service-offering-editor">
|
||||
{editingOffering && previewWorkspace ? (
|
||||
<div className="service-offering-editor__preview">
|
||||
<Segmented
|
||||
className="service-offering-editor__view"
|
||||
value={previewPage}
|
||||
options={[
|
||||
{ value: "offerings", label: "列表卡片" },
|
||||
{ value: "detail", label: "详情内容" },
|
||||
]}
|
||||
onChange={onPreviewPageChange}
|
||||
/>
|
||||
<Alert
|
||||
type="info"
|
||||
showIcon
|
||||
message={previewPage === "offerings" ? "正在核对列表展示" : "正在核对详情展示"}
|
||||
description={
|
||||
previewPage === "offerings"
|
||||
? "右侧「列表展示」字段修改后,会实时反映在当前卡片。"
|
||||
: "右侧「详情展示」字段修改后,会实时反映在当前详情内容。"
|
||||
}
|
||||
/>
|
||||
<ComponentTemplatePreview
|
||||
workspace={previewWorkspace}
|
||||
page={previewPage}
|
||||
offeringId={editingOffering.id}
|
||||
targets={previewTargets[previewPage]}
|
||||
selection={{
|
||||
targetKey: previewPage === "offerings" ? listTarget.key : (detailTarget?.key ?? ""),
|
||||
recordId: editingOffering.id,
|
||||
}}
|
||||
onTargetSelected={() => {}}
|
||||
/>
|
||||
</div>
|
||||
) : null}
|
||||
<Form
|
||||
className="service-offering-editor__form"
|
||||
form={form}
|
||||
layout="vertical"
|
||||
onValuesChange={(_, allValues) => onValuesChange(allValues)}
|
||||
onFinish={onFinish}
|
||||
>
|
||||
<div className="service-offering-editor__form-scroll">
|
||||
<h4 className="admin-subhead">基础信息</h4>
|
||||
<Form.Item name="kind" label="类型" rules={[{ required: true }]}>
|
||||
<Select
|
||||
options={[
|
||||
{ value: "service", label: "服务" },
|
||||
{ value: "product", label: "定制产品" },
|
||||
{ value: "package", label: "套餐" },
|
||||
{ value: "subscription", label: "订阅" },
|
||||
]}
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item name="name" label="名称" rules={[{ required: true }]}>
|
||||
<Input />
|
||||
</Form.Item>
|
||||
<Form.Item name="summary" label="一句话说明">
|
||||
<Input />
|
||||
</Form.Item>
|
||||
{!hasTemplateDetailCopy ? (
|
||||
<Form.Item name="description" label="详细介绍">
|
||||
<Input.TextArea rows={5} />
|
||||
</Form.Item>
|
||||
) : null}
|
||||
<Form.Item name="priceText" label="价格展示">
|
||||
<Input placeholder="例如:按现场评估报价 / ¥ 2,800 起" />
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
name="coverUrl"
|
||||
label="封面图片地址"
|
||||
help="点击上传,或粘贴服务/产品封面图片地址。"
|
||||
>
|
||||
<ImageUrlField placeholder="粘贴服务或产品封面图片地址" scope="offering" />
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
name="sortOrder"
|
||||
label="展示顺序"
|
||||
help="数字越小越靠前,不确定时填写 0。"
|
||||
rules={[{ type: "number", min: 0, max: 9999 }]}
|
||||
>
|
||||
<Input type="number" min={0} max={9999} />
|
||||
</Form.Item>
|
||||
<Form.Item name="isEnabled" label="公开状态">
|
||||
<Select
|
||||
options={[
|
||||
{ value: true, label: "已启用" },
|
||||
{ value: false, label: "已停用" },
|
||||
]}
|
||||
/>
|
||||
</Form.Item>
|
||||
{activeTemplateFields.length ? (
|
||||
<div>
|
||||
<h4 className="admin-subhead">
|
||||
{previewPage === "offerings" ? "列表展示字段" : "详情展示字段"}
|
||||
</h4>
|
||||
<p className="admin-section-description admin-offset-bottom">
|
||||
这里只编辑左侧预览对应的字段;它们与小程序页面编辑的是同一份业务数据。
|
||||
</p>
|
||||
<RecordContentFields
|
||||
section={{
|
||||
...templateFieldSection,
|
||||
fields: activeTemplateFields,
|
||||
}}
|
||||
sectionKey="offering"
|
||||
/>
|
||||
</div>
|
||||
) : null}
|
||||
{editingOffering ? (
|
||||
<Button htmlType="button" onClick={onEditInBrand}>
|
||||
在小程序页面编辑
|
||||
</Button>
|
||||
) : null}
|
||||
</div>
|
||||
</Form>
|
||||
</div>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
import { Button, Popconfirm, Space, Table } from "antd";
|
||||
import type { Offering } from "@personal-brand/api-client";
|
||||
import { AdminSection } from "../../components/AdminSection.js";
|
||||
import { EmptyState } from "../../components/EmptyState.js";
|
||||
import { TableSkeleton } from "../../components/TableSkeleton.js";
|
||||
import { MutationError } from "../../components/QueryState.js";
|
||||
import { StatusTag } from "../../components/StatusTag.js";
|
||||
import type { useOfferingMutations } from "./use-offering-data.js";
|
||||
|
||||
type OfferingsTableProps = {
|
||||
pageLabel: string;
|
||||
detailSectionTitles: string[];
|
||||
items: Offering[];
|
||||
loading: boolean;
|
||||
saveError: unknown;
|
||||
toggleOffering: ReturnType<typeof useOfferingMutations>["toggleOffering"];
|
||||
deleteOffering: ReturnType<typeof useOfferingMutations>["deleteOffering"];
|
||||
onEdit: (item: Offering) => void;
|
||||
};
|
||||
|
||||
const offeringKindLabels: Record<string, string> = {
|
||||
service: "服务",
|
||||
product: "定制产品",
|
||||
package: "套餐",
|
||||
subscription: "订阅",
|
||||
};
|
||||
|
||||
export function OfferingsTable({
|
||||
pageLabel,
|
||||
detailSectionTitles,
|
||||
items,
|
||||
loading,
|
||||
saveError,
|
||||
toggleOffering,
|
||||
deleteOffering,
|
||||
onEdit,
|
||||
}: OfferingsTableProps) {
|
||||
const columns = [
|
||||
{ title: "名称", dataIndex: "name" },
|
||||
{
|
||||
title: "业务类型",
|
||||
dataIndex: "kind",
|
||||
render: (value: unknown) => (
|
||||
<StatusTag tone="neutral" label={offeringKindLabels[String(value)] ?? String(value)} />
|
||||
),
|
||||
},
|
||||
{ title: "价格", dataIndex: "priceText" },
|
||||
{
|
||||
title: "状态",
|
||||
dataIndex: "isEnabled",
|
||||
render: (value: boolean) => (
|
||||
<StatusTag tone={value ? "success" : "neutral"} label={value ? "已启用" : "已停用"} />
|
||||
),
|
||||
},
|
||||
{
|
||||
title: "操作",
|
||||
render: (_: unknown, item: Offering) => (
|
||||
<Space>
|
||||
<Button type="link" size="small" onClick={() => onEdit(item)}>
|
||||
编辑详情
|
||||
</Button>
|
||||
<Button
|
||||
type="link"
|
||||
size="small"
|
||||
loading={toggleOffering.isPending && toggleOffering.variables?.id === item.id}
|
||||
onClick={() => toggleOffering.mutate({ id: item.id, isEnabled: !item.isEnabled })}
|
||||
>
|
||||
{item.isEnabled ? "禁用" : "启用"}
|
||||
</Button>
|
||||
<Popconfirm
|
||||
title="确认删除这项业务提供项?"
|
||||
description="如果它已经关联咨询表单,系统会阻止删除。"
|
||||
onConfirm={() => deleteOffering.mutate(item.id)}
|
||||
okText="删除"
|
||||
cancelText="取消"
|
||||
>
|
||||
<Button
|
||||
type="link"
|
||||
danger
|
||||
size="small"
|
||||
loading={deleteOffering.isPending && deleteOffering.variables === item.id}
|
||||
>
|
||||
删除
|
||||
</Button>
|
||||
</Popconfirm>
|
||||
</Space>
|
||||
),
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
<AdminSection
|
||||
title={`${pageLabel}中的内容`}
|
||||
description={
|
||||
detailSectionTitles.length
|
||||
? `编辑单项详情时,附加字段将用于:${detailSectionTitles.join("、")}。列表中的名称、说明、价格和封面也会显示在业务展示页。`
|
||||
: "已启用的项目会公开展示。"
|
||||
}
|
||||
>
|
||||
{loading && items.length === 0 ? (
|
||||
<TableSkeleton />
|
||||
) : (
|
||||
<Table
|
||||
scroll={{ x: 760 }}
|
||||
rowKey="id"
|
||||
dataSource={items}
|
||||
columns={columns}
|
||||
locale={{
|
||||
emptyText: (
|
||||
<EmptyState
|
||||
compact
|
||||
title="还没有业务提供项"
|
||||
description="创建后,小程序业务展示页会优先读取这些内容。"
|
||||
/>
|
||||
),
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
<MutationError error={saveError} />
|
||||
<MutationError error={toggleOffering.error} />
|
||||
<MutationError error={deleteOffering.error} />
|
||||
</AdminSection>
|
||||
);
|
||||
}
|
||||
@@ -11,18 +11,26 @@
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 72vh;
|
||||
border: 1px solid #e5e7eb;
|
||||
border: 1px solid var(--admin-border);
|
||||
border-radius: 12px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.service-offering-editor__preview > * {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.service-offering-editor__view {
|
||||
align-self: flex-start;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.service-offering-editor__preview > .component-template-preview-shell {
|
||||
flex: 1;
|
||||
flex: 1 1 0;
|
||||
min-height: 0;
|
||||
}
|
||||
|
||||
.service-offering-editor__preview .component-template-preview {
|
||||
min-height: 0;
|
||||
}
|
||||
|
||||
@@ -30,14 +38,35 @@
|
||||
min-width: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
max-height: 72vh;
|
||||
overflow-y: auto;
|
||||
padding-right: 4px;
|
||||
}
|
||||
|
||||
.service-offering-editor__form-scroll {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
flex: none;
|
||||
max-height: 66vh;
|
||||
overflow-y: auto;
|
||||
padding: 20px 16px 24px;
|
||||
border-radius: 12px;
|
||||
background: var(--admin-fill);
|
||||
border: 1px solid var(--admin-border);
|
||||
}
|
||||
|
||||
.service-offering-editor__form-scroll > .ant-typography:first-child {
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
.service-offering-editor__form-scroll .ant-form-item {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.service-offering-editor__form-scroll .ant-typography h5.ant-typography {
|
||||
margin: 28px 0 4px;
|
||||
padding-bottom: 8px;
|
||||
border-bottom: 1px solid var(--admin-border);
|
||||
}
|
||||
|
||||
.service-offering-editor__form-scroll > .ant-typography-secondary {
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.service-offering-editor__preview .ant-alert {
|
||||
|
||||
@@ -1,128 +1,46 @@
|
||||
import {
|
||||
Alert,
|
||||
Button,
|
||||
Form,
|
||||
Input,
|
||||
Modal,
|
||||
Popconfirm,
|
||||
Segmented,
|
||||
Select,
|
||||
Space,
|
||||
Table,
|
||||
Tag,
|
||||
Typography,
|
||||
message,
|
||||
} from "antd";
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import type {
|
||||
Offering,
|
||||
RuntimeWorkspace,
|
||||
TemplateAdminField,
|
||||
TemplateAdminSection,
|
||||
} from "@personal-brand/api-client";
|
||||
import { useMemo, useState } from "react";
|
||||
import { useEffect, useRef } from "react";
|
||||
import { createApiClient } from "../../lib/api.js";
|
||||
import { AdminPageHeader } from "../../components/AdminPageHeader.js";
|
||||
import { ImageUrlField } from "../../components/ImageUrlField.js";
|
||||
import { RecordContentFields } from "../../components/RecordContentEditor.js";
|
||||
import { ComponentTemplatePreview } from "../brand/ComponentTemplatePreview.js";
|
||||
import type { PreviewTarget } from "../brand/preview-selection.js";
|
||||
import {
|
||||
applyPresentationValues,
|
||||
presentationFieldName,
|
||||
readPresentationValue,
|
||||
} from "../brand/presentation-bindings.js";
|
||||
import { MutationError, QueryState } from "../../components/QueryState.js";
|
||||
import { Button } from "antd";
|
||||
import type { Offering, TemplateAdminField } from "@personal-brand/api-client";
|
||||
import { useMemo } from "react";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import "./ServicesPage.css";
|
||||
import { AdminPageHeader } from "../../components/AdminPageHeader.js";
|
||||
import { QueryState } from "../../components/QueryState.js";
|
||||
import { OfferingEditorModal } from "./OfferingEditorModal.js";
|
||||
import { OfferingsTable } from "./OfferingsTable.js";
|
||||
import { detailPageLabel, hasTemplateDetailCopy, offeringPageLabel } from "./offering-model.js";
|
||||
import { buildOfferingPreviewWorkspace, previewTargetsByPage } from "./offering-preview.js";
|
||||
import { useOfferingEditor } from "./use-offering-editor.js";
|
||||
import { useOfferingMutations, useOfferingQueries } from "./use-offering-data.js";
|
||||
|
||||
type PreviewPage = "offerings" | "detail";
|
||||
|
||||
export function ServicesPage() {
|
||||
const navigate = useNavigate();
|
||||
const client = createApiClient();
|
||||
const queryClient = useQueryClient();
|
||||
const [offeringForm] = Form.useForm();
|
||||
const [offeringOpen, setOfferingOpen] = useState(false);
|
||||
const [editingOffering, setEditingOffering] = useState<Offering | null>(null);
|
||||
const [previewPage, setPreviewPage] = useState<"offerings" | "detail">("detail");
|
||||
const listFieldsRef = useRef<HTMLDivElement | null>(null);
|
||||
const detailFieldsRef = useRef<HTMLDivElement | null>(null);
|
||||
const formScrollRef = useRef<HTMLDivElement | null>(null);
|
||||
const offerings = useQuery({
|
||||
queryKey: ["admin-offerings"],
|
||||
queryFn: () => client.listAdminOfferings(),
|
||||
const { offerings, workspace, previewWorkspace, templateFields, retry } = useOfferingQueries();
|
||||
const editor = useOfferingEditor(templateFields);
|
||||
const mutations = useOfferingMutations({
|
||||
editingOffering: editor.editingOffering,
|
||||
templateFields,
|
||||
onSuccess: () => {
|
||||
editor.closeOffering();
|
||||
editor.offeringForm.resetFields();
|
||||
},
|
||||
});
|
||||
const workspace = useQuery({
|
||||
queryKey: ["admin-workspace-offering-fields"],
|
||||
queryFn: () => client.getAdminWorkspace(),
|
||||
});
|
||||
const previewWorkspace = useQuery({
|
||||
queryKey: ["admin-preview-workspace-services"],
|
||||
queryFn: () => client.getAdminPreviewWorkspace(),
|
||||
});
|
||||
const templateFields: TemplateAdminField[] = (
|
||||
workspace.data?.templateContent?.admin.sections ?? []
|
||||
)
|
||||
.filter((section) => section.target === "offering")
|
||||
.flatMap((section) =>
|
||||
section.fields.filter((field) => field.binding.startsWith("offering.config.")),
|
||||
);
|
||||
const templateFieldSection = useMemo<TemplateAdminSection>(
|
||||
() => ({
|
||||
key: "offering",
|
||||
title: "模板内容",
|
||||
description: "",
|
||||
page: "detail",
|
||||
target: "offering",
|
||||
fields: templateFields,
|
||||
}),
|
||||
[templateFields],
|
||||
);
|
||||
const offeringPageLabel =
|
||||
workspace.data?.templateContent?.navigation.find((item) => item.page === "offerings")?.label ??
|
||||
"业务展示页";
|
||||
const detailPageLabel =
|
||||
workspace.data?.templateContent?.navigation.find((item) => item.page === "detail")?.label ??
|
||||
"详情页";
|
||||
const detailSections = (workspace.data?.templateContent?.admin.sections ?? []).filter(
|
||||
(section) => section.target === "offering" && section.page === "detail",
|
||||
);
|
||||
const visualOfferingTarget = (workspace.data?.templateContent?.admin.sections ?? [])
|
||||
.filter((section) => section.target === "offering" && section.page === "offerings")
|
||||
.flatMap((section) => section.previewTargets ?? [])
|
||||
.find((target) => templateFields.some((field) => field.previewTarget === target.key)) ?? {
|
||||
key: "linjing-editorial.offerings.item",
|
||||
|
||||
const sections = workspace.data?.templateContent?.admin.sections ?? [];
|
||||
const previewTargets = useMemo(() => previewTargetsByPage(sections), [sections]);
|
||||
const listTarget = previewTargets.offerings.find((target) =>
|
||||
templateFields.some((field) => field.previewTarget === target.key),
|
||||
) ?? {
|
||||
key: "offering.list.item",
|
||||
label: "业务卡片",
|
||||
page: "offerings",
|
||||
source: "offering",
|
||||
};
|
||||
const hasTemplateDetailCopy = templateFields.some(
|
||||
(field) => field.binding === "offering.config.details.background",
|
||||
);
|
||||
const previewTargets = useMemo<Record<string, PreviewTarget[]>>(
|
||||
() =>
|
||||
["offerings", "detail"].reduce<Record<string, PreviewTarget[]>>((result, page) => {
|
||||
result[page] = (workspace.data?.templateContent?.admin.sections ?? [])
|
||||
.filter((section) => section.page === page)
|
||||
.flatMap((section) =>
|
||||
(section.previewTargets ?? []).map((target) => ({
|
||||
...target,
|
||||
page: section.page,
|
||||
source: section.fields.some(
|
||||
(field) =>
|
||||
field.binding.startsWith("offering.") && field.previewTarget === target.key,
|
||||
)
|
||||
? "offering"
|
||||
: section.target,
|
||||
})),
|
||||
);
|
||||
return result;
|
||||
}, {}),
|
||||
[workspace.data?.templateContent],
|
||||
);
|
||||
const detailTarget = previewTargets.detail.find((target) => target.source === "offering");
|
||||
const listFields = useMemo(
|
||||
() => templateFields.filter((field) => field.previewTarget === visualOfferingTarget.key),
|
||||
[templateFields, visualOfferingTarget.key],
|
||||
() => templateFields.filter((field) => field.previewTarget === listTarget.key),
|
||||
[templateFields, listTarget.key],
|
||||
);
|
||||
const detailTarget = previewTargets.detail?.find((target) => target.source === "offering");
|
||||
const detailFields = useMemo(
|
||||
() => templateFields.filter((field) => field.previewTarget === detailTarget?.key),
|
||||
[templateFields, detailTarget?.key],
|
||||
@@ -134,410 +52,85 @@ export function ServicesPage() {
|
||||
),
|
||||
[templateFields, listFields, detailFields],
|
||||
);
|
||||
useEffect(() => {
|
||||
const target = previewPage === "offerings" ? listFieldsRef.current : detailFieldsRef.current;
|
||||
if (!target || !formScrollRef.current) return;
|
||||
formScrollRef.current.scrollTo({
|
||||
top: target.offsetTop - formScrollRef.current.offsetTop - 12,
|
||||
behavior: "smooth",
|
||||
const activeTemplateFields: TemplateAdminField[] =
|
||||
editor.previewPage === "offerings"
|
||||
? [...listFields, ...otherFields.filter((field) => field.page === "offerings")]
|
||||
: [...detailFields, ...otherFields.filter((field) => field.page === "detail")];
|
||||
const previewWorkspaceDraft = useMemo(() => {
|
||||
if (!previewWorkspace.data || !editor.editingOffering) return undefined;
|
||||
return buildOfferingPreviewWorkspace({
|
||||
previewWorkspace: previewWorkspace.data,
|
||||
editingOffering: editor.editingOffering,
|
||||
templateFields,
|
||||
formValues: editor.formValues,
|
||||
});
|
||||
}, [
|
||||
previewWorkspace.data,
|
||||
editor.editingOffering,
|
||||
templateFields,
|
||||
editor.formValues,
|
||||
editor.offeringDraftVersion,
|
||||
]);
|
||||
|
||||
const navigateToBrand = () => {
|
||||
if (!editor.editingOffering) return;
|
||||
void navigate("/admin/brand", {
|
||||
state: {
|
||||
targetKey:
|
||||
editor.previewPage === "offerings"
|
||||
? listTarget.key
|
||||
: (detailTarget?.key ?? listTarget.key),
|
||||
recordId: editor.editingOffering.id,
|
||||
},
|
||||
});
|
||||
}, [previewPage, editingOffering?.id]);
|
||||
const previewWorkspaceDraft = useMemo<RuntimeWorkspace | undefined>(() => {
|
||||
if (!previewWorkspace.data || !editingOffering) return undefined;
|
||||
const values = offeringForm.getFieldsValue(true) as Record<string, unknown>;
|
||||
const config = applyPresentationValues(
|
||||
editingOffering.config,
|
||||
[{ key: "offering", fields: templateFields }],
|
||||
values,
|
||||
);
|
||||
const offeringValues = {
|
||||
name: values.name,
|
||||
summary: values.summary,
|
||||
description: values.description,
|
||||
priceText: values.priceText,
|
||||
coverUrl: values.coverUrl,
|
||||
};
|
||||
return {
|
||||
...previewWorkspace.data,
|
||||
offerings: previewWorkspace.data.offerings.map((item) =>
|
||||
item.id === editingOffering.id
|
||||
? {
|
||||
...item,
|
||||
name:
|
||||
typeof offeringValues.name === "string" && offeringValues.name.trim()
|
||||
? offeringValues.name
|
||||
: item.name,
|
||||
summary:
|
||||
typeof offeringValues.summary === "string" ? offeringValues.summary : item.summary,
|
||||
priceText:
|
||||
typeof offeringValues.priceText === "string"
|
||||
? offeringValues.priceText
|
||||
: item.priceText,
|
||||
coverUrl:
|
||||
typeof offeringValues.coverUrl === "string" && offeringValues.coverUrl.trim()
|
||||
? offeringValues.coverUrl
|
||||
: item.coverUrl,
|
||||
config,
|
||||
presentation: {
|
||||
...item.presentation,
|
||||
...config,
|
||||
...(config.presentation && typeof config.presentation === "object"
|
||||
? (config.presentation as Record<string, unknown>)
|
||||
: {}),
|
||||
heroImage:
|
||||
typeof config.detailHero === "string"
|
||||
? config.detailHero
|
||||
: typeof offeringValues.coverUrl === "string" && offeringValues.coverUrl.trim()
|
||||
? offeringValues.coverUrl
|
||||
: (item.coverUrl ?? null),
|
||||
},
|
||||
}
|
||||
: item,
|
||||
),
|
||||
brand: previewWorkspace.data.brand,
|
||||
};
|
||||
}, [previewWorkspace.data, editingOffering, templateFields]);
|
||||
const saveOffering = useMutation({
|
||||
mutationFn: (values: Record<string, unknown>) => {
|
||||
const fields = Object.fromEntries(
|
||||
Object.entries(values).filter(([key]) => key !== "config" && !key.startsWith("offering:")),
|
||||
);
|
||||
const config = applyPresentationValues(
|
||||
editingOffering?.config,
|
||||
[{ key: "offering", fields: templateFields }],
|
||||
values,
|
||||
);
|
||||
const body = { ...fields, config };
|
||||
return editingOffering
|
||||
? client.updateAdminOffering(editingOffering.id, body)
|
||||
: client.createAdminOffering(body as Omit<Offering, "id" | "brandId">);
|
||||
},
|
||||
onSuccess: () => {
|
||||
message.success("业务提供项已保存");
|
||||
setOfferingOpen(false);
|
||||
setEditingOffering(null);
|
||||
offeringForm.resetFields();
|
||||
void queryClient.invalidateQueries({ queryKey: ["admin-offerings"] });
|
||||
},
|
||||
});
|
||||
const deleteOffering = useMutation({
|
||||
mutationFn: (id: string) => client.deleteAdminOffering(id),
|
||||
onSuccess: () => {
|
||||
message.success("业务提供项已删除");
|
||||
void queryClient.invalidateQueries({ queryKey: ["admin-offerings"] });
|
||||
},
|
||||
});
|
||||
const toggleOffering = useMutation({
|
||||
mutationFn: ({ id, isEnabled }: { id: string; isEnabled: boolean }) =>
|
||||
client.updateAdminOffering(id, { isEnabled }),
|
||||
onSuccess: () => {
|
||||
message.success("业务提供项状态已更新");
|
||||
void queryClient.invalidateQueries({ queryKey: ["admin-offerings"] });
|
||||
},
|
||||
});
|
||||
const beginOffering = (item?: Offering) => {
|
||||
setEditingOffering(item ?? null);
|
||||
setOfferingOpen(true);
|
||||
offeringForm.setFieldsValue(
|
||||
item
|
||||
? {
|
||||
kind: item.kind,
|
||||
name: item.name,
|
||||
summary: item.summary ?? "",
|
||||
description: item.description ?? "",
|
||||
priceText: item.priceText ?? "",
|
||||
coverUrl: item.coverUrl ?? "",
|
||||
sortOrder: item.sortOrder,
|
||||
isEnabled: item.isEnabled,
|
||||
...Object.fromEntries(
|
||||
templateFields.map((field) => [
|
||||
presentationFieldName("offering", field.key),
|
||||
readPresentationValue(item.config, field.binding, field),
|
||||
]),
|
||||
),
|
||||
}
|
||||
: {
|
||||
kind: "service",
|
||||
isEnabled: true,
|
||||
sortOrder: 0,
|
||||
...Object.fromEntries(
|
||||
templateFields.map((field) => [
|
||||
presentationFieldName("offering", field.key),
|
||||
field.input === "list" ? [] : undefined,
|
||||
]),
|
||||
),
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
return (
|
||||
<QueryState
|
||||
loading={offerings.isLoading || workspace.isLoading}
|
||||
error={offerings.error || workspace.error}
|
||||
onRetry={() => {
|
||||
void offerings.refetch();
|
||||
void workspace.refetch();
|
||||
}}
|
||||
onRetry={retry}
|
||||
>
|
||||
<AdminPageHeader
|
||||
title="小程序内容:业务展示与详情"
|
||||
description={`在「${offeringPageLabel}」管理访客能选择的服务、产品或案例;每项内容的补充资料会显示在对应的「${detailPageLabel}」。`}
|
||||
title="业务提供项"
|
||||
description={`在「${offeringPageLabel(workspace.data?.templateContent ?? undefined)}」管理访客能选择的服务、产品或案例;每项内容的补充资料会显示在对应的「${detailPageLabel(workspace.data?.templateContent ?? undefined)}」。`}
|
||||
extra={
|
||||
<Button type="primary" onClick={() => beginOffering()}>
|
||||
<Button type="primary" onClick={() => editor.beginOffering()}>
|
||||
新增业务提供项
|
||||
</Button>
|
||||
}
|
||||
/>
|
||||
<section aria-label="业务提供项列表">
|
||||
<Space wrap style={{ marginBottom: 16 }}>
|
||||
<Typography.Title level={5} style={{ margin: 0 }}>
|
||||
{offeringPageLabel}中的内容
|
||||
</Typography.Title>
|
||||
<Tag color="blue">已启用的项目会公开展示</Tag>
|
||||
</Space>
|
||||
{detailSections.length ? (
|
||||
<Typography.Paragraph type="secondary">
|
||||
编辑单项详情时,附加字段将用于:
|
||||
{detailSections.map((section) => section.title).join("、")}
|
||||
。列表中的名称、说明、价格和封面也会显示在业务展示页。
|
||||
</Typography.Paragraph>
|
||||
) : null}
|
||||
<Table
|
||||
scroll={{ x: 760 }}
|
||||
rowKey="id"
|
||||
loading={offerings.isLoading}
|
||||
dataSource={offerings.data ?? []}
|
||||
columns={[
|
||||
{ title: "名称", dataIndex: "name" },
|
||||
{
|
||||
title: "业务类型",
|
||||
dataIndex: "kind",
|
||||
render: (value) => (
|
||||
<Tag>
|
||||
{(
|
||||
{
|
||||
service: "服务",
|
||||
product: "定制产品",
|
||||
package: "套餐",
|
||||
subscription: "订阅",
|
||||
} as Record<string, string>
|
||||
)[String(value)] ?? String(value)}
|
||||
</Tag>
|
||||
),
|
||||
},
|
||||
{ title: "价格", dataIndex: "priceText" },
|
||||
{
|
||||
title: "状态",
|
||||
dataIndex: "isEnabled",
|
||||
render: (value) => (value ? "已启用" : "已停用"),
|
||||
},
|
||||
{
|
||||
title: "操作",
|
||||
render: (_: unknown, item: Offering) => (
|
||||
<Space>
|
||||
<Button size="small" onClick={() => beginOffering(item)}>
|
||||
编辑详情
|
||||
</Button>
|
||||
<Button
|
||||
size="small"
|
||||
loading={toggleOffering.isPending && toggleOffering.variables?.id === item.id}
|
||||
onClick={() =>
|
||||
toggleOffering.mutate({ id: item.id, isEnabled: !item.isEnabled })
|
||||
}
|
||||
>
|
||||
{item.isEnabled ? "禁用" : "启用"}
|
||||
</Button>
|
||||
<Popconfirm
|
||||
title="确认删除这项业务提供项?"
|
||||
description="如果它已经关联咨询表单,系统会阻止删除。"
|
||||
onConfirm={() => deleteOffering.mutate(item.id)}
|
||||
okText="删除"
|
||||
cancelText="取消"
|
||||
>
|
||||
<Button
|
||||
danger
|
||||
size="small"
|
||||
loading={deleteOffering.isPending && deleteOffering.variables === item.id}
|
||||
>
|
||||
删除
|
||||
</Button>
|
||||
</Popconfirm>
|
||||
</Space>
|
||||
),
|
||||
},
|
||||
]}
|
||||
/>
|
||||
{offerings.data?.length === 0 && (
|
||||
<Typography.Paragraph type="secondary">
|
||||
还没有公开业务提供项。创建后,小程序服务页会优先读取这些内容。
|
||||
</Typography.Paragraph>
|
||||
)}
|
||||
<MutationError error={saveOffering.error} />
|
||||
<MutationError error={toggleOffering.error} />
|
||||
<MutationError error={deleteOffering.error} />
|
||||
</section>
|
||||
<Modal
|
||||
open={offeringOpen}
|
||||
title={editingOffering ? "编辑业务提供项" : "新增业务提供项"}
|
||||
width={960}
|
||||
onCancel={() => {
|
||||
setOfferingOpen(false);
|
||||
setEditingOffering(null);
|
||||
offeringForm.resetFields();
|
||||
}}
|
||||
onOk={() => offeringForm.submit()}
|
||||
confirmLoading={saveOffering.isPending}
|
||||
>
|
||||
<div className="service-offering-editor">
|
||||
{editingOffering && previewWorkspaceDraft ? (
|
||||
<div className="service-offering-editor__preview">
|
||||
<Segmented
|
||||
className="service-offering-editor__view"
|
||||
value={previewPage}
|
||||
options={[
|
||||
{ value: "offerings", label: "列表卡片" },
|
||||
{ value: "detail", label: "详情内容" },
|
||||
]}
|
||||
onChange={(value) => setPreviewPage(value as "offerings" | "detail")}
|
||||
/>
|
||||
<Alert
|
||||
type="info"
|
||||
showIcon
|
||||
message={previewPage === "offerings" ? "正在核对列表展示" : "正在核对详情展示"}
|
||||
description={
|
||||
previewPage === "offerings"
|
||||
? "右侧「列表展示」字段修改后,会实时反映在当前卡片。"
|
||||
: "右侧「详情展示」字段修改后,会实时反映在当前详情内容。"
|
||||
}
|
||||
/>
|
||||
<ComponentTemplatePreview
|
||||
workspace={previewWorkspaceDraft}
|
||||
page={previewPage}
|
||||
targets={previewTargets[previewPage] ?? []}
|
||||
selection={{
|
||||
targetKey:
|
||||
previewPage === "offerings"
|
||||
? visualOfferingTarget.key
|
||||
: (detailTarget?.key ?? ""),
|
||||
recordId: editingOffering.id,
|
||||
}}
|
||||
onTargetSelected={() => {}}
|
||||
/>
|
||||
</div>
|
||||
) : null}
|
||||
<Form
|
||||
className="service-offering-editor__form"
|
||||
form={offeringForm}
|
||||
layout="vertical"
|
||||
onFinish={(values) => saveOffering.mutate(values as Record<string, unknown>)}
|
||||
>
|
||||
<div ref={formScrollRef} className="service-offering-editor__form-scroll">
|
||||
<Typography.Title level={5}>基础信息</Typography.Title>
|
||||
<Form.Item name="kind" label="类型" rules={[{ required: true }]}>
|
||||
<Select
|
||||
options={[
|
||||
{ value: "service", label: "服务" },
|
||||
{ value: "product", label: "定制产品" },
|
||||
{ value: "package", label: "套餐" },
|
||||
{ value: "subscription", label: "订阅" },
|
||||
]}
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item name="name" label="名称" rules={[{ required: true }]}>
|
||||
<Input />
|
||||
</Form.Item>
|
||||
<Form.Item name="summary" label="一句话说明">
|
||||
<Input />
|
||||
</Form.Item>
|
||||
{!hasTemplateDetailCopy ? (
|
||||
<Form.Item name="description" label="详细介绍">
|
||||
<Input.TextArea rows={5} />
|
||||
</Form.Item>
|
||||
) : null}
|
||||
<Form.Item name="priceText" label="价格展示">
|
||||
<Input placeholder="例如:按现场评估报价 / ¥ 2,800 起" />
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
name="coverUrl"
|
||||
label="封面图片地址"
|
||||
help="填写图片地址;图片上传能力将在后续媒体管理中提供。"
|
||||
>
|
||||
<ImageUrlField placeholder="粘贴服务或产品封面图片地址" />
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
name="sortOrder"
|
||||
label="展示顺序"
|
||||
help="数字越小越靠前,不确定时填写 0。"
|
||||
rules={[{ type: "number", min: 0, max: 9999 }]}
|
||||
>
|
||||
<Input type="number" min={0} max={9999} />
|
||||
</Form.Item>
|
||||
<Form.Item name="isEnabled" label="公开状态">
|
||||
<Select
|
||||
options={[
|
||||
{ value: true, label: "已启用" },
|
||||
{ value: false, label: "已停用" },
|
||||
]}
|
||||
/>
|
||||
</Form.Item>
|
||||
</div>
|
||||
{templateFields.length ? (
|
||||
<>
|
||||
<Typography.Paragraph type="secondary">
|
||||
以下模板字段与左侧预览及小程序页面编辑的是同一份业务数据。
|
||||
</Typography.Paragraph>
|
||||
{listFields.length ? (
|
||||
<div ref={listFieldsRef}>
|
||||
<Typography.Title level={5}>列表展示</Typography.Title>
|
||||
<RecordContentFields
|
||||
section={{
|
||||
...templateFieldSection,
|
||||
fields: listFields,
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
) : null}
|
||||
{detailFields.length ? (
|
||||
<div ref={detailFieldsRef}>
|
||||
<Typography.Title level={5}>详情展示</Typography.Title>
|
||||
<RecordContentFields
|
||||
section={{
|
||||
...templateFieldSection,
|
||||
fields: detailFields,
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
) : null}
|
||||
{otherFields.length ? (
|
||||
<>
|
||||
<Typography.Title level={5}>其他模板内容</Typography.Title>
|
||||
<RecordContentFields
|
||||
section={{
|
||||
...templateFieldSection,
|
||||
fields: otherFields,
|
||||
}}
|
||||
/>
|
||||
</>
|
||||
) : null}
|
||||
{editingOffering ? (
|
||||
<Button
|
||||
htmlType="button"
|
||||
onClick={() =>
|
||||
navigate("/admin/brand", {
|
||||
state: {
|
||||
targetKey: visualOfferingTarget.key,
|
||||
recordId: editingOffering.id,
|
||||
},
|
||||
})
|
||||
}
|
||||
>
|
||||
在小程序页面编辑
|
||||
</Button>
|
||||
) : null}
|
||||
</>
|
||||
) : null}
|
||||
</Form>
|
||||
</div>
|
||||
</Modal>
|
||||
<OfferingsTable
|
||||
pageLabel={offeringPageLabel(workspace.data?.templateContent ?? undefined)}
|
||||
detailSectionTitles={sections
|
||||
.filter((section) => section.target === "offering" && section.page === "detail")
|
||||
.map((section) => section.title)}
|
||||
items={offerings.data ?? []}
|
||||
loading={offerings.isLoading}
|
||||
saveError={mutations.saveOffering.error}
|
||||
toggleOffering={mutations.toggleOffering}
|
||||
deleteOffering={mutations.deleteOffering}
|
||||
onEdit={(item: Offering) => editor.beginOffering(item)}
|
||||
/>
|
||||
<OfferingEditorModal
|
||||
open={editor.offeringOpen}
|
||||
editingOffering={editor.editingOffering}
|
||||
form={editor.offeringForm}
|
||||
previewPage={editor.previewPage}
|
||||
previewWorkspace={previewWorkspaceDraft}
|
||||
previewTargets={previewTargets}
|
||||
activeTemplateFields={activeTemplateFields}
|
||||
templateFieldSection={editor.templateFieldSection}
|
||||
hasTemplateDetailCopy={hasTemplateDetailCopy(templateFields)}
|
||||
listTarget={listTarget}
|
||||
detailTarget={detailTarget}
|
||||
saving={mutations.saveOffering.isPending}
|
||||
onClose={editor.closeOffering}
|
||||
onPreviewPageChange={(page: PreviewPage) => editor.setPreviewPage(page)}
|
||||
onValuesChange={(values) => editor.handleValuesChange(null, values)}
|
||||
onFinish={(values) => mutations.saveOffering.mutate(values)}
|
||||
onEditInBrand={navigateToBrand}
|
||||
/>
|
||||
</QueryState>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
import type {
|
||||
AdminTemplateContent,
|
||||
Offering,
|
||||
TemplateAdminField,
|
||||
} from "@personal-brand/api-client";
|
||||
import {
|
||||
applyPresentationValues,
|
||||
presentationFieldName,
|
||||
readPresentationValue,
|
||||
} from "../../lib/presentation/presentation-bindings.js";
|
||||
|
||||
export type OfferingFormValues = Record<string, unknown>;
|
||||
|
||||
export function offeringTemplateFields(
|
||||
sections: AdminTemplateContent["admin"]["sections"],
|
||||
): TemplateAdminField[] {
|
||||
return sections
|
||||
.filter((section) => section.target === "offering")
|
||||
.flatMap((section) =>
|
||||
section.fields.filter((field) => field.binding.startsWith("offering.config.")),
|
||||
);
|
||||
}
|
||||
|
||||
export function offeringDefaultFormValues(
|
||||
templateFields: TemplateAdminField[],
|
||||
): OfferingFormValues {
|
||||
return {
|
||||
kind: "service",
|
||||
isEnabled: true,
|
||||
sortOrder: 0,
|
||||
...Object.fromEntries(
|
||||
templateFields.map((field) => [
|
||||
presentationFieldName("offering", field.key),
|
||||
field.input === "list" ? [] : undefined,
|
||||
]),
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
export function offeringEditFormValues(
|
||||
item: Offering,
|
||||
templateFields: TemplateAdminField[],
|
||||
): OfferingFormValues {
|
||||
return {
|
||||
kind: item.kind,
|
||||
name: item.name,
|
||||
summary: item.summary ?? "",
|
||||
description: item.description ?? "",
|
||||
priceText: item.priceText ?? "",
|
||||
coverUrl: item.coverUrl ?? "",
|
||||
sortOrder: item.sortOrder,
|
||||
isEnabled: item.isEnabled,
|
||||
...Object.fromEntries(
|
||||
templateFields.map((field) => {
|
||||
const value = readPresentationValue(item.config, field.binding, field);
|
||||
return [
|
||||
presentationFieldName("offering", field.key),
|
||||
value === undefined || value === null || value === ""
|
||||
? field.input === "select"
|
||||
? field.options?.[0]?.value
|
||||
: field.input === "list"
|
||||
? []
|
||||
: undefined
|
||||
: value,
|
||||
];
|
||||
}),
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
export function buildOfferingRequestBody(
|
||||
values: OfferingFormValues,
|
||||
editingOffering: Offering | null,
|
||||
templateFields: TemplateAdminField[],
|
||||
): Record<string, unknown> {
|
||||
const fields = Object.fromEntries(
|
||||
Object.entries(values).filter(([key]) => key !== "config" && !key.startsWith("offering:")),
|
||||
);
|
||||
return {
|
||||
...fields,
|
||||
config: applyPresentationValues(
|
||||
editingOffering?.config,
|
||||
[{ key: "offering", fields: templateFields }],
|
||||
values,
|
||||
),
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import type { AdminTemplateContent, TemplateAdminField } from "@personal-brand/api-client";
|
||||
|
||||
export function offeringPageLabel(templateContent?: AdminTemplateContent): string {
|
||||
return (
|
||||
templateContent?.navigation.find((item) => item.page === "offerings")?.label ?? "业务展示页"
|
||||
);
|
||||
}
|
||||
|
||||
export function detailPageLabel(templateContent?: AdminTemplateContent): string {
|
||||
return templateContent?.navigation.find((item) => item.page === "detail")?.label ?? "详情页";
|
||||
}
|
||||
|
||||
export function hasTemplateDetailCopy(templateFields: TemplateAdminField[]): boolean {
|
||||
return templateFields.some((field) => field.binding === "offering.config.details.background");
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
import type {
|
||||
AdminTemplateContent,
|
||||
Offering,
|
||||
RuntimeWorkspace,
|
||||
TemplateAdminField,
|
||||
} from "@personal-brand/api-client";
|
||||
import type { PreviewTarget } from "../brand/preview-selection.js";
|
||||
import { applyPresentationValues } from "../../lib/presentation/presentation-bindings.js";
|
||||
|
||||
export function previewTargetsByPage(
|
||||
sections: AdminTemplateContent["admin"]["sections"],
|
||||
): Record<"offerings" | "detail", PreviewTarget[]> {
|
||||
const result: Record<"offerings" | "detail", PreviewTarget[]> = {
|
||||
offerings: [],
|
||||
detail: [],
|
||||
};
|
||||
for (const page of ["offerings", "detail"] as const) {
|
||||
result[page] = sections
|
||||
.filter((section) => section.page === page)
|
||||
.flatMap((section) =>
|
||||
(section.previewTargets ?? []).map((target) => ({
|
||||
...target,
|
||||
page: section.page,
|
||||
source: section.fields.some(
|
||||
(field) => field.binding.startsWith("offering.") && field.previewTarget === target.key,
|
||||
)
|
||||
? "offering"
|
||||
: section.target,
|
||||
})),
|
||||
);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
export function buildOfferingPreviewWorkspace(options: {
|
||||
previewWorkspace: RuntimeWorkspace;
|
||||
editingOffering: Offering;
|
||||
templateFields: TemplateAdminField[];
|
||||
formValues: Record<string, unknown>;
|
||||
}): RuntimeWorkspace {
|
||||
const { previewWorkspace, editingOffering, templateFields, formValues } = options;
|
||||
const config = applyPresentationValues(
|
||||
editingOffering.config,
|
||||
[{ key: "offering", fields: templateFields }],
|
||||
formValues,
|
||||
);
|
||||
const offeringValues = {
|
||||
name: formValues.name,
|
||||
summary: formValues.summary,
|
||||
description: formValues.description,
|
||||
priceText: formValues.priceText,
|
||||
coverUrl: formValues.coverUrl,
|
||||
};
|
||||
return {
|
||||
...previewWorkspace,
|
||||
offerings: previewWorkspace.offerings.map((item) =>
|
||||
item.id === editingOffering.id
|
||||
? {
|
||||
...item,
|
||||
name:
|
||||
typeof offeringValues.name === "string" && offeringValues.name.trim()
|
||||
? offeringValues.name
|
||||
: item.name,
|
||||
summary:
|
||||
typeof offeringValues.summary === "string" ? offeringValues.summary : item.summary,
|
||||
priceText:
|
||||
typeof offeringValues.priceText === "string"
|
||||
? offeringValues.priceText
|
||||
: item.priceText,
|
||||
coverUrl:
|
||||
typeof offeringValues.coverUrl === "string" && offeringValues.coverUrl.trim()
|
||||
? offeringValues.coverUrl
|
||||
: item.coverUrl,
|
||||
config,
|
||||
presentation: {
|
||||
...item.presentation,
|
||||
...config,
|
||||
...(config.presentation && typeof config.presentation === "object"
|
||||
? (config.presentation as Record<string, unknown>)
|
||||
: {}),
|
||||
...(typeof config.area === "string" ? { area: config.area } : {}),
|
||||
...(typeof config.series === "string" ? { series: config.series } : {}),
|
||||
...(typeof config.spaceType === "string" ? { spaceType: config.spaceType } : {}),
|
||||
heroImage:
|
||||
typeof config.detailHero === "string"
|
||||
? config.detailHero
|
||||
: typeof offeringValues.coverUrl === "string" && offeringValues.coverUrl.trim()
|
||||
? offeringValues.coverUrl
|
||||
: (item.coverUrl ?? null),
|
||||
details: {
|
||||
...item.presentation.details,
|
||||
...(config.details && typeof config.details === "object"
|
||||
? {
|
||||
...item.presentation.details,
|
||||
...(config.details as Record<string, unknown>),
|
||||
}
|
||||
: {}),
|
||||
},
|
||||
},
|
||||
}
|
||||
: item,
|
||||
),
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import type { Offering } from "@personal-brand/api-client";
|
||||
import { message } from "antd";
|
||||
import { useMemo } from "react";
|
||||
import { createApiClient } from "../../lib/api.js";
|
||||
import {
|
||||
buildOfferingRequestBody,
|
||||
offeringTemplateFields,
|
||||
type OfferingFormValues,
|
||||
} from "./offering-form.js";
|
||||
|
||||
export function useOfferingQueries() {
|
||||
const client = createApiClient();
|
||||
const offerings = useQuery({
|
||||
queryKey: ["admin-offerings"],
|
||||
queryFn: () => client.listAdminOfferings(),
|
||||
refetchOnMount: "always",
|
||||
});
|
||||
const workspace = useQuery({
|
||||
queryKey: ["admin-workspace-offering-fields"],
|
||||
queryFn: () => client.getAdminWorkspace(),
|
||||
});
|
||||
const previewWorkspace = useQuery({
|
||||
queryKey: ["admin-preview-workspace-services"],
|
||||
queryFn: () => client.getAdminPreviewWorkspace(),
|
||||
refetchOnMount: "always",
|
||||
});
|
||||
const templateFields = useMemo(
|
||||
() => offeringTemplateFields(workspace.data?.templateContent?.admin.sections ?? []),
|
||||
[workspace.data?.templateContent?.admin.sections],
|
||||
);
|
||||
return {
|
||||
offerings,
|
||||
workspace,
|
||||
previewWorkspace,
|
||||
templateFields,
|
||||
retry: () => {
|
||||
void offerings.refetch();
|
||||
void workspace.refetch();
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export function useOfferingMutations(options: {
|
||||
editingOffering: Offering | null;
|
||||
templateFields: ReturnType<typeof offeringTemplateFields>;
|
||||
onSuccess: () => void;
|
||||
}) {
|
||||
const client = createApiClient();
|
||||
const queryClient = useQueryClient();
|
||||
const invalidateAfterSave = () => {
|
||||
void queryClient.invalidateQueries({ queryKey: ["admin-offerings"] });
|
||||
void queryClient.invalidateQueries({ queryKey: ["admin-workspace-offering-fields"] });
|
||||
void queryClient.invalidateQueries({ queryKey: ["admin-preview-workspace-services"] });
|
||||
};
|
||||
const saveOffering = useMutation({
|
||||
mutationFn: (values: OfferingFormValues) =>
|
||||
options.editingOffering
|
||||
? client.updateAdminOffering(
|
||||
options.editingOffering.id,
|
||||
buildOfferingRequestBody(values, options.editingOffering, options.templateFields),
|
||||
)
|
||||
: client.createAdminOffering(
|
||||
buildOfferingRequestBody(values, null, options.templateFields) as Omit<
|
||||
Offering,
|
||||
"id" | "brandId"
|
||||
>,
|
||||
),
|
||||
onSuccess: () => {
|
||||
message.success("业务提供项已保存");
|
||||
invalidateAfterSave();
|
||||
options.onSuccess();
|
||||
},
|
||||
});
|
||||
const deleteOffering = useMutation({
|
||||
mutationFn: (id: string) => client.deleteAdminOffering(id),
|
||||
onSuccess: () => {
|
||||
message.success("业务提供项已删除");
|
||||
void queryClient.invalidateQueries({ queryKey: ["admin-offerings"] });
|
||||
},
|
||||
});
|
||||
const toggleOffering = useMutation({
|
||||
mutationFn: ({ id, isEnabled }: { id: string; isEnabled: boolean }) =>
|
||||
client.updateAdminOffering(id, { isEnabled }),
|
||||
onSuccess: () => {
|
||||
message.success("业务提供项状态已更新");
|
||||
void queryClient.invalidateQueries({ queryKey: ["admin-offerings"] });
|
||||
},
|
||||
});
|
||||
return { saveOffering, deleteOffering, toggleOffering };
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
import { Form } from "antd";
|
||||
import { useMemo, useState } from "react";
|
||||
import type {
|
||||
Offering,
|
||||
TemplateAdminField,
|
||||
TemplateAdminSection,
|
||||
} from "@personal-brand/api-client";
|
||||
import { offeringDefaultFormValues, offeringEditFormValues } from "./offering-form.js";
|
||||
|
||||
export type OfferingPreviewPage = "offerings" | "detail";
|
||||
|
||||
export function useOfferingEditor(templateFields: TemplateAdminField[]) {
|
||||
const [offeringForm] = Form.useForm();
|
||||
const [offeringOpen, setOfferingOpen] = useState(false);
|
||||
const [editingOffering, setEditingOffering] = useState<Offering | null>(null);
|
||||
const [offeringDraftVersion, setOfferingDraftVersion] = useState(0);
|
||||
const [previewPage, setPreviewPage] = useState<OfferingPreviewPage>("detail");
|
||||
const [formValues, setFormValues] = useState<Record<string, unknown>>({});
|
||||
|
||||
const templateFieldSection = useMemo<TemplateAdminSection>(
|
||||
() => ({
|
||||
key: "offering",
|
||||
title: "模板内容",
|
||||
description: "",
|
||||
page: "detail",
|
||||
target: "offering",
|
||||
fields: templateFields,
|
||||
}),
|
||||
[templateFields],
|
||||
);
|
||||
|
||||
const beginOffering = (item?: Offering) => {
|
||||
setEditingOffering(item ?? null);
|
||||
setPreviewPage("detail");
|
||||
setOfferingOpen(true);
|
||||
offeringForm.setFieldsValue(
|
||||
item
|
||||
? offeringEditFormValues(item, templateFields)
|
||||
: offeringDefaultFormValues(templateFields),
|
||||
);
|
||||
setFormValues(offeringForm.getFieldsValue(true) as Record<string, unknown>);
|
||||
};
|
||||
|
||||
const closeOffering = () => {
|
||||
setOfferingOpen(false);
|
||||
setEditingOffering(null);
|
||||
offeringForm.resetFields();
|
||||
};
|
||||
|
||||
const handleValuesChange = (_: unknown, allValues: Record<string, unknown>) => {
|
||||
setFormValues(allValues);
|
||||
setOfferingDraftVersion((version) => version + 1);
|
||||
};
|
||||
|
||||
return {
|
||||
offeringForm,
|
||||
offeringOpen,
|
||||
editingOffering,
|
||||
previewPage,
|
||||
templateFieldSection,
|
||||
formValues,
|
||||
offeringDraftVersion,
|
||||
setPreviewPage,
|
||||
beginOffering,
|
||||
closeOffering,
|
||||
handleValuesChange,
|
||||
};
|
||||
}
|
||||
@@ -1,23 +1,12 @@
|
||||
import {
|
||||
Alert,
|
||||
Button,
|
||||
Card,
|
||||
Form,
|
||||
Input,
|
||||
Modal,
|
||||
Select,
|
||||
Space,
|
||||
Table,
|
||||
Tag,
|
||||
Typography,
|
||||
message,
|
||||
} from "antd";
|
||||
import { Alert, Button, Card, Form, Input, Modal, Select, Space, Table, message } from "antd";
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import type { AdminBrandMember } from "@personal-brand/api-client";
|
||||
import { useState } from "react";
|
||||
import { createApiClient } from "../../lib/api.js";
|
||||
import { AdminPageHeader } from "../../components/AdminPageHeader.js";
|
||||
import { MutationError, QueryState } from "../../components/QueryState.js";
|
||||
import { EmptyState } from "../../components/EmptyState.js";
|
||||
import { StatusTag } from "../../components/StatusTag.js";
|
||||
|
||||
const roleLabels: Record<string, string> = {
|
||||
owner: "负责人",
|
||||
@@ -81,14 +70,22 @@ export function MembersPage() {
|
||||
<Alert
|
||||
type="info"
|
||||
showIcon
|
||||
className="admin-offset-bottom"
|
||||
message="请将初始账号和密码安全地交给成员"
|
||||
description="当前采用负责人手动添加方式;系统不会再次显示成员初始密码。"
|
||||
style={{ marginBottom: 16 }}
|
||||
/>
|
||||
<Table
|
||||
rowKey="id"
|
||||
loading={members.isLoading}
|
||||
dataSource={members.data ?? []}
|
||||
locale={{
|
||||
emptyText: (
|
||||
<EmptyState
|
||||
compact
|
||||
title="还没有其他成员"
|
||||
description="添加协作者后,他们可以按角色维护当前品牌。"
|
||||
/>
|
||||
),
|
||||
}}
|
||||
columns={[
|
||||
{
|
||||
title: "成员",
|
||||
@@ -127,9 +124,12 @@ export function MembersPage() {
|
||||
title: "说明",
|
||||
render: (_: unknown, item: AdminBrandMember) => (
|
||||
<Space>
|
||||
<Tag>{roleLabels[item.role] ?? item.role}</Tag>
|
||||
<StatusTag
|
||||
tone={item.role === "owner" ? "info" : "neutral"}
|
||||
label={roleLabels[item.role] ?? item.role}
|
||||
/>
|
||||
{!item.adminUser.isEnabled ? (
|
||||
<Typography.Text type="danger">账号已停用</Typography.Text>
|
||||
<StatusTag tone="warning" label="账号已停用" />
|
||||
) : null}
|
||||
</Space>
|
||||
),
|
||||
@@ -148,7 +148,7 @@ export function MembersPage() {
|
||||
}}
|
||||
onOk={() => addForm.submit()}
|
||||
confirmLoading={create.isPending}
|
||||
destroyOnClose
|
||||
destroyOnHidden
|
||||
>
|
||||
<Form
|
||||
form={addForm}
|
||||
@@ -169,14 +169,14 @@ export function MembersPage() {
|
||||
label="登录账号"
|
||||
rules={[{ required: true, message: "请输入登录账号" }]}
|
||||
>
|
||||
<Input placeholder="例如:linran" />
|
||||
<Input placeholder="例如:brand-owner" />
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
name="displayName"
|
||||
label="成员姓名"
|
||||
rules={[{ required: true, message: "请输入成员姓名" }]}
|
||||
>
|
||||
<Input placeholder="例如:林然" />
|
||||
<Input placeholder="例如:品牌主理人" />
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
name="password"
|
||||
|
||||
@@ -1,185 +1,55 @@
|
||||
import {
|
||||
Button,
|
||||
Divider,
|
||||
Form,
|
||||
Input,
|
||||
List,
|
||||
Modal,
|
||||
Popconfirm,
|
||||
Select,
|
||||
Space,
|
||||
Table,
|
||||
Tag,
|
||||
Typography,
|
||||
message,
|
||||
} from "antd";
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import { isTrustContentComplete } from "@personal-brand/api-client";
|
||||
import type {
|
||||
TemplateAdminField,
|
||||
TrustContent,
|
||||
TrustContentInput,
|
||||
} from "@personal-brand/api-client";
|
||||
import { useEffect, useState } from "react";
|
||||
import { useSearchParams } from "react-router-dom";
|
||||
import { createApiClient } from "../../lib/api.js";
|
||||
import { Button, Form } from "antd";
|
||||
import { AdminPageHeader } from "../../components/AdminPageHeader.js";
|
||||
import { ImageUrlField } from "../../components/ImageUrlField.js";
|
||||
import { TemplateListField } from "../../components/TemplateListField.js";
|
||||
import { MutationError, QueryState } from "../../components/QueryState.js";
|
||||
|
||||
const types = [
|
||||
{
|
||||
value: "schedule",
|
||||
label: "时间与服务安排",
|
||||
help: "说明你通常什么时候提供服务、接受预约或处理订单。多项内容可以分行填写。",
|
||||
},
|
||||
{
|
||||
value: "coverage",
|
||||
label: "服务范围与方式",
|
||||
help: "说明服务地点、覆盖范围、适用对象或承接边界。多项内容可以分行填写。",
|
||||
},
|
||||
{
|
||||
value: "process",
|
||||
label: "合作流程",
|
||||
help: "说明客户从提出需求到完成合作会经历哪些步骤,每行写一步。",
|
||||
},
|
||||
{
|
||||
value: "credential",
|
||||
label: "资质与专业证明",
|
||||
help: "说明资质、经验、制作标准或让客户放心的专业依据。",
|
||||
},
|
||||
{
|
||||
value: "case",
|
||||
label: "案例与客户反馈",
|
||||
help: "写代表性案例、服务结果或客户评价,多条内容可以分行填写。",
|
||||
},
|
||||
{
|
||||
value: "promise",
|
||||
label: "服务承诺与响应说明",
|
||||
help: "说明回复时间、交付承诺、售后方式或合作预期。",
|
||||
},
|
||||
];
|
||||
type TrustTypeOption = {
|
||||
type: string;
|
||||
label: string;
|
||||
adminFields: {
|
||||
title: string;
|
||||
summary: string;
|
||||
content: string;
|
||||
summaryHelp?: string;
|
||||
summaryPlaceholder?: string;
|
||||
};
|
||||
pages?: string[];
|
||||
help?: string;
|
||||
placeholder?: string;
|
||||
required?: boolean;
|
||||
configFields?: TemplateAdminField[];
|
||||
hideStandardFields?: Array<"summary" | "content">;
|
||||
maxPublishedItems?: number;
|
||||
};
|
||||
const fallbackTypes: TrustTypeOption[] = types.map(({ value, label, help }) => ({
|
||||
type: value,
|
||||
label,
|
||||
adminFields: { title: "标题", summary: "摘要", content: "详细内容" },
|
||||
help,
|
||||
}));
|
||||
import { AdminSection } from "../../components/AdminSection.js";
|
||||
import { QueryState } from "../../components/QueryState.js";
|
||||
import { StatusTag } from "../../components/StatusTag.js";
|
||||
import { TrustContentEditorModal } from "./components/TrustContentEditorModal.js";
|
||||
import { TrustContentList } from "./components/TrustContentList.js";
|
||||
import { TrustRequirementsList } from "./components/TrustRequirementsList.js";
|
||||
import type { TrustTypeOption } from "./domain/trust-content-domain.js";
|
||||
import {
|
||||
createTrustPageLabelResolver,
|
||||
groupTrustContentByType,
|
||||
selectTrustTypeOptions,
|
||||
sortTrustContentByTypeOrder,
|
||||
} from "./domain/trust-content-domain.js";
|
||||
import { useTrustContentEditor } from "./hooks/useTrustContentEditor.js";
|
||||
import { useTrustContentQueries } from "./hooks/useTrustContentQueries.js";
|
||||
|
||||
export function TrustContentPage() {
|
||||
const client = createApiClient();
|
||||
const queryClient = useQueryClient();
|
||||
const [editing, setEditing] = useState<TrustContent | null>(null);
|
||||
const [open, setOpen] = useState(false);
|
||||
const [form] = Form.useForm<TrustContentInput>();
|
||||
const [searchParams] = useSearchParams();
|
||||
const selectedType = Form.useWatch("type", form);
|
||||
const query = useQuery({
|
||||
queryKey: ["trust-content"],
|
||||
queryFn: () => client.listAdminTrustContent(),
|
||||
const { query, workspace } = useTrustContentQueries();
|
||||
const availableTypes = selectTrustTypeOptions(workspace.data?.templateContent?.trustContentTypes);
|
||||
const pageLabel = createTrustPageLabelResolver(workspace.data?.templateContent?.navigation);
|
||||
const items = sortTrustContentByTypeOrder(query.data ?? [], availableTypes);
|
||||
const contentByType = groupTrustContentByType(items);
|
||||
const firstMissingRequiredType =
|
||||
availableTypes.find((item) => item.required && !contentByType.has(item.type))?.type ??
|
||||
availableTypes[0]?.type ??
|
||||
"credential";
|
||||
const {
|
||||
begin,
|
||||
closeEditor,
|
||||
editing,
|
||||
form: editorForm,
|
||||
open,
|
||||
remove,
|
||||
save,
|
||||
} = useTrustContentEditor({
|
||||
availableTypes,
|
||||
contentByType,
|
||||
firstMissingRequiredType,
|
||||
});
|
||||
const workspace = useQuery({
|
||||
queryKey: ["admin-workspace-trust-types"],
|
||||
queryFn: () => client.getAdminWorkspace(),
|
||||
});
|
||||
const availableTypes: TrustTypeOption[] = workspace.data?.templateContent?.trustContentTypes
|
||||
?.length
|
||||
? workspace.data.templateContent.trustContentTypes
|
||||
: fallbackTypes;
|
||||
const pageLabel = (page: string) =>
|
||||
workspace.data?.templateContent?.navigation.find((item) => item.page === page)?.label ??
|
||||
(
|
||||
{ home: "首页", offerings: "业务展示页", detail: "详情页", profile: "主理人页" } as Record<
|
||||
string,
|
||||
string
|
||||
>
|
||||
)[page] ??
|
||||
page;
|
||||
const selectedType = Form.useWatch("type", editorForm);
|
||||
const selectedTypeMeta: TrustTypeOption | undefined = availableTypes.find(
|
||||
(item) => item.type === selectedType,
|
||||
);
|
||||
const trustPageLabels = [
|
||||
...new Set(availableTypes.flatMap((item) => item.pages ?? []).map(pageLabel)),
|
||||
];
|
||||
const trustPlacement = trustPageLabels.length
|
||||
? `小程序的${trustPageLabels.join("、")}中`
|
||||
: "小程序对应的信任展示区域中";
|
||||
const selectedTypeMeta = availableTypes.find((item) => item.type === selectedType);
|
||||
const contentByType = new Map<string, TrustContent>();
|
||||
for (const item of query.data ?? []) {
|
||||
const current = contentByType.get(item.type);
|
||||
const hasConfig = Object.keys(item.config ?? {}).length > 0;
|
||||
const currentHasConfig = Object.keys(current?.config ?? {}).length > 0;
|
||||
if (
|
||||
!current ||
|
||||
(item.isPublished && !current.isPublished) ||
|
||||
(item.isPublished === current.isPublished && hasConfig && !currentHasConfig)
|
||||
) {
|
||||
contentByType.set(item.type, item);
|
||||
}
|
||||
}
|
||||
const firstMissingRequiredType =
|
||||
availableTypes.find((item) => item.required && !contentByType.has(item.type))?.type ??
|
||||
availableTypes[0]?.type ??
|
||||
"credential";
|
||||
const requestedType = searchParams.get("type");
|
||||
const save = useMutation({
|
||||
mutationFn: (values: TrustContentInput) =>
|
||||
editing
|
||||
? client.updateAdminTrustContent(editing.id, values)
|
||||
: client.createAdminTrustContent(values),
|
||||
onSuccess: () => {
|
||||
message.success("品牌内容已保存为草稿,发布后小程序才会更新");
|
||||
setOpen(false);
|
||||
setEditing(null);
|
||||
form.resetFields();
|
||||
void queryClient.invalidateQueries({ queryKey: ["trust-content"] });
|
||||
},
|
||||
});
|
||||
const remove = useMutation({
|
||||
mutationFn: (id: string) => client.deleteAdminTrustContent(id),
|
||||
onSuccess: () => {
|
||||
message.success("品牌内容已删除");
|
||||
void queryClient.invalidateQueries({ queryKey: ["trust-content"] });
|
||||
},
|
||||
});
|
||||
const begin = (item?: TrustContent, type?: string) => {
|
||||
setEditing(item ?? null);
|
||||
setOpen(true);
|
||||
form.setFieldsValue(
|
||||
item
|
||||
? {
|
||||
type: item.type,
|
||||
title: item.title,
|
||||
...(item.summary ? { summary: item.summary } : {}),
|
||||
content: item.content,
|
||||
config: item.config ?? {},
|
||||
...(item.coverUrl ? { coverUrl: item.coverUrl } : {}),
|
||||
isPublished: item.isPublished,
|
||||
}
|
||||
: { type: type ?? firstMissingRequiredType, isPublished: false, config: {} },
|
||||
);
|
||||
};
|
||||
useEffect(() => {
|
||||
if (!requestedType || !availableTypes.some((item) => item.type === requestedType)) return;
|
||||
begin(contentByType.get(requestedType), requestedType);
|
||||
}, [requestedType, availableTypes.length]);
|
||||
|
||||
return (
|
||||
<QueryState
|
||||
loading={query.isLoading || workspace.isLoading}
|
||||
@@ -187,228 +57,54 @@ export function TrustContentPage() {
|
||||
onRetry={() => void Promise.all([query.refetch(), workspace.refetch()])}
|
||||
>
|
||||
<AdminPageHeader
|
||||
title="小程序内容:品牌介绍与信任"
|
||||
description={`填写真实的经历、案例、资历、流程和服务说明。这些内容会显示在${trustPlacement};保存后需发布品牌,小程序才会更新。`}
|
||||
title="信任内容"
|
||||
description={`填写真实的经历、案例、资历、流程与服务说明,发布品牌后即会展示在${trustPlacement}。`}
|
||||
extra={
|
||||
<Button type="primary" onClick={() => begin()}>
|
||||
添加品牌内容
|
||||
</Button>
|
||||
}
|
||||
/>
|
||||
<section aria-labelledby="trust-requirements-title">
|
||||
<Typography.Title id="trust-requirements-title" level={5}>
|
||||
当前模板需要配置的内容
|
||||
</Typography.Title>
|
||||
<Typography.Paragraph type="secondary">
|
||||
标记为“发布必填”的项目需要填写完整后,才能发布小程序。
|
||||
</Typography.Paragraph>
|
||||
<List
|
||||
size="small"
|
||||
dataSource={availableTypes}
|
||||
renderItem={(item) => {
|
||||
const content = contentByType.get(item.type);
|
||||
const publishedCount = (query.data ?? []).filter(
|
||||
(record) => record.type === item.type && record.isPublished,
|
||||
).length;
|
||||
const tooMany =
|
||||
item.maxPublishedItems !== undefined && publishedCount > item.maxPublishedItems;
|
||||
const complete = Boolean(content && isTrustContentComplete(content, item) && !tooMany);
|
||||
return (
|
||||
<List.Item
|
||||
actions={[
|
||||
<Button
|
||||
key={item.type}
|
||||
type="link"
|
||||
size="small"
|
||||
onClick={() => (content ? begin(content) : begin(undefined, item.type))}
|
||||
>
|
||||
{content ? "编辑" : "新增"}
|
||||
</Button>,
|
||||
]}
|
||||
>
|
||||
<Space wrap>
|
||||
<Typography.Text strong>{item.label}</Typography.Text>
|
||||
{item.required && <Tag color="orange">发布必填</Tag>}
|
||||
{(item.pages ?? []).map((page) => (
|
||||
<Tag key={page}>{pageLabel(page)}</Tag>
|
||||
))}
|
||||
<Tag color={complete ? "success" : "default"}>
|
||||
{tooMany
|
||||
? `公开内容过多(${publishedCount} 条)`
|
||||
: complete
|
||||
? "内容完整"
|
||||
: content
|
||||
? "需要完善"
|
||||
: "尚未填写"}
|
||||
</Tag>
|
||||
{item.help && <Typography.Text type="secondary">{item.help}</Typography.Text>}
|
||||
</Space>
|
||||
</List.Item>
|
||||
);
|
||||
}}
|
||||
/>
|
||||
</section>
|
||||
<Divider />
|
||||
<section aria-label="已配置的品牌内容">
|
||||
<Table
|
||||
rowKey="id"
|
||||
dataSource={query.data ?? []}
|
||||
locale={{ emptyText: "还没有品牌内容,请先按上方模板要求添加。" }}
|
||||
columns={[
|
||||
{
|
||||
title: "内容类型",
|
||||
dataIndex: "type",
|
||||
render: (value) => (
|
||||
<Tag>{availableTypes.find((item) => item.type === value)?.label ?? value}</Tag>
|
||||
),
|
||||
},
|
||||
{ title: "标题", dataIndex: "title" },
|
||||
{
|
||||
title: "内容预览",
|
||||
ellipsis: { showTitle: true },
|
||||
render: (_value: unknown, item: TrustContent) => {
|
||||
const meta = availableTypes.find((type) => type.type === item.type);
|
||||
if (meta?.hideStandardFields?.includes("content")) {
|
||||
return (
|
||||
meta.configFields
|
||||
?.flatMap((field) => {
|
||||
const value = item.config?.[field.key];
|
||||
if (Array.isArray(value))
|
||||
return value.length ? [`${field.label}:${value.length} 项`] : [];
|
||||
return typeof value === "string" && value.trim()
|
||||
? [`${field.label}:${value}`]
|
||||
: [];
|
||||
})
|
||||
.join(";") || "尚未填写区块内容"
|
||||
);
|
||||
}
|
||||
return item.summary || item.content || "未填写";
|
||||
},
|
||||
},
|
||||
{
|
||||
title: "发布状态",
|
||||
dataIndex: "isPublished",
|
||||
render: (value) => (
|
||||
<Tag color={value ? "success" : "default"}>{value ? "随发布展示" : "草稿"}</Tag>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: "操作",
|
||||
render: (_: unknown, item: TrustContent) => (
|
||||
<Space>
|
||||
<Button size="small" onClick={() => begin(item)}>
|
||||
编辑
|
||||
</Button>
|
||||
<Popconfirm
|
||||
title="确认删除这条信任内容?"
|
||||
description="删除后需发布品牌,才会更新小程序展示。"
|
||||
onConfirm={() => remove.mutate(item.id)}
|
||||
>
|
||||
<Button size="small" danger loading={remove.isPending}>
|
||||
删除
|
||||
</Button>
|
||||
</Popconfirm>
|
||||
</Space>
|
||||
),
|
||||
},
|
||||
]}
|
||||
/>
|
||||
<MutationError error={remove.error} />
|
||||
</section>
|
||||
<Modal
|
||||
open={open}
|
||||
title={editing ? "编辑品牌内容" : "添加品牌内容"}
|
||||
onCancel={() => {
|
||||
setOpen(false);
|
||||
setEditing(null);
|
||||
form.resetFields();
|
||||
}}
|
||||
onOk={() => form.submit()}
|
||||
confirmLoading={save.isPending}
|
||||
destroyOnClose
|
||||
<AdminSection
|
||||
title="当前模板需要配置的内容"
|
||||
description="标记为「发布必填」的项目需要填写完整后,才能发布小程序。"
|
||||
>
|
||||
<Form
|
||||
form={form}
|
||||
layout="vertical"
|
||||
onFinish={(values) => save.mutate({ ...values, content: values.content ?? "" })}
|
||||
>
|
||||
<Form.Item name="type" label="内容类型" rules={[{ required: true }]}>
|
||||
<Select
|
||||
options={availableTypes.map((item) => ({ value: item.type, label: item.label }))}
|
||||
/>
|
||||
</Form.Item>
|
||||
{selectedTypeMeta?.pages?.length ? (
|
||||
<Typography.Paragraph type="secondary">
|
||||
这类内容会显示在:
|
||||
{selectedTypeMeta.pages.map(pageLabel).join("、")}
|
||||
</Typography.Paragraph>
|
||||
) : null}
|
||||
<Form.Item
|
||||
name="title"
|
||||
label={selectedTypeMeta?.adminFields.title ?? "标题"}
|
||||
rules={[{ required: true }]}
|
||||
>
|
||||
<Input placeholder="例如:服务过 30+ 位独立创作者" />
|
||||
</Form.Item>
|
||||
{!selectedTypeMeta?.hideStandardFields?.includes("summary") && (
|
||||
<Form.Item
|
||||
name="summary"
|
||||
label={selectedTypeMeta?.adminFields.summary ?? "摘要"}
|
||||
help={selectedTypeMeta?.adminFields.summaryHelp}
|
||||
>
|
||||
<Input placeholder={selectedTypeMeta?.adminFields.summaryPlaceholder} />
|
||||
</Form.Item>
|
||||
)}
|
||||
{!selectedTypeMeta?.hideStandardFields?.includes("content") && (
|
||||
<Form.Item
|
||||
name="content"
|
||||
label={selectedTypeMeta?.adminFields.content ?? "详细内容"}
|
||||
help={
|
||||
selectedTypeMeta?.help ?? "每行写一项,页面会按模板样式展示。不要填写 HTML 或代码。"
|
||||
}
|
||||
rules={[{ required: true }]}
|
||||
>
|
||||
<Input.TextArea
|
||||
rows={8}
|
||||
showCount
|
||||
maxLength={2000}
|
||||
placeholder={selectedTypeMeta?.placeholder ?? "例如:\n第一项内容\n第二项内容"}
|
||||
/>
|
||||
</Form.Item>
|
||||
)}
|
||||
{selectedTypeMeta?.configFields?.map((field) =>
|
||||
field.input === "list" ? (
|
||||
<TemplateListField key={field.key} field={field} name={["config", field.key]} />
|
||||
) : (
|
||||
<Form.Item
|
||||
key={field.key}
|
||||
name={["config", field.key]}
|
||||
label={field.label}
|
||||
help={field.help}
|
||||
rules={[{ required: field.required === true }]}
|
||||
>
|
||||
{field.input === "textarea" ? <Input.TextArea rows={3} /> : <Input />}
|
||||
</Form.Item>
|
||||
),
|
||||
)}
|
||||
<Form.Item
|
||||
name="coverUrl"
|
||||
label="配图地址"
|
||||
help="粘贴一张可公开访问的图片地址,保存前会显示预览。"
|
||||
>
|
||||
<ImageUrlField placeholder="粘贴案例或经历配图地址" />
|
||||
</Form.Item>
|
||||
<Form.Item name="isPublished" label="公开状态">
|
||||
<Select
|
||||
options={[
|
||||
{ value: true, label: "随品牌发布展示" },
|
||||
{ value: false, label: "保存为草稿" },
|
||||
]}
|
||||
/>
|
||||
</Form.Item>
|
||||
<MutationError error={save.error} />
|
||||
</Form>
|
||||
</Modal>
|
||||
<TrustRequirementsList
|
||||
availableTypes={availableTypes}
|
||||
contentByType={contentByType}
|
||||
items={items}
|
||||
pageLabel={pageLabel}
|
||||
onEdit={begin}
|
||||
/>
|
||||
</AdminSection>
|
||||
<AdminSection
|
||||
title="已配置的品牌内容"
|
||||
description="同一类型可以保存多条;标记为草稿的内容不会随品牌发布展示。"
|
||||
extra={<StatusTag tone="info" label={`共 ${items.length} 条`} />}
|
||||
>
|
||||
<TrustContentList
|
||||
availableTypes={availableTypes}
|
||||
items={items}
|
||||
pageLabel={pageLabel}
|
||||
removeError={remove.error}
|
||||
removePendingId={remove.isPending ? remove.variables : undefined}
|
||||
onCreate={() => begin()}
|
||||
onEdit={(item) => begin(item)}
|
||||
onDelete={(id) => remove.mutate(id)}
|
||||
/>
|
||||
</AdminSection>
|
||||
<TrustContentEditorModal
|
||||
availableTypes={availableTypes}
|
||||
editing={editing}
|
||||
form={editorForm}
|
||||
open={open}
|
||||
pageLabel={pageLabel}
|
||||
saveError={save.error}
|
||||
savePending={save.isPending}
|
||||
selectedTypeMeta={selectedTypeMeta}
|
||||
onCancel={closeEditor}
|
||||
onFinish={(values) => save.mutate(values)}
|
||||
/>
|
||||
</QueryState>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
import { Form, Input, Modal, Select } from "antd";
|
||||
import type { FormInstance } from "antd";
|
||||
import type { TrustContent, TrustContentInput } from "@personal-brand/api-client";
|
||||
import { ImageUrlField } from "../../../components/ImageUrlField.js";
|
||||
import { TemplateListField } from "../../../components/TemplateListField.js";
|
||||
import { MutationError } from "../../../components/QueryState.js";
|
||||
import type { TrustTypeOption } from "../domain/trust-content-domain.js";
|
||||
|
||||
export function TrustContentEditorModal({
|
||||
availableTypes,
|
||||
editing,
|
||||
form,
|
||||
open,
|
||||
pageLabel,
|
||||
saveError,
|
||||
savePending,
|
||||
selectedTypeMeta,
|
||||
onCancel,
|
||||
onFinish,
|
||||
}: {
|
||||
availableTypes: TrustTypeOption[];
|
||||
editing: TrustContent | null;
|
||||
form: FormInstance<TrustContentInput>;
|
||||
open: boolean;
|
||||
pageLabel: (page: string) => string;
|
||||
saveError: unknown;
|
||||
savePending: boolean;
|
||||
selectedTypeMeta?: TrustTypeOption | undefined;
|
||||
onCancel: () => void;
|
||||
onFinish: (values: TrustContentInput) => void;
|
||||
}) {
|
||||
return (
|
||||
<Modal
|
||||
open={open}
|
||||
title={editing ? "编辑品牌内容" : "添加品牌内容"}
|
||||
onCancel={onCancel}
|
||||
onOk={() => form.submit()}
|
||||
confirmLoading={savePending}
|
||||
destroyOnHidden
|
||||
>
|
||||
<Form
|
||||
form={form}
|
||||
layout="vertical"
|
||||
onFinish={(values) => onFinish({ ...values, content: values.content ?? "" })}
|
||||
>
|
||||
<Form.Item name="type" label="内容类型" rules={[{ required: true }]}>
|
||||
<Select
|
||||
options={availableTypes.map((item) => ({ value: item.type, label: item.label }))}
|
||||
/>
|
||||
</Form.Item>
|
||||
{selectedTypeMeta?.pages?.length ? (
|
||||
<p className="admin-section-description admin-offset-bottom">
|
||||
这类内容会显示在:{selectedTypeMeta.pages.map(pageLabel).join("、")}
|
||||
</p>
|
||||
) : null}
|
||||
<Form.Item
|
||||
name="title"
|
||||
label={selectedTypeMeta?.adminFields.title ?? "标题"}
|
||||
rules={[{ required: true }]}
|
||||
>
|
||||
<Input placeholder="例如:服务过 30+ 位独立创作者" />
|
||||
</Form.Item>
|
||||
{!selectedTypeMeta?.hideStandardFields?.includes("summary") && (
|
||||
<Form.Item
|
||||
name="summary"
|
||||
label={selectedTypeMeta?.adminFields.summary ?? "摘要"}
|
||||
help={selectedTypeMeta?.adminFields.summaryHelp}
|
||||
>
|
||||
<Input placeholder={selectedTypeMeta?.adminFields.summaryPlaceholder} />
|
||||
</Form.Item>
|
||||
)}
|
||||
{!selectedTypeMeta?.hideStandardFields?.includes("content") && (
|
||||
<Form.Item
|
||||
name="content"
|
||||
label={selectedTypeMeta?.adminFields.content ?? "详细内容"}
|
||||
help={
|
||||
selectedTypeMeta?.help ?? "每行写一项,页面会按模板样式展示。不要填写 HTML 或代码。"
|
||||
}
|
||||
rules={[{ required: true }]}
|
||||
>
|
||||
<Input.TextArea
|
||||
rows={8}
|
||||
showCount
|
||||
maxLength={2000}
|
||||
placeholder={selectedTypeMeta?.placeholder ?? "例如:\n第一项内容\n第二项内容"}
|
||||
/>
|
||||
</Form.Item>
|
||||
)}
|
||||
{selectedTypeMeta?.configFields?.map((field) =>
|
||||
field.input === "list" ? (
|
||||
<TemplateListField key={field.key} field={field} name={["config", field.key]} />
|
||||
) : (
|
||||
<Form.Item
|
||||
key={field.key}
|
||||
name={["config", field.key]}
|
||||
label={field.label}
|
||||
help={field.help}
|
||||
rules={[{ required: field.required === true }]}
|
||||
>
|
||||
{field.input === "textarea" ? <Input.TextArea rows={3} /> : <Input />}
|
||||
</Form.Item>
|
||||
),
|
||||
)}
|
||||
<Form.Item
|
||||
name="coverUrl"
|
||||
label="配图地址"
|
||||
help="粘贴一张可公开访问的图片地址,保存前会显示预览。"
|
||||
>
|
||||
<ImageUrlField placeholder="粘贴案例或经历配图地址" scope="trust" />
|
||||
</Form.Item>
|
||||
<Form.Item name="isPublished" label="公开状态">
|
||||
<Select
|
||||
options={[
|
||||
{ value: true, label: "随品牌发布展示" },
|
||||
{ value: false, label: "保存为草稿" },
|
||||
]}
|
||||
/>
|
||||
</Form.Item>
|
||||
<MutationError error={saveError} />
|
||||
</Form>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
import { Button, Popconfirm } from "antd";
|
||||
import { FileTextOutlined } from "@ant-design/icons";
|
||||
import type { TrustContent } from "@personal-brand/api-client";
|
||||
import { EmptyState } from "../../../components/EmptyState.js";
|
||||
import { MutationError } from "../../../components/QueryState.js";
|
||||
import { StatusTag } from "../../../components/StatusTag.js";
|
||||
import type { TrustTypeOption } from "../domain/trust-content-domain.js";
|
||||
import { getTrustContentPreview } from "../domain/trust-content-domain.js";
|
||||
import { TrustContentTypeIcon } from "./TrustContentTypeIcon.js";
|
||||
|
||||
export function TrustContentList({
|
||||
availableTypes,
|
||||
items,
|
||||
pageLabel,
|
||||
removeError,
|
||||
removePendingId,
|
||||
onCreate,
|
||||
onEdit,
|
||||
onDelete,
|
||||
}: {
|
||||
availableTypes: TrustTypeOption[];
|
||||
items: TrustContent[];
|
||||
pageLabel: (page: string) => string;
|
||||
removeError: unknown;
|
||||
removePendingId?: string | undefined;
|
||||
onCreate: () => void;
|
||||
onEdit: (item: TrustContent) => void;
|
||||
onDelete: (id: string) => void;
|
||||
}) {
|
||||
if (!items.length) {
|
||||
return (
|
||||
<section aria-label="已配置的品牌内容">
|
||||
<EmptyState
|
||||
icon={<FileTextOutlined />}
|
||||
title="还没有品牌内容"
|
||||
description="按上方模板要求逐项添加,访客才能看到你的经历与证明。"
|
||||
action={<Button onClick={onCreate}>添加品牌内容</Button>}
|
||||
/>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<section aria-label="已配置的品牌内容">
|
||||
<ul className="admin-list">
|
||||
{items.map((item) => {
|
||||
const typeMeta = availableTypes.find((type) => type.type === item.type);
|
||||
const pages = (typeMeta?.pages ?? []).map(pageLabel);
|
||||
const meta = [typeMeta?.label ?? item.type]
|
||||
.concat(pages.length ? `展示于${pages.join("、")}` : [])
|
||||
.join(" · ");
|
||||
return (
|
||||
<li key={item.id} className="admin-row admin-record">
|
||||
<div className="admin-record__thumb">
|
||||
{item.coverUrl ? (
|
||||
<img src={item.coverUrl} alt="" loading="lazy" />
|
||||
) : (
|
||||
<TrustContentTypeIcon type={item.type} />
|
||||
)}
|
||||
</div>
|
||||
<div className="admin-row-main">
|
||||
<div className="admin-row-line">
|
||||
<span className="admin-row-title">{item.title}</span>
|
||||
<StatusTag
|
||||
tone={item.isPublished ? "success" : "neutral"}
|
||||
label={item.isPublished ? "已发布" : "草稿"}
|
||||
/>
|
||||
</div>
|
||||
<p className="admin-row-meta">{meta}</p>
|
||||
<p className="admin-row-summary">{getTrustContentPreview(item, typeMeta)}</p>
|
||||
</div>
|
||||
<div className="admin-record__actions">
|
||||
<Button type="link" size="small" onClick={() => onEdit(item)}>
|
||||
编辑
|
||||
</Button>
|
||||
<Popconfirm
|
||||
title="确认删除这条品牌内容?"
|
||||
description="删除后需发布品牌,才会更新小程序展示。"
|
||||
onConfirm={() => onDelete(item.id)}
|
||||
>
|
||||
<Button type="link" size="small" danger loading={removePendingId === item.id}>
|
||||
删除
|
||||
</Button>
|
||||
</Popconfirm>
|
||||
</div>
|
||||
</li>
|
||||
);
|
||||
})}
|
||||
</ul>
|
||||
<MutationError error={removeError} />
|
||||
</section>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import {
|
||||
ApartmentOutlined,
|
||||
ClockCircleOutlined,
|
||||
EnvironmentOutlined,
|
||||
FileTextOutlined,
|
||||
SafetyCertificateOutlined,
|
||||
StarOutlined,
|
||||
CheckCircleOutlined,
|
||||
} from "@ant-design/icons";
|
||||
import type { ReactNode } from "react";
|
||||
|
||||
// 类型图标只为让列表可扫读,模板未声明的类型回落到通用图标。
|
||||
const TYPE_ICONS: Record<string, ReactNode> = {
|
||||
schedule: <ClockCircleOutlined />,
|
||||
coverage: <EnvironmentOutlined />,
|
||||
process: <ApartmentOutlined />,
|
||||
credential: <SafetyCertificateOutlined />,
|
||||
case: <StarOutlined />,
|
||||
promise: <CheckCircleOutlined />,
|
||||
};
|
||||
|
||||
export function TrustContentTypeIcon({ type }: { type: string }) {
|
||||
return <>{TYPE_ICONS[type] ?? <FileTextOutlined />}</>;
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
import { Button } from "antd";
|
||||
import { isTrustContentComplete } from "@personal-brand/api-client";
|
||||
import type { TrustContent } from "@personal-brand/api-client";
|
||||
import type { TrustTypeOption } from "../domain/trust-content-domain.js";
|
||||
import { StatusTag } from "../../../components/StatusTag.js";
|
||||
|
||||
export function TrustRequirementsList({
|
||||
availableTypes,
|
||||
contentByType,
|
||||
items,
|
||||
pageLabel,
|
||||
onEdit,
|
||||
}: {
|
||||
availableTypes: TrustTypeOption[];
|
||||
contentByType: Map<string, TrustContent>;
|
||||
items: TrustContent[];
|
||||
pageLabel: (page: string) => string;
|
||||
onEdit: (item?: TrustContent, type?: string) => void;
|
||||
}) {
|
||||
return (
|
||||
<ul className="admin-list">
|
||||
{availableTypes.map((item) => {
|
||||
const content = contentByType.get(item.type);
|
||||
const publishedCount = items.filter(
|
||||
(record) => record.type === item.type && record.isPublished,
|
||||
).length;
|
||||
const configuredCount = items.filter((record) => record.type === item.type).length;
|
||||
const tooMany =
|
||||
item.maxPublishedItems !== undefined && publishedCount > item.maxPublishedItems;
|
||||
const complete = Boolean(content && isTrustContentComplete(content, item) && !tooMany);
|
||||
|
||||
return (
|
||||
<li key={item.type} className="admin-row">
|
||||
<div className="admin-row-main">
|
||||
<div className="admin-row-line">
|
||||
<span className="admin-row-title">{item.label}</span>
|
||||
{item.required ? <StatusTag tone="warning" label="发布必填" /> : null}
|
||||
<StatusTag
|
||||
tone={tooMany ? "error" : complete ? "success" : "neutral"}
|
||||
label={
|
||||
tooMany
|
||||
? `公开内容过多(${publishedCount} 条)`
|
||||
: complete
|
||||
? "内容完整"
|
||||
: content
|
||||
? "需要完善"
|
||||
: "尚未填写"
|
||||
}
|
||||
/>
|
||||
{configuredCount > 1 ? (
|
||||
<span className="admin-row-meta">已配置 {configuredCount} 条</span>
|
||||
) : null}
|
||||
{(item.pages ?? []).map((page) => (
|
||||
<span key={page} className="admin-row-meta">
|
||||
{pageLabel(page)}
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
{item.help ? <p className="admin-row-help">{item.help}</p> : null}
|
||||
</div>
|
||||
<Button
|
||||
type="link"
|
||||
size="small"
|
||||
onClick={() => (content ? onEdit(content) : onEdit(undefined, item.type))}
|
||||
>
|
||||
{content ? "编辑" : "新增"}
|
||||
</Button>
|
||||
</li>
|
||||
);
|
||||
})}
|
||||
</ul>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,152 @@
|
||||
import type { TemplateAdminField } from "@personal-brand/api-client";
|
||||
import type { TrustContent } from "@personal-brand/api-client";
|
||||
|
||||
export type TrustTypeOption = {
|
||||
type: string;
|
||||
label: string;
|
||||
adminFields: {
|
||||
title: string;
|
||||
summary: string;
|
||||
content: string;
|
||||
summaryHelp?: string;
|
||||
summaryPlaceholder?: string;
|
||||
};
|
||||
pages?: string[];
|
||||
help?: string;
|
||||
placeholder?: string;
|
||||
required?: boolean;
|
||||
configFields?: TemplateAdminField[];
|
||||
hideStandardFields?: Array<"summary" | "content">;
|
||||
maxPublishedItems?: number;
|
||||
};
|
||||
|
||||
const fallbackTypeSeeds = [
|
||||
{
|
||||
value: "schedule",
|
||||
label: "时间与服务安排",
|
||||
help: "说明你通常什么时候提供服务、接受预约或处理订单。多项内容可以分行填写。",
|
||||
},
|
||||
{
|
||||
value: "coverage",
|
||||
label: "服务范围与方式",
|
||||
help: "说明服务地点、覆盖范围、适用对象或承接边界。多项内容可以分行填写。",
|
||||
},
|
||||
{
|
||||
value: "process",
|
||||
label: "合作流程",
|
||||
help: "说明客户从提出需求到完成合作会经历哪些步骤,每行写一步。",
|
||||
},
|
||||
{
|
||||
value: "credential",
|
||||
label: "资质与专业证明",
|
||||
help: "说明资质、经验、制作标准或让客户放心的专业依据。",
|
||||
},
|
||||
{
|
||||
value: "case",
|
||||
label: "案例与客户反馈",
|
||||
help: "写代表性案例、服务结果或客户评价,多条内容可以分行填写。",
|
||||
},
|
||||
{
|
||||
value: "promise",
|
||||
label: "服务承诺与响应说明",
|
||||
help: "说明回复时间、交付承诺、售后方式或合作预期。",
|
||||
},
|
||||
];
|
||||
|
||||
export const fallbackTrustTypes: TrustTypeOption[] = fallbackTypeSeeds.map(
|
||||
({ value, label, help }) => ({
|
||||
type: value,
|
||||
label,
|
||||
adminFields: { title: "标题", summary: "摘要", content: "详细内容" },
|
||||
help,
|
||||
}),
|
||||
);
|
||||
|
||||
const pageLabels: Record<string, string> = {
|
||||
home: "首页",
|
||||
offerings: "业务展示页",
|
||||
service: "服务介绍页",
|
||||
detail: "详情页",
|
||||
profile: "主理人页",
|
||||
inquiry: "咨询页",
|
||||
};
|
||||
|
||||
export function createTrustPageLabelResolver(navigation?: Array<{ page: string; label: string }>) {
|
||||
return (page: string) =>
|
||||
navigation?.find((item) => item.page === page)?.label ?? pageLabels[page] ?? page;
|
||||
}
|
||||
|
||||
export function selectTrustTypeOptions(workspaceTypes?: TrustTypeOption[]): TrustTypeOption[] {
|
||||
return workspaceTypes?.length ? workspaceTypes : fallbackTrustTypes;
|
||||
}
|
||||
|
||||
export function groupTrustContentByType(items: TrustContent[]) {
|
||||
const contentByType = new Map<string, TrustContent>();
|
||||
|
||||
for (const item of items) {
|
||||
const current = contentByType.get(item.type);
|
||||
const hasConfig = Object.keys(item.config ?? {}).length > 0;
|
||||
const currentHasConfig = Object.keys(current?.config ?? {}).length > 0;
|
||||
|
||||
if (
|
||||
!current ||
|
||||
(item.isPublished && !current.isPublished) ||
|
||||
(item.isPublished === current.isPublished && hasConfig && !currentHasConfig)
|
||||
) {
|
||||
contentByType.set(item.type, item);
|
||||
}
|
||||
}
|
||||
|
||||
return contentByType;
|
||||
}
|
||||
|
||||
export function getTrustContentPreview(item: TrustContent, typeMeta?: TrustTypeOption): string {
|
||||
if (typeMeta?.hideStandardFields?.includes("content")) {
|
||||
const fragments =
|
||||
typeMeta.configFields?.flatMap((field) => {
|
||||
const value = item.config?.[field.key];
|
||||
if (Array.isArray(value)) {
|
||||
return value.length ? [`${field.label}:${value.length} 项`] : [];
|
||||
}
|
||||
if (typeof value !== "string") return [];
|
||||
const text = value.trim();
|
||||
return text ? [`${field.label}:${stripFieldLabel(field.label, text)}`] : [];
|
||||
}) ?? [];
|
||||
if (!fragments.length) return "尚未填写区块内容";
|
||||
return fragments.length > 3 ? `${fragments.slice(0, 3).join(";")}…` : fragments.join(";");
|
||||
}
|
||||
|
||||
return item.summary || item.content || "未填写";
|
||||
}
|
||||
|
||||
// 模板示例数据常把展示前缀写进值内(如“地点:…”),与字段名重复时去掉。
|
||||
function stripFieldLabel(label: string, value: string): string {
|
||||
const match = /^([^::]{1,8})[::]\s*/.exec(value);
|
||||
if (!match) return value;
|
||||
const token = (match[1] ?? "").trim();
|
||||
if (token && sharesMeaningfulOverlap(label, token)) return value.slice(match[0].length);
|
||||
return value;
|
||||
}
|
||||
|
||||
// 前缀与字段名只要有两个连续字重合,就视为重复标签。
|
||||
function sharesMeaningfulOverlap(label: string, token: string): boolean {
|
||||
if (token.length < 2) return label.includes(token);
|
||||
for (let index = 0; index + 2 <= token.length; index += 1) {
|
||||
if (label.includes(token.slice(index, index + 2))) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// 列表按模板声明的类型顺序排列,与「当前模板需要配置的内容」保持一致。
|
||||
export function sortTrustContentByTypeOrder(
|
||||
items: TrustContent[],
|
||||
availableTypes: TrustTypeOption[],
|
||||
): TrustContent[] {
|
||||
const orderOf = new Map(availableTypes.map((item, index) => [item.type, index]));
|
||||
return [...items].sort((left, right) => {
|
||||
const leftOrder = orderOf.get(left.type) ?? availableTypes.length;
|
||||
const rightOrder = orderOf.get(right.type) ?? availableTypes.length;
|
||||
if (leftOrder !== rightOrder) return leftOrder - rightOrder;
|
||||
return left.title.localeCompare(right.title, "zh-Hans-CN");
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { useSearchParams } from "react-router-dom";
|
||||
import { Form } from "antd";
|
||||
import type { TrustContent, TrustContentInput } from "@personal-brand/api-client";
|
||||
import type { TrustTypeOption } from "../domain/trust-content-domain.js";
|
||||
import { useTrustContentMutations } from "./useTrustContentMutations.js";
|
||||
|
||||
export function useTrustContentEditor({
|
||||
availableTypes,
|
||||
contentByType,
|
||||
firstMissingRequiredType,
|
||||
}: {
|
||||
availableTypes: TrustTypeOption[];
|
||||
contentByType: Map<string, TrustContent>;
|
||||
firstMissingRequiredType: string;
|
||||
}) {
|
||||
const [editing, setEditing] = useState<TrustContent | null>(null);
|
||||
const [open, setOpen] = useState(false);
|
||||
const [form] = Form.useForm<TrustContentInput>();
|
||||
const [searchParams] = useSearchParams();
|
||||
|
||||
const closeEditor = () => {
|
||||
setOpen(false);
|
||||
setEditing(null);
|
||||
form.resetFields();
|
||||
};
|
||||
|
||||
const { save, remove } = useTrustContentMutations({ editing, closeEditor });
|
||||
|
||||
const begin = (item?: TrustContent, type?: string) => {
|
||||
setEditing(item ?? null);
|
||||
setOpen(true);
|
||||
form.setFieldsValue(
|
||||
item
|
||||
? {
|
||||
type: item.type,
|
||||
title: item.title,
|
||||
...(item.summary ? { summary: item.summary } : {}),
|
||||
content: item.content,
|
||||
config: item.config ?? {},
|
||||
...(item.coverUrl ? { coverUrl: item.coverUrl } : {}),
|
||||
isPublished: item.isPublished,
|
||||
}
|
||||
: { type: type ?? firstMissingRequiredType, isPublished: false, config: {} },
|
||||
);
|
||||
};
|
||||
|
||||
const requestedType = searchParams.get("type");
|
||||
|
||||
useEffect(() => {
|
||||
if (!requestedType || !availableTypes.some((item) => item.type === requestedType)) return;
|
||||
begin(contentByType.get(requestedType), requestedType);
|
||||
}, [requestedType, availableTypes.length]);
|
||||
|
||||
return { begin, closeEditor, editing, form, open, remove, save };
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||
import { message } from "antd";
|
||||
import type { TrustContent, TrustContentInput } from "@personal-brand/api-client";
|
||||
import { createApiClient } from "../../../lib/api.js";
|
||||
|
||||
export function useTrustContentMutations({
|
||||
editing,
|
||||
closeEditor,
|
||||
}: {
|
||||
editing: TrustContent | null;
|
||||
closeEditor: () => void;
|
||||
}) {
|
||||
const client = createApiClient();
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
const save = useMutation({
|
||||
mutationFn: (values: TrustContentInput) =>
|
||||
editing
|
||||
? client.updateAdminTrustContent(editing.id, values)
|
||||
: client.createAdminTrustContent(values),
|
||||
onSuccess: () => {
|
||||
message.success("品牌内容已保存为草稿,发布后小程序才会更新");
|
||||
closeEditor();
|
||||
void queryClient.invalidateQueries({ queryKey: ["trust-content"] });
|
||||
},
|
||||
});
|
||||
|
||||
const remove = useMutation({
|
||||
mutationFn: (id: string) => client.deleteAdminTrustContent(id),
|
||||
onSuccess: () => {
|
||||
message.success("品牌内容已删除");
|
||||
void queryClient.invalidateQueries({ queryKey: ["trust-content"] });
|
||||
},
|
||||
});
|
||||
|
||||
return { save, remove };
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { createApiClient } from "../../../lib/api.js";
|
||||
|
||||
export function useTrustContentQueries() {
|
||||
const client = createApiClient();
|
||||
|
||||
return {
|
||||
query: useQuery({
|
||||
queryKey: ["trust-content"],
|
||||
queryFn: () => client.listAdminTrustContent(),
|
||||
}),
|
||||
workspace: useQuery({
|
||||
queryKey: ["admin-workspace-trust-types"],
|
||||
queryFn: () => client.getAdminWorkspace(),
|
||||
}),
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
import { message } from "antd";
|
||||
import { useMutation } from "@tanstack/react-query";
|
||||
import type { FormInstance } from "antd";
|
||||
import type { BrandFieldDefinition, InquiryForm } from "@personal-brand/api-client";
|
||||
import { createApiClient } from "../../lib/api.js";
|
||||
|
||||
interface FieldMutationOptions {
|
||||
client?: ReturnType<typeof createApiClient>;
|
||||
form: FormInstance<Record<string, unknown>>;
|
||||
queryClient: {
|
||||
invalidateQueries: (options: { queryKey: readonly unknown[] }) => Promise<void>;
|
||||
};
|
||||
onClose: () => void;
|
||||
}
|
||||
|
||||
export function useFieldMutations({
|
||||
client = createApiClient(),
|
||||
form,
|
||||
queryClient,
|
||||
onClose,
|
||||
}: FieldMutationOptions) {
|
||||
const createField = useMutation({
|
||||
mutationFn: (values: Omit<BrandFieldDefinition, "id" | "source">) =>
|
||||
client.createAdminField(values),
|
||||
onSuccess: () => {
|
||||
message.success("字段已创建");
|
||||
onClose();
|
||||
form.resetFields();
|
||||
void queryClient.invalidateQueries({ queryKey: ["admin-workspace"] });
|
||||
},
|
||||
});
|
||||
const removeField = useMutation({
|
||||
mutationFn: (id: string) => client.deleteAdminField(id),
|
||||
onSuccess: () => void queryClient.invalidateQueries({ queryKey: ["admin-workspace"] }),
|
||||
});
|
||||
return { createField, removeField };
|
||||
}
|
||||
|
||||
export function useInquiryFormMutations({
|
||||
client = createApiClient(),
|
||||
form,
|
||||
queryClient,
|
||||
onClose,
|
||||
}: {
|
||||
client?: ReturnType<typeof createApiClient>;
|
||||
form: FormInstance<Record<string, unknown>>;
|
||||
queryClient: {
|
||||
invalidateQueries: (options: { queryKey: readonly unknown[] }) => Promise<void>;
|
||||
};
|
||||
onClose: () => void;
|
||||
}) {
|
||||
const createForm = useMutation({
|
||||
mutationFn: (values: {
|
||||
name: string;
|
||||
offeringId?: string | null;
|
||||
purpose?: InquiryForm["purpose"];
|
||||
targetType?: InquiryForm["targetType"];
|
||||
submissionAction?: InquiryForm["submissionAction"];
|
||||
fieldsSnapshot: unknown[];
|
||||
}) => client.createAdminInquiryForm(values),
|
||||
onSuccess: () => {
|
||||
message.success("咨询表单已创建");
|
||||
onClose();
|
||||
form.resetFields();
|
||||
void queryClient.invalidateQueries({ queryKey: ["admin-inquiry-forms"] });
|
||||
},
|
||||
});
|
||||
const updateForm = useMutation({
|
||||
mutationFn: ({ id, body }: { id: string; body: Partial<InquiryForm> }) =>
|
||||
client.updateAdminInquiryForm(id, {
|
||||
...(body.name === undefined ? {} : { name: body.name }),
|
||||
...(body.offeringId === undefined ? {} : { offeringId: body.offeringId }),
|
||||
...(body.fieldsSnapshot === undefined ? {} : { fieldsSnapshot: body.fieldsSnapshot }),
|
||||
...(body.isEnabled === undefined ? {} : { isEnabled: body.isEnabled }),
|
||||
}),
|
||||
onSuccess: () => {
|
||||
message.success("咨询表单已更新");
|
||||
onClose();
|
||||
form.resetFields();
|
||||
void queryClient.invalidateQueries({ queryKey: ["admin-inquiry-forms"] });
|
||||
void queryClient.invalidateQueries({ queryKey: ["public-runtime-workspace"] });
|
||||
},
|
||||
});
|
||||
return { createForm, updateForm };
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { createApiClient } from "../../lib/api.js";
|
||||
|
||||
/**
|
||||
* 咨询表单与自定义字段只需要两份后台数据:品牌工作空间(含本品牌业务提供项)和表单列表。
|
||||
*
|
||||
* 注意:这里不能用 `getPublicWorkspace()` 取业务提供项。公开工作空间不带 brandSlug 时会回退到
|
||||
* 默认品牌,管理其它品牌时下拉框会列出别的品牌的业务(跨品牌串数据)。
|
||||
*/
|
||||
export function useFormWorkspaceQueries(client = createApiClient()) {
|
||||
return {
|
||||
workspace: useQuery({
|
||||
queryKey: ["admin-workspace"],
|
||||
queryFn: () => client.getAdminWorkspace(),
|
||||
}),
|
||||
forms: useQuery({
|
||||
queryKey: ["admin-inquiry-forms"],
|
||||
queryFn: () => client.listAdminInquiryForms(),
|
||||
}),
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
import { ConfigProvider } from "antd";
|
||||
import type { ThemeConfig } from "antd";
|
||||
|
||||
export const adminTheme: ThemeConfig = {
|
||||
token: {
|
||||
colorPrimary: "#2563EB",
|
||||
colorLink: "#2563EB",
|
||||
colorText: "#1C1F23",
|
||||
colorTextSecondary: "#6B7280",
|
||||
colorTextTertiary: "#9AA1AC",
|
||||
colorTextQuaternary: "#C3C7CF",
|
||||
colorBgLayout: "#F7F8FA",
|
||||
colorBgContainer: "#FFFFFF",
|
||||
colorBorder: "#D8DBE0",
|
||||
colorBorderSecondary: "#E7E9EC",
|
||||
colorSplit: "#F0F1F3",
|
||||
colorFillTertiary: "#F7F8FA",
|
||||
colorFillQuaternary: "#FAFAFB",
|
||||
colorSuccess: "#12B76A",
|
||||
colorSuccessBg: "#ECFDF3",
|
||||
colorSuccessBorder: "#ABEFC6",
|
||||
colorSuccessText: "#067647",
|
||||
colorWarning: "#F79009",
|
||||
colorWarningBg: "#FFFAEB",
|
||||
colorWarningBorder: "#FEDF89",
|
||||
colorWarningText: "#B54708",
|
||||
colorError: "#F04438",
|
||||
colorErrorBg: "#FEF3F2",
|
||||
colorErrorBorder: "#FBD5D1",
|
||||
colorErrorText: "#B42318",
|
||||
colorInfo: "#2563EB",
|
||||
colorInfoBg: "#EFF4FF",
|
||||
colorInfoBorder: "#B2CCFF",
|
||||
colorInfoText: "#2563EB",
|
||||
borderRadius: 6,
|
||||
borderRadiusLG: 10,
|
||||
borderRadiusSM: 4,
|
||||
fontSize: 14,
|
||||
fontFamily:
|
||||
"Inter, 'PingFang SC', 'Noto Sans SC', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif",
|
||||
controlHeight: 32,
|
||||
controlHeightLG: 40,
|
||||
boxShadow: "0 1px 2px rgba(16, 24, 40, 0.04)",
|
||||
boxShadowSecondary: "0 8px 24px rgba(16, 24, 40, 0.08)",
|
||||
wireframe: false,
|
||||
},
|
||||
components: {
|
||||
Layout: {
|
||||
headerHeight: 56,
|
||||
headerBg: "#FFFFFF",
|
||||
headerPadding: "0 24px",
|
||||
siderBg: "#FFFFFF",
|
||||
bodyBg: "#F7F8FA",
|
||||
triggerBg: "#FFFFFF",
|
||||
triggerColor: "#475467",
|
||||
triggerHeight: 40,
|
||||
},
|
||||
Menu: {
|
||||
itemHeight: 36,
|
||||
itemBorderRadius: 6,
|
||||
itemBg: "transparent",
|
||||
itemColor: "#475467",
|
||||
itemHoverBg: "#F7F8FA",
|
||||
itemHoverColor: "#1C1F23",
|
||||
itemSelectedBg: "#EFF4FF",
|
||||
itemSelectedColor: "#2563EB",
|
||||
itemMarginInline: 8,
|
||||
itemMarginBlock: 2,
|
||||
groupTitleColor: "#9AA1AC",
|
||||
groupTitleFontSize: 12,
|
||||
collapsedWidth: 0,
|
||||
subMenuItemBg: "transparent",
|
||||
},
|
||||
Card: {
|
||||
paddingLG: 20,
|
||||
headerFontSize: 16,
|
||||
headerHeight: 52,
|
||||
headerHeightSM: 44,
|
||||
},
|
||||
Table: {
|
||||
headerBg: "#FAFAFB",
|
||||
headerColor: "#6B7280",
|
||||
rowHoverBg: "#FAFAFB",
|
||||
headerSplitColor: "transparent",
|
||||
borderColor: "#F0F1F3",
|
||||
cellPaddingBlock: 16,
|
||||
headerBorderRadius: 8,
|
||||
},
|
||||
Button: { fontWeight: 500, primaryShadow: "none", defaultShadow: "none" },
|
||||
Progress: { defaultColor: "#2563EB", remainingColor: "#F0F1F3", lineBorderRadius: 3 },
|
||||
Tag: { defaultBg: "#F2F4F7", defaultColor: "#475467", borderRadiusSM: 6 },
|
||||
Tabs: { inkBarColor: "#2563EB", itemSelectedColor: "#1C1F23", itemColor: "#6B7280" },
|
||||
Form: { labelColor: "#475467", labelFontSize: 13, verticalLabelPadding: "0 0 6px" },
|
||||
Modal: { borderRadiusLG: 12 },
|
||||
Statistic: { titleFontSize: 12, contentFontSize: 28 },
|
||||
Alert: { borderRadius: 8 },
|
||||
Descriptions: {
|
||||
labelBg: "#FAFAFB",
|
||||
labelColor: "#6B7280",
|
||||
contentColor: "#1C1F23",
|
||||
itemPaddingBottom: 12,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
ConfigProvider.config({ theme: adminTheme });
|
||||
@@ -1,326 +1,38 @@
|
||||
import React, { Suspense, useState } from "react";
|
||||
import React from "react";
|
||||
import { createRoot } from "react-dom/client";
|
||||
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import {
|
||||
App,
|
||||
Button,
|
||||
Card,
|
||||
Form,
|
||||
Input,
|
||||
Layout,
|
||||
Menu,
|
||||
Select,
|
||||
Space,
|
||||
Tag,
|
||||
Typography,
|
||||
message,
|
||||
} from "antd";
|
||||
import zhCN from "antd/locale/zh_CN";
|
||||
import { BrowserRouter } from "react-router-dom";
|
||||
import { Root } from "./app/Root.js";
|
||||
import { createApiClient } from "./lib/api.js";
|
||||
const FeatureInquiriesPage = React.lazy(() =>
|
||||
import("./features/inquiries/InquiriesPage.js").then((module) => ({
|
||||
default: module.InquiriesPage,
|
||||
})),
|
||||
);
|
||||
const FeatureTrustContentPage = React.lazy(() =>
|
||||
import("./features/trust-content/TrustContentPage.js").then((module) => ({
|
||||
default: module.TrustContentPage,
|
||||
})),
|
||||
);
|
||||
const FeatureServicesPage = React.lazy(() =>
|
||||
import("./features/services/ServicesPage.js").then((module) => ({
|
||||
default: module.ServicesPage,
|
||||
})),
|
||||
);
|
||||
const FeatureBrandPage = React.lazy(() =>
|
||||
import("./features/brand/BrandPage.js").then((module) => ({ default: module.BrandPage })),
|
||||
);
|
||||
const FeatureWorkspacePage = React.lazy(() =>
|
||||
import("./features/workspace/WorkspacePage.js").then((module) => ({
|
||||
default: module.WorkspacePage,
|
||||
})),
|
||||
);
|
||||
const FeatureOverviewPage = React.lazy(() =>
|
||||
import("./features/overview/OverviewPage.js").then((module) => ({
|
||||
default: module.OverviewPage,
|
||||
})),
|
||||
);
|
||||
const FeatureCapabilitiesPage = React.lazy(() =>
|
||||
import("./features/capabilities/CapabilitiesPage.js").then((module) => ({
|
||||
default: module.CapabilitiesPage,
|
||||
})),
|
||||
);
|
||||
const FeatureMembersPage = React.lazy(() =>
|
||||
import("./features/team/MembersPage.js").then((module) => ({
|
||||
default: module.MembersPage,
|
||||
})),
|
||||
);
|
||||
const FeaturePublicationPage = React.lazy(() =>
|
||||
import("./features/publication/PublicationPage.js").then((module) => ({
|
||||
default: module.PublicationPage,
|
||||
})),
|
||||
);
|
||||
import { BrowserRouter, Navigate, Route, Routes, useLocation, useNavigate } from "react-router-dom";
|
||||
import { adminTheme } from "./lib/theme.js";
|
||||
import { AdminConfigProvider } from "./components/AdminConfigProvider.js";
|
||||
import "./styles/admin.css";
|
||||
import "antd/dist/reset.css";
|
||||
|
||||
const queryClient = new QueryClient();
|
||||
const api = createApiClient;
|
||||
|
||||
function Login({
|
||||
onLogin,
|
||||
}: {
|
||||
onLogin: (session: { role: string; mustChangePassword: boolean }) => void;
|
||||
}) {
|
||||
const [form] = Form.useForm();
|
||||
const [loading, setLoading] = useState(false);
|
||||
async function submit(values: { username: string; password: string }) {
|
||||
setLoading(true);
|
||||
try {
|
||||
const result = await api().loginAdmin(values.username, values.password);
|
||||
localStorage.setItem("adminToken", result.token);
|
||||
localStorage.setItem("adminRole", result.role);
|
||||
localStorage.setItem("adminMustChangePassword", String(result.mustChangePassword));
|
||||
onLogin(result);
|
||||
} catch (error) {
|
||||
message.error(error instanceof Error ? error.message : "登录失败");
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}
|
||||
return (
|
||||
<Card title="个人品牌后台" style={{ maxWidth: 420, margin: "120px auto" }}>
|
||||
<Form form={form} layout="vertical" onFinish={submit}>
|
||||
<Form.Item name="username" label="账号" initialValue="admin" rules={[{ required: true }]}>
|
||||
<Input />
|
||||
</Form.Item>
|
||||
<Form.Item name="password" label="密码" rules={[{ required: true }]}>
|
||||
<Input.Password />
|
||||
</Form.Item>
|
||||
<Button type="primary" htmlType="submit" loading={loading} block>
|
||||
登录
|
||||
</Button>
|
||||
</Form>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
||||
function ChangePassword({ onComplete }: { onComplete: () => void }) {
|
||||
const [form] = Form.useForm<{
|
||||
currentPassword: string;
|
||||
newPassword: string;
|
||||
confirmPassword: string;
|
||||
}>();
|
||||
const [loading, setLoading] = useState(false);
|
||||
async function submit(values: {
|
||||
currentPassword: string;
|
||||
newPassword: string;
|
||||
confirmPassword: string;
|
||||
}) {
|
||||
if (values.newPassword !== values.confirmPassword) {
|
||||
message.error("两次输入的新密码不一致");
|
||||
return;
|
||||
}
|
||||
setLoading(true);
|
||||
try {
|
||||
await api().changeAdminPassword(values.currentPassword, values.newPassword);
|
||||
localStorage.setItem("adminMustChangePassword", "false");
|
||||
message.success("密码已更新");
|
||||
onComplete();
|
||||
} catch (error) {
|
||||
message.error(error instanceof Error ? error.message : "密码更新失败");
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}
|
||||
return (
|
||||
<Card title="首次登录需要修改密码" style={{ maxWidth: 420, margin: "120px auto" }}>
|
||||
<Typography.Paragraph type="secondary">请先设置只有你本人知道的新密码。</Typography.Paragraph>
|
||||
<Form form={form} layout="vertical" onFinish={submit}>
|
||||
<Form.Item name="currentPassword" label="初始密码" rules={[{ required: true }]}>
|
||||
<Input.Password />
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
name="newPassword"
|
||||
label="新密码"
|
||||
rules={[{ required: true, min: 8, message: "请输入至少 8 位新密码" }]}
|
||||
>
|
||||
<Input.Password />
|
||||
</Form.Item>
|
||||
<Form.Item name="confirmPassword" label="确认新密码" rules={[{ required: true }]}>
|
||||
<Input.Password />
|
||||
</Form.Item>
|
||||
<Button type="primary" htmlType="submit" loading={loading} block>
|
||||
保存新密码
|
||||
</Button>
|
||||
</Form>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
||||
function Dashboard({ onLogout, role }: { onLogout: () => void; role: string }) {
|
||||
const navigate = useNavigate();
|
||||
const location = useLocation();
|
||||
const brand = useQuery({
|
||||
queryKey: ["admin-shell-brand"],
|
||||
queryFn: () => createApiClient().getAdminBrand(),
|
||||
});
|
||||
const memberships = useQuery({
|
||||
queryKey: ["admin-brand-memberships"],
|
||||
queryFn: () => createApiClient().listAdminBrands(),
|
||||
});
|
||||
const switchBrand = async (brandId: string) => {
|
||||
try {
|
||||
const result = await createApiClient().switchAdminBrand(brandId);
|
||||
localStorage.setItem("adminToken", result.token);
|
||||
window.location.reload();
|
||||
} catch (error) {
|
||||
message.error(error instanceof Error ? error.message : "品牌切换失败");
|
||||
}
|
||||
};
|
||||
const page = location.pathname.split("/")[2] || "overview";
|
||||
const items = [
|
||||
{
|
||||
type: "group" as const,
|
||||
label: "日常经营",
|
||||
children: [
|
||||
{ key: "overview", label: "当前品牌概览" },
|
||||
{ key: "publication", label: "配置与发布" },
|
||||
{ key: "brand", label: "小程序页面" },
|
||||
{ key: "trust", label: "信任内容" },
|
||||
{ key: "services", label: "业务提供项" },
|
||||
{ key: "inquiries", label: "咨询记录" },
|
||||
],
|
||||
const queryClient = new QueryClient({
|
||||
defaultOptions: {
|
||||
queries: {
|
||||
staleTime: 30_000,
|
||||
retry: 2,
|
||||
refetchOnWindowFocus: false,
|
||||
},
|
||||
...(role === "editor"
|
||||
? []
|
||||
: [
|
||||
{
|
||||
type: "group" as const,
|
||||
label: "系统管理",
|
||||
children: [
|
||||
{ key: "workspace", label: "模板与表单设置" },
|
||||
{ key: "capabilities", label: "能力插件" },
|
||||
{ key: "members", label: "团队成员" },
|
||||
],
|
||||
},
|
||||
]),
|
||||
];
|
||||
return (
|
||||
<Layout style={{ minHeight: "100vh" }}>
|
||||
<Layout.Sider breakpoint="lg" collapsedWidth={0}>
|
||||
<Typography.Title level={4} style={{ color: "white", padding: 20 }}>
|
||||
当前品牌工作区
|
||||
</Typography.Title>
|
||||
<Menu
|
||||
theme="dark"
|
||||
selectedKeys={[page]}
|
||||
onClick={({ key }) => navigate(`/admin/${key}`)}
|
||||
items={items}
|
||||
/>
|
||||
</Layout.Sider>
|
||||
<Layout>
|
||||
<Layout.Header
|
||||
style={{
|
||||
background: "white",
|
||||
display: "flex",
|
||||
justifyContent: "space-between",
|
||||
alignItems: "center",
|
||||
}}
|
||||
>
|
||||
<Space>
|
||||
<Typography.Text strong>{brand.data?.name || "当前品牌"}</Typography.Text>
|
||||
<Typography.Text type="secondary">品牌工作区</Typography.Text>
|
||||
<Tag color={role === "owner" ? "blue" : "default"}>
|
||||
{role === "owner" ? "负责人" : "内容编辑"}
|
||||
</Tag>
|
||||
<Select
|
||||
size="small"
|
||||
value={brand.data?.id}
|
||||
loading={memberships.isLoading}
|
||||
onChange={(value) => {
|
||||
if (value) void switchBrand(value);
|
||||
}}
|
||||
options={(memberships.data ?? []).map((item) => ({
|
||||
value: item.brand.id,
|
||||
label: item.brand.name,
|
||||
}))}
|
||||
/>
|
||||
</Space>
|
||||
<Button type="text" onClick={onLogout}>
|
||||
退出登录
|
||||
</Button>
|
||||
</Layout.Header>
|
||||
<Layout.Content style={{ padding: 24 }}>
|
||||
<Suspense fallback={<Card loading />}>
|
||||
<Routes>
|
||||
<Route path="/admin/overview" element={<FeatureOverviewPage />} />
|
||||
<Route
|
||||
path="/admin/publication"
|
||||
element={<FeaturePublicationPage canManageTemplate={role !== "editor"} />}
|
||||
/>
|
||||
<Route path="/admin/brand" element={<FeatureBrandPage />} />
|
||||
{role === "editor" ? null : (
|
||||
<Route path="/admin/workspace" element={<FeatureWorkspacePage />} />
|
||||
)}
|
||||
{role === "editor" ? null : (
|
||||
<Route path="/admin/capabilities" element={<FeatureCapabilitiesPage />} />
|
||||
)}
|
||||
{role === "editor" ? null : (
|
||||
<Route path="/admin/members" element={<FeatureMembersPage />} />
|
||||
)}
|
||||
<Route path="/admin/trust" element={<FeatureTrustContentPage />} />
|
||||
<Route path="/admin/services" element={<FeatureServicesPage />} />
|
||||
<Route path="/admin/inquiries" element={<FeatureInquiriesPage />} />
|
||||
<Route path="*" element={<Navigate to="/admin/overview" replace />} />
|
||||
</Routes>
|
||||
</Suspense>
|
||||
</Layout.Content>
|
||||
</Layout>
|
||||
</Layout>
|
||||
);
|
||||
}
|
||||
mutations: {
|
||||
retry: 0,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export const api = createApiClient;
|
||||
|
||||
function Root() {
|
||||
const [loggedIn, setLoggedIn] = useState(Boolean(localStorage.getItem("adminToken")));
|
||||
const [role, setRole] = useState(localStorage.getItem("adminRole") || "owner");
|
||||
const [mustChangePassword, setMustChangePassword] = useState(
|
||||
localStorage.getItem("adminMustChangePassword") === "true",
|
||||
);
|
||||
React.useEffect(() => {
|
||||
const expire = () => {
|
||||
message.warning("登录状态已失效,请重新登录");
|
||||
setLoggedIn(false);
|
||||
};
|
||||
window.addEventListener("admin-auth-expired", expire);
|
||||
return () => window.removeEventListener("admin-auth-expired", expire);
|
||||
}, []);
|
||||
const logout = () => {
|
||||
localStorage.removeItem("adminToken");
|
||||
localStorage.removeItem("adminRole");
|
||||
localStorage.removeItem("adminMustChangePassword");
|
||||
setLoggedIn(false);
|
||||
};
|
||||
if (!loggedIn)
|
||||
return (
|
||||
<Login
|
||||
onLogin={(session) => {
|
||||
setRole(session.role);
|
||||
setMustChangePassword(session.mustChangePassword);
|
||||
setLoggedIn(true);
|
||||
}}
|
||||
/>
|
||||
);
|
||||
if (mustChangePassword) return <ChangePassword onComplete={() => setMustChangePassword(false)} />;
|
||||
return <Dashboard onLogout={logout} role={role} />;
|
||||
}
|
||||
createRoot(document.getElementById("app")!).render(
|
||||
<React.StrictMode>
|
||||
<QueryClientProvider client={queryClient}>
|
||||
<App>
|
||||
<AdminConfigProvider locale={zhCN} theme={adminTheme}>
|
||||
<QueryClientProvider client={queryClient}>
|
||||
<BrowserRouter>
|
||||
<Root />
|
||||
</BrowserRouter>
|
||||
</App>
|
||||
</QueryClientProvider>
|
||||
</QueryClientProvider>
|
||||
</AdminConfigProvider>
|
||||
</React.StrictMode>,
|
||||
);
|
||||
@@ -0,0 +1,856 @@
|
||||
/*
|
||||
* 后台全局样式。视觉规则见 apps/admin/design.md。
|
||||
* 颜色令牌与 apps/admin/src/lib/theme.ts 保持一致,改动需同步。
|
||||
*/
|
||||
:root {
|
||||
--admin-bg: #f7f8fa;
|
||||
--admin-surface: #ffffff;
|
||||
--admin-border: #e7e9ec;
|
||||
--admin-divider: #f0f1f3;
|
||||
--admin-text: #1c1f23;
|
||||
--admin-text-secondary: #6b7280;
|
||||
--admin-text-tertiary: #9aa1ac;
|
||||
--admin-primary: #2563eb;
|
||||
--admin-primary-bg: #eff4ff;
|
||||
--admin-fill: #f7f8fa;
|
||||
--admin-fill-quiet: #fafafb;
|
||||
|
||||
--admin-tone-success-bg: #ecfdf3;
|
||||
--admin-tone-success-border: #abefc6;
|
||||
--admin-tone-success-fg: #067647;
|
||||
--admin-tone-warning-bg: #fffaeb;
|
||||
--admin-tone-warning-border: #fedf89;
|
||||
--admin-tone-warning-fg: #b54708;
|
||||
--admin-tone-error-bg: #fef3f2;
|
||||
--admin-tone-error-border: #fbd5d1;
|
||||
--admin-tone-error-fg: #b42318;
|
||||
--admin-tone-neutral-bg: #f2f4f7;
|
||||
--admin-tone-neutral-border: #e7e9ec;
|
||||
--admin-tone-neutral-fg: #475467;
|
||||
--admin-tone-info-bg: #eff4ff;
|
||||
--admin-tone-info-border: #b2ccff;
|
||||
--admin-tone-info-fg: #2563eb;
|
||||
}
|
||||
|
||||
html,
|
||||
body,
|
||||
#app {
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
background: var(--admin-bg);
|
||||
color: var(--admin-text);
|
||||
font-variant-numeric: tabular-nums;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
}
|
||||
|
||||
:where(a, button, [tabindex]):focus-visible {
|
||||
outline: 2px solid var(--admin-primary);
|
||||
outline-offset: 2px;
|
||||
}
|
||||
|
||||
/* 外壳 */
|
||||
.admin-shell {
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
.admin-sider,
|
||||
.admin-sider .ant-layout-sider-children {
|
||||
border-right: 1px solid var(--admin-border);
|
||||
}
|
||||
|
||||
.admin-sider.ant-layout-sider-collapsed,
|
||||
.admin-sider.ant-layout-sider-zero-width,
|
||||
.admin-sider.ant-layout-sider-zero-width .ant-layout-sider-children {
|
||||
border-right: 0;
|
||||
}
|
||||
|
||||
.admin-sider .ant-layout-sider-zero-width-trigger {
|
||||
border: 1px solid var(--admin-border);
|
||||
border-left: 0;
|
||||
border-radius: 0 6px 6px 0;
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
.admin-sider-brand {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
height: 56px;
|
||||
padding: 0 20px;
|
||||
}
|
||||
|
||||
.admin-sider-brand-mark {
|
||||
width: 24px;
|
||||
height: 24px;
|
||||
border-radius: 6px;
|
||||
background: var(--admin-primary);
|
||||
color: #fff;
|
||||
font-size: 13px;
|
||||
font-weight: 600;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
flex: none;
|
||||
}
|
||||
|
||||
.admin-sider-brand-name {
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
color: var(--admin-text);
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.admin-sider .ant-menu {
|
||||
border-inline-end: 0;
|
||||
padding: 4px 0 12px;
|
||||
}
|
||||
|
||||
.admin-sider .ant-menu-item-group-title {
|
||||
padding: 16px 24px 6px;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.admin-main {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-height: 100vh;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.admin-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 16px;
|
||||
border-bottom: 1px solid var(--admin-border);
|
||||
}
|
||||
|
||||
.admin-header-left {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.admin-header-brand {
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
color: var(--admin-text);
|
||||
}
|
||||
|
||||
.admin-header-context {
|
||||
font-size: 13px;
|
||||
color: var(--admin-text-tertiary);
|
||||
}
|
||||
|
||||
.admin-brand-switcher {
|
||||
min-width: 140px;
|
||||
}
|
||||
|
||||
.admin-equal-height > .ant-col > .ant-card {
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.admin-content {
|
||||
flex: 1;
|
||||
padding: 24px;
|
||||
}
|
||||
|
||||
.admin-content-inner {
|
||||
max-width: 1200px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
/* 页面头部 */
|
||||
.admin-page-header {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
justify-content: space-between;
|
||||
gap: 24px;
|
||||
margin-bottom: 32px;
|
||||
}
|
||||
|
||||
.admin-page-header-text {
|
||||
flex: 1 1 auto;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.admin-page-header-title {
|
||||
margin: 0;
|
||||
font-size: 20px;
|
||||
font-weight: 600;
|
||||
line-height: 1.4;
|
||||
color: var(--admin-text);
|
||||
}
|
||||
|
||||
.admin-page-header-description {
|
||||
margin: 6px 0 0;
|
||||
max-width: 880px;
|
||||
font-size: 13px;
|
||||
line-height: 1.6;
|
||||
color: var(--admin-text-secondary);
|
||||
}
|
||||
|
||||
/* 区块与列表 */
|
||||
.admin-section {
|
||||
padding: 20px;
|
||||
border: 1px solid var(--admin-border);
|
||||
border-radius: 10px;
|
||||
background: var(--admin-surface);
|
||||
}
|
||||
|
||||
.admin-section + .admin-section {
|
||||
margin-top: 16px;
|
||||
}
|
||||
|
||||
.admin-section-head {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
justify-content: space-between;
|
||||
gap: 16px;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.admin-section-head:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.admin-section-title {
|
||||
margin: 0;
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
line-height: 1.45;
|
||||
color: var(--admin-text);
|
||||
}
|
||||
|
||||
.admin-subhead {
|
||||
margin: 0;
|
||||
font-size: 15px;
|
||||
font-weight: 600;
|
||||
line-height: 1.45;
|
||||
color: var(--admin-text);
|
||||
}
|
||||
|
||||
.admin-section-description {
|
||||
margin: 6px 0 0;
|
||||
font-size: 13px;
|
||||
line-height: 1.5;
|
||||
color: var(--admin-text-secondary);
|
||||
}
|
||||
|
||||
.admin-stack {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.admin-stack-lg {
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.admin-stack-tight {
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.admin-actions {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.admin-row-title {
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
color: var(--admin-text);
|
||||
}
|
||||
|
||||
.admin-row-meta {
|
||||
font-size: 12px;
|
||||
color: var(--admin-text-tertiary);
|
||||
}
|
||||
|
||||
.admin-row-summary {
|
||||
font-size: 13px;
|
||||
line-height: 1.5;
|
||||
color: var(--admin-text-secondary);
|
||||
display: -webkit-box;
|
||||
-webkit-line-clamp: 2;
|
||||
-webkit-box-orient: vertical;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
/* 列表行 */
|
||||
.admin-list {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
list-style: none;
|
||||
}
|
||||
|
||||
.admin-row.admin-record {
|
||||
align-items: flex-start;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.admin-record__thumb {
|
||||
flex: none;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
margin-top: 2px;
|
||||
width: 48px;
|
||||
height: 48px;
|
||||
border-radius: 8px;
|
||||
border: 1px solid var(--admin-border);
|
||||
background: var(--admin-fill);
|
||||
color: var(--admin-text-tertiary);
|
||||
font-size: 18px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.admin-record__thumb img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
}
|
||||
|
||||
.admin-record__actions {
|
||||
flex: none;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
align-self: center;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.admin-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 16px;
|
||||
padding: 14px 0;
|
||||
border-bottom: 1px solid var(--admin-divider);
|
||||
}
|
||||
|
||||
.admin-row:last-child {
|
||||
border-bottom: 0;
|
||||
}
|
||||
|
||||
.admin-row-main {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
flex: 1 1 auto;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
/* 行内段落默认自带浏览器下边距,行内布局统一交给 gap 控制。 */
|
||||
.admin-row-main > .admin-row-meta,
|
||||
.admin-row-main > .admin-row-summary,
|
||||
.admin-row-main > .admin-row-help {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.admin-row-line {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.admin-row-help {
|
||||
margin: 6px 0 0;
|
||||
font-size: 13px;
|
||||
line-height: 1.5;
|
||||
color: var(--admin-text-secondary);
|
||||
}
|
||||
|
||||
.admin-field-stack {
|
||||
display: grid;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.admin-field-label {
|
||||
display: block;
|
||||
font-size: 13px;
|
||||
font-weight: 500;
|
||||
color: var(--admin-text-secondary);
|
||||
margin-bottom: 6px;
|
||||
}
|
||||
|
||||
.admin-offset-top {
|
||||
margin-top: 16px;
|
||||
}
|
||||
|
||||
.admin-offset-top-xs {
|
||||
margin-top: 4px;
|
||||
}
|
||||
|
||||
.admin-divider {
|
||||
margin: 16px 0;
|
||||
}
|
||||
|
||||
.admin-offset-top-sm {
|
||||
margin-top: 8px;
|
||||
}
|
||||
|
||||
.admin-offset-top-md {
|
||||
margin-top: 12px;
|
||||
}
|
||||
|
||||
.admin-offset-bottom {
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.admin-text-xs {
|
||||
font-size: 12px;
|
||||
line-height: 1.5;
|
||||
color: var(--admin-text-secondary);
|
||||
}
|
||||
|
||||
.admin-text-xs-quiet {
|
||||
font-size: 12px;
|
||||
color: var(--admin-text-tertiary);
|
||||
}
|
||||
|
||||
.admin-text-warning {
|
||||
color: var(--admin-tone-warning-fg);
|
||||
}
|
||||
|
||||
.admin-flush {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.admin-flush-top {
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
.admin-block {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.admin-offset-bottom-sm {
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.admin-offset-bottom-lg {
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
|
||||
.admin-offset-top-lg {
|
||||
margin-top: 24px;
|
||||
}
|
||||
|
||||
.admin-link-flush {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.admin-form-row {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 16px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.admin-form-row-center {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 16px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.admin-flex-1 {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.admin-field-w-sm {
|
||||
width: 90px;
|
||||
}
|
||||
|
||||
.admin-field-w-md {
|
||||
width: 150px;
|
||||
}
|
||||
|
||||
.admin-field-w-lg {
|
||||
width: 160px;
|
||||
}
|
||||
|
||||
.admin-field-w-xl {
|
||||
width: 220px;
|
||||
}
|
||||
|
||||
.admin-field-w-2xl {
|
||||
width: 180px;
|
||||
}
|
||||
|
||||
.admin-field-stack-xs {
|
||||
display: grid;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.admin-form-column {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-height: 0;
|
||||
}
|
||||
|
||||
.admin-brand-title {
|
||||
margin: 0;
|
||||
font-size: 18px;
|
||||
font-weight: 600;
|
||||
line-height: 1.45;
|
||||
color: var(--admin-text);
|
||||
}
|
||||
|
||||
.admin-brand-tagline {
|
||||
margin: 6px 0 12px;
|
||||
font-size: 14px;
|
||||
line-height: 1.5;
|
||||
color: var(--admin-text-secondary);
|
||||
}
|
||||
|
||||
.admin-field-offset {
|
||||
margin-top: 30px;
|
||||
}
|
||||
|
||||
.admin-offset-bottom-xs {
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.admin-visual-card {
|
||||
width: 260px;
|
||||
}
|
||||
|
||||
.admin-swatch {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
height: 24px;
|
||||
padding: 0 8px;
|
||||
border-radius: 6px;
|
||||
background: var(--admin-fill);
|
||||
color: var(--admin-text-secondary);
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.admin-swatch::before {
|
||||
content: "";
|
||||
width: 10px;
|
||||
height: 10px;
|
||||
border-radius: 3px;
|
||||
border: 1px solid var(--admin-border);
|
||||
background: var(--swatch-color, transparent);
|
||||
}
|
||||
|
||||
/* 描述列表(键值展示) */
|
||||
.admin-descriptions .ant-descriptions-item-label {
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
/* 状态标签 */
|
||||
.admin-status-tag {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
height: 24px;
|
||||
padding: 0 8px;
|
||||
border-radius: 6px;
|
||||
font-size: 12px;
|
||||
font-weight: 500;
|
||||
line-height: 1;
|
||||
white-space: nowrap;
|
||||
background: var(--admin-tone-neutral-bg);
|
||||
color: var(--admin-tone-neutral-fg);
|
||||
}
|
||||
|
||||
.admin-status-tag[data-tone="success"] {
|
||||
background: var(--admin-tone-success-bg);
|
||||
color: var(--admin-tone-success-fg);
|
||||
}
|
||||
|
||||
.admin-status-tag[data-tone="warning"] {
|
||||
background: var(--admin-tone-warning-bg);
|
||||
color: var(--admin-tone-warning-fg);
|
||||
}
|
||||
|
||||
.admin-status-tag[data-tone="error"] {
|
||||
background: var(--admin-tone-error-bg);
|
||||
color: var(--admin-tone-error-fg);
|
||||
}
|
||||
|
||||
.admin-status-tag[data-tone="info"] {
|
||||
background: var(--admin-tone-info-bg);
|
||||
color: var(--admin-tone-info-fg);
|
||||
}
|
||||
|
||||
/* 指标卡 */
|
||||
.admin-metric-label {
|
||||
font-size: 12px;
|
||||
color: var(--admin-text-tertiary);
|
||||
}
|
||||
|
||||
.admin-metric-value {
|
||||
margin-top: 8px;
|
||||
font-size: 28px;
|
||||
font-weight: 600;
|
||||
line-height: 1.2;
|
||||
color: var(--admin-text);
|
||||
}
|
||||
|
||||
.admin-metric-suffix {
|
||||
margin-left: 6px;
|
||||
font-size: 12px;
|
||||
font-weight: 400;
|
||||
color: var(--admin-text-tertiary);
|
||||
}
|
||||
|
||||
/* 反馈 */
|
||||
.admin-empty {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
text-align: center;
|
||||
padding: 40px 24px;
|
||||
}
|
||||
|
||||
.admin-empty--compact {
|
||||
padding: 24px 16px;
|
||||
}
|
||||
|
||||
.admin-empty__icon {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
margin-bottom: 12px;
|
||||
border-radius: 10px;
|
||||
background: var(--admin-fill);
|
||||
color: var(--admin-text-tertiary);
|
||||
font-size: 20px;
|
||||
}
|
||||
|
||||
.admin-empty--compact .admin-empty__icon {
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
margin-bottom: 8px;
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
.admin-empty__title {
|
||||
margin: 0;
|
||||
font-size: 15px;
|
||||
font-weight: 600;
|
||||
line-height: 1.5;
|
||||
color: var(--admin-text);
|
||||
}
|
||||
|
||||
.admin-empty--compact .admin-empty__title {
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.admin-empty__description {
|
||||
margin: 6px 0 0;
|
||||
max-width: 360px;
|
||||
font-size: 13px;
|
||||
line-height: 1.6;
|
||||
color: var(--admin-text-secondary);
|
||||
}
|
||||
|
||||
.admin-empty__action {
|
||||
margin-top: 16px;
|
||||
}
|
||||
|
||||
.admin-empty--compact .admin-empty__action {
|
||||
margin-top: 12px;
|
||||
}
|
||||
|
||||
.admin-table-skeleton {
|
||||
border-top: 1px solid var(--admin-divider);
|
||||
}
|
||||
|
||||
.admin-table-skeleton__row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
min-height: 52px;
|
||||
padding: 0 16px;
|
||||
border-bottom: 1px solid var(--admin-divider);
|
||||
}
|
||||
|
||||
.admin-table-skeleton__row:last-child {
|
||||
border-bottom: 0;
|
||||
}
|
||||
|
||||
.admin-table-skeleton__row .ant-skeleton {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.admin-table-skeleton__row .ant-skeleton-input {
|
||||
width: 60%;
|
||||
min-width: 120px;
|
||||
}
|
||||
|
||||
.admin-list-skeleton {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.admin-list-skeleton__row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
padding: 14px 0;
|
||||
border-bottom: 1px solid var(--admin-divider);
|
||||
}
|
||||
|
||||
.admin-list-skeleton__row:last-child {
|
||||
border-bottom: 0;
|
||||
}
|
||||
|
||||
.admin-list-skeleton__thumb .ant-skeleton-input {
|
||||
width: 48px;
|
||||
min-width: 48px;
|
||||
height: 48px;
|
||||
}
|
||||
|
||||
.admin-list-skeleton__body {
|
||||
flex: 1;
|
||||
display: grid;
|
||||
gap: 8px;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.admin-list-skeleton__body .ant-skeleton-input:last-child {
|
||||
width: 45%;
|
||||
}
|
||||
|
||||
.admin-error-note {
|
||||
padding: 12px 16px;
|
||||
border: 1px solid var(--admin-tone-error-border);
|
||||
border-radius: 8px;
|
||||
background: var(--admin-tone-error-bg);
|
||||
color: var(--admin-tone-error-fg);
|
||||
font-size: 14px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.admin-loading-stack {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.admin-log {
|
||||
margin: 0;
|
||||
padding: 16px;
|
||||
border-radius: 8px;
|
||||
background: #1c1f23;
|
||||
color: #e4e7ec;
|
||||
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
|
||||
font-size: 12px;
|
||||
line-height: 1.7;
|
||||
max-height: 280px;
|
||||
overflow: auto;
|
||||
white-space: pre-wrap;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
.admin-log__line {
|
||||
color: #e4e7ec;
|
||||
white-space: pre-wrap;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
.admin-log__line[data-stream="stderr"] {
|
||||
color: #fda29b;
|
||||
}
|
||||
|
||||
.admin-log__time {
|
||||
color: #98a2b3;
|
||||
}
|
||||
|
||||
.admin-code-input {
|
||||
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.admin-thumb {
|
||||
width: 80px;
|
||||
height: 80px;
|
||||
object-fit: cover;
|
||||
border-radius: 8px;
|
||||
border: 1px solid var(--admin-border);
|
||||
}
|
||||
|
||||
.admin-thumb-remove {
|
||||
position: absolute;
|
||||
top: 8px;
|
||||
right: 8px;
|
||||
}
|
||||
|
||||
.admin-thumb-wrap {
|
||||
position: relative;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.admin-media-preview {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
min-height: 140px;
|
||||
border-radius: 8px;
|
||||
overflow: hidden;
|
||||
border: 1px solid var(--admin-border);
|
||||
background: var(--admin-fill);
|
||||
}
|
||||
|
||||
@media (max-width: 1024px) {
|
||||
.admin-content {
|
||||
padding: 16px;
|
||||
}
|
||||
}
|
||||
|
||||
/* 登录与改密 */
|
||||
.admin-auth {
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 24px;
|
||||
background: var(--admin-bg);
|
||||
}
|
||||
|
||||
.admin-auth-card {
|
||||
width: 100%;
|
||||
max-width: 400px;
|
||||
}
|
||||
|
||||
.admin-auth-card .ant-card-body {
|
||||
padding: 32px;
|
||||
}
|
||||
|
||||
.admin-auth-brand {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.admin-auth-hint {
|
||||
margin: 8px 0 20px;
|
||||
font-size: 13px;
|
||||
color: var(--admin-text-secondary);
|
||||
}
|
||||
|
||||
.admin-auth-footnote {
|
||||
margin: 16px 0 0;
|
||||
font-size: 12px;
|
||||
color: var(--admin-text-tertiary);
|
||||
text-align: center;
|
||||
}
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
filterSectionsForPreviewTarget,
|
||||
presentationFieldName,
|
||||
readPresentationValue,
|
||||
} from "../src/features/brand/presentation-bindings.ts";
|
||||
} from "../src/lib/presentation/presentation-bindings.ts";
|
||||
import {
|
||||
resolvePreviewSelection,
|
||||
previewTrustRecordId,
|
||||
|
||||
@@ -7,12 +7,14 @@ export default defineConfig({
|
||||
css: { postcss: { plugins: [templatePreviewCss()] } },
|
||||
base: process.env.VITE_APP_BASE_PATH ?? "/",
|
||||
resolve: {
|
||||
dedupe: ["react", "react-dom"],
|
||||
alias: {
|
||||
"@tarojs/components": `${process.cwd()}/src/features/brand/taro-web-components.jsx`,
|
||||
"@tarojs/taro": `${process.cwd()}/src/features/brand/taro-web-runtime.jsx`,
|
||||
},
|
||||
},
|
||||
define: {
|
||||
"process.env": "{}",
|
||||
"process.env.TARO_PLATFORM": JSON.stringify("web"),
|
||||
"process.env.TARO_ENV": JSON.stringify("h5"),
|
||||
PREVIEW_ALL_TEMPLATES: JSON.stringify(true),
|
||||
@@ -26,7 +28,32 @@ export default defineConfig({
|
||||
target: process.env.VITE_DEV_API_TARGET ?? "http://localhost:3001",
|
||||
rewrite: (path) => path.replace(/^\/api/, ""),
|
||||
},
|
||||
"/media": {
|
||||
target: process.env.VITE_MEDIA_API_TARGET ?? "http://localhost:3001",
|
||||
changeOrigin: true,
|
||||
},
|
||||
...(process.env.VITE_MEDIA_PROXY_TARGET
|
||||
? {
|
||||
[`/${(process.env.OBJECT_STORAGE_BUCKET ?? "personal-brand-media").replace(/^\/+/, "")}`]:
|
||||
{
|
||||
target: process.env.VITE_MEDIA_PROXY_TARGET,
|
||||
changeOrigin: true,
|
||||
},
|
||||
}
|
||||
: {}),
|
||||
},
|
||||
},
|
||||
build: {
|
||||
outDir: "dist",
|
||||
rollupOptions: {
|
||||
output: {
|
||||
manualChunks(id) {
|
||||
if (id.includes("/node_modules/.pnpm/react-dom@")) return "react-runtime";
|
||||
if (id.includes("/node_modules/.pnpm/react@")) return "react-runtime";
|
||||
if (id.includes("/node_modules/.pnpm/scheduler@")) return "react-runtime";
|
||||
return undefined;
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
build: { outDir: "dist" },
|
||||
});
|
||||
@@ -0,0 +1,43 @@
|
||||
FROM node:22-alpine AS base
|
||||
ENV PNPM_HOME=/pnpm
|
||||
ENV PATH="$PNPM_HOME:$PATH"
|
||||
RUN corepack enable \
|
||||
&& apk add --no-cache openssl libc6-compat
|
||||
WORKDIR /app
|
||||
|
||||
FROM base AS build
|
||||
COPY pnpm-lock.yaml pnpm-workspace.yaml package.json ./
|
||||
COPY tsconfig.base.json ./
|
||||
COPY packages ./packages
|
||||
COPY apps/api/package.json apps/api/package.json
|
||||
COPY apps/api/tsconfig.json apps/api/tsconfig.json
|
||||
COPY apps/api/prisma ./apps/api/prisma
|
||||
COPY apps/api/src ./apps/api/src
|
||||
RUN pnpm install --frozen-lockfile
|
||||
RUN pnpm --filter @personal-brand/config build
|
||||
RUN pnpm --filter @personal-brand/types build
|
||||
RUN pnpm --filter @personal-brand/validation build
|
||||
RUN pnpm --filter @personal-brand/api exec prisma generate
|
||||
RUN pnpm --filter @personal-brand/api build
|
||||
RUN pnpm --filter @personal-brand/api --prod deploy /out/api
|
||||
|
||||
FROM base AS runtime
|
||||
ENV NODE_ENV=production
|
||||
WORKDIR /app
|
||||
COPY --from=build /out/api ./
|
||||
COPY --from=build /app/apps/api/dist ./dist
|
||||
COPY --from=build /app/apps/api/prisma ./prisma
|
||||
COPY --from=build /app/packages/config/dist ./node_modules/@personal-brand/config/dist
|
||||
COPY --from=build /app/packages/types/dist ./node_modules/@personal-brand/types/dist
|
||||
COPY --from=build /app/packages/validation/dist ./node_modules/@personal-brand/validation/dist
|
||||
RUN mkdir -p /app/media /app/seed-media
|
||||
COPY apps/api/prisma/assets/ /app/seed-media/
|
||||
COPY docker/api-entrypoint.sh /usr/local/bin/api-entrypoint.sh
|
||||
RUN chmod +x /usr/local/bin/api-entrypoint.sh \
|
||||
&& chown -R node:node /app
|
||||
USER node
|
||||
EXPOSE 3001
|
||||
HEALTHCHECK --interval=30s --timeout=5s --start-period=15s --retries=3 \
|
||||
CMD node -e "fetch('http://127.0.0.1:'+(process.env.API_PORT||3001)+'/health').then(r=>{if(!r.ok)process.exit(1)}).catch(()=>process.exit(1))"
|
||||
ENTRYPOINT ["/usr/local/bin/api-entrypoint.sh"]
|
||||
CMD ["node", "dist/main.js"]
|
||||
@@ -4,11 +4,11 @@
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"build": "tsc -p tsconfig.json",
|
||||
"dev": "pnpm build && node --env-file=.env dist/main.js",
|
||||
"dev": "pnpm build && node --env-file=.env --watch dist/main.js",
|
||||
"lint": "eslint .",
|
||||
"typecheck": "tsc -p tsconfig.json --noEmit",
|
||||
"test": "tsx --test test/**/*.test.ts",
|
||||
"test:integration": "pnpm build && node --env-file=.env test/run-integration.cjs",
|
||||
"test:integration": "pnpm build && node --env-file=.env test/run-integration.cjs && pnpm --filter @personal-brand/api exec tsx --test test/http.upload.test.js",
|
||||
"clean": "rimraf dist",
|
||||
"start": "node dist/main.js",
|
||||
"db:generate": "prisma generate",
|
||||
@@ -17,6 +17,10 @@
|
||||
"db:seed": "tsx prisma/seed.ts"
|
||||
},
|
||||
"dependencies": {
|
||||
"@aws-sdk/client-s3": "^3.1149.0",
|
||||
"@aws-sdk/s3-request-presigner": "^3.1149.0",
|
||||
"@fastify/multipart": "^10.1.3",
|
||||
"@fastify/static": "^10.1.6",
|
||||
"@nestjs/common": "^11.0.11",
|
||||
"@nestjs/core": "^11.0.11",
|
||||
"@nestjs/platform-fastify": "^11.0.11",
|
||||
@@ -27,13 +31,14 @@
|
||||
"bcryptjs": "^2.4.3",
|
||||
"class-transformer": "^0.5.1",
|
||||
"class-validator": "^0.14.1",
|
||||
"fastify": "^5.2.1",
|
||||
"fastify": "^5.11.3",
|
||||
"miniprogram-ci": "^2.1.31",
|
||||
"prisma": "^6.2.1",
|
||||
"reflect-metadata": "^0.2.2",
|
||||
"rxjs": "^7.8.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^22.10.5",
|
||||
"prisma": "^6.2.1",
|
||||
"tsx": "^4.19.2"
|
||||
}
|
||||
}
|
||||
|
After Width: | Height: | Size: 82 KiB |
|
After Width: | Height: | Size: 125 KiB |
|
After Width: | Height: | Size: 163 KiB |
|
After Width: | Height: | Size: 121 KiB |
|
After Width: | Height: | Size: 182 KiB |
|
After Width: | Height: | Size: 167 KiB |
|
After Width: | Height: | Size: 154 KiB |