Compare commits
328 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 8a061f085f | |||
| b20e566a65 | |||
| 4d434c9c67 | |||
| 62e61a9e63 | |||
| a01217539c | |||
| 26334ed072 | |||
| fc2e5b65de | |||
| ee493823bf | |||
| 8b5bb6a981 | |||
| 0a36188b35 | |||
| 6cf66c722c | |||
| 4db21cf1a1 | |||
| 2f633b307c | |||
| 62353a6800 | |||
| 233ed0af3b | |||
| 7dd5fdfb12 | |||
| 48d6900ab6 | |||
| 5ca9aa00aa | |||
| c0d04ee500 | |||
| 3ac008a217 | |||
| cd1e9ae488 | |||
| 18147e157f | |||
| f7c94b4f16 | |||
| cc750dc1d6 | |||
| 984dec79ee | |||
| f84614bbb4 | |||
| c0ce494732 | |||
| 69e201f927 | |||
| ecd9973d8f | |||
| bbd7e52e70 | |||
| 1c91e6bae9 | |||
| 029fd690a5 | |||
| 0bfc19b1a4 | |||
| bafb342600 | |||
| bac5c7ad80 | |||
| c05cd0e96d | |||
| 8de41796fb | |||
| 4b3b1f76ae | |||
| 75d820b574 | |||
| 0f48d7abda | |||
| 4a0e18472b | |||
| 491f03e825 | |||
| 88053353ab | |||
| ceacce9ed5 | |||
| 3913bf3bf3 | |||
| 478291e2b3 | |||
| 6754caf076 | |||
| 92c3175acf | |||
| 46361ec713 | |||
| 5586ed90cd | |||
| 4cec5b1fe5 | |||
| 07630c9046 | |||
| 4488b0c006 | |||
| 99c74f20d2 | |||
| a598d1cd30 | |||
| da6a38daa4 | |||
| c5926bd593 | |||
| df546ff39f | |||
| d6d4a77473 | |||
| 0518976953 | |||
| 8f83624ffe | |||
| 7c6dae472c | |||
| 209db59422 | |||
| 21d44026d9 | |||
| 3b192b0b88 | |||
| 1b3a7f3a36 | |||
| 34a1897c09 | |||
| 36017a19b1 | |||
| 9c7550a1c4 | |||
| fe1c6c8158 | |||
| acc841bb21 | |||
| 61a99aeea9 | |||
| 76375eff83 | |||
| 713dce52b4 | |||
| e41bf838d4 | |||
| 0692bebf07 | |||
| b19f875e7b | |||
| 090002b6c0 | |||
| 8726cf14e3 | |||
| 7298b1a5d5 | |||
| 1401f1dcd2 | |||
| 155426b669 | |||
| b4d6f2bd91 | |||
| 029c17347e | |||
| b626db5d84 | |||
| d98ef6b808 | |||
| d13a6ee3cd | |||
| 10fa361983 | |||
| 1a615ffe93 | |||
| 0269802e59 | |||
| e4e9eb2169 | |||
| b5fb9a0bb2 | |||
| 9d800a4cbd | |||
| 2a9493165b | |||
| b32c68d56b | |||
| 6816835fb8 | |||
| 571959900b | |||
| 7bc710f139 | |||
| 397bdad73f | |||
| 83b1b0e5f6 | |||
| 91fed31b10 | |||
| 1933b9b608 | |||
| a2abbb6169 | |||
| 53a79d1255 | |||
| 0181af09c5 | |||
| 9cd0c9508a | |||
| 4f363fa9e7 | |||
| 291137a15d | |||
| e2a5f21f9d | |||
| 3ef4432b2f | |||
| 33b868dfac | |||
| 5c4ad1d8db | |||
| a346fae7a4 | |||
| 37bc297d1a | |||
| bc1616c3f7 | |||
| 46a200e0ba | |||
| 429eaabe6b | |||
| 607a0224cd | |||
| 53e0db6a98 | |||
| 456b3af461 | |||
| 1f7ecffe4c | |||
| 8df0a2bea7 | |||
| 672a995c59 | |||
| 69f52921a7 | |||
| 9cb88dc181 | |||
| 345d5db9c9 | |||
| 7c9240fc84 | |||
| 2610288df0 | |||
| 62652cd072 | |||
| 9d49ed5e70 | |||
| bdbd135318 | |||
| 8ca893efab | |||
| d0ab838da6 | |||
| 50ab0f1748 | |||
| fa6fb80d19 | |||
| bd1930f6b1 | |||
| dc4295d1bd | |||
| 256526c5ec | |||
| 1c4b986924 | |||
| bf501d2374 | |||
| 442500b1a1 | |||
| 490c26a7e1 | |||
| b40eb83f27 | |||
| f80a0f2c27 | |||
| 528669f662 | |||
| f5e523a425 | |||
| 16fa07ceaf | |||
| b21403a47c | |||
| 02d89e6385 | |||
| f9a5b6e81a | |||
| 16c386f165 | |||
| 1c787ed576 | |||
| 4372018c09 | |||
| aca3df4bf2 | |||
| 71f508e02b | |||
| 9d96c73246 | |||
| fa0d928980 | |||
| c8ea5a3119 | |||
| 6f427cb553 | |||
| 89fd333702 | |||
| ab10431001 | |||
| e93e4b8f84 | |||
| d90847bad0 | |||
| ffa753707b | |||
| ac2f9f4793 | |||
| 3ba7b179e8 | |||
| 4e7079c221 | |||
| 3c19b7dd97 | |||
| a7d55b7293 | |||
| 7e3dc131ad | |||
| f09e00e16f | |||
| ff462bca9a | |||
| aa0e140fec | |||
| dc30932012 | |||
| f8d8e2d6d5 | |||
| 54fca99208 | |||
| 9859abba7e | |||
| 26472f8678 | |||
| c89560e4f8 | |||
| f3353bbce5 | |||
| 666bcb8633 | |||
| ffed560d43 | |||
| a7a0a54688 | |||
| 5199b495e0 | |||
| 04fd4d50d0 | |||
| 82b98aa4e3 | |||
| 2088a1ee19 | |||
| 7dffd40f3f | |||
| 021b9e0329 | |||
| 0304201e80 | |||
| fd05621660 | |||
| dd4362c397 | |||
| 2ebdb08a2f | |||
| 87515decb3 | |||
| 4a5b9eaffa | |||
| e06d9f4711 | |||
| 28ef916a22 | |||
| fa3484041e | |||
| 06cbcdeb9c | |||
| ebd8c07147 | |||
| 39e38aac7e | |||
| 87c4af7364 | |||
| 9f67221457 | |||
| 23587418c1 | |||
| daf534b4db | |||
| 0621ac18fb | |||
| 442f1ea842 | |||
| 8e25e23e81 | |||
| 118993a01f | |||
| a017a27b60 | |||
| 8f361981bf | |||
| 847a3f0dc3 | |||
| 49a5c057db | |||
| 4bb6ae20cd | |||
| 5deffbdbfb | |||
| ad757e9ba8 | |||
| 07fbb74485 | |||
| ca6fa2244b | |||
| e63b57db19 | |||
| 205c1110c2 | |||
| fb4432b307 | |||
| 3328c52cb4 | |||
| ab44515e8b | |||
| cb6ecaaba6 | |||
| 78365d648c | |||
| 4ba51c502b | |||
| e9eddbb26e | |||
| ab3b230d01 | |||
| c00ca3620d | |||
| 45d3d8164d | |||
| defdcb409f | |||
| 4d76ee6d0e | |||
| bdc9dbde8d | |||
| 3fc2f23e10 | |||
| 09e732bfa3 | |||
| 50ba6e9c56 | |||
| 6a23e79f4c | |||
| 2dbe665bdc | |||
| 8d6c0f9ac0 | |||
| 51f2b5fbfa | |||
| 2cd4e25682 | |||
| 1a0afb6d39 | |||
| 05dffbfa15 | |||
| a0a6c14758 | |||
| ed7fd4e013 | |||
| bf9cd1bffd | |||
| ca621c9db8 | |||
| 507a21a318 | |||
| f396cb1fef | |||
| 2b85f63e2b | |||
| e742f1e88b | |||
| 2ccadce34a | |||
| b0ff254cd8 | |||
| c3362851ff | |||
| 804054df33 | |||
| 1bc3bec977 | |||
| 309b180087 | |||
| 118d57d710 | |||
| 0cb2b2cebb | |||
| daeb24bbeb | |||
| f4766d32ff | |||
| b920c894b9 | |||
| 37038a7591 | |||
| 944306e45c | |||
| 9ed0c24d11 | |||
| 50349dd8e9 | |||
| e2fd28a35b | |||
| 15c35c49de | |||
| a49d8d99b6 | |||
| aa9d689c76 | |||
| b59d4484ec | |||
| cd23119470 | |||
| 18ab639669 | |||
| fc03905777 | |||
| ea8152ebf3 | |||
| 78973e3fbf | |||
| 317f910f3c | |||
| d36fe13bcd | |||
| 15b878f2a4 | |||
| 09eda9a11e | |||
| 23c0cc7a5f | |||
| 1725b9e4b4 | |||
| cc9933d1ce | |||
| b810cabc6d | |||
| 25aee745cc | |||
| 097c7dec4b | |||
| 92cf51ba3d | |||
| 94d2a88581 | |||
| da21cd3daa | |||
| 19cb312465 | |||
| 2b7ef65cce | |||
| 745c192693 | |||
| 34532dc9bf | |||
| f053908acb | |||
| 959e0b66cb | |||
| ac1e0a9f13 | |||
| 2a208d5dea | |||
| 82c447b193 | |||
| 75765bf9d4 | |||
| 6479365d6a | |||
| d11757c854 | |||
| 479de04f7c | |||
| cebeefdb22 | |||
| e93e4a7721 | |||
| cd6b82abd8 | |||
| 047ffd7b16 | |||
| bca1d8afea | |||
| 0418370c31 | |||
| cd206d6baa | |||
| aeb72154a7 | |||
| e0d3c840a2 | |||
| f2303f7fb8 | |||
| fb530e2ff5 | |||
| 8c4419e04e | |||
| 85f2c156b0 | |||
| addfcfb0b1 | |||
| b392c28787 | |||
| b534a569f8 | |||
| b0f565103f | |||
| 5e33dd9847 | |||
| 9a550cbaaf | |||
| 823e439101 | |||
| 6c299f1a1d | |||
| 7c9827875f | |||
| ae7c63c08d | |||
| 270cebc79a | |||
| ba21cc89c6 | |||
| 81a6e3674b |
@@ -39,6 +39,9 @@ src/
|
|||||||
|
|
||||||
## UI 约束
|
## UI 约束
|
||||||
|
|
||||||
|
- 使用 shared-ui CSS 变量与组件,勿各端自造设计 token
|
||||||
|
- **mini-user 微信 `openType` Button**:祖先禁止 `e.stopPropagation()`(Taro→`catchtap`,选头像/手机号等会静默失效);遮罩与 sheet 拆开绑关闭。见 `.cursor/rules/mini-user-weapp-opentype.mdc`
|
||||||
|
|
||||||
- C 端订单 **5 Tab**(含 pending_ship)
|
- C 端订单 **5 Tab**(含 pending_ship)
|
||||||
- 门店列表仅 `OPEN` 状态
|
- 门店列表仅 `OPEN` 状态
|
||||||
- 原型 `pages/` 只读;路由对照 `pages/ROUTE_MAP.md`
|
- 原型 `pages/` 只读;路由对照 `pages/ROUTE_MAP.md`
|
||||||
|
|||||||
@@ -29,4 +29,5 @@ chore(shared-types): add OrderStatus enum
|
|||||||
## Agent 行为
|
## Agent 行为
|
||||||
|
|
||||||
- **仅用户明确要求时** 才执行 git commit / push
|
- **仅用户明确要求时** 才执行 git commit / push
|
||||||
- 不 amend 已推送的 commit,不 force push main/master
|
- 不 amend 已推送的 commit,不 force push main/master/dev
|
||||||
|
- 发版:`dev`→测试(staging),`main`→生产;用户只说「发布/发版」默认发**生产**(见 dukang-release skill);明确说「发测试」才发 staging
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
---
|
||||||
|
description: 小程序子页不要画与原生导航栏重复的二级 title,标题只用 navigationBarTitleText
|
||||||
|
globs: apps/mini-user/**/*.{tsx,ts}
|
||||||
|
alwaysApply: false
|
||||||
|
---
|
||||||
|
|
||||||
|
# mini-user · 小程序导航标题
|
||||||
|
|
||||||
|
微信小程序已有原生导航栏。页面内再画一层 `SubPageHeader` / 自定义 title,会与原生标题叠成**二级 title**。
|
||||||
|
|
||||||
|
## weapp
|
||||||
|
|
||||||
|
- 页面标题只走 `index.config.ts` 的 `navigationBarTitleText`
|
||||||
|
- **不要**设 `navigationStyle: 'custom'`(除非该页需要完全自定义导航,如滚动透明顶栏、商品详情)
|
||||||
|
- **不要**在页面内再渲染与原生标题重复的 `SubPageHeader`
|
||||||
|
- H5 没有原生导航栏:可保留 `SubPageHeader`(仅返回键;H5 实现已隐藏 title 文案)
|
||||||
|
|
||||||
|
```tsx
|
||||||
|
// ✅ weapp 用原生标题;H5 保留返回栏
|
||||||
|
export default definePageConfig({
|
||||||
|
navigationBarTitleText: '申请发票',
|
||||||
|
});
|
||||||
|
|
||||||
|
{process.env.TARO_ENV === 'h5' ? (
|
||||||
|
<SubPageHeader title="申请发票" onBack={...} />
|
||||||
|
) : null}
|
||||||
|
```
|
||||||
|
|
||||||
|
```tsx
|
||||||
|
// ❌ 未配页标题 + 再画一层 SubPageHeader(weapp 会双标题)
|
||||||
|
<SubPageHeader title="申请发票" />
|
||||||
|
```
|
||||||
|
|
||||||
|
弹层/区块标题(如「编辑发票抬头」)不是导航二级 title,可保留。
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
---
|
||||||
|
description: 微信小程序 open-type 按钮踩坑 — 禁止祖先 catchtap / stopPropagation
|
||||||
|
globs: apps/mini-user/**/*.{tsx,ts,css,scss}
|
||||||
|
alwaysApply: false
|
||||||
|
---
|
||||||
|
|
||||||
|
# mini-user · 微信 open-type 硬规则
|
||||||
|
|
||||||
|
## 禁止(必踩坑)
|
||||||
|
|
||||||
|
**现象**:`Button openType="chooseAvatar" | getPhoneNumber | getUserInfo | share | contact"` 点击无反应、无回调。
|
||||||
|
|
||||||
|
**根因**:祖先节点上的 `onClick={(e) => e.stopPropagation()}` 在 Taro 微信端会编译成 **`catchtap`**,拦截子级 `button` 的原生 open-type 能力。
|
||||||
|
|
||||||
|
```tsx
|
||||||
|
// ❌ 弹层内容上 stopPropagation — 内部 chooseAvatar 会失效
|
||||||
|
<View className="mask" onClick={close}>
|
||||||
|
<View className="sheet" onClick={(e) => e.stopPropagation()}>
|
||||||
|
<Button openType="chooseAvatar" onChooseAvatar={...}>选头像</Button>
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
```
|
||||||
|
|
||||||
|
## 正确写法
|
||||||
|
|
||||||
|
遮罩与内容拆开:只在 **backdrop** 上关弹层,**sheet 不要**绑 stopPropagation / catchtap。
|
||||||
|
|
||||||
|
```tsx
|
||||||
|
// ✅
|
||||||
|
<View className="mask">
|
||||||
|
<View className="backdrop" onClick={close} />
|
||||||
|
<View className="sheet">
|
||||||
|
<Button openType="chooseAvatar" plain hoverClass="none" onChooseAvatar={...}>
|
||||||
|
...
|
||||||
|
</Button>
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
```
|
||||||
|
|
||||||
|
## 附加
|
||||||
|
|
||||||
|
- `Button` 内 `Image` / 文案加 `pointer-events: none`(或父级 `> * { pointer-events: none }`),避免抢触摸
|
||||||
|
- 同类能力:`getPhoneNumber`、`contact`、`share` 同样忌祖先 `catchtap`
|
||||||
|
- 详情见知识库「C 端 · 踩坑 · chooseAvatar」
|
||||||
|
|
||||||
|
参照实现:`apps/mini-user/src/pages/mine/index.tsx` 资料弹层。
|
||||||
@@ -13,7 +13,7 @@
|
|||||||
|
|
||||||
> **h5-partner 与 admin-web 端口同为 5175**,勿同时 `dev:partner` + `dev:admin`。
|
> **h5-partner 与 admin-web 端口同为 5175**,勿同时 `dev:partner` + `dev:admin`。
|
||||||
|
|
||||||
Vite 代理:`/api` → `localhost:3000`。
|
Vite 代理:`/api` → `localhost:3010`(可用 `VITE_API_TARGET` 覆盖)。
|
||||||
|
|
||||||
## 共享包
|
## 共享包
|
||||||
|
|
||||||
|
|||||||
@@ -1,89 +1,91 @@
|
|||||||
---
|
---
|
||||||
name: dukang-release
|
name: dukang-release
|
||||||
description: >-
|
description: >-
|
||||||
杜康好客生产发布流程:dev_jacy 提交合并到 dev,并用 deploy.sh 发版。
|
杜康好客发布流程:dev→测试(staging),main→生产;同机双栈。
|
||||||
Use when the user says 发布、上传、deploy、上线、发版, or @杜康发布 / @dukang-release.
|
Use when the user says 发布、上传、deploy、上线、发版、发测试、发生产,
|
||||||
|
or @杜康发布 / @dukang-release.
|
||||||
---
|
---
|
||||||
|
|
||||||
# 杜康发布
|
# 杜康发布
|
||||||
|
|
||||||
将已完成改动发到生产(`aliyun-smarthr`)。**仅用户明确要求发布时执行。**
|
同机双栈:`/opt/dukang-staging`(测试)与 `/opt/dukang`(生产)。**仅用户明确要求发布时执行。**
|
||||||
|
|
||||||
## 分支约定
|
## 分支与环境
|
||||||
|
|
||||||
| 分支 | 用途 |
|
| 分支 | 环境 | 目录 | 端口 | 域名 |
|
||||||
|------|------|
|
|------|------|------|------|------|
|
||||||
| `dev_jacy` | 日常开发 / 提交 |
|
| `dev_jacy` | 日常开发 | 本机 | — | — |
|
||||||
| `dev` | **发布分支**(服务器拉这个) |
|
| `dev` | **staging 测试** | `/opt/dukang-staging` | 8190–8194 | `*-test.dukanghaoke.com` |
|
||||||
|
| `main` | **production 生产** | `/opt/dukang` | 8090–8094 | `*.dukanghaoke.com` |
|
||||||
|
|
||||||
默认:`dev_jacy` → merge → `dev` → 部署。勿 force push `main`/`dev`。
|
默认:`dev_jacy` → merge → `dev` → merge → `main` → **发生产**。勿 force push `main`/`dev`。
|
||||||
|
|
||||||
|
> **团队约定(2026-08)**:用户说「发布 / 发版 / 直接发版」且**未特别强调**时 → **发生产(production)**。
|
||||||
|
> 仅当用户明确说「发测试 / staging / 测试环境」时 → 发 staging。
|
||||||
|
|
||||||
|
用户说「发生产 / 上线生产 / 发版」→ 用 `deploy-prod.sh`。
|
||||||
|
用户说「发测试」→ 用 `deploy-staging.sh`。
|
||||||
|
|
||||||
## 标准流程(Windows)
|
## 标准流程(Windows)
|
||||||
|
|
||||||
PowerShell 下 **分支名必须加引号**(否则 `checkout` 与 `dev` 会被粘成 `checkoutdev`)。
|
PowerShell 下 **分支名必须加引号**。
|
||||||
|
|
||||||
### 1. 提交(在 `dev_jacy`)
|
### A. 发测试(日常)
|
||||||
|
|
||||||
```powershell
|
|
||||||
git status -sb
|
|
||||||
git add <files>
|
|
||||||
git commit -m @"
|
|
||||||
fix(scope): summary
|
|
||||||
|
|
||||||
Optional body.
|
|
||||||
"@
|
|
||||||
```
|
|
||||||
|
|
||||||
- Conventional Commits;不提交 `.env` / `dist` / `node_modules`
|
|
||||||
- 用户未要求 commit 时不要擅自提交
|
|
||||||
|
|
||||||
### 2. 推送并合并到 `dev`
|
|
||||||
|
|
||||||
```powershell
|
```powershell
|
||||||
|
# 1. 在 dev_jacy 提交(用户要求时)
|
||||||
git push -u origin HEAD
|
git push -u origin HEAD
|
||||||
git checkout "dev"
|
git checkout "dev"
|
||||||
git pull origin "dev"
|
git pull origin "dev"
|
||||||
git merge "dev_jacy" -m "merge(dev_jacy): <简述>"
|
git merge "dev_jacy" -m "merge(dev_jacy): <简述>"
|
||||||
git push origin "dev"
|
git push origin "dev"
|
||||||
git checkout "dev_jacy"
|
git checkout "dev_jacy"
|
||||||
|
|
||||||
|
# 2. 发 staging
|
||||||
|
& "C:\Program Files\Git\bin\bash.exe" "<repo>/deploy/deploy-staging.sh" -- --skip-db
|
||||||
```
|
```
|
||||||
|
|
||||||
### 3. 远程发版
|
### B. 发生产(验收后)
|
||||||
|
|
||||||
本机无 WSL bash 时用 **Git Bash**:
|
|
||||||
|
|
||||||
```powershell
|
```powershell
|
||||||
& "C:\Program Files\Git\bin\bash.exe" "<repo>/deploy/deploy.sh" --branch "dev" -- --skip-db
|
git checkout "main"
|
||||||
|
git pull origin "main"
|
||||||
|
git merge "dev" -m "merge(dev): <简述>"
|
||||||
|
git push origin "main"
|
||||||
|
git checkout "dev_jacy"
|
||||||
|
|
||||||
|
& "C:\Program Files\Git\bin\bash.exe" "<repo>/deploy/deploy-prod.sh" -- --skip-db
|
||||||
```
|
```
|
||||||
|
|
||||||
- 默认加 `--skip-db`(无迁移时)
|
- 默认加 `--skip-db`(无迁移时)
|
||||||
- 有 Prisma 迁移时去掉 `--skip-db`,按用户确认是否 `--seed` / `--accept-data-loss`
|
- 有 Prisma 迁移:先在 **staging** 跑通(可 `--seed` / `--accept-data-loss`),再生产去掉 `--skip-db`
|
||||||
- `deploy/deploy.env` 提供 `DEPLOY_HOST` 等(勿提交密钥)
|
- Staging 微信:正式号 + 全 Mock(`.env.staging`)
|
||||||
|
- `deploy/deploy.env` 提供 `DEPLOY_HOST`、`STAGING_APP_ROOT`、`PROD_APP_ROOT`(勿提交密钥)
|
||||||
|
|
||||||
### 4. 等待完成
|
### 首次启用 Staging
|
||||||
|
|
||||||
后台跑部署时轮询终端输出,成功标志:
|
服务器一次性:`bash deploy/bootstrap-staging.sh`(见脚本说明)→ 配 `.env.staging` → DNS `*-test` → nginx → `deploy-staging.sh -- --seed`
|
||||||
|
|
||||||
|
### 同步环境变量
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
bash deploy/sync-api-env.sh staging
|
||||||
|
bash deploy/sync-api-env.sh production
|
||||||
|
```
|
||||||
|
|
||||||
|
## 等待完成
|
||||||
|
|
||||||
- 出现 `发版完成`
|
- 出现 `发版完成`
|
||||||
- `exit_code: 0`
|
- `exit_code: 0`
|
||||||
- `mini-user(h5): 200`(或对应前端 200)
|
- `mini-user(h5): 200` / `api: 200`
|
||||||
|
|
||||||
说明:API 健康检查短暂 `FAIL`/`000` 多为重启中,以 `发版完成` + `exit_code: 0` 为准。
|
## 回复用户
|
||||||
|
|
||||||
### 5. 回复用户
|
说明:环境(测试/生产)、commit、建议硬刷验证。测试后台有橙色「测试环境」条。
|
||||||
|
|
||||||
一句说明:已合并 commit、发版结果、建议微信强刷验证。
|
|
||||||
|
|
||||||
## 常用变体
|
|
||||||
|
|
||||||
| 场景 | 做法 |
|
|
||||||
|------|------|
|
|
||||||
| 仅部署已推送的 `dev` | 跳过 commit/merge,直接跑 `deploy.sh --branch "dev" -- --skip-db` |
|
|
||||||
| 检查服务器 | `deploy.sh --branch "dev" --check` |
|
|
||||||
| 含 DB | `deploy.sh --branch "dev" --`(无 skip-db)或按用户给 seed 参数 |
|
|
||||||
|
|
||||||
## 禁止
|
## 禁止
|
||||||
|
|
||||||
- 不 amend 已推送 commit;不 force push `main`/`master`/`dev`
|
- 不 amend 已推送 commit;不 force push `main`/`dev`
|
||||||
- 不把 `.env` / 私钥打进仓库
|
- 不把 `.env*` 私钥打进仓库
|
||||||
- 用户只说「修好」未说发布时 → **只改代码,不发版**
|
- **禁止**再用 `dev` 直发生产
|
||||||
|
- 用户只说「修好」未说发布 → 只改代码,不发版
|
||||||
|
|||||||
@@ -51,7 +51,7 @@
|
|||||||
|-----|------|----------|
|
|-----|------|----------|
|
||||||
| ACC-010 | 工单 | 四类型;总部决策;补发/退款流转 |
|
| ACC-010 | 工单 | 四类型;总部决策;补发/退款流转 |
|
||||||
| ACC-011 | 发票 | 四组合申请;2 工作日回传;可下载 |
|
| ACC-011 | 发票 | 四组合申请;2 工作日回传;可下载 |
|
||||||
| ACC-012 | 代下单 | W3:手机号建用户;权益自动发 |
|
| ACC-012 | 代下单 | W3:客户+合伙人双短信;手机号建用户(来源 PARTNER_PROXY);线下确认后已付款已完成并发权益;C 端展示代下单人 |
|
||||||
| ACC-013 | 问卷评价 | 成交问卷无激励;核销评价;总部可看 |
|
| ACC-013 | 问卷评价 | 成交问卷无激励;核销评价;总部可看 |
|
||||||
| ACC-014 | 推广分享 | 推广码归因;商品分享带渠道 |
|
| ACC-014 | 推广分享 | 推广码归因;商品分享带渠道 |
|
||||||
| ACC-018 | 话术 | OPT-012 3 日内对齐 |
|
| ACC-018 | 话术 | OPT-012 3 日内对齐 |
|
||||||
|
|||||||
@@ -32,6 +32,7 @@
|
|||||||
| REQ-U-024 | 推广码 | 扫码归因;现场提货有码归码 |
|
| REQ-U-024 | 推广码 | 扫码归因;现场提货有码归码 |
|
||||||
| REQ-U-025 | 分享 | 微信商品分享+渠道参数 |
|
| REQ-U-025 | 分享 | 微信商品分享+渠道参数 |
|
||||||
| REQ-U-026 | 门店规则 | 附件一完整展示 |
|
| REQ-U-026 | 门店规则 | 附件一完整展示 |
|
||||||
|
| REQ-U-027 | 门店套餐 **3.4.10** | 门店详情展示生效套餐;套餐异议申诉入口 |
|
||||||
|
|
||||||
## 门店端 REQ-S
|
## 门店端 REQ-S
|
||||||
|
|
||||||
@@ -58,6 +59,7 @@
|
|||||||
| REQ-S-018 | 权限 | §4.6 矩阵 |
|
| REQ-S-018 | 权限 | §4.6 矩阵 |
|
||||||
| REQ-S-019 | 多店选店 | 记住上次所选 |
|
| REQ-S-019 | 多店选店 | 记住上次所选 |
|
||||||
| REQ-S-020 | 待处理核销 | Wave 3 弱网单 |
|
| REQ-S-020 | 待处理核销 | Wave 3 弱网单 |
|
||||||
|
| REQ-S-021 | 门店套餐 **3.4.10** | 套餐列表/编辑/提审 |
|
||||||
|
|
||||||
## 合伙人端 REQ-P
|
## 合伙人端 REQ-P
|
||||||
|
|
||||||
@@ -89,6 +91,7 @@
|
|||||||
| REQ-P-024 | 负责人复核 | 待复核→待总部审 |
|
| REQ-P-024 | 负责人复核 | 待复核→待总部审 |
|
||||||
| REQ-P-025 | 合同同日 | 同日提交校验 |
|
| REQ-P-025 | 合同同日 | 同日提交校验 |
|
||||||
| REQ-P-026 | 我的仓库 | Wave 3 管仓只读 |
|
| REQ-P-026 | 我的仓库 | Wave 3 管仓只读 |
|
||||||
|
| REQ-P-027 | 门店套餐 **3.4.10** | 拓店套餐页;门店套餐列表/编辑/提审 |
|
||||||
|
|
||||||
## 总部端 REQ-H
|
## 总部端 REQ-H
|
||||||
|
|
||||||
@@ -122,3 +125,4 @@
|
|||||||
| REQ-H-022 | 签约主体 | 山西领势酒业 |
|
| REQ-H-022 | 签约主体 | 山西领势酒业 |
|
||||||
| REQ-H-023 | 热力图 | 腾讯位置服务 |
|
| REQ-H-023 | 热力图 | 腾讯位置服务 |
|
||||||
| REQ-H-024 | 结算异议 | 门店 3 日异议处理 |
|
| REQ-H-024 | 结算异议 | 门店 3 日异议处理 |
|
||||||
|
| REQ-H-025 | 门店套餐 **3.4.10** | 门店详情套餐 Tab 直存;套餐变更审核通过/驳回 |
|
||||||
|
|||||||
@@ -8,7 +8,13 @@ server/dukang-api/.env
|
|||||||
server/dukang-api/.env.development
|
server/dukang-api/.env.development
|
||||||
server/dukang-api/.env.production
|
server/dukang-api/.env.production
|
||||||
server/dukang-api/.env.production.local
|
server/dukang-api/.env.production.local
|
||||||
|
server/dukang-api/.env.staging
|
||||||
|
server/dukang-api/.env.staging.local
|
||||||
deploy/deploy.env
|
deploy/deploy.env
|
||||||
|
deploy/.staging-mysql.pass
|
||||||
|
deploy/_ops-*.log
|
||||||
|
deploy/_ops-*.sh
|
||||||
|
|
||||||
.DS_Store
|
.DS_Store
|
||||||
coverage/
|
coverage/
|
||||||
*.tsbuildinfo
|
*.tsbuildinfo
|
||||||
|
|||||||
@@ -0,0 +1,45 @@
|
|||||||
|
# 2026-08-12 工作记录
|
||||||
|
|
||||||
|
## 杜康好客 · 三项功能需求落地(dev_jacy 分支)
|
||||||
|
|
||||||
|
### 需求1:管理端用户列表增加好客权益金额列
|
||||||
|
- 后端 `server/dukang-api/src/modules/ops/admin-users.service.ts`:
|
||||||
|
- 新增常量 `BENEFIT_STAT_STATUSES = ['ACTIVE','USED_UP']`、`UserBenefitStat` 类型、`EMPTY_BENEFIT_STAT`、`toAmount()`。
|
||||||
|
- `list()` / `detail()` 均调用新增私有方法 `loadBenefitStats(userIds)`,用 `benefitCoupon.groupBy({ by:['userId'], where:{status:{in:[...BENEFIT_STAT_STATUSES]}}, _sum:{totalAmount,usedAmount,balance} })` 批量聚合,避免 N+1。
|
||||||
|
- `mapAdminUserRow` 增加 `benefit` 参数并展开到返回对象。统计口径与 C 端 `listCoupons` 一致(排除 VOID)。
|
||||||
|
- 前端 `apps/admin-web/src/lib/api.ts`:`AdminUserRow` 增加 `benefitTotalAmount?/benefitUsedAmount?/benefitBalance?: number`。
|
||||||
|
- 前端 `apps/admin-web/src/pages/UsersPage.tsx`:新增「剩余权益/已用权益/累计权益」三列(右对齐、可排序,scroll x 改为 1830),详情抽屉 Descriptions 增加「好客权益」项。
|
||||||
|
|
||||||
|
### 需求2:管理端门店入驻合同支持多图上传
|
||||||
|
- 新建共享工具 `server/dukang-api/src/common/store-media/contract-urls.util.ts`:`MAX_CONTRACT_FILES=20`、`normalizeContractUrls(urls?, legacy?)`、`contractMediaType(url)`(.pdf→FILE 否则 IMAGE)。
|
||||||
|
- 后端 `admin-stores.service.ts`:import 上述工具;create(645 行)/ update(451 行)路径由单条 `contractUrl` 改为遍历建立多条 `bizType:'CONTRACT'` 记录(`sortOrder:i`、`mediaType` 按扩展名判定)。
|
||||||
|
- DTO `admin-mutate.dto.ts`:`contractUrl?:string` 标记 `@deprecated`,新增 `contractUrls?:string[]`(`@IsArray @IsString({each:true}) @ArrayMaxSize(20)`)。
|
||||||
|
- 前端 `apps/admin-web/src/lib/storeCreate.ts`:`StoreCreateForm.contractUrl?:string` → `contractUrls?:string[]`。
|
||||||
|
- `MultiImageUpload.tsx`:新增 `isPdf()`、`FilePdfOutlined`、PDF 缩略图卡片、`buttonText` prop。
|
||||||
|
- `StoresPage.tsx`:编辑抽屉 + 创建 step1 表单均改用 `MultiImageUpload`(name=contractUrls, maxCount=20, accept=image/*,.pdf, buttonText="批量上传合同"),回显/保存 payload 改为 `contractUrls:string[]`。
|
||||||
|
|
||||||
|
### 需求3:合伙人 H5 门店入驻合同支持多图上传
|
||||||
|
|
||||||
|
## 发布流水线(同一会话,22:45 后)
|
||||||
|
|
||||||
|
完整跑通 dukang-release 标准流程:`dev_jacy` → push → merge `dev` → merge `main` → 发生产。
|
||||||
|
- 提交 `8805335` feat(ops,store,partner): 用户权益列 + 门店合同多图上传(13 文件,356+/59-)
|
||||||
|
- `dev_jacy` push → `origin/dev_jacy`(8805335)
|
||||||
|
- merge `dev_jacy`→`dev` → `491f03e`,push `origin/dev`
|
||||||
|
- merge `dev`→`main` → `4a0e184`,push `origin/main`
|
||||||
|
- `deploy/deploy-prod.sh -- --skip-db`(无 Prisma schema 变更,故 --skip-db)→ `DEPLOY_EXIT=0`,`==> 发版完成 (production)`
|
||||||
|
- 生产 PM2 全 online:`dukang-api`(8090) / admin-web / h5-partner / h5-shop / h5-user;健康检查 `api:200` `mini-user(h5):200`;版本记录 commit=4a0e184
|
||||||
|
|
||||||
|
### 踩坑/注意
|
||||||
|
- `git checkout main` 时本机工作树出现 `server/dukang-api` 大量 `D`(误删)假象:实为 sandbox 下 checkout 未刷新工作树,非仓库损坏。用 `git checkout -f main` 重新填充即恢复;`origin/main` 始终正确(ls-remote 核对 4a0e184)。
|
||||||
|
- 提交/合并后 `git status` 报 "ahead of origin by N" 为本地 tracking ref 陈旧,非真实分歧(ls-remote 已核对远程三分支均含本次提交)。
|
||||||
|
- 仅提交 13 个需求文件 + 新建 `server/dukang-api/src/common/store-media/`,已排除 `.workbuddy/` 与 `fix_acl.ps1`。
|
||||||
|
- 发布命令在 sandbox 下直接运行 SSH 部署成功(未强制禁用沙箱)。
|
||||||
|
- `apps/h5-partner/src/lib/storeDraft.ts`:`StoreDraftForm.contractUrl:string` → `contractUrls:string[]`;`defaultStoreForm` 改为 `contractUrls:[]`;新增 `MAX_CONTRACT_COUNT=20`;`normalizeStoreDraftForm` 新增 `contractUrls` 计算(兼容旧 `contractUrl` 迁移为数组,去重限 20);`validateStoreStep2` 参数/校验改为 `contractUrls`,不足 1 张返回「请上传签约合同」。
|
||||||
|
- `MultiOssUploadField.tsx`:新增 `accept?`、`unit?` props,`isPdf()`,PDF 缩略图卡片。
|
||||||
|
- `StoreCreatePage.tsx`:签约合同区块 `OssUploadField` → `MultiOssUploadField`(value=`form.contractUrls ?? []`, maxCount=MAX_CONTRACT_COUNT, unit="个", accept="image/*,.pdf");提交体 `contractUrl` → `contractUrls`,新增 `const contractUrls = Array.from(new Set(...)).slice(0, MAX_CONTRACT_COUNT)`;envPhotoUrls slice 上限由 3 改为 20。修正了渲染块误用未定义变量 `contractUrls`(已改为从 form 读取)。
|
||||||
|
|
||||||
|
### 验证
|
||||||
|
- 后端 `npx tsc --noEmit`(server/dukang-api)通过,exit 0。
|
||||||
|
- admin-web / h5-partner 使用 `git stash` 基线对比法:本次改动**未引入任何新类型错误**(现存错误均为预存在基线问题:css module 声明、`import.meta.env`、过期 config 类型、TabLayout `end`、staff `staffRole` 等)。
|
||||||
|
- 向后兼容:旧 `contractUrl` 字段保留并标记 deprecated,H5 草稿旧数据自动迁移;避免破坏现有 API 客户端。
|
||||||
@@ -0,0 +1,79 @@
|
|||||||
|
# 2026-08-16
|
||||||
|
|
||||||
|
## 新增:线上库同步本地 CLI 工具
|
||||||
|
- 文件:`deploy/sync-prod-db-to-local.sh`(新建,未提交)
|
||||||
|
- 用途:将生产库 `dukang_prod`(阿里云 RDS `rm-bp139andp1aa385i9.mysql.rds.aliyuncs.com:3306`,用户 `dukangadmin`)同步到本地 Docker MySQL `dukang_haoke`(localhost:6016 / 容器内 `dukang-v1-mysql`,root/root)。
|
||||||
|
- 原理:SSH 隧道借道 `dukang-server`(`-L 6018:rds:3306`)→ 本地无 mysql 客户端,故在 `dukang-v1-mysql` 容器内跑 mysqldump/mysql,经 `host.docker.internal:TUNNEL_PORT` 连隧道;管道直导,不落临时文件。
|
||||||
|
- 安全:默认先 `docker exec mysqldump` 备份本地到 `deploy/backups/`;需 `--yes` 跳过交互确认;`--dry-run` 只读远端 DATABASE_URL 并打印计划。
|
||||||
|
- 远端凭据从 `/opt/dukang/server/dukang-api/.env.production` 的 DATABASE_URL 运行时解析(密码经 `MYSQL_PWD` 环境变量传入,避免命令行暴露)。
|
||||||
|
- 已知限制:不支持密码含 `@`;prod DB 名与本地不同(dukang_prod→dukang_haoke)靠 mysqldump 不带 `--databases` 实现库名映射。
|
||||||
|
- 状态:仅跑通 `--dry-run`,未执行真实同步(待用户确认,因会覆盖本地库并拉取生产数据)。
|
||||||
|
|
||||||
|
## 修复:首次同步失败的根因
|
||||||
|
- 失败现象:`mysqldump` 退出码 2,提示 `本地库可能处于不一致状态`(工具自身的失败兜底提示)。
|
||||||
|
- 真实根因有两条:
|
||||||
|
1. **密码解析错误**:生产 DB 密码含 `@` 字符(`passHasAt=true`)。原 bash 解析用「第一个 @」切分 userinfo/host,把密码里 `@` 之后的部分截断,导致 Access denied。
|
||||||
|
修复:改为在服务端用 `new URL()` 解析,base64 回传各字段(user/host/port/db/password),本地 `base64 -d` 还原,彻底免疫 `@`/`:`/`$` 等特殊字符。服务端 auth 测试 `authTestStatus=0` 验证密码正确。
|
||||||
|
2. **权限不足**:`dukangadmin`(应用库用户)无 `RELOAD`/`FLUSH_TABLES` 权限。`--single-transaction` 仍会触发全局 `FLUSH TABLES` → Access denied。
|
||||||
|
修复:`mysqldump` 改用 `--lock-tables=0`(不发起 FTWRL)+ `--set-gtid-purged=OFF`(RDS 启用 GTID,否则本地恢复会报 GTID_PURGED 错误),并保留 `--skip-routines --skip-events --column-statistics=0 --no-tablespaces --add-drop-table --skip-triggers --no-create-db`。
|
||||||
|
- 验证:结构导出(--no-data)在 4 组 flag 中仅 `--lock-tables=0` / `--skip-lock-tables`(不含 --single-transaction)退出 0。
|
||||||
|
- 现工具已修正并实际执行同步(--yes,先自动备份本地到 deploy/backups/)。
|
||||||
|
- 注意:`--lock-tables=0` 无事务一致性快照;生产库在线写入期间导出可能有极小不一致,但恢复时 mysqldump 自带 `FOREIGN_KEY_CHECKS=0`,_dev 库可接受。若需完全一致快照,可给 dukangadmin 授 RELOAD 后用 --single-transaction。
|
||||||
|
|
||||||
|
## 修改:套餐审核导航样式恢复一致
|
||||||
|
- 文件:`apps/admin-web/src/layouts/AdminLayout.tsx` 的 `attachPackageAuditBadge`(`/store-package-audits` 项)。
|
||||||
|
- 诉求演变:用户先要求「文字恒为白色」→ 后改为「不要单独处理,保持与子菜单一致,只是多一个待审徽章图标」。
|
||||||
|
- 最终实现:label 改为 `<span style={{display:'inline-flex',gap:6}}>套餐审核{pendingCount>0 && <Badge count size="small"/>}</span>`。文字无强制颜色,随菜单主题继承 normal/hover/selected 颜色;徽章仅 pendingCount>0 时作为图标提示,不参与着色。
|
||||||
|
|
||||||
|
## 发布流水线(本次收尾,含之前未上线的 8+1 文件)
|
||||||
|
- 背景:此前「联系电话脱敏+套餐多行输入+同步工具」等 9 文件 commit `8de4179` 已 push dev_jacy/dev/main,但**生产发布失败**(deploy.env 丢失导致 `未配置 DEPLOY_HOST`)。
|
||||||
|
- 修复发布:`deploy.env` 是 gitignore 的本地密钥文件,已丢失不可找回;改用 SSH 别名 `dukang-server`(~/.ssh/config:HostName 47.110.129.57 / User root / IdentityFile pem)覆盖:`bash deploy/deploy-prod.sh --host dukang-server -- --skip-db`。
|
||||||
|
- 关键排查:`origin/*` 本地缓存 ref 多次陈旧(误报 ahead/behind),必须以 `git ls-remote` 为准。本次真实远端:dev_jacy=8de4179、dev=c05cd0e、main=bac5c7a,与本地一致,无丢失。
|
||||||
|
- 本次提交:`bafb342` fix(admin) 套餐审核样式 → push dev_jacy → merge dev(`0bfc19b`) → merge main(`029fd69`) → push。
|
||||||
|
- 发布结果:`DEPLOY_EXIT=0`,`==> 发版完成 (production)`,健康检查 api:200 / mini-user(h5):200,系统版本记录 commit `029fd69`。
|
||||||
|
- 提示:以后若想恢复标准 `bash deploy/deploy-prod.sh`(不带 --host),需重建 `deploy/deploy.env`(从 `deploy.env.example` 复制,填入 DEPLOY_HOST=47.110.129.57 等;该文件 gitignore,勿提交)。
|
||||||
|
|
||||||
|
## 排查:h5-partner 本地 /login 调 /partner/me 报 401
|
||||||
|
- 现象:`http://localhost:5176/login` 启动后控制台报 `GET /api/v1/partner/me 401 (Unauthorized)`。
|
||||||
|
- 结论:**不是 bug,是登录页的「过期 token 探测」**。链路:Vite 代理 `/api`→`localhost:3010`(正常);后端返回 `{"code":401,"message":"Missing token"}`(说明后端在线、代理通)。`ensureSession()`(api.ts:244)只在 localStorage 有 token 时才打 `/partner/me`;无 token 直接返回未登录。所以 401 来自之前测试残留的失效 token → 前端静默清除并展示登录表单,不崩、不弹错。刷新页面(token 已清)即不再出现。
|
||||||
|
- 本地登录方式(关键,README 已过期):
|
||||||
|
- `MOCK_SMS=true`(.env),短信走 mock,不连运营商;固定码 `MOCK_SMS_FIXED_CODE` 默认 `999888`(README 写的 123456 已不准)。
|
||||||
|
- README 的测试号 `13700000001` **不在本地同步库**;本地 `partner_account` 共 9 个,可用真实号如 `18049821889`(Jacy) / `13073729990`(queen)(均 ACTIVE)。
|
||||||
|
- 流程:填真实合伙人手机号 → 获取验证码 → **验证码打印在 `pnpm dev:api` 后端终端**(`Mock SMS → 180****8889 code=XXXXXX`)→ 填码登录。
|
||||||
|
- 注意 h5-partner 默认 5175,本次因 5175 被占自动落到 5176,代理是路径匹配不受影响。
|
||||||
|
|
||||||
|
## 发布:v3.4.17 门店套餐审核快捷入口 上生产
|
||||||
|
- 提交 `1c91e6b`(dev_jacy 上,含后端 admin-stores.service.ts + AdminStorePackagesSection/StorePackageAuditsPage/StoresPage 三前端 + 开发计划文档)。
|
||||||
|
- 流水线:直接快进推送(避免 git checkout 工作树不刷新):`git push origin dev_jacy` + `dev_jacy:dev` + `dev_jacy:main`,三分支统一到 `1c91e6b`;本地 `git branch -f dev/main origin/*` 同步。
|
||||||
|
- 部署:`bash deploy/deploy-prod.sh --host dukang-server -- --skip-db`(后端仅给列表响应加字段,无 schema 变更,故 skip-db)。
|
||||||
|
- 结果:`DEPLOY_EXIT=0`,新 tag `v3.4.17`,全部应用构建通过,PM2 重启 dukang-api/h5-shop/h5-partner/admin-web(另拉起 h5-user),健康检查 api:200 / mini-user(h5):200,系统版本记录 commit `1c91e6b`。
|
||||||
|
|
||||||
|
## 发布:v3.4.18 套餐变更对比逐字段列出变动明细
|
||||||
|
- 需求:套餐变更对比「将变动的地方详细列出来」(之前只给「新增/删除/变更/未变」粗粒度标记,不列具体字段)。
|
||||||
|
- 改动仅在 `apps/admin-web/src/pages/StorePackageAuditsPage.tsx`:
|
||||||
|
- 新增 `fieldChanges(live, proposed)`:逐字段比对 价格/套餐名称/菜品内容/可用时间/其他说明/图片,产出 `label+旧值→新值` 明细。
|
||||||
|
- `diffPackages` 给「变更」行附 `changes`。
|
||||||
|
- `PackageDetailCard` 在「待审核」卡片底部渲染「变更明细」块(旧值删除线 → 新值加粗,橙色块)。
|
||||||
|
- 抽屉顶部加「新增 X · 删除 Y · 变更 Z · 未变 W」汇总条。
|
||||||
|
- 提交 `bbd7e52`(feat(admin) 套餐变更对比逐字段列出变动明细),快进推送 dev_jacy/dev/main。
|
||||||
|
- 部署:`bash deploy/deploy-prod.sh --host dukang-server -- --skip-db`(无 schema 变更)。
|
||||||
|
- 结果:构建通过、PM2 重启 admin-web 等、健康检查 api:200 / mini-user(h5):200,系统版本记录 commit `bbd7e52`(无精确 tag,记 tag=-,无害)。
|
||||||
|
- 已知局限:配对按「套餐名称」(空则索引) 位置匹配;若套餐被**改名**,会误判为「删除旧名+新增新名」而非「变更」,故名称变更不会出现在逐字段明细里。
|
||||||
|
|
||||||
|
## 优化:套餐变更对比·逐字差异 + 文档并入 v3.4.17
|
||||||
|
- 需求:变动明细要能**定位到文本中具体哪些字变了(逐字检查)**,且把开发计划文档合并到 v3.4.17 文档里(不再单独留 v3.4.18 文档)。
|
||||||
|
- 代码改动(仍仅 `StorePackageAuditsPage.tsx`):
|
||||||
|
- `diffText(a,b)`:LCS 动态规划 (`dp[i][j]`)+回溯,产出 `equal/delete/insert` 段落并合并相邻同类型;`O(|a|·|b|)`,字段长度可控。
|
||||||
|
- `TextDiff({oldText,newText})`:两行渲染——「原:」红删线标被删字、「新:」绿标新增字。
|
||||||
|
- `FieldChange` 增加 `kind: 'text'|'value'`:价格/图片走 `旧→新`;套餐名称/菜品内容/可用时间/其他说明走 `TextDiff` 逐字高亮。
|
||||||
|
- `杜康好客-v3.4.17-门店套餐审核快捷入口.md` 新增第 F 节「套餐变更对比·逐字段/逐字明细」,并把原先 v3.4.18 的字段级说明并入,删去独立 v3.4.18 文档计划。
|
||||||
|
- 提交 `ecd9973`,快进推送 dev_jacy/dev/main,部署 `--host dukang-server -- --skip-db`。
|
||||||
|
- 结果:构建通过、健康检查 api:200 / mini-user(h5):200,系统版本记录 commit `ecd9973`(tag=-,无害)。
|
||||||
|
- 验证要点:开任一「变更」套餐的待审核卡片 → 底部「变更明细」→ 菜品/说明等文本以红删+绿增逐字呈现。
|
||||||
|
|
||||||
|
## 优化:h5-partner 门店详情·门店套餐「编辑套餐」按钮
|
||||||
|
- 需求:按钮**缩小、靠最右侧、保持美观**。根因:`.partner-btn-outline` 是整行大按钮(`flex:1; height:48px; font-size:16px`),放在卡片标题右侧会被拉伸成大块。
|
||||||
|
- 改动:`apps/h5-partner/src/styles.css` 新增 `.partner-btn-outline--compact`(`flex:none; height:30px; padding:0 14px; font-size:13px; font-weight:500; border-radius:var(--radius-sm); color:var(--color-primary)`,hover 用 `color-mix` 8% 底色);`StoreDetailPage.tsx:288` 的「编辑套餐」按钮加该类(父级 `space-between` 已保证贴右)。
|
||||||
|
- 提交 `69e201f`,快进推送 dev_jacy/dev/main,部署 `--host dukang-server -- --skip-db`。
|
||||||
|
- 结果:构建通过、PM2 重启 h5-partner、健康检查 api:200 / mini-user(h5):200,系统版本记录 commit `69e201f`(tag=-,无害)。
|
||||||
|
- 注意:`StoreDetailPage.tsx:311` 有个历史遗留 TS 错误(`status === 'CLOSED'` 类型无重叠),与本改动无关,未动。
|
||||||
@@ -0,0 +1,70 @@
|
|||||||
|
# 2026-08-17 工作日志
|
||||||
|
|
||||||
|
## 杜康好客 v3.4.18 门店体验与登录态优化(含 F 项)
|
||||||
|
|
||||||
|
### 已实现并发布
|
||||||
|
- **A** mini-user 门店座机脱敏:改 `apps/mini-user/src/lib/phone.ts` 的 `maskPhone` 座机分支,中间四位 `****`(保留区号+首2+末2)。
|
||||||
|
- **B** 套餐详情图 1/5 计数 + 自动轮播:`ProductCarousel.tsx` detail 变体加 autoplay(3.5s) + 右下角 `1/N` 计数。
|
||||||
|
- **C** 合伙人暂停禁止登录:`auth.service.ts` 三处非 ACTIVE 抛「该账号已暂停使用,请联系客服人员」;`h5-partner/LoginPage.tsx` 同步文案;复用 `DISABLED` 枚举,无迁移。
|
||||||
|
- **D** 门店端提现/筛选栏留白对齐:`h5-shop/styles.css` 补 `--space-page`。
|
||||||
|
- **E** 休息中核销→是否开启营业:`PhoneRedeemPage`/`RedeemConfirmPage` 弹「是否开启营业?」,确认调 `PUT /shop/store/status` 开张后继续。
|
||||||
|
- **F(本次新增)** 门店套餐图片自适应完整显示:`ProductCarousel` 新增 `imageFit="adaptive"`(`mode="widthFix"` + 按真实比例动态算 Swiper 高度),`product-detail.css` 加 `.detail-carousel-wrap--adaptive` 覆盖固定 1:1 裁剪;仅 `store-package-detail` 使用。根因:原 `.detail-carousel-wrap` 固定 `aspect-ratio:1` + `overflow:hidden` + `aspectFill` 裁掉非正方形图。
|
||||||
|
|
||||||
|
### 发布状态
|
||||||
|
- 文档:`杜康好客-v3.4.18-门店体验与登录态优化.md`(含 A–F 范围、实现位置、验收清单)。
|
||||||
|
- git:本地 `dev_jacy` 提交 v3.4.18 各功能 + F 修复;已 `git push origin dev_jacy:main`(干净快进 `984dec7..18147e1`)。
|
||||||
|
- 生产部署:后台运行 `deploy/deploy-prod.sh --host dukang-server`(/opt/dukang, main)。SSH 配置主机 `dukang-server` 即生产机;`deploy.env` 缺失,用 `--host` 覆盖。
|
||||||
|
|
||||||
|
### 注意
|
||||||
|
- 本次 git 发布前曾遇 origin/main 比本地新、working tree 异常删除 503 文件(已 `reset --hard HEAD` 还原,提交完好);最终 fetch 后确认本地领先可快进,安全发布。
|
||||||
|
- 四端 tsc 仅余项目既有环境类报错(CSS 导入/ImportMeta.env),本次改动文件无新增类型错误。
|
||||||
|
|
||||||
|
### F 项方案 A 改写(22:18)
|
||||||
|
- 放弃手算高度逻辑(SelectorQuery + onLoad 测自然宽高),改用 swiper 原生 `autoHeight`:海报有多高轮播就有多高,无裁切。
|
||||||
|
- `ProductCarousel.tsx`:删 `wrapWidth`/`imgHeights`/`handleImageLoad`/`swiperStyle`,adaptive 模式加 `autoHeight={isAdaptive}`,image 保持 `mode="widthFix"`。
|
||||||
|
- `product-detail.css`:`.detail-carousel-wrap--adaptive` 覆盖(删 `aspect-ratio:1`/`overflow:hidden`),并给 `.detail-carousel`/`.detail-carousel-item`/`.detail-carousel-image` 在 adaptive 下 `height:auto`。
|
||||||
|
- 已提交 `cd1e9ae` 并 `git push origin dev_jacy:main`(干净快进 `18147e1..cd1e9ae`)。
|
||||||
|
- 重要:F 是原生微信小程序端改动,服务器部署只覆盖 H5-user 构建;真机小程序用户需经「微信开发者工具上传 + 微信审核」才能生效。
|
||||||
|
|
||||||
|
### E 项缺陷修复(22:46 测试不通过)
|
||||||
|
- **根因**:门店非 OPEN 时,后端 `redeem.service.ts:loadOpenStoreAccount`(previewRedeem/confirmRedeem 共用)抛「门店未营业」,导致 `RedeemConfirmPage` 的 `preview` 拉取失败 → `preview` 为 null → 「确认核销」按钮 `disabled={!preview}` → 点击不了 → 开张弹窗永远不触发。手机号路径因弹窗在「发送验证码」时触发故未暴露。
|
||||||
|
- **修复**:`RedeemConfirmPage` 把 preview 拉取抽成 `loadPreview()`;确认按钮改为 `disabled={loading || (!preview && !storeClosed)}`(闭店时仍可点→弹框);`openStoreAndContinue` 开张成功后 `await loadPreview()` 再 `doConfirm()`。
|
||||||
|
- 弹窗文案对齐需求:「门店目前休息中无法核销,是否开启营业」(两页 modal title=门店休息中 / desc=该句;内联提示改为「门店目前休息中无法核销,开启营业后可继续」)。
|
||||||
|
- 提交 `3ac008a`,`git push origin dev_jacy:main`(快进 `cd1e9ae..3ac008a`),生产重新部署中(deploy-prod.sh --host dukang-server)。
|
||||||
|
- 注意:后端 `updateShopStatus` 对 CLOSED(永久关闭) 门店拒绝开张(抛「门店已永久关闭...」),属预期;需求针对 闭店/休息中(PAUSED) 场景,OK。
|
||||||
|
|
||||||
|
### E 项方案二次修正(23:00 用户纠正:前置到点击扫码)
|
||||||
|
- **用户新要求**:门店 PAUSED 时,**点击「扫码核销」按钮那一刻就弹窗**,而不是扫完码进确认页才弹。
|
||||||
|
- **改动**:`apps/h5-shop/src/pages/HomePage.tsx`(门店端首页)。
|
||||||
|
- 复用 dashboard 已加载的 `status`(`dash?.store?.status`,L384 `status = String(store?.status||'')`)。
|
||||||
|
- `handleScan()` 开头:`if (status !== 'OPEN') { setShowOpenModal(true); return; }` —— 不进入 isWechatEnv/scanQrCode 流程。
|
||||||
|
- 新增 `openStoreAndContinue()`:`PUT /shop/store/status {OPEN}`,成功后 `loadDashboard()` 刷新状态(开关/扫码按钮同步),用户可再次点击扫码。
|
||||||
|
- 弹窗复用全局 `.shop-redeem-modal` 样式(与确认页一致),文案「门店目前休息中无法核销,是否开启营业?」。
|
||||||
|
- `RedeemConfirmPage` 的弹窗保留为带码直入确认页的兜底。
|
||||||
|
- 提交 `c0d04ee`,`git push origin dev_jacy:main`(快进 `3ac008a..c0d04ee`),生产重新部署中(deploy-prod.sh --host dukang-server)。文档 E 节已同步更新方案描述。
|
||||||
|
|
||||||
|
### C 项缺陷修复(合伙人端 DISABLED 仍登录 - 微信路径)
|
||||||
|
- **现象**:手机号(短信)路径已正确拦截(login 前先 `POST /partner/auth/phone/check` 校验非 ACTIVE 即拒),但**微信 OAuth 路径**报错被吞 → 用户无任何提示。
|
||||||
|
- **根因**:`apps/h5-partner/src/contexts/PartnerSessionContext.tsx` L118 `catch { stripOAuthParamsFromLocation(); }` 把微信回调里 `processPartnerWechatOAuthCallback` 抛出的「该账号已暂停使用」错误吞掉。
|
||||||
|
- **修复**:`catch (e) { stripOAuthParamsFromLocation(); toastError(e); }`(`toastError` 从 `@/lib/toast` 引入),让微信登录被暂停时同样弹「该账号已暂停使用,请联系客服人员」。
|
||||||
|
- 提交 `5ca9aa0`,`git push origin dev_jacy:main`(快进 `c0d04ee..5ca9aa0`)。
|
||||||
|
- 生产部署完成(deploy-prod.sh --host dukang-server, 38s):dukang-api 200、各 h5/partner 服务 online。mini-user(h5) 健康检查 FAIL 与本次无关(非 v3.4.18 改动范围,本次改 native 小程序 + h5-shop + h5-partner)。
|
||||||
|
- **验收状态**:A/B/C/D/E/F 全部提交并发布生产;C 项的短信 + 微信两条路径拦截逻辑均已落地,建议真机/微信环境复测一次确认 toast 文案展示。
|
||||||
|
|
||||||
|
### C 项双拦截增强(23:37 用户要求“两个都要拦”)
|
||||||
|
- **澄清**:city 合伙人有两个独立状态字段,别混:
|
||||||
|
- `partner_account.status`(AccountStatus: ACTIVE/DISABLED)= **登录账号启用态**,feature 原拦截查的就是它(子账号自身)。
|
||||||
|
- `partner_account.bindingStatus`(CityPartnerStatus: ACTIVE/PAUSED)= **城市合伙人绑定态**,主账号为准;子账号取父主账号的此字段。
|
||||||
|
- **需求**:子账号 `status=DISABLED` 与 主账号 `bindingStatus=PAUSED` **都要拦**。
|
||||||
|
- **实现**:`auth.service.ts` 新增统一闸门 `assertPartnerAccountActive(account)`(L313),同时拦上述两种;替换三处旧校验:`assertPartnerAccountByPhone`(L334) / `loginPartner`(L1086) / `loginPartnerWechat`(L1748)。
|
||||||
|
- 自身非 ACTIVE → 「该账号已暂停使用,请联系客服人员」
|
||||||
|
- 主账号 bindingStatus 非 ACTIVE → 「该合伙人合作已暂停,请联系客服人员」
|
||||||
|
- **文档**:`杜康好客-v3.4.18-...md` C 节重写为双拦截;顶部范围表 + 验收清单同步。
|
||||||
|
- 提交 `48d6900`,`git push origin dev_jacy:main`(快进 `5ca9aa0..48d6900`),生产部署完成(task I2mWSU, 37s):commit=48d6900、api 200、各服务 online。
|
||||||
|
- **生产实测双拦截均生效**:
|
||||||
|
- `status=DISABLED`(id=7 临时翻转→测试→已还原 ACTIVE):`phone/check` 返回 400「该账号已暂停使用,请联系客服人员」;还原后 201 ok:true。
|
||||||
|
- `bindingStatus=PAUSED`(18049821889 等 3 个主账号):`phone/check` 返回 400「该合伙人合作已暂停,请联系客服人员」(修复前为 200 ok:true)。
|
||||||
|
- 库内 status!=ACTIVE 数量=0;binding_status!=ACTIVE 数量=3(均为主账号 PAUSED)。
|
||||||
|
- **遗留未提交文件(非本次改动,需用户决策)**:
|
||||||
|
- `apps/h5-shop/src/styles.css`:`shop-records-status-chips` 由 `padding:0` → `padding-bottom:10px`(D 项后续微调,未提交)。
|
||||||
|
- `apps/mini-user/src/styles/product-detail.css`:工作区版本把方案A(`aspect-ratio:auto`/`height:auto`)改回固定 4:3(`aspect-ratio:1.33`/`height:100%`),与已上线方案A矛盾,疑似另一轮实验性改动。已与用户确认前**暂不提交**。
|
||||||
@@ -11,7 +11,7 @@
|
|||||||
| **V3.0 唯一需求源** | [`杜康好客-v3-PRD.md`](./杜康好客-v3-PRD.md) | 产品需求与三波交付(**只看这个**) |
|
| **V3.0 唯一需求源** | [`杜康好客-v3-PRD.md`](./杜康好客-v3-PRD.md) | 产品需求与三波交付(**只看这个**) |
|
||||||
| **现状对照** | [`杜康好客-v3-现状对照.md`](./杜康好客-v3-现状对照.md) | 已完成 / 冲突 / 缺口审计 |
|
| **现状对照** | [`杜康好客-v3-现状对照.md`](./杜康好客-v3-现状对照.md) | 已完成 / 冲突 / 缺口审计 |
|
||||||
| **V3 实现验收** | [`杜康好客-v3编码手册.md`](./杜康好客-v3编码手册.md) | 核销规则、分工、闭环 |
|
| **V3 实现验收** | [`杜康好客-v3编码手册.md`](./杜康好客-v3编码手册.md) | 核销规则、分工、闭环 |
|
||||||
| ~~V2 / preV1~~ | 历史参考 | **不再作为需求依据** |
|
| ~~V2 / preV1~~ | 历史参考(**已压缩**;V2 全文见 git 2026-08-06 前) | **不再作为需求依据** |
|
||||||
|
|
||||||
**禁止**:臆造 PRD 未定义规则;依赖 `doc/` 下过时文档;跨 OWNER 直写他人 Prisma 表。
|
**禁止**:臆造 PRD 未定义规则;依赖 `doc/` 下过时文档;跨 OWNER 直写他人 Prisma 表。
|
||||||
|
|
||||||
@@ -28,7 +28,7 @@ pnpm db:generate && pnpm db:validate
|
|||||||
cd server/dukang-api && npx prisma db push && pnpm prisma:seed
|
cd server/dukang-api && npx prisma db push && pnpm prisma:seed
|
||||||
|
|
||||||
# 开发(分终端)
|
# 开发(分终端)
|
||||||
pnpm dev:api # http://localhost:3000/api/v1
|
pnpm dev:api # http://localhost:3010/api/v1
|
||||||
pnpm dev:user # :5173
|
pnpm dev:user # :5173
|
||||||
pnpm dev:shop # :5174
|
pnpm dev:shop # :5174
|
||||||
pnpm dev:partner # :5175
|
pnpm dev:partner # :5175
|
||||||
@@ -40,7 +40,7 @@ node scripts/smoke-prev1.mjs
|
|||||||
pnpm lint && pnpm test
|
pnpm lint && pnpm test
|
||||||
```
|
```
|
||||||
|
|
||||||
Mock 验证码:`123456`。测试账号见 [`README.md`](./README.md)。
|
Mock 验证码:`999888`。测试账号见 [`README.md`](./README.md)。
|
||||||
|
|
||||||
> **端口冲突**:`h5-partner` 与 `admin-web` 同为 5175,勿同时 `dev:partner` + `dev:admin`。
|
> **端口冲突**:`h5-partner` 与 `admin-web` 同为 5175,勿同时 `dev:partner` + `dev:admin`。
|
||||||
|
|
||||||
@@ -137,6 +137,23 @@ C 端门店仅 status=OPEN
|
|||||||
订单 Tab:待付款 | 已付款 | 已完成
|
订单 Tab:待付款 | 已付款 | 已完成
|
||||||
```
|
```
|
||||||
|
|
||||||
|
**iOS 微信 H5 JSSDK**:登录/OAuth 后禁止仅 SPA 跳转再调扫码;见 `packages/weixin-sdk/GOTCHAS.md`、知识库「门店端 · 踩坑」。
|
||||||
|
**微信小程序 open-type**:`chooseAvatar` 等 Button 的祖先禁止 `stopPropagation`(会编成 catchtap);见知识库「C 端 · 踩坑」、`.cursor/rules/mini-user-weapp-opentype.mdc`。
|
||||||
|
**微信小程序页面标题**:weapp 只用原生 `navigationBarTitleText`,不要再画一层与导航栏重复的 `SubPageHeader` title;见 `.cursor/rules/mini-user-weapp-nav-title.mdc`。
|
||||||
|
|
||||||
|
## 环境与发版
|
||||||
|
|
||||||
|
| 环境 | 分支 | 目录 | 端口 | 域名 |
|
||||||
|
|------|------|------|------|------|
|
||||||
|
| local | `dev_jacy` | 本机 Docker 6016/6017 | API `:3010` | — |
|
||||||
|
| **staging 测试** | `dev` | `/opt/dukang-staging` | 8190–8194 | `*-test.dukanghaoke.com` |
|
||||||
|
| **production 生产** | `main` | `/opt/dukang` | 8090–8094 | `*.dukanghaoke.com` |
|
||||||
|
|
||||||
|
- 日常发布 → `deploy/deploy-staging.sh`(`dev`)
|
||||||
|
- 生产发布 → `deploy/deploy-prod.sh`(`main`,验收后)
|
||||||
|
- Staging:正式微信 + 全 Mock;配置见 `.env.staging.example`
|
||||||
|
- 详情:`@dukang-release` / `.cursor/skills/dukang-release/SKILL.md`
|
||||||
|
|
||||||
## 提交与 PR
|
## 提交与 PR
|
||||||
|
|
||||||
- Conventional Commits:`feat(trade):`、`fix(redeem):`;scope = 端或模块
|
- Conventional Commits:`feat(trade):`、`fix(redeem):`;scope = 端或模块
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
ayPJ4CQqbUcec3jX
|
||||||
@@ -22,6 +22,7 @@ V2 规划中的 `mini-partner` / `mini-hq` 非 V3 主交付。
|
|||||||
- 禁止 import `server/` 或另一个 `apps/*` 的源码
|
- 禁止 import `server/` 或另一个 `apps/*` 的源码
|
||||||
- UI 共享组件优先 `@dukang/shared-ui`
|
- UI 共享组件优先 `@dukang/shared-ui`
|
||||||
- C 端订单列表 **3 Tab**:`待付款 | 已付款 | 已完成`(Tab key: `pending_pay` / `paid` / `completed`)
|
- C 端订单列表 **3 Tab**:`待付款 | 已付款 | 已完成`(Tab key: `pending_pay` / `paid` / `completed`)
|
||||||
|
- **mini-user 微信 open-type**:含 `chooseAvatar` / `getPhoneNumber` 等的 `Button`,祖先禁止 `stopPropagation`(会编成 `catchtap` 导致点击无反应);见知识库 C 端踩坑、`.cursor/rules/mini-user-weapp-opentype.mdc`
|
||||||
|
|
||||||
## 新页面 workflow
|
## 新页面 workflow
|
||||||
|
|
||||||
|
|||||||
@@ -10,9 +10,13 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ant-design/icons": "^5.5.1",
|
"@ant-design/icons": "^5.5.1",
|
||||||
|
"@dukang/domain": "workspace:*",
|
||||||
"@dukang/shared-types": "workspace:*",
|
"@dukang/shared-types": "workspace:*",
|
||||||
|
"@dukang/shared-ui": "workspace:*",
|
||||||
"antd": "^5.22.0",
|
"antd": "^5.22.0",
|
||||||
"dayjs": "^1.11.13",
|
"dayjs": "^1.11.13",
|
||||||
|
"echarts": "^6.1.0",
|
||||||
|
"echarts-for-react": "^3.0.6",
|
||||||
"element-china-area-data": "^6.1.0",
|
"element-china-area-data": "^6.1.0",
|
||||||
"react": "^18.3.1",
|
"react": "^18.3.1",
|
||||||
"react-dom": "^18.3.1",
|
"react-dom": "^18.3.1",
|
||||||
|
|||||||
@@ -5,7 +5,10 @@ import LoginPage from './pages/LoginPage';
|
|||||||
import DashboardPage from './pages/DashboardPage';
|
import DashboardPage from './pages/DashboardPage';
|
||||||
import UsersPage from './pages/UsersPage';
|
import UsersPage from './pages/UsersPage';
|
||||||
import OrdersPage from './pages/OrdersPage';
|
import OrdersPage from './pages/OrdersPage';
|
||||||
|
import BigScreenPage from './pages/BigScreenPage';
|
||||||
|
import StorePackageAuditsPage from './pages/StorePackageAuditsPage';
|
||||||
import StoresPage from './pages/StoresPage';
|
import StoresPage from './pages/StoresPage';
|
||||||
|
import StoreRatingsPage from './pages/StoreRatingsPage';
|
||||||
import StoreAccountsPage from './pages/StoreAccountsPage';
|
import StoreAccountsPage from './pages/StoreAccountsPage';
|
||||||
import BenefitCouponsPage from './pages/BenefitCouponsPage';
|
import BenefitCouponsPage from './pages/BenefitCouponsPage';
|
||||||
import BenefitLedgersPage from './pages/BenefitLedgersPage';
|
import BenefitLedgersPage from './pages/BenefitLedgersPage';
|
||||||
@@ -20,6 +23,7 @@ import CityPartnersPage from './pages/CityPartnersPage';
|
|||||||
import CityWarehousesPage from './pages/CityWarehousesPage';
|
import CityWarehousesPage from './pages/CityWarehousesPage';
|
||||||
import FulfillmentProvidersPage from './pages/FulfillmentProvidersPage';
|
import FulfillmentProvidersPage from './pages/FulfillmentProvidersPage';
|
||||||
import StoreMediaPage from './pages/StoreMediaPage';
|
import StoreMediaPage from './pages/StoreMediaPage';
|
||||||
|
import StoreCategoriesPage from './pages/StoreCategoriesPage';
|
||||||
import PromoCodesPage from './pages/PromoCodesPage';
|
import PromoCodesPage from './pages/PromoCodesPage';
|
||||||
import PromoCodeDetailLayout from './pages/promo/PromoCodeDetailLayout';
|
import PromoCodeDetailLayout from './pages/promo/PromoCodeDetailLayout';
|
||||||
import PromoCodeDetailPage from './pages/promo/PromoCodeDetailPage';
|
import PromoCodeDetailPage from './pages/promo/PromoCodeDetailPage';
|
||||||
@@ -30,9 +34,12 @@ import ResourcesPage from './pages/ResourcesPage';
|
|||||||
import StoreBillsPage from './pages/StoreBillsPage';
|
import StoreBillsPage from './pages/StoreBillsPage';
|
||||||
import PartnerBillsPage from './pages/PartnerBillsPage';
|
import PartnerBillsPage from './pages/PartnerBillsPage';
|
||||||
import WineryBillsPage from './pages/WineryBillsPage';
|
import WineryBillsPage from './pages/WineryBillsPage';
|
||||||
|
import LogisticsBillsPage from './pages/LogisticsBillsPage';
|
||||||
import TicketsPage from './pages/TicketsPage';
|
import TicketsPage from './pages/TicketsPage';
|
||||||
|
import SupportTicketsPage from './pages/SupportTicketsPage';
|
||||||
import InvoicesPage from './pages/InvoicesPage';
|
import InvoicesPage from './pages/InvoicesPage';
|
||||||
import UserLogsPage from './pages/UserLogsPage';
|
import UserLogsPage from './pages/UserLogsPage';
|
||||||
|
import DomainEventsPage from './pages/DomainEventsPage';
|
||||||
import HqLogsPage from './pages/HqLogsPage';
|
import HqLogsPage from './pages/HqLogsPage';
|
||||||
import ThirdPartyLogsPage from './pages/ThirdPartyLogsPage';
|
import ThirdPartyLogsPage from './pages/ThirdPartyLogsPage';
|
||||||
import StoreLogsPage from './pages/StoreLogsPage';
|
import StoreLogsPage from './pages/StoreLogsPage';
|
||||||
@@ -40,6 +47,15 @@ import PartnerLogsPage from './pages/PartnerLogsPage';
|
|||||||
import WechatBindingsPage from './pages/WechatBindingsPage';
|
import WechatBindingsPage from './pages/WechatBindingsPage';
|
||||||
import HqPermissionsPage from './pages/HqPermissionsPage';
|
import HqPermissionsPage from './pages/HqPermissionsPage';
|
||||||
import SystemSettingsPage from './pages/SystemSettingsPage';
|
import SystemSettingsPage from './pages/SystemSettingsPage';
|
||||||
|
import TestWhitelistPage from './pages/TestWhitelistPage';
|
||||||
|
import WecomBotsPage from './pages/WecomBotsPage';
|
||||||
|
import WecomMessagePushesPage from './pages/WecomMessagePushesPage';
|
||||||
|
import WecomBotLogsPage from './pages/WecomBotLogsPage';
|
||||||
|
import LlmConfigsPage from './pages/LlmConfigsPage';
|
||||||
|
import KnowledgeBasesPage from './pages/KnowledgeBasesPage';
|
||||||
|
import DevPlanVersionsPage from './pages/DevPlanVersionsPage';
|
||||||
|
import DevPlanTasksPage from './pages/DevPlanTasksPage';
|
||||||
|
import DevPlanSettingsPage from './pages/DevPlanSettingsPage';
|
||||||
|
|
||||||
function RequireAuth({ children }: { children: React.ReactNode }) {
|
function RequireAuth({ children }: { children: React.ReactNode }) {
|
||||||
if (!getToken()) return <Navigate to="/login" replace />;
|
if (!getToken()) return <Navigate to="/login" replace />;
|
||||||
@@ -50,6 +66,14 @@ export default function App() {
|
|||||||
return (
|
return (
|
||||||
<Routes>
|
<Routes>
|
||||||
<Route path="/login" element={<LoginPage />} />
|
<Route path="/login" element={<LoginPage />} />
|
||||||
|
<Route
|
||||||
|
path="/orders/big-screen"
|
||||||
|
element={
|
||||||
|
<RequireAuth>
|
||||||
|
<BigScreenPage />
|
||||||
|
</RequireAuth>
|
||||||
|
}
|
||||||
|
/>
|
||||||
<Route
|
<Route
|
||||||
element={
|
element={
|
||||||
<RequireAuth>
|
<RequireAuth>
|
||||||
@@ -66,9 +90,21 @@ export default function App() {
|
|||||||
<Route index element={<PromoCodeDetailPage />} />
|
<Route index element={<PromoCodeDetailPage />} />
|
||||||
<Route path="users" element={<PromoCodeUsersPage />} />
|
<Route path="users" element={<PromoCodeUsersPage />} />
|
||||||
</Route>
|
</Route>
|
||||||
|
<Route path="/wecom-bots" element={<Navigate to="/wecom/bots" replace />} />
|
||||||
|
<Route path="/wecom/bots" element={<WecomBotsPage />} />
|
||||||
|
<Route path="/wecom/pushes" element={<WecomMessagePushesPage />} />
|
||||||
|
<Route path="/logs/wecom-bots" element={<WecomBotLogsPage />} />
|
||||||
|
<Route path="/llm-configs" element={<LlmConfigsPage />} />
|
||||||
|
<Route path="/knowledge-bases" element={<KnowledgeBasesPage />} />
|
||||||
|
<Route path="/dev-plan/versions" element={<DevPlanVersionsPage />} />
|
||||||
|
<Route path="/dev-plan/tasks" element={<DevPlanTasksPage />} />
|
||||||
|
<Route path="/dev-plan/settings" element={<DevPlanSettingsPage />} />
|
||||||
<Route path="/products" element={<ProductsPage />} />
|
<Route path="/products" element={<ProductsPage />} />
|
||||||
<Route path="/product-detail-templates" element={<ProductDetailTemplatesPage />} />
|
<Route path="/product-detail-templates" element={<ProductDetailTemplatesPage />} />
|
||||||
<Route path="/stores" element={<StoresPage />} />
|
<Route path="/stores" element={<StoresPage />} />
|
||||||
|
<Route path="/store-package-audits" element={<StorePackageAuditsPage />} />
|
||||||
|
<Route path="/store-ratings" element={<StoreRatingsPage />} />
|
||||||
|
<Route path="/store-categories" element={<StoreCategoriesPage />} />
|
||||||
<Route path="/store-accounts" element={<StoreAccountsPage />} />
|
<Route path="/store-accounts" element={<StoreAccountsPage />} />
|
||||||
<Route path="/store-media" element={<StoreMediaPage />} />
|
<Route path="/store-media" element={<StoreMediaPage />} />
|
||||||
<Route path="/resources" element={<ResourcesPage />} />
|
<Route path="/resources" element={<ResourcesPage />} />
|
||||||
@@ -84,21 +120,33 @@ export default function App() {
|
|||||||
<Route path="/redeem-pending" element={<PendingRedeemPage />} />
|
<Route path="/redeem-pending" element={<PendingRedeemPage />} />
|
||||||
<Route path="/redeem/debug" element={<RedeemDebugPage />} />
|
<Route path="/redeem/debug" element={<RedeemDebugPage />} />
|
||||||
<Route path="/finance/store-bills" element={<StoreBillsPage />} />
|
<Route path="/finance/store-bills" element={<StoreBillsPage />} />
|
||||||
|
<Route
|
||||||
|
path="/finance/store-withdrawals"
|
||||||
|
element={<Navigate to="/finance/store-bills?kind=WITHDRAW" replace />}
|
||||||
|
/>
|
||||||
<Route path="/finance/partner-bills" element={<PartnerBillsPage />} />
|
<Route path="/finance/partner-bills" element={<PartnerBillsPage />} />
|
||||||
<Route path="/finance/winery-bills" element={<WineryBillsPage />} />
|
<Route path="/finance/winery-bills" element={<WineryBillsPage />} />
|
||||||
|
<Route path="/finance/logistics-bills" element={<LogisticsBillsPage />} />
|
||||||
<Route path="/store-bills" element={<Navigate to="/finance/store-bills" replace />} />
|
<Route path="/store-bills" element={<Navigate to="/finance/store-bills" replace />} />
|
||||||
<Route path="/store-payouts" element={<Navigate to="/finance/store-bills" replace />} />
|
<Route path="/store-payouts" element={<Navigate to="/finance/store-bills" replace />} />
|
||||||
|
<Route
|
||||||
|
path="/store-withdrawals"
|
||||||
|
element={<Navigate to="/finance/store-bills?kind=WITHDRAW" replace />}
|
||||||
|
/>
|
||||||
<Route path="/partner-bills" element={<Navigate to="/finance/partner-bills" replace />} />
|
<Route path="/partner-bills" element={<Navigate to="/finance/partner-bills" replace />} />
|
||||||
<Route path="/tickets" element={<TicketsPage />} />
|
<Route path="/tickets" element={<TicketsPage />} />
|
||||||
|
<Route path="/tickets/support" element={<SupportTicketsPage />} />
|
||||||
<Route path="/invoices" element={<InvoicesPage />} />
|
<Route path="/invoices" element={<InvoicesPage />} />
|
||||||
<Route path="/logs/users" element={<UserLogsPage />} />
|
<Route path="/logs/users" element={<UserLogsPage />} />
|
||||||
<Route path="/logs/stores" element={<StoreLogsPage />} />
|
<Route path="/logs/stores" element={<StoreLogsPage />} />
|
||||||
<Route path="/logs/partners" element={<PartnerLogsPage />} />
|
<Route path="/logs/partners" element={<PartnerLogsPage />} />
|
||||||
<Route path="/logs/hq" element={<HqLogsPage />} />
|
<Route path="/logs/hq" element={<HqLogsPage />} />
|
||||||
<Route path="/logs/third-party" element={<ThirdPartyLogsPage />} />
|
<Route path="/logs/third-party" element={<ThirdPartyLogsPage />} />
|
||||||
|
<Route path="/logs/domain-events" element={<DomainEventsPage />} />
|
||||||
<Route path="/deliveries" element={<DeliveriesPage />} />
|
<Route path="/deliveries" element={<DeliveriesPage />} />
|
||||||
<Route path="/deliveries/xiaofeixia" element={<XiaofeixiaTestPage />} />
|
<Route path="/deliveries/xiaofeixia" element={<XiaofeixiaTestPage />} />
|
||||||
<Route path="/hq-permissions" element={<HqPermissionsPage />} />
|
<Route path="/hq-permissions" element={<HqPermissionsPage />} />
|
||||||
|
<Route path="/test-whitelist" element={<TestWhitelistPage />} />
|
||||||
<Route path="/system-settings" element={<SystemSettingsPage />} />
|
<Route path="/system-settings" element={<SystemSettingsPage />} />
|
||||||
<Route path="/hq-accounts" element={<HqAccountsPage />} />
|
<Route path="/hq-accounts" element={<HqAccountsPage />} />
|
||||||
</Route>
|
</Route>
|
||||||
|
|||||||
@@ -86,3 +86,656 @@ body,
|
|||||||
.admin-table-nowrap .ant-table-cell-ellipsis {
|
.admin-table-nowrap .ant-table-cell-ellipsis {
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.admin-package-audit-cols {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 1fr 1fr;
|
||||||
|
gap: 16px;
|
||||||
|
align-items: start;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-package-audit-col {
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-package-audit-text {
|
||||||
|
white-space: pre-wrap;
|
||||||
|
word-break: break-word;
|
||||||
|
overflow: visible;
|
||||||
|
max-width: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* v3.5.1 #1 订单大屏:发布会现场 */
|
||||||
|
html:has(.big-screen-page),
|
||||||
|
body:has(.big-screen-page),
|
||||||
|
#root:has(.big-screen-page) {
|
||||||
|
overflow: hidden;
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.big-screen-page {
|
||||||
|
position: fixed;
|
||||||
|
inset: 0;
|
||||||
|
width: 100vw;
|
||||||
|
height: 100vh;
|
||||||
|
background: radial-gradient(ellipse at 50% 18%, #163a6b 0%, #0b1e3a 42%, #061224 100%);
|
||||||
|
color: #d6e8ff;
|
||||||
|
padding: 20px 48px 24px;
|
||||||
|
box-sizing: border-box;
|
||||||
|
overflow: hidden;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
|
.big-screen-stars {
|
||||||
|
pointer-events: none;
|
||||||
|
position: absolute;
|
||||||
|
inset: 0;
|
||||||
|
background-image:
|
||||||
|
radial-gradient(1px 1px at 8% 18%, rgba(255, 255, 255, 0.35), transparent),
|
||||||
|
radial-gradient(1px 1px at 22% 72%, rgba(160, 210, 255, 0.28), transparent),
|
||||||
|
radial-gradient(1.5px 1.5px at 78% 24%, rgba(255, 255, 255, 0.22), transparent),
|
||||||
|
radial-gradient(1px 1px at 91% 68%, rgba(160, 210, 255, 0.3), transparent),
|
||||||
|
radial-gradient(1px 1px at 46% 88%, rgba(255, 255, 255, 0.18), transparent),
|
||||||
|
radial-gradient(1.5px 1.5px at 61% 12%, rgba(160, 210, 255, 0.25), transparent);
|
||||||
|
opacity: 0.7;
|
||||||
|
}
|
||||||
|
|
||||||
|
.big-screen-frame {
|
||||||
|
pointer-events: none;
|
||||||
|
position: absolute;
|
||||||
|
inset: 14px 18px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.big-screen-corner {
|
||||||
|
position: absolute;
|
||||||
|
width: 28px;
|
||||||
|
height: 28px;
|
||||||
|
border: 1px solid rgba(105, 192, 255, 0.7);
|
||||||
|
}
|
||||||
|
|
||||||
|
.big-screen-corner--tl {
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
border-right: none;
|
||||||
|
border-bottom: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.big-screen-corner--tr {
|
||||||
|
top: 0;
|
||||||
|
right: 0;
|
||||||
|
border-left: none;
|
||||||
|
border-bottom: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.big-screen-corner--bl {
|
||||||
|
bottom: 0;
|
||||||
|
left: 0;
|
||||||
|
border-right: none;
|
||||||
|
border-top: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.big-screen-corner--br {
|
||||||
|
bottom: 0;
|
||||||
|
right: 0;
|
||||||
|
border-left: none;
|
||||||
|
border-top: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.big-screen-header {
|
||||||
|
position: relative;
|
||||||
|
z-index: 1;
|
||||||
|
flex: 0 0 auto;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
padding-bottom: 10px;
|
||||||
|
border-bottom: 1px solid rgba(105, 192, 255, 0.18);
|
||||||
|
}
|
||||||
|
|
||||||
|
.big-screen-brand {
|
||||||
|
display: flex;
|
||||||
|
align-items: baseline;
|
||||||
|
gap: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.big-screen-title {
|
||||||
|
margin: 0;
|
||||||
|
font-size: 28px;
|
||||||
|
line-height: 1;
|
||||||
|
font-weight: 700;
|
||||||
|
letter-spacing: 4px;
|
||||||
|
color: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.big-screen-subtitle {
|
||||||
|
font-size: 16px;
|
||||||
|
color: rgba(200, 220, 245, 0.55);
|
||||||
|
letter-spacing: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.big-screen-live-wrap {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.big-screen-live-label {
|
||||||
|
font-size: 18px;
|
||||||
|
color: rgba(230, 244, 255, 0.88);
|
||||||
|
letter-spacing: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.big-screen-live {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 8px;
|
||||||
|
padding: 4px 12px 4px 10px;
|
||||||
|
border: 1px solid rgba(64, 169, 255, 0.7);
|
||||||
|
border-radius: 6px;
|
||||||
|
font-size: 14px;
|
||||||
|
font-weight: 700;
|
||||||
|
color: #fff;
|
||||||
|
letter-spacing: 2px;
|
||||||
|
background: rgba(8, 28, 56, 0.55);
|
||||||
|
}
|
||||||
|
|
||||||
|
.big-screen-live-dot {
|
||||||
|
width: 8px;
|
||||||
|
height: 8px;
|
||||||
|
border-radius: 50%;
|
||||||
|
background: #ff4d4f;
|
||||||
|
box-shadow: 0 0 8px #ff4d4f;
|
||||||
|
animation: big-screen-pulse 1.2s ease-in-out infinite;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes big-screen-pulse {
|
||||||
|
0%,
|
||||||
|
100% {
|
||||||
|
opacity: 1;
|
||||||
|
transform: scale(1);
|
||||||
|
}
|
||||||
|
50% {
|
||||||
|
opacity: 0.35;
|
||||||
|
transform: scale(0.75);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.big-screen-hero {
|
||||||
|
position: relative;
|
||||||
|
z-index: 1;
|
||||||
|
flex: 0 0 auto;
|
||||||
|
text-align: center;
|
||||||
|
padding: 16px 0 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.big-screen-clock {
|
||||||
|
font-size: 84px;
|
||||||
|
line-height: 1;
|
||||||
|
font-weight: 500;
|
||||||
|
font-variant-numeric: tabular-nums;
|
||||||
|
letter-spacing: 10px;
|
||||||
|
color: #9fd3ff;
|
||||||
|
text-shadow: 0 0 28px rgba(105, 192, 255, 0.45);
|
||||||
|
}
|
||||||
|
|
||||||
|
.big-screen-date {
|
||||||
|
margin-top: 8px;
|
||||||
|
font-size: 16px;
|
||||||
|
letter-spacing: 4px;
|
||||||
|
color: rgba(180, 210, 240, 0.65);
|
||||||
|
}
|
||||||
|
|
||||||
|
.big-screen-list {
|
||||||
|
position: relative;
|
||||||
|
z-index: 1;
|
||||||
|
flex: 1;
|
||||||
|
min-height: 0;
|
||||||
|
width: 100%;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
padding: 0;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.big-screen-list-head,
|
||||||
|
.big-screen-row {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: minmax(180px, 18%) minmax(0, 1fr) minmax(140px, 16%) minmax(160px, 18%);
|
||||||
|
align-items: center;
|
||||||
|
column-gap: 16px;
|
||||||
|
width: 100%;
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
.big-screen-list-body {
|
||||||
|
flex: 1 1 0%;
|
||||||
|
min-height: 0;
|
||||||
|
height: 0;
|
||||||
|
overflow: hidden;
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
.big-screen-track {
|
||||||
|
position: absolute;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
top: 0;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
|
.big-screen-track.is-rolling {
|
||||||
|
animation: big-screen-marquee-up var(--marquee-ms, 20s) linear infinite;
|
||||||
|
}
|
||||||
|
|
||||||
|
.big-screen-track.is-paused {
|
||||||
|
animation-play-state: paused;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes big-screen-marquee-up {
|
||||||
|
from {
|
||||||
|
transform: translateY(0);
|
||||||
|
}
|
||||||
|
to {
|
||||||
|
transform: translateY(-50%);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.big-screen-row {
|
||||||
|
position: relative;
|
||||||
|
flex: 0 0 auto;
|
||||||
|
height: 68px;
|
||||||
|
margin-bottom: 12px;
|
||||||
|
padding: 0 28px 0 40px;
|
||||||
|
background: rgba(18, 48, 88, 0.45);
|
||||||
|
border: 1px solid transparent;
|
||||||
|
border-radius: 4px;
|
||||||
|
font-size: 22px;
|
||||||
|
color: #e8f4ff;
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
.big-screen-row.is-latest {
|
||||||
|
border-color: rgba(64, 169, 255, 0.85);
|
||||||
|
box-shadow: 0 0 16px rgba(24, 144, 255, 0.28);
|
||||||
|
}
|
||||||
|
|
||||||
|
.big-screen-row--t1 {
|
||||||
|
background: rgba(22, 54, 98, 0.48);
|
||||||
|
border-color: rgba(105, 192, 255, 0.16);
|
||||||
|
}
|
||||||
|
|
||||||
|
.big-screen-row--t1 .big-screen-amount {
|
||||||
|
color: #e6f4ff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.big-screen-row--t2.is-latest {
|
||||||
|
border-color: rgba(255, 229, 143, 0.95);
|
||||||
|
box-shadow: 0 0 18px rgba(255, 229, 143, 0.42);
|
||||||
|
}
|
||||||
|
|
||||||
|
.big-screen-row--t3.is-latest {
|
||||||
|
border-color: #ffd666;
|
||||||
|
box-shadow: 0 0 22px rgba(250, 173, 20, 0.55);
|
||||||
|
}
|
||||||
|
|
||||||
|
.big-screen-row--t2 {
|
||||||
|
background: rgba(64, 48, 8, 0.42);
|
||||||
|
border-color: rgba(255, 229, 143, 0.45);
|
||||||
|
color: #fff7d6;
|
||||||
|
}
|
||||||
|
|
||||||
|
.big-screen-row--t2 .big-screen-amount {
|
||||||
|
color: #ffe58f;
|
||||||
|
text-shadow: 0 0 10px rgba(255, 229, 143, 0.45);
|
||||||
|
}
|
||||||
|
|
||||||
|
.big-screen-row--t3 {
|
||||||
|
background: rgba(72, 48, 0, 0.5);
|
||||||
|
border-color: rgba(250, 173, 20, 0.75);
|
||||||
|
color: #ffe7a3;
|
||||||
|
box-shadow: 0 0 18px rgba(250, 173, 20, 0.28);
|
||||||
|
}
|
||||||
|
|
||||||
|
.big-screen-row--t3 .big-screen-amount {
|
||||||
|
color: #ffd666;
|
||||||
|
text-shadow: 0 0 14px rgba(255, 214, 102, 0.7);
|
||||||
|
}
|
||||||
|
|
||||||
|
.big-screen-row-mark {
|
||||||
|
position: absolute;
|
||||||
|
left: 12px;
|
||||||
|
top: 50%;
|
||||||
|
width: 10px;
|
||||||
|
height: 22px;
|
||||||
|
margin-top: -11px;
|
||||||
|
border-radius: 6px;
|
||||||
|
background: #40a9ff;
|
||||||
|
box-shadow: 0 0 10px #40a9ff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.big-screen-row--t2 .big-screen-row-mark {
|
||||||
|
background: #ffe58f;
|
||||||
|
box-shadow: 0 0 10px #ffe58f;
|
||||||
|
}
|
||||||
|
|
||||||
|
.big-screen-row--t3 .big-screen-row-mark {
|
||||||
|
background: #ffd666;
|
||||||
|
box-shadow: 0 0 12px #ffd666;
|
||||||
|
}
|
||||||
|
|
||||||
|
.big-screen-amount {
|
||||||
|
font-weight: 700;
|
||||||
|
font-variant-numeric: tabular-nums;
|
||||||
|
white-space: nowrap;
|
||||||
|
letter-spacing: 0.5px;
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.big-screen-amount--6d {
|
||||||
|
font-size: 0.86em;
|
||||||
|
letter-spacing: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.big-screen-items {
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.big-screen-time,
|
||||||
|
.big-screen-phone {
|
||||||
|
font-variant-numeric: tabular-nums;
|
||||||
|
letter-spacing: 1px;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.big-screen-empty {
|
||||||
|
position: absolute;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
/* 全屏高度黄金分割点(≈0.382),略偏上 */
|
||||||
|
top: 38.2%;
|
||||||
|
transform: translateY(-50%);
|
||||||
|
z-index: 2;
|
||||||
|
text-align: center;
|
||||||
|
color: rgba(145, 190, 230, 0.42);
|
||||||
|
padding: 0 40px;
|
||||||
|
font-size: 60px;
|
||||||
|
letter-spacing: 6px;
|
||||||
|
font-weight: 400;
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.big-screen-fx {
|
||||||
|
position: absolute;
|
||||||
|
inset: 0;
|
||||||
|
z-index: 20;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
pointer-events: none;
|
||||||
|
overflow: hidden;
|
||||||
|
background: rgba(4, 12, 28, 0.38);
|
||||||
|
}
|
||||||
|
|
||||||
|
.big-screen-fx-canvas {
|
||||||
|
position: absolute;
|
||||||
|
inset: 0;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.big-screen-fx-shock {
|
||||||
|
position: absolute;
|
||||||
|
width: 40px;
|
||||||
|
height: 40px;
|
||||||
|
border-radius: 50%;
|
||||||
|
border: 3px solid rgba(255, 214, 102, 0.85);
|
||||||
|
animation: big-screen-shock 1.1s ease-out forwards;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes big-screen-shock {
|
||||||
|
0% {
|
||||||
|
transform: scale(0.2);
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
100% {
|
||||||
|
transform: scale(28);
|
||||||
|
opacity: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.big-screen-fx-sweep {
|
||||||
|
position: absolute;
|
||||||
|
inset: 0;
|
||||||
|
background: linear-gradient(
|
||||||
|
115deg,
|
||||||
|
transparent 38%,
|
||||||
|
rgba(255, 245, 200, 0.22) 50%,
|
||||||
|
transparent 62%
|
||||||
|
);
|
||||||
|
background-size: 220% 100%;
|
||||||
|
animation: big-screen-sweep 1.4s ease-out 0.15s both;
|
||||||
|
}
|
||||||
|
|
||||||
|
.big-screen-fx-sweep--alt {
|
||||||
|
animation-delay: 0.55s;
|
||||||
|
background: linear-gradient(
|
||||||
|
65deg,
|
||||||
|
transparent 38%,
|
||||||
|
rgba(255, 214, 102, 0.2) 50%,
|
||||||
|
transparent 62%
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
.big-screen-fx-shock--late {
|
||||||
|
animation-delay: 0.35s;
|
||||||
|
border-color: rgba(255, 236, 179, 0.55);
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes big-screen-sweep {
|
||||||
|
from {
|
||||||
|
background-position: 120% 0;
|
||||||
|
opacity: 0;
|
||||||
|
}
|
||||||
|
30% {
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
to {
|
||||||
|
background-position: -40% 0;
|
||||||
|
opacity: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.big-screen-fx-card {
|
||||||
|
position: relative;
|
||||||
|
z-index: 2;
|
||||||
|
min-width: min(420px, 92vw);
|
||||||
|
max-width: min(920px, 92vw);
|
||||||
|
padding: 28px 40px 32px;
|
||||||
|
border-radius: 12px;
|
||||||
|
text-align: center;
|
||||||
|
background: rgba(8, 22, 48, 0.82);
|
||||||
|
backdrop-filter: blur(8px);
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
.big-screen-fx-card--t1 {
|
||||||
|
border: 2px solid rgba(105, 192, 255, 0.85);
|
||||||
|
box-shadow: 0 0 32px rgba(24, 144, 255, 0.45);
|
||||||
|
animation: big-screen-card-in-t1 0.55s cubic-bezier(0.2, 0.9, 0.2, 1) both;
|
||||||
|
}
|
||||||
|
|
||||||
|
.big-screen-fx-card--t2 {
|
||||||
|
border: 2px solid rgba(255, 229, 143, 0.95);
|
||||||
|
box-shadow: 0 0 40px rgba(255, 214, 102, 0.5);
|
||||||
|
animation: big-screen-card-in-t2 0.6s cubic-bezier(0.16, 1.2, 0.3, 1) both;
|
||||||
|
}
|
||||||
|
|
||||||
|
.big-screen-fx-card--t3 {
|
||||||
|
min-width: min(560px, 94vw);
|
||||||
|
padding: 36px 48px 40px;
|
||||||
|
border: 3px solid #ffd666;
|
||||||
|
box-shadow:
|
||||||
|
0 0 28px rgba(255, 214, 102, 0.85),
|
||||||
|
0 0 80px rgba(250, 173, 20, 0.45);
|
||||||
|
animation: big-screen-card-in-t3 0.7s cubic-bezier(0.12, 1.4, 0.2, 1) both;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes big-screen-card-in-t1 {
|
||||||
|
from {
|
||||||
|
opacity: 0;
|
||||||
|
transform: translateY(80px) scale(0.92);
|
||||||
|
}
|
||||||
|
to {
|
||||||
|
opacity: 1;
|
||||||
|
transform: translateY(0) scale(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes big-screen-card-in-t2 {
|
||||||
|
0% {
|
||||||
|
opacity: 0;
|
||||||
|
transform: scale(0.6);
|
||||||
|
}
|
||||||
|
70% {
|
||||||
|
transform: scale(1.06);
|
||||||
|
}
|
||||||
|
100% {
|
||||||
|
opacity: 1;
|
||||||
|
transform: scale(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes big-screen-card-in-t3 {
|
||||||
|
0% {
|
||||||
|
opacity: 0;
|
||||||
|
transform: scale(0.4) rotate(-4deg);
|
||||||
|
}
|
||||||
|
55% {
|
||||||
|
transform: scale(1.12) rotate(1deg);
|
||||||
|
}
|
||||||
|
100% {
|
||||||
|
opacity: 1;
|
||||||
|
transform: scale(1) rotate(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.big-screen-fx-kicker {
|
||||||
|
font-size: 16px;
|
||||||
|
letter-spacing: 8px;
|
||||||
|
color: rgba(230, 244, 255, 0.7);
|
||||||
|
margin-bottom: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.big-screen-fx-card--t2 .big-screen-fx-kicker,
|
||||||
|
.big-screen-fx-card--t3 .big-screen-fx-kicker {
|
||||||
|
color: #ffe58f;
|
||||||
|
}
|
||||||
|
|
||||||
|
.big-screen-fx-amount {
|
||||||
|
font-size: clamp(44px, 8.5vw, 64px);
|
||||||
|
font-weight: 800;
|
||||||
|
font-variant-numeric: tabular-nums;
|
||||||
|
letter-spacing: 2px;
|
||||||
|
line-height: 1.1;
|
||||||
|
color: #e6f7ff;
|
||||||
|
max-width: 100%;
|
||||||
|
margin-inline: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.big-screen-fx-amount--6d {
|
||||||
|
font-size: clamp(36px, 7vw, 52px) !important;
|
||||||
|
letter-spacing: 1px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.big-screen-fx-card--t1 .big-screen-fx-amount {
|
||||||
|
color: #91d5ff;
|
||||||
|
text-shadow: 0 0 18px rgba(105, 192, 255, 0.6);
|
||||||
|
}
|
||||||
|
|
||||||
|
.big-screen-fx-card--t2 .big-screen-fx-amount {
|
||||||
|
color: #ffe58f;
|
||||||
|
text-shadow: 0 0 20px rgba(255, 229, 143, 0.7);
|
||||||
|
animation: big-screen-amount-pop 0.8s ease-out 0.15s both;
|
||||||
|
}
|
||||||
|
|
||||||
|
.big-screen-fx-card--t3 .big-screen-fx-amount {
|
||||||
|
font-size: clamp(52px, 10vw, 84px);
|
||||||
|
color: #ffd666;
|
||||||
|
text-shadow:
|
||||||
|
0 0 12px #ffd666,
|
||||||
|
0 0 36px rgba(250, 173, 20, 0.8);
|
||||||
|
animation: big-screen-amount-flash 0.9s ease-in-out infinite;
|
||||||
|
}
|
||||||
|
|
||||||
|
.big-screen-fx-card--t3 .big-screen-fx-amount--6d {
|
||||||
|
font-size: clamp(44px, 8.5vw, 68px) !important;
|
||||||
|
letter-spacing: 1px;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes big-screen-amount-pop {
|
||||||
|
0% {
|
||||||
|
transform: scale(0.7);
|
||||||
|
}
|
||||||
|
70% {
|
||||||
|
transform: scale(1.12);
|
||||||
|
}
|
||||||
|
100% {
|
||||||
|
transform: scale(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes big-screen-amount-flash {
|
||||||
|
0%,
|
||||||
|
100% {
|
||||||
|
filter: brightness(1);
|
||||||
|
}
|
||||||
|
50% {
|
||||||
|
filter: brightness(1.35);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.big-screen-fx-items {
|
||||||
|
margin-top: 12px;
|
||||||
|
font-size: 22px;
|
||||||
|
color: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.big-screen-fx-meta {
|
||||||
|
margin-top: 10px;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
gap: 28px;
|
||||||
|
font-size: 16px;
|
||||||
|
color: rgba(210, 228, 250, 0.75);
|
||||||
|
font-variant-numeric: tabular-nums;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 1200px) {
|
||||||
|
.big-screen-clock {
|
||||||
|
font-size: 56px;
|
||||||
|
}
|
||||||
|
.big-screen-row {
|
||||||
|
grid-template-columns: minmax(140px, 20%) minmax(0, 1fr) minmax(110px, 16%) minmax(130px, 18%);
|
||||||
|
font-size: 16px;
|
||||||
|
}
|
||||||
|
.big-screen-amount--6d {
|
||||||
|
font-size: 0.82em;
|
||||||
|
}
|
||||||
|
.big-screen-fx-amount {
|
||||||
|
font-size: clamp(36px, 8vw, 44px);
|
||||||
|
}
|
||||||
|
.big-screen-fx-card--t3 .big-screen-fx-amount {
|
||||||
|
font-size: clamp(40px, 9vw, 56px);
|
||||||
|
}
|
||||||
|
.big-screen-fx-amount--6d {
|
||||||
|
font-size: clamp(32px, 6.5vw, 40px) !important;
|
||||||
|
}
|
||||||
|
.big-screen-fx-card--t3 .big-screen-fx-amount--6d {
|
||||||
|
font-size: clamp(34px, 7vw, 48px) !important;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,381 @@
|
|||||||
|
import { forwardRef, useEffect, useImperativeHandle, useRef, useState } from 'react';
|
||||||
|
import { useNavigate } from 'react-router-dom';
|
||||||
|
import { Alert, Button, Form, Input, InputNumber, Modal, Space, Typography, message } from 'antd';
|
||||||
|
import { DownOutlined, UpOutlined } from '@ant-design/icons';
|
||||||
|
import type { StorePackageItemDto, StorePackagesResponse } from '@dukang/shared-types';
|
||||||
|
import { STORE_PACKAGE_IMAGE_MAX_COUNT, STORE_PACKAGE_MAX_COUNT, normalizeStorePackageImageUrls } from '@dukang/shared-types';
|
||||||
|
import { request } from '../lib/api';
|
||||||
|
import { PACKAGE_AUDIT_CHANGED_EVENT } from '../lib/admin-events';
|
||||||
|
import PackageImagesUpload from './PackageImagesUpload';
|
||||||
|
|
||||||
|
type PackageRow = StorePackageItemDto;
|
||||||
|
|
||||||
|
export type AdminStorePackagesHandle = {
|
||||||
|
/** 套餐已加载时写入;加载中则跳过,避免空数据覆盖线上套餐 */
|
||||||
|
saveIfLoaded: (opts?: { quiet?: boolean }) => Promise<{ skipped: boolean }>;
|
||||||
|
};
|
||||||
|
|
||||||
|
function emptyRow(index = 0): PackageRow {
|
||||||
|
return {
|
||||||
|
name: '',
|
||||||
|
price: '0',
|
||||||
|
dishes: '',
|
||||||
|
usableTime: '',
|
||||||
|
otherNotes: '',
|
||||||
|
imageUrl: '',
|
||||||
|
imageUrls: [],
|
||||||
|
sortOrder: index,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const AdminStorePackagesSection = forwardRef<AdminStorePackagesHandle, { storeId: string }>(
|
||||||
|
function AdminStorePackagesSection({ storeId }, ref) {
|
||||||
|
const [items, setItems] = useState<PackageRow[]>([emptyRow()]);
|
||||||
|
const [collapsed, setCollapsed] = useState<Record<number, boolean>>({});
|
||||||
|
const [loading, setLoading] = useState(true);
|
||||||
|
const [saving, setSaving] = useState(false);
|
||||||
|
const [pendingRequest, setPendingRequest] = useState<StorePackagesResponse['pendingRequest']>(null);
|
||||||
|
const itemsRef = useRef(items);
|
||||||
|
const loadingRef = useRef(loading);
|
||||||
|
const navigate = useNavigate();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
itemsRef.current = items;
|
||||||
|
}, [items]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
loadingRef.current = loading;
|
||||||
|
}, [loading]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setLoading(true);
|
||||||
|
setPendingRequest(null);
|
||||||
|
request<StorePackagesResponse>(`/admin/stores/${storeId}/packages`)
|
||||||
|
.then((data) => {
|
||||||
|
setPendingRequest(data.pendingRequest ?? null);
|
||||||
|
setItems(
|
||||||
|
data.live?.length
|
||||||
|
? data.live.map((p, i) => {
|
||||||
|
const imageUrls = normalizeStorePackageImageUrls(p);
|
||||||
|
return {
|
||||||
|
...p,
|
||||||
|
price: String(p.price),
|
||||||
|
imageUrl: imageUrls[0] ?? '',
|
||||||
|
imageUrls,
|
||||||
|
sortOrder: i,
|
||||||
|
};
|
||||||
|
})
|
||||||
|
: [],
|
||||||
|
);
|
||||||
|
})
|
||||||
|
.catch((e) => message.error(e instanceof Error ? e.message : '加载套餐失败'))
|
||||||
|
.finally(() => setLoading(false));
|
||||||
|
}, [storeId]);
|
||||||
|
|
||||||
|
// 在审核页完成审核后,自动刷新本页「有待审核套餐」提醒
|
||||||
|
useEffect(() => {
|
||||||
|
const onChanged = () => {
|
||||||
|
request<StorePackagesResponse>(`/admin/stores/${storeId}/packages`)
|
||||||
|
.then((data) => setPendingRequest(data.pendingRequest ?? null))
|
||||||
|
.catch(() => undefined);
|
||||||
|
};
|
||||||
|
window.addEventListener(PACKAGE_AUDIT_CHANGED_EVENT, onChanged);
|
||||||
|
return () => window.removeEventListener(PACKAGE_AUDIT_CHANGED_EVENT, onChanged);
|
||||||
|
}, [storeId]);
|
||||||
|
|
||||||
|
function goAudit() {
|
||||||
|
if (pendingRequest) navigate(`/store-package-audits?requestId=${pendingRequest.id}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const pendingReminder =
|
||||||
|
pendingRequest && pendingRequest.status === 'PENDING' ? (
|
||||||
|
<Alert
|
||||||
|
type="warning"
|
||||||
|
showIcon
|
||||||
|
style={{ marginBottom: 16 }}
|
||||||
|
message="该门店有待审核套餐"
|
||||||
|
description={
|
||||||
|
<Space>
|
||||||
|
<Button size="small" type="primary" onClick={goAudit}>
|
||||||
|
审核
|
||||||
|
</Button>
|
||||||
|
<Button size="small" onClick={goAudit}>
|
||||||
|
对比
|
||||||
|
</Button>
|
||||||
|
</Space>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
) : null;
|
||||||
|
|
||||||
|
function updateAt(index: number, patch: Partial<PackageRow>) {
|
||||||
|
setItems((prev) => prev.map((item, i) => (i === index ? { ...item, ...patch } : item)));
|
||||||
|
}
|
||||||
|
|
||||||
|
function addRow() {
|
||||||
|
if (items.length >= STORE_PACKAGE_MAX_COUNT) return;
|
||||||
|
setItems((prev) => [...prev, emptyRow(prev.length)]);
|
||||||
|
}
|
||||||
|
|
||||||
|
function removeAt(index: number) {
|
||||||
|
const run = () => {
|
||||||
|
setItems((prev) => {
|
||||||
|
const next = prev.filter((_, i) => i !== index).map((item, i) => ({ ...item, sortOrder: i }));
|
||||||
|
return next.length ? next : [];
|
||||||
|
});
|
||||||
|
setCollapsed((prev) => {
|
||||||
|
const next: Record<number, boolean> = {};
|
||||||
|
Object.entries(prev).forEach(([k, v]) => {
|
||||||
|
const i = Number(k);
|
||||||
|
if (i < index) next[i] = v;
|
||||||
|
else if (i > index) next[i - 1] = v;
|
||||||
|
});
|
||||||
|
return next;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
if (items.length === 1) {
|
||||||
|
Modal.confirm({
|
||||||
|
title: '清空门店套餐',
|
||||||
|
content: '删除最后一条套餐后,该门店将无展示套餐,确认继续?',
|
||||||
|
okText: '确认删除',
|
||||||
|
cancelText: '取消',
|
||||||
|
onOk: run,
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
run();
|
||||||
|
}
|
||||||
|
|
||||||
|
function toggleCollapse(index: number) {
|
||||||
|
setCollapsed((prev) => ({ ...prev, [index]: !prev[index] }));
|
||||||
|
}
|
||||||
|
|
||||||
|
async function save(opts?: { quiet?: boolean }) {
|
||||||
|
const currentItems = itemsRef.current;
|
||||||
|
const filled = currentItems
|
||||||
|
.map((item, index) => {
|
||||||
|
const imageUrls = normalizeStorePackageImageUrls(item);
|
||||||
|
return {
|
||||||
|
name: item.name.trim(),
|
||||||
|
price: item.price.trim(),
|
||||||
|
dishes: item.dishes.trim(),
|
||||||
|
usableTime: item.usableTime?.trim() || null,
|
||||||
|
otherNotes: item.otherNotes?.trim() || null,
|
||||||
|
imageUrl: imageUrls[0] ?? null,
|
||||||
|
imageUrls,
|
||||||
|
sortOrder: index,
|
||||||
|
};
|
||||||
|
})
|
||||||
|
// 允许整店无套餐:忽略空白占位行(默认 price=0 不算已填)
|
||||||
|
.filter((item) => {
|
||||||
|
const hasText = !!(item.name || item.dishes || item.usableTime || item.otherNotes);
|
||||||
|
const hasImages = item.imageUrls.length > 0;
|
||||||
|
const hasNonZeroPrice = item.price !== '' && Number(item.price) !== 0;
|
||||||
|
return hasText || hasImages || hasNonZeroPrice;
|
||||||
|
});
|
||||||
|
|
||||||
|
for (let i = 0; i < filled.length; i++) {
|
||||||
|
const item = filled[i];
|
||||||
|
if (!item.name) {
|
||||||
|
message.warning(`第 ${i + 1} 条套餐名称不能为空`);
|
||||||
|
throw new Error('套餐校验失败');
|
||||||
|
}
|
||||||
|
if (!item.dishes) {
|
||||||
|
message.warning(`第 ${i + 1} 条套餐菜品不能为空`);
|
||||||
|
throw new Error('套餐校验失败');
|
||||||
|
}
|
||||||
|
const price = Number(item.price);
|
||||||
|
if (!Number.isFinite(price) || price < 0) {
|
||||||
|
message.warning(`第 ${i + 1} 条套餐价格须为非负数字`);
|
||||||
|
throw new Error('套餐校验失败');
|
||||||
|
}
|
||||||
|
if ((item.imageUrls?.length ?? 0) > STORE_PACKAGE_IMAGE_MAX_COUNT) {
|
||||||
|
message.warning(`第 ${i + 1} 条套餐图片最多 ${STORE_PACKAGE_IMAGE_MAX_COUNT} 张`);
|
||||||
|
throw new Error('套餐校验失败');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
setSaving(true);
|
||||||
|
try {
|
||||||
|
const data = await request<{ live: PackageRow[] }>(`/admin/stores/${storeId}/packages`, {
|
||||||
|
method: 'PUT',
|
||||||
|
body: JSON.stringify({
|
||||||
|
packages: filled.map((p) => ({ ...p, price: Number(p.price).toFixed(2) })),
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
if (!opts?.quiet) message.success('套餐已保存并生效');
|
||||||
|
setItems(
|
||||||
|
data.live?.length
|
||||||
|
? data.live.map((p, i) => {
|
||||||
|
const imageUrls = normalizeStorePackageImageUrls(p);
|
||||||
|
return {
|
||||||
|
...p,
|
||||||
|
price: String(p.price),
|
||||||
|
imageUrl: imageUrls[0] ?? '',
|
||||||
|
imageUrls,
|
||||||
|
sortOrder: i,
|
||||||
|
};
|
||||||
|
})
|
||||||
|
: [],
|
||||||
|
);
|
||||||
|
} catch (e) {
|
||||||
|
if (!opts?.quiet) message.error(e instanceof Error ? e.message : '保存失败');
|
||||||
|
throw e;
|
||||||
|
} finally {
|
||||||
|
setSaving(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
useImperativeHandle(ref, () => ({
|
||||||
|
saveIfLoaded: async (opts) => {
|
||||||
|
if (loadingRef.current) return { skipped: true };
|
||||||
|
await save(opts);
|
||||||
|
return { skipped: false };
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
|
||||||
|
if (loading) {
|
||||||
|
return <Typography.Text type="secondary">加载套餐中…</Typography.Text>;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!items.length) {
|
||||||
|
return (
|
||||||
|
<Form layout="vertical" requiredMark={false}>
|
||||||
|
<Alert type="info" showIcon style={{ marginBottom: 16 }} message="该门店暂无套餐,可添加或保存为空。" />
|
||||||
|
{pendingReminder}
|
||||||
|
<Button onClick={addRow} style={{ marginBottom: 16 }}>
|
||||||
|
添加套餐
|
||||||
|
</Button>
|
||||||
|
<Button type="primary" loading={saving} onClick={() => void save().catch(() => undefined)}>
|
||||||
|
保存套餐
|
||||||
|
</Button>
|
||||||
|
</Form>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Form layout="vertical" requiredMark={false}>
|
||||||
|
{pendingReminder}
|
||||||
|
<Alert
|
||||||
|
type="info"
|
||||||
|
showIcon
|
||||||
|
style={{ marginBottom: 16 }}
|
||||||
|
message={`总部直存立即生效,无需审核。同一门店最多 ${STORE_PACKAGE_MAX_COUNT} 条套餐。`}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{items.map((item, index) => {
|
||||||
|
const isCollapsed = !!collapsed[index];
|
||||||
|
const displayName = item.name.trim() || `套餐 ${index + 1}`;
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
key={index}
|
||||||
|
style={{
|
||||||
|
marginBottom: 16,
|
||||||
|
padding: 16,
|
||||||
|
border: '1px solid #f0f0f0',
|
||||||
|
borderRadius: 8,
|
||||||
|
background: '#fafafa',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Space style={{ width: '100%', justifyContent: 'space-between', marginBottom: isCollapsed ? 0 : 12 }}>
|
||||||
|
<Button
|
||||||
|
type="text"
|
||||||
|
icon={isCollapsed ? <DownOutlined /> : <UpOutlined />}
|
||||||
|
onClick={() => toggleCollapse(index)}
|
||||||
|
style={{ paddingLeft: 0, height: 'auto' }}
|
||||||
|
>
|
||||||
|
<Typography.Title level={5} style={{ margin: 0 }}>
|
||||||
|
{displayName}
|
||||||
|
</Typography.Title>
|
||||||
|
</Button>
|
||||||
|
{items.length > 0 ? (
|
||||||
|
<Button type="link" danger onClick={() => removeAt(index)}>
|
||||||
|
删除
|
||||||
|
</Button>
|
||||||
|
) : null}
|
||||||
|
</Space>
|
||||||
|
|
||||||
|
{!isCollapsed ? (
|
||||||
|
<>
|
||||||
|
<Form.Item label="套餐名称" required style={{ marginBottom: 12 }}>
|
||||||
|
<Input
|
||||||
|
placeholder="如:套餐A"
|
||||||
|
value={item.name}
|
||||||
|
onChange={(e) => updateAt(index, { name: e.target.value })}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
|
||||||
|
<Form.Item label="价格(元)" required style={{ marginBottom: 12 }}>
|
||||||
|
<InputNumber
|
||||||
|
min={0}
|
||||||
|
precision={2}
|
||||||
|
style={{ width: '100%' }}
|
||||||
|
addonAfter="元"
|
||||||
|
placeholder="198"
|
||||||
|
value={item.price === '' ? undefined : Number(item.price)}
|
||||||
|
onChange={(v) => updateAt(index, { price: v != null ? String(v) : '' })}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
|
||||||
|
<Form.Item label="菜品" required style={{ marginBottom: 12 }}>
|
||||||
|
<Input.TextArea
|
||||||
|
rows={2}
|
||||||
|
placeholder="红烧肉、红烧鱼、油焖茄子"
|
||||||
|
value={item.dishes}
|
||||||
|
onChange={(e) => updateAt(index, { dishes: e.target.value })}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
|
||||||
|
<Form.Item label="使用时间" style={{ marginBottom: 12 }}>
|
||||||
|
<Input.TextArea
|
||||||
|
rows={2}
|
||||||
|
placeholder="节假日除外"
|
||||||
|
value={item.usableTime || ''}
|
||||||
|
onChange={(e) => updateAt(index, { usableTime: e.target.value })}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
|
||||||
|
<Form.Item label="套餐图片" style={{ marginBottom: 12 }}>
|
||||||
|
<PackageImagesUpload
|
||||||
|
value={normalizeStorePackageImageUrls(item)}
|
||||||
|
onChange={(imageUrls) =>
|
||||||
|
updateAt(index, {
|
||||||
|
imageUrls,
|
||||||
|
imageUrl: imageUrls[0] ?? '',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
|
||||||
|
<Form.Item label="其他说明" style={{ marginBottom: 0 }}>
|
||||||
|
<Input.TextArea
|
||||||
|
rows={2}
|
||||||
|
placeholder="不可叠加"
|
||||||
|
value={item.otherNotes || ''}
|
||||||
|
onChange={(e) => updateAt(index, { otherNotes: e.target.value })}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
</>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
|
||||||
|
{items.length < STORE_PACKAGE_MAX_COUNT ? (
|
||||||
|
<Button onClick={addRow} style={{ marginBottom: 16 }}>
|
||||||
|
添加套餐
|
||||||
|
</Button>
|
||||||
|
) : null}
|
||||||
|
|
||||||
|
<Typography.Paragraph type="secondary" style={{ marginBottom: 12 }}>
|
||||||
|
上传套餐图后请点右上角「保存修改」(会连同套餐一起保存),或点下方「保存套餐」。仅上传不保存,刷新会丢失。
|
||||||
|
</Typography.Paragraph>
|
||||||
|
|
||||||
|
<Button type="primary" loading={saving} onClick={() => void save().catch(() => undefined)}>
|
||||||
|
保存套餐
|
||||||
|
</Button>
|
||||||
|
</Form>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
export default AdminStorePackagesSection;
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
import { useMemo } from 'react';
|
||||||
|
import { Select } from 'antd';
|
||||||
|
import { getDistrictOptionsByCityCode } from '../lib/china-region';
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
cityCode?: string | null;
|
||||||
|
value?: string[];
|
||||||
|
onChange?: (value: string[]) => void;
|
||||||
|
placeholder?: string;
|
||||||
|
disabled?: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
/** 已选开城城市后,仅多选该市下区县(不再选省/市) */
|
||||||
|
export default function CityDistrictMultiSelect({
|
||||||
|
cityCode,
|
||||||
|
value,
|
||||||
|
onChange,
|
||||||
|
placeholder,
|
||||||
|
disabled,
|
||||||
|
}: Props) {
|
||||||
|
const options = useMemo(() => getDistrictOptionsByCityCode(cityCode), [cityCode]);
|
||||||
|
const ready = Boolean(cityCode) && options.length > 0;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Select
|
||||||
|
mode="multiple"
|
||||||
|
allowClear
|
||||||
|
showSearch
|
||||||
|
optionFilterProp="label"
|
||||||
|
value={value}
|
||||||
|
onChange={onChange}
|
||||||
|
disabled={disabled || !ready}
|
||||||
|
placeholder={
|
||||||
|
placeholder ??
|
||||||
|
(cityCode ? (ready ? '请选择区县(可多选)' : '该城市暂无区县数据') : '请先选择开城城市')
|
||||||
|
}
|
||||||
|
options={options}
|
||||||
|
style={{ width: '100%' }}
|
||||||
|
maxTagCount="responsive"
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
import { useCallback, useEffect, useState } from 'react';
|
import { useCallback, useEffect, useState } from 'react';
|
||||||
import {
|
import {
|
||||||
Button,
|
Button,
|
||||||
Cascader,
|
|
||||||
Checkbox,
|
Checkbox,
|
||||||
Drawer,
|
Drawer,
|
||||||
Form,
|
Form,
|
||||||
@@ -27,8 +26,9 @@ import {
|
|||||||
type PartnerPermissionKey,
|
type PartnerPermissionKey,
|
||||||
} from '@dukang/shared-types';
|
} from '@dukang/shared-types';
|
||||||
import { request, type Paginated } from '../lib/api';
|
import { request, type Paginated } from '../lib/api';
|
||||||
import { CHINA_REGION_OPTIONS } from '../lib/china-region';
|
import { districtCodeLabel, formatDistrictLabels } from '../lib/china-region';
|
||||||
import { fmtTime } from '../lib/constants';
|
import { fmtTime } from '../lib/constants';
|
||||||
|
import CityDistrictMultiSelect from './CityDistrictMultiSelect';
|
||||||
import PartnerSubAccountList from './PartnerSubAccountList';
|
import PartnerSubAccountList from './PartnerSubAccountList';
|
||||||
|
|
||||||
type PartnerRow = {
|
type PartnerRow = {
|
||||||
@@ -37,6 +37,7 @@ type PartnerRow = {
|
|||||||
phone: string;
|
phone: string;
|
||||||
name: string;
|
name: string;
|
||||||
scopeType?: string;
|
scopeType?: string;
|
||||||
|
districtCodes?: string[] | null;
|
||||||
orderCommissionRate?: number;
|
orderCommissionRate?: number;
|
||||||
redeemCommissionRate?: number;
|
redeemCommissionRate?: number;
|
||||||
accountCount: number;
|
accountCount: number;
|
||||||
@@ -65,6 +66,7 @@ type PartnerDetail = PartnerRow & {
|
|||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
cityId: string;
|
cityId: string;
|
||||||
|
cityCode?: string;
|
||||||
maxPartnerCommissionRate?: number;
|
maxPartnerCommissionRate?: number;
|
||||||
onChanged?: () => void;
|
onChanged?: () => void;
|
||||||
};
|
};
|
||||||
@@ -92,14 +94,31 @@ function commissionSumError(
|
|||||||
redeemPercent: number,
|
redeemPercent: number,
|
||||||
maxRate: number,
|
maxRate: number,
|
||||||
): string | null {
|
): string | null {
|
||||||
const sum = orderPercent / 100 + redeemPercent / 100;
|
// API 可能把 Prisma Decimal 序列化为字符串;`"0.05" + 1e-9` 会变成字符串拼接导致误判超限
|
||||||
if (sum > maxRate + 1e-9) {
|
const max = Number(maxRate);
|
||||||
return `订单佣金与核销佣金合计不得超过 ${(maxRate * 100).toFixed(2)}%(当前 ${(sum * 100).toFixed(2)}%)`;
|
const sum = Number(orderPercent) / 100 + Number(redeemPercent) / 100;
|
||||||
|
if (!Number.isFinite(max) || !Number.isFinite(sum)) return '佣金比例无效';
|
||||||
|
if (sum > max + 1e-9) {
|
||||||
|
return `订单佣金与核销佣金合计不得超过 ${(max * 100).toFixed(2)}%(当前 ${(sum * 100).toFixed(2)}%)`;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function CityPartnersPanel({ cityId, maxPartnerCommissionRate = 0.05, onChanged }: Props) {
|
function formatApiError(err: unknown): string | null {
|
||||||
|
if (err && typeof err === 'object' && 'errorFields' in err) return null;
|
||||||
|
if (!(err instanceof Error)) return '操作失败';
|
||||||
|
return err.message.replace(/\b(\d{6})\b/g, (code) => {
|
||||||
|
const label = districtCodeLabel(code);
|
||||||
|
return label !== code ? `${label}(${code})` : code;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function CityPartnersPanel({
|
||||||
|
cityId,
|
||||||
|
cityCode,
|
||||||
|
maxPartnerCommissionRate = 0.05,
|
||||||
|
onChanged,
|
||||||
|
}: Props) {
|
||||||
const [editForm] = Form.useForm();
|
const [editForm] = Form.useForm();
|
||||||
const [createForm] = Form.useForm();
|
const [createForm] = Form.useForm();
|
||||||
const [subForm] = Form.useForm();
|
const [subForm] = Form.useForm();
|
||||||
@@ -153,29 +172,34 @@ export default function CityPartnersPanel({ cityId, maxPartnerCommissionRate = 0
|
|||||||
|
|
||||||
async function savePartner() {
|
async function savePartner() {
|
||||||
if (!detail) return;
|
if (!detail) return;
|
||||||
const v = await editForm.validateFields();
|
try {
|
||||||
const err = commissionSumError(
|
const v = await editForm.validateFields();
|
||||||
Number(v.orderCommissionRate ?? 0),
|
const err = commissionSumError(
|
||||||
Number(v.redeemCommissionRate ?? 0),
|
Number(v.orderCommissionRate ?? 0),
|
||||||
maxPartnerCommissionRate,
|
Number(v.redeemCommissionRate ?? 0),
|
||||||
);
|
maxPartnerCommissionRate,
|
||||||
if (err) {
|
);
|
||||||
message.error(err);
|
if (err) {
|
||||||
return;
|
message.error(err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await request(`/admin/partners/${detail.id}`, {
|
||||||
|
method: 'PUT',
|
||||||
|
body: JSON.stringify({
|
||||||
|
...v,
|
||||||
|
orderCommissionRate: Number(v.orderCommissionRate ?? 0) / 100,
|
||||||
|
redeemCommissionRate: Number(v.redeemCommissionRate ?? 3) / 100,
|
||||||
|
districtCodes: editScopeType === CityPartnerScopeType.DISTRICT ? flattenDistrictCodes(v.districtCodes) : undefined,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
message.success('已保存');
|
||||||
|
setDrawerOpen(false);
|
||||||
|
void loadPartners();
|
||||||
|
onChanged?.();
|
||||||
|
} catch (e) {
|
||||||
|
const msg = formatApiError(e);
|
||||||
|
if (msg) message.error(msg);
|
||||||
}
|
}
|
||||||
await request(`/admin/partners/${detail.id}`, {
|
|
||||||
method: 'PUT',
|
|
||||||
body: JSON.stringify({
|
|
||||||
...v,
|
|
||||||
orderCommissionRate: Number(v.orderCommissionRate ?? 0) / 100,
|
|
||||||
redeemCommissionRate: Number(v.redeemCommissionRate ?? 3) / 100,
|
|
||||||
districtCodes: editScopeType === CityPartnerScopeType.DISTRICT ? flattenDistrictCodes(v.districtCodes) : undefined,
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
message.success('已保存');
|
|
||||||
setDrawerOpen(false);
|
|
||||||
void loadPartners();
|
|
||||||
onChanged?.();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function deleteSubAccount(subId: string) {
|
async function deleteSubAccount(subId: string) {
|
||||||
@@ -187,6 +211,14 @@ export default function CityPartnersPanel({ cityId, maxPartnerCommissionRate = 0
|
|||||||
}
|
}
|
||||||
|
|
||||||
const columns: ColumnsType<PartnerRow> = [
|
const columns: ColumnsType<PartnerRow> = [
|
||||||
|
{
|
||||||
|
title: '区县',
|
||||||
|
dataIndex: 'districtCodes',
|
||||||
|
width: 160,
|
||||||
|
ellipsis: true,
|
||||||
|
render: (codes: string[] | null | undefined, row) =>
|
||||||
|
row.scopeType === CityPartnerScopeType.CITY_WIDE ? '全城' : formatDistrictLabels(codes),
|
||||||
|
},
|
||||||
{ title: '公司名', dataIndex: 'companyName', ellipsis: true },
|
{ title: '公司名', dataIndex: 'companyName', ellipsis: true },
|
||||||
{ title: '主账号', dataIndex: 'phone', width: 120 },
|
{ title: '主账号', dataIndex: 'phone', width: 120 },
|
||||||
{
|
{
|
||||||
@@ -249,11 +281,11 @@ export default function CityPartnersPanel({ cityId, maxPartnerCommissionRate = 0
|
|||||||
label: '主账号',
|
label: '主账号',
|
||||||
children: (
|
children: (
|
||||||
<Form form={editForm} layout="vertical">
|
<Form form={editForm} layout="vertical">
|
||||||
<Form.Item name="companyName" label="公司名" rules={[{ required: true }]}><Input /></Form.Item>
|
<Form.Item name="companyName" label="公司名"><Input placeholder="选填" /></Form.Item>
|
||||||
<Form.Item name="name" label="主账号姓名" rules={[{ required: true }]}><Input /></Form.Item>
|
<Form.Item name="name" label="主账号姓名" rules={[{ required: true }]}><Input /></Form.Item>
|
||||||
<Form.Item name="phone" label="登录手机号" rules={[{ required: true }]}><Input /></Form.Item>
|
<Form.Item name="phone" label="登录手机号" rules={[{ required: true }]}><Input /></Form.Item>
|
||||||
<Form.Item name="contactPhone" label="业务联系电话"><Input /></Form.Item>
|
<Form.Item name="contactPhone" label="业务联系电话"><Input /></Form.Item>
|
||||||
<Form.Item name="address" label="地址" rules={[{ required: true }]}><Input /></Form.Item>
|
<Form.Item name="address" label="地址"><Input placeholder="选填" /></Form.Item>
|
||||||
<Form.Item name="bindingStatus" label="绑定状态" rules={[{ required: true }]}>
|
<Form.Item name="bindingStatus" label="绑定状态" rules={[{ required: true }]}>
|
||||||
<Select options={BINDING_OPTIONS} />
|
<Select options={BINDING_OPTIONS} />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
@@ -261,8 +293,12 @@ export default function CityPartnersPanel({ cityId, maxPartnerCommissionRate = 0
|
|||||||
<Select options={SCOPE_OPTIONS} onChange={(v) => setEditScopeType(v)} />
|
<Select options={SCOPE_OPTIONS} onChange={(v) => setEditScopeType(v)} />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
{editScopeType === CityPartnerScopeType.DISTRICT && (
|
{editScopeType === CityPartnerScopeType.DISTRICT && (
|
||||||
<Form.Item name="districtCodes" label="区县">
|
<Form.Item
|
||||||
<Cascader options={CHINA_REGION_OPTIONS} multiple changeOnSelect />
|
name="districtCodes"
|
||||||
|
label="区县"
|
||||||
|
extra="仅作标识,可多选当前城市下的区县(不做互斥)"
|
||||||
|
>
|
||||||
|
<CityDistrictMultiSelect cityCode={cityCode} />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
)}
|
)}
|
||||||
<Space style={{ width: '100%' }} size="large">
|
<Space style={{ width: '100%' }} size="large">
|
||||||
@@ -316,42 +352,51 @@ export default function CityPartnersPanel({ cityId, maxPartnerCommissionRate = 0
|
|||||||
</Drawer>
|
</Drawer>
|
||||||
|
|
||||||
<Modal title="新建城市合伙人" open={createOpen} width={560} onCancel={() => setCreateOpen(false)} onOk={async () => {
|
<Modal title="新建城市合伙人" open={createOpen} width={560} onCancel={() => setCreateOpen(false)} onOk={async () => {
|
||||||
const v = await createForm.validateFields();
|
try {
|
||||||
const err = commissionSumError(
|
const v = await createForm.validateFields();
|
||||||
Number(v.orderCommissionRate ?? 0),
|
const err = commissionSumError(
|
||||||
Number(v.redeemCommissionRate ?? 3),
|
Number(v.orderCommissionRate ?? 0),
|
||||||
maxPartnerCommissionRate,
|
Number(v.redeemCommissionRate ?? 3),
|
||||||
);
|
maxPartnerCommissionRate,
|
||||||
if (err) {
|
);
|
||||||
message.error(err);
|
if (err) {
|
||||||
return;
|
message.error(err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await request('/admin/partners', {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify({
|
||||||
|
...v,
|
||||||
|
cityId,
|
||||||
|
orderCommissionRate: Number(v.orderCommissionRate ?? 0) / 100,
|
||||||
|
redeemCommissionRate: Number(v.redeemCommissionRate ?? 3) / 100,
|
||||||
|
districtCodes: createScopeType === CityPartnerScopeType.DISTRICT ? flattenDistrictCodes(v.districtCodes) : undefined,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
message.success('已创建');
|
||||||
|
setCreateOpen(false);
|
||||||
|
void loadPartners();
|
||||||
|
onChanged?.();
|
||||||
|
} catch (e) {
|
||||||
|
const msg = formatApiError(e);
|
||||||
|
if (msg) message.error(msg);
|
||||||
}
|
}
|
||||||
await request('/admin/partners', {
|
|
||||||
method: 'POST',
|
|
||||||
body: JSON.stringify({
|
|
||||||
...v,
|
|
||||||
cityId,
|
|
||||||
orderCommissionRate: Number(v.orderCommissionRate ?? 0) / 100,
|
|
||||||
redeemCommissionRate: Number(v.redeemCommissionRate ?? 3) / 100,
|
|
||||||
districtCodes: createScopeType === CityPartnerScopeType.DISTRICT ? flattenDistrictCodes(v.districtCodes) : undefined,
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
message.success('已创建');
|
|
||||||
setCreateOpen(false);
|
|
||||||
void loadPartners();
|
|
||||||
onChanged?.();
|
|
||||||
}}>
|
}}>
|
||||||
<Form form={createForm} layout="vertical">
|
<Form form={createForm} layout="vertical">
|
||||||
<Form.Item name="companyName" label="公司名" rules={[{ required: true }]}><Input /></Form.Item>
|
<Form.Item name="companyName" label="公司名"><Input placeholder="选填" /></Form.Item>
|
||||||
<Form.Item name="name" label="主账号姓名" rules={[{ required: true }]}><Input /></Form.Item>
|
<Form.Item name="name" label="主账号姓名" rules={[{ required: true }]}><Input /></Form.Item>
|
||||||
<Form.Item name="phone" label="登录手机号" rules={[{ required: true }]}><Input /></Form.Item>
|
<Form.Item name="phone" label="登录手机号" rules={[{ required: true }]}><Input /></Form.Item>
|
||||||
<Form.Item name="address" label="地址" rules={[{ required: true }]}><Input /></Form.Item>
|
<Form.Item name="address" label="地址"><Input placeholder="选填" /></Form.Item>
|
||||||
<Form.Item name="scopeType" label="管辖类型" rules={[{ required: true }]}>
|
<Form.Item name="scopeType" label="管辖类型" rules={[{ required: true }]}>
|
||||||
<Select options={SCOPE_OPTIONS} onChange={(v) => setCreateScopeType(v)} />
|
<Select options={SCOPE_OPTIONS} onChange={(v) => setCreateScopeType(v)} />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
{createScopeType === CityPartnerScopeType.DISTRICT && (
|
{createScopeType === CityPartnerScopeType.DISTRICT && (
|
||||||
<Form.Item name="districtCodes" label="区县" rules={[{ required: true }]}>
|
<Form.Item
|
||||||
<Cascader options={CHINA_REGION_OPTIONS} multiple changeOnSelect />
|
name="districtCodes"
|
||||||
|
label="区县"
|
||||||
|
extra="选填;仅作标识,可多选当前城市下的区县(不做互斥)"
|
||||||
|
>
|
||||||
|
<CityDistrictMultiSelect cityCode={cityCode} />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
)}
|
)}
|
||||||
<Space style={{ width: '100%' }} size="large">
|
<Space style={{ width: '100%' }} size="large">
|
||||||
|
|||||||
@@ -0,0 +1,138 @@
|
|||||||
|
import { useEffect, useState } from 'react';
|
||||||
|
import { Button, Space } from 'antd';
|
||||||
|
import { ArrowDownOutlined, ArrowUpOutlined, DeleteOutlined, PlusOutlined } from '@ant-design/icons';
|
||||||
|
import {
|
||||||
|
parseMiniHomeBanners,
|
||||||
|
serializeMiniHomeBanners,
|
||||||
|
} from '@dukang/shared-types';
|
||||||
|
import OssUpload from './OssUpload';
|
||||||
|
|
||||||
|
const MAX_BANNERS = 8;
|
||||||
|
|
||||||
|
/** 编辑态保留空位;下发/入库仍用 parseMiniHomeBanners 过滤空串 */
|
||||||
|
function parseBannersForEdit(raw?: string | null): string[] {
|
||||||
|
if (!raw?.trim()) return [];
|
||||||
|
try {
|
||||||
|
const parsed = JSON.parse(raw.trim()) as unknown;
|
||||||
|
if (!Array.isArray(parsed)) return parseMiniHomeBanners(raw);
|
||||||
|
return parsed
|
||||||
|
.filter((u): u is string => typeof u === 'string')
|
||||||
|
.map((u) => u.trim())
|
||||||
|
.slice(0, MAX_BANNERS);
|
||||||
|
} catch {
|
||||||
|
return parseMiniHomeBanners(raw);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Ant Form 控件:单图 URL 字符串(默认 OSS 路径 footer) */
|
||||||
|
export function ConfigImageField({
|
||||||
|
value,
|
||||||
|
onChange,
|
||||||
|
bizType = 'footer',
|
||||||
|
}: {
|
||||||
|
value?: string;
|
||||||
|
onChange?: (url: string) => void;
|
||||||
|
bizType?: string;
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<OssUpload
|
||||||
|
bizType={bizType}
|
||||||
|
mediaType="IMAGE"
|
||||||
|
value={value ?? ''}
|
||||||
|
onChange={(url) => onChange?.(url ?? '')}
|
||||||
|
placeholder="上传或粘贴图片 URL"
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Ant Form 控件:多图 JSON 字符串(默认 OSS 路径 swiper) */
|
||||||
|
export function ConfigImageListField({
|
||||||
|
value,
|
||||||
|
onChange,
|
||||||
|
bizType = 'swiper',
|
||||||
|
}: {
|
||||||
|
value?: string;
|
||||||
|
onChange?: (json: string) => void;
|
||||||
|
bizType?: string;
|
||||||
|
}) {
|
||||||
|
const [urls, setUrls] = useState<string[]>(() => parseBannersForEdit(value));
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setUrls(parseBannersForEdit(value));
|
||||||
|
}, [value]);
|
||||||
|
|
||||||
|
/** 本地可含空位;写入 Form 时去掉空串 */
|
||||||
|
function commit(next: string[]) {
|
||||||
|
const clipped = next.slice(0, MAX_BANNERS);
|
||||||
|
setUrls(clipped);
|
||||||
|
onChange?.(serializeMiniHomeBanners(clipped));
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateAt(index: number, url: string) {
|
||||||
|
const next = [...urls];
|
||||||
|
next[index] = url;
|
||||||
|
commit(next);
|
||||||
|
}
|
||||||
|
|
||||||
|
function removeAt(index: number) {
|
||||||
|
commit(urls.filter((_, i) => i !== index));
|
||||||
|
}
|
||||||
|
|
||||||
|
function move(index: number, delta: number) {
|
||||||
|
const target = index + delta;
|
||||||
|
if (target < 0 || target >= urls.length) return;
|
||||||
|
const next = [...urls];
|
||||||
|
const tmp = next[index];
|
||||||
|
next[index] = next[target];
|
||||||
|
next[target] = tmp;
|
||||||
|
commit(next);
|
||||||
|
}
|
||||||
|
|
||||||
|
function add() {
|
||||||
|
if (urls.length >= MAX_BANNERS) return;
|
||||||
|
// 只加本地空位,避免 serialize 过滤空串导致「点击无反应」
|
||||||
|
setUrls((prev) => [...prev, '']);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Space direction="vertical" style={{ width: '100%' }} size="middle">
|
||||||
|
{urls.map((url, index) => (
|
||||||
|
<Space key={`banner-${index}`} align="start" style={{ width: '100%' }} wrap>
|
||||||
|
<div style={{ flex: 1, minWidth: 240 }}>
|
||||||
|
<OssUpload
|
||||||
|
bizType={bizType}
|
||||||
|
mediaType="IMAGE"
|
||||||
|
value={url}
|
||||||
|
onChange={(u) => updateAt(index, u)}
|
||||||
|
placeholder="上传或粘贴图片 URL"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<Space>
|
||||||
|
<Button
|
||||||
|
type="text"
|
||||||
|
icon={<ArrowUpOutlined />}
|
||||||
|
disabled={index === 0}
|
||||||
|
onClick={() => move(index, -1)}
|
||||||
|
/>
|
||||||
|
<Button
|
||||||
|
type="text"
|
||||||
|
icon={<ArrowDownOutlined />}
|
||||||
|
disabled={index === urls.length - 1}
|
||||||
|
onClick={() => move(index, 1)}
|
||||||
|
/>
|
||||||
|
<Button type="text" danger icon={<DeleteOutlined />} onClick={() => removeAt(index)} />
|
||||||
|
</Space>
|
||||||
|
</Space>
|
||||||
|
))}
|
||||||
|
<Button
|
||||||
|
type="dashed"
|
||||||
|
block
|
||||||
|
icon={<PlusOutlined />}
|
||||||
|
disabled={urls.length >= MAX_BANNERS}
|
||||||
|
onClick={add}
|
||||||
|
>
|
||||||
|
添加轮播图({urls.length}/{MAX_BANNERS})
|
||||||
|
</Button>
|
||||||
|
</Space>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
import { Button, Form, Space, Typography } from 'antd';
|
import { Typography } from 'antd';
|
||||||
import { MinusCircleOutlined, PlusOutlined } from '@ant-design/icons';
|
import MultiImageUpload from './MultiImageUpload';
|
||||||
import OssUpload from './OssUpload';
|
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
name?: string;
|
name?: string;
|
||||||
@@ -8,42 +7,35 @@ type Props = {
|
|||||||
bizType?: string;
|
bizType?: string;
|
||||||
/** 最多可添加张数;不传则不限制 */
|
/** 最多可添加张数;不传则不限制 */
|
||||||
maxCount?: number;
|
maxCount?: number;
|
||||||
|
/** Form.Item 注入 */
|
||||||
|
value?: string[];
|
||||||
|
onChange?: (urls: string[]) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 商品详情/轮播等多图列表。
|
||||||
|
* 可直接包在 Form.Item 下(value/onChange),也可用 Form.List 的 name 外层再包 Form.Item。
|
||||||
|
*/
|
||||||
export default function DetailImageUrlList({
|
export default function DetailImageUrlList({
|
||||||
name = 'detailImageUrls',
|
|
||||||
label,
|
label,
|
||||||
bizType = 'DETAIL',
|
bizType = 'DETAIL',
|
||||||
maxCount,
|
maxCount,
|
||||||
|
value,
|
||||||
|
onChange,
|
||||||
}: Props) {
|
}: Props) {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{maxCount != null && (
|
<Typography.Text type="secondary" style={{ display: 'block', marginBottom: 8 }}>
|
||||||
<Typography.Text type="secondary" style={{ display: 'block', marginBottom: 8 }}>
|
{label}:支持批量上传{maxCount != null ? `,最多 ${maxCount} 张` : ''}
|
||||||
最多 {maxCount} 张{label}
|
</Typography.Text>
|
||||||
</Typography.Text>
|
<MultiImageUpload
|
||||||
)}
|
bizType={bizType}
|
||||||
<Form.List name={name}>
|
mediaType="IMAGE"
|
||||||
{(fields, { add, remove }) => (
|
maxCount={maxCount}
|
||||||
<>
|
value={value}
|
||||||
{fields.map((field) => (
|
onChange={onChange}
|
||||||
<Space key={field.key} align="start" style={{ display: 'flex', marginBottom: 8 }}>
|
tip={`支持一次选择多张${label}`}
|
||||||
<Form.Item {...field} style={{ flex: 1, marginBottom: 0 }}>
|
/>
|
||||||
<OssUpload bizType={bizType} mediaType="IMAGE" />
|
|
||||||
</Form.Item>
|
|
||||||
{fields.length > 1 && (
|
|
||||||
<MinusCircleOutlined onClick={() => remove(field.name)} style={{ marginTop: 8 }} />
|
|
||||||
)}
|
|
||||||
</Space>
|
|
||||||
))}
|
|
||||||
{(!maxCount || fields.length < maxCount) && (
|
|
||||||
<Button type="dashed" onClick={() => add('')} block icon={<PlusOutlined />}>
|
|
||||||
添加{label}
|
|
||||||
</Button>
|
|
||||||
)}
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</Form.List>
|
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,215 @@
|
|||||||
|
import { useEffect, useRef, useState } from 'react';
|
||||||
|
import { Button, Image, Space, Typography, Upload, message } from 'antd';
|
||||||
|
import { UploadOutlined, DeleteOutlined, FilePdfOutlined } from '@ant-design/icons';
|
||||||
|
import type { UploadProps } from 'antd';
|
||||||
|
import { uploadFileToOss, type OssMediaType } from '../lib/upload';
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
value?: string[];
|
||||||
|
onChange?: (urls: string[]) => void;
|
||||||
|
bizType: string;
|
||||||
|
mediaType?: OssMediaType;
|
||||||
|
/** 最多张数;不传则不限制 */
|
||||||
|
maxCount?: number;
|
||||||
|
tip?: string;
|
||||||
|
accept?: string;
|
||||||
|
/** 上传按钮文案,默认「批量上传图片」 */
|
||||||
|
buttonText?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
function normalizeUrls(value?: string[]) {
|
||||||
|
return (value ?? []).map((u) => String(u || '').trim()).filter(Boolean);
|
||||||
|
}
|
||||||
|
|
||||||
|
function isPdf(url: string) {
|
||||||
|
return /\.pdf(\?|$)/i.test(url);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 多图批量上传(一次可选多张),用于套餐图 / 环境照 / 商品详情图等。
|
||||||
|
* Form.Item 直接绑定 string[]。
|
||||||
|
*/
|
||||||
|
export default function MultiImageUpload({
|
||||||
|
value,
|
||||||
|
onChange,
|
||||||
|
bizType,
|
||||||
|
mediaType = 'IMAGE',
|
||||||
|
maxCount,
|
||||||
|
tip,
|
||||||
|
accept = 'image/*',
|
||||||
|
buttonText = '批量上传图片',
|
||||||
|
}: Props) {
|
||||||
|
const urls = normalizeUrls(value);
|
||||||
|
const urlsRef = useRef(urls);
|
||||||
|
const onChangeRef = useRef(onChange);
|
||||||
|
const [uploading, setUploading] = useState(false);
|
||||||
|
const batchBuf = useRef<File[]>([]);
|
||||||
|
const batchTimer = useRef<ReturnType<typeof setTimeout> | null>(null);
|
||||||
|
const uploadChain = useRef(Promise.resolve());
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
urlsRef.current = urls;
|
||||||
|
}, [urls]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
onChangeRef.current = onChange;
|
||||||
|
}, [onChange]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
return () => {
|
||||||
|
if (batchTimer.current) clearTimeout(batchTimer.current);
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const remaining = maxCount != null ? Math.max(0, maxCount - urls.length) : Number.POSITIVE_INFINITY;
|
||||||
|
const canAdd = remaining > 0;
|
||||||
|
|
||||||
|
async function uploadBatch(files: File[]) {
|
||||||
|
const current = urlsRef.current;
|
||||||
|
const room = maxCount != null ? Math.max(0, maxCount - current.length) : files.length;
|
||||||
|
const picked = files.slice(0, room);
|
||||||
|
if (!picked.length) {
|
||||||
|
message.warning(maxCount != null ? `最多 ${maxCount} 张` : '无法上传');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (files.length > picked.length) {
|
||||||
|
message.warning(`已达上限,仅上传前 ${picked.length} 张`);
|
||||||
|
}
|
||||||
|
|
||||||
|
setUploading(true);
|
||||||
|
const appended: string[] = [];
|
||||||
|
let fail = 0;
|
||||||
|
try {
|
||||||
|
for (const file of picked) {
|
||||||
|
try {
|
||||||
|
const result = await uploadFileToOss(file, { bizType, mediaType });
|
||||||
|
appended.push(result.url);
|
||||||
|
} catch {
|
||||||
|
fail += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (appended.length) {
|
||||||
|
// 始终基于最新列表追加,避免并行上传互相覆盖
|
||||||
|
const next = [...urlsRef.current, ...appended];
|
||||||
|
urlsRef.current = next;
|
||||||
|
onChangeRef.current?.(next);
|
||||||
|
message.success(`成功上传 ${appended.length} 张${fail ? `,失败 ${fail} 张` : ''}`);
|
||||||
|
} else if (fail) {
|
||||||
|
message.error('上传失败');
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
setUploading(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function enqueueUploadBatch(files: File[]) {
|
||||||
|
uploadChain.current = uploadChain.current
|
||||||
|
.then(() => uploadBatch(files))
|
||||||
|
.catch(() => undefined);
|
||||||
|
}
|
||||||
|
|
||||||
|
function flushBatch() {
|
||||||
|
if (batchTimer.current) {
|
||||||
|
clearTimeout(batchTimer.current);
|
||||||
|
batchTimer.current = null;
|
||||||
|
}
|
||||||
|
if (!batchBuf.current.length) return;
|
||||||
|
const files = [...batchBuf.current];
|
||||||
|
batchBuf.current = [];
|
||||||
|
enqueueUploadBatch(files);
|
||||||
|
}
|
||||||
|
|
||||||
|
const beforeUpload: UploadProps['beforeUpload'] = (file) => {
|
||||||
|
batchBuf.current.push(file as File);
|
||||||
|
// 多选时 beforeUpload 可能逐文件触发;短防抖合并成一次批量
|
||||||
|
if (batchTimer.current) clearTimeout(batchTimer.current);
|
||||||
|
batchTimer.current = setTimeout(() => {
|
||||||
|
flushBatch();
|
||||||
|
}, 80);
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
|
function removeAt(index: number) {
|
||||||
|
const next = urlsRef.current.filter((_, i) => i !== index);
|
||||||
|
urlsRef.current = next;
|
||||||
|
onChangeRef.current?.(next);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Space direction="vertical" style={{ width: '100%' }} size="middle">
|
||||||
|
<Typography.Text type="secondary">
|
||||||
|
{tip ??
|
||||||
|
(maxCount != null
|
||||||
|
? `最多 ${maxCount} 张,支持一次选择多张批量上传`
|
||||||
|
: '支持一次选择多张批量上传')}
|
||||||
|
{maxCount != null ? `(已选 ${urls.length}/${maxCount})` : urls.length ? `(已选 ${urls.length})` : ''}
|
||||||
|
</Typography.Text>
|
||||||
|
|
||||||
|
{urls.length > 0 ? (
|
||||||
|
<Image.PreviewGroup>
|
||||||
|
<Space wrap size={12}>
|
||||||
|
{urls.map((url, index) => (
|
||||||
|
<div key={`${url}-${index}`} style={{ position: 'relative', width: 96 }}>
|
||||||
|
{isPdf(url) ? (
|
||||||
|
<a
|
||||||
|
href={url}
|
||||||
|
target="_blank"
|
||||||
|
rel="noreferrer"
|
||||||
|
style={{
|
||||||
|
display: 'flex',
|
||||||
|
width: 96,
|
||||||
|
height: 96,
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
flexDirection: 'column',
|
||||||
|
gap: 4,
|
||||||
|
borderRadius: 6,
|
||||||
|
border: '1px solid #f0f0f0',
|
||||||
|
background: '#fafafa',
|
||||||
|
fontSize: 12,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<FilePdfOutlined style={{ fontSize: 24, color: '#cf1322' }} />
|
||||||
|
<span>PDF</span>
|
||||||
|
</a>
|
||||||
|
) : (
|
||||||
|
<Image
|
||||||
|
src={url}
|
||||||
|
width={96}
|
||||||
|
height={96}
|
||||||
|
style={{ objectFit: 'cover', borderRadius: 6, border: '1px solid #f0f0f0' }}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
<Button
|
||||||
|
type="text"
|
||||||
|
danger
|
||||||
|
size="small"
|
||||||
|
icon={<DeleteOutlined />}
|
||||||
|
onClick={() => removeAt(index)}
|
||||||
|
style={{
|
||||||
|
position: 'absolute',
|
||||||
|
top: 0,
|
||||||
|
right: 0,
|
||||||
|
background: 'rgba(255,255,255,0.85)',
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</Space>
|
||||||
|
</Image.PreviewGroup>
|
||||||
|
) : null}
|
||||||
|
|
||||||
|
<Upload
|
||||||
|
accept={accept}
|
||||||
|
multiple
|
||||||
|
showUploadList={false}
|
||||||
|
beforeUpload={beforeUpload}
|
||||||
|
disabled={uploading || !canAdd}
|
||||||
|
>
|
||||||
|
<Button icon={<UploadOutlined />} loading={uploading} disabled={!canAdd}>
|
||||||
|
{canAdd ? buttonText : '已达上限'}
|
||||||
|
</Button>
|
||||||
|
</Upload>
|
||||||
|
</Space>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,185 @@
|
|||||||
|
import { useCallback, useEffect, useMemo, useState } from 'react';
|
||||||
|
import {
|
||||||
|
Button,
|
||||||
|
Descriptions,
|
||||||
|
Drawer,
|
||||||
|
Empty,
|
||||||
|
Image,
|
||||||
|
Space,
|
||||||
|
Spin,
|
||||||
|
Timeline,
|
||||||
|
Typography,
|
||||||
|
message,
|
||||||
|
} from 'antd';
|
||||||
|
import type { OrderTrackDto, OrderTrackNodeDto } from '@dukang/shared-types';
|
||||||
|
import { isXfxProviderCode } from '@dukang/shared-types';
|
||||||
|
import { request } from '../lib/api';
|
||||||
|
import { DELIVERY_PROVIDER_LABELS, fmtTime } from '../lib/constants';
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
open: boolean;
|
||||||
|
orderId: string | null;
|
||||||
|
orderNo?: string | null;
|
||||||
|
orderStatus?: string | null;
|
||||||
|
onClose: () => void;
|
||||||
|
};
|
||||||
|
|
||||||
|
function providerLabel(provider?: string | null, company?: string | null) {
|
||||||
|
if (company) return company;
|
||||||
|
if (!provider) return '—';
|
||||||
|
if (DELIVERY_PROVIDER_LABELS[provider]) return DELIVERY_PROVIDER_LABELS[provider];
|
||||||
|
if (isXfxProviderCode(provider)) return '小飞侠';
|
||||||
|
return provider;
|
||||||
|
}
|
||||||
|
|
||||||
|
function sortOldestFirst(nodes: OrderTrackNodeDto[]) {
|
||||||
|
return [...nodes].sort((a, b) => {
|
||||||
|
const ta = new Date(a.createTime).getTime();
|
||||||
|
const tb = new Date(b.createTime).getTime();
|
||||||
|
if (Number.isNaN(ta) && Number.isNaN(tb)) return 0;
|
||||||
|
if (Number.isNaN(ta)) return 1;
|
||||||
|
if (Number.isNaN(tb)) return -1;
|
||||||
|
return ta - tb;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function OrderTrackDrawer({
|
||||||
|
open,
|
||||||
|
orderId,
|
||||||
|
orderNo,
|
||||||
|
orderStatus,
|
||||||
|
onClose,
|
||||||
|
}: Props) {
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
const [track, setTrack] = useState<OrderTrackDto | null>(null);
|
||||||
|
|
||||||
|
const load = useCallback(async () => {
|
||||||
|
if (!orderId) return;
|
||||||
|
setLoading(true);
|
||||||
|
try {
|
||||||
|
const data = await request<OrderTrackDto>(`/admin/orders/${orderId}/track`);
|
||||||
|
setTrack(data);
|
||||||
|
} catch (e) {
|
||||||
|
setTrack(null);
|
||||||
|
message.error(e instanceof Error ? e.message : '加载路由失败');
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
}, [orderId]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!open || !orderId) {
|
||||||
|
setTrack(null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
void load();
|
||||||
|
}, [open, orderId, load]);
|
||||||
|
|
||||||
|
const nodes = useMemo(
|
||||||
|
() => (track?.nodes?.length ? sortOldestFirst(track.nodes) : []),
|
||||||
|
[track?.nodes],
|
||||||
|
);
|
||||||
|
const timelineComplete = ['PENDING_RECEIVE', 'DELIVERED', 'COMPLETED'].includes(
|
||||||
|
orderStatus || '',
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Drawer
|
||||||
|
title="物流路由"
|
||||||
|
width={520}
|
||||||
|
open={open}
|
||||||
|
onClose={onClose}
|
||||||
|
extra={
|
||||||
|
<Button onClick={() => void load()} loading={loading} disabled={!orderId}>
|
||||||
|
刷新
|
||||||
|
</Button>
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<Spin spinning={loading}>
|
||||||
|
{(orderNo || track?.trackingNo || track?.provider) && (
|
||||||
|
<Descriptions column={1} bordered size="small" style={{ marginBottom: 16 }}>
|
||||||
|
{orderNo ? <Descriptions.Item label="订单号">{orderNo}</Descriptions.Item> : null}
|
||||||
|
<Descriptions.Item label="配送方式">
|
||||||
|
{providerLabel(track?.provider, track?.logisticsCompany)}
|
||||||
|
</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="运单号">{track?.trackingNo || '—'}</Descriptions.Item>
|
||||||
|
{track?.manualQueryUrl ? (
|
||||||
|
<Descriptions.Item label="物流查询">
|
||||||
|
<a href={track.manualQueryUrl} target="_blank" rel="noreferrer">
|
||||||
|
打开物流查询
|
||||||
|
</a>
|
||||||
|
</Descriptions.Item>
|
||||||
|
) : null}
|
||||||
|
{track?.estimatedArrival?.arriveTime ? (
|
||||||
|
<Descriptions.Item label="预计送达">
|
||||||
|
{fmtTime(track.estimatedArrival.arriveTime)}
|
||||||
|
{track.estimatedArrival.siteName
|
||||||
|
? `(${track.estimatedArrival.siteName})`
|
||||||
|
: ''}
|
||||||
|
</Descriptions.Item>
|
||||||
|
) : null}
|
||||||
|
</Descriptions>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{track?.signPhotoUrls && track.signPhotoUrls.length > 0 ? (
|
||||||
|
<div style={{ marginBottom: 16 }}>
|
||||||
|
<Typography.Title level={5} style={{ marginTop: 0 }}>
|
||||||
|
签收照片
|
||||||
|
</Typography.Title>
|
||||||
|
<Image.PreviewGroup>
|
||||||
|
<Space wrap>
|
||||||
|
{track.signPhotoUrls.map((url) => (
|
||||||
|
<Image
|
||||||
|
key={url}
|
||||||
|
src={url}
|
||||||
|
width={96}
|
||||||
|
height={96}
|
||||||
|
style={{ objectFit: 'cover', borderRadius: 6 }}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</Space>
|
||||||
|
</Image.PreviewGroup>
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
|
|
||||||
|
<Typography.Title level={5} style={{ marginTop: 0 }}>
|
||||||
|
物流动态
|
||||||
|
</Typography.Title>
|
||||||
|
{nodes.length > 0 ? (
|
||||||
|
<Timeline
|
||||||
|
items={nodes.map((node, index) => {
|
||||||
|
const isLatest = index === nodes.length - 1;
|
||||||
|
return {
|
||||||
|
color: isLatest ? (timelineComplete ? 'green' : 'blue') : 'gray',
|
||||||
|
children: (
|
||||||
|
<div>
|
||||||
|
{node.statusName ? (
|
||||||
|
<Typography.Text strong style={{ display: 'block' }}>
|
||||||
|
{node.statusName}
|
||||||
|
</Typography.Text>
|
||||||
|
) : null}
|
||||||
|
<Typography.Text style={{ display: 'block', whiteSpace: 'pre-wrap' }}>
|
||||||
|
{node.trackInfo || '—'}
|
||||||
|
</Typography.Text>
|
||||||
|
<Typography.Text type="secondary" style={{ fontSize: 12 }}>
|
||||||
|
{fmtTime(node.createTime)}
|
||||||
|
</Typography.Text>
|
||||||
|
</div>
|
||||||
|
),
|
||||||
|
};
|
||||||
|
})}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<Empty
|
||||||
|
image={Empty.PRESENTED_IMAGE_SIMPLE}
|
||||||
|
description={
|
||||||
|
track?.manualQueryUrl
|
||||||
|
? '暂无实时路由节点,可使用上方物流查询链接'
|
||||||
|
: '暂无路由信息,请稍后刷新'
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</Spin>
|
||||||
|
</Drawer>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import { Button, Image, Input, Space, Upload, message } from 'antd';
|
import { Button, Image, Input, Modal, Space, Upload, message } from 'antd';
|
||||||
import { UploadOutlined } from '@ant-design/icons';
|
import { EyeOutlined, FilePdfOutlined, UploadOutlined } from '@ant-design/icons';
|
||||||
import type { UploadProps } from 'antd';
|
import type { UploadProps } from 'antd';
|
||||||
import { uploadFileToOss, type OssMediaType, type UploadFileResult } from '../lib/upload';
|
import { uploadFileToOss, type OssMediaType, type UploadFileResult } from '../lib/upload';
|
||||||
|
|
||||||
@@ -15,7 +15,13 @@ type OssUploadProps = {
|
|||||||
placeholder?: string;
|
placeholder?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
const DEFAULT_MAX_MB = 10;
|
function isImageUrl(url: string) {
|
||||||
|
return /\.(png|jpe?g|gif|webp|bmp|svg)(\?|#|$)/i.test(url);
|
||||||
|
}
|
||||||
|
|
||||||
|
function isPdfUrl(url: string) {
|
||||||
|
return /\.pdf(\?|#|$)/i.test(url);
|
||||||
|
}
|
||||||
|
|
||||||
export default function OssUpload({
|
export default function OssUpload({
|
||||||
value,
|
value,
|
||||||
@@ -24,22 +30,16 @@ export default function OssUpload({
|
|||||||
bizType,
|
bizType,
|
||||||
mediaType = 'IMAGE',
|
mediaType = 'IMAGE',
|
||||||
accept,
|
accept,
|
||||||
maxSizeMb = DEFAULT_MAX_MB,
|
|
||||||
placeholder = '上传后自动填入,或手动粘贴 URL',
|
placeholder = '上传后自动填入,或手动粘贴 URL',
|
||||||
}: OssUploadProps) {
|
}: OssUploadProps) {
|
||||||
const [uploading, setUploading] = useState(false);
|
const [uploading, setUploading] = useState(false);
|
||||||
|
const [pdfPreviewOpen, setPdfPreviewOpen] = useState(false);
|
||||||
|
|
||||||
const resolvedAccept =
|
const resolvedAccept =
|
||||||
accept ?? (mediaType === 'VIDEO' ? 'video/*' : mediaType === 'FILE' ? undefined : 'image/*');
|
accept ?? (mediaType === 'VIDEO' ? 'video/*' : mediaType === 'FILE' ? undefined : 'image/*');
|
||||||
|
|
||||||
const customRequest: UploadProps['customRequest'] = async ({ file, onSuccess, onError }) => {
|
const customRequest: UploadProps['customRequest'] = async ({ file, onSuccess, onError }) => {
|
||||||
const raw = file as File;
|
const raw = file as File;
|
||||||
if (raw.size > maxSizeMb * 1024 * 1024) {
|
|
||||||
const err = new Error(`文件不能超过 ${maxSizeMb}MB`);
|
|
||||||
message.error(err.message);
|
|
||||||
onError?.(err);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
setUploading(true);
|
setUploading(true);
|
||||||
try {
|
try {
|
||||||
const result = await uploadFileToOss(raw, { bizType, mediaType });
|
const result = await uploadFileToOss(raw, { bizType, mediaType });
|
||||||
@@ -56,6 +56,57 @@ export default function OssUpload({
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const filePreview =
|
||||||
|
value && mediaType === 'FILE' ? (
|
||||||
|
isImageUrl(value) ? (
|
||||||
|
<Image src={value} width={120} height={120} style={{ objectFit: 'cover', borderRadius: 4 }} />
|
||||||
|
) : isPdfUrl(value) ? (
|
||||||
|
<Space direction="vertical" size={8}>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
width: 120,
|
||||||
|
height: 120,
|
||||||
|
borderRadius: 4,
|
||||||
|
border: '1px solid #f0f0f0',
|
||||||
|
background: '#fafafa',
|
||||||
|
display: 'flex',
|
||||||
|
flexDirection: 'column',
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
gap: 8,
|
||||||
|
color: '#cf1322',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<FilePdfOutlined style={{ fontSize: 36 }} />
|
||||||
|
<span style={{ fontSize: 12, color: 'rgba(0,0,0,0.45)' }}>PDF 合同</span>
|
||||||
|
</div>
|
||||||
|
<Space wrap>
|
||||||
|
<Button type="link" size="small" icon={<EyeOutlined />} onClick={() => setPdfPreviewOpen(true)}>
|
||||||
|
预览
|
||||||
|
</Button>
|
||||||
|
<Button type="link" size="small" href={value} target="_blank" rel="noreferrer">
|
||||||
|
新窗口打开
|
||||||
|
</Button>
|
||||||
|
</Space>
|
||||||
|
<Modal
|
||||||
|
title="签约合同预览"
|
||||||
|
open={pdfPreviewOpen}
|
||||||
|
onCancel={() => setPdfPreviewOpen(false)}
|
||||||
|
footer={null}
|
||||||
|
width="90vw"
|
||||||
|
styles={{ body: { height: '75vh', padding: 0 } }}
|
||||||
|
destroyOnClose
|
||||||
|
>
|
||||||
|
<iframe title="合同 PDF 预览" src={value} style={{ width: '100%', height: '100%', border: 0 }} />
|
||||||
|
</Modal>
|
||||||
|
</Space>
|
||||||
|
) : (
|
||||||
|
<Button type="link" href={value} target="_blank" rel="noreferrer" style={{ paddingLeft: 0 }}>
|
||||||
|
打开已上传文件
|
||||||
|
</Button>
|
||||||
|
)
|
||||||
|
) : null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Space direction="vertical" style={{ width: '100%' }} size="small">
|
<Space direction="vertical" style={{ width: '100%' }} size="small">
|
||||||
{value && mediaType === 'IMAGE' && (
|
{value && mediaType === 'IMAGE' && (
|
||||||
@@ -64,6 +115,7 @@ export default function OssUpload({
|
|||||||
{value && mediaType === 'VIDEO' && (
|
{value && mediaType === 'VIDEO' && (
|
||||||
<video src={value} controls style={{ maxWidth: '100%', maxHeight: 160, borderRadius: 4 }} />
|
<video src={value} controls style={{ maxWidth: '100%', maxHeight: 160, borderRadius: 4 }} />
|
||||||
)}
|
)}
|
||||||
|
{filePreview}
|
||||||
<Space wrap>
|
<Space wrap>
|
||||||
<Upload
|
<Upload
|
||||||
accept={resolvedAccept}
|
accept={resolvedAccept}
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
import { STORE_PACKAGE_IMAGE_MAX_COUNT } from '@dukang/shared-types';
|
||||||
|
import MultiImageUpload from './MultiImageUpload';
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
value?: string[];
|
||||||
|
onChange?: (urls: string[]) => void;
|
||||||
|
};
|
||||||
|
|
||||||
|
/** 套餐多图:批量上传,最多 STORE_PACKAGE_IMAGE_MAX_COUNT 张 */
|
||||||
|
export default function PackageImagesUpload({ value, onChange }: Props) {
|
||||||
|
return (
|
||||||
|
<MultiImageUpload
|
||||||
|
bizType="STORE_PACKAGE"
|
||||||
|
mediaType="IMAGE"
|
||||||
|
maxCount={STORE_PACKAGE_IMAGE_MAX_COUNT}
|
||||||
|
value={value}
|
||||||
|
onChange={onChange}
|
||||||
|
tip={`套餐图片最多 ${STORE_PACKAGE_IMAGE_MAX_COUNT} 张,支持批量选择上传,可逐张删除`}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,616 @@
|
|||||||
|
import { useMemo, useState } from 'react';
|
||||||
|
import {
|
||||||
|
Button, Image, Input, InputNumber, Modal, Radio, Select, Space, Switch, Table, Typography, message,
|
||||||
|
} from 'antd';
|
||||||
|
import { EditOutlined, MinusCircleOutlined, PlusOutlined } from '@ant-design/icons';
|
||||||
|
import { request } from '../lib/api';
|
||||||
|
import { PRODUCT_STATUS_LABELS } from '../lib/constants';
|
||||||
|
import OssUpload from './OssUpload';
|
||||||
|
|
||||||
|
type SpecValue = { id?: string; name: string; sortOrder?: number };
|
||||||
|
type SpecAttr = { id?: string; name: string; sortOrder?: number; values: SpecValue[] };
|
||||||
|
type SkuRow = {
|
||||||
|
id?: string;
|
||||||
|
specValueIds: string[];
|
||||||
|
skuCode?: string;
|
||||||
|
barcode69: string;
|
||||||
|
price: number;
|
||||||
|
benefitAmount?: number;
|
||||||
|
status: string;
|
||||||
|
allowOnlinePurchase: boolean;
|
||||||
|
allowCrossCityDelivery: boolean;
|
||||||
|
allowOnSitePickup: boolean;
|
||||||
|
saleUnit: 'BOTTLE' | 'BOX';
|
||||||
|
bottlesPerUnit: number;
|
||||||
|
isDefault: boolean;
|
||||||
|
sortOrder?: number;
|
||||||
|
specText?: string;
|
||||||
|
imageUrl?: string | null;
|
||||||
|
};
|
||||||
|
|
||||||
|
function cartesian(attrs: SpecAttr[]): string[][] {
|
||||||
|
if (!attrs.length) return [[]];
|
||||||
|
return attrs.reduce<string[][]>(
|
||||||
|
(acc, attr) => {
|
||||||
|
const next: string[][] = [];
|
||||||
|
const values = attr.values.filter((v) => v.name?.trim());
|
||||||
|
for (const prev of acc) {
|
||||||
|
for (const v of values) {
|
||||||
|
const vid = v.id || `__new__:${attr.name}:${v.name}`;
|
||||||
|
next.push([...prev, vid]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return next.length ? next : acc;
|
||||||
|
},
|
||||||
|
[[]],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function keyOf(ids: string[]) {
|
||||||
|
return [...ids].sort().join('_');
|
||||||
|
}
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
productId: string;
|
||||||
|
initialAttrs: SpecAttr[];
|
||||||
|
initialSkus: SkuRow[];
|
||||||
|
onSaved: () => void;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function ProductSpecsEditor({ productId, initialAttrs, initialSkus, onSaved }: Props) {
|
||||||
|
const [attrs, setAttrs] = useState<SpecAttr[]>(
|
||||||
|
initialAttrs.length
|
||||||
|
? initialAttrs
|
||||||
|
: [],
|
||||||
|
);
|
||||||
|
const [skus, setSkus] = useState<SkuRow[]>(
|
||||||
|
initialSkus.length
|
||||||
|
? initialSkus.map((s) => ({
|
||||||
|
...s,
|
||||||
|
specValueIds: s.specValueIds ?? [],
|
||||||
|
status: s.status || 'ON_SALE',
|
||||||
|
allowOnlinePurchase: s.allowOnlinePurchase !== false,
|
||||||
|
allowCrossCityDelivery: s.allowCrossCityDelivery !== false,
|
||||||
|
allowOnSitePickup: !!s.allowOnSitePickup,
|
||||||
|
saleUnit: s.saleUnit === 'BOX' ? 'BOX' : 'BOTTLE',
|
||||||
|
bottlesPerUnit: s.bottlesPerUnit || (s.saleUnit === 'BOX' ? 6 : 1),
|
||||||
|
isDefault: !!s.isDefault,
|
||||||
|
imageUrl: s.imageUrl ?? '',
|
||||||
|
}))
|
||||||
|
: [
|
||||||
|
{
|
||||||
|
specValueIds: [],
|
||||||
|
barcode69: '',
|
||||||
|
price: 0,
|
||||||
|
status: 'ON_SALE',
|
||||||
|
allowOnlinePurchase: true,
|
||||||
|
allowCrossCityDelivery: true,
|
||||||
|
allowOnSitePickup: false,
|
||||||
|
saleUnit: 'BOTTLE',
|
||||||
|
bottlesPerUnit: 1,
|
||||||
|
isDefault: true,
|
||||||
|
imageUrl: '',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
);
|
||||||
|
const [saving, setSaving] = useState(false);
|
||||||
|
const [editIndex, setEditIndex] = useState<number | null>(null);
|
||||||
|
|
||||||
|
const combos = useMemo(() => cartesian(attrs.filter((a) => a.name.trim() && a.values.some((v) => v.name.trim()))), [attrs]);
|
||||||
|
|
||||||
|
function regenerateMatrix() {
|
||||||
|
const byKey = new Map(skus.map((s) => [keyOf(s.specValueIds ?? []), s]));
|
||||||
|
const next: SkuRow[] = combos.map((ids, i) => {
|
||||||
|
const existing = byKey.get(keyOf(ids));
|
||||||
|
if (existing) return { ...existing, specValueIds: ids, sortOrder: i };
|
||||||
|
return {
|
||||||
|
specValueIds: ids,
|
||||||
|
barcode69: '',
|
||||||
|
price: skus[0]?.price ?? 0,
|
||||||
|
benefitAmount: skus[0]?.benefitAmount,
|
||||||
|
status: 'DRAFT',
|
||||||
|
allowOnlinePurchase: true,
|
||||||
|
allowCrossCityDelivery: true,
|
||||||
|
allowOnSitePickup: false,
|
||||||
|
saleUnit: 'BOTTLE',
|
||||||
|
bottlesPerUnit: 1,
|
||||||
|
isDefault: i === 0,
|
||||||
|
sortOrder: i,
|
||||||
|
imageUrl: '',
|
||||||
|
};
|
||||||
|
});
|
||||||
|
if (next.length && !next.some((s) => s.isDefault)) next[0].isDefault = true;
|
||||||
|
setSkus(next.length ? next : skus);
|
||||||
|
}
|
||||||
|
|
||||||
|
function patchSku(index: number, patch: Partial<SkuRow>) {
|
||||||
|
setSkus((prev) => {
|
||||||
|
const next = [...prev];
|
||||||
|
next[index] = { ...next[index], ...patch };
|
||||||
|
return next;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async function handleSave() {
|
||||||
|
setSaving(true);
|
||||||
|
try {
|
||||||
|
// 1) 保存规格轴(新建值尚无 id,先提交 attrs)
|
||||||
|
const specsRes = await request<{
|
||||||
|
specAttrs: SpecAttr[];
|
||||||
|
skus: SkuRow[];
|
||||||
|
}>(`/admin/products/${productId}/specs`, {
|
||||||
|
method: 'PUT',
|
||||||
|
body: JSON.stringify({
|
||||||
|
attrs: attrs.map((a, i) => ({
|
||||||
|
id: a.id,
|
||||||
|
name: a.name.trim(),
|
||||||
|
sortOrder: i,
|
||||||
|
values: a.values
|
||||||
|
.filter((v) => v.name.trim())
|
||||||
|
.map((v, j) => ({ id: v.id, name: v.name.trim(), sortOrder: j })),
|
||||||
|
})),
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
|
// 映射临时 id → 真实 id
|
||||||
|
const nameToId = new Map<string, string>();
|
||||||
|
for (const a of specsRes.specAttrs ?? []) {
|
||||||
|
for (const v of a.values ?? []) {
|
||||||
|
nameToId.set(`${a.name}:${v.name}`, v.id!);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const resolveIds = (ids: string[]) =>
|
||||||
|
ids.map((id) => {
|
||||||
|
if (!id.startsWith('__new__:')) return id;
|
||||||
|
const [, attrName, valueName] = id.split(':');
|
||||||
|
const real = nameToId.get(`${attrName}:${valueName}`);
|
||||||
|
if (!real) throw new Error(`规格值未创建:${attrName}/${valueName}`);
|
||||||
|
return real;
|
||||||
|
});
|
||||||
|
|
||||||
|
const payloadSkus = skus.map((s, i) => ({
|
||||||
|
id: s.id,
|
||||||
|
specValueIds: resolveIds(s.specValueIds ?? []),
|
||||||
|
barcode69: s.barcode69.trim(),
|
||||||
|
price: s.price,
|
||||||
|
benefitAmount: s.benefitAmount,
|
||||||
|
status: s.status,
|
||||||
|
allowOnlinePurchase: s.allowOnlinePurchase,
|
||||||
|
allowCrossCityDelivery: s.allowCrossCityDelivery,
|
||||||
|
allowOnSitePickup: s.allowOnSitePickup,
|
||||||
|
saleUnit: s.saleUnit,
|
||||||
|
bottlesPerUnit: s.saleUnit === 'BOX' ? s.bottlesPerUnit || 6 : 1,
|
||||||
|
isDefault: !!s.isDefault,
|
||||||
|
sortOrder: i,
|
||||||
|
imageUrl: s.imageUrl?.trim() || null,
|
||||||
|
}));
|
||||||
|
|
||||||
|
const barcodes = payloadSkus.map((row) => row.barcode69);
|
||||||
|
if (barcodes.some((b) => !b)) throw new Error('每个规格须填写独立 69 码');
|
||||||
|
if (new Set(barcodes).size !== barcodes.length) {
|
||||||
|
throw new Error('同一商品内 69 码不可重复,每个规格请填写不同 69 码');
|
||||||
|
}
|
||||||
|
|
||||||
|
await request(`/admin/products/${productId}/skus`, {
|
||||||
|
method: 'PUT',
|
||||||
|
body: JSON.stringify({ skus: payloadSkus }),
|
||||||
|
});
|
||||||
|
message.success('规格与 SKU 已保存');
|
||||||
|
onSaved();
|
||||||
|
} catch (e) {
|
||||||
|
message.error(e instanceof Error ? e.message : '保存失败');
|
||||||
|
} finally {
|
||||||
|
setSaving(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const editing = editIndex != null ? skus[editIndex] : null;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<Typography.Paragraph type="secondary">
|
||||||
|
SKU 码由系统自动生成(DK 开头),无需填写。每个规格必须填写<strong>互不相同</strong>的 69 码,并可单独上传主图。
|
||||||
|
点「填写」在弹窗中编辑。先配置销售规格轴(如「包装」),再生成 SKU 矩阵。
|
||||||
|
</Typography.Paragraph>
|
||||||
|
|
||||||
|
<Typography.Title level={5}>规格轴</Typography.Title>
|
||||||
|
{attrs.map((attr, ai) => (
|
||||||
|
<div key={ai} style={{ marginBottom: 12, padding: 12, border: '1px solid #f0f0f0', borderRadius: 8 }}>
|
||||||
|
<Space align="start" style={{ width: '100%' }} wrap>
|
||||||
|
<Input
|
||||||
|
style={{ width: 140 }}
|
||||||
|
placeholder="规格名"
|
||||||
|
value={attr.name}
|
||||||
|
onChange={(e) => {
|
||||||
|
const next = [...attrs];
|
||||||
|
next[ai] = { ...attr, name: e.target.value };
|
||||||
|
setAttrs(next);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<Button
|
||||||
|
type="text"
|
||||||
|
danger
|
||||||
|
icon={<MinusCircleOutlined />}
|
||||||
|
onClick={() => setAttrs(attrs.filter((_, i) => i !== ai))}
|
||||||
|
/>
|
||||||
|
</Space>
|
||||||
|
<div style={{ marginTop: 8 }}>
|
||||||
|
{attr.values.map((val, vi) => (
|
||||||
|
<Space key={vi} style={{ display: 'flex', marginBottom: 6 }}>
|
||||||
|
<Input
|
||||||
|
placeholder="规格值"
|
||||||
|
value={val.name}
|
||||||
|
onChange={(e) => {
|
||||||
|
const next = [...attrs];
|
||||||
|
const values = [...attr.values];
|
||||||
|
values[vi] = { ...val, name: e.target.value };
|
||||||
|
next[ai] = { ...attr, values };
|
||||||
|
setAttrs(next);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<Button
|
||||||
|
type="text"
|
||||||
|
danger
|
||||||
|
icon={<MinusCircleOutlined />}
|
||||||
|
onClick={() => {
|
||||||
|
const next = [...attrs];
|
||||||
|
next[ai] = { ...attr, values: attr.values.filter((_, j) => j !== vi) };
|
||||||
|
setAttrs(next);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</Space>
|
||||||
|
))}
|
||||||
|
<Button
|
||||||
|
type="dashed"
|
||||||
|
size="small"
|
||||||
|
icon={<PlusOutlined />}
|
||||||
|
onClick={() => {
|
||||||
|
const next = [...attrs];
|
||||||
|
next[ai] = { ...attr, values: [...attr.values, { name: '' }] };
|
||||||
|
setAttrs(next);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
添加规格值
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
<Space style={{ marginBottom: 16 }}>
|
||||||
|
<Button
|
||||||
|
icon={<PlusOutlined />}
|
||||||
|
disabled={attrs.length >= 3}
|
||||||
|
onClick={() => setAttrs([...attrs, { name: '', values: [{ name: '' }] }])}
|
||||||
|
>
|
||||||
|
添加规格轴
|
||||||
|
</Button>
|
||||||
|
<Button onClick={regenerateMatrix}>按规格生成 SKU 矩阵</Button>
|
||||||
|
</Space>
|
||||||
|
|
||||||
|
<Typography.Title level={5}>SKU 列表</Typography.Title>
|
||||||
|
<Table
|
||||||
|
size="small"
|
||||||
|
rowKey={(_, i) => String(i)}
|
||||||
|
pagination={false}
|
||||||
|
scroll={{ x: 1240 }}
|
||||||
|
dataSource={skus}
|
||||||
|
columns={[
|
||||||
|
{
|
||||||
|
title: '规格',
|
||||||
|
width: 140,
|
||||||
|
render: (_, row) => row.specText || (row.specValueIds?.length ? row.specValueIds.join(',') : '默认'),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'SKU',
|
||||||
|
width: 110,
|
||||||
|
render: (_, row) => (
|
||||||
|
<Typography.Text type="secondary">
|
||||||
|
{row.skuCode || '保存后自动生成'}
|
||||||
|
</Typography.Text>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: <span>69码 <Typography.Text type="danger">*</Typography.Text></span>,
|
||||||
|
width: 180,
|
||||||
|
render: (_, row, index) => (
|
||||||
|
<Input
|
||||||
|
placeholder="本规格独立 69 码"
|
||||||
|
value={row.barcode69}
|
||||||
|
onChange={(e) => {
|
||||||
|
const next = [...skus];
|
||||||
|
next[index] = { ...row, barcode69: e.target.value };
|
||||||
|
setSkus(next);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '售价',
|
||||||
|
width: 100,
|
||||||
|
render: (_, row, index) => (
|
||||||
|
<InputNumber
|
||||||
|
min={0}
|
||||||
|
style={{ width: '100%' }}
|
||||||
|
value={row.price}
|
||||||
|
onChange={(v) => {
|
||||||
|
const next = [...skus];
|
||||||
|
next[index] = { ...row, price: Number(v) || 0 };
|
||||||
|
setSkus(next);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '权益',
|
||||||
|
width: 100,
|
||||||
|
render: (_, row, index) => (
|
||||||
|
<InputNumber
|
||||||
|
min={0}
|
||||||
|
style={{ width: '100%' }}
|
||||||
|
value={row.benefitAmount}
|
||||||
|
onChange={(v) => {
|
||||||
|
const next = [...skus];
|
||||||
|
next[index] = { ...row, benefitAmount: v == null ? undefined : Number(v) };
|
||||||
|
setSkus(next);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '状态',
|
||||||
|
width: 110,
|
||||||
|
render: (_, row, index) => (
|
||||||
|
<Select
|
||||||
|
style={{ width: '100%' }}
|
||||||
|
value={row.status}
|
||||||
|
options={Object.entries(PRODUCT_STATUS_LABELS).map(([value, label]) => ({ value, label }))}
|
||||||
|
onChange={(status) => {
|
||||||
|
const next = [...skus];
|
||||||
|
next[index] = { ...row, status };
|
||||||
|
setSkus(next);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '单位',
|
||||||
|
width: 160,
|
||||||
|
render: (_, row, index) => (
|
||||||
|
<Space>
|
||||||
|
<Select
|
||||||
|
style={{ width: 80 }}
|
||||||
|
value={row.saleUnit}
|
||||||
|
options={[
|
||||||
|
{ value: 'BOTTLE', label: '瓶' },
|
||||||
|
{ value: 'BOX', label: '箱' },
|
||||||
|
]}
|
||||||
|
onChange={(saleUnit) => {
|
||||||
|
const next = [...skus];
|
||||||
|
next[index] = {
|
||||||
|
...row,
|
||||||
|
saleUnit,
|
||||||
|
bottlesPerUnit: saleUnit === 'BOX' ? row.bottlesPerUnit || 6 : 1,
|
||||||
|
};
|
||||||
|
setSkus(next);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
{row.saleUnit === 'BOX' ? (
|
||||||
|
<InputNumber
|
||||||
|
min={1}
|
||||||
|
style={{ width: 70 }}
|
||||||
|
value={row.bottlesPerUnit}
|
||||||
|
onChange={(v) => {
|
||||||
|
const next = [...skus];
|
||||||
|
next[index] = { ...row, bottlesPerUnit: Number(v) || 6 };
|
||||||
|
setSkus(next);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
) : null}
|
||||||
|
</Space>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '履约',
|
||||||
|
width: 200,
|
||||||
|
render: (_, row, index) => (
|
||||||
|
<Space direction="vertical" size={0}>
|
||||||
|
<Switch
|
||||||
|
checkedChildren="线上"
|
||||||
|
unCheckedChildren="线上"
|
||||||
|
checked={row.allowOnlinePurchase}
|
||||||
|
onChange={(checked) => {
|
||||||
|
const next = [...skus];
|
||||||
|
next[index] = {
|
||||||
|
...row,
|
||||||
|
allowOnlinePurchase: checked,
|
||||||
|
allowCrossCityDelivery: checked ? row.allowCrossCityDelivery : false,
|
||||||
|
};
|
||||||
|
setSkus(next);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<Switch
|
||||||
|
checkedChildren="跨城"
|
||||||
|
unCheckedChildren="跨城"
|
||||||
|
disabled={!row.allowOnlinePurchase}
|
||||||
|
checked={row.allowCrossCityDelivery}
|
||||||
|
onChange={(checked) => {
|
||||||
|
const next = [...skus];
|
||||||
|
next[index] = { ...row, allowCrossCityDelivery: checked };
|
||||||
|
setSkus(next);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<Switch
|
||||||
|
checkedChildren="现场"
|
||||||
|
unCheckedChildren="现场"
|
||||||
|
checked={row.allowOnSitePickup}
|
||||||
|
onChange={(checked) => {
|
||||||
|
const next = [...skus];
|
||||||
|
next[index] = { ...row, allowOnSitePickup: checked };
|
||||||
|
setSkus(next);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</Space>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '默认',
|
||||||
|
width: 70,
|
||||||
|
render: (_, row, index) => (
|
||||||
|
<Radio
|
||||||
|
checked={row.isDefault}
|
||||||
|
onChange={() => {
|
||||||
|
setSkus(skus.map((s, i) => ({ ...s, isDefault: i === index })));
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '主图',
|
||||||
|
width: 72,
|
||||||
|
render: (_, row) =>
|
||||||
|
row.imageUrl ? (
|
||||||
|
<Image src={row.imageUrl} width={40} height={40} style={{ objectFit: 'cover', borderRadius: 4 }} />
|
||||||
|
) : (
|
||||||
|
<Typography.Text type="secondary">无</Typography.Text>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '编辑',
|
||||||
|
width: 80,
|
||||||
|
fixed: 'right',
|
||||||
|
render: (_, row, index) => (
|
||||||
|
<Button type="link" size="small" icon={<EditOutlined />} onClick={() => setEditIndex(index)}>
|
||||||
|
填写
|
||||||
|
</Button>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Button type="primary" loading={saving} style={{ marginTop: 16 }} onClick={() => void handleSave()}>
|
||||||
|
保存规格与 SKU
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
<Modal
|
||||||
|
title={`编辑规格${editing?.specText ? ` · ${editing.specText}` : editing?.skuCode ? ` · ${editing.skuCode}` : ''}`}
|
||||||
|
open={editIndex != null}
|
||||||
|
onCancel={() => setEditIndex(null)}
|
||||||
|
onOk={() => setEditIndex(null)}
|
||||||
|
okText="完成"
|
||||||
|
width={560}
|
||||||
|
destroyOnClose
|
||||||
|
>
|
||||||
|
{editing && editIndex != null ? (
|
||||||
|
<Space direction="vertical" size={14} style={{ width: '100%' }}>
|
||||||
|
<div>
|
||||||
|
<Typography.Text type="secondary">SKU</Typography.Text>
|
||||||
|
<div>{editing.skuCode || '保存后自动生成'}</div>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<Typography.Text>69 码 <Typography.Text type="danger">*</Typography.Text></Typography.Text>
|
||||||
|
<Input
|
||||||
|
placeholder="本规格独立 69 码"
|
||||||
|
value={editing.barcode69}
|
||||||
|
onChange={(e) => patchSku(editIndex, { barcode69: e.target.value })}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<Typography.Text>主图</Typography.Text>
|
||||||
|
<OssUpload
|
||||||
|
bizType="COVER"
|
||||||
|
value={editing.imageUrl || ''}
|
||||||
|
onChange={(url) => patchSku(editIndex, { imageUrl: url })}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<Space>
|
||||||
|
<div>
|
||||||
|
<Typography.Text>售价</Typography.Text>
|
||||||
|
<InputNumber
|
||||||
|
min={0}
|
||||||
|
style={{ width: 140 }}
|
||||||
|
value={editing.price}
|
||||||
|
onChange={(v) => patchSku(editIndex, { price: Number(v) || 0 })}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<Typography.Text>权益</Typography.Text>
|
||||||
|
<InputNumber
|
||||||
|
min={0}
|
||||||
|
style={{ width: 140 }}
|
||||||
|
value={editing.benefitAmount}
|
||||||
|
onChange={(v) => patchSku(editIndex, { benefitAmount: v == null ? undefined : Number(v) })}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</Space>
|
||||||
|
<div>
|
||||||
|
<Typography.Text>状态</Typography.Text>
|
||||||
|
<Select
|
||||||
|
style={{ width: '100%' }}
|
||||||
|
value={editing.status}
|
||||||
|
options={Object.entries(PRODUCT_STATUS_LABELS).map(([value, label]) => ({ value, label }))}
|
||||||
|
onChange={(status) => patchSku(editIndex, { status })}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<Space>
|
||||||
|
<Select
|
||||||
|
style={{ width: 100 }}
|
||||||
|
value={editing.saleUnit}
|
||||||
|
options={[
|
||||||
|
{ value: 'BOTTLE', label: '瓶' },
|
||||||
|
{ value: 'BOX', label: '箱' },
|
||||||
|
]}
|
||||||
|
onChange={(saleUnit) =>
|
||||||
|
patchSku(editIndex, {
|
||||||
|
saleUnit,
|
||||||
|
bottlesPerUnit: saleUnit === 'BOX' ? editing.bottlesPerUnit || 6 : 1,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
{editing.saleUnit === 'BOX' ? (
|
||||||
|
<InputNumber
|
||||||
|
min={1}
|
||||||
|
value={editing.bottlesPerUnit}
|
||||||
|
onChange={(v) => patchSku(editIndex, { bottlesPerUnit: Number(v) || 6 })}
|
||||||
|
/>
|
||||||
|
) : null}
|
||||||
|
</Space>
|
||||||
|
<Space>
|
||||||
|
<Switch
|
||||||
|
checkedChildren="线上"
|
||||||
|
unCheckedChildren="线上"
|
||||||
|
checked={editing.allowOnlinePurchase}
|
||||||
|
onChange={(checked) =>
|
||||||
|
patchSku(editIndex, {
|
||||||
|
allowOnlinePurchase: checked,
|
||||||
|
allowCrossCityDelivery: checked ? editing.allowCrossCityDelivery : false,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<Switch
|
||||||
|
checkedChildren="跨城"
|
||||||
|
unCheckedChildren="跨城"
|
||||||
|
disabled={!editing.allowOnlinePurchase}
|
||||||
|
checked={editing.allowCrossCityDelivery}
|
||||||
|
onChange={(checked) => patchSku(editIndex, { allowCrossCityDelivery: checked })}
|
||||||
|
/>
|
||||||
|
<Switch
|
||||||
|
checkedChildren="现场"
|
||||||
|
unCheckedChildren="现场"
|
||||||
|
checked={editing.allowOnSitePickup}
|
||||||
|
onChange={(checked) => patchSku(editIndex, { allowOnSitePickup: checked })}
|
||||||
|
/>
|
||||||
|
<Switch
|
||||||
|
checkedChildren="默认"
|
||||||
|
unCheckedChildren="默认"
|
||||||
|
checked={editing.isDefault}
|
||||||
|
onChange={(checked) => {
|
||||||
|
if (!checked) return;
|
||||||
|
setSkus((prev) => prev.map((s, i) => ({ ...s, isDefault: i === editIndex })));
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</Space>
|
||||||
|
</Space>
|
||||||
|
) : null}
|
||||||
|
</Modal>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,484 @@
|
|||||||
|
import { useEffect, useMemo, useRef, useState } from 'react';
|
||||||
|
import {
|
||||||
|
Alert,
|
||||||
|
Button,
|
||||||
|
Checkbox,
|
||||||
|
Form,
|
||||||
|
Input,
|
||||||
|
InputNumber,
|
||||||
|
Modal,
|
||||||
|
QRCode,
|
||||||
|
Radio,
|
||||||
|
Select,
|
||||||
|
Space,
|
||||||
|
Typography,
|
||||||
|
message,
|
||||||
|
} from 'antd';
|
||||||
|
import type {
|
||||||
|
HqProxyOrderCreateRequest,
|
||||||
|
PartnerProxyDeliveryMode,
|
||||||
|
PartnerProxyOrderOptions,
|
||||||
|
PartnerProxyOrderPreviewResult,
|
||||||
|
ProxyOrderCreateResponse,
|
||||||
|
ProxyOrderPayResponse,
|
||||||
|
} from '@dukang/shared-types';
|
||||||
|
import ChinaRegionCascader from './ChinaRegionCascader';
|
||||||
|
import { parseRegionCodes } from '../lib/china-region';
|
||||||
|
import { request } from '../lib/api';
|
||||||
|
|
||||||
|
type ProxyOrderModalProps = {
|
||||||
|
open: boolean;
|
||||||
|
onClose: () => void;
|
||||||
|
onSuccess: (order: { id: string; orderNo: string }) => void;
|
||||||
|
};
|
||||||
|
|
||||||
|
type PayStatus = {
|
||||||
|
id: string;
|
||||||
|
orderNo: string;
|
||||||
|
status: string;
|
||||||
|
payStatus: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
function fmtMoney(n: number) {
|
||||||
|
return n.toLocaleString('zh-CN', { minimumFractionDigits: 2, maximumFractionDigits: 2 });
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function ProxyOrderModal({ open, onClose, onSuccess }: ProxyOrderModalProps) {
|
||||||
|
const [options, setOptions] = useState<PartnerProxyOrderOptions | null>(null);
|
||||||
|
const [loadingOptions, setLoadingOptions] = useState(false);
|
||||||
|
const [phone, setPhone] = useState('');
|
||||||
|
const [receiverName, setReceiverName] = useState('');
|
||||||
|
const [regionCodes, setRegionCodes] = useState<string[]>([]);
|
||||||
|
const [addressDetail, setAddressDetail] = useState('');
|
||||||
|
const [productId, setProductId] = useState<string>();
|
||||||
|
const [skuId, setSkuId] = useState<string>();
|
||||||
|
const [quantity, setQuantity] = useState(2);
|
||||||
|
const [promoCodeId, setPromoCodeId] = useState<string>();
|
||||||
|
const [deliveryMode, setDeliveryMode] = useState<PartnerProxyDeliveryMode>('ADDRESS');
|
||||||
|
const [autoReceive, setAutoReceive] = useState(false);
|
||||||
|
const [preview, setPreview] = useState<PartnerProxyOrderPreviewResult | null>(null);
|
||||||
|
const [previewLoading, setPreviewLoading] = useState(false);
|
||||||
|
const [submitting, setSubmitting] = useState(false);
|
||||||
|
|
||||||
|
const [step, setStep] = useState<'form' | 'pay'>('form');
|
||||||
|
const [created, setCreated] = useState<ProxyOrderCreateResponse | null>(null);
|
||||||
|
const [codeUrl, setCodeUrl] = useState<string | null>(null);
|
||||||
|
const [payLoading, setPayLoading] = useState(false);
|
||||||
|
const pollRef = useRef<number | null>(null);
|
||||||
|
|
||||||
|
const region = useMemo(() => parseRegionCodes(regionCodes), [regionCodes]);
|
||||||
|
|
||||||
|
function stopPoll() {
|
||||||
|
if (pollRef.current != null) {
|
||||||
|
window.clearInterval(pollRef.current);
|
||||||
|
pollRef.current = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!open) return;
|
||||||
|
setLoadingOptions(true);
|
||||||
|
request<PartnerProxyOrderOptions>('/admin/proxy-orders/options')
|
||||||
|
.then((data) => {
|
||||||
|
setOptions(data);
|
||||||
|
if (data.products[0]) setProductId(data.products[0].id);
|
||||||
|
})
|
||||||
|
.catch((e) => message.error(e instanceof Error ? e.message : '加载失败'))
|
||||||
|
.finally(() => setLoadingOptions(false));
|
||||||
|
}, [open]);
|
||||||
|
|
||||||
|
const selectedProduct = options?.products.find((p) => p.id === productId);
|
||||||
|
const skuOptions = (selectedProduct?.skus ?? []).filter((s) => s.status === 'ON_SALE');
|
||||||
|
const selectedSku =
|
||||||
|
skuOptions.find((s) => s.id === skuId) ||
|
||||||
|
skuOptions.find((s) => s.id === selectedProduct?.defaultSkuId) ||
|
||||||
|
skuOptions[0];
|
||||||
|
const allowOnline = selectedSku
|
||||||
|
? selectedSku.allowOnlinePurchase !== false
|
||||||
|
: selectedProduct
|
||||||
|
? selectedProduct.allowOnlinePurchase !== false
|
||||||
|
: true;
|
||||||
|
const allowOnSite = selectedSku
|
||||||
|
? !!selectedSku.allowOnSitePickup
|
||||||
|
: !!selectedProduct?.allowOnSitePickup;
|
||||||
|
const allowCrossCity = selectedSku
|
||||||
|
? selectedSku.allowCrossCityDelivery !== false
|
||||||
|
: selectedProduct
|
||||||
|
? selectedProduct.allowCrossCityDelivery !== false
|
||||||
|
: true;
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!open || !selectedProduct) return;
|
||||||
|
const def =
|
||||||
|
skuOptions.find((s) => s.id === selectedProduct.defaultSkuId) ||
|
||||||
|
skuOptions.find((s) => s.isDefault) ||
|
||||||
|
skuOptions[0];
|
||||||
|
if (def && skuId !== def.id && (!skuId || !skuOptions.some((s) => s.id === skuId))) {
|
||||||
|
setSkuId(def.id);
|
||||||
|
setQuantity(def.saleUnit === 'BOX' ? 1 : Math.max(quantity, 2));
|
||||||
|
}
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
}, [open, productId, selectedProduct?.id]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!open || !selectedProduct) return;
|
||||||
|
if (!allowOnline && allowOnSite && deliveryMode !== 'ON_SITE_PICKUP') {
|
||||||
|
setDeliveryMode('ON_SITE_PICKUP');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (allowOnline && !allowOnSite && deliveryMode !== 'ADDRESS') {
|
||||||
|
setDeliveryMode('ADDRESS');
|
||||||
|
}
|
||||||
|
}, [open, selectedProduct, allowOnline, allowOnSite, deliveryMode]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!open || !productId || quantity < 1 || step !== 'form') {
|
||||||
|
if (step === 'form') setPreview(null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const timer = window.setTimeout(() => {
|
||||||
|
setPreviewLoading(true);
|
||||||
|
request<PartnerProxyOrderPreviewResult>('/admin/proxy-orders/preview', {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify({
|
||||||
|
productId,
|
||||||
|
quantity,
|
||||||
|
deliveryMode,
|
||||||
|
skuId: skuId || undefined,
|
||||||
|
receiverCity: deliveryMode === 'ADDRESS' ? region?.city || undefined : undefined,
|
||||||
|
receiverDistrict: deliveryMode === 'ADDRESS' ? region?.district || undefined : undefined,
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
.then(setPreview)
|
||||||
|
.catch(() => setPreview(null))
|
||||||
|
.finally(() => setPreviewLoading(false));
|
||||||
|
}, 300);
|
||||||
|
return () => window.clearTimeout(timer);
|
||||||
|
}, [open, productId, skuId, quantity, deliveryMode, region?.city, region?.district, step]);
|
||||||
|
|
||||||
|
useEffect(() => () => stopPoll(), []);
|
||||||
|
|
||||||
|
function resetForm() {
|
||||||
|
stopPoll();
|
||||||
|
setPhone('');
|
||||||
|
setReceiverName('');
|
||||||
|
setRegionCodes([]);
|
||||||
|
setAddressDetail('');
|
||||||
|
setQuantity(2);
|
||||||
|
setProductId(undefined);
|
||||||
|
setSkuId(undefined);
|
||||||
|
setPromoCodeId(undefined);
|
||||||
|
setDeliveryMode('ADDRESS');
|
||||||
|
setAutoReceive(false);
|
||||||
|
setPreview(null);
|
||||||
|
setProductId(options?.products[0]?.id);
|
||||||
|
setStep('form');
|
||||||
|
setCreated(null);
|
||||||
|
setCodeUrl(null);
|
||||||
|
setPayLoading(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleClose() {
|
||||||
|
resetForm();
|
||||||
|
onClose();
|
||||||
|
}
|
||||||
|
|
||||||
|
function validateForm(): string | null {
|
||||||
|
if (!/^1\d{10}$/.test(phone.trim())) return '请输入有效手机号';
|
||||||
|
if (!productId) return '请选择商品';
|
||||||
|
if (deliveryMode === 'ADDRESS') {
|
||||||
|
if (!allowOnline) return '该商品不支持线上购买';
|
||||||
|
if (!region?.province || !region?.city || !region?.district) return '请选择省市区';
|
||||||
|
if (!addressDetail.trim()) return '请填写详细地址';
|
||||||
|
if (!autoReceive) return '配送到址须勾选同意自动收货';
|
||||||
|
} else if (!allowOnSite) {
|
||||||
|
return '该商品不支持现场提货';
|
||||||
|
}
|
||||||
|
if (!preview) return '请等待费用计算完成';
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function startPoll(orderId: string) {
|
||||||
|
stopPoll();
|
||||||
|
pollRef.current = window.setInterval(() => {
|
||||||
|
void request<PayStatus>(`/admin/proxy-orders/${orderId}/pay-status`)
|
||||||
|
.then((st) => {
|
||||||
|
if (st.payStatus === 'PAID') {
|
||||||
|
stopPoll();
|
||||||
|
message.success(`支付成功:${st.orderNo}`);
|
||||||
|
const payload = { id: st.id, orderNo: st.orderNo };
|
||||||
|
resetForm();
|
||||||
|
onSuccess(payload);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(() => undefined);
|
||||||
|
}, 2000);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function submit() {
|
||||||
|
const err = validateForm();
|
||||||
|
if (err) {
|
||||||
|
message.warning(err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const payload: HqProxyOrderCreateRequest = {
|
||||||
|
phone: phone.trim(),
|
||||||
|
deliveryMode,
|
||||||
|
autoReceive: deliveryMode === 'ADDRESS' ? true : undefined,
|
||||||
|
receiverName: receiverName.trim() || undefined,
|
||||||
|
province: deliveryMode === 'ADDRESS' ? region?.province : undefined,
|
||||||
|
city: deliveryMode === 'ADDRESS' ? region?.city : undefined,
|
||||||
|
district: deliveryMode === 'ADDRESS' ? region?.district : undefined,
|
||||||
|
addressDetail: deliveryMode === 'ADDRESS' ? addressDetail.trim() : undefined,
|
||||||
|
productId: productId!,
|
||||||
|
quantity,
|
||||||
|
promoCodeId: promoCodeId || undefined,
|
||||||
|
skuId: skuId || undefined,
|
||||||
|
};
|
||||||
|
|
||||||
|
setSubmitting(true);
|
||||||
|
try {
|
||||||
|
const order = await request<ProxyOrderCreateResponse>('/admin/proxy-orders', {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify(payload),
|
||||||
|
});
|
||||||
|
setCreated(order);
|
||||||
|
setStep('pay');
|
||||||
|
setPayLoading(true);
|
||||||
|
const pay = await request<ProxyOrderPayResponse>(`/admin/proxy-orders/${order.id}/pay`, {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify({ payMethod: 'NATIVE' }),
|
||||||
|
});
|
||||||
|
if (pay.mode === 'mock') {
|
||||||
|
message.success(`支付成功:${order.orderNo}`);
|
||||||
|
resetForm();
|
||||||
|
onSuccess({ id: order.id, orderNo: order.orderNo });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setCodeUrl(pay.codeUrl ?? null);
|
||||||
|
startPoll(order.id);
|
||||||
|
} catch (e) {
|
||||||
|
message.error(e instanceof Error ? e.message : '下单失败');
|
||||||
|
setStep('form');
|
||||||
|
setCreated(null);
|
||||||
|
} finally {
|
||||||
|
setSubmitting(false);
|
||||||
|
setPayLoading(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const deliveryLabel =
|
||||||
|
preview?.deliveryType === 'ON_SITE_PICKUP'
|
||||||
|
? '现场提货'
|
||||||
|
: preview?.deliveryType === 'CROSS_CITY'
|
||||||
|
? '跨城配送'
|
||||||
|
: '同城配送';
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Modal
|
||||||
|
title={step === 'pay' ? '代下单 · 待支付' : '代下单'}
|
||||||
|
open={open}
|
||||||
|
onCancel={handleClose}
|
||||||
|
width={640}
|
||||||
|
destroyOnClose
|
||||||
|
footer={
|
||||||
|
step === 'pay' ? (
|
||||||
|
<Space>
|
||||||
|
<Button onClick={handleClose}>关闭</Button>
|
||||||
|
</Space>
|
||||||
|
) : (
|
||||||
|
<Space>
|
||||||
|
<Button onClick={handleClose}>取消</Button>
|
||||||
|
<Button type="primary" loading={submitting || loadingOptions} onClick={() => void submit()}>
|
||||||
|
提交并收款
|
||||||
|
</Button>
|
||||||
|
</Space>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{step === 'pay' && created ? (
|
||||||
|
<div style={{ textAlign: 'center' }}>
|
||||||
|
<Alert
|
||||||
|
type="info"
|
||||||
|
showIcon
|
||||||
|
style={{ marginBottom: 16, textAlign: 'left' }}
|
||||||
|
message={`订单 ${created.orderNo} 待支付 ¥${fmtMoney(created.payAmount)},请扫码支付`}
|
||||||
|
description={
|
||||||
|
created.deliveryType === 'ON_SITE_PICKUP'
|
||||||
|
? '支付完成后订单即为已完成,并发放好客权益'
|
||||||
|
: '支付完成后将进入待发货,由总部履约发货'
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
{payLoading && !codeUrl ? (
|
||||||
|
<Typography.Text type="secondary">正在生成收款码…</Typography.Text>
|
||||||
|
) : codeUrl ? (
|
||||||
|
<Space direction="vertical" size={12} align="center">
|
||||||
|
<QRCode value={codeUrl} size={200} />
|
||||||
|
<Typography.Text type="secondary">请使用微信扫一扫完成支付,成功后自动关闭</Typography.Text>
|
||||||
|
<Typography.Text type="secondary" style={{ fontSize: 12, wordBreak: 'break-all' }}>
|
||||||
|
{codeUrl}
|
||||||
|
</Typography.Text>
|
||||||
|
</Space>
|
||||||
|
) : (
|
||||||
|
<Typography.Text type="danger">收款码生成失败,请关闭后重试</Typography.Text>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<Alert
|
||||||
|
type="info"
|
||||||
|
showIcon
|
||||||
|
style={{ marginBottom: 16 }}
|
||||||
|
message="提交后生成微信收款码,支付成功后发放好客权益;配送单进入待发货"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Form layout="vertical">
|
||||||
|
<Form.Item label="用户手机号" required>
|
||||||
|
<Input
|
||||||
|
placeholder="11 位手机号"
|
||||||
|
value={phone}
|
||||||
|
maxLength={11}
|
||||||
|
onChange={(e) => setPhone(e.target.value.replace(/\D/g, '').slice(0, 11))}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
|
||||||
|
<Form.Item label="酒品" required>
|
||||||
|
<Select
|
||||||
|
showSearch
|
||||||
|
optionFilterProp="label"
|
||||||
|
loading={loadingOptions}
|
||||||
|
placeholder="选择商品"
|
||||||
|
value={productId}
|
||||||
|
onChange={(id) => {
|
||||||
|
setProductId(id);
|
||||||
|
setSkuId(undefined);
|
||||||
|
}}
|
||||||
|
options={(options?.products ?? []).map((p) => ({
|
||||||
|
value: p.id,
|
||||||
|
label: `${p.name} · ${p.spec} · ¥${fmtMoney(p.price)}`,
|
||||||
|
}))}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
|
||||||
|
{skuOptions.length > 1 || selectedProduct?.specEnabled ? (
|
||||||
|
<Form.Item label="规格" required>
|
||||||
|
<Select
|
||||||
|
placeholder="选择规格"
|
||||||
|
value={skuId}
|
||||||
|
onChange={(id) => {
|
||||||
|
setSkuId(id);
|
||||||
|
const sku = skuOptions.find((s) => s.id === id);
|
||||||
|
if (sku?.saleUnit === 'BOX') setQuantity(1);
|
||||||
|
}}
|
||||||
|
options={skuOptions.map((s) => ({
|
||||||
|
value: s.id,
|
||||||
|
label: `${s.specText || '默认'} · ¥${fmtMoney(s.price)} · ${s.saleUnit === 'BOX' ? `${s.bottlesPerUnit}瓶/箱` : '瓶'}`,
|
||||||
|
}))}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
) : null}
|
||||||
|
|
||||||
|
<Form.Item label={selectedSku?.saleUnit === 'BOX' ? '数量(箱)' : '数量(瓶)'} required>
|
||||||
|
<InputNumber
|
||||||
|
min={1}
|
||||||
|
value={quantity}
|
||||||
|
onChange={(v) => setQuantity(Math.max(1, Number(v) || 1))}
|
||||||
|
style={{ width: '100%' }}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
|
||||||
|
{(options?.promoCodes.length ?? 0) > 0 ? (
|
||||||
|
<Form.Item label="绑定推广码(选填)">
|
||||||
|
<Select
|
||||||
|
allowClear
|
||||||
|
placeholder="不绑定"
|
||||||
|
value={promoCodeId}
|
||||||
|
onChange={setPromoCodeId}
|
||||||
|
options={(options?.promoCodes ?? []).map((p) => ({
|
||||||
|
value: p.id,
|
||||||
|
label: `${p.code} · ${p.name}`,
|
||||||
|
}))}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
) : null}
|
||||||
|
|
||||||
|
<Form.Item label="履约方式" required>
|
||||||
|
{allowOnline && allowOnSite ? (
|
||||||
|
<Radio.Group
|
||||||
|
value={deliveryMode}
|
||||||
|
onChange={(e) => {
|
||||||
|
setDeliveryMode(e.target.value);
|
||||||
|
if (e.target.value !== 'ADDRESS') setAutoReceive(false);
|
||||||
|
}}
|
||||||
|
options={[
|
||||||
|
{ value: 'ADDRESS', label: '配送到址' },
|
||||||
|
{ value: 'ON_SITE_PICKUP', label: '现场提货' },
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<Typography.Text type="secondary">
|
||||||
|
{!allowOnline && allowOnSite
|
||||||
|
? '该商品仅支持现场提货'
|
||||||
|
: allowOnline && !allowOnSite
|
||||||
|
? allowCrossCity
|
||||||
|
? '该商品仅支持配送到址(含跨城)'
|
||||||
|
: '该商品仅支持配送到址(不可跨城)'
|
||||||
|
: '该商品暂无可选履约方式'}
|
||||||
|
</Typography.Text>
|
||||||
|
)}
|
||||||
|
</Form.Item>
|
||||||
|
|
||||||
|
{deliveryMode === 'ADDRESS' && allowOnline ? (
|
||||||
|
<>
|
||||||
|
<Form.Item label="收货人(选填)">
|
||||||
|
<Input
|
||||||
|
placeholder="默认:用户+手机尾号"
|
||||||
|
value={receiverName}
|
||||||
|
maxLength={32}
|
||||||
|
onChange={(e) => setReceiverName(e.target.value)}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item label="省市区" required>
|
||||||
|
<ChinaRegionCascader value={regionCodes} onChange={setRegionCodes} />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item label="详细地址" required>
|
||||||
|
<Input.TextArea
|
||||||
|
rows={2}
|
||||||
|
placeholder="街道门牌等"
|
||||||
|
value={addressDetail}
|
||||||
|
maxLength={256}
|
||||||
|
onChange={(e) => setAddressDetail(e.target.value)}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item>
|
||||||
|
<Checkbox checked={autoReceive} onChange={(e) => setAutoReceive(e.target.checked)}>
|
||||||
|
同意自动收货(配送到址必选)
|
||||||
|
</Checkbox>
|
||||||
|
</Form.Item>
|
||||||
|
</>
|
||||||
|
) : null}
|
||||||
|
|
||||||
|
<div style={{ background: '#fafafa', borderRadius: 8, padding: 12 }}>
|
||||||
|
<Typography.Text type="secondary">费用预览</Typography.Text>
|
||||||
|
{previewLoading ? (
|
||||||
|
<div>计算中…</div>
|
||||||
|
) : preview ? (
|
||||||
|
<Space direction="vertical" size={2} style={{ width: '100%', marginTop: 8 }}>
|
||||||
|
<div>履约:{deliveryLabel}</div>
|
||||||
|
<div>商品金额:¥{fmtMoney(preview.productAmount)}</div>
|
||||||
|
<div>实付:¥{fmtMoney(preview.payAmount)}</div>
|
||||||
|
<div>好客权益:¥{fmtMoney(preview.benefitAmount)}</div>
|
||||||
|
</Space>
|
||||||
|
) : (
|
||||||
|
<div style={{ marginTop: 8 }}>
|
||||||
|
<Typography.Text type="secondary">请完善商品与数量</Typography.Text>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</Form>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</Modal>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,84 @@
|
|||||||
|
import { Descriptions } from 'antd';
|
||||||
|
import { REDEEM_CHANNEL_LABELS, type RedeemChannel } from '@dukang/shared-types';
|
||||||
|
import { fmtTime } from '../lib/constants';
|
||||||
|
|
||||||
|
function maskPhone(phone: string | null | undefined) {
|
||||||
|
if (!phone || phone.length < 7) return phone ?? '—';
|
||||||
|
return `${phone.slice(0, 3)}****${phone.slice(-4)}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
detail: Record<string, unknown>;
|
||||||
|
/** 列表页已脱敏展示时可设为 false,详情抽屉展示完整手机号 */
|
||||||
|
maskUserPhone?: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function RedeemRecordDetailDescriptions({ detail, maskUserPhone = false }: Props) {
|
||||||
|
const user = detail.user as
|
||||||
|
| { userNo?: string; nickname?: string | null; phone?: string | null }
|
||||||
|
| undefined;
|
||||||
|
const store = detail.store as
|
||||||
|
| {
|
||||||
|
name?: string;
|
||||||
|
cityName?: string;
|
||||||
|
address?: string;
|
||||||
|
partnerAccount?: { companyName?: string };
|
||||||
|
}
|
||||||
|
| undefined;
|
||||||
|
const coupon = detail.coupon as { couponNo?: string; order?: { orderNo?: string } } | undefined;
|
||||||
|
const channel = detail.channel === 'PHONE' ? 'PHONE' : 'SCAN';
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Descriptions column={1} bordered size="small">
|
||||||
|
<Descriptions.Item label="核销号">{String(detail.redeemNo ?? '—')}</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="方式">{REDEEM_CHANNEL_LABELS[channel as RedeemChannel]}</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="核销额">¥{Number(detail.amount ?? 0).toFixed(2)}</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="结算额">¥{Number(detail.settleAmount ?? 0).toFixed(2)}</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="时间">{fmtTime(String(detail.createdAt ?? ''))}</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="用户编号">{user?.userNo ?? '—'}</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="用户昵称">{user?.nickname?.trim() || '—'}</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="用户手机">
|
||||||
|
{maskUserPhone ? maskPhone(user?.phone) : user?.phone || '—'}
|
||||||
|
</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="门店">
|
||||||
|
{store?.name ?? '—'}
|
||||||
|
{store?.cityName ? `(${store.cityName})` : ''}
|
||||||
|
</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="门店地址">{store?.address ?? '—'}</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="合伙人">{store?.partnerAccount?.companyName ?? '—'}</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="权益券号">{coupon?.couponNo ?? '—'}</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="关联订单">{coupon?.order?.orderNo ?? '—'}</Descriptions.Item>
|
||||||
|
{Array.isArray(detail.allocations) && (detail.allocations as unknown[]).length > 0 ? (
|
||||||
|
<Descriptions.Item label="券分摊">
|
||||||
|
{(
|
||||||
|
detail.allocations as Array<{
|
||||||
|
couponNo?: string;
|
||||||
|
orderNo?: string | null;
|
||||||
|
amount?: number;
|
||||||
|
}>
|
||||||
|
)
|
||||||
|
.map((a, idx) => {
|
||||||
|
const role = idx === 0 ? '主' : '次';
|
||||||
|
return `${role} ${a.couponNo ?? '—'}¥${Number(a.amount ?? 0).toFixed(2)}${
|
||||||
|
a.orderNo ? `(订单 ${a.orderNo})` : ''
|
||||||
|
}`;
|
||||||
|
})
|
||||||
|
.join(';')}
|
||||||
|
</Descriptions.Item>
|
||||||
|
) : null}
|
||||||
|
{detail.payout ? (
|
||||||
|
<Descriptions.Item label="门店结算单">
|
||||||
|
¥{Number((detail.payout as { settleAmount?: number }).settleAmount ?? 0).toFixed(2)}
|
||||||
|
{' / '}
|
||||||
|
{String((detail.payout as { status?: string }).status ?? '—')}
|
||||||
|
</Descriptions.Item>
|
||||||
|
) : null}
|
||||||
|
{detail.rating ? (
|
||||||
|
<Descriptions.Item label="评价">
|
||||||
|
服务 {(detail.rating as { serviceScore?: number }).serviceScore ?? '—'} 分 / 环境{' '}
|
||||||
|
{(detail.rating as { envScore?: number }).envScore ?? '—'} 分
|
||||||
|
</Descriptions.Item>
|
||||||
|
) : null}
|
||||||
|
</Descriptions>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,453 @@
|
|||||||
|
import { useEffect, useState } from 'react';
|
||||||
|
import { Button, Image, Input, Modal, Space, Tag, Typography, message } from 'antd';
|
||||||
|
import type {
|
||||||
|
StorePackageAuditDetailDto,
|
||||||
|
StorePackageItemDto,
|
||||||
|
StorePackageViewDto,
|
||||||
|
} from '@dukang/shared-types';
|
||||||
|
import { normalizeStorePackageImageUrls } from '@dukang/shared-types';
|
||||||
|
import { request } from '../lib/api';
|
||||||
|
import { notifyPackageAuditChanged } from '../lib/admin-events';
|
||||||
|
import { fmtTime } from '../lib/constants';
|
||||||
|
|
||||||
|
const HQ_PACKAGE_STATUS_LABELS: Record<string, string> = {
|
||||||
|
PENDING: '待审核',
|
||||||
|
APPROVED: '已通过',
|
||||||
|
REJECTED: '已驳回',
|
||||||
|
};
|
||||||
|
|
||||||
|
function packageKey(pkg: StorePackageItemDto | StorePackageViewDto, index: number) {
|
||||||
|
const name = String(pkg.name ?? '').trim();
|
||||||
|
return name ? `name:${name}` : `idx:${index}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function imageSignature(pkg: StorePackageItemDto | StorePackageViewDto) {
|
||||||
|
return normalizeStorePackageImageUrls(pkg).join('|');
|
||||||
|
}
|
||||||
|
|
||||||
|
type FieldChange = { label: string; old: string; now: string; kind: 'text' | 'value' };
|
||||||
|
|
||||||
|
function diffText(a: string, b: string): Array<{ type: 'equal' | 'insert' | 'delete'; text: string }> {
|
||||||
|
const m = a.length;
|
||||||
|
const n = b.length;
|
||||||
|
const dp: number[][] = Array.from({ length: m + 1 }, () => new Array(n + 1).fill(0));
|
||||||
|
for (let i = m - 1; i >= 0; i--) {
|
||||||
|
for (let j = n - 1; j >= 0; j--) {
|
||||||
|
dp[i][j] = a[i] === b[j] ? dp[i + 1][j + 1] + 1 : Math.max(dp[i + 1][j], dp[i][j + 1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const raw: Array<{ type: 'equal' | 'insert' | 'delete'; text: string }> = [];
|
||||||
|
let i = 0;
|
||||||
|
let j = 0;
|
||||||
|
while (i < m && j < n) {
|
||||||
|
if (a[i] === b[j]) {
|
||||||
|
raw.push({ type: 'equal', text: a[i] });
|
||||||
|
i++;
|
||||||
|
j++;
|
||||||
|
} else if (dp[i + 1][j] >= dp[i][j + 1]) {
|
||||||
|
raw.push({ type: 'delete', text: a[i] });
|
||||||
|
i++;
|
||||||
|
} else {
|
||||||
|
raw.push({ type: 'insert', text: b[j] });
|
||||||
|
j++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while (i < m) raw.push({ type: 'delete', text: a[i++] });
|
||||||
|
while (j < n) raw.push({ type: 'insert', text: b[j++] });
|
||||||
|
const merged: Array<{ type: 'equal' | 'insert' | 'delete'; text: string }> = [];
|
||||||
|
for (const s of raw) {
|
||||||
|
const last = merged[merged.length - 1];
|
||||||
|
if (last && last.type === s.type) last.text += s.text;
|
||||||
|
else merged.push({ ...s });
|
||||||
|
}
|
||||||
|
return merged;
|
||||||
|
}
|
||||||
|
|
||||||
|
function fieldChanges(
|
||||||
|
live: StorePackageItemDto | StorePackageViewDto,
|
||||||
|
proposed: StorePackageItemDto | StorePackageViewDto,
|
||||||
|
): FieldChange[] {
|
||||||
|
const changes: FieldChange[] = [];
|
||||||
|
const text = (v: string | number | null | undefined) => (v ?? '').toString().trim();
|
||||||
|
const pushText = (label: string, oldV: string, newV: string) => {
|
||||||
|
if (oldV !== newV) changes.push({ label, old: oldV, now: newV, kind: 'text' });
|
||||||
|
};
|
||||||
|
const pushValue = (label: string, oldV: string, newV: string) => {
|
||||||
|
if (oldV !== newV) changes.push({ label, old: oldV || '(空)', now: newV || '(空)', kind: 'value' });
|
||||||
|
};
|
||||||
|
pushValue('价格', `¥${text(live.price)}`, `¥${text(proposed.price)}`);
|
||||||
|
pushText('套餐名称', text(live.name), text(proposed.name));
|
||||||
|
pushText('菜品内容', text(live.dishes), text(proposed.dishes));
|
||||||
|
pushText('可用时间', text(live.usableTime), text(proposed.usableTime));
|
||||||
|
pushText('其他说明', text(live.otherNotes), text(proposed.otherNotes));
|
||||||
|
const liveImgs = normalizeStorePackageImageUrls(live);
|
||||||
|
const proposedImgs = normalizeStorePackageImageUrls(proposed);
|
||||||
|
if (imageSignature(live) !== imageSignature(proposed)) {
|
||||||
|
changes.push({ label: '图片', old: `${liveImgs.length} 张`, now: `${proposedImgs.length} 张`, kind: 'value' });
|
||||||
|
}
|
||||||
|
return changes;
|
||||||
|
}
|
||||||
|
|
||||||
|
function diffPackages(live: StorePackageViewDto[], proposed: StorePackageItemDto[]) {
|
||||||
|
const liveMap = new Map(live.map((p, i) => [packageKey(p, i), p]));
|
||||||
|
const proposedMap = new Map(proposed.map((p, i) => [packageKey(p, i), p]));
|
||||||
|
const keys = new Set([...liveMap.keys(), ...proposedMap.keys()]);
|
||||||
|
const rows: Array<{
|
||||||
|
key: string;
|
||||||
|
change: 'added' | 'removed' | 'changed' | 'unchanged';
|
||||||
|
live?: StorePackageViewDto;
|
||||||
|
proposed?: StorePackageItemDto;
|
||||||
|
changes?: FieldChange[];
|
||||||
|
}> = [];
|
||||||
|
|
||||||
|
for (const key of keys) {
|
||||||
|
const l = liveMap.get(key);
|
||||||
|
const p = proposedMap.get(key);
|
||||||
|
if (l && !p) {
|
||||||
|
rows.push({ key, change: 'removed', live: l });
|
||||||
|
} else if (!l && p) {
|
||||||
|
rows.push({ key, change: 'added', proposed: p });
|
||||||
|
} else if (l && p) {
|
||||||
|
const changed =
|
||||||
|
l.price !== p.price ||
|
||||||
|
l.dishes !== p.dishes ||
|
||||||
|
(l.usableTime ?? '') !== (p.usableTime ?? '') ||
|
||||||
|
(l.otherNotes ?? '') !== (p.otherNotes ?? '') ||
|
||||||
|
imageSignature(l) !== imageSignature(p);
|
||||||
|
rows.push({
|
||||||
|
key,
|
||||||
|
change: changed ? 'changed' : 'unchanged',
|
||||||
|
live: l,
|
||||||
|
proposed: p,
|
||||||
|
changes: changed ? fieldChanges(l, p) : undefined,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return rows;
|
||||||
|
}
|
||||||
|
|
||||||
|
const CHANGE_LABELS = {
|
||||||
|
added: { text: '新增', color: 'green' },
|
||||||
|
removed: { text: '删除', color: 'red' },
|
||||||
|
changed: { text: '变更', color: 'orange' },
|
||||||
|
unchanged: { text: '未变', color: 'default' },
|
||||||
|
} as const;
|
||||||
|
|
||||||
|
function TextDiff({ oldText, newText }: { oldText: string; newText: string }) {
|
||||||
|
const segs = diffText(oldText, newText);
|
||||||
|
return (
|
||||||
|
<div style={{ marginTop: 2 }}>
|
||||||
|
<div style={{ lineHeight: 1.6 }}>
|
||||||
|
<Typography.Text type="secondary">原:</Typography.Text>
|
||||||
|
{segs
|
||||||
|
.filter((s) => s.type !== 'insert')
|
||||||
|
.map((s, idx) =>
|
||||||
|
s.type === 'delete' ? (
|
||||||
|
<Typography.Text key={idx} delete style={{ color: '#cf1322' }}>
|
||||||
|
{s.text || '(空)'}
|
||||||
|
</Typography.Text>
|
||||||
|
) : (
|
||||||
|
<Typography.Text key={idx}>{s.text}</Typography.Text>
|
||||||
|
),
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div style={{ lineHeight: 1.6 }}>
|
||||||
|
<Typography.Text type="secondary">新:</Typography.Text>
|
||||||
|
{segs
|
||||||
|
.filter((s) => s.type !== 'delete')
|
||||||
|
.map((s, idx) =>
|
||||||
|
s.type === 'insert' ? (
|
||||||
|
<Typography.Text key={idx} style={{ color: '#389e0d' }}>
|
||||||
|
{s.text || '(空)'}
|
||||||
|
</Typography.Text>
|
||||||
|
) : (
|
||||||
|
<Typography.Text key={idx}>{s.text}</Typography.Text>
|
||||||
|
),
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function PackageDetailCard({
|
||||||
|
title,
|
||||||
|
pkg,
|
||||||
|
change,
|
||||||
|
changes,
|
||||||
|
}: {
|
||||||
|
title?: string;
|
||||||
|
pkg: StorePackageItemDto | StorePackageViewDto;
|
||||||
|
change?: keyof typeof CHANGE_LABELS;
|
||||||
|
changes?: FieldChange[];
|
||||||
|
}) {
|
||||||
|
const images = normalizeStorePackageImageUrls(pkg);
|
||||||
|
const meta = change ? CHANGE_LABELS[change] : null;
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
marginBottom: 12,
|
||||||
|
padding: 12,
|
||||||
|
border: '1px solid #f0f0f0',
|
||||||
|
borderRadius: 8,
|
||||||
|
background: '#fafafa',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Space style={{ marginBottom: 8 }} wrap>
|
||||||
|
{title ? <Typography.Text type="secondary">{title}</Typography.Text> : null}
|
||||||
|
{meta ? <Tag color={meta.color}>{meta.text}</Tag> : null}
|
||||||
|
</Space>
|
||||||
|
<div style={{ marginBottom: 8 }}>
|
||||||
|
<strong>{pkg.name}</strong>
|
||||||
|
<span style={{ marginLeft: 8 }}>¥{pkg.price}</span>
|
||||||
|
</div>
|
||||||
|
<Typography.Paragraph className="admin-package-audit-text" style={{ marginBottom: 8 }}>
|
||||||
|
{pkg.dishes || '—'}
|
||||||
|
</Typography.Paragraph>
|
||||||
|
{pkg.usableTime ? (
|
||||||
|
<Typography.Paragraph type="secondary" className="admin-package-audit-text" style={{ marginBottom: 4 }}>
|
||||||
|
可用时间:{pkg.usableTime}
|
||||||
|
</Typography.Paragraph>
|
||||||
|
) : null}
|
||||||
|
{pkg.otherNotes ? (
|
||||||
|
<Typography.Paragraph type="secondary" className="admin-package-audit-text" style={{ marginBottom: 8 }}>
|
||||||
|
其他说明:{pkg.otherNotes}
|
||||||
|
</Typography.Paragraph>
|
||||||
|
) : null}
|
||||||
|
{images.length ? (
|
||||||
|
<Image.PreviewGroup>
|
||||||
|
<Space wrap size={8}>
|
||||||
|
{images.map((url) => (
|
||||||
|
<Image key={url} src={url} width={72} height={72} style={{ objectFit: 'cover', borderRadius: 4 }} />
|
||||||
|
))}
|
||||||
|
</Space>
|
||||||
|
</Image.PreviewGroup>
|
||||||
|
) : (
|
||||||
|
<Typography.Text type="secondary">无套餐图片</Typography.Text>
|
||||||
|
)}
|
||||||
|
{changes && changes.length ? (
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
marginTop: 8,
|
||||||
|
padding: 8,
|
||||||
|
background: '#fff7e6',
|
||||||
|
border: '1px solid #ffe7ba',
|
||||||
|
borderRadius: 6,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Typography.Text strong style={{ fontSize: 12 }}>
|
||||||
|
变更明细
|
||||||
|
</Typography.Text>
|
||||||
|
<ul style={{ margin: '6px 0 0', paddingLeft: 18 }}>
|
||||||
|
{changes.map((c) => (
|
||||||
|
<li key={c.label} style={{ marginBottom: 6 }}>
|
||||||
|
<Typography.Text type="secondary">{c.label}:</Typography.Text>
|
||||||
|
{c.kind === 'text' ? (
|
||||||
|
<TextDiff oldText={c.old} newText={c.now} />
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<Typography.Text delete type="secondary">
|
||||||
|
{c.old}
|
||||||
|
</Typography.Text>
|
||||||
|
<Typography.Text type="secondary"> → </Typography.Text>
|
||||||
|
<Typography.Text strong>{c.now}</Typography.Text>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export type StorePackageAuditPanelProps = {
|
||||||
|
requestId: string;
|
||||||
|
/** 是否在面板顶部显示通过/驳回(抽屉 extra 另有按钮时可关) */
|
||||||
|
showActions?: boolean;
|
||||||
|
onAudited?: () => void;
|
||||||
|
onDetailLoaded?: (detail: StorePackageAuditDetailDto | null) => void;
|
||||||
|
};
|
||||||
|
|
||||||
|
/** 套餐变更对比 + 通过/驳回(审核通知页与门店详情抽屉共用) */
|
||||||
|
export default function StorePackageAuditPanel({
|
||||||
|
requestId,
|
||||||
|
showActions = true,
|
||||||
|
onAudited,
|
||||||
|
onDetailLoaded,
|
||||||
|
}: StorePackageAuditPanelProps) {
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
const [detail, setDetail] = useState<StorePackageAuditDetailDto | null>(null);
|
||||||
|
const [rejectOpen, setRejectOpen] = useState(false);
|
||||||
|
const [rejectReason, setRejectReason] = useState('');
|
||||||
|
const [auditing, setAuditing] = useState(false);
|
||||||
|
|
||||||
|
async function load() {
|
||||||
|
setLoading(true);
|
||||||
|
try {
|
||||||
|
const data = await request<StorePackageAuditDetailDto>(`/admin/store-package-audits/${requestId}`);
|
||||||
|
setDetail(data);
|
||||||
|
onDetailLoaded?.(data);
|
||||||
|
} catch (e) {
|
||||||
|
message.error(e instanceof Error ? e.message : '加载套餐审核详情失败');
|
||||||
|
setDetail(null);
|
||||||
|
onDetailLoaded?.(null);
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
void load();
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
}, [requestId]);
|
||||||
|
|
||||||
|
async function audit(action: 'APPROVE' | 'REJECT', reason?: string) {
|
||||||
|
if (!detail) return;
|
||||||
|
setAuditing(true);
|
||||||
|
try {
|
||||||
|
await request(`/admin/store-package-audits/${detail.id}/audit`, {
|
||||||
|
method: 'PUT',
|
||||||
|
body: JSON.stringify(action === 'REJECT' ? { action, rejectReason: reason } : { action }),
|
||||||
|
});
|
||||||
|
message.success(action === 'APPROVE' ? '套餐已通过' : '套餐已驳回');
|
||||||
|
notifyPackageAuditChanged();
|
||||||
|
onAudited?.();
|
||||||
|
await load();
|
||||||
|
} catch (e) {
|
||||||
|
message.error(e instanceof Error ? e.message : '操作失败');
|
||||||
|
} finally {
|
||||||
|
setAuditing(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (loading && !detail) {
|
||||||
|
return <Typography.Text type="secondary">加载套餐变更…</Typography.Text>;
|
||||||
|
}
|
||||||
|
if (!detail) {
|
||||||
|
return <Typography.Text type="secondary">暂无套餐审核详情</Typography.Text>;
|
||||||
|
}
|
||||||
|
|
||||||
|
const diffRows = diffPackages(detail.livePackages ?? [], detail.packages ?? []);
|
||||||
|
const changeByKey = new Map(diffRows.map((row) => [row.key, row.change]));
|
||||||
|
const changesByKey = new Map(diffRows.map((row) => [row.key, row.changes]));
|
||||||
|
const addedCount = diffRows.filter((r) => r.change === 'added').length;
|
||||||
|
const removedCount = diffRows.filter((r) => r.change === 'removed').length;
|
||||||
|
const changedCount = diffRows.filter((r) => r.change === 'changed').length;
|
||||||
|
const unchangedCount = diffRows.filter((r) => r.change === 'unchanged').length;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<Space style={{ marginBottom: 12, width: '100%', justifyContent: 'space-between' }} wrap>
|
||||||
|
<Space wrap>
|
||||||
|
<Tag>{HQ_PACKAGE_STATUS_LABELS[detail.status] ?? detail.status}</Tag>
|
||||||
|
<Typography.Text type="secondary">
|
||||||
|
提交方:{detail.submitterType === 'PARTNER' ? '合伙人' : '门店'} · {fmtTime(detail.createdAt)}
|
||||||
|
</Typography.Text>
|
||||||
|
</Space>
|
||||||
|
{showActions && detail.status === 'PENDING' ? (
|
||||||
|
<Space>
|
||||||
|
<Button type="primary" loading={auditing} onClick={() => void audit('APPROVE')}>
|
||||||
|
通过套餐
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
danger
|
||||||
|
loading={auditing}
|
||||||
|
onClick={() => {
|
||||||
|
setRejectReason('');
|
||||||
|
setRejectOpen(true);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
驳回套餐
|
||||||
|
</Button>
|
||||||
|
</Space>
|
||||||
|
) : null}
|
||||||
|
</Space>
|
||||||
|
{detail.rejectReason ? (
|
||||||
|
<Typography.Paragraph type="danger">驳回原因:{detail.rejectReason}</Typography.Paragraph>
|
||||||
|
) : null}
|
||||||
|
<Space direction="vertical" size={4} style={{ marginBottom: 12 }}>
|
||||||
|
<Typography.Text type="secondary">
|
||||||
|
线上已审核 {detail.livePackages?.length ?? 0} 条 · 待审核 {detail.packages?.length ?? 0} 条
|
||||||
|
</Typography.Text>
|
||||||
|
<Space wrap>
|
||||||
|
<Tag color="green">新增 {addedCount}</Tag>
|
||||||
|
<Tag color="red">删除 {removedCount}</Tag>
|
||||||
|
<Tag color="orange">变更 {changedCount}</Tag>
|
||||||
|
{unchangedCount ? <Tag>未变 {unchangedCount}</Tag> : null}
|
||||||
|
</Space>
|
||||||
|
</Space>
|
||||||
|
<div className="admin-package-audit-cols">
|
||||||
|
<div className="admin-package-audit-col">
|
||||||
|
<Typography.Title level={5} style={{ marginTop: 0 }}>
|
||||||
|
线上已审核套餐
|
||||||
|
</Typography.Title>
|
||||||
|
{(detail.livePackages ?? []).length ? (
|
||||||
|
(detail.livePackages ?? []).map((pkg, index) => (
|
||||||
|
<PackageDetailCard
|
||||||
|
key={`live-${packageKey(pkg, index)}`}
|
||||||
|
title={`套餐 ${index + 1}`}
|
||||||
|
pkg={pkg}
|
||||||
|
change={changeByKey.get(packageKey(pkg, index))}
|
||||||
|
/>
|
||||||
|
))
|
||||||
|
) : (
|
||||||
|
<Typography.Text type="secondary">暂无线上套餐</Typography.Text>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div className="admin-package-audit-col">
|
||||||
|
<Typography.Title level={5} style={{ marginTop: 0 }}>
|
||||||
|
待审核套餐
|
||||||
|
</Typography.Title>
|
||||||
|
{(detail.packages ?? []).length ? (
|
||||||
|
(detail.packages ?? []).map((pkg, index) => (
|
||||||
|
<PackageDetailCard
|
||||||
|
key={`pending-${packageKey(pkg, index)}`}
|
||||||
|
title={`套餐 ${index + 1}`}
|
||||||
|
pkg={pkg}
|
||||||
|
change={changeByKey.get(packageKey(pkg, index))}
|
||||||
|
changes={changesByKey.get(packageKey(pkg, index))}
|
||||||
|
/>
|
||||||
|
))
|
||||||
|
) : (
|
||||||
|
<Typography.Text type="secondary">暂无待审核套餐</Typography.Text>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<Modal
|
||||||
|
title="驳回套餐变更"
|
||||||
|
open={rejectOpen}
|
||||||
|
confirmLoading={auditing}
|
||||||
|
onCancel={() => setRejectOpen(false)}
|
||||||
|
onOk={() => {
|
||||||
|
if (!rejectReason.trim()) {
|
||||||
|
message.warning('请填写驳回原因');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
void audit('REJECT', rejectReason.trim()).then(() => setRejectOpen(false));
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Input.TextArea
|
||||||
|
rows={3}
|
||||||
|
value={rejectReason}
|
||||||
|
placeholder="驳回原因"
|
||||||
|
onChange={(e) => setRejectReason(e.target.value)}
|
||||||
|
/>
|
||||||
|
</Modal>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 供门店详情抽屉 extra 调用 */
|
||||||
|
export async function auditStorePackageRequest(
|
||||||
|
requestId: string,
|
||||||
|
action: 'APPROVE' | 'REJECT',
|
||||||
|
rejectReason?: string,
|
||||||
|
) {
|
||||||
|
await request(`/admin/store-package-audits/${requestId}/audit`, {
|
||||||
|
method: 'PUT',
|
||||||
|
body: JSON.stringify(action === 'REJECT' ? { action, rejectReason } : { action }),
|
||||||
|
});
|
||||||
|
notifyPackageAuditChanged();
|
||||||
|
}
|
||||||
@@ -0,0 +1,230 @@
|
|||||||
|
import { useEffect, useRef, useState } from 'react';
|
||||||
|
import { Button, Empty, Input, List, Modal, Space, Spin, Typography, message } from 'antd';
|
||||||
|
import { request } from '../lib/api';
|
||||||
|
import {
|
||||||
|
placeToPicked,
|
||||||
|
type LbsPlaceItem,
|
||||||
|
type TencentPickedLocation,
|
||||||
|
} from '../lib/tencentLocPicker';
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
open: boolean;
|
||||||
|
onClose: () => void;
|
||||||
|
onPick: (loc: TencentPickedLocation) => void;
|
||||||
|
latitude?: number | null;
|
||||||
|
longitude?: number | null;
|
||||||
|
/** 城市名,提升搜索相关性 */
|
||||||
|
region?: string | null;
|
||||||
|
};
|
||||||
|
|
||||||
|
function hasCoords(lat: unknown, lng: unknown): lat is number {
|
||||||
|
const a = typeof lat === 'number' ? lat : Number(lat);
|
||||||
|
const b = typeof lng === 'number' ? lng : Number(lng);
|
||||||
|
return Number.isFinite(a) && Number.isFinite(b) && !(a === 0 && b === 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function TencentLocPickerModal({
|
||||||
|
open,
|
||||||
|
onClose,
|
||||||
|
onPick,
|
||||||
|
latitude,
|
||||||
|
longitude,
|
||||||
|
region,
|
||||||
|
}: Props) {
|
||||||
|
const [keyword, setKeyword] = useState('');
|
||||||
|
const [items, setItems] = useState<LbsPlaceItem[]>([]);
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
const [pending, setPending] = useState<TencentPickedLocation | null>(null);
|
||||||
|
const [hint, setHint] = useState('输入地点名称搜索,或加载附近地点');
|
||||||
|
const seqRef = useRef(0);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!open) {
|
||||||
|
setKeyword('');
|
||||||
|
setItems([]);
|
||||||
|
setPending(null);
|
||||||
|
setHint('输入地点名称搜索,或加载附近地点');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const lat = latitude != null ? Number(latitude) : NaN;
|
||||||
|
const lng = longitude != null ? Number(longitude) : NaN;
|
||||||
|
if (hasCoords(lat, lng)) {
|
||||||
|
void loadNearby(lat, lng);
|
||||||
|
}
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
}, [open]);
|
||||||
|
|
||||||
|
async function loadNearby(lat: number, lng: number) {
|
||||||
|
const seq = ++seqRef.current;
|
||||||
|
setLoading(true);
|
||||||
|
setHint('正在加载附近地点…');
|
||||||
|
try {
|
||||||
|
const res = await request<{ items: LbsPlaceItem[] }>(
|
||||||
|
`/common/lbs/nearby?lat=${encodeURIComponent(String(lat))}&lng=${encodeURIComponent(String(lng))}`,
|
||||||
|
);
|
||||||
|
if (seq !== seqRef.current) return;
|
||||||
|
setItems(res.items ?? []);
|
||||||
|
setHint(res.items?.length ? `附近 ${res.items.length} 个地点,点击选择` : '附近暂无地点,请搜索');
|
||||||
|
} catch (e) {
|
||||||
|
if (seq !== seqRef.current) return;
|
||||||
|
const msg = e instanceof Error ? e.message : '加载附近地点失败';
|
||||||
|
setItems([]);
|
||||||
|
setHint(msg);
|
||||||
|
message.error(msg);
|
||||||
|
} finally {
|
||||||
|
if (seq === seqRef.current) setLoading(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function runSearch(q: string) {
|
||||||
|
const trimmed = q.trim();
|
||||||
|
if (!trimmed) {
|
||||||
|
message.warning('请输入搜索关键词');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const seq = ++seqRef.current;
|
||||||
|
setLoading(true);
|
||||||
|
setHint('搜索中…');
|
||||||
|
try {
|
||||||
|
const params = new URLSearchParams({ keyword: trimmed });
|
||||||
|
if (region?.trim()) params.set('region', region.trim());
|
||||||
|
const lat = latitude != null ? Number(latitude) : NaN;
|
||||||
|
const lng = longitude != null ? Number(longitude) : NaN;
|
||||||
|
if (Number.isFinite(lat) && Number.isFinite(lng)) {
|
||||||
|
params.set('lat', String(lat));
|
||||||
|
params.set('lng', String(lng));
|
||||||
|
}
|
||||||
|
const res = await request<{ items: LbsPlaceItem[] }>(`/common/lbs/suggest?${params.toString()}`);
|
||||||
|
if (seq !== seqRef.current) return;
|
||||||
|
setItems(res.items ?? []);
|
||||||
|
setHint(res.items?.length ? `找到 ${res.items.length} 个结果,点击选择` : '无匹配结果,换个关键词试试');
|
||||||
|
} catch (e) {
|
||||||
|
if (seq !== seqRef.current) return;
|
||||||
|
const msg = e instanceof Error ? e.message : '搜索失败';
|
||||||
|
setItems([]);
|
||||||
|
setHint(msg);
|
||||||
|
message.error(msg);
|
||||||
|
} finally {
|
||||||
|
if (seq === seqRef.current) setLoading(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function useBrowserLocation() {
|
||||||
|
if (!navigator.geolocation) {
|
||||||
|
message.error('当前浏览器不支持定位');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setLoading(true);
|
||||||
|
navigator.geolocation.getCurrentPosition(
|
||||||
|
(pos) => {
|
||||||
|
const lat = pos.coords.latitude;
|
||||||
|
const lng = pos.coords.longitude;
|
||||||
|
setPending({ latitude: lat, longitude: lng, name: '当前位置' });
|
||||||
|
void loadNearby(lat, lng);
|
||||||
|
},
|
||||||
|
() => {
|
||||||
|
setLoading(false);
|
||||||
|
message.error('定位失败,请检查浏览器定位权限');
|
||||||
|
},
|
||||||
|
{ enableHighAccuracy: true, timeout: 12000 },
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function confirmPick() {
|
||||||
|
if (!pending) {
|
||||||
|
message.warning('请先从列表中选择一个地点');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
onPick(pending);
|
||||||
|
onClose();
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Modal
|
||||||
|
title="地图选点(腾讯位置服务)"
|
||||||
|
open={open}
|
||||||
|
onCancel={onClose}
|
||||||
|
width={720}
|
||||||
|
destroyOnClose
|
||||||
|
footer={
|
||||||
|
<Space style={{ width: '100%', justifyContent: 'space-between' }}>
|
||||||
|
<Typography.Text type="secondary" style={{ maxWidth: 420 }} ellipsis>
|
||||||
|
{pending
|
||||||
|
? `${pending.latitude.toFixed(6)}, ${pending.longitude.toFixed(6)}${
|
||||||
|
pending.name ? ` · ${pending.name}` : ''
|
||||||
|
}`
|
||||||
|
: '搜索或选择附近地点后确认'}
|
||||||
|
</Typography.Text>
|
||||||
|
<Space>
|
||||||
|
<Button onClick={onClose}>取消</Button>
|
||||||
|
<Button type="primary" disabled={!pending} onClick={confirmPick}>
|
||||||
|
确认选点
|
||||||
|
</Button>
|
||||||
|
</Space>
|
||||||
|
</Space>
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<Space direction="vertical" style={{ width: '100%' }} size="middle">
|
||||||
|
<Space.Compact style={{ width: '100%' }}>
|
||||||
|
<Input
|
||||||
|
allowClear
|
||||||
|
placeholder="输入小区 / 写字楼 / 门店名称"
|
||||||
|
value={keyword}
|
||||||
|
onChange={(e) => setKeyword(e.target.value)}
|
||||||
|
onPressEnter={() => void runSearch(keyword)}
|
||||||
|
/>
|
||||||
|
<Button type="primary" loading={loading} onClick={() => void runSearch(keyword)}>
|
||||||
|
搜索
|
||||||
|
</Button>
|
||||||
|
</Space.Compact>
|
||||||
|
<Space wrap>
|
||||||
|
<Button onClick={useBrowserLocation} disabled={loading}>
|
||||||
|
定位当前位置
|
||||||
|
</Button>
|
||||||
|
<Typography.Text type="secondary">{hint}</Typography.Text>
|
||||||
|
</Space>
|
||||||
|
<div style={{ height: 420, overflow: 'auto', border: '1px solid #f0f0f0', borderRadius: 8 }}>
|
||||||
|
{loading && !items.length ? (
|
||||||
|
<div style={{ height: '100%', display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
|
||||||
|
<Spin tip="加载中…" />
|
||||||
|
</div>
|
||||||
|
) : items.length ? (
|
||||||
|
<List
|
||||||
|
size="small"
|
||||||
|
dataSource={items}
|
||||||
|
renderItem={(item) => {
|
||||||
|
const active =
|
||||||
|
pending?.latitude === item.latitude && pending?.longitude === item.longitude;
|
||||||
|
return (
|
||||||
|
<List.Item
|
||||||
|
style={{
|
||||||
|
cursor: 'pointer',
|
||||||
|
background: active ? 'rgba(22, 119, 255, 0.08)' : undefined,
|
||||||
|
paddingInline: 12,
|
||||||
|
}}
|
||||||
|
onClick={() => setPending(placeToPicked(item))}
|
||||||
|
>
|
||||||
|
<List.Item.Meta
|
||||||
|
title={item.title}
|
||||||
|
description={
|
||||||
|
<span>
|
||||||
|
{item.address}
|
||||||
|
<br />
|
||||||
|
<Typography.Text type="secondary" style={{ fontSize: 12 }}>
|
||||||
|
{item.latitude.toFixed(6)}, {item.longitude.toFixed(6)}
|
||||||
|
</Typography.Text>
|
||||||
|
</span>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</List.Item>
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<Empty style={{ marginTop: 80 }} description={hint} />
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</Space>
|
||||||
|
</Modal>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,8 +1,9 @@
|
|||||||
import { useEffect, useRef, useState } from 'react';
|
import { useEffect, useMemo, useRef, useState } from 'react';
|
||||||
import { Outlet, useLocation, useNavigate } from 'react-router-dom';
|
import { Outlet, useLocation, useNavigate } from 'react-router-dom';
|
||||||
import { Layout, Menu, Typography, Button, Space } from 'antd';
|
import { Layout, Menu, Typography, Button, Space, Badge } from 'antd';
|
||||||
import type { MenuProps } from 'antd';
|
import type { MenuProps } from 'antd';
|
||||||
import {
|
import {
|
||||||
|
RobotOutlined,
|
||||||
DashboardOutlined,
|
DashboardOutlined,
|
||||||
UserOutlined,
|
UserOutlined,
|
||||||
ShoppingOutlined,
|
ShoppingOutlined,
|
||||||
@@ -17,12 +18,17 @@ import {
|
|||||||
LockOutlined,
|
LockOutlined,
|
||||||
SettingOutlined,
|
SettingOutlined,
|
||||||
AccountBookOutlined,
|
AccountBookOutlined,
|
||||||
|
ProjectOutlined,
|
||||||
} from '@ant-design/icons';
|
} from '@ant-design/icons';
|
||||||
|
import { hasAnySystemSettingsPermission } from '@dukang/shared-types';
|
||||||
import { clearAuth, request, type HqProfile } from '../lib/api';
|
import { clearAuth, request, type HqProfile } from '../lib/api';
|
||||||
import { bindAdminEllipsisTitle } from '../lib/ellipsis-title';
|
import { bindAdminEllipsisTitle } from '../lib/ellipsis-title';
|
||||||
|
import { AUDIT_NOTICE_CHANGED_EVENT, PACKAGE_AUDIT_CHANGED_EVENT } from '../lib/admin-events';
|
||||||
|
|
||||||
const { Header, Sider, Content } = Layout;
|
const { Header, Sider, Content } = Layout;
|
||||||
|
|
||||||
|
type MenuItem = NonNullable<MenuProps['items']>[number];
|
||||||
|
|
||||||
const MENU_ITEMS: MenuProps['items'] = [
|
const MENU_ITEMS: MenuProps['items'] = [
|
||||||
{ key: '/', icon: <DashboardOutlined />, label: '概览' },
|
{ key: '/', icon: <DashboardOutlined />, label: '概览' },
|
||||||
{ key: '/users', icon: <UserOutlined />, label: '用户' },
|
{ key: '/users', icon: <UserOutlined />, label: '用户' },
|
||||||
@@ -38,12 +44,26 @@ const MENU_ITEMS: MenuProps['items'] = [
|
|||||||
},
|
},
|
||||||
{ key: '/orders', icon: <ShoppingOutlined />, label: '订单' },
|
{ key: '/orders', icon: <ShoppingOutlined />, label: '订单' },
|
||||||
{ key: '/promo-codes', icon: <GiftOutlined />, label: '推广码' },
|
{ key: '/promo-codes', icon: <GiftOutlined />, label: '推广码' },
|
||||||
|
{
|
||||||
|
key: 'wecom-group',
|
||||||
|
icon: <TeamOutlined />,
|
||||||
|
label: '企微机器人',
|
||||||
|
children: [
|
||||||
|
{ key: '/wecom/bots', label: '智能机器人' },
|
||||||
|
{ key: '/wecom/pushes', label: '消息推送' },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{ key: '/llm-configs', icon: <RobotOutlined />, label: '语言模型' },
|
||||||
|
{ key: '/knowledge-bases', icon: <FileTextOutlined />, label: '知识库' },
|
||||||
{
|
{
|
||||||
key: 'stores-group',
|
key: 'stores-group',
|
||||||
icon: <ShopOutlined />,
|
icon: <ShopOutlined />,
|
||||||
label: '门店',
|
label: '门店',
|
||||||
children: [
|
children: [
|
||||||
{ key: '/stores', label: '门店列表' },
|
{ key: '/stores', label: '门店列表' },
|
||||||
|
{ key: '/store-package-audits', label: '审核通知' },
|
||||||
|
{ key: '/store-ratings', label: '门店评价' },
|
||||||
|
{ key: '/store-categories', label: '门店分类' },
|
||||||
{ key: '/store-accounts', label: '门店账户' },
|
{ key: '/store-accounts', label: '门店账户' },
|
||||||
{ key: '/store-media', label: '门店资源' },
|
{ key: '/store-media', label: '门店资源' },
|
||||||
],
|
],
|
||||||
@@ -67,6 +87,7 @@ const MENU_ITEMS: MenuProps['items'] = [
|
|||||||
{ key: '/finance/store-bills', label: '门店账单' },
|
{ key: '/finance/store-bills', label: '门店账单' },
|
||||||
{ key: '/finance/partner-bills', label: '合伙人账单' },
|
{ key: '/finance/partner-bills', label: '合伙人账单' },
|
||||||
{ key: '/finance/winery-bills', label: '酒厂账单' },
|
{ key: '/finance/winery-bills', label: '酒厂账单' },
|
||||||
|
{ key: '/finance/logistics-bills', label: '物流对账' },
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -90,7 +111,25 @@ const MENU_ITEMS: MenuProps['items'] = [
|
|||||||
{ key: '/deliveries/xiaofeixia', label: '小飞侠联调' },
|
{ key: '/deliveries/xiaofeixia', label: '小飞侠联调' },
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{ key: '/tickets', icon: <CarOutlined />, label: '工单中心' },
|
{
|
||||||
|
key: 'tickets-group',
|
||||||
|
icon: <CarOutlined />,
|
||||||
|
label: '工单',
|
||||||
|
children: [
|
||||||
|
{ key: '/tickets', label: '工单中心' },
|
||||||
|
{ key: '/tickets/support', label: '技术支持' },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'dev-plan-group',
|
||||||
|
icon: <ProjectOutlined />,
|
||||||
|
label: '开发计划',
|
||||||
|
children: [
|
||||||
|
{ key: '/dev-plan/versions', label: '版本列表' },
|
||||||
|
{ key: '/dev-plan/tasks', label: '任务列表' },
|
||||||
|
{ key: '/dev-plan/settings', label: '开发设置' },
|
||||||
|
],
|
||||||
|
},
|
||||||
{ key: '/invoices', icon: <FileTextOutlined />, label: '发票管理' },
|
{ key: '/invoices', icon: <FileTextOutlined />, label: '发票管理' },
|
||||||
{ key: '/resources', icon: <CloudUploadOutlined />, label: 'OSS 资源库' },
|
{ key: '/resources', icon: <CloudUploadOutlined />, label: 'OSS 资源库' },
|
||||||
{
|
{
|
||||||
@@ -103,23 +142,169 @@ const MENU_ITEMS: MenuProps['items'] = [
|
|||||||
{ key: '/logs/partners', label: '合伙人日志' },
|
{ key: '/logs/partners', label: '合伙人日志' },
|
||||||
{ key: '/logs/hq', label: 'HQ 操作日志' },
|
{ key: '/logs/hq', label: 'HQ 操作日志' },
|
||||||
{ key: '/logs/third-party', label: '第三方日志' },
|
{ key: '/logs/third-party', label: '第三方日志' },
|
||||||
|
{ key: '/logs/domain-events', label: '领域事件' },
|
||||||
|
{ key: '/logs/wecom-bots', label: '智能机器人日志' },
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{ key: '/hq-permissions', icon: <LockOutlined />, label: '权限分配' },
|
{ key: '/hq-permissions', icon: <LockOutlined />, label: '权限分配' },
|
||||||
|
{ key: '/test-whitelist', icon: <SafetyOutlined />, label: '白名单管理' },
|
||||||
{ key: '/system-settings', icon: <SettingOutlined />, label: '系统设置' },
|
{ key: '/system-settings', icon: <SettingOutlined />, label: '系统设置' },
|
||||||
{ key: '/hq-accounts', icon: <SafetyOutlined />, label: 'HQ账户' },
|
{ key: '/hq-accounts', icon: <SafetyOutlined />, label: 'HQ账户' },
|
||||||
];
|
];
|
||||||
|
|
||||||
|
function menuAllowed(key: string, permissionKeys: string[]): boolean {
|
||||||
|
if (key === 'tickets-group') {
|
||||||
|
return permissionKeys.includes('tickets') || permissionKeys.includes('tech_support');
|
||||||
|
}
|
||||||
|
if (key === 'dev-plan-group') {
|
||||||
|
return permissionKeys.includes('dev_plan');
|
||||||
|
}
|
||||||
|
const map: Record<string, string | 'system_settings_any'> = {
|
||||||
|
'/': 'dashboard',
|
||||||
|
'/users': 'users',
|
||||||
|
'/wechat-bindings': 'wechat_bindings',
|
||||||
|
'products-group': 'products',
|
||||||
|
'/products': 'products',
|
||||||
|
'/product-detail-templates': 'products',
|
||||||
|
'/orders': 'orders',
|
||||||
|
'/promo-codes': 'promo_codes',
|
||||||
|
'/wecom/bots': 'wecom_bots',
|
||||||
|
'/wecom/pushes': 'wecom_bots',
|
||||||
|
'wecom-group': 'wecom_bots',
|
||||||
|
'/llm-configs': 'llm_configs',
|
||||||
|
'/knowledge-bases': 'knowledge_bases',
|
||||||
|
'stores-group': 'stores',
|
||||||
|
'/stores': 'stores',
|
||||||
|
'/store-package-audits': 'stores',
|
||||||
|
'/store-ratings': 'stores',
|
||||||
|
'/store-categories': 'stores',
|
||||||
|
'/store-accounts': 'stores',
|
||||||
|
'/store-media': 'stores',
|
||||||
|
'partners-group': 'partners',
|
||||||
|
'/cities': 'partners',
|
||||||
|
'/city-partners': 'partners',
|
||||||
|
'/city-warehouses': 'partners',
|
||||||
|
'/fulfillment-providers': 'partners',
|
||||||
|
'finance-group': 'finance',
|
||||||
|
'/finance/store-bills': 'finance',
|
||||||
|
'/finance/store-withdrawals': 'finance',
|
||||||
|
'/finance/partner-bills': 'finance',
|
||||||
|
'/finance/winery-bills': 'finance',
|
||||||
|
'/finance/logistics-bills': 'finance',
|
||||||
|
'benefit-group': 'benefit',
|
||||||
|
'/benefit/coupons': 'benefit',
|
||||||
|
'/benefit/ledgers': 'benefit',
|
||||||
|
'/redeem-records': 'benefit',
|
||||||
|
'/redeem-pending': 'benefit',
|
||||||
|
'/redeem/debug': 'benefit',
|
||||||
|
'deliveries-group': 'deliveries',
|
||||||
|
'/deliveries': 'deliveries',
|
||||||
|
'/deliveries/xiaofeixia': 'deliveries',
|
||||||
|
'/tickets': 'tickets',
|
||||||
|
'/tickets/support': 'tech_support',
|
||||||
|
'dev-plan-group': 'dev_plan',
|
||||||
|
'/dev-plan/versions': 'dev_plan',
|
||||||
|
'/dev-plan/tasks': 'dev_plan',
|
||||||
|
'/dev-plan/settings': 'dev_plan',
|
||||||
|
'/invoices': 'invoices',
|
||||||
|
'/resources': 'resources',
|
||||||
|
'logs-group': 'logs',
|
||||||
|
'/logs/users': 'logs',
|
||||||
|
'/logs/wecom-bots': 'logs',
|
||||||
|
'/logs/stores': 'logs',
|
||||||
|
'/logs/partners': 'logs',
|
||||||
|
'/logs/hq': 'logs',
|
||||||
|
'/logs/third-party': 'logs',
|
||||||
|
'/logs/domain-events': 'logs',
|
||||||
|
'/hq-permissions': 'hq_permissions',
|
||||||
|
'/test-whitelist': 'test_whitelist',
|
||||||
|
'/system-settings': 'system_settings_any',
|
||||||
|
'/hq-accounts': 'hq_accounts',
|
||||||
|
};
|
||||||
|
const need = map[key];
|
||||||
|
if (!need) return true;
|
||||||
|
if (need === 'system_settings_any') return hasAnySystemSettingsPermission(permissionKeys);
|
||||||
|
return permissionKeys.includes(need);
|
||||||
|
}
|
||||||
|
|
||||||
|
function filterMenuItems(items: MenuProps['items'], permissionKeys: string[]): MenuProps['items'] {
|
||||||
|
if (!items) return items;
|
||||||
|
return items
|
||||||
|
.map((item) => {
|
||||||
|
if (!item || typeof item !== 'object' || !('key' in item)) return item;
|
||||||
|
const key = String(item.key);
|
||||||
|
if ('children' in item && Array.isArray(item.children)) {
|
||||||
|
if (!menuAllowed(key, permissionKeys)) return null;
|
||||||
|
const children = filterMenuItems(item.children as MenuProps['items'], permissionKeys);
|
||||||
|
if (!children?.length) return null;
|
||||||
|
return { ...item, children } as MenuItem;
|
||||||
|
}
|
||||||
|
return menuAllowed(key, permissionKeys) ? item : null;
|
||||||
|
})
|
||||||
|
.filter(Boolean) as MenuProps['items'];
|
||||||
|
}
|
||||||
|
|
||||||
|
function attachAuditBadge(items: MenuProps['items'], pendingCount: number): MenuProps['items'] {
|
||||||
|
if (!items) return items;
|
||||||
|
return items.map((item) => {
|
||||||
|
if (!item || typeof item !== 'object' || !('key' in item)) return item;
|
||||||
|
if ('children' in item && Array.isArray(item.children)) {
|
||||||
|
return {
|
||||||
|
...item,
|
||||||
|
children: attachAuditBadge(item.children as MenuProps['items'], pendingCount),
|
||||||
|
} as MenuItem;
|
||||||
|
}
|
||||||
|
if (String(item.key) === '/store-package-audits') {
|
||||||
|
return {
|
||||||
|
...item,
|
||||||
|
label: (
|
||||||
|
<span style={{ display: 'inline-flex', alignItems: 'center', gap: 6 }}>
|
||||||
|
审核通知
|
||||||
|
{pendingCount > 0 && <Badge count={pendingCount} size="small" />}
|
||||||
|
</span>
|
||||||
|
),
|
||||||
|
} as MenuItem;
|
||||||
|
}
|
||||||
|
return item;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const IS_STAGING = import.meta.env.VITE_APP_ENV === 'staging';
|
||||||
|
|
||||||
export default function AdminLayout() {
|
export default function AdminLayout() {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
const contentRef = useRef<HTMLDivElement>(null);
|
const contentRef = useRef<HTMLDivElement>(null);
|
||||||
const [profile, setProfile] = useState<HqProfile | null>(null);
|
const [profile, setProfile] = useState<HqProfile | null>(null);
|
||||||
|
const [auditPendingCount, setAuditPendingCount] = useState(0);
|
||||||
|
|
||||||
|
function refreshAuditPendingCount() {
|
||||||
|
Promise.all([
|
||||||
|
request<{ pendingCount: number }>('/admin/store-package-audits/summary').catch(() => ({ pendingCount: 0 })),
|
||||||
|
request<{ pendingCount: number; packagePendingCount?: number }>('/admin/store-info-change-requests/summary').catch(() => ({ pendingCount: 0 })),
|
||||||
|
])
|
||||||
|
.then(([pkg, info]) => setAuditPendingCount((pkg.pendingCount ?? 0) + (info.pendingCount ?? 0)))
|
||||||
|
.catch(() => {});
|
||||||
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
request<HqProfile>('/admin/auth/me').then(setProfile).catch(() => {});
|
request<HqProfile>('/admin/auth/me').then(setProfile).catch(() => {});
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
refreshAuditPendingCount();
|
||||||
|
}, [location.pathname]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const onChanged = () => refreshAuditPendingCount();
|
||||||
|
window.addEventListener(PACKAGE_AUDIT_CHANGED_EVENT, onChanged);
|
||||||
|
window.addEventListener(AUDIT_NOTICE_CHANGED_EVENT, onChanged);
|
||||||
|
return () => {
|
||||||
|
window.removeEventListener(PACKAGE_AUDIT_CHANGED_EVENT, onChanged);
|
||||||
|
window.removeEventListener(AUDIT_NOTICE_CHANGED_EVENT, onChanged);
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
contentRef.current?.scrollTo({ top: 0, left: 0 });
|
contentRef.current?.scrollTo({ top: 0, left: 0 });
|
||||||
}, [location.pathname]);
|
}, [location.pathname]);
|
||||||
@@ -137,26 +322,53 @@ export default function AdminLayout() {
|
|||||||
? '/promo-codes'
|
? '/promo-codes'
|
||||||
: location.pathname;
|
: location.pathname;
|
||||||
|
|
||||||
|
const menuItems = useMemo(() => {
|
||||||
|
const base =
|
||||||
|
!profile || profile.adminRole === 'SUPER_ADMIN'
|
||||||
|
? MENU_ITEMS
|
||||||
|
: filterMenuItems(MENU_ITEMS, profile.permissionKeys ?? []);
|
||||||
|
return attachAuditBadge(base, auditPendingCount);
|
||||||
|
}, [profile, auditPendingCount]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Layout style={{ height: '100vh', overflow: 'hidden' }}>
|
<Layout style={{ height: '100vh', overflow: 'hidden' }}>
|
||||||
|
{IS_STAGING ? (
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
position: 'fixed',
|
||||||
|
top: 0,
|
||||||
|
left: 0,
|
||||||
|
right: 0,
|
||||||
|
zIndex: 1100,
|
||||||
|
background: '#d48806',
|
||||||
|
color: '#fff',
|
||||||
|
textAlign: 'center',
|
||||||
|
fontSize: 13,
|
||||||
|
fontWeight: 600,
|
||||||
|
lineHeight: '28px',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
测试环境 · staging · 数据与生产隔离 · Mock 开启
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
<Sider
|
<Sider
|
||||||
breakpoint="lg"
|
breakpoint="lg"
|
||||||
collapsedWidth={64}
|
collapsedWidth={64}
|
||||||
theme="dark"
|
theme="dark"
|
||||||
width={220}
|
width={220}
|
||||||
style={{ height: '100vh', overflow: 'hidden' }}
|
style={{ height: '100vh', overflow: 'hidden', marginTop: IS_STAGING ? 28 : 0 }}
|
||||||
>
|
>
|
||||||
<div style={{ display: 'flex', flexDirection: 'column', height: '100vh' }}>
|
<div style={{ display: 'flex', flexDirection: 'column', height: IS_STAGING ? 'calc(100vh - 28px)' : '100vh' }}>
|
||||||
<div style={{ flexShrink: 0, padding: '16px', color: '#fff', fontWeight: 600 }}>
|
<div style={{ flexShrink: 0, padding: '16px', color: '#fff', fontWeight: 600 }}>
|
||||||
杜康 HQ
|
杜康 HQ{IS_STAGING ? ' · 测试' : ''}
|
||||||
</div>
|
</div>
|
||||||
<div className="admin-sider-menu-scroll" style={{ flex: 1, minHeight: 0, overflow: 'auto' }}>
|
<div className="admin-sider-menu-scroll" style={{ flex: 1, minHeight: 0, overflow: 'auto' }}>
|
||||||
<Menu
|
<Menu
|
||||||
theme="dark"
|
theme="dark"
|
||||||
mode="inline"
|
mode="inline"
|
||||||
selectedKeys={[selectedKey]}
|
selectedKeys={[selectedKey]}
|
||||||
defaultOpenKeys={['products-group', 'stores-group', 'partners-group', 'finance-group', 'benefit-group', 'logs-group', 'deliveries-group']}
|
defaultOpenKeys={[]}
|
||||||
items={MENU_ITEMS}
|
items={menuItems}
|
||||||
onClick={({ key }) => {
|
onClick={({ key }) => {
|
||||||
if (key.startsWith('/')) navigate(key);
|
if (key.startsWith('/')) navigate(key);
|
||||||
}}
|
}}
|
||||||
@@ -164,7 +376,15 @@ export default function AdminLayout() {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</Sider>
|
</Sider>
|
||||||
<Layout style={{ height: '100vh', overflow: 'hidden', display: 'flex', flexDirection: 'column' }}>
|
<Layout
|
||||||
|
style={{
|
||||||
|
height: IS_STAGING ? 'calc(100vh - 28px)' : '100vh',
|
||||||
|
marginTop: IS_STAGING ? 28 : 0,
|
||||||
|
overflow: 'hidden',
|
||||||
|
display: 'flex',
|
||||||
|
flexDirection: 'column',
|
||||||
|
}}
|
||||||
|
>
|
||||||
<Header
|
<Header
|
||||||
style={{
|
style={{
|
||||||
flexShrink: 0,
|
flexShrink: 0,
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
export const PACKAGE_AUDIT_CHANGED_EVENT = 'admin:package-audit-changed';
|
||||||
|
export const AUDIT_NOTICE_CHANGED_EVENT = 'dukang:audit-notice-changed';
|
||||||
|
|
||||||
|
export function notifyPackageAuditChanged() {
|
||||||
|
window.dispatchEvent(new Event(PACKAGE_AUDIT_CHANGED_EVENT));
|
||||||
|
window.dispatchEvent(new Event(AUDIT_NOTICE_CHANGED_EVENT));
|
||||||
|
}
|
||||||
|
|
||||||
|
export function notifyAuditNoticeChanged() {
|
||||||
|
notifyPackageAuditChanged();
|
||||||
|
}
|
||||||
@@ -7,6 +7,7 @@ export type HqProfile = {
|
|||||||
name: string;
|
name: string;
|
||||||
adminRole: string;
|
adminRole: string;
|
||||||
status: string;
|
status: string;
|
||||||
|
permissionKeys?: string[];
|
||||||
};
|
};
|
||||||
|
|
||||||
export function getToken() {
|
export function getToken() {
|
||||||
@@ -84,9 +85,56 @@ export type DashboardStats = {
|
|||||||
pendingBills?: number;
|
pendingBills?: number;
|
||||||
pendingPartnerDraftBills?: number;
|
pendingPartnerDraftBills?: number;
|
||||||
openTickets?: number;
|
openTickets?: number;
|
||||||
|
pendingStoreWithdrawals?: number;
|
||||||
|
overdueStoreWithdrawals?: number;
|
||||||
ordersByStatus: Array<{ status: string; count: number }>;
|
ordersByStatus: Array<{ status: string; count: number }>;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type DashboardAnalytics = {
|
||||||
|
summary: {
|
||||||
|
users: number;
|
||||||
|
orders: number;
|
||||||
|
payingUsers: number;
|
||||||
|
partners: number;
|
||||||
|
stores: number;
|
||||||
|
redeems: number;
|
||||||
|
redeemAmount: number;
|
||||||
|
};
|
||||||
|
byDate: Array<{
|
||||||
|
date: string;
|
||||||
|
users: number;
|
||||||
|
orders: number;
|
||||||
|
partners: number;
|
||||||
|
stores: number;
|
||||||
|
redeems: number;
|
||||||
|
redeemAmount: number;
|
||||||
|
}>;
|
||||||
|
byCity: Array<{
|
||||||
|
cityId: string;
|
||||||
|
cityName: string;
|
||||||
|
users: number;
|
||||||
|
orders: number;
|
||||||
|
partners: number;
|
||||||
|
stores: number;
|
||||||
|
redeems: number;
|
||||||
|
redeemAmount: number;
|
||||||
|
}>;
|
||||||
|
byPromo: Array<{
|
||||||
|
promoCodeId: string | null;
|
||||||
|
code: string;
|
||||||
|
name: string;
|
||||||
|
users: number;
|
||||||
|
orders: number;
|
||||||
|
}>;
|
||||||
|
byPartner: Array<{
|
||||||
|
partnerAccountId: string;
|
||||||
|
companyName: string;
|
||||||
|
stores: number;
|
||||||
|
redeems: number;
|
||||||
|
redeemAmount: number;
|
||||||
|
}>;
|
||||||
|
};
|
||||||
|
|
||||||
export type SystemVersion = {
|
export type SystemVersion = {
|
||||||
id: string;
|
id: string;
|
||||||
gitTag: string | null;
|
gitTag: string | null;
|
||||||
@@ -119,6 +167,13 @@ export type AdminUserRow = {
|
|||||||
sourceLabel: string | null;
|
sourceLabel: string | null;
|
||||||
createdAt: string;
|
createdAt: string;
|
||||||
orderCount: number;
|
orderCount: number;
|
||||||
|
isTest?: boolean;
|
||||||
|
/** 好客权益·累计获得(含已使用,不含退款作废) */
|
||||||
|
benefitTotalAmount?: number;
|
||||||
|
/** 好客权益·已使用(已核销) */
|
||||||
|
benefitUsedAmount?: number;
|
||||||
|
/** 好客权益·剩余未使用 */
|
||||||
|
benefitBalance?: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type AdminOrderItem = {
|
export type AdminOrderItem = {
|
||||||
@@ -145,6 +200,13 @@ export type AdminOrderRow = {
|
|||||||
city?: { id: string; name: string; code: string };
|
city?: { id: string; name: string; code: string };
|
||||||
fulfillmentWarehouseId?: string | null;
|
fulfillmentWarehouseId?: string | null;
|
||||||
fulfillmentWarehouse?: { id: string; name: string } | null;
|
fulfillmentWarehouse?: { id: string; name: string } | null;
|
||||||
|
fulfillmentHold?: boolean;
|
||||||
|
fulfillmentHoldReason?: string | null;
|
||||||
|
orderType?: string;
|
||||||
|
isProxyOrder?: boolean;
|
||||||
|
proxyPartnerName?: string | null;
|
||||||
|
proxyPartnerPhone?: string | null;
|
||||||
|
isTest?: boolean;
|
||||||
user?: { id: string; userNo: string; phone: string | null; nickname: string | null };
|
user?: { id: string; userNo: string; phone: string | null; nickname: string | null };
|
||||||
delivery?: {
|
delivery?: {
|
||||||
provider: string;
|
provider: string;
|
||||||
|
|||||||
@@ -79,6 +79,39 @@ export function districtCodeToCityCode(districtCode: string): string {
|
|||||||
return `${districtCode.slice(0, 4)}00`;
|
return `${districtCode.slice(0, 4)}00`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type DistrictOption = { value: string; label: string };
|
||||||
|
|
||||||
|
/** 按开城城市 code(4 位或 6 位)取该市下区县列表 */
|
||||||
|
export function getDistrictOptionsByCityCode(cityCode?: string | null): DistrictOption[] {
|
||||||
|
if (!cityCode?.trim()) return [];
|
||||||
|
const normalized = normalizeCityAdcode(cityCode.trim());
|
||||||
|
const prefix4 = normalized.slice(0, 4);
|
||||||
|
|
||||||
|
for (const province of regionData) {
|
||||||
|
for (const city of province.children ?? []) {
|
||||||
|
const cityValue = String(city.value);
|
||||||
|
const cityNorm = normalizeCityAdcode(cityValue);
|
||||||
|
if (cityNorm === normalized || cityValue === prefix4 || cityValue === cityCode.trim()) {
|
||||||
|
return (city.children ?? []).map((d) => ({
|
||||||
|
value: String(d.value),
|
||||||
|
label: String(d.label),
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
export function districtCodeLabel(code: string): string {
|
||||||
|
return codeToText[code] || code;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 列表展示:区县码 → 中文名,顿号拼接 */
|
||||||
|
export function formatDistrictLabels(codes?: string[] | null): string {
|
||||||
|
if (!codes?.length) return '—';
|
||||||
|
return codes.map((c) => districtCodeLabel(String(c))).join('、');
|
||||||
|
}
|
||||||
|
|
||||||
export function parseRegionCodes(codes?: string[]): ParsedChinaRegion | null {
|
export function parseRegionCodes(codes?: string[]): ParsedChinaRegion | null {
|
||||||
if (!codes || codes.length < 3) return null;
|
if (!codes || codes.length < 3) return null;
|
||||||
const [provinceCode, cityCode, districtCode] = codes;
|
const [provinceCode, cityCode, districtCode] = codes;
|
||||||
|
|||||||
@@ -19,6 +19,17 @@ export const ORDER_STATUS_LABELS: Record<string, string> = {
|
|||||||
REFUNDED: '已退款',
|
REFUNDED: '已退款',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** 订单状态流转操作人(common_event.param3) */
|
||||||
|
export const ORDER_STATUS_OPERATOR_LABELS: Record<string, string> = {
|
||||||
|
USER: '用户',
|
||||||
|
USER_ON_SITE: '用户·现场取货',
|
||||||
|
USER_WECHAT_CONFIRM: '用户·微信确认收货',
|
||||||
|
WECHAT_TRADE_MANAGE: '微信结算同步',
|
||||||
|
MOCK: 'Mock',
|
||||||
|
MOCK_PAY: 'Mock 支付',
|
||||||
|
SYSTEM: '系统',
|
||||||
|
};
|
||||||
|
|
||||||
/** 订单状态 Tag 颜色(Ant Design preset) */
|
/** 订单状态 Tag 颜色(Ant Design preset) */
|
||||||
export const ORDER_STATUS_COLORS: Record<string, string> = {
|
export const ORDER_STATUS_COLORS: Record<string, string> = {
|
||||||
PENDING_PAY: 'red',
|
PENDING_PAY: 'red',
|
||||||
@@ -34,8 +45,8 @@ export const ORDER_STATUS_COLORS: Record<string, string> = {
|
|||||||
|
|
||||||
export const STORE_STATUS_LABELS: Record<string, string> = {
|
export const STORE_STATUS_LABELS: Record<string, string> = {
|
||||||
OPEN: '营业中',
|
OPEN: '营业中',
|
||||||
PAUSED: '暂停',
|
PAUSED: '临时闭店',
|
||||||
CLOSED: '已关闭',
|
CLOSED: '永久关闭',
|
||||||
};
|
};
|
||||||
|
|
||||||
export const STORE_AUDIT_STATUS_LABELS: Record<string, string> = {
|
export const STORE_AUDIT_STATUS_LABELS: Record<string, string> = {
|
||||||
@@ -62,9 +73,11 @@ export const CITY_STATUS_LABELS: Record<string, string> = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const PARTNER_BILL_STATUS_LABELS: Record<string, string> = {
|
export const PARTNER_BILL_STATUS_LABELS: Record<string, string> = {
|
||||||
DRAFT: '草稿',
|
PENDING_REVIEW: '待审核',
|
||||||
CONFIRMED: '已确认',
|
AWAITING_CONFIRM: '待合伙人确认',
|
||||||
PAID: '已结算',
|
UNPAID: '未打款',
|
||||||
|
PAID: '已打款',
|
||||||
|
REJECTED: '已驳回',
|
||||||
};
|
};
|
||||||
|
|
||||||
export const MEDIA_TYPE_LABELS: Record<string, string> = {
|
export const MEDIA_TYPE_LABELS: Record<string, string> = {
|
||||||
@@ -126,3 +139,37 @@ export const LEDGER_TYPE_LABELS: Record<string, string> = {
|
|||||||
export function fmtTime(v?: string | null) {
|
export function fmtTime(v?: string | null) {
|
||||||
return v ? new Date(v).toLocaleString('zh-CN') : '—';
|
return v ? new Date(v).toLocaleString('zh-CN') : '—';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 联系电话脱敏:手机 138****5678;座机 0379-****888;空值返回 — */
|
||||||
|
export function maskPhone(phone?: string | null): string {
|
||||||
|
const raw = String(phone ?? '').trim().replace(/\s+/g, '');
|
||||||
|
if (!raw) return '—';
|
||||||
|
if (/^1[3-9]\d{9}$/.test(raw)) {
|
||||||
|
const digits = raw.replace(/\D/g, '');
|
||||||
|
return `${digits.slice(0, 3)}****${digits.slice(-4)}`;
|
||||||
|
}
|
||||||
|
if (/^0\d{2,3}-?\d{7,8}(-\d{1,6})?$/.test(raw)) {
|
||||||
|
const extMatch = raw.match(/-(\d{1,6})$/);
|
||||||
|
const hasExt = !!extMatch && raw.indexOf('-') !== raw.lastIndexOf('-');
|
||||||
|
const ext = hasExt ? extMatch![1] : '';
|
||||||
|
const main = hasExt ? raw.slice(0, -(ext.length + 1)) : raw;
|
||||||
|
const digits = main.replace(/\D/g, '');
|
||||||
|
const areaLen = digits.startsWith('01') || digits.startsWith('02') ? 3 : 4;
|
||||||
|
const area = digits.slice(0, areaLen);
|
||||||
|
const local = digits.slice(areaLen);
|
||||||
|
const keepTail = Math.min(4, Math.max(2, local.length - 4));
|
||||||
|
const maskedLocal =
|
||||||
|
local.length <= 4 ? '*'.repeat(local.length) : `${'*'.repeat(local.length - keepTail)}${local.slice(-keepTail)}`;
|
||||||
|
const joiner = main.includes('-') ? '-' : '';
|
||||||
|
return ext ? `${area}${joiner}${maskedLocal}-${ext}` : `${area}${joiner}${maskedLocal}`;
|
||||||
|
}
|
||||||
|
const digits = raw.replace(/\D/g, '');
|
||||||
|
if (digits.length >= 11) {
|
||||||
|
return `${digits.slice(0, 3)}****${digits.slice(-4)}`;
|
||||||
|
}
|
||||||
|
if (digits.length >= 7) {
|
||||||
|
return `${digits.slice(0, 3)}****${digits.slice(-2)}`;
|
||||||
|
}
|
||||||
|
if (digits.length > 0) return `${digits.slice(0, 1)}****`;
|
||||||
|
return '****';
|
||||||
|
}
|
||||||
|
|||||||
@@ -27,6 +27,11 @@ export const HQ_OPERATION_ACTION_OPTIONS = [
|
|||||||
{ value: 'STORE_AUDIT', label: '门店审核' },
|
{ value: 'STORE_AUDIT', label: '门店审核' },
|
||||||
{ value: 'STORE_ACCOUNT_CREATE', label: '新增门店账户' },
|
{ value: 'STORE_ACCOUNT_CREATE', label: '新增门店账户' },
|
||||||
{ value: 'STORE_ACCOUNT_UPDATE', label: '编辑门店账户' },
|
{ value: 'STORE_ACCOUNT_UPDATE', label: '编辑门店账户' },
|
||||||
|
{ value: 'STORE_ACCOUNT_STAFF_DELETE', label: '删除门店子账号' },
|
||||||
|
{ value: 'STORE_CATEGORY_CREATE', label: '新增门店分类' },
|
||||||
|
{ value: 'STORE_CATEGORY_UPDATE', label: '编辑门店分类' },
|
||||||
|
{ value: 'STORE_CATEGORY_DELETE', label: '删除门店分类' },
|
||||||
|
{ value: 'STORE_CATEGORY_ENSURE', label: '初始化默认门店分类' },
|
||||||
{ value: 'PRODUCT_CREATE', label: '新增商品' },
|
{ value: 'PRODUCT_CREATE', label: '新增商品' },
|
||||||
{ value: 'PRODUCT_UPDATE', label: '编辑商品' },
|
{ value: 'PRODUCT_UPDATE', label: '编辑商品' },
|
||||||
{ value: 'PRODUCT_DELETE', label: '删除商品' },
|
{ value: 'PRODUCT_DELETE', label: '删除商品' },
|
||||||
@@ -34,11 +39,27 @@ export const HQ_OPERATION_ACTION_OPTIONS = [
|
|||||||
{ value: 'DELIVERY_UPDATE', label: '编辑配送单' },
|
{ value: 'DELIVERY_UPDATE', label: '编辑配送单' },
|
||||||
{ value: 'TICKET_APPROVE', label: '工单通过' },
|
{ value: 'TICKET_APPROVE', label: '工单通过' },
|
||||||
{ value: 'TICKET_REJECT', label: '工单驳回' },
|
{ value: 'TICKET_REJECT', label: '工单驳回' },
|
||||||
|
{ value: 'TICKET_CREATE', label: '创建工单' },
|
||||||
|
{ value: 'SUPPORT_TICKET_CREATE', label: '创建技术支持工单' },
|
||||||
|
{ value: 'SUPPORT_TICKET_APPROVE', label: '技术支持评审通过' },
|
||||||
|
{ value: 'SUPPORT_TICKET_REJECT', label: '技术支持评审驳回' },
|
||||||
|
{ value: 'SUPPORT_TICKET_START_TESTING', label: '技术支持转入测试' },
|
||||||
|
{ value: 'SUPPORT_TICKET_PASS', label: '技术支持测试通过' },
|
||||||
|
{ value: 'INVOICE_CREATE', label: '创建发票申请' },
|
||||||
|
{ value: 'INVOICE_ISSUE', label: '开具发票' },
|
||||||
|
{ value: 'INVOICE_REJECT', label: '驳回发票' },
|
||||||
{ value: 'STORE_PAYOUT_CONFIRM', label: '门店打款确认' },
|
{ value: 'STORE_PAYOUT_CONFIRM', label: '门店打款确认' },
|
||||||
{ value: 'STORE_PAYOUT_BATCH_CONFIRM', label: '批量门店打款' },
|
{ value: 'STORE_PAYOUT_BATCH_CONFIRM', label: '批量门店打款' },
|
||||||
|
{ value: 'STORE_BILL_CONFIRM', label: '门店对账单确认打款' },
|
||||||
|
{ value: 'STORE_BILL_BATCH_CONFIRM', label: '批量门店对账单打款' },
|
||||||
{ value: 'PARTNER_BILL_GENERATE', label: '生成合伙人账单' },
|
{ value: 'PARTNER_BILL_GENERATE', label: '生成合伙人账单' },
|
||||||
|
{ value: 'PARTNER_BILL_SEND', label: '发送合伙人账单' },
|
||||||
|
{ value: 'PARTNER_BILL_BATCH_SEND', label: '批量发送合伙人账单' },
|
||||||
{ value: 'PARTNER_BILL_CONFIRM', label: '确认合伙人账单' },
|
{ value: 'PARTNER_BILL_CONFIRM', label: '确认合伙人账单' },
|
||||||
{ value: 'PARTNER_BILL_MARK_PAID', label: '合伙人账单结算' },
|
{ value: 'PARTNER_BILL_MARK_PAID', label: '合伙人账单结算' },
|
||||||
|
{ value: 'PARTNER_BILL_BATCH_MARK_PAID', label: '批量合伙人账单结算' },
|
||||||
|
{ value: 'WINERY_BILL_CONFIRM', label: '酒厂对账单确认打款' },
|
||||||
|
{ value: 'WINERY_BILL_BATCH_CONFIRM', label: '批量酒厂对账单打款' },
|
||||||
] as const;
|
] as const;
|
||||||
|
|
||||||
export const HQ_OPERATION_ACTION_LABELS: Record<string, string> = Object.fromEntries(
|
export const HQ_OPERATION_ACTION_LABELS: Record<string, string> = Object.fromEntries(
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import { isStoreContactPhone, STORE_CONTACT_PHONE_HINT } from '@dukang/domain';
|
||||||
|
|
||||||
export type StoreCreateForm = {
|
export type StoreCreateForm = {
|
||||||
partnerAccountId: string;
|
partnerAccountId: string;
|
||||||
cityId: string;
|
cityId: string;
|
||||||
@@ -6,35 +8,101 @@ export type StoreCreateForm = {
|
|||||||
city?: string;
|
city?: string;
|
||||||
district: string;
|
district: string;
|
||||||
districtCode?: string;
|
districtCode?: string;
|
||||||
|
categoryParentId?: string;
|
||||||
|
categoryId: string;
|
||||||
name: string;
|
name: string;
|
||||||
phone: string;
|
phone: string;
|
||||||
address: string;
|
address: string;
|
||||||
|
latitude?: number | null;
|
||||||
|
longitude?: number | null;
|
||||||
intro?: string;
|
intro?: string;
|
||||||
|
benefitUsageRule?: string;
|
||||||
|
/** 对外联系电话(店长);可与登录号不同,支持座机 */
|
||||||
|
contactPhone?: string;
|
||||||
|
openTime?: string;
|
||||||
|
closeTime?: string;
|
||||||
|
openTime2?: string;
|
||||||
|
closeTime2?: string;
|
||||||
|
avgPrice?: number | null;
|
||||||
coverUrl?: string;
|
coverUrl?: string;
|
||||||
envPhotoUrls?: string[];
|
envPhotoUrls?: string[];
|
||||||
contractUrl?: string;
|
/** 签约合同,支持多张照片 / PDF */
|
||||||
|
contractUrls?: string[];
|
||||||
bankAccountName: string;
|
bankAccountName: string;
|
||||||
bankAccountNo: string;
|
bankAccountNo: string;
|
||||||
bankBranch: string;
|
bankBranch: string;
|
||||||
settlementRate?: number;
|
settlementRate?: number;
|
||||||
|
sortOrder?: number;
|
||||||
|
visibilityWhitelistEnabled?: boolean;
|
||||||
|
visibilityPhones?: string[];
|
||||||
};
|
};
|
||||||
|
|
||||||
const PHONE_RE = /^1\d{10}$/;
|
const PHONE_RE = /^1\d{10}$/;
|
||||||
const BANK_RE = /^\d{16,19}$/;
|
const BANK_RE = /^\d{16,19}$/;
|
||||||
|
const TIME_RE = /^([01]\d|2[0-3]):([0-5]\d)$/;
|
||||||
|
|
||||||
|
function timeToMinutes(hhmm: string): number {
|
||||||
|
const [h, m] = hhmm.split(':').map(Number);
|
||||||
|
return h * 60 + m;
|
||||||
|
}
|
||||||
|
|
||||||
export function validateStoreCreateStep1(
|
export function validateStoreCreateStep1(
|
||||||
form: Pick<StoreCreateForm, 'partnerAccountId' | 'cityId' | 'regionCodes' | 'name' | 'phone' | 'address' | 'intro'>,
|
form: Pick<
|
||||||
|
StoreCreateForm,
|
||||||
|
| 'partnerAccountId'
|
||||||
|
| 'cityId'
|
||||||
|
| 'regionCodes'
|
||||||
|
| 'categoryId'
|
||||||
|
| 'name'
|
||||||
|
| 'phone'
|
||||||
|
| 'address'
|
||||||
|
| 'intro'
|
||||||
|
| 'benefitUsageRule'
|
||||||
|
| 'openTime'
|
||||||
|
| 'closeTime'
|
||||||
|
| 'openTime2'
|
||||||
|
| 'closeTime2'
|
||||||
|
| 'avgPrice'
|
||||||
|
| 'contactPhone'
|
||||||
|
>,
|
||||||
): string | null {
|
): string | null {
|
||||||
if (!form.partnerAccountId) return '请选择开城合伙人';
|
if (!form.partnerAccountId) return '请选择开城合伙人';
|
||||||
if (!form.regionCodes || form.regionCodes.length < 3) return '请选择省 / 市 / 区县';
|
if (!form.regionCodes || form.regionCodes.length < 3) return '请选择省 / 市 / 区县';
|
||||||
if (!form.cityId) return '所选地区未匹配到开城城市,请先在「开城 → 城市」配置对应区划';
|
if (!form.cityId) return '所选地区未匹配到开城城市,请先在「开城 → 城市」配置对应区划';
|
||||||
|
if (!form.categoryId?.trim()) return '请选择门店分类(细类)';
|
||||||
if (!form.name?.trim()) return '请填写门店名称';
|
if (!form.name?.trim()) return '请填写门店名称';
|
||||||
if (!form.phone?.trim()) return '请填写门店手机号';
|
if (!form.phone?.trim()) return '请填写门店手机号';
|
||||||
if (!PHONE_RE.test(form.phone.trim())) return '门店手机号须为11位手机号';
|
if (!PHONE_RE.test(form.phone.trim())) return '门店手机号须为11位手机号';
|
||||||
|
const contactPhone = form.contactPhone?.trim();
|
||||||
|
if (contactPhone && !isStoreContactPhone(contactPhone)) return STORE_CONTACT_PHONE_HINT;
|
||||||
if (!form.address?.trim()) return '请填写详细地址';
|
if (!form.address?.trim()) return '请填写详细地址';
|
||||||
|
|
||||||
|
const openTime = String(form.openTime || '').trim();
|
||||||
|
const closeTime = String(form.closeTime || '').trim();
|
||||||
|
if (!openTime || !closeTime) return '请填写营业时间';
|
||||||
|
if (!TIME_RE.test(openTime) || !TIME_RE.test(closeTime)) return '营业时间格式须为 HH:MM';
|
||||||
|
if (timeToMinutes(openTime) >= timeToMinutes(closeTime)) return '营业结束时间须晚于开始时间';
|
||||||
|
|
||||||
|
const openTime2 = String(form.openTime2 || '').trim();
|
||||||
|
const closeTime2 = String(form.closeTime2 || '').trim();
|
||||||
|
if (openTime2 || closeTime2) {
|
||||||
|
if (!openTime2 || !closeTime2) return '请完整填写第二段营业时间';
|
||||||
|
if (!TIME_RE.test(openTime2) || !TIME_RE.test(closeTime2)) return '第二段时间格式须为 HH:MM';
|
||||||
|
if (timeToMinutes(openTime2) >= timeToMinutes(closeTime2)) return '第二段结束时间须晚于开始时间';
|
||||||
|
if (timeToMinutes(closeTime) >= timeToMinutes(openTime2)) return '第二段开始时间须晚于第一段结束时间';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (form.avgPrice != null && String(form.avgPrice).trim() !== '') {
|
||||||
|
const n = Number(form.avgPrice);
|
||||||
|
if (Number.isNaN(n) || n < 0) return '人均费用须为非负数字';
|
||||||
|
}
|
||||||
|
|
||||||
if (form.intro?.trim()) {
|
if (form.intro?.trim()) {
|
||||||
const len = form.intro.trim().length;
|
const len = form.intro.trim().length;
|
||||||
if (len < 10 || len > 500) return '门店简介须为 10~500 字';
|
if (len < 2 || len > 500) return '门店简介须为 2~500 字';
|
||||||
|
}
|
||||||
|
if (form.benefitUsageRule?.trim() && form.benefitUsageRule.trim().length > 1000) {
|
||||||
|
return '好客权益券使用规则最多 1000 字';
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
export type TencentPickedLocation = {
|
||||||
|
latitude: number;
|
||||||
|
longitude: number;
|
||||||
|
address?: string;
|
||||||
|
name?: string;
|
||||||
|
cityname?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type LbsPlaceItem = {
|
||||||
|
id: string;
|
||||||
|
title: string;
|
||||||
|
address: string;
|
||||||
|
latitude: number;
|
||||||
|
longitude: number;
|
||||||
|
city?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export function placeToPicked(item: LbsPlaceItem): TencentPickedLocation {
|
||||||
|
return {
|
||||||
|
latitude: item.latitude,
|
||||||
|
longitude: item.longitude,
|
||||||
|
address: item.address || undefined,
|
||||||
|
name: item.title || undefined,
|
||||||
|
cityname: item.city || undefined,
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -1,4 +1,9 @@
|
|||||||
import { apiBase, CLIENT_APP, getToken, clearAuth } from './api';
|
import { apiBase, CLIENT_APP, getToken, clearAuth } from './api';
|
||||||
|
import {
|
||||||
|
compressImageFileIfNeeded,
|
||||||
|
DEFAULT_OSS_MAX_UPLOAD_BYTES,
|
||||||
|
formatOssMaxSizeMb,
|
||||||
|
} from '@dukang/shared-ui/compressImage';
|
||||||
|
|
||||||
export type OssMediaType = 'IMAGE' | 'VIDEO' | 'FILE';
|
export type OssMediaType = 'IMAGE' | 'VIDEO' | 'FILE';
|
||||||
|
|
||||||
@@ -9,14 +14,24 @@ export type UploadFileResult = {
|
|||||||
mock: boolean;
|
mock: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
async function prepareUploadFile(file: File, mediaType: OssMediaType): Promise<File> {
|
||||||
|
if (mediaType !== 'IMAGE') return file;
|
||||||
|
const compressed = await compressImageFileIfNeeded(file);
|
||||||
|
if (compressed.size > DEFAULT_OSS_MAX_UPLOAD_BYTES) {
|
||||||
|
throw new Error(`图片压缩后仍超过 ${formatOssMaxSizeMb()}MB,请换一张较小的图片`);
|
||||||
|
}
|
||||||
|
return compressed;
|
||||||
|
}
|
||||||
|
|
||||||
/** 经 API 服务端转存 OSS,避免浏览器直传跨域 */
|
/** 经 API 服务端转存 OSS,避免浏览器直传跨域 */
|
||||||
export async function uploadFileToOss(
|
export async function uploadFileToOss(
|
||||||
file: File,
|
file: File,
|
||||||
options: { bizType: string; mediaType?: OssMediaType },
|
options: { bizType: string; mediaType?: OssMediaType },
|
||||||
): Promise<UploadFileResult> {
|
): Promise<UploadFileResult> {
|
||||||
const mediaType = options.mediaType ?? (file.type.startsWith('video/') ? 'VIDEO' : 'IMAGE');
|
const mediaType = options.mediaType ?? (file.type.startsWith('video/') ? 'VIDEO' : 'IMAGE');
|
||||||
|
const prepared = await prepareUploadFile(file, mediaType);
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
formData.append('file', file);
|
formData.append('file', prepared);
|
||||||
formData.append('bizType', options.bizType);
|
formData.append('bizType', options.bizType);
|
||||||
formData.append('mediaType', mediaType);
|
formData.append('mediaType', mediaType);
|
||||||
|
|
||||||
|
|||||||
@@ -1,45 +1,12 @@
|
|||||||
export type UserLogCategory =
|
export {
|
||||||
| 'login'
|
USER_LOG_CATEGORY_OPTIONS,
|
||||||
| 'browse_product'
|
resolveUserLogCategory,
|
||||||
| 'order'
|
eventNamesForUserLogCategory,
|
||||||
| 'pay'
|
type UserLogCategory,
|
||||||
| 'wechat_auth'
|
} from '@dukang/shared-types';
|
||||||
| 'browse_store'
|
|
||||||
| 'redeem'
|
|
||||||
| 'profile';
|
|
||||||
|
|
||||||
const USER_LOG_EVENT_CATEGORIES: Record<UserLogCategory, readonly string[]> = {
|
import { USER_LOG_CATEGORY_OPTIONS } from '@dukang/shared-types';
|
||||||
login: ['login_success', 'sms_login', 'sms_send', 'sms_verify_fail'],
|
|
||||||
browse_product: ['home_view', 'product_click', 'product_detail_view'],
|
|
||||||
order: ['order_confirm_view', 'order_submit'],
|
|
||||||
pay: ['pay_success', 'pay_fail'],
|
|
||||||
wechat_auth: ['wechat_login', 'wechat_phone', 'wechat_location', 'wechat_album'],
|
|
||||||
browse_store: ['store_list_view', 'store_detail_view'],
|
|
||||||
redeem: ['benefit_redeem_start', 'benefit_redeem_success'],
|
|
||||||
profile: ['profile_update', 'bind_phone'],
|
|
||||||
};
|
|
||||||
|
|
||||||
export const USER_LOG_CATEGORY_OPTIONS: Array<{ value: UserLogCategory | ''; label: string }> = [
|
export const USER_LOG_CATEGORY_LABELS: Record<string, string> = Object.fromEntries(
|
||||||
{ value: '', label: '全部' },
|
|
||||||
{ value: 'login', label: '登录' },
|
|
||||||
{ value: 'browse_product', label: '浏览商品' },
|
|
||||||
{ value: 'order', label: '下单' },
|
|
||||||
{ value: 'pay', label: '支付' },
|
|
||||||
{ value: 'wechat_auth', label: '微信授权' },
|
|
||||||
{ value: 'browse_store', label: '浏览门店' },
|
|
||||||
{ value: 'redeem', label: '核销' },
|
|
||||||
{ value: 'profile', label: '信息修改' },
|
|
||||||
];
|
|
||||||
|
|
||||||
export function resolveUserLogCategory(eventName: string): UserLogCategory | null {
|
|
||||||
for (const [category, events] of Object.entries(USER_LOG_EVENT_CATEGORIES) as Array<
|
|
||||||
[UserLogCategory, readonly string[]]
|
|
||||||
>) {
|
|
||||||
if (events.includes(eventName)) return category;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const USER_LOG_CATEGORY_LABELS = Object.fromEntries(
|
|
||||||
USER_LOG_CATEGORY_OPTIONS.filter((o) => o.value).map((o) => [o.value, o.label]),
|
USER_LOG_CATEGORY_OPTIONS.filter((o) => o.value).map((o) => [o.value, o.label]),
|
||||||
) as Record<string, string>;
|
);
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import type { ColumnsType } from 'antd/es/table';
|
|||||||
import type { AdminBenefitGrantRequest } from '@dukang/shared-types';
|
import type { AdminBenefitGrantRequest } from '@dukang/shared-types';
|
||||||
import { request } from '../lib/api';
|
import { request } from '../lib/api';
|
||||||
import { COUPON_STATUS_LABELS, fmtTime } from '../lib/constants';
|
import { COUPON_STATUS_LABELS, fmtTime } from '../lib/constants';
|
||||||
|
import RedeemRecordDetailDescriptions from '../components/RedeemRecordDetailDescriptions';
|
||||||
import { useAdminList } from '../lib/useAdminList';
|
import { useAdminList } from '../lib/useAdminList';
|
||||||
|
|
||||||
type Row = {
|
type Row = {
|
||||||
@@ -33,6 +34,34 @@ type Row = {
|
|||||||
order?: { orderNo: string } | null;
|
order?: { orderNo: string } | null;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
type CouponRedeemRecord = {
|
||||||
|
id: string;
|
||||||
|
redeemNo: string;
|
||||||
|
amount: number;
|
||||||
|
settleAmount: number;
|
||||||
|
couponAmount?: number;
|
||||||
|
role?: 'PRIMARY' | 'SECONDARY';
|
||||||
|
createdAt: string;
|
||||||
|
store?: { id: string; name: string; cityName?: string | null } | null;
|
||||||
|
};
|
||||||
|
|
||||||
|
type CouponRedeemSummary = {
|
||||||
|
couponNo: string;
|
||||||
|
totalAmount: number;
|
||||||
|
usedAmount: number;
|
||||||
|
balance: number;
|
||||||
|
status: string;
|
||||||
|
redeemCount: number;
|
||||||
|
redeemRecordSum: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
type CouponDetail = Row & {
|
||||||
|
redeemSummary?: CouponRedeemSummary | null;
|
||||||
|
redeemRecords?: CouponRedeemRecord[];
|
||||||
|
user?: { userNo?: string; phone?: string | null };
|
||||||
|
order?: { orderNo?: string } | null;
|
||||||
|
};
|
||||||
|
|
||||||
export default function BenefitCouponsPage() {
|
export default function BenefitCouponsPage() {
|
||||||
const [form] = Form.useForm();
|
const [form] = Form.useForm();
|
||||||
const [grantForm] = Form.useForm<AdminBenefitGrantRequest>();
|
const [grantForm] = Form.useForm<AdminBenefitGrantRequest>();
|
||||||
@@ -50,8 +79,25 @@ export default function BenefitCouponsPage() {
|
|||||||
},
|
},
|
||||||
[filters],
|
[filters],
|
||||||
);
|
);
|
||||||
const [detail, setDetail] = useState<Record<string, unknown> | null>(null);
|
const [detail, setDetail] = useState<CouponDetail | null>(null);
|
||||||
const [drawerOpen, setDrawerOpen] = useState(false);
|
const [drawerOpen, setDrawerOpen] = useState(false);
|
||||||
|
const [redeemDetail, setRedeemDetail] = useState<Record<string, unknown> | null>(null);
|
||||||
|
const [redeemDrawerOpen, setRedeemDrawerOpen] = useState(false);
|
||||||
|
const [redeemDetailLoading, setRedeemDetailLoading] = useState(false);
|
||||||
|
|
||||||
|
async function openRedeemDetail(redeemId: string) {
|
||||||
|
setRedeemDetailLoading(true);
|
||||||
|
setRedeemDrawerOpen(true);
|
||||||
|
try {
|
||||||
|
const res = await request<Record<string, unknown>>(`/admin/redeem-records/${redeemId}`);
|
||||||
|
setRedeemDetail(res);
|
||||||
|
} catch (e) {
|
||||||
|
message.error(e instanceof Error ? e.message : '加载核销详情失败');
|
||||||
|
setRedeemDrawerOpen(false);
|
||||||
|
} finally {
|
||||||
|
setRedeemDetailLoading(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const columns: ColumnsType<Row> = [
|
const columns: ColumnsType<Row> = [
|
||||||
{ title: '券号', dataIndex: 'couponNo', width: 200, ellipsis: false },
|
{ title: '券号', dataIndex: 'couponNo', width: 200, ellipsis: false },
|
||||||
@@ -197,7 +243,8 @@ export default function BenefitCouponsPage() {
|
|||||||
|
|
||||||
<Drawer
|
<Drawer
|
||||||
title="权益券详情"
|
title="权益券详情"
|
||||||
width={560}
|
width={980}
|
||||||
|
styles={{ body: { paddingBottom: 24 } }}
|
||||||
open={drawerOpen}
|
open={drawerOpen}
|
||||||
onClose={() => setDrawerOpen(false)}
|
onClose={() => setDrawerOpen(false)}
|
||||||
extra={
|
extra={
|
||||||
@@ -218,26 +265,132 @@ export default function BenefitCouponsPage() {
|
|||||||
}
|
}
|
||||||
>
|
>
|
||||||
{detail && (
|
{detail && (
|
||||||
<Descriptions column={1} bordered size="small">
|
<>
|
||||||
<Descriptions.Item label="券号">{String(detail.couponNo)}</Descriptions.Item>
|
<Descriptions column={1} bordered size="small">
|
||||||
<Descriptions.Item label="用户">
|
<Descriptions.Item label="券号">{detail.couponNo}</Descriptions.Item>
|
||||||
{String((detail.user as { userNo?: string } | undefined)?.userNo ?? '—')}
|
<Descriptions.Item label="用户">{detail.user?.userNo ?? '—'}</Descriptions.Item>
|
||||||
</Descriptions.Item>
|
<Descriptions.Item label="手机号">{detail.user?.phone ?? '—'}</Descriptions.Item>
|
||||||
<Descriptions.Item label="手机号">
|
<Descriptions.Item label="关联订单">{detail.order?.orderNo ?? '—'}</Descriptions.Item>
|
||||||
{String((detail.user as { phone?: string } | undefined)?.phone ?? '—')}
|
<Descriptions.Item label="总额">¥{Number(detail.totalAmount).toFixed(2)}</Descriptions.Item>
|
||||||
</Descriptions.Item>
|
<Descriptions.Item label="余额">¥{Number(detail.balance).toFixed(2)}</Descriptions.Item>
|
||||||
<Descriptions.Item label="关联订单">
|
<Descriptions.Item label="状态">
|
||||||
{String((detail.order as { orderNo?: string } | null | undefined)?.orderNo ?? '—')}
|
{COUPON_STATUS_LABELS[detail.status] || detail.status}
|
||||||
</Descriptions.Item>
|
</Descriptions.Item>
|
||||||
<Descriptions.Item label="总额">¥{String(detail.totalAmount)}</Descriptions.Item>
|
<Descriptions.Item label="来源">{detail.sourceProduct}</Descriptions.Item>
|
||||||
<Descriptions.Item label="余额">¥{String(detail.balance)}</Descriptions.Item>
|
</Descriptions>
|
||||||
<Descriptions.Item label="状态">
|
|
||||||
{COUPON_STATUS_LABELS[String(detail.status)] || String(detail.status)}
|
<Typography.Title level={5} style={{ marginTop: 16, marginBottom: 8 }}>
|
||||||
</Descriptions.Item>
|
权益核销
|
||||||
<Descriptions.Item label="来源">{String(detail.sourceProduct)}</Descriptions.Item>
|
</Typography.Title>
|
||||||
</Descriptions>
|
{detail.redeemSummary ? (
|
||||||
|
<>
|
||||||
|
<Descriptions column={2} bordered size="small" style={{ marginBottom: 12 }}>
|
||||||
|
<Descriptions.Item label="权益券号">{detail.redeemSummary.couponNo}</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="券状态">{detail.redeemSummary.status}</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="权益总额">
|
||||||
|
¥{Number(detail.redeemSummary.totalAmount).toFixed(2)}
|
||||||
|
</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="已核销">
|
||||||
|
<Typography.Text type="danger" strong>
|
||||||
|
¥{Number(detail.redeemSummary.usedAmount).toFixed(2)}
|
||||||
|
</Typography.Text>
|
||||||
|
<Typography.Text type="secondary" style={{ marginLeft: 8 }}>
|
||||||
|
({detail.redeemSummary.redeemCount} 笔核销单)
|
||||||
|
</Typography.Text>
|
||||||
|
</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="剩余余额">
|
||||||
|
¥{Number(detail.redeemSummary.balance).toFixed(2)}
|
||||||
|
</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="核销单合计额">
|
||||||
|
¥{Number(detail.redeemSummary.redeemRecordSum).toFixed(2)}
|
||||||
|
<Typography.Text type="secondary" style={{ marginLeft: 8 }}>
|
||||||
|
(本券分摊合计)
|
||||||
|
</Typography.Text>
|
||||||
|
</Descriptions.Item>
|
||||||
|
</Descriptions>
|
||||||
|
<Table
|
||||||
|
size="small"
|
||||||
|
rowKey="id"
|
||||||
|
pagination={false}
|
||||||
|
tableLayout="fixed"
|
||||||
|
locale={{ emptyText: '暂无关联核销单' }}
|
||||||
|
dataSource={detail.redeemRecords ?? []}
|
||||||
|
columns={[
|
||||||
|
{ title: '核销号', dataIndex: 'redeemNo', ellipsis: true },
|
||||||
|
{
|
||||||
|
title: '角色',
|
||||||
|
dataIndex: 'role',
|
||||||
|
width: 72,
|
||||||
|
render: (v: string | undefined) =>
|
||||||
|
v === 'SECONDARY' ? <Tag color="orange">次券</Tag> : <Tag color="blue">主券</Tag>,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '门店',
|
||||||
|
dataIndex: ['store', 'name'],
|
||||||
|
ellipsis: true,
|
||||||
|
render: (v: string | undefined, row: CouponRedeemRecord) =>
|
||||||
|
v ? `${v}${row.store?.cityName ? `(${row.store.cityName})` : ''}` : '—',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '本券分摊',
|
||||||
|
dataIndex: 'couponAmount',
|
||||||
|
width: 96,
|
||||||
|
render: (v: number | undefined, row: CouponRedeemRecord) =>
|
||||||
|
`¥${Number(v ?? row.amount).toFixed(2)}`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '核销总额',
|
||||||
|
dataIndex: 'amount',
|
||||||
|
width: 96,
|
||||||
|
render: (v: number) => `¥${Number(v).toFixed(2)}`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '结算额',
|
||||||
|
dataIndex: 'settleAmount',
|
||||||
|
width: 96,
|
||||||
|
render: (v: number) => `¥${Number(v).toFixed(2)}`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '时间',
|
||||||
|
dataIndex: 'createdAt',
|
||||||
|
width: 148,
|
||||||
|
render: (v: string) => fmtTime(v),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '操作',
|
||||||
|
width: 64,
|
||||||
|
render: (_: unknown, row: CouponRedeemRecord) => (
|
||||||
|
<Button type="link" size="small" onClick={() => void openRedeemDetail(row.id)}>
|
||||||
|
详情
|
||||||
|
</Button>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<Typography.Text type="secondary">暂无核销摘要</Typography.Text>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
)}
|
)}
|
||||||
</Drawer>
|
</Drawer>
|
||||||
|
|
||||||
|
<Drawer
|
||||||
|
title="核销单详情"
|
||||||
|
width={640}
|
||||||
|
open={redeemDrawerOpen}
|
||||||
|
onClose={() => {
|
||||||
|
setRedeemDrawerOpen(false);
|
||||||
|
setRedeemDetail(null);
|
||||||
|
}}
|
||||||
|
destroyOnClose
|
||||||
|
>
|
||||||
|
{redeemDetailLoading ? (
|
||||||
|
<Typography.Text type="secondary">加载中…</Typography.Text>
|
||||||
|
) : redeemDetail ? (
|
||||||
|
<RedeemRecordDetailDescriptions detail={redeemDetail} />
|
||||||
|
) : null}
|
||||||
|
</Drawer>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,525 @@
|
|||||||
|
import { useCallback, useEffect, useMemo, useRef, useState, type CSSProperties } from 'react';
|
||||||
|
import { request } from '../lib/api';
|
||||||
|
import sfxTier1 from '../assets/big-screen/celebrate-t1.mp3';
|
||||||
|
import sfxTier2 from '../assets/big-screen/celebrate-t2.mp3';
|
||||||
|
import sfxTier3 from '../assets/big-screen/celebrate-t3.mp3';
|
||||||
|
|
||||||
|
export type BigScreenOrder = {
|
||||||
|
id: string;
|
||||||
|
orderNo: string;
|
||||||
|
payAmount: number;
|
||||||
|
items: string;
|
||||||
|
/** 展示用时间(付款成功时间) */
|
||||||
|
createdAt: string;
|
||||||
|
paidAt?: string;
|
||||||
|
userPhoneMasked: string | null;
|
||||||
|
};
|
||||||
|
|
||||||
|
type AmountTier = 1 | 2 | 3;
|
||||||
|
|
||||||
|
const POLL_MS = 3000;
|
||||||
|
const ROW_MS = 2500;
|
||||||
|
/** 不足此条数时重复填充,保证滚动连贯 */
|
||||||
|
const MIN_SCROLL_ROWS = 10;
|
||||||
|
const FX_DURATION_MS = 10_000;
|
||||||
|
const WEEKDAYS = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];
|
||||||
|
|
||||||
|
const CELEBRATE_SFX: Record<AmountTier, string> = {
|
||||||
|
1: sfxTier1,
|
||||||
|
2: sfxTier2,
|
||||||
|
3: sfxTier3,
|
||||||
|
};
|
||||||
|
|
||||||
|
/** 浏览器自动播放策略:需用户手势后才能出声 */
|
||||||
|
let audioUnlocked = false;
|
||||||
|
const sharedAudio = typeof Audio !== 'undefined' ? new Audio() : null;
|
||||||
|
|
||||||
|
function unlockCelebrateAudio() {
|
||||||
|
if (audioUnlocked || !sharedAudio) return;
|
||||||
|
sharedAudio.muted = true;
|
||||||
|
sharedAudio.src = CELEBRATE_SFX[1];
|
||||||
|
void sharedAudio
|
||||||
|
.play()
|
||||||
|
.then(() => {
|
||||||
|
sharedAudio.pause();
|
||||||
|
sharedAudio.currentTime = 0;
|
||||||
|
sharedAudio.muted = false;
|
||||||
|
audioUnlocked = true;
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
/* 等待下次手势 */
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function playCelebrateSfx(tier: AmountTier): () => void {
|
||||||
|
if (!sharedAudio) return () => undefined;
|
||||||
|
try {
|
||||||
|
sharedAudio.pause();
|
||||||
|
sharedAudio.currentTime = 0;
|
||||||
|
sharedAudio.src = CELEBRATE_SFX[tier];
|
||||||
|
sharedAudio.volume = tier === 3 ? 0.85 : tier === 2 ? 0.75 : 0.65;
|
||||||
|
sharedAudio.muted = false;
|
||||||
|
void sharedAudio.play().catch(() => {
|
||||||
|
/* 未解锁时静默失败 */
|
||||||
|
});
|
||||||
|
} catch {
|
||||||
|
/* ignore */
|
||||||
|
}
|
||||||
|
return () => {
|
||||||
|
try {
|
||||||
|
sharedAudio.pause();
|
||||||
|
sharedAudio.currentTime = 0;
|
||||||
|
} catch {
|
||||||
|
/* ignore */
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function pad(n: number) {
|
||||||
|
return String(n).padStart(2, '0');
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatClock(d: Date) {
|
||||||
|
return `${pad(d.getHours())}:${pad(d.getMinutes())}:${pad(d.getSeconds())}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatDateLine(d: Date) {
|
||||||
|
return `${d.getFullYear()} / ${pad(d.getMonth() + 1)} / ${pad(d.getDate())} ${WEEKDAYS[d.getDay()]}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatOrderTime(iso: string): string {
|
||||||
|
try {
|
||||||
|
return formatClock(new Date(iso));
|
||||||
|
} catch {
|
||||||
|
return iso;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// function formatAmount(n: number): string {
|
||||||
|
// return Number(n || 0).toLocaleString('zh-CN', {
|
||||||
|
// minimumFractionDigits: 0,
|
||||||
|
// maximumFractionDigits: 0,
|
||||||
|
// });
|
||||||
|
// }
|
||||||
|
|
||||||
|
function formatAmount(n: number): string {
|
||||||
|
const num = Number(n || 0);
|
||||||
|
// 先保留两位小数,再分割处理
|
||||||
|
const fixed = num.toFixed(2);
|
||||||
|
const [intStr, decStr] = fixed.split('.');
|
||||||
|
const intFormatted = Number(intStr).toLocaleString('zh-CN');
|
||||||
|
return decStr === '00' ? intFormatted : `${intFormatted}.${decStr}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function amountCssClass(payAmount: number, base: string): string {
|
||||||
|
const wide = Math.floor(Math.abs(Number(payAmount || 0))) >= 100_000;
|
||||||
|
return wide ? `${base} ${base}--6d` : base;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function amountTier(payAmount: number): AmountTier {
|
||||||
|
if (payAmount >= 1000) return 3;
|
||||||
|
if (payAmount >= 500) return 2;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
function LiveClock() {
|
||||||
|
const [now, setNow] = useState(() => new Date());
|
||||||
|
useEffect(() => {
|
||||||
|
const id = setInterval(() => setNow(new Date()), 1000);
|
||||||
|
return () => clearInterval(id);
|
||||||
|
}, []);
|
||||||
|
return (
|
||||||
|
<div className="big-screen-hero">
|
||||||
|
<div className="big-screen-clock">{formatClock(now)}</div>
|
||||||
|
<div className="big-screen-date">{formatDateLine(now)}</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function OrderRow({
|
||||||
|
order,
|
||||||
|
latest,
|
||||||
|
}: {
|
||||||
|
order: BigScreenOrder;
|
||||||
|
latest?: boolean;
|
||||||
|
}) {
|
||||||
|
const tier = amountTier(order.payAmount);
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
className={`big-screen-row big-screen-row--t${tier}${latest ? ' is-latest' : ''}`}
|
||||||
|
>
|
||||||
|
{latest ? <span className="big-screen-row-mark" /> : null}
|
||||||
|
<span className={amountCssClass(order.payAmount, 'big-screen-amount')}>
|
||||||
|
¥ {formatAmount(order.payAmount)}
|
||||||
|
</span>
|
||||||
|
<span className="big-screen-items">{order.items || '—'}</span>
|
||||||
|
<span className="big-screen-time">{formatOrderTime(order.paidAt ?? order.createdAt)}</span>
|
||||||
|
<span className="big-screen-phone">{order.userPhoneMasked || '—'}</span>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
type Particle = {
|
||||||
|
x: number;
|
||||||
|
y: number;
|
||||||
|
vx: number;
|
||||||
|
vy: number;
|
||||||
|
rot: number;
|
||||||
|
vr: number;
|
||||||
|
w: number;
|
||||||
|
h: number;
|
||||||
|
color: string;
|
||||||
|
life: number;
|
||||||
|
kind: 'rect' | 'ribbon' | 'spark';
|
||||||
|
rain?: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
const TIER_COLORS: Record<AmountTier, string[]> = {
|
||||||
|
1: ['#e6f7ff', '#91d5ff', '#40a9ff', '#ffffff', '#69c0ff'],
|
||||||
|
2: ['#fff1b8', '#ffe58f', '#ffd666', '#fffbe6', '#ffe7ba'],
|
||||||
|
3: ['#ffd666', '#faad14', '#ffec3d', '#fff1b8', '#ff4d4f', '#ff7a45', '#ffffff'],
|
||||||
|
};
|
||||||
|
|
||||||
|
function spawnParticles(tier: AmountTier, w: number, h: number): Particle[] {
|
||||||
|
const colors = TIER_COLORS[tier];
|
||||||
|
const count = tier === 3 ? 180 : tier === 2 ? 110 : 70;
|
||||||
|
const out: Particle[] = [];
|
||||||
|
const cx = w / 2;
|
||||||
|
const cy = h * 0.42;
|
||||||
|
for (let i = 0; i < count; i++) {
|
||||||
|
const angle = Math.random() * Math.PI * 2;
|
||||||
|
const speed = (tier === 3 ? 8 : tier === 2 ? 6 : 4) * (0.4 + Math.random());
|
||||||
|
const kind: Particle['kind'] =
|
||||||
|
tier === 3 && Math.random() < 0.25 ? 'ribbon' : Math.random() < 0.2 ? 'spark' : 'rect';
|
||||||
|
out.push({
|
||||||
|
x: cx + (Math.random() - 0.5) * 80,
|
||||||
|
y: cy + (Math.random() - 0.5) * 40,
|
||||||
|
vx: Math.cos(angle) * speed,
|
||||||
|
vy: Math.sin(angle) * speed - (tier === 3 ? 6 : 3),
|
||||||
|
rot: Math.random() * 360,
|
||||||
|
vr: (Math.random() - 0.5) * 18,
|
||||||
|
w: kind === 'ribbon' ? 10 + Math.random() * 16 : kind === 'spark' ? 2 : 6 + Math.random() * 8,
|
||||||
|
h: kind === 'ribbon' ? 28 + Math.random() * 24 : kind === 'spark' ? 10 + Math.random() * 8 : 4 + Math.random() * 6,
|
||||||
|
color: colors[Math.floor(Math.random() * colors.length)],
|
||||||
|
life: 1,
|
||||||
|
kind,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (tier >= 2) {
|
||||||
|
for (let i = 0; i < (tier === 3 ? 80 : 40); i++) {
|
||||||
|
out.push({
|
||||||
|
x: Math.random() * w,
|
||||||
|
y: -20 - Math.random() * 80,
|
||||||
|
vx: (Math.random() - 0.5) * 1.4,
|
||||||
|
vy: 3 + Math.random() * 5,
|
||||||
|
rot: Math.random() * 360,
|
||||||
|
vr: (Math.random() - 0.5) * 10,
|
||||||
|
w: 5 + Math.random() * 8,
|
||||||
|
h: 10 + Math.random() * 14,
|
||||||
|
color: colors[Math.floor(Math.random() * colors.length)],
|
||||||
|
life: 1,
|
||||||
|
kind: 'rect',
|
||||||
|
rain: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
function CelebrateFx({ order, onDone }: { order: BigScreenOrder; onDone: () => void }) {
|
||||||
|
const canvasRef = useRef<HTMLCanvasElement | null>(null);
|
||||||
|
const onDoneRef = useRef(onDone);
|
||||||
|
onDoneRef.current = onDone;
|
||||||
|
const tier = amountTier(order.payAmount);
|
||||||
|
const [displayAmount, setDisplayAmount] = useState(tier === 3 ? 0 : order.payAmount);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const timer = window.setTimeout(() => onDoneRef.current(), FX_DURATION_MS);
|
||||||
|
return () => window.clearTimeout(timer);
|
||||||
|
}, [order.id]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const stop = playCelebrateSfx(tier);
|
||||||
|
return stop;
|
||||||
|
}, [order.id, tier]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (tier !== 3) return;
|
||||||
|
const start = performance.now();
|
||||||
|
const dur = 900;
|
||||||
|
let raf = 0;
|
||||||
|
const tick = (now: number) => {
|
||||||
|
const p = Math.min(1, (now - start) / dur);
|
||||||
|
const eased = 1 - (1 - p) ** 3;
|
||||||
|
setDisplayAmount(Math.round(order.payAmount * eased));
|
||||||
|
if (p < 1) raf = requestAnimationFrame(tick);
|
||||||
|
};
|
||||||
|
raf = requestAnimationFrame(tick);
|
||||||
|
return () => cancelAnimationFrame(raf);
|
||||||
|
}, [order.payAmount, order.id, tier]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const canvas = canvasRef.current;
|
||||||
|
if (!canvas) return;
|
||||||
|
const ctx = canvas.getContext('2d');
|
||||||
|
if (!ctx) return;
|
||||||
|
const resize = () => {
|
||||||
|
canvas.width = canvas.clientWidth * devicePixelRatio;
|
||||||
|
canvas.height = canvas.clientHeight * devicePixelRatio;
|
||||||
|
ctx.setTransform(devicePixelRatio, 0, 0, devicePixelRatio, 0, 0);
|
||||||
|
};
|
||||||
|
resize();
|
||||||
|
const particles = spawnParticles(tier, canvas.clientWidth, canvas.clientHeight);
|
||||||
|
let raf = 0;
|
||||||
|
let last = performance.now();
|
||||||
|
const started = performance.now();
|
||||||
|
const gravity = tier === 3 ? 0.18 : 0.14;
|
||||||
|
const loop = (now: number) => {
|
||||||
|
const dt = Math.min(32, now - last) / 16.6;
|
||||||
|
last = now;
|
||||||
|
ctx.clearRect(0, 0, canvas.clientWidth, canvas.clientHeight);
|
||||||
|
for (const p of particles) {
|
||||||
|
p.vy += gravity * dt;
|
||||||
|
p.x += p.vx * dt;
|
||||||
|
p.y += p.vy * dt;
|
||||||
|
p.rot += p.vr * dt;
|
||||||
|
p.life -= (tier === 3 ? 0.002 : 0.003) * dt;
|
||||||
|
if (
|
||||||
|
p.rain &&
|
||||||
|
(p.y > canvas.clientHeight + 30 || p.life <= 0) &&
|
||||||
|
now - started < FX_DURATION_MS - 400
|
||||||
|
) {
|
||||||
|
p.x = Math.random() * canvas.clientWidth;
|
||||||
|
p.y = -16 - Math.random() * 60;
|
||||||
|
p.vx = (Math.random() - 0.5) * 1.4;
|
||||||
|
p.vy = 3 + Math.random() * 5;
|
||||||
|
p.life = 1;
|
||||||
|
}
|
||||||
|
if (p.life <= 0) continue;
|
||||||
|
ctx.save();
|
||||||
|
ctx.translate(p.x, p.y);
|
||||||
|
ctx.rotate((p.rot * Math.PI) / 180);
|
||||||
|
ctx.globalAlpha = Math.max(0, p.life);
|
||||||
|
ctx.fillStyle = p.color;
|
||||||
|
if (p.kind === 'spark') {
|
||||||
|
ctx.fillRect(-p.w / 2, -p.h / 2, p.w, p.h);
|
||||||
|
} else {
|
||||||
|
ctx.fillRect(-p.w / 2, -p.h / 2, p.w, p.h);
|
||||||
|
}
|
||||||
|
ctx.restore();
|
||||||
|
}
|
||||||
|
raf = requestAnimationFrame(loop);
|
||||||
|
};
|
||||||
|
raf = requestAnimationFrame(loop);
|
||||||
|
const onResize = () => resize();
|
||||||
|
window.addEventListener('resize', onResize);
|
||||||
|
return () => {
|
||||||
|
cancelAnimationFrame(raf);
|
||||||
|
window.removeEventListener('resize', onResize);
|
||||||
|
};
|
||||||
|
}, [order.id, tier]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className={`big-screen-fx big-screen-fx--t${tier}`} role="presentation">
|
||||||
|
<canvas ref={canvasRef} className="big-screen-fx-canvas" />
|
||||||
|
{tier === 3 ? <div className="big-screen-fx-shock" /> : null}
|
||||||
|
{tier === 3 ? <div className="big-screen-fx-shock big-screen-fx-shock--late" /> : null}
|
||||||
|
{tier >= 2 ? <div className="big-screen-fx-sweep" /> : null}
|
||||||
|
{tier >= 2 ? <div className="big-screen-fx-sweep big-screen-fx-sweep--alt" /> : null}
|
||||||
|
<div className={`big-screen-fx-card big-screen-fx-card--t${tier}`}>
|
||||||
|
<div className="big-screen-fx-kicker">{tier === 3 ? '高额成交' : tier === 2 ? '大额成交' : '新成交'}</div>
|
||||||
|
<div className={amountCssClass(displayAmount || order.payAmount, 'big-screen-fx-amount')}>
|
||||||
|
¥ {formatAmount(displayAmount)}
|
||||||
|
</div>
|
||||||
|
<div className="big-screen-fx-items">{order.items || '—'}</div>
|
||||||
|
<div className="big-screen-fx-meta">
|
||||||
|
<span>{order.userPhoneMasked || '—'}</span>
|
||||||
|
<span>{formatOrderTime(order.paidAt ?? order.createdAt)}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function BigScreenPage() {
|
||||||
|
const [items, setItems] = useState<BigScreenOrder[]>([]);
|
||||||
|
const [loadError, setLoadError] = useState('');
|
||||||
|
const [paused, setPaused] = useState(false);
|
||||||
|
const [celebrate, setCelebrate] = useState<BigScreenOrder | null>(null);
|
||||||
|
const seenIdsRef = useRef<Set<string> | null>(null);
|
||||||
|
const celebratedIdsRef = useRef<Set<string>>(new Set());
|
||||||
|
const queueRef = useRef<BigScreenOrder[]>([]);
|
||||||
|
const celebratingRef = useRef(false);
|
||||||
|
const viewportRef = useRef<HTMLDivElement | null>(null);
|
||||||
|
const dayKeyRef = useRef('');
|
||||||
|
const [viewportH, setViewportH] = useState(0);
|
||||||
|
|
||||||
|
const playNext = useCallback(() => {
|
||||||
|
const next = queueRef.current.shift() ?? null;
|
||||||
|
celebratingRef.current = !!next;
|
||||||
|
setCelebrate(next);
|
||||||
|
setPaused(!!next);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const enqueueNew = useCallback(
|
||||||
|
(fresh: BigScreenOrder[]) => {
|
||||||
|
const toCelebrate = fresh.filter((o) => !celebratedIdsRef.current.has(o.id));
|
||||||
|
if (!toCelebrate.length) return;
|
||||||
|
for (const o of toCelebrate) celebratedIdsRef.current.add(o.id);
|
||||||
|
const ranked = [...toCelebrate].sort((a, b) => {
|
||||||
|
const td = amountTier(b.payAmount) - amountTier(a.payAmount);
|
||||||
|
if (td !== 0) return td;
|
||||||
|
return +new Date(b.paidAt ?? b.createdAt) - +new Date(a.paidAt ?? a.createdAt);
|
||||||
|
});
|
||||||
|
queueRef.current.push(...ranked);
|
||||||
|
if (!celebratingRef.current) playNext();
|
||||||
|
},
|
||||||
|
[playNext],
|
||||||
|
);
|
||||||
|
|
||||||
|
const fetchData = useCallback(() => {
|
||||||
|
const now = new Date();
|
||||||
|
const todayKey = `${now.getFullYear()}-${pad(now.getMonth() + 1)}-${pad(now.getDate())}`;
|
||||||
|
if (dayKeyRef.current && dayKeyRef.current !== todayKey) {
|
||||||
|
seenIdsRef.current = null;
|
||||||
|
celebratedIdsRef.current = new Set();
|
||||||
|
queueRef.current = [];
|
||||||
|
celebratingRef.current = false;
|
||||||
|
setCelebrate(null);
|
||||||
|
setPaused(false);
|
||||||
|
}
|
||||||
|
dayKeyRef.current = todayKey;
|
||||||
|
|
||||||
|
return request<{ items: BigScreenOrder[] }>('/admin/orders/big-screen?limit=2000')
|
||||||
|
.then((d) => {
|
||||||
|
const list = d.items ?? [];
|
||||||
|
setItems(list);
|
||||||
|
setLoadError('');
|
||||||
|
const seen = seenIdsRef.current;
|
||||||
|
if (!seen) {
|
||||||
|
seenIdsRef.current = new Set(list.map((o) => o.id));
|
||||||
|
for (const o of list) celebratedIdsRef.current.add(o.id);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const fresh = list.filter((o) => !seen.has(o.id));
|
||||||
|
for (const o of fresh) seen.add(o.id);
|
||||||
|
enqueueNew(fresh);
|
||||||
|
})
|
||||||
|
.catch((e) => {
|
||||||
|
setLoadError(e instanceof Error ? e.message : '加载失败');
|
||||||
|
});
|
||||||
|
}, [enqueueNew]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
void fetchData();
|
||||||
|
const id = setInterval(() => void fetchData(), POLL_MS);
|
||||||
|
return () => clearInterval(id);
|
||||||
|
}, [fetchData]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
unlockCelebrateAudio();
|
||||||
|
const unlock = () => unlockCelebrateAudio();
|
||||||
|
window.addEventListener('pointerdown', unlock, { once: true });
|
||||||
|
window.addEventListener('keydown', unlock, { once: true });
|
||||||
|
return () => {
|
||||||
|
window.removeEventListener('pointerdown', unlock);
|
||||||
|
window.removeEventListener('keydown', unlock);
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const html = document.documentElement;
|
||||||
|
const prevHtml = html.style.overflow;
|
||||||
|
const prevBody = document.body.style.overflow;
|
||||||
|
html.style.overflow = 'hidden';
|
||||||
|
document.body.style.overflow = 'hidden';
|
||||||
|
return () => {
|
||||||
|
html.style.overflow = prevHtml;
|
||||||
|
document.body.style.overflow = prevBody;
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const el = viewportRef.current;
|
||||||
|
if (!el) return;
|
||||||
|
const measure = () => setViewportH(el.clientHeight);
|
||||||
|
measure();
|
||||||
|
const ro = new ResizeObserver(measure);
|
||||||
|
ro.observe(el);
|
||||||
|
return () => ro.disconnect();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const unitItems = useMemo(() => {
|
||||||
|
if (!items.length) return [];
|
||||||
|
const rowH = 80;
|
||||||
|
const visible = Math.max(1, Math.ceil((viewportH || 480) / rowH));
|
||||||
|
const minCount = Math.max(MIN_SCROLL_ROWS, visible + 1);
|
||||||
|
const unit: BigScreenOrder[] = [];
|
||||||
|
while (unit.length < minCount) unit.push(...items);
|
||||||
|
return unit;
|
||||||
|
}, [items, viewportH]);
|
||||||
|
|
||||||
|
const trackItems = useMemo(() => unitItems.concat(unitItems), [unitItems]);
|
||||||
|
const marqueeMs = Math.max(unitItems.length, 1) * ROW_MS;
|
||||||
|
const rolling = items.length > 0 && unitItems.length > 0;
|
||||||
|
const latestId = items[0]?.id;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="big-screen-page">
|
||||||
|
<div className="big-screen-stars" aria-hidden />
|
||||||
|
<div className="big-screen-frame" aria-hidden>
|
||||||
|
<span className="big-screen-corner big-screen-corner--tl" />
|
||||||
|
<span className="big-screen-corner big-screen-corner--tr" />
|
||||||
|
<span className="big-screen-corner big-screen-corner--bl" />
|
||||||
|
<span className="big-screen-corner big-screen-corner--br" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<header className="big-screen-header">
|
||||||
|
<div className="big-screen-brand">
|
||||||
|
<h1 className="big-screen-title">杜康好客</h1>
|
||||||
|
<span className="big-screen-subtitle">· 发布会现场</span>
|
||||||
|
</div>
|
||||||
|
<div className="big-screen-live-wrap">
|
||||||
|
<span className="big-screen-live-label">实时成交</span>
|
||||||
|
<span className="big-screen-live">
|
||||||
|
<span className="big-screen-live-dot" />
|
||||||
|
LIVE
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<LiveClock />
|
||||||
|
|
||||||
|
<div className="big-screen-list">
|
||||||
|
<div className="big-screen-list-body" ref={viewportRef}>
|
||||||
|
{items.length === 0 ? null : (
|
||||||
|
<div
|
||||||
|
className={`big-screen-track${rolling ? ' is-rolling' : ''}${paused ? ' is-paused' : ''}`}
|
||||||
|
style={rolling ? ({ ['--marquee-ms']: `${marqueeMs}ms` } as CSSProperties) : undefined}
|
||||||
|
>
|
||||||
|
{trackItems.map((o, idx) => (
|
||||||
|
<OrderRow
|
||||||
|
key={`${o.id}-${idx}`}
|
||||||
|
order={o}
|
||||||
|
latest={idx % items.length === 0 && o.id === latestId}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{items.length === 0 ? (
|
||||||
|
<div className="big-screen-empty">{loadError || '当日暂无订单'}</div>
|
||||||
|
) : null}
|
||||||
|
|
||||||
|
{celebrate ? (
|
||||||
|
<CelebrateFx
|
||||||
|
key={celebrate.id}
|
||||||
|
order={celebrate}
|
||||||
|
onDone={playNext}
|
||||||
|
/>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
import { useCallback, useEffect, useState } from 'react';
|
import { useCallback, useEffect, useState } from 'react';
|
||||||
|
import { Link } from 'react-router-dom';
|
||||||
import {
|
import {
|
||||||
Button,
|
Button,
|
||||||
Descriptions,
|
Descriptions,
|
||||||
@@ -17,7 +18,7 @@ import {
|
|||||||
} from 'antd';
|
} from 'antd';
|
||||||
import type { ColumnsType } from 'antd/es/table';
|
import type { ColumnsType } from 'antd/es/table';
|
||||||
import { WAREHOUSE_MANAGER_LABELS, WarehouseManagerType } from '@dukang/shared-types';
|
import { WAREHOUSE_MANAGER_LABELS, WarehouseManagerType } from '@dukang/shared-types';
|
||||||
import { request, type Paginated } from '../lib/api';
|
import { request, type HqProfile, type Paginated } from '../lib/api';
|
||||||
import { parseProvinceCityCodes, type ParsedProvinceCity } from '../lib/china-region';
|
import { parseProvinceCityCodes, type ParsedProvinceCity } from '../lib/china-region';
|
||||||
import { ADMIN_OPTIONS_PAGE_SIZE, CITY_STATUS_LABELS, fmtTime } from '../lib/constants';
|
import { ADMIN_OPTIONS_PAGE_SIZE, CITY_STATUS_LABELS, fmtTime } from '../lib/constants';
|
||||||
import { useAdminList } from '../lib/useAdminList';
|
import { useAdminList } from '../lib/useAdminList';
|
||||||
@@ -50,6 +51,40 @@ type Row = {
|
|||||||
|
|
||||||
type PartnerOption = { id: string; companyName: string; cityId?: string | null };
|
type PartnerOption = { id: string; companyName: string; cityId?: string | null };
|
||||||
|
|
||||||
|
type CityDeletePreview = {
|
||||||
|
city: { id: string; code: string; name: string; province: string; status: string };
|
||||||
|
canDelete: boolean;
|
||||||
|
blockers: string[];
|
||||||
|
warnings: string[];
|
||||||
|
summary: {
|
||||||
|
primaryPartnerCount: number;
|
||||||
|
staffCount: number;
|
||||||
|
storeCount: number;
|
||||||
|
warehouseCount: number;
|
||||||
|
orderCount: number;
|
||||||
|
redeemCount: number;
|
||||||
|
partnerBillCount: number;
|
||||||
|
};
|
||||||
|
partners: Array<{
|
||||||
|
id: string;
|
||||||
|
phone: string;
|
||||||
|
name: string;
|
||||||
|
companyName?: string | null;
|
||||||
|
status: string;
|
||||||
|
staff: Array<{ id: string; phone: string; name: string; staffRole?: string | null }>;
|
||||||
|
}>;
|
||||||
|
orphanStaff: Array<{ id: string; phone: string; name: string }>;
|
||||||
|
stores: Array<{
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
phone: string;
|
||||||
|
status: string;
|
||||||
|
address: string;
|
||||||
|
partnerAccount?: { companyName?: string | null; phone?: string } | null;
|
||||||
|
}>;
|
||||||
|
warehouses: Array<{ id: string; name: string; status: string; address: string }>;
|
||||||
|
};
|
||||||
|
|
||||||
const MANAGER_OPTIONS = Object.entries(WAREHOUSE_MANAGER_LABELS).map(([value, label]) => ({ value, label }));
|
const MANAGER_OPTIONS = Object.entries(WAREHOUSE_MANAGER_LABELS).map(([value, label]) => ({ value, label }));
|
||||||
|
|
||||||
export default function CitiesPage() {
|
export default function CitiesPage() {
|
||||||
@@ -82,6 +117,18 @@ export default function CitiesPage() {
|
|||||||
const createRegionCodes = Form.useWatch('regionCodes', createForm);
|
const createRegionCodes = Form.useWatch('regionCodes', createForm);
|
||||||
const [warehouseManagerType, setWarehouseManagerType] = useState<WarehouseManagerType>(WarehouseManagerType.HQ);
|
const [warehouseManagerType, setWarehouseManagerType] = useState<WarehouseManagerType>(WarehouseManagerType.HQ);
|
||||||
const [editWarehouseManagerType, setEditWarehouseManagerType] = useState<WarehouseManagerType>(WarehouseManagerType.HQ);
|
const [editWarehouseManagerType, setEditWarehouseManagerType] = useState<WarehouseManagerType>(WarehouseManagerType.HQ);
|
||||||
|
const [deleteOpen, setDeleteOpen] = useState(false);
|
||||||
|
const [deleteLoading, setDeleteLoading] = useState(false);
|
||||||
|
const [deleteSubmitting, setDeleteSubmitting] = useState(false);
|
||||||
|
const [deleteTarget, setDeleteTarget] = useState<Row | null>(null);
|
||||||
|
const [deletePreview, setDeletePreview] = useState<CityDeletePreview | null>(null);
|
||||||
|
const [confirmName, setConfirmName] = useState('');
|
||||||
|
const [profile, setProfile] = useState<HqProfile | null>(null);
|
||||||
|
const canDeleteCities = (profile?.permissionKeys ?? []).includes('cities_delete');
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
request<HqProfile>('/admin/auth/me').then(setProfile).catch(() => {});
|
||||||
|
}, []);
|
||||||
|
|
||||||
const loadPartners = useCallback(async (cityId: string) => {
|
const loadPartners = useCallback(async (cityId: string) => {
|
||||||
const res = await request<Paginated<PartnerOption>>(`/admin/partners?pageSize=${ADMIN_OPTIONS_PAGE_SIZE}&cityId=${cityId}`);
|
const res = await request<Paginated<PartnerOption>>(`/admin/partners?pageSize=${ADMIN_OPTIONS_PAGE_SIZE}&cityId=${cityId}`);
|
||||||
@@ -129,22 +176,85 @@ export default function CitiesPage() {
|
|||||||
setDrawerOpen(true);
|
setDrawerOpen(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const openDelete = async (row: Row) => {
|
||||||
|
setDeleteTarget(row);
|
||||||
|
setDeletePreview(null);
|
||||||
|
setConfirmName('');
|
||||||
|
setDeleteOpen(true);
|
||||||
|
setDeleteLoading(true);
|
||||||
|
try {
|
||||||
|
const preview = await request<CityDeletePreview>(`/admin/cities/${row.id}/delete-preview`);
|
||||||
|
setDeletePreview(preview);
|
||||||
|
} catch (e) {
|
||||||
|
message.error(e instanceof Error ? e.message : '加载删除预览失败');
|
||||||
|
setDeleteOpen(false);
|
||||||
|
} finally {
|
||||||
|
setDeleteLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const confirmDelete = async () => {
|
||||||
|
if (!deleteTarget || !deletePreview) return;
|
||||||
|
if (!deletePreview.canDelete) {
|
||||||
|
message.error(deletePreview.blockers.join(';') || '当前城市不可删除');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (confirmName.trim() !== deletePreview.city.name) {
|
||||||
|
message.warning(`请输入城市名称「${deletePreview.city.name}」确认删除`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setDeleteSubmitting(true);
|
||||||
|
try {
|
||||||
|
await request(`/admin/cities/${deleteTarget.id}`, {
|
||||||
|
method: 'DELETE',
|
||||||
|
body: JSON.stringify({ confirmName: confirmName.trim() }),
|
||||||
|
});
|
||||||
|
message.success(`已删除城市「${deletePreview.city.name}」`);
|
||||||
|
setDeleteOpen(false);
|
||||||
|
setDeleteTarget(null);
|
||||||
|
setDeletePreview(null);
|
||||||
|
setConfirmName('');
|
||||||
|
if (detail?.id === deleteTarget.id) setDrawerOpen(false);
|
||||||
|
void reload();
|
||||||
|
} catch (e) {
|
||||||
|
message.error(e instanceof Error ? e.message : '删除失败');
|
||||||
|
} finally {
|
||||||
|
setDeleteSubmitting(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const columns: ColumnsType<Row> = [
|
const columns: ColumnsType<Row> = [
|
||||||
{ title: '编码', dataIndex: 'code', width: 90 },
|
{ title: '编码', dataIndex: 'code', width: 90 },
|
||||||
{ title: '城市', dataIndex: 'name', width: 100 },
|
{ title: '城市', dataIndex: 'name', width: 100 },
|
||||||
{ title: '省份', dataIndex: 'province', width: 90 },
|
{ title: '省份', dataIndex: 'province', width: 90 },
|
||||||
{ title: '状态', dataIndex: 'status', width: 90, render: (s) => <Tag>{CITY_STATUS_LABELS[s] || s}</Tag> },
|
{ title: '状态', dataIndex: 'status', width: 90, render: (s) => <Tag>{CITY_STATUS_LABELS[s] || s}</Tag> },
|
||||||
{ title: '合伙人', dataIndex: 'partnerBindingCount', width: 90 },
|
{ title: '合伙人', dataIndex: 'partnerBindingCount', width: 90 },
|
||||||
{ title: '门店', dataIndex: 'storeCount', width: 70 },
|
{
|
||||||
|
title: '门店',
|
||||||
|
dataIndex: 'storeCount',
|
||||||
|
width: 70,
|
||||||
|
render: (n: number, row) => (
|
||||||
|
<Link to={`/stores?cityId=${row.id}`} title={`查看「${row.name}」门店`}>
|
||||||
|
{n ?? 0}
|
||||||
|
</Link>
|
||||||
|
),
|
||||||
|
},
|
||||||
{ title: '订单', dataIndex: 'orderCount', width: 70 },
|
{ title: '订单', dataIndex: 'orderCount', width: 70 },
|
||||||
{ title: '创建', dataIndex: 'createdAt', width: 160, render: fmtTime },
|
{ title: '创建', dataIndex: 'createdAt', width: 160, render: fmtTime },
|
||||||
{
|
{
|
||||||
title: '操作',
|
title: '操作',
|
||||||
width: 80,
|
width: 140,
|
||||||
render: (_, row) => (
|
render: (_, row) => (
|
||||||
<Button type="link" size="small" onClick={() => void openDetail(row)}>
|
<Space size={0}>
|
||||||
管理
|
<Button type="link" size="small" onClick={() => void openDetail(row)}>
|
||||||
</Button>
|
管理
|
||||||
|
</Button>
|
||||||
|
{canDeleteCities ? (
|
||||||
|
<Button type="link" size="small" danger onClick={() => void openDelete(row)}>
|
||||||
|
删除
|
||||||
|
</Button>
|
||||||
|
) : null}
|
||||||
|
</Space>
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
@@ -264,6 +374,26 @@ export default function CitiesPage() {
|
|||||||
setDetail(refreshed);
|
setDetail(refreshed);
|
||||||
void reload();
|
void reload();
|
||||||
}}>保存</Button>
|
}}>保存</Button>
|
||||||
|
{canDeleteCities ? (
|
||||||
|
<Button
|
||||||
|
danger
|
||||||
|
style={{ marginLeft: 8 }}
|
||||||
|
onClick={() =>
|
||||||
|
void openDelete({
|
||||||
|
id: String(detail.id),
|
||||||
|
code: String(detail.code),
|
||||||
|
name: String(detail.name),
|
||||||
|
province: String(detail.province),
|
||||||
|
status: String(detail.status),
|
||||||
|
storeCount: Number(detail.storeCount ?? 0),
|
||||||
|
orderCount: Number(detail.orderCount ?? 0),
|
||||||
|
createdAt: String(detail.createdAt ?? ''),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
>
|
||||||
|
删除城市
|
||||||
|
</Button>
|
||||||
|
) : null}
|
||||||
</Form>
|
</Form>
|
||||||
</>
|
</>
|
||||||
),
|
),
|
||||||
@@ -274,6 +404,7 @@ export default function CitiesPage() {
|
|||||||
children: detail?.id ? (
|
children: detail?.id ? (
|
||||||
<CityPartnersPanel
|
<CityPartnersPanel
|
||||||
cityId={String(detail.id)}
|
cityId={String(detail.id)}
|
||||||
|
cityCode={detail.code != null ? String(detail.code) : undefined}
|
||||||
maxPartnerCommissionRate={
|
maxPartnerCommissionRate={
|
||||||
detail.maxPartnerCommissionRate != null
|
detail.maxPartnerCommissionRate != null
|
||||||
? Number(detail.maxPartnerCommissionRate)
|
? Number(detail.maxPartnerCommissionRate)
|
||||||
@@ -406,6 +537,140 @@ export default function CitiesPage() {
|
|||||||
</Form.Item>
|
</Form.Item>
|
||||||
</Form>
|
</Form>
|
||||||
</Modal>
|
</Modal>
|
||||||
|
|
||||||
|
<Modal
|
||||||
|
title={deleteTarget ? `删除城市「${deleteTarget.name}」` : '删除城市'}
|
||||||
|
open={deleteOpen}
|
||||||
|
onCancel={() => {
|
||||||
|
if (deleteSubmitting) return;
|
||||||
|
setDeleteOpen(false);
|
||||||
|
}}
|
||||||
|
okText="确认删除"
|
||||||
|
okButtonProps={{
|
||||||
|
danger: true,
|
||||||
|
disabled:
|
||||||
|
!deletePreview?.canDelete ||
|
||||||
|
!deletePreview ||
|
||||||
|
confirmName.trim() !== (deletePreview?.city.name ?? ''),
|
||||||
|
loading: deleteSubmitting,
|
||||||
|
}}
|
||||||
|
confirmLoading={deleteSubmitting}
|
||||||
|
onOk={() => void confirmDelete()}
|
||||||
|
width={720}
|
||||||
|
destroyOnClose
|
||||||
|
>
|
||||||
|
{deleteLoading || !deletePreview ? (
|
||||||
|
<Typography.Text type="secondary">正在加载关联数据…</Typography.Text>
|
||||||
|
) : (
|
||||||
|
<Space direction="vertical" size="middle" style={{ width: '100%' }}>
|
||||||
|
<Descriptions size="small" bordered column={2}>
|
||||||
|
<Descriptions.Item label="编码">{deletePreview.city.code}</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="省份">{deletePreview.city.province}</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="合伙人主账号">{deletePreview.summary.primaryPartnerCount}</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="子账号">{deletePreview.summary.staffCount}</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="门店">{deletePreview.summary.storeCount}</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="仓库">{deletePreview.summary.warehouseCount}</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="订单">{deletePreview.summary.orderCount}</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="核销">{deletePreview.summary.redeemCount}</Descriptions.Item>
|
||||||
|
</Descriptions>
|
||||||
|
|
||||||
|
{deletePreview.blockers.length > 0 && (
|
||||||
|
<Typography.Paragraph type="danger" style={{ marginBottom: 0 }}>
|
||||||
|
{deletePreview.blockers.map((b) => (
|
||||||
|
<div key={b}>• {b}</div>
|
||||||
|
))}
|
||||||
|
</Typography.Paragraph>
|
||||||
|
)}
|
||||||
|
{deletePreview.warnings.length > 0 && (
|
||||||
|
<Typography.Paragraph type="warning" style={{ marginBottom: 0 }}>
|
||||||
|
{deletePreview.warnings.map((w) => (
|
||||||
|
<div key={w}>• {w}</div>
|
||||||
|
))}
|
||||||
|
</Typography.Paragraph>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<Typography.Text strong>合伙人及子账号</Typography.Text>
|
||||||
|
<Table
|
||||||
|
size="small"
|
||||||
|
style={{ marginTop: 8 }}
|
||||||
|
pagination={false}
|
||||||
|
rowKey="id"
|
||||||
|
locale={{ emptyText: '无合伙人' }}
|
||||||
|
dataSource={deletePreview.partners.flatMap((p) => [
|
||||||
|
{
|
||||||
|
id: p.id,
|
||||||
|
kind: '主账号',
|
||||||
|
name: p.companyName || p.name,
|
||||||
|
phone: p.phone,
|
||||||
|
parent: '—',
|
||||||
|
},
|
||||||
|
...p.staff.map((s) => ({
|
||||||
|
id: s.id,
|
||||||
|
kind: '子账号',
|
||||||
|
name: s.name,
|
||||||
|
phone: s.phone,
|
||||||
|
parent: p.companyName || p.name,
|
||||||
|
})),
|
||||||
|
]).concat(
|
||||||
|
deletePreview.orphanStaff.map((s) => ({
|
||||||
|
id: s.id,
|
||||||
|
kind: '子账号',
|
||||||
|
name: s.name,
|
||||||
|
phone: s.phone,
|
||||||
|
parent: '(无主账号)',
|
||||||
|
})),
|
||||||
|
)}
|
||||||
|
columns={[
|
||||||
|
{ title: '类型', dataIndex: 'kind', width: 80 },
|
||||||
|
{ title: '名称', dataIndex: 'name', ellipsis: true },
|
||||||
|
{ title: '手机号', dataIndex: 'phone', width: 120 },
|
||||||
|
{ title: '归属', dataIndex: 'parent', ellipsis: true },
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<Typography.Text strong>门店</Typography.Text>
|
||||||
|
<Table
|
||||||
|
size="small"
|
||||||
|
style={{ marginTop: 8 }}
|
||||||
|
pagination={false}
|
||||||
|
rowKey="id"
|
||||||
|
locale={{ emptyText: '无门店' }}
|
||||||
|
dataSource={deletePreview.stores}
|
||||||
|
columns={[
|
||||||
|
{ title: '门店名', dataIndex: 'name', ellipsis: true },
|
||||||
|
{ title: '电话', dataIndex: 'phone', width: 120 },
|
||||||
|
{ title: '状态', dataIndex: 'status', width: 90 },
|
||||||
|
{
|
||||||
|
title: '合伙人',
|
||||||
|
width: 140,
|
||||||
|
ellipsis: true,
|
||||||
|
render: (_, r) => r.partnerAccount?.companyName || r.partnerAccount?.phone || '—',
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{deletePreview.canDelete ? (
|
||||||
|
<Form.Item
|
||||||
|
label={`请输入城市名称「${deletePreview.city.name}」确认删除`}
|
||||||
|
style={{ marginBottom: 0 }}
|
||||||
|
>
|
||||||
|
<Input
|
||||||
|
value={confirmName}
|
||||||
|
placeholder={deletePreview.city.name}
|
||||||
|
onChange={(e) => setConfirmName(e.target.value)}
|
||||||
|
disabled={deleteSubmitting}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
) : (
|
||||||
|
<Typography.Text type="secondary">存在阻断项,无法删除。请先处理订单等关联数据。</Typography.Text>
|
||||||
|
)}
|
||||||
|
</Space>
|
||||||
|
)}
|
||||||
|
</Modal>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ import { Link } from 'react-router-dom';
|
|||||||
import {
|
import {
|
||||||
Alert,
|
Alert,
|
||||||
Button,
|
Button,
|
||||||
Cascader,
|
|
||||||
Checkbox,
|
Checkbox,
|
||||||
Descriptions,
|
Descriptions,
|
||||||
Drawer,
|
Drawer,
|
||||||
@@ -32,9 +31,10 @@ import {
|
|||||||
type PartnerPermissionKey,
|
type PartnerPermissionKey,
|
||||||
} from '@dukang/shared-types';
|
} from '@dukang/shared-types';
|
||||||
import { request, type Paginated } from '../lib/api';
|
import { request, type Paginated } from '../lib/api';
|
||||||
import { CHINA_REGION_OPTIONS } from '../lib/china-region';
|
import { districtCodeLabel, formatDistrictLabels } from '../lib/china-region';
|
||||||
import { ADMIN_OPTIONS_PAGE_SIZE, fmtTime } from '../lib/constants';
|
import { ADMIN_OPTIONS_PAGE_SIZE, fmtTime } from '../lib/constants';
|
||||||
import { useAdminList } from '../lib/useAdminList';
|
import { useAdminList } from '../lib/useAdminList';
|
||||||
|
import CityDistrictMultiSelect from '../components/CityDistrictMultiSelect';
|
||||||
import PartnerSubAccountList, { type PartnerSubAccountRow } from '../components/PartnerSubAccountList';
|
import PartnerSubAccountList, { type PartnerSubAccountRow } from '../components/PartnerSubAccountList';
|
||||||
|
|
||||||
type SubRow = PartnerSubAccountRow;
|
type SubRow = PartnerSubAccountRow;
|
||||||
@@ -48,6 +48,7 @@ type Row = {
|
|||||||
cityId?: string | null;
|
cityId?: string | null;
|
||||||
cityName?: string | null;
|
cityName?: string | null;
|
||||||
scopeType?: string;
|
scopeType?: string;
|
||||||
|
districtCodes?: string[] | null;
|
||||||
orderCommissionRate?: number;
|
orderCommissionRate?: number;
|
||||||
redeemCommissionRate?: number;
|
redeemCommissionRate?: number;
|
||||||
bindingStatus?: string;
|
bindingStatus?: string;
|
||||||
@@ -58,6 +59,7 @@ type Row = {
|
|||||||
accountCount: number;
|
accountCount: number;
|
||||||
subAccounts?: SubRow[];
|
subAccounts?: SubRow[];
|
||||||
createdAt: string;
|
createdAt: string;
|
||||||
|
isTest?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
type PartnerDetail = Row & {
|
type PartnerDetail = Row & {
|
||||||
@@ -98,27 +100,40 @@ function flattenDistrictCodes(values: string[] | string[][] | undefined): string
|
|||||||
}
|
}
|
||||||
|
|
||||||
function commissionSumError(orderPercent: number, redeemPercent: number, maxRate: number): string | null {
|
function commissionSumError(orderPercent: number, redeemPercent: number, maxRate: number): string | null {
|
||||||
const sum = orderPercent / 100 + redeemPercent / 100;
|
// API 可能把 Prisma Decimal 序列化为字符串;`"0.05" + 1e-9` 会变成字符串拼接导致误判超限
|
||||||
if (sum > maxRate + 1e-9) {
|
const max = Number(maxRate);
|
||||||
return `订单佣金与核销佣金合计不得超过 ${(maxRate * 100).toFixed(2)}%(当前 ${(sum * 100).toFixed(2)}%)`;
|
const sum = Number(orderPercent) / 100 + Number(redeemPercent) / 100;
|
||||||
|
if (!Number.isFinite(max) || !Number.isFinite(sum)) return '佣金比例无效';
|
||||||
|
if (sum > max + 1e-9) {
|
||||||
|
return `订单佣金与核销佣金合计不得超过 ${(max * 100).toFixed(2)}%(当前 ${(sum * 100).toFixed(2)}%)`;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function formatApiError(err: unknown): string | null {
|
||||||
|
if (err && typeof err === 'object' && 'errorFields' in err) return null;
|
||||||
|
if (!(err instanceof Error)) return '操作失败';
|
||||||
|
return err.message.replace(/\b(\d{6})\b/g, (code) => {
|
||||||
|
const label = districtCodeLabel(code);
|
||||||
|
return label !== code ? `${label}(${code})` : code;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
export default function CityPartnersPage() {
|
export default function CityPartnersPage() {
|
||||||
const [filterForm] = Form.useForm();
|
const [filterForm] = Form.useForm();
|
||||||
const [editForm] = Form.useForm();
|
const [editForm] = Form.useForm();
|
||||||
const [createForm] = Form.useForm();
|
const [createForm] = Form.useForm();
|
||||||
const [subForm] = Form.useForm();
|
const [subForm] = Form.useForm();
|
||||||
const [subEditForm] = Form.useForm();
|
const [subEditForm] = Form.useForm();
|
||||||
const [filters, setFilters] = useState<Record<string, string>>({});
|
const [filters, setFilters] = useState<Record<string, string | boolean>>({});
|
||||||
const { data, loading, page, pageSize, setPage, setPageSize, reload } = useAdminList<Row>(
|
const { data, loading, page, pageSize, setPage, setPageSize, reload } = useAdminList<Row>(
|
||||||
'/admin/partners',
|
'/admin/partners',
|
||||||
() => {
|
() => {
|
||||||
const qs = new URLSearchParams();
|
const qs = new URLSearchParams();
|
||||||
if (filters.companyName) qs.set('companyName', filters.companyName);
|
if (filters.companyName) qs.set('companyName', String(filters.companyName));
|
||||||
if (filters.phone) qs.set('phone', filters.phone);
|
if (filters.phone) qs.set('phone', String(filters.phone));
|
||||||
if (filters.cityId) qs.set('cityId', filters.cityId);
|
if (filters.cityId) qs.set('cityId', String(filters.cityId));
|
||||||
|
if (filters.excludeTest) qs.set('excludeTest', 'true');
|
||||||
return qs;
|
return qs;
|
||||||
},
|
},
|
||||||
[filters],
|
[filters],
|
||||||
@@ -135,6 +150,7 @@ export default function CityPartnersPage() {
|
|||||||
const [editScopeType, setEditScopeType] = useState<CityPartnerScopeType>(CityPartnerScopeType.CITY_WIDE);
|
const [editScopeType, setEditScopeType] = useState<CityPartnerScopeType>(CityPartnerScopeType.CITY_WIDE);
|
||||||
const [maxCommissionRate, setMaxCommissionRate] = useState(0.05);
|
const [maxCommissionRate, setMaxCommissionRate] = useState(0.05);
|
||||||
const [createMaxRate, setCreateMaxRate] = useState(0.05);
|
const [createMaxRate, setCreateMaxRate] = useState(0.05);
|
||||||
|
const [createCityCode, setCreateCityCode] = useState<string | undefined>();
|
||||||
|
|
||||||
const loadCities = useCallback(async () => {
|
const loadCities = useCallback(async () => {
|
||||||
const res = await request<Paginated<CityOption>>(`/admin/cities?pageSize=${ADMIN_OPTIONS_PAGE_SIZE}`);
|
const res = await request<Paginated<CityOption>>(`/admin/cities?pageSize=${ADMIN_OPTIONS_PAGE_SIZE}`);
|
||||||
@@ -145,11 +161,15 @@ export default function CityPartnersPage() {
|
|||||||
void loadCities();
|
void loadCities();
|
||||||
}, [loadCities]);
|
}, [loadCities]);
|
||||||
|
|
||||||
|
const editCityCode = detail?.cityId
|
||||||
|
? cities.find((c) => c.id === detail.cityId)?.code
|
||||||
|
: undefined;
|
||||||
|
|
||||||
async function openPartner(id: string) {
|
async function openPartner(id: string) {
|
||||||
const d = await request<PartnerDetail>(`/admin/partners/${id}`);
|
const d = await request<PartnerDetail>(`/admin/partners/${id}`);
|
||||||
setDetail(d);
|
setDetail(d);
|
||||||
setEditScopeType((d.scopeType as CityPartnerScopeType) || CityPartnerScopeType.CITY_WIDE);
|
setEditScopeType((d.scopeType as CityPartnerScopeType) || CityPartnerScopeType.CITY_WIDE);
|
||||||
setMaxCommissionRate(d.maxPartnerCommissionRate ?? 0.05);
|
setMaxCommissionRate(Number(d.maxPartnerCommissionRate ?? 0.05));
|
||||||
editForm.setFieldsValue({
|
editForm.setFieldsValue({
|
||||||
name: d.name,
|
name: d.name,
|
||||||
phone: d.phone,
|
phone: d.phone,
|
||||||
@@ -171,28 +191,33 @@ export default function CityPartnersPage() {
|
|||||||
|
|
||||||
async function savePartner() {
|
async function savePartner() {
|
||||||
if (!detail) return;
|
if (!detail) return;
|
||||||
const v = await editForm.validateFields();
|
try {
|
||||||
const err = commissionSumError(
|
const v = await editForm.validateFields();
|
||||||
Number(v.orderCommissionRate ?? 0),
|
const err = commissionSumError(
|
||||||
Number(v.redeemCommissionRate ?? 0),
|
Number(v.orderCommissionRate ?? 0),
|
||||||
maxCommissionRate,
|
Number(v.redeemCommissionRate ?? 0),
|
||||||
);
|
maxCommissionRate,
|
||||||
if (err) {
|
);
|
||||||
message.error(err);
|
if (err) {
|
||||||
return;
|
message.error(err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await request(`/admin/partners/${detail.id}`, {
|
||||||
|
method: 'PUT',
|
||||||
|
body: JSON.stringify({
|
||||||
|
...v,
|
||||||
|
orderCommissionRate: Number(v.orderCommissionRate ?? 0) / 100,
|
||||||
|
redeemCommissionRate: Number(v.redeemCommissionRate ?? 3) / 100,
|
||||||
|
districtCodes: editScopeType === CityPartnerScopeType.DISTRICT ? flattenDistrictCodes(v.districtCodes) : undefined,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
message.success('已保存');
|
||||||
|
setDrawerOpen(false);
|
||||||
|
void reload();
|
||||||
|
} catch (e) {
|
||||||
|
const msg = formatApiError(e);
|
||||||
|
if (msg) message.error(msg);
|
||||||
}
|
}
|
||||||
await request(`/admin/partners/${detail.id}`, {
|
|
||||||
method: 'PUT',
|
|
||||||
body: JSON.stringify({
|
|
||||||
...v,
|
|
||||||
orderCommissionRate: Number(v.orderCommissionRate ?? 0) / 100,
|
|
||||||
redeemCommissionRate: Number(v.redeemCommissionRate ?? 3) / 100,
|
|
||||||
districtCodes: editScopeType === CityPartnerScopeType.DISTRICT ? flattenDistrictCodes(v.districtCodes) : undefined,
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
message.success('已保存');
|
|
||||||
setDrawerOpen(false);
|
|
||||||
void reload();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function refreshPartnerContext(parentId: string) {
|
async function refreshPartnerContext(parentId: string) {
|
||||||
@@ -229,14 +254,36 @@ export default function CityPartnersPage() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function onCreateCityChange(cityId: string) {
|
async function onCreateCityChange(cityId: string) {
|
||||||
|
createForm.setFieldsValue({ districtCodes: undefined });
|
||||||
|
const matched = cities.find((c) => c.id === cityId);
|
||||||
|
setCreateCityCode(matched?.code);
|
||||||
const cityRes = await request<{ maxPartnerCommissionRate?: number }>(`/admin/cities/${cityId}`);
|
const cityRes = await request<{ maxPartnerCommissionRate?: number }>(`/admin/cities/${cityId}`);
|
||||||
setCreateMaxRate(cityRes.maxPartnerCommissionRate ?? 0.05);
|
setCreateMaxRate(Number(cityRes.maxPartnerCommissionRate ?? 0.05));
|
||||||
}
|
}
|
||||||
|
|
||||||
const columns: ColumnsType<Row> = [
|
const columns: ColumnsType<Row> = [
|
||||||
{ title: '公司名', dataIndex: 'companyName', ellipsis: true },
|
|
||||||
{ title: '城市', dataIndex: 'cityName', width: 90 },
|
{ title: '城市', dataIndex: 'cityName', width: 90 },
|
||||||
{ title: '主账号姓名', dataIndex: 'name', width: 100, ellipsis: true },
|
{
|
||||||
|
title: '区县',
|
||||||
|
dataIndex: 'districtCodes',
|
||||||
|
width: 160,
|
||||||
|
ellipsis: true,
|
||||||
|
render: (codes: string[] | null | undefined, row) =>
|
||||||
|
row.scopeType === CityPartnerScopeType.CITY_WIDE ? '全城' : formatDistrictLabels(codes),
|
||||||
|
},
|
||||||
|
{ title: '公司名', dataIndex: 'companyName', ellipsis: true, width: 140 },
|
||||||
|
{
|
||||||
|
title: '主账号姓名',
|
||||||
|
dataIndex: 'name',
|
||||||
|
width: 120,
|
||||||
|
ellipsis: true,
|
||||||
|
render: (v, row) => (
|
||||||
|
<Space size={4}>
|
||||||
|
<span>{v}</span>
|
||||||
|
{row.isTest ? <Tag color="orange">测试</Tag> : null}
|
||||||
|
</Space>
|
||||||
|
),
|
||||||
|
},
|
||||||
{ title: '登录手机', dataIndex: 'phone', width: 120 },
|
{ title: '登录手机', dataIndex: 'phone', width: 120 },
|
||||||
{
|
{
|
||||||
title: '管辖',
|
title: '管辖',
|
||||||
@@ -267,7 +314,16 @@ export default function CityPartnersPage() {
|
|||||||
ellipsis: true,
|
ellipsis: true,
|
||||||
render: (v) => v || '—',
|
render: (v) => v || '—',
|
||||||
},
|
},
|
||||||
{ title: '门店', dataIndex: 'storeCount', width: 60 },
|
{
|
||||||
|
title: '门店',
|
||||||
|
dataIndex: 'storeCount',
|
||||||
|
width: 60,
|
||||||
|
render: (n: number, row) => (
|
||||||
|
<Link to={`/stores?partnerId=${row.id}`} title={`查看「${row.companyName || row.phone}」门店`}>
|
||||||
|
{n ?? 0}
|
||||||
|
</Link>
|
||||||
|
),
|
||||||
|
},
|
||||||
{ title: '子账号', dataIndex: 'accountCount', width: 70, render: (n) => Math.max(0, n - 1) },
|
{ title: '子账号', dataIndex: 'accountCount', width: 70, render: (n) => Math.max(0, n - 1) },
|
||||||
{ title: '创建', dataIndex: 'createdAt', width: 150, render: fmtTime },
|
{ title: '创建', dataIndex: 'createdAt', width: 150, render: fmtTime },
|
||||||
{
|
{
|
||||||
@@ -299,6 +355,7 @@ export default function CityPartnersPage() {
|
|||||||
});
|
});
|
||||||
setCreateScopeType(CityPartnerScopeType.CITY_WIDE);
|
setCreateScopeType(CityPartnerScopeType.CITY_WIDE);
|
||||||
setCreateMaxRate(0.05);
|
setCreateMaxRate(0.05);
|
||||||
|
setCreateCityCode(undefined);
|
||||||
setCreateOpen(true);
|
setCreateOpen(true);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
@@ -327,12 +384,6 @@ export default function CityPartnersPage() {
|
|||||||
setPage(1);
|
setPage(1);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Form.Item name="companyName" label="公司">
|
|
||||||
<Input allowClear placeholder="公司名" />
|
|
||||||
</Form.Item>
|
|
||||||
<Form.Item name="phone" label="手机">
|
|
||||||
<Input allowClear placeholder="登录手机" />
|
|
||||||
</Form.Item>
|
|
||||||
<Form.Item name="cityId" label="城市">
|
<Form.Item name="cityId" label="城市">
|
||||||
<Select
|
<Select
|
||||||
allowClear
|
allowClear
|
||||||
@@ -343,6 +394,15 @@ export default function CityPartnersPage() {
|
|||||||
options={cities.map((c) => ({ value: c.id, label: c.name }))}
|
options={cities.map((c) => ({ value: c.id, label: c.name }))}
|
||||||
/>
|
/>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
|
<Form.Item name="companyName" label="公司">
|
||||||
|
<Input allowClear placeholder="公司名" />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="phone" label="手机">
|
||||||
|
<Input allowClear placeholder="登录手机" />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="excludeTest" valuePropName="checked">
|
||||||
|
<Checkbox>过滤测试账号</Checkbox>
|
||||||
|
</Form.Item>
|
||||||
<Form.Item>
|
<Form.Item>
|
||||||
<Space>
|
<Space>
|
||||||
<Button type="primary" htmlType="submit">
|
<Button type="primary" htmlType="submit">
|
||||||
@@ -409,7 +469,11 @@ export default function CityPartnersPage() {
|
|||||||
<>
|
<>
|
||||||
<Descriptions column={2} size="small" bordered style={{ marginBottom: 16 }}>
|
<Descriptions column={2} size="small" bordered style={{ marginBottom: 16 }}>
|
||||||
<Descriptions.Item label="城市">{detail.cityName ?? '—'}</Descriptions.Item>
|
<Descriptions.Item label="城市">{detail.cityName ?? '—'}</Descriptions.Item>
|
||||||
<Descriptions.Item label="门店数">{detail.storeCount ?? 0}</Descriptions.Item>
|
<Descriptions.Item label="门店数">
|
||||||
|
<Link to={`/stores?partnerId=${detail.id}`} title="查看该城市合伙人门店">
|
||||||
|
{detail.storeCount ?? 0}
|
||||||
|
</Link>
|
||||||
|
</Descriptions.Item>
|
||||||
<Descriptions.Item label="管仓仓库" span={2}>
|
<Descriptions.Item label="管仓仓库" span={2}>
|
||||||
{detail.managedWarehouseName ?? (
|
{detail.managedWarehouseName ?? (
|
||||||
<Typography.Text type="secondary">
|
<Typography.Text type="secondary">
|
||||||
@@ -425,8 +489,8 @@ export default function CityPartnersPage() {
|
|||||||
label: '主账号',
|
label: '主账号',
|
||||||
children: (
|
children: (
|
||||||
<Form form={editForm} layout="vertical">
|
<Form form={editForm} layout="vertical">
|
||||||
<Form.Item name="companyName" label="公司名" rules={[{ required: true }]}>
|
<Form.Item name="companyName" label="公司名">
|
||||||
<Input />
|
<Input placeholder="选填" />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item name="name" label="主账号姓名" rules={[{ required: true }]}>
|
<Form.Item name="name" label="主账号姓名" rules={[{ required: true }]}>
|
||||||
<Input />
|
<Input />
|
||||||
@@ -437,8 +501,8 @@ export default function CityPartnersPage() {
|
|||||||
<Form.Item name="contactPhone" label="业务联系电话">
|
<Form.Item name="contactPhone" label="业务联系电话">
|
||||||
<Input />
|
<Input />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item name="address" label="地址" rules={[{ required: true }]}>
|
<Form.Item name="address" label="地址">
|
||||||
<Input />
|
<Input placeholder="选填" />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item name="bindingStatus" label="绑定状态" rules={[{ required: true }]}>
|
<Form.Item name="bindingStatus" label="绑定状态" rules={[{ required: true }]}>
|
||||||
<Select options={BINDING_OPTIONS} />
|
<Select options={BINDING_OPTIONS} />
|
||||||
@@ -447,8 +511,12 @@ export default function CityPartnersPage() {
|
|||||||
<Select options={SCOPE_OPTIONS} onChange={(v) => setEditScopeType(v)} />
|
<Select options={SCOPE_OPTIONS} onChange={(v) => setEditScopeType(v)} />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
{editScopeType === CityPartnerScopeType.DISTRICT && (
|
{editScopeType === CityPartnerScopeType.DISTRICT && (
|
||||||
<Form.Item name="districtCodes" label="区县">
|
<Form.Item
|
||||||
<Cascader options={CHINA_REGION_OPTIONS} multiple changeOnSelect />
|
name="districtCodes"
|
||||||
|
label="区县"
|
||||||
|
extra="仅作标识,可多选当前城市下的区县(不做互斥)"
|
||||||
|
>
|
||||||
|
<CityDistrictMultiSelect cityCode={editCityCode} />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
)}
|
)}
|
||||||
<Space style={{ width: '100%' }} size="large">
|
<Space style={{ width: '100%' }} size="large">
|
||||||
@@ -502,29 +570,34 @@ export default function CityPartnersPage() {
|
|||||||
width={560}
|
width={560}
|
||||||
onCancel={() => setCreateOpen(false)}
|
onCancel={() => setCreateOpen(false)}
|
||||||
onOk={async () => {
|
onOk={async () => {
|
||||||
const v = await createForm.validateFields();
|
try {
|
||||||
const err = commissionSumError(
|
const v = await createForm.validateFields();
|
||||||
Number(v.orderCommissionRate ?? 0),
|
const err = commissionSumError(
|
||||||
Number(v.redeemCommissionRate ?? 3),
|
Number(v.orderCommissionRate ?? 0),
|
||||||
createMaxRate,
|
Number(v.redeemCommissionRate ?? 3),
|
||||||
);
|
createMaxRate,
|
||||||
if (err) {
|
);
|
||||||
message.error(err);
|
if (err) {
|
||||||
return;
|
message.error(err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await request('/admin/partners', {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify({
|
||||||
|
...v,
|
||||||
|
orderCommissionRate: Number(v.orderCommissionRate ?? 0) / 100,
|
||||||
|
redeemCommissionRate: Number(v.redeemCommissionRate ?? 3) / 100,
|
||||||
|
districtCodes:
|
||||||
|
createScopeType === CityPartnerScopeType.DISTRICT ? flattenDistrictCodes(v.districtCodes) : undefined,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
message.success('已创建');
|
||||||
|
setCreateOpen(false);
|
||||||
|
void reload();
|
||||||
|
} catch (e) {
|
||||||
|
const msg = formatApiError(e);
|
||||||
|
if (msg) message.error(msg);
|
||||||
}
|
}
|
||||||
await request('/admin/partners', {
|
|
||||||
method: 'POST',
|
|
||||||
body: JSON.stringify({
|
|
||||||
...v,
|
|
||||||
orderCommissionRate: Number(v.orderCommissionRate ?? 0) / 100,
|
|
||||||
redeemCommissionRate: Number(v.redeemCommissionRate ?? 3) / 100,
|
|
||||||
districtCodes:
|
|
||||||
createScopeType === CityPartnerScopeType.DISTRICT ? flattenDistrictCodes(v.districtCodes) : undefined,
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
message.success('已创建');
|
|
||||||
setCreateOpen(false);
|
|
||||||
void reload();
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Form form={createForm} layout="vertical">
|
<Form form={createForm} layout="vertical">
|
||||||
@@ -536,8 +609,8 @@ export default function CityPartnersPage() {
|
|||||||
onChange={(id) => void onCreateCityChange(id)}
|
onChange={(id) => void onCreateCityChange(id)}
|
||||||
/>
|
/>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item name="companyName" label="公司名" rules={[{ required: true }]}>
|
<Form.Item name="companyName" label="公司名">
|
||||||
<Input />
|
<Input placeholder="选填" />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item name="name" label="主账号姓名" rules={[{ required: true }]}>
|
<Form.Item name="name" label="主账号姓名" rules={[{ required: true }]}>
|
||||||
<Input />
|
<Input />
|
||||||
@@ -545,15 +618,19 @@ export default function CityPartnersPage() {
|
|||||||
<Form.Item name="phone" label="登录手机号" rules={[{ required: true }]}>
|
<Form.Item name="phone" label="登录手机号" rules={[{ required: true }]}>
|
||||||
<Input />
|
<Input />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item name="address" label="地址" rules={[{ required: true }]}>
|
<Form.Item name="address" label="地址">
|
||||||
<Input />
|
<Input placeholder="选填" />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item name="scopeType" label="管辖类型" rules={[{ required: true }]}>
|
<Form.Item name="scopeType" label="管辖类型" rules={[{ required: true }]}>
|
||||||
<Select options={SCOPE_OPTIONS} onChange={(v) => setCreateScopeType(v)} />
|
<Select options={SCOPE_OPTIONS} onChange={(v) => setCreateScopeType(v)} />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
{createScopeType === CityPartnerScopeType.DISTRICT && (
|
{createScopeType === CityPartnerScopeType.DISTRICT && (
|
||||||
<Form.Item name="districtCodes" label="区县" rules={[{ required: true }]}>
|
<Form.Item
|
||||||
<Cascader options={CHINA_REGION_OPTIONS} multiple changeOnSelect />
|
name="districtCodes"
|
||||||
|
label="区县"
|
||||||
|
extra="选填;仅作标识,可多选当前城市下的区县(不做互斥)"
|
||||||
|
>
|
||||||
|
<CityDistrictMultiSelect cityCode={createCityCode} />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
)}
|
)}
|
||||||
<Space style={{ width: '100%' }} size="large">
|
<Space style={{ width: '100%' }} size="large">
|
||||||
|
|||||||
@@ -1,17 +1,22 @@
|
|||||||
import { useCallback, useEffect, useState } from 'react';
|
import { useCallback, useEffect, useMemo, useState } from 'react';
|
||||||
import { Link } from 'react-router-dom';
|
import { Link } from 'react-router-dom';
|
||||||
import {
|
import {
|
||||||
Button, Card, Col, Descriptions, Modal, Row, Space, Statistic, Table, Typography, message,
|
Button, Card, Col, DatePicker, Descriptions, Form, Modal, Row, Select, Space, Statistic, Table, Typography, message,
|
||||||
} from 'antd';
|
} from 'antd';
|
||||||
import { CloudUploadOutlined, ReloadOutlined } from '@ant-design/icons';
|
import { CloudUploadOutlined, ReloadOutlined } from '@ant-design/icons';
|
||||||
|
import dayjs, { type Dayjs } from 'dayjs';
|
||||||
|
import ReactECharts from 'echarts-for-react';
|
||||||
|
import type { EChartsOption } from 'echarts';
|
||||||
import {
|
import {
|
||||||
request,
|
request,
|
||||||
|
type DashboardAnalytics,
|
||||||
type DashboardStats,
|
type DashboardStats,
|
||||||
type DeployTriggerResult,
|
type DeployTriggerResult,
|
||||||
type HqProfile,
|
type HqProfile,
|
||||||
|
type Paginated,
|
||||||
type SystemVersion,
|
type SystemVersion,
|
||||||
} from '../lib/api';
|
} from '../lib/api';
|
||||||
import { fmtTime } from '../lib/constants';
|
import { ADMIN_OPTIONS_PAGE_SIZE, fmtTime } from '../lib/constants';
|
||||||
|
|
||||||
const STATUS_LABELS: Record<string, string> = {
|
const STATUS_LABELS: Record<string, string> = {
|
||||||
PENDING_PAY: '待付款',
|
PENDING_PAY: '待付款',
|
||||||
@@ -31,6 +36,26 @@ const DEPLOYED_BY_LABELS: Record<string, string> = {
|
|||||||
admin: 'Admin 发布',
|
admin: 'Admin 发布',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
type CityOption = { id: string; name: string; code: string };
|
||||||
|
type PromoOption = { id: string; code: string; name: string };
|
||||||
|
|
||||||
|
type AnalyticsFilters = {
|
||||||
|
range: [Dayjs, Dayjs];
|
||||||
|
cityId?: string;
|
||||||
|
promoCodeId?: string;
|
||||||
|
partnerAccountId?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
function buildAnalyticsQs(f: AnalyticsFilters) {
|
||||||
|
const qs = new URLSearchParams();
|
||||||
|
qs.set('dateFrom', f.range[0].format('YYYY-MM-DD'));
|
||||||
|
qs.set('dateTo', f.range[1].format('YYYY-MM-DD'));
|
||||||
|
if (f.cityId) qs.set('cityId', f.cityId);
|
||||||
|
if (f.promoCodeId) qs.set('promoCodeId', f.promoCodeId);
|
||||||
|
if (f.partnerAccountId) qs.set('partnerAccountId', f.partnerAccountId);
|
||||||
|
return qs.toString();
|
||||||
|
}
|
||||||
|
|
||||||
export default function DashboardPage() {
|
export default function DashboardPage() {
|
||||||
const [stats, setStats] = useState<DashboardStats | null>(null);
|
const [stats, setStats] = useState<DashboardStats | null>(null);
|
||||||
const [version, setVersion] = useState<SystemVersion | null>(null);
|
const [version, setVersion] = useState<SystemVersion | null>(null);
|
||||||
@@ -40,6 +65,21 @@ export default function DashboardPage() {
|
|||||||
const [deploying, setDeploying] = useState(false);
|
const [deploying, setDeploying] = useState(false);
|
||||||
const isSuperAdmin = profile?.adminRole === 'SUPER_ADMIN';
|
const isSuperAdmin = profile?.adminRole === 'SUPER_ADMIN';
|
||||||
|
|
||||||
|
const [filterForm] = Form.useForm<{
|
||||||
|
range: [Dayjs, Dayjs];
|
||||||
|
cityId?: string;
|
||||||
|
promoCodeId?: string;
|
||||||
|
partnerAccountId?: string;
|
||||||
|
}>();
|
||||||
|
const [filters, setFilters] = useState<AnalyticsFilters>({
|
||||||
|
range: [dayjs().subtract(29, 'day'), dayjs()],
|
||||||
|
});
|
||||||
|
const [analytics, setAnalytics] = useState<DashboardAnalytics | null>(null);
|
||||||
|
const [analyticsLoading, setAnalyticsLoading] = useState(true);
|
||||||
|
const [cities, setCities] = useState<CityOption[]>([]);
|
||||||
|
const [promos, setPromos] = useState<PromoOption[]>([]);
|
||||||
|
const [partners, setPartners] = useState<Array<{ id: string; companyName?: string | null; name: string }>>([]);
|
||||||
|
|
||||||
const loadVersion = useCallback(() => {
|
const loadVersion = useCallback(() => {
|
||||||
setVersionLoading(true);
|
setVersionLoading(true);
|
||||||
return request<SystemVersion | null>('/admin/dashboard/version')
|
return request<SystemVersion | null>('/admin/dashboard/version')
|
||||||
@@ -48,14 +88,91 @@ export default function DashboardPage() {
|
|||||||
.finally(() => setVersionLoading(false));
|
.finally(() => setVersionLoading(false));
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
const loadAnalytics = useCallback((f: AnalyticsFilters) => {
|
||||||
|
setAnalyticsLoading(true);
|
||||||
|
return request<DashboardAnalytics>(`/admin/dashboard/analytics?${buildAnalyticsQs(f)}`)
|
||||||
|
.then(setAnalytics)
|
||||||
|
.catch((e) => {
|
||||||
|
message.error(e instanceof Error ? e.message : '加载统计失败');
|
||||||
|
setAnalytics(null);
|
||||||
|
})
|
||||||
|
.finally(() => setAnalyticsLoading(false));
|
||||||
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
request<DashboardStats>('/admin/dashboard/stats')
|
request<DashboardStats>('/admin/dashboard/stats')
|
||||||
.then(setStats)
|
.then(setStats)
|
||||||
.finally(() => setLoading(false));
|
.finally(() => setLoading(false));
|
||||||
void loadVersion();
|
request<HqProfile>('/admin/auth/me')
|
||||||
request<HqProfile>('/admin/auth/me').then(setProfile).catch(() => {});
|
.then((p) => {
|
||||||
|
setProfile(p);
|
||||||
|
if (p.adminRole === 'SUPER_ADMIN') {
|
||||||
|
void loadVersion();
|
||||||
|
} else {
|
||||||
|
setVersionLoading(false);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
setVersionLoading(false);
|
||||||
|
});
|
||||||
|
void request<Paginated<CityOption>>(`/admin/cities?pageSize=${ADMIN_OPTIONS_PAGE_SIZE}`)
|
||||||
|
.then((res) => setCities(res.items ?? []))
|
||||||
|
.catch(() => setCities([]));
|
||||||
|
void request<Paginated<PromoOption>>(`/admin/promo-codes?pageSize=${ADMIN_OPTIONS_PAGE_SIZE}`)
|
||||||
|
.then((res) => setPromos(res.items ?? []))
|
||||||
|
.catch(() => setPromos([]));
|
||||||
|
void request<Paginated<{ id: string; companyName?: string | null; name: string }>>(
|
||||||
|
`/admin/partners?pageSize=${ADMIN_OPTIONS_PAGE_SIZE}`,
|
||||||
|
)
|
||||||
|
.then((res) => setPartners(res.items ?? []))
|
||||||
|
.catch(() => setPartners([]));
|
||||||
}, [loadVersion]);
|
}, [loadVersion]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
void loadAnalytics(filters);
|
||||||
|
}, [filters, loadAnalytics]);
|
||||||
|
|
||||||
|
function applyFilters(values: {
|
||||||
|
range?: [Dayjs, Dayjs];
|
||||||
|
cityId?: string;
|
||||||
|
promoCodeId?: string;
|
||||||
|
partnerAccountId?: string;
|
||||||
|
}) {
|
||||||
|
const next: AnalyticsFilters = {
|
||||||
|
range: values.range ?? filters.range,
|
||||||
|
cityId: values.cityId || undefined,
|
||||||
|
promoCodeId: values.promoCodeId || undefined,
|
||||||
|
partnerAccountId: values.partnerAccountId || undefined,
|
||||||
|
};
|
||||||
|
setFilters(next);
|
||||||
|
}
|
||||||
|
|
||||||
|
function setCityFilter(cityId: string) {
|
||||||
|
const next = { ...filters, cityId: cityId === filters.cityId ? undefined : cityId };
|
||||||
|
filterForm.setFieldsValue({ cityId: next.cityId });
|
||||||
|
setFilters(next);
|
||||||
|
}
|
||||||
|
|
||||||
|
function setPromoFilter(promoCodeId: string) {
|
||||||
|
const key = promoCodeId === 'null' || promoCodeId === '' ? 'none' : promoCodeId;
|
||||||
|
const next = {
|
||||||
|
...filters,
|
||||||
|
promoCodeId: key === filters.promoCodeId ? undefined : key,
|
||||||
|
};
|
||||||
|
filterForm.setFieldsValue({ promoCodeId: next.promoCodeId });
|
||||||
|
setFilters(next);
|
||||||
|
}
|
||||||
|
|
||||||
|
function setPartnerFilter(partnerAccountId: string) {
|
||||||
|
const next = {
|
||||||
|
...filters,
|
||||||
|
partnerAccountId:
|
||||||
|
partnerAccountId === filters.partnerAccountId ? undefined : partnerAccountId,
|
||||||
|
};
|
||||||
|
filterForm.setFieldsValue({ partnerAccountId: next.partnerAccountId });
|
||||||
|
setFilters(next);
|
||||||
|
}
|
||||||
|
|
||||||
function handleDeploy() {
|
function handleDeploy() {
|
||||||
Modal.confirm({
|
Modal.confirm({
|
||||||
title: '确认发布更新?',
|
title: '确认发布更新?',
|
||||||
@@ -79,10 +196,181 @@ export default function DashboardPage() {
|
|||||||
|
|
||||||
const shortSha = version?.commitId ? version.commitId.slice(0, 7) : '—';
|
const shortSha = version?.commitId ? version.commitId.slice(0, 7) : '—';
|
||||||
|
|
||||||
|
const ordersDrillQs = useMemo(() => {
|
||||||
|
const qs = new URLSearchParams();
|
||||||
|
qs.set('createdFrom', filters.range[0].format('YYYY-MM-DD'));
|
||||||
|
qs.set('createdTo', filters.range[1].format('YYYY-MM-DD'));
|
||||||
|
if (filters.cityId && filters.cityId !== 'none') qs.set('cityId', filters.cityId);
|
||||||
|
return qs.toString();
|
||||||
|
}, [filters]);
|
||||||
|
|
||||||
|
const byDateOption = useMemo<EChartsOption>(() => {
|
||||||
|
const rows = analytics?.byDate ?? [];
|
||||||
|
return {
|
||||||
|
tooltip: { trigger: 'axis' },
|
||||||
|
legend: { data: ['新增用户', '订单数'] },
|
||||||
|
grid: { left: 40, right: 20, top: 40, bottom: 40 },
|
||||||
|
xAxis: {
|
||||||
|
type: 'category',
|
||||||
|
data: rows.map((r) => r.date.slice(5)),
|
||||||
|
axisLabel: { rotate: rows.length > 14 ? 45 : 0 },
|
||||||
|
},
|
||||||
|
yAxis: { type: 'value', minInterval: 1 },
|
||||||
|
series: [
|
||||||
|
{ name: '新增用户', type: 'line', smooth: true, data: rows.map((r) => r.users) },
|
||||||
|
{ name: '订单数', type: 'line', smooth: true, data: rows.map((r) => r.orders) },
|
||||||
|
],
|
||||||
|
};
|
||||||
|
}, [analytics]);
|
||||||
|
|
||||||
|
const byCityOption = useMemo<EChartsOption>(() => {
|
||||||
|
const rows = analytics?.byCity ?? [];
|
||||||
|
return {
|
||||||
|
tooltip: { trigger: 'axis' },
|
||||||
|
legend: { data: ['用户', '订单'] },
|
||||||
|
grid: { left: 48, right: 20, top: 40, bottom: 48 },
|
||||||
|
xAxis: {
|
||||||
|
type: 'category',
|
||||||
|
data: rows.map((r) => r.cityName),
|
||||||
|
axisLabel: { interval: 0, rotate: rows.length > 4 ? 30 : 0 },
|
||||||
|
},
|
||||||
|
yAxis: { type: 'value', minInterval: 1 },
|
||||||
|
series: [
|
||||||
|
{ name: '用户', type: 'bar', data: rows.map((r) => r.users), barMaxWidth: 36 },
|
||||||
|
{ name: '订单', type: 'bar', data: rows.map((r) => r.orders), barMaxWidth: 36 },
|
||||||
|
],
|
||||||
|
};
|
||||||
|
}, [analytics]);
|
||||||
|
|
||||||
|
const byPromoOption = useMemo<EChartsOption>(() => {
|
||||||
|
const rows = analytics?.byPromo ?? [];
|
||||||
|
return {
|
||||||
|
tooltip: { trigger: 'axis' },
|
||||||
|
legend: { data: ['用户', '订单'] },
|
||||||
|
grid: { left: 48, right: 20, top: 40, bottom: 64 },
|
||||||
|
xAxis: {
|
||||||
|
type: 'category',
|
||||||
|
data: rows.map((r) => r.name || r.code),
|
||||||
|
axisLabel: { interval: 0, rotate: rows.length > 3 ? 30 : 0 },
|
||||||
|
},
|
||||||
|
yAxis: { type: 'value', minInterval: 1 },
|
||||||
|
series: [
|
||||||
|
{ name: '用户', type: 'bar', data: rows.map((r) => r.users), barMaxWidth: 36 },
|
||||||
|
{ name: '订单', type: 'bar', data: rows.map((r) => r.orders), barMaxWidth: 36 },
|
||||||
|
],
|
||||||
|
};
|
||||||
|
}, [analytics]);
|
||||||
|
|
||||||
|
const opsByDateOption = useMemo<EChartsOption>(() => {
|
||||||
|
const rows = analytics?.byDate ?? [];
|
||||||
|
return {
|
||||||
|
tooltip: { trigger: 'axis' },
|
||||||
|
legend: { data: ['新增合伙人', '新签门店', '核销笔数', '核销金额'] },
|
||||||
|
grid: { left: 48, right: 48, top: 48, bottom: 40 },
|
||||||
|
xAxis: {
|
||||||
|
type: 'category',
|
||||||
|
data: rows.map((r) => r.date.slice(5)),
|
||||||
|
axisLabel: { rotate: rows.length > 14 ? 45 : 0 },
|
||||||
|
},
|
||||||
|
yAxis: [
|
||||||
|
{ type: 'value', name: '数量', minInterval: 1 },
|
||||||
|
{ type: 'value', name: '金额', minInterval: 1 },
|
||||||
|
],
|
||||||
|
series: [
|
||||||
|
{ name: '新增合伙人', type: 'line', smooth: true, data: rows.map((r) => r.partners) },
|
||||||
|
{ name: '新签门店', type: 'line', smooth: true, data: rows.map((r) => r.stores) },
|
||||||
|
{ name: '核销笔数', type: 'line', smooth: true, data: rows.map((r) => r.redeems) },
|
||||||
|
{
|
||||||
|
name: '核销金额',
|
||||||
|
type: 'line',
|
||||||
|
smooth: true,
|
||||||
|
yAxisIndex: 1,
|
||||||
|
data: rows.map((r) => r.redeemAmount),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
}, [analytics]);
|
||||||
|
|
||||||
|
const opsByCityOption = useMemo<EChartsOption>(() => {
|
||||||
|
const rows = analytics?.byCity ?? [];
|
||||||
|
return {
|
||||||
|
tooltip: { trigger: 'axis' },
|
||||||
|
legend: { data: ['合伙人', '门店', '核销笔数'] },
|
||||||
|
grid: { left: 48, right: 20, top: 40, bottom: 48 },
|
||||||
|
xAxis: {
|
||||||
|
type: 'category',
|
||||||
|
data: rows.map((r) => r.cityName),
|
||||||
|
axisLabel: { interval: 0, rotate: rows.length > 4 ? 30 : 0 },
|
||||||
|
},
|
||||||
|
yAxis: { type: 'value', minInterval: 1 },
|
||||||
|
series: [
|
||||||
|
{ name: '合伙人', type: 'bar', data: rows.map((r) => r.partners), barMaxWidth: 28 },
|
||||||
|
{ name: '门店', type: 'bar', data: rows.map((r) => r.stores), barMaxWidth: 28 },
|
||||||
|
{ name: '核销笔数', type: 'bar', data: rows.map((r) => r.redeems), barMaxWidth: 28 },
|
||||||
|
],
|
||||||
|
};
|
||||||
|
}, [analytics]);
|
||||||
|
|
||||||
|
const opsByPartnerOption = useMemo<EChartsOption>(() => {
|
||||||
|
const rows = analytics?.byPartner ?? [];
|
||||||
|
return {
|
||||||
|
tooltip: { trigger: 'axis' },
|
||||||
|
legend: { data: ['门店', '核销笔数', '核销金额'] },
|
||||||
|
grid: { left: 48, right: 48, top: 40, bottom: 64 },
|
||||||
|
xAxis: {
|
||||||
|
type: 'category',
|
||||||
|
data: rows.map((r) => r.companyName),
|
||||||
|
axisLabel: { interval: 0, rotate: rows.length > 3 ? 30 : 0 },
|
||||||
|
},
|
||||||
|
yAxis: [
|
||||||
|
{ type: 'value', name: '数量', minInterval: 1 },
|
||||||
|
{ type: 'value', name: '金额' },
|
||||||
|
],
|
||||||
|
series: [
|
||||||
|
{ name: '门店', type: 'bar', data: rows.map((r) => r.stores), barMaxWidth: 28 },
|
||||||
|
{ name: '核销笔数', type: 'bar', data: rows.map((r) => r.redeems), barMaxWidth: 28 },
|
||||||
|
{
|
||||||
|
name: '核销金额',
|
||||||
|
type: 'line',
|
||||||
|
yAxisIndex: 1,
|
||||||
|
data: rows.map((r) => r.redeemAmount),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
}, [analytics]);
|
||||||
|
|
||||||
|
const redeemByCityOption = useMemo<EChartsOption>(() => {
|
||||||
|
const rows = analytics?.byCity ?? [];
|
||||||
|
return {
|
||||||
|
tooltip: { trigger: 'axis' },
|
||||||
|
legend: { data: ['核销笔数', '核销金额'] },
|
||||||
|
grid: { left: 48, right: 48, top: 40, bottom: 48 },
|
||||||
|
xAxis: {
|
||||||
|
type: 'category',
|
||||||
|
data: rows.map((r) => r.cityName),
|
||||||
|
axisLabel: { interval: 0, rotate: rows.length > 4 ? 30 : 0 },
|
||||||
|
},
|
||||||
|
yAxis: [
|
||||||
|
{ type: 'value', name: '笔数', minInterval: 1 },
|
||||||
|
{ type: 'value', name: '金额' },
|
||||||
|
],
|
||||||
|
series: [
|
||||||
|
{ name: '核销笔数', type: 'bar', data: rows.map((r) => r.redeems), barMaxWidth: 36 },
|
||||||
|
{
|
||||||
|
name: '核销金额',
|
||||||
|
type: 'line',
|
||||||
|
yAxisIndex: 1,
|
||||||
|
data: rows.map((r) => r.redeemAmount),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
}, [analytics]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<Typography.Title level={4}>数据概览</Typography.Title>
|
<Typography.Title level={4}>数据概览</Typography.Title>
|
||||||
|
|
||||||
|
{isSuperAdmin ? (
|
||||||
<Card
|
<Card
|
||||||
title="系统版本"
|
title="系统版本"
|
||||||
loading={versionLoading}
|
loading={versionLoading}
|
||||||
@@ -92,16 +380,14 @@ export default function DashboardPage() {
|
|||||||
<Button icon={<ReloadOutlined />} onClick={() => void loadVersion()}>
|
<Button icon={<ReloadOutlined />} onClick={() => void loadVersion()}>
|
||||||
刷新版本
|
刷新版本
|
||||||
</Button>
|
</Button>
|
||||||
{isSuperAdmin && (
|
<Button
|
||||||
<Button
|
type="primary"
|
||||||
type="primary"
|
icon={<CloudUploadOutlined />}
|
||||||
icon={<CloudUploadOutlined />}
|
loading={deploying}
|
||||||
loading={deploying}
|
onClick={handleDeploy}
|
||||||
onClick={handleDeploy}
|
>
|
||||||
>
|
发布更新
|
||||||
发布更新
|
</Button>
|
||||||
</Button>
|
|
||||||
)}
|
|
||||||
</Space>
|
</Space>
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
@@ -122,6 +408,7 @@ export default function DashboardPage() {
|
|||||||
<Typography.Text type="secondary">尚未记录发版信息</Typography.Text>
|
<Typography.Text type="secondary">尚未记录发版信息</Typography.Text>
|
||||||
)}
|
)}
|
||||||
</Card>
|
</Card>
|
||||||
|
) : null}
|
||||||
|
|
||||||
<Row gutter={[16, 16]} style={{ marginBottom: 24 }}>
|
<Row gutter={[16, 16]} style={{ marginBottom: 24 }}>
|
||||||
<Col xs={24} sm={12} lg={6}>
|
<Col xs={24} sm={12} lg={6}>
|
||||||
@@ -166,6 +453,237 @@ export default function DashboardPage() {
|
|||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
|
|
||||||
|
<Card
|
||||||
|
title="数据统计筛选"
|
||||||
|
style={{ marginBottom: 24 }}
|
||||||
|
extra={
|
||||||
|
<Button
|
||||||
|
icon={<ReloadOutlined />}
|
||||||
|
size="small"
|
||||||
|
onClick={() => void loadAnalytics(filters)}
|
||||||
|
>
|
||||||
|
刷新
|
||||||
|
</Button>
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<Form
|
||||||
|
form={filterForm}
|
||||||
|
layout="inline"
|
||||||
|
initialValues={{ range: filters.range }}
|
||||||
|
onFinish={applyFilters}
|
||||||
|
>
|
||||||
|
<Form.Item name="range" label="日期" rules={[{ required: true, message: '请选择日期' }]}>
|
||||||
|
<DatePicker.RangePicker allowClear={false} />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="cityId" label="城市">
|
||||||
|
<Select
|
||||||
|
allowClear
|
||||||
|
placeholder="全部开城"
|
||||||
|
style={{ width: 160 }}
|
||||||
|
options={[
|
||||||
|
{ value: 'none', label: '未选城' },
|
||||||
|
...cities.map((c) => ({ value: c.id, label: c.name })),
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="promoCodeId" label="推广码">
|
||||||
|
<Select
|
||||||
|
allowClear
|
||||||
|
placeholder="全部来源"
|
||||||
|
style={{ width: 200 }}
|
||||||
|
options={[
|
||||||
|
{ value: 'none', label: '自然量 / 无推广码' },
|
||||||
|
...promos.map((p) => ({ value: p.id, label: `${p.name}(${p.code})` })),
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="partnerAccountId" label="合伙人">
|
||||||
|
<Select
|
||||||
|
allowClear
|
||||||
|
placeholder="全部合伙人"
|
||||||
|
style={{ width: 200 }}
|
||||||
|
options={partners.map((p) => ({
|
||||||
|
value: p.id,
|
||||||
|
label: p.companyName || p.name,
|
||||||
|
}))}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item>
|
||||||
|
<Button type="primary" htmlType="submit">查询</Button>
|
||||||
|
</Form.Item>
|
||||||
|
</Form>
|
||||||
|
</Card>
|
||||||
|
|
||||||
|
<Card
|
||||||
|
title="用户 / 订单统计"
|
||||||
|
style={{ marginBottom: 24 }}
|
||||||
|
extra={
|
||||||
|
<Space>
|
||||||
|
<Link to={`/orders?${ordersDrillQs}`}>查看订单</Link>
|
||||||
|
<Link to="/users">查看用户</Link>
|
||||||
|
</Space>
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<Row gutter={[16, 16]} style={{ marginBottom: 16 }}>
|
||||||
|
<Col xs={24} sm={8}>
|
||||||
|
<Statistic title="区间新增用户" value={analytics?.summary.users ?? 0} />
|
||||||
|
</Col>
|
||||||
|
<Col xs={24} sm={8}>
|
||||||
|
<Statistic title="区间订单数" value={analytics?.summary.orders ?? 0} />
|
||||||
|
</Col>
|
||||||
|
<Col xs={24} sm={8}>
|
||||||
|
<Statistic title="区间付费用户" value={analytics?.summary.payingUsers ?? 0} />
|
||||||
|
</Col>
|
||||||
|
</Row>
|
||||||
|
|
||||||
|
<Row gutter={[16, 16]}>
|
||||||
|
<Col xs={24}>
|
||||||
|
<Card type="inner" title="按日趋势" loading={analyticsLoading} size="small">
|
||||||
|
<ReactECharts option={byDateOption} style={{ height: 320 }} notMerge />
|
||||||
|
</Card>
|
||||||
|
</Col>
|
||||||
|
<Col xs={24} lg={12}>
|
||||||
|
<Card
|
||||||
|
type="inner"
|
||||||
|
title="按城市(点击柱联动筛选)"
|
||||||
|
loading={analyticsLoading}
|
||||||
|
size="small"
|
||||||
|
>
|
||||||
|
<ReactECharts
|
||||||
|
option={byCityOption}
|
||||||
|
style={{ height: 300 }}
|
||||||
|
notMerge
|
||||||
|
onEvents={{
|
||||||
|
click: (params: { name?: string }) => {
|
||||||
|
const row = (analytics?.byCity ?? []).find((r) => r.cityName === params.name);
|
||||||
|
if (row) setCityFilter(row.cityId);
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</Card>
|
||||||
|
</Col>
|
||||||
|
<Col xs={24} lg={12}>
|
||||||
|
<Card
|
||||||
|
type="inner"
|
||||||
|
title="按推广码(点击柱联动筛选)"
|
||||||
|
loading={analyticsLoading}
|
||||||
|
size="small"
|
||||||
|
>
|
||||||
|
<ReactECharts
|
||||||
|
option={byPromoOption}
|
||||||
|
style={{ height: 300 }}
|
||||||
|
notMerge
|
||||||
|
onEvents={{
|
||||||
|
click: (params: { name?: string }) => {
|
||||||
|
const row = (analytics?.byPromo ?? []).find(
|
||||||
|
(r) => (r.name || r.code) === params.name,
|
||||||
|
);
|
||||||
|
if (row) setPromoFilter(row.promoCodeId ?? 'none');
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</Card>
|
||||||
|
</Col>
|
||||||
|
</Row>
|
||||||
|
</Card>
|
||||||
|
|
||||||
|
<Card
|
||||||
|
title="合伙人 / 门店 / 核销统计"
|
||||||
|
style={{ marginBottom: 24 }}
|
||||||
|
extra={
|
||||||
|
<Space>
|
||||||
|
<Link to="/city-partners">查看合伙人</Link>
|
||||||
|
<Link to="/stores">查看门店</Link>
|
||||||
|
<Link to="/redeem-records">查看核销</Link>
|
||||||
|
</Space>
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<Row gutter={[16, 16]} style={{ marginBottom: 16 }}>
|
||||||
|
<Col xs={24} sm={6}>
|
||||||
|
<Statistic title="区间新增合伙人" value={analytics?.summary.partners ?? 0} />
|
||||||
|
</Col>
|
||||||
|
<Col xs={24} sm={6}>
|
||||||
|
<Statistic title="区间新签门店" value={analytics?.summary.stores ?? 0} />
|
||||||
|
</Col>
|
||||||
|
<Col xs={24} sm={6}>
|
||||||
|
<Statistic title="区间核销笔数" value={analytics?.summary.redeems ?? 0} />
|
||||||
|
</Col>
|
||||||
|
<Col xs={24} sm={6}>
|
||||||
|
<Statistic title="区间核销金额" value={analytics?.summary.redeemAmount ?? 0} precision={2} />
|
||||||
|
</Col>
|
||||||
|
</Row>
|
||||||
|
|
||||||
|
<Row gutter={[16, 16]}>
|
||||||
|
<Col xs={24}>
|
||||||
|
<Card type="inner" title="按日趋势(合伙人 / 门店 / 核销)" loading={analyticsLoading} size="small">
|
||||||
|
<ReactECharts option={opsByDateOption} style={{ height: 320 }} notMerge />
|
||||||
|
</Card>
|
||||||
|
</Col>
|
||||||
|
<Col xs={24} lg={12}>
|
||||||
|
<Card
|
||||||
|
type="inner"
|
||||||
|
title="按城市(点击柱联动筛选)"
|
||||||
|
loading={analyticsLoading}
|
||||||
|
size="small"
|
||||||
|
>
|
||||||
|
<ReactECharts
|
||||||
|
option={opsByCityOption}
|
||||||
|
style={{ height: 300 }}
|
||||||
|
notMerge
|
||||||
|
onEvents={{
|
||||||
|
click: (params: { name?: string }) => {
|
||||||
|
const row = (analytics?.byCity ?? []).find((r) => r.cityName === params.name);
|
||||||
|
if (row) setCityFilter(row.cityId);
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</Card>
|
||||||
|
</Col>
|
||||||
|
<Col xs={24} lg={12}>
|
||||||
|
<Card
|
||||||
|
type="inner"
|
||||||
|
title="按城市核销金额"
|
||||||
|
loading={analyticsLoading}
|
||||||
|
size="small"
|
||||||
|
>
|
||||||
|
<ReactECharts
|
||||||
|
option={redeemByCityOption}
|
||||||
|
style={{ height: 300 }}
|
||||||
|
notMerge
|
||||||
|
onEvents={{
|
||||||
|
click: (params: { name?: string }) => {
|
||||||
|
const row = (analytics?.byCity ?? []).find((r) => r.cityName === params.name);
|
||||||
|
if (row) setCityFilter(row.cityId);
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</Card>
|
||||||
|
</Col>
|
||||||
|
<Col xs={24}>
|
||||||
|
<Card
|
||||||
|
type="inner"
|
||||||
|
title="按合伙人(门店 / 核销,点击联动筛选)"
|
||||||
|
loading={analyticsLoading}
|
||||||
|
size="small"
|
||||||
|
>
|
||||||
|
<ReactECharts
|
||||||
|
option={opsByPartnerOption}
|
||||||
|
style={{ height: 320 }}
|
||||||
|
notMerge
|
||||||
|
onEvents={{
|
||||||
|
click: (params: { name?: string }) => {
|
||||||
|
const row = (analytics?.byPartner ?? []).find(
|
||||||
|
(r) => r.companyName === params.name,
|
||||||
|
);
|
||||||
|
if (row) setPartnerFilter(row.partnerAccountId);
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</Card>
|
||||||
|
</Col>
|
||||||
|
</Row>
|
||||||
|
</Card>
|
||||||
|
|
||||||
<Row gutter={[16, 16]} style={{ marginBottom: 24 }}>
|
<Row gutter={[16, 16]} style={{ marginBottom: 24 }}>
|
||||||
<Col xs={24} sm={12} lg={8}>
|
<Col xs={24} sm={12} lg={8}>
|
||||||
<Card
|
<Card
|
||||||
@@ -199,6 +717,26 @@ export default function DashboardPage() {
|
|||||||
/>
|
/>
|
||||||
</Card>
|
</Card>
|
||||||
</Col>
|
</Col>
|
||||||
|
<Col xs={24} sm={12} lg={8}>
|
||||||
|
<Card
|
||||||
|
loading={loading}
|
||||||
|
title="待审门店提现"
|
||||||
|
extra={<Link to="/finance/store-bills?kind=WITHDRAW">去处理</Link>}
|
||||||
|
>
|
||||||
|
<Statistic
|
||||||
|
value={stats?.pendingStoreWithdrawals ?? 0}
|
||||||
|
suffix="笔"
|
||||||
|
valueStyle={{
|
||||||
|
color: (stats?.overdueStoreWithdrawals ?? 0) > 0 ? '#cf1322' : (stats?.pendingStoreWithdrawals ?? 0) > 0 ? '#fa8c16' : undefined,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<Typography.Text type="secondary">
|
||||||
|
{(stats?.overdueStoreWithdrawals ?? 0) > 0
|
||||||
|
? `超时未审 ${stats?.overdueStoreWithdrawals} 笔(FIN-003)`
|
||||||
|
: '工作日 T+0 审完'}
|
||||||
|
</Typography.Text>
|
||||||
|
</Card>
|
||||||
|
</Col>
|
||||||
<Col xs={24} sm={12} lg={8}>
|
<Col xs={24} sm={12} lg={8}>
|
||||||
<Card loading={loading} title="待处理工单">
|
<Card loading={loading} title="待处理工单">
|
||||||
<Statistic value={stats?.openTickets ?? 0} suffix="个" />
|
<Statistic value={stats?.openTickets ?? 0} suffix="个" />
|
||||||
|
|||||||
@@ -3,13 +3,26 @@ import {
|
|||||||
Button, Descriptions, Drawer, Form, Input, Space, Table, Typography, message,
|
Button, Descriptions, Drawer, Form, Input, Space, Table, Typography, message,
|
||||||
} from 'antd';
|
} from 'antd';
|
||||||
import type { ColumnsType } from 'antd/es/table';
|
import type { ColumnsType } from 'antd/es/table';
|
||||||
|
import OrderTrackDrawer from '../components/OrderTrackDrawer';
|
||||||
import { request } from '../lib/api';
|
import { request } from '../lib/api';
|
||||||
import { ORDER_STATUS_LABELS, fmtTime } from '../lib/constants';
|
import { ORDER_STATUS_LABELS, fmtTime } from '../lib/constants';
|
||||||
import { useAdminList } from '../lib/useAdminList';
|
import { useAdminList } from '../lib/useAdminList';
|
||||||
|
|
||||||
type Row = {
|
type Row = {
|
||||||
id: string; provider: string; trackingNo: string | null; providerOrderNo: string | null; updatedAt: string;
|
id: string;
|
||||||
order?: { orderNo: string; status: string; receiverName: string; receiverPhone: string; deliveryType: string };
|
orderId: string;
|
||||||
|
provider: string;
|
||||||
|
trackingNo: string | null;
|
||||||
|
providerOrderNo: string | null;
|
||||||
|
updatedAt: string;
|
||||||
|
order?: {
|
||||||
|
id: string;
|
||||||
|
orderNo: string;
|
||||||
|
status: string;
|
||||||
|
receiverName: string;
|
||||||
|
receiverPhone: string;
|
||||||
|
deliveryType: string;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function DeliveriesPage() {
|
export default function DeliveriesPage() {
|
||||||
@@ -29,6 +42,22 @@ export default function DeliveriesPage() {
|
|||||||
);
|
);
|
||||||
const [detail, setDetail] = useState<Row | null>(null);
|
const [detail, setDetail] = useState<Row | null>(null);
|
||||||
const [drawerOpen, setDrawerOpen] = useState(false);
|
const [drawerOpen, setDrawerOpen] = useState(false);
|
||||||
|
const [trackOpen, setTrackOpen] = useState(false);
|
||||||
|
const [trackOrderId, setTrackOrderId] = useState<string | null>(null);
|
||||||
|
const [trackOrderNo, setTrackOrderNo] = useState<string | null>(null);
|
||||||
|
const [trackOrderStatus, setTrackOrderStatus] = useState<string | null>(null);
|
||||||
|
|
||||||
|
function openTrack(row: Row) {
|
||||||
|
const orderId = row.orderId || row.order?.id;
|
||||||
|
if (!orderId) {
|
||||||
|
message.warning('缺少关联订单,无法查询路由');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setTrackOrderId(orderId);
|
||||||
|
setTrackOrderNo(row.order?.orderNo ?? null);
|
||||||
|
setTrackOrderStatus(row.order?.status ?? null);
|
||||||
|
setTrackOpen(true);
|
||||||
|
}
|
||||||
|
|
||||||
const columns: ColumnsType<Row> = [
|
const columns: ColumnsType<Row> = [
|
||||||
{ title: '订单号', dataIndex: ['order', 'orderNo'], width: 170 },
|
{ title: '订单号', dataIndex: ['order', 'orderNo'], width: 170 },
|
||||||
@@ -39,14 +68,17 @@ export default function DeliveriesPage() {
|
|||||||
{ title: '收货人', dataIndex: ['order', 'receiverName'], width: 90 },
|
{ title: '收货人', dataIndex: ['order', 'receiverName'], width: 90 },
|
||||||
{ title: '更新', dataIndex: 'updatedAt', width: 160, render: fmtTime },
|
{ title: '更新', dataIndex: 'updatedAt', width: 160, render: fmtTime },
|
||||||
{
|
{
|
||||||
title: '操作', width: 80,
|
title: '操作', width: 140,
|
||||||
render: (_, row) => (
|
render: (_, row) => (
|
||||||
<Button type="link" size="small" onClick={async () => {
|
<Space size={0}>
|
||||||
const d = await request<Row>(`/admin/deliveries/${row.id}`);
|
<Button type="link" size="small" onClick={() => openTrack(row)}>路由</Button>
|
||||||
setDetail(d);
|
<Button type="link" size="small" onClick={async () => {
|
||||||
editForm.setFieldsValue({ provider: d.provider, trackingNo: d.trackingNo, providerOrderNo: d.providerOrderNo });
|
const d = await request<Row>(`/admin/deliveries/${row.id}`);
|
||||||
setDrawerOpen(true);
|
setDetail(d);
|
||||||
}}>编辑</Button>
|
editForm.setFieldsValue({ provider: d.provider, trackingNo: d.trackingNo, providerOrderNo: d.providerOrderNo });
|
||||||
|
setDrawerOpen(true);
|
||||||
|
}}>编辑</Button>
|
||||||
|
</Space>
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
@@ -87,9 +119,22 @@ export default function DeliveriesPage() {
|
|||||||
<Form.Item name="providerOrderNo" label="第三方单号"><Input /></Form.Item>
|
<Form.Item name="providerOrderNo" label="第三方单号"><Input /></Form.Item>
|
||||||
<Form.Item name="trackingNo" label="运单号"><Input /></Form.Item>
|
<Form.Item name="trackingNo" label="运单号"><Input /></Form.Item>
|
||||||
</Form>
|
</Form>
|
||||||
|
<Button
|
||||||
|
style={{ marginTop: 8 }}
|
||||||
|
onClick={() => openTrack(detail)}
|
||||||
|
>
|
||||||
|
查看路由
|
||||||
|
</Button>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</Drawer>
|
</Drawer>
|
||||||
|
<OrderTrackDrawer
|
||||||
|
open={trackOpen}
|
||||||
|
orderId={trackOrderId}
|
||||||
|
orderNo={trackOrderNo}
|
||||||
|
orderStatus={trackOrderStatus}
|
||||||
|
onClose={() => setTrackOpen(false)}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,103 @@
|
|||||||
|
import { useEffect, useState } from 'react';
|
||||||
|
import { Button, Collapse, Form, Input, Select, Typography, message } from 'antd';
|
||||||
|
import type {
|
||||||
|
DevPlanSettingsDto,
|
||||||
|
KnowledgeBaseOptionDto,
|
||||||
|
LlmApiConfigOptionDto,
|
||||||
|
} from '@dukang/shared-types';
|
||||||
|
import { request } from '../lib/api';
|
||||||
|
|
||||||
|
export default function DevPlanSettingsPage() {
|
||||||
|
const [loading, setLoading] = useState(true);
|
||||||
|
const [saving, setSaving] = useState(false);
|
||||||
|
const [llmOptions, setLlmOptions] = useState<LlmApiConfigOptionDto[]>([]);
|
||||||
|
const [kbOptions, setKbOptions] = useState<KnowledgeBaseOptionDto[]>([]);
|
||||||
|
const [settingsForm] = Form.useForm();
|
||||||
|
|
||||||
|
async function loadAll() {
|
||||||
|
setLoading(true);
|
||||||
|
try {
|
||||||
|
const [s, llm, kb] = await Promise.all([
|
||||||
|
request<DevPlanSettingsDto>('/admin/dev-plan/settings'),
|
||||||
|
request<LlmApiConfigOptionDto[]>('/admin/llm-configs/options'),
|
||||||
|
request<KnowledgeBaseOptionDto[]>('/admin/knowledge-bases/options'),
|
||||||
|
]);
|
||||||
|
setLlmOptions(llm);
|
||||||
|
setKbOptions(kb);
|
||||||
|
settingsForm.setFieldsValue({
|
||||||
|
reviewAssistantLlmConfigId: s.reviewAssistantLlmConfigId,
|
||||||
|
reviewAssistantKnowledgeBaseId: s.reviewAssistantKnowledgeBaseId,
|
||||||
|
reviewAssistantPrompt: s.reviewAssistantPrompt,
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
message.error(e instanceof Error ? e.message : '加载失败');
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
void loadAll();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
async function saveSettings() {
|
||||||
|
const values = await settingsForm.validateFields();
|
||||||
|
setSaving(true);
|
||||||
|
try {
|
||||||
|
await request<DevPlanSettingsDto>('/admin/dev-plan/settings', {
|
||||||
|
method: 'PUT',
|
||||||
|
body: JSON.stringify(values),
|
||||||
|
});
|
||||||
|
message.success('设置已保存');
|
||||||
|
} catch (e) {
|
||||||
|
message.error(e instanceof Error ? e.message : '保存失败');
|
||||||
|
} finally {
|
||||||
|
setSaving(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<Typography.Title level={4}>开发计划 · 开发设置</Typography.Title>
|
||||||
|
<Typography.Paragraph type="secondary">
|
||||||
|
任务评审派发 Webhook 已迁移至「企微机器人 → 消息推送」,勾选「开发任务评审派发」条件即可。
|
||||||
|
</Typography.Paragraph>
|
||||||
|
|
||||||
|
<Collapse
|
||||||
|
defaultActiveKey={['review-ai']}
|
||||||
|
style={{ marginTop: 16 }}
|
||||||
|
items={[
|
||||||
|
{
|
||||||
|
key: 'review-ai',
|
||||||
|
label: '本地审核 AI 助手',
|
||||||
|
children: (
|
||||||
|
<Form form={settingsForm} layout="vertical" disabled={loading}>
|
||||||
|
<Typography.Paragraph type="secondary">
|
||||||
|
仅用于技术支持批量预审(只读知识库 + LLM),preview 阶段不写库。
|
||||||
|
</Typography.Paragraph>
|
||||||
|
<Form.Item name="reviewAssistantLlmConfigId" label="语言模型">
|
||||||
|
<Select
|
||||||
|
allowClear
|
||||||
|
options={llmOptions.map((o) => ({ value: o.id, label: o.name }))}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="reviewAssistantKnowledgeBaseId" label="知识库">
|
||||||
|
<Select
|
||||||
|
allowClear
|
||||||
|
options={kbOptions.map((o) => ({ value: o.id, label: o.name }))}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="reviewAssistantPrompt" label="审核提示词">
|
||||||
|
<Input.TextArea rows={5} />
|
||||||
|
</Form.Item>
|
||||||
|
<Button type="primary" loading={saving} onClick={() => void saveSettings()}>
|
||||||
|
保存
|
||||||
|
</Button>
|
||||||
|
</Form>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,382 @@
|
|||||||
|
import { useEffect, useState } from 'react';
|
||||||
|
import {
|
||||||
|
Button,
|
||||||
|
Form,
|
||||||
|
Input,
|
||||||
|
Modal,
|
||||||
|
Popconfirm,
|
||||||
|
Select,
|
||||||
|
Space,
|
||||||
|
Table,
|
||||||
|
Tag,
|
||||||
|
Typography,
|
||||||
|
message,
|
||||||
|
} from 'antd';
|
||||||
|
import type { ColumnsType } from 'antd/es/table';
|
||||||
|
import {
|
||||||
|
DEV_PLAN_TASK_STATUS_LABELS,
|
||||||
|
DEV_PLAN_TASK_TYPE_LABELS,
|
||||||
|
SUPPORT_TICKET_STATUS_LABELS,
|
||||||
|
type DevPlanTaskDto,
|
||||||
|
type DevPlanTaskStatusDto,
|
||||||
|
type DevPlanTaskTypeDto,
|
||||||
|
type DevPlanVersionDto,
|
||||||
|
type SupportTicketDto,
|
||||||
|
} from '@dukang/shared-types';
|
||||||
|
import { request } from '../lib/api';
|
||||||
|
import { fmtTime } from '../lib/constants';
|
||||||
|
import { useAdminList } from '../lib/useAdminList';
|
||||||
|
|
||||||
|
const TYPE_OPTIONS = (Object.keys(DEV_PLAN_TASK_TYPE_LABELS) as DevPlanTaskTypeDto[]).map((v) => ({
|
||||||
|
value: v,
|
||||||
|
label: DEV_PLAN_TASK_TYPE_LABELS[v],
|
||||||
|
}));
|
||||||
|
|
||||||
|
const STATUS_OPTIONS = (Object.keys(DEV_PLAN_TASK_STATUS_LABELS) as DevPlanTaskStatusDto[]).map(
|
||||||
|
(v) => ({ value: v, label: DEV_PLAN_TASK_STATUS_LABELS[v] }),
|
||||||
|
);
|
||||||
|
|
||||||
|
const STATUS_COLOR: Record<DevPlanTaskStatusDto, string> = {
|
||||||
|
TODO: 'default',
|
||||||
|
DEVELOPED: 'blue',
|
||||||
|
RELEASED: 'green',
|
||||||
|
};
|
||||||
|
|
||||||
|
const DEFAULT_DISPATCH_SUPPLEMENT = '请按以下任务进入开发流程';
|
||||||
|
|
||||||
|
export default function DevPlanTasksPage() {
|
||||||
|
const [filters, setFilters] = useState<Record<string, string>>({});
|
||||||
|
const [selectedRowKeys, setSelectedRowKeys] = useState<string[]>([]);
|
||||||
|
const [modalOpen, setModalOpen] = useState(false);
|
||||||
|
const [dispatchOpen, setDispatchOpen] = useState(false);
|
||||||
|
const [batchEditOpen, setBatchEditOpen] = useState(false);
|
||||||
|
const [batchSaving, setBatchSaving] = useState(false);
|
||||||
|
const [versions, setVersions] = useState<DevPlanVersionDto[]>([]);
|
||||||
|
const [supportTickets, setSupportTickets] = useState<SupportTicketDto[]>([]);
|
||||||
|
const [editing, setEditing] = useState<DevPlanTaskDto | null>(null);
|
||||||
|
const [saving, setSaving] = useState(false);
|
||||||
|
const [dispatching, setDispatching] = useState(false);
|
||||||
|
const [form] = Form.useForm();
|
||||||
|
const [dispatchForm] = Form.useForm<{ supplement?: string }>();
|
||||||
|
const [batchForm] = Form.useForm<{ status?: DevPlanTaskStatusDto; versionId?: string }>();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!batchEditOpen) return;
|
||||||
|
request<{ items: DevPlanVersionDto[] }>('/admin/dev-plan/versions?pageSize=100')
|
||||||
|
.then((res) => setVersions(res.items ?? []))
|
||||||
|
.catch(() => setVersions([]));
|
||||||
|
}, [batchEditOpen]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!modalOpen || editing) return;
|
||||||
|
request<{ items: SupportTicketDto[] }>('/admin/support-tickets?pageSize=100')
|
||||||
|
.then((res) => setSupportTickets(res.items ?? []))
|
||||||
|
.catch(() => setSupportTickets([]));
|
||||||
|
}, [modalOpen, editing]);
|
||||||
|
|
||||||
|
const { data, loading, page, pageSize, setPage, setPageSize, reload } = useAdminList<DevPlanTaskDto>(
|
||||||
|
'/admin/dev-plan/tasks',
|
||||||
|
() => {
|
||||||
|
const qs = new URLSearchParams();
|
||||||
|
if (filters.status) qs.set('status', filters.status);
|
||||||
|
if (filters.type) qs.set('type', filters.type);
|
||||||
|
if (filters.keyword) qs.set('keyword', filters.keyword);
|
||||||
|
return qs;
|
||||||
|
},
|
||||||
|
[filters],
|
||||||
|
);
|
||||||
|
|
||||||
|
function openCreate() {
|
||||||
|
setEditing(null);
|
||||||
|
form.setFieldsValue({ content: '', type: 'BUG', status: 'TODO', supportTicketId: undefined });
|
||||||
|
setModalOpen(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
function openEdit(row: DevPlanTaskDto) {
|
||||||
|
setEditing(row);
|
||||||
|
form.setFieldsValue({ content: row.content, type: row.type, status: row.status });
|
||||||
|
setModalOpen(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function save() {
|
||||||
|
const values = await form.validateFields();
|
||||||
|
setSaving(true);
|
||||||
|
try {
|
||||||
|
if (editing) {
|
||||||
|
await request(`/admin/dev-plan/tasks/${editing.id}`, {
|
||||||
|
method: 'PUT',
|
||||||
|
body: JSON.stringify(values),
|
||||||
|
});
|
||||||
|
message.success('已更新');
|
||||||
|
} else {
|
||||||
|
await request('/admin/dev-plan/tasks', {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify({
|
||||||
|
content: values.content,
|
||||||
|
type: values.type,
|
||||||
|
supportTicketId: values.supportTicketId || undefined,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
message.success('已创建');
|
||||||
|
}
|
||||||
|
setModalOpen(false);
|
||||||
|
reload();
|
||||||
|
} catch (e) {
|
||||||
|
message.error(e instanceof Error ? e.message : '保存失败');
|
||||||
|
} finally {
|
||||||
|
setSaving(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function remove(id: string) {
|
||||||
|
try {
|
||||||
|
await request(`/admin/dev-plan/tasks/${id}`, { method: 'DELETE' });
|
||||||
|
message.success('已删除');
|
||||||
|
reload();
|
||||||
|
} catch (e) {
|
||||||
|
message.error(e instanceof Error ? e.message : '删除失败');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function openDispatch() {
|
||||||
|
dispatchForm.setFieldsValue({
|
||||||
|
supplement: DEFAULT_DISPATCH_SUPPLEMENT,
|
||||||
|
});
|
||||||
|
setDispatchOpen(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
function openBatchEdit() {
|
||||||
|
batchForm.setFieldsValue({ status: undefined, versionId: undefined });
|
||||||
|
setBatchEditOpen(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function submitBatchEdit() {
|
||||||
|
const values = await batchForm.validateFields();
|
||||||
|
if (!values.status && !values.versionId) {
|
||||||
|
message.warning('请至少选择状态或关联版本');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setBatchSaving(true);
|
||||||
|
try {
|
||||||
|
await request('/admin/dev-plan/tasks/batch-update', {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify({
|
||||||
|
taskIds: selectedRowKeys,
|
||||||
|
status: values.status || undefined,
|
||||||
|
versionId: values.versionId || undefined,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
message.success('批量更新成功');
|
||||||
|
setBatchEditOpen(false);
|
||||||
|
setSelectedRowKeys([]);
|
||||||
|
reload();
|
||||||
|
} catch (e) {
|
||||||
|
message.error(e instanceof Error ? e.message : '批量更新失败');
|
||||||
|
} finally {
|
||||||
|
setBatchSaving(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function submitDispatch() {
|
||||||
|
const values = await dispatchForm.validateFields();
|
||||||
|
setDispatching(true);
|
||||||
|
try {
|
||||||
|
await request('/admin/dev-plan/tasks/dispatch', {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify({
|
||||||
|
taskIds: selectedRowKeys,
|
||||||
|
supplement: values.supplement?.trim() || undefined,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
message.success('已派发到企微群');
|
||||||
|
setDispatchOpen(false);
|
||||||
|
setSelectedRowKeys([]);
|
||||||
|
reload();
|
||||||
|
} catch (e) {
|
||||||
|
message.error(e instanceof Error ? e.message : '派发失败');
|
||||||
|
} finally {
|
||||||
|
setDispatching(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const columns: ColumnsType<DevPlanTaskDto> = [
|
||||||
|
{ title: '任务号', dataIndex: 'taskNo', width: 160 },
|
||||||
|
{
|
||||||
|
title: '类型',
|
||||||
|
dataIndex: 'type',
|
||||||
|
width: 80,
|
||||||
|
render: (t: DevPlanTaskTypeDto) => DEV_PLAN_TASK_TYPE_LABELS[t],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '状态',
|
||||||
|
dataIndex: 'status',
|
||||||
|
width: 90,
|
||||||
|
render: (s: DevPlanTaskStatusDto) => (
|
||||||
|
<Tag color={STATUS_COLOR[s]}>{DEV_PLAN_TASK_STATUS_LABELS[s]}</Tag>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{ title: '内容', dataIndex: 'content', ellipsis: true },
|
||||||
|
{ title: '来源工单', dataIndex: 'supportTicketNo', width: 140, render: (v) => v || '—' },
|
||||||
|
{ title: '创建人', dataIndex: 'creatorName', width: 90 },
|
||||||
|
{ title: '创建时间', dataIndex: 'createdAt', width: 160, render: fmtTime },
|
||||||
|
{
|
||||||
|
title: '操作',
|
||||||
|
width: 120,
|
||||||
|
render: (_, row) => (
|
||||||
|
<Space>
|
||||||
|
<Button type="link" size="small" onClick={() => openEdit(row)}>
|
||||||
|
编辑
|
||||||
|
</Button>
|
||||||
|
<Popconfirm title="确认删除?" onConfirm={() => void remove(row.id)}>
|
||||||
|
<Button type="link" size="small" danger>
|
||||||
|
删除
|
||||||
|
</Button>
|
||||||
|
</Popconfirm>
|
||||||
|
</Space>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<div style={{ display: 'flex', justifyContent: 'space-between', marginBottom: 16 }}>
|
||||||
|
<Typography.Title level={4} style={{ margin: 0 }}>
|
||||||
|
开发计划 · 任务列表
|
||||||
|
</Typography.Title>
|
||||||
|
<Space>
|
||||||
|
<Button disabled={!selectedRowKeys.length} onClick={openBatchEdit}>
|
||||||
|
批量编辑
|
||||||
|
</Button>
|
||||||
|
<Button disabled={!selectedRowKeys.length} onClick={openDispatch}>
|
||||||
|
评审
|
||||||
|
</Button>
|
||||||
|
<Button type="primary" onClick={openCreate}>
|
||||||
|
新建任务
|
||||||
|
</Button>
|
||||||
|
</Space>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<Form
|
||||||
|
layout="inline"
|
||||||
|
style={{ marginBottom: 16 }}
|
||||||
|
onFinish={(v) => {
|
||||||
|
setFilters(v);
|
||||||
|
setPage(1);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Form.Item name="type" label="类型">
|
||||||
|
<Select allowClear style={{ width: 100 }} options={TYPE_OPTIONS} />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="status" label="状态">
|
||||||
|
<Select allowClear style={{ width: 100 }} options={STATUS_OPTIONS} />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="keyword" label="关键词">
|
||||||
|
<Input allowClear placeholder="任务号/内容" style={{ width: 160 }} />
|
||||||
|
</Form.Item>
|
||||||
|
<Button type="primary" htmlType="submit">
|
||||||
|
筛选
|
||||||
|
</Button>
|
||||||
|
</Form>
|
||||||
|
|
||||||
|
<Table
|
||||||
|
rowKey="id"
|
||||||
|
loading={loading}
|
||||||
|
columns={columns}
|
||||||
|
dataSource={data?.items ?? []}
|
||||||
|
rowSelection={{
|
||||||
|
selectedRowKeys,
|
||||||
|
onChange: (keys) => setSelectedRowKeys(keys as string[]),
|
||||||
|
}}
|
||||||
|
scroll={{ x: 1100 }}
|
||||||
|
pagination={{
|
||||||
|
current: page,
|
||||||
|
pageSize,
|
||||||
|
total: data?.total ?? 0,
|
||||||
|
showSizeChanger: true,
|
||||||
|
onChange: (p, ps) => {
|
||||||
|
setPage(p);
|
||||||
|
setPageSize(ps);
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Modal
|
||||||
|
title={editing ? '编辑任务' : '新建任务'}
|
||||||
|
open={modalOpen}
|
||||||
|
onCancel={() => setModalOpen(false)}
|
||||||
|
onOk={() => void save()}
|
||||||
|
confirmLoading={saving}
|
||||||
|
destroyOnClose
|
||||||
|
>
|
||||||
|
<Form form={form} layout="vertical">
|
||||||
|
<Form.Item name="content" label="任务内容" rules={[{ required: true }]}>
|
||||||
|
<Input.TextArea rows={4} maxLength={4000} showCount />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="type" label="类型" rules={[{ required: true }]}>
|
||||||
|
<Select options={TYPE_OPTIONS} />
|
||||||
|
</Form.Item>
|
||||||
|
{editing ? (
|
||||||
|
<Form.Item name="status" label="状态" rules={[{ required: true }]}>
|
||||||
|
<Select options={STATUS_OPTIONS} />
|
||||||
|
</Form.Item>
|
||||||
|
) : (
|
||||||
|
<Form.Item name="supportTicketId" label="绑定技术支持工单">
|
||||||
|
<Select
|
||||||
|
allowClear
|
||||||
|
showSearch
|
||||||
|
optionFilterProp="label"
|
||||||
|
placeholder="可选:关联工单"
|
||||||
|
options={supportTickets.map((t) => ({
|
||||||
|
value: t.id,
|
||||||
|
label: `${t.ticketNo} · ${SUPPORT_TICKET_STATUS_LABELS[t.status]} · ${t.title}`,
|
||||||
|
}))}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
)}
|
||||||
|
</Form>
|
||||||
|
</Modal>
|
||||||
|
|
||||||
|
<Modal
|
||||||
|
title="评审派发"
|
||||||
|
open={dispatchOpen}
|
||||||
|
onCancel={() => setDispatchOpen(false)}
|
||||||
|
onOk={() => void submitDispatch()}
|
||||||
|
confirmLoading={dispatching}
|
||||||
|
destroyOnClose
|
||||||
|
>
|
||||||
|
<Typography.Paragraph type="secondary">
|
||||||
|
已选 {selectedRowKeys.length} 条任务,将通过「企微机器人 → 消息推送」中勾选「开发任务评审派发」的实例推送到开发群(@
|
||||||
|
userid 由各推送配置)。
|
||||||
|
</Typography.Paragraph>
|
||||||
|
<Form form={dispatchForm} layout="vertical">
|
||||||
|
<Form.Item name="supplement" label="补充说明">
|
||||||
|
<Input.TextArea rows={3} placeholder="默认任务说明;@ 成员由消息推送配置决定" />
|
||||||
|
</Form.Item>
|
||||||
|
</Form>
|
||||||
|
</Modal>
|
||||||
|
|
||||||
|
<Modal
|
||||||
|
title="批量编辑任务"
|
||||||
|
open={batchEditOpen}
|
||||||
|
onCancel={() => setBatchEditOpen(false)}
|
||||||
|
onOk={() => void submitBatchEdit()}
|
||||||
|
confirmLoading={batchSaving}
|
||||||
|
destroyOnClose
|
||||||
|
>
|
||||||
|
<Typography.Paragraph type="secondary">已选 {selectedRowKeys.length} 条任务</Typography.Paragraph>
|
||||||
|
<Form form={batchForm} layout="vertical">
|
||||||
|
<Form.Item name="status" label="状态(不修改请留空)">
|
||||||
|
<Select allowClear placeholder="不修改" options={STATUS_OPTIONS} />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="versionId" label="关联版本(追加关联,不修改请留空)">
|
||||||
|
<Select
|
||||||
|
allowClear
|
||||||
|
placeholder="不修改"
|
||||||
|
options={versions.map((v) => ({ value: v.id, label: v.versionNo }))}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
</Form>
|
||||||
|
</Modal>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,241 @@
|
|||||||
|
import { useEffect, useState } from 'react';
|
||||||
|
import {
|
||||||
|
Button,
|
||||||
|
Form,
|
||||||
|
Input,
|
||||||
|
Modal,
|
||||||
|
Popconfirm,
|
||||||
|
Select,
|
||||||
|
Space,
|
||||||
|
Table,
|
||||||
|
Tag,
|
||||||
|
Typography,
|
||||||
|
message,
|
||||||
|
} from 'antd';
|
||||||
|
import type { ColumnsType } from 'antd/es/table';
|
||||||
|
import {
|
||||||
|
DEV_PLAN_VERSION_STATUS_LABELS,
|
||||||
|
type DevPlanTaskDto,
|
||||||
|
type DevPlanVersionDto,
|
||||||
|
type DevPlanVersionStatusDto,
|
||||||
|
} from '@dukang/shared-types';
|
||||||
|
import { request } from '../lib/api';
|
||||||
|
import { fmtTime } from '../lib/constants';
|
||||||
|
import { useAdminList } from '../lib/useAdminList';
|
||||||
|
|
||||||
|
|
||||||
|
const STATUS_OPTIONS = (Object.keys(DEV_PLAN_VERSION_STATUS_LABELS) as DevPlanVersionStatusDto[]).map(
|
||||||
|
(v) => ({ value: v, label: DEV_PLAN_VERSION_STATUS_LABELS[v] }),
|
||||||
|
);
|
||||||
|
|
||||||
|
const STATUS_COLOR: Record<DevPlanVersionStatusDto, string> = {
|
||||||
|
PENDING: 'default',
|
||||||
|
IN_PROGRESS: 'processing',
|
||||||
|
TESTING: 'purple',
|
||||||
|
RELEASED: 'green',
|
||||||
|
};
|
||||||
|
|
||||||
|
function formatDuration(minutes?: number | null) {
|
||||||
|
if (minutes == null) return '—';
|
||||||
|
if (minutes < 60) return `${minutes} 分钟`;
|
||||||
|
return `${Math.floor(minutes / 60)} 小时 ${minutes % 60} 分`;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function DevPlanVersionsPage() {
|
||||||
|
const [filters, setFilters] = useState<Record<string, string>>({});
|
||||||
|
const [modalOpen, setModalOpen] = useState(false);
|
||||||
|
const [editing, setEditing] = useState<DevPlanVersionDto | null>(null);
|
||||||
|
const [saving, setSaving] = useState(false);
|
||||||
|
const [allTasks, setAllTasks] = useState<DevPlanTaskDto[]>([]);
|
||||||
|
const [form] = Form.useForm();
|
||||||
|
|
||||||
|
const { data, loading, page, pageSize, setPage, setPageSize, reload } =
|
||||||
|
useAdminList<DevPlanVersionDto>('/admin/dev-plan/versions', () => {
|
||||||
|
const qs = new URLSearchParams();
|
||||||
|
if (filters.status) qs.set('status', filters.status);
|
||||||
|
return qs;
|
||||||
|
}, [filters]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
void request<{ items: DevPlanTaskDto[] }>('/admin/dev-plan/tasks?page=1&pageSize=500')
|
||||||
|
.then((res) => setAllTasks(res.items ?? []))
|
||||||
|
.catch(() => setAllTasks([]));
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
async function openEdit(row: DevPlanVersionDto) {
|
||||||
|
const detail = await request<DevPlanVersionDto>(`/admin/dev-plan/versions/${row.id}`);
|
||||||
|
setEditing(detail);
|
||||||
|
form.setFieldsValue({
|
||||||
|
versionNo: detail.versionNo,
|
||||||
|
content: detail.content ?? '',
|
||||||
|
status: detail.status,
|
||||||
|
taskIds: detail.taskIds ?? [],
|
||||||
|
});
|
||||||
|
setModalOpen(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
function openCreate() {
|
||||||
|
setEditing(null);
|
||||||
|
form.setFieldsValue({ versionNo: '', content: '', status: 'PENDING', taskIds: [] });
|
||||||
|
setModalOpen(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function save() {
|
||||||
|
const values = await form.validateFields();
|
||||||
|
setSaving(true);
|
||||||
|
try {
|
||||||
|
const body = {
|
||||||
|
versionNo: values.versionNo.trim(),
|
||||||
|
content: values.content?.trim() || undefined,
|
||||||
|
status: values.status,
|
||||||
|
taskIds: values.taskIds ?? [],
|
||||||
|
};
|
||||||
|
if (editing) {
|
||||||
|
await request(`/admin/dev-plan/versions/${editing.id}`, {
|
||||||
|
method: 'PUT',
|
||||||
|
body: JSON.stringify(body),
|
||||||
|
});
|
||||||
|
message.success('已更新');
|
||||||
|
} else {
|
||||||
|
await request('/admin/dev-plan/versions', { method: 'POST', body: JSON.stringify(body) });
|
||||||
|
message.success('已创建');
|
||||||
|
}
|
||||||
|
setModalOpen(false);
|
||||||
|
reload();
|
||||||
|
} catch (e) {
|
||||||
|
message.error(e instanceof Error ? e.message : '保存失败');
|
||||||
|
} finally {
|
||||||
|
setSaving(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function remove(id: string) {
|
||||||
|
try {
|
||||||
|
await request(`/admin/dev-plan/versions/${id}`, { method: 'DELETE' });
|
||||||
|
message.success('已删除');
|
||||||
|
reload();
|
||||||
|
} catch (e) {
|
||||||
|
message.error(e instanceof Error ? e.message : '删除失败');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const columns: ColumnsType<DevPlanVersionDto> = [
|
||||||
|
{ title: '版本号', dataIndex: 'versionNo', width: 120 },
|
||||||
|
{
|
||||||
|
title: '状态',
|
||||||
|
dataIndex: 'status',
|
||||||
|
width: 100,
|
||||||
|
render: (s: DevPlanVersionStatusDto) => (
|
||||||
|
<Tag color={STATUS_COLOR[s]}>{DEV_PLAN_VERSION_STATUS_LABELS[s]}</Tag>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{ title: '内容', dataIndex: 'content', ellipsis: true, render: (v) => v || '—' },
|
||||||
|
{ title: '开发起始', dataIndex: 'devStartedAt', width: 160, render: (v) => (v ? fmtTime(v) : '—') },
|
||||||
|
{ title: '开发完成', dataIndex: 'devCompletedAt', width: 160, render: (v) => (v ? fmtTime(v) : '—') },
|
||||||
|
{ title: '上线时间', dataIndex: 'releasedAt', width: 160, render: (v) => (v ? fmtTime(v) : '—') },
|
||||||
|
{
|
||||||
|
title: '用时',
|
||||||
|
dataIndex: 'durationMinutes',
|
||||||
|
width: 100,
|
||||||
|
render: (v) => formatDuration(v),
|
||||||
|
},
|
||||||
|
{ title: '创建时间', dataIndex: 'createdAt', width: 160, render: fmtTime },
|
||||||
|
{
|
||||||
|
title: '操作',
|
||||||
|
width: 120,
|
||||||
|
render: (_, row) => (
|
||||||
|
<Space>
|
||||||
|
<Button type="link" size="small" onClick={() => void openEdit(row)}>
|
||||||
|
编辑
|
||||||
|
</Button>
|
||||||
|
<Popconfirm title="确认删除?(不删除关联任务)" onConfirm={() => void remove(row.id)}>
|
||||||
|
<Button type="link" size="small" danger>
|
||||||
|
删除
|
||||||
|
</Button>
|
||||||
|
</Popconfirm>
|
||||||
|
</Space>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<div style={{ display: 'flex', justifyContent: 'space-between', marginBottom: 16 }}>
|
||||||
|
<Typography.Title level={4} style={{ margin: 0 }}>
|
||||||
|
开发计划 · 版本列表
|
||||||
|
</Typography.Title>
|
||||||
|
<Button type="primary" onClick={openCreate}>
|
||||||
|
新建版本
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<Form
|
||||||
|
layout="inline"
|
||||||
|
style={{ marginBottom: 16 }}
|
||||||
|
onFinish={(v) => {
|
||||||
|
setFilters(v);
|
||||||
|
setPage(1);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Form.Item name="status" label="状态">
|
||||||
|
<Select allowClear style={{ width: 120 }} options={STATUS_OPTIONS} />
|
||||||
|
</Form.Item>
|
||||||
|
<Button type="primary" htmlType="submit">
|
||||||
|
筛选
|
||||||
|
</Button>
|
||||||
|
</Form>
|
||||||
|
|
||||||
|
<Table
|
||||||
|
rowKey="id"
|
||||||
|
loading={loading}
|
||||||
|
columns={columns}
|
||||||
|
dataSource={data?.items ?? []}
|
||||||
|
scroll={{ x: 1100 }}
|
||||||
|
pagination={{
|
||||||
|
current: page,
|
||||||
|
pageSize,
|
||||||
|
total: data?.total ?? 0,
|
||||||
|
showSizeChanger: true,
|
||||||
|
onChange: (p, ps) => {
|
||||||
|
setPage(p);
|
||||||
|
setPageSize(ps);
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Modal
|
||||||
|
title={editing ? '编辑版本' : '新建版本'}
|
||||||
|
open={modalOpen}
|
||||||
|
onCancel={() => setModalOpen(false)}
|
||||||
|
onOk={() => void save()}
|
||||||
|
confirmLoading={saving}
|
||||||
|
destroyOnClose
|
||||||
|
width={640}
|
||||||
|
>
|
||||||
|
<Form form={form} layout="vertical">
|
||||||
|
<Form.Item name="versionNo" label="版本号" rules={[{ required: true }]}>
|
||||||
|
<Input placeholder="如 v3.4.11" maxLength={32} />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="status" label="状态" rules={[{ required: true }]}>
|
||||||
|
<Select options={STATUS_OPTIONS} />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="content" label="内容">
|
||||||
|
<Input.TextArea placeholder="版本描述 / 更新日志" rows={3} maxLength={500} showCount />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="taskIds" label="关联任务">
|
||||||
|
<Select
|
||||||
|
mode="multiple"
|
||||||
|
allowClear
|
||||||
|
showSearch
|
||||||
|
optionFilterProp="label"
|
||||||
|
options={allTasks.map((t) => ({
|
||||||
|
value: t.id,
|
||||||
|
label: `${t.taskNo} · ${t.content.slice(0, 40)}`,
|
||||||
|
}))}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
</Form>
|
||||||
|
</Modal>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,127 @@
|
|||||||
|
import { useCallback, useEffect, useState } from 'react';
|
||||||
|
import { useSearchParams } from 'react-router-dom';
|
||||||
|
import { Card, Descriptions, Drawer, Select, Space, Table, Tag } from 'antd';
|
||||||
|
import type { ColumnsType } from 'antd/es/table';
|
||||||
|
import { request } from '../lib/api';
|
||||||
|
import { fmtTime } from '../lib/constants';
|
||||||
|
|
||||||
|
type Row = {
|
||||||
|
id: string;
|
||||||
|
eventType: string;
|
||||||
|
refType: string;
|
||||||
|
refId: string;
|
||||||
|
status?: string | null;
|
||||||
|
param1?: string | null;
|
||||||
|
param2?: string | null;
|
||||||
|
param3?: string | null;
|
||||||
|
remark?: string | null;
|
||||||
|
createdAt: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
const EVENT_OPTIONS = [
|
||||||
|
{ value: '', label: '全部领域事件' },
|
||||||
|
{ value: 'ORDER_STATUS', label: '订单状态' },
|
||||||
|
{ value: 'BENEFIT_LEDGER', label: '权益流水' },
|
||||||
|
{ value: 'STORE_AUDIT', label: '门店审核' },
|
||||||
|
{ value: 'TICKET_COLLAB', label: '工单协作' },
|
||||||
|
{ value: 'PROMO_TOUCH', label: '推广触达' },
|
||||||
|
];
|
||||||
|
|
||||||
|
export default function DomainEventsPage() {
|
||||||
|
const [params, setParams] = useSearchParams();
|
||||||
|
const eventType = params.get('eventType') ?? '';
|
||||||
|
const refType = params.get('refType') ?? '';
|
||||||
|
const refId = params.get('refId') ?? '';
|
||||||
|
const [data, setData] = useState<{ items: Row[]; total: number; page: number; pageSize: number } | null>(null);
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
const [detail, setDetail] = useState<Row | null>(null);
|
||||||
|
|
||||||
|
const load = useCallback(() => {
|
||||||
|
setLoading(true);
|
||||||
|
const q = new URLSearchParams();
|
||||||
|
if (eventType) q.set('eventType', eventType);
|
||||||
|
if (refType) q.set('refType', refType);
|
||||||
|
if (refId) q.set('refId', refId);
|
||||||
|
q.set('page', params.get('page') ?? '1');
|
||||||
|
q.set('pageSize', '20');
|
||||||
|
request<{ items: Row[]; total: number; page: number; pageSize: number }>(
|
||||||
|
`/admin/logs/domain-events?${q.toString()}`,
|
||||||
|
)
|
||||||
|
.then(setData)
|
||||||
|
.finally(() => setLoading(false));
|
||||||
|
}, [eventType, refType, refId, params]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
load();
|
||||||
|
}, [load]);
|
||||||
|
|
||||||
|
const columns: ColumnsType<Row> = [
|
||||||
|
{ title: '时间', dataIndex: 'createdAt', width: 170, render: (v) => fmtTime(v) },
|
||||||
|
{ title: '类型', dataIndex: 'eventType', width: 130, render: (v) => <Tag>{v}</Tag> },
|
||||||
|
{ title: '关联', render: (_, r) => `${r.refType} #${r.refId}` },
|
||||||
|
{ title: '状态', dataIndex: 'status', width: 100 },
|
||||||
|
{ title: '摘要', render: (_, r) => r.param1 || r.remark || '—' },
|
||||||
|
{
|
||||||
|
title: '操作',
|
||||||
|
width: 80,
|
||||||
|
render: (_, r) => (
|
||||||
|
<a
|
||||||
|
onClick={async () => {
|
||||||
|
setDetail(await request<Row>(`/admin/logs/domain-events/${r.id}`));
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
详情
|
||||||
|
</a>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Card title="领域事件">
|
||||||
|
<Space wrap style={{ marginBottom: 16 }}>
|
||||||
|
<Select
|
||||||
|
style={{ width: 180 }}
|
||||||
|
value={eventType}
|
||||||
|
options={EVENT_OPTIONS}
|
||||||
|
onChange={(v) => {
|
||||||
|
const next = new URLSearchParams(params);
|
||||||
|
if (v) next.set('eventType', v);
|
||||||
|
else next.delete('eventType');
|
||||||
|
next.set('page', '1');
|
||||||
|
setParams(next);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</Space>
|
||||||
|
<Table
|
||||||
|
rowKey="id"
|
||||||
|
loading={loading}
|
||||||
|
columns={columns}
|
||||||
|
dataSource={data?.items ?? []}
|
||||||
|
pagination={{
|
||||||
|
current: data?.page ?? 1,
|
||||||
|
pageSize: data?.pageSize ?? 20,
|
||||||
|
total: data?.total ?? 0,
|
||||||
|
onChange: (p) => {
|
||||||
|
const next = new URLSearchParams(params);
|
||||||
|
next.set('page', String(p));
|
||||||
|
setParams(next);
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<Drawer open={!!detail} title="事件详情" width={520} onClose={() => setDetail(null)}>
|
||||||
|
{detail && (
|
||||||
|
<Descriptions column={1} size="small">
|
||||||
|
<Descriptions.Item label="ID">{detail.id}</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="类型">{detail.eventType}</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="关联">{`${detail.refType} #${detail.refId}`}</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="param1">{detail.param1}</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="param2">{detail.param2}</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="param3">{detail.param3}</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="备注">{detail.remark}</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="时间">{fmtTime(detail.createdAt)}</Descriptions.Item>
|
||||||
|
</Descriptions>
|
||||||
|
)}
|
||||||
|
</Drawer>
|
||||||
|
</Card>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -2,8 +2,10 @@ import { useCallback, useEffect, useMemo, useState } from 'react';
|
|||||||
import {
|
import {
|
||||||
Alert,
|
Alert,
|
||||||
Button,
|
Button,
|
||||||
|
Divider,
|
||||||
Form,
|
Form,
|
||||||
Input,
|
Input,
|
||||||
|
InputNumber,
|
||||||
Modal,
|
Modal,
|
||||||
Select,
|
Select,
|
||||||
Space,
|
Space,
|
||||||
@@ -14,10 +16,13 @@ import {
|
|||||||
} from 'antd';
|
} from 'antd';
|
||||||
import type { ColumnsType } from 'antd/es/table';
|
import type { ColumnsType } from 'antd/es/table';
|
||||||
import {
|
import {
|
||||||
|
DEFAULT_XFX_LOGISTICS_PRICING,
|
||||||
FULFILLMENT_PROVIDER_STATUS_LABELS,
|
FULFILLMENT_PROVIDER_STATUS_LABELS,
|
||||||
FULFILLMENT_PROVIDER_TYPE_LABELS,
|
FULFILLMENT_PROVIDER_TYPE_LABELS,
|
||||||
FulfillmentProviderStatus,
|
FulfillmentProviderStatus,
|
||||||
FulfillmentProviderType,
|
FulfillmentProviderType,
|
||||||
|
LOGISTICS_SETTLEMENT_METHOD_LABELS,
|
||||||
|
LogisticsSettlementMethod,
|
||||||
isXfxProviderCode,
|
isXfxProviderCode,
|
||||||
type FulfillmentProviderDto,
|
type FulfillmentProviderDto,
|
||||||
} from '@dukang/shared-types';
|
} from '@dukang/shared-types';
|
||||||
@@ -32,6 +37,9 @@ const STATUS_OPTIONS = Object.entries(FULFILLMENT_PROVIDER_STATUS_LABELS).map(([
|
|||||||
value,
|
value,
|
||||||
label,
|
label,
|
||||||
}));
|
}));
|
||||||
|
const SETTLEMENT_OPTIONS = Object.entries(LOGISTICS_SETTLEMENT_METHOD_LABELS).map(
|
||||||
|
([value, label]) => ({ value, label }),
|
||||||
|
);
|
||||||
const SIGN_OPTIONS = [
|
const SIGN_OPTIONS = [
|
||||||
{ value: 'MD5', label: 'MD5' },
|
{ value: 'MD5', label: 'MD5' },
|
||||||
{ value: 'HMAC-SHA256', label: 'HMAC-SHA256' },
|
{ value: 'HMAC-SHA256', label: 'HMAC-SHA256' },
|
||||||
@@ -77,6 +85,12 @@ export default function FulfillmentProvidersPage() {
|
|||||||
status: FulfillmentProviderStatus.ACTIVE,
|
status: FulfillmentProviderStatus.ACTIVE,
|
||||||
apiUrl: DEFAULT_XFX_API_URL,
|
apiUrl: DEFAULT_XFX_API_URL,
|
||||||
signType: 'MD5',
|
signType: 'MD5',
|
||||||
|
settlementMethod: LogisticsSettlementMethod.PREPAID,
|
||||||
|
baseBottles: DEFAULT_XFX_LOGISTICS_PRICING.baseBottles,
|
||||||
|
baseFee: DEFAULT_XFX_LOGISTICS_PRICING.baseFee,
|
||||||
|
extraBottleFee: DEFAULT_XFX_LOGISTICS_PRICING.extraBottleFee,
|
||||||
|
boxBottles: DEFAULT_XFX_LOGISTICS_PRICING.boxBottles,
|
||||||
|
boxFee: DEFAULT_XFX_LOGISTICS_PRICING.boxFee,
|
||||||
});
|
});
|
||||||
setOpen(true);
|
setOpen(true);
|
||||||
}
|
}
|
||||||
@@ -84,6 +98,7 @@ export default function FulfillmentProvidersPage() {
|
|||||||
function openEdit(row: FulfillmentProviderDto) {
|
function openEdit(row: FulfillmentProviderDto) {
|
||||||
setEditRow(row);
|
setEditRow(row);
|
||||||
const xfx = row.xiaofeixiaConfig;
|
const xfx = row.xiaofeixiaConfig;
|
||||||
|
const pricing = row.pricingRules;
|
||||||
form.setFieldsValue({
|
form.setFieldsValue({
|
||||||
code: row.code,
|
code: row.code,
|
||||||
name: row.name,
|
name: row.name,
|
||||||
@@ -94,6 +109,16 @@ export default function FulfillmentProvidersPage() {
|
|||||||
apiKey: '',
|
apiKey: '',
|
||||||
signType: xfx?.signType || 'MD5',
|
signType: xfx?.signType || 'MD5',
|
||||||
appId: xfx?.appId || '',
|
appId: xfx?.appId || '',
|
||||||
|
bankAccountName: row.bankAccountName || '',
|
||||||
|
bankName: row.bankName || '',
|
||||||
|
bankBranch: row.bankBranch || '',
|
||||||
|
bankAccountNo: row.bankAccountNo || '',
|
||||||
|
settlementMethod: row.settlementMethod || LogisticsSettlementMethod.PREPAID,
|
||||||
|
baseBottles: pricing?.baseBottles ?? DEFAULT_XFX_LOGISTICS_PRICING.baseBottles,
|
||||||
|
baseFee: pricing?.baseFee ?? DEFAULT_XFX_LOGISTICS_PRICING.baseFee,
|
||||||
|
extraBottleFee: pricing?.extraBottleFee ?? DEFAULT_XFX_LOGISTICS_PRICING.extraBottleFee,
|
||||||
|
boxBottles: pricing?.boxBottles ?? DEFAULT_XFX_LOGISTICS_PRICING.boxBottles,
|
||||||
|
boxFee: pricing?.boxFee ?? DEFAULT_XFX_LOGISTICS_PRICING.boxFee,
|
||||||
});
|
});
|
||||||
setOpen(true);
|
setOpen(true);
|
||||||
}
|
}
|
||||||
@@ -104,6 +129,18 @@ export default function FulfillmentProvidersPage() {
|
|||||||
name: v.name,
|
name: v.name,
|
||||||
type: v.type,
|
type: v.type,
|
||||||
status: v.status,
|
status: v.status,
|
||||||
|
bankAccountName: v.bankAccountName || null,
|
||||||
|
bankName: v.bankName || null,
|
||||||
|
bankBranch: v.bankBranch || null,
|
||||||
|
bankAccountNo: v.bankAccountNo || null,
|
||||||
|
settlementMethod: v.settlementMethod,
|
||||||
|
pricingRules: {
|
||||||
|
baseBottles: Number(v.baseBottles),
|
||||||
|
baseFee: Number(v.baseFee),
|
||||||
|
extraBottleFee: Number(v.extraBottleFee),
|
||||||
|
boxBottles: v.boxBottles != null ? Number(v.boxBottles) : undefined,
|
||||||
|
boxFee: v.boxFee != null ? Number(v.boxFee) : undefined,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
if (isXfxProviderCode(String(v.code)) && v.type === FulfillmentProviderType.API) {
|
if (isXfxProviderCode(String(v.code)) && v.type === FulfillmentProviderType.API) {
|
||||||
@@ -144,6 +181,19 @@ export default function FulfillmentProvidersPage() {
|
|||||||
dataIndex: 'type',
|
dataIndex: 'type',
|
||||||
render: (v) => FULFILLMENT_PROVIDER_TYPE_LABELS[v as FulfillmentProviderType] || v,
|
render: (v) => FULFILLMENT_PROVIDER_TYPE_LABELS[v as FulfillmentProviderType] || v,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
title: '结算',
|
||||||
|
dataIndex: 'settlementMethod',
|
||||||
|
width: 100,
|
||||||
|
render: (v) =>
|
||||||
|
LOGISTICS_SETTLEMENT_METHOD_LABELS[v as LogisticsSettlementMethod] || v || '—',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '充值余额',
|
||||||
|
dataIndex: 'prepaidBalance',
|
||||||
|
width: 100,
|
||||||
|
render: (v) => `¥${Number(v || 0).toFixed(2)}`,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
title: '状态',
|
title: '状态',
|
||||||
dataIndex: 'status',
|
dataIndex: 'status',
|
||||||
@@ -188,7 +238,7 @@ export default function FulfillmentProvidersPage() {
|
|||||||
仓配管理
|
仓配管理
|
||||||
</Typography.Title>
|
</Typography.Title>
|
||||||
<Typography.Text type="secondary">
|
<Typography.Text type="secondary">
|
||||||
注册第三方履约接口并填写凭证;仓库绑定后,推单将使用此处配置的 API 地址与密钥
|
注册承运商接口凭证,并配置物流对账用的银行账户、结算方式与计价标准
|
||||||
</Typography.Text>
|
</Typography.Text>
|
||||||
</div>
|
</div>
|
||||||
<Button type="primary" onClick={openCreate}>
|
<Button type="primary" onClick={openCreate}>
|
||||||
@@ -200,7 +250,7 @@ export default function FulfillmentProvidersPage() {
|
|||||||
type="info"
|
type="info"
|
||||||
showIcon
|
showIcon
|
||||||
style={{ marginBottom: 16 }}
|
style={{ marginBottom: 16 }}
|
||||||
message="小飞侠配置已从「系统设置 → 同城配送」迁至本页。寄件地址以仓库联系人/地址为准。"
|
message="小飞侠默认计价:2瓶6元,加一瓶+2元,6瓶一箱14元。财务对账见「财务 → 物流对账」。"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Table rowKey="id" loading={loading} columns={columns} dataSource={rows} pagination={false} />
|
<Table rowKey="id" loading={loading} columns={columns} dataSource={rows} pagination={false} />
|
||||||
@@ -210,7 +260,7 @@ export default function FulfillmentProvidersPage() {
|
|||||||
open={open}
|
open={open}
|
||||||
onCancel={() => setOpen(false)}
|
onCancel={() => setOpen(false)}
|
||||||
onOk={() => void submit()}
|
onOk={() => void submit()}
|
||||||
width={560}
|
width={640}
|
||||||
destroyOnClose
|
destroyOnClose
|
||||||
>
|
>
|
||||||
<Form form={form} layout="vertical">
|
<Form form={form} layout="vertical">
|
||||||
@@ -227,11 +277,58 @@ export default function FulfillmentProvidersPage() {
|
|||||||
<Select options={STATUS_OPTIONS} />
|
<Select options={STATUS_OPTIONS} />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
|
|
||||||
|
<Divider orientation="left">物流对账</Divider>
|
||||||
|
<Form.Item name="settlementMethod" label="结算方式" rules={[{ required: true }]}>
|
||||||
|
<Select options={SETTLEMENT_OPTIONS} />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="bankAccountName" label="收款户名">
|
||||||
|
<Input />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="bankName" label="开户银行">
|
||||||
|
<Input />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="bankBranch" label="开户支行">
|
||||||
|
<Input />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="bankAccountNo" label="银行账号">
|
||||||
|
<Input />
|
||||||
|
</Form.Item>
|
||||||
|
<Space wrap style={{ width: '100%' }}>
|
||||||
|
<Form.Item
|
||||||
|
name="baseBottles"
|
||||||
|
label="起送瓶数"
|
||||||
|
rules={[{ required: true }]}
|
||||||
|
style={{ marginBottom: 12 }}
|
||||||
|
>
|
||||||
|
<InputNumber min={1} style={{ width: 120 }} />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item
|
||||||
|
name="baseFee"
|
||||||
|
label="起送费用(元)"
|
||||||
|
rules={[{ required: true }]}
|
||||||
|
style={{ marginBottom: 12 }}
|
||||||
|
>
|
||||||
|
<InputNumber min={0} precision={2} style={{ width: 120 }} />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item
|
||||||
|
name="extraBottleFee"
|
||||||
|
label="加一瓶(元)"
|
||||||
|
rules={[{ required: true }]}
|
||||||
|
style={{ marginBottom: 12 }}
|
||||||
|
>
|
||||||
|
<InputNumber min={0} precision={2} style={{ width: 120 }} />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="boxBottles" label="箱规瓶数" style={{ marginBottom: 12 }}>
|
||||||
|
<InputNumber min={1} style={{ width: 120 }} />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="boxFee" label="一箱费用(元)" style={{ marginBottom: 12 }}>
|
||||||
|
<InputNumber min={0} precision={2} style={{ width: 120 }} />
|
||||||
|
</Form.Item>
|
||||||
|
</Space>
|
||||||
|
|
||||||
{showXfxFields && (
|
{showXfxFields && (
|
||||||
<>
|
<>
|
||||||
<Typography.Title level={5} style={{ marginTop: 8 }}>
|
<Divider orientation="left">小飞侠接口参数</Divider>
|
||||||
小飞侠接口参数
|
|
||||||
</Typography.Title>
|
|
||||||
<Form.Item
|
<Form.Item
|
||||||
name="apiUrl"
|
name="apiUrl"
|
||||||
label="API 地址"
|
label="API 地址"
|
||||||
|
|||||||
@@ -33,6 +33,15 @@ type AccountPermRes = {
|
|||||||
|
|
||||||
const ROLE_LABELS = Object.fromEntries(HQ_ADMIN_ROLES.map((r) => [r.value, r.label]));
|
const ROLE_LABELS = Object.fromEntries(HQ_ADMIN_ROLES.map((r) => [r.value, r.label]));
|
||||||
|
|
||||||
|
const CATALOG_GROUPS = [...new Set(HQ_PERMISSION_CATALOG.map((p) => p.group ?? '其他'))];
|
||||||
|
|
||||||
|
function groupColSpan(itemCount: number): number {
|
||||||
|
if (itemCount <= 2) return 12;
|
||||||
|
if (itemCount === 3) return 8;
|
||||||
|
if (itemCount === 4) return 6;
|
||||||
|
return 8;
|
||||||
|
}
|
||||||
|
|
||||||
function PermissionChecklist({
|
function PermissionChecklist({
|
||||||
value,
|
value,
|
||||||
onChange,
|
onChange,
|
||||||
@@ -49,13 +58,44 @@ function PermissionChecklist({
|
|||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
onChange={(checked) => onChange(checked as string[])}
|
onChange={(checked) => onChange(checked as string[])}
|
||||||
>
|
>
|
||||||
<Row gutter={[8, 8]}>
|
{CATALOG_GROUPS.map((group) => {
|
||||||
{HQ_PERMISSION_CATALOG.map((item) => (
|
const items = HQ_PERMISSION_CATALOG.filter((p) => (p.group ?? '其他') === group);
|
||||||
<Col key={item.key} span={8}>
|
const span = groupColSpan(items.length);
|
||||||
<Checkbox value={item.key}>{item.label}</Checkbox>
|
const compact = items.length <= 3;
|
||||||
</Col>
|
return (
|
||||||
))}
|
<div
|
||||||
</Row>
|
key={group}
|
||||||
|
style={{
|
||||||
|
marginBottom: 16,
|
||||||
|
padding: '12px 16px',
|
||||||
|
background: '#fafafa',
|
||||||
|
borderRadius: 8,
|
||||||
|
border: '1px solid #f0f0f0',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Typography.Text strong style={{ display: 'block', marginBottom: 10 }}>
|
||||||
|
{group}
|
||||||
|
</Typography.Text>
|
||||||
|
{compact ? (
|
||||||
|
<Space size={[24, 8]} wrap>
|
||||||
|
{items.map((item) => (
|
||||||
|
<Checkbox key={item.key} value={item.key}>
|
||||||
|
{item.label}
|
||||||
|
</Checkbox>
|
||||||
|
))}
|
||||||
|
</Space>
|
||||||
|
) : (
|
||||||
|
<Row gutter={[12, 10]}>
|
||||||
|
{items.map((item) => (
|
||||||
|
<Col key={item.key} xs={24} sm={12} md={span}>
|
||||||
|
<Checkbox value={item.key}>{item.label}</Checkbox>
|
||||||
|
</Col>
|
||||||
|
))}
|
||||||
|
</Row>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
})}
|
||||||
</Checkbox.Group>
|
</Checkbox.Group>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -74,6 +114,12 @@ export default function HqPermissionsPage() {
|
|||||||
const [accountLoading, setAccountLoading] = useState(false);
|
const [accountLoading, setAccountLoading] = useState(false);
|
||||||
const [accountSaving, setAccountSaving] = useState(false);
|
const [accountSaving, setAccountSaving] = useState(false);
|
||||||
|
|
||||||
|
const selectedAccount = useMemo(
|
||||||
|
() => accounts.find((a) => a.id === accountId),
|
||||||
|
[accounts, accountId],
|
||||||
|
);
|
||||||
|
const selectedIsSuperAdmin = selectedAccount?.adminRole === 'SUPER_ADMIN';
|
||||||
|
|
||||||
const previewEffectiveKeys = useMemo(
|
const previewEffectiveKeys = useMemo(
|
||||||
() => [...new Set([...roleInheritedKeys, ...accountKeys])],
|
() => [...new Set([...roleInheritedKeys, ...accountKeys])],
|
||||||
[roleInheritedKeys, accountKeys],
|
[roleInheritedKeys, accountKeys],
|
||||||
@@ -158,7 +204,9 @@ export default function HqPermissionsPage() {
|
|||||||
<div>
|
<div>
|
||||||
<Typography.Title level={4}>权限分配</Typography.Title>
|
<Typography.Title level={4}>权限分配</Typography.Title>
|
||||||
<Typography.Paragraph type="secondary">
|
<Typography.Paragraph type="secondary">
|
||||||
按角色配置基础权限;按用户可追加专属权限。最终生效权限 = 角色权限 ∪ 用户权限(超级管理员始终拥有全部权限)。
|
按角色配置基础权限;按用户可追加专属权限。最终生效权限 = 角色权限 ∪ 用户权限。
|
||||||
|
超级管理员默认拥有除「危险操作」外的全部权限;删除用户/订单/城市需在「按用户分配」中单独勾选(默认均无)。
|
||||||
|
「系统设置」已拆分为各配置分组;「财务」对应门店/合伙人/酒厂账单。
|
||||||
</Typography.Paragraph>
|
</Typography.Paragraph>
|
||||||
|
|
||||||
<Tabs
|
<Tabs
|
||||||
@@ -183,7 +231,11 @@ export default function HqPermissionsPage() {
|
|||||||
</Form.Item>
|
</Form.Item>
|
||||||
</Form>
|
</Form>
|
||||||
{role === 'SUPER_ADMIN' ? (
|
{role === 'SUPER_ADMIN' ? (
|
||||||
<Alert type="info" showIcon message="超级管理员拥有全部权限,无需配置" />
|
<Alert
|
||||||
|
type="info"
|
||||||
|
showIcon
|
||||||
|
message="超级管理员基础权限固定(不含危险操作)。删除用户/订单/城市请到「按用户分配」为具体账号勾选。"
|
||||||
|
/>
|
||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
<PermissionChecklist value={roleKeys} onChange={setRoleKeys} />
|
<PermissionChecklist value={roleKeys} onChange={setRoleKeys} />
|
||||||
@@ -212,12 +264,10 @@ export default function HqPermissionsPage() {
|
|||||||
value={accountId}
|
value={accountId}
|
||||||
onChange={setAccountId}
|
onChange={setAccountId}
|
||||||
optionFilterProp="label"
|
optionFilterProp="label"
|
||||||
options={accounts
|
options={accounts.map((a) => ({
|
||||||
.filter((a) => a.adminRole !== 'SUPER_ADMIN')
|
value: a.id,
|
||||||
.map((a) => ({
|
label: `${a.name} · ${a.loginName || a.phone} · ${ROLE_LABELS[a.adminRole] || a.adminRole}`,
|
||||||
value: a.id,
|
}))}
|
||||||
label: `${a.name} · ${a.loginName || a.phone} · ${ROLE_LABELS[a.adminRole] || a.adminRole}`,
|
|
||||||
}))}
|
|
||||||
/>
|
/>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
</Form>
|
</Form>
|
||||||
@@ -225,28 +275,57 @@ export default function HqPermissionsPage() {
|
|||||||
<Alert type="info" showIcon message="请先选择要配置的 HQ 账户" />
|
<Alert type="info" showIcon message="请先选择要配置的 HQ 账户" />
|
||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
<Space wrap style={{ marginBottom: 12 }}>
|
<div style={{ marginBottom: 12 }}>
|
||||||
<span>角色继承:</span>
|
<span style={{ marginRight: 8 }}>角色继承:</span>
|
||||||
{roleInheritedKeys.map((key) => {
|
{selectedIsSuperAdmin ? (
|
||||||
const item = HQ_PERMISSION_CATALOG.find((p) => p.key === key);
|
<Tag color="blue">超级管理员基础权限(不含危险操作)</Tag>
|
||||||
return (
|
) : (
|
||||||
<Tag key={key} color="blue">
|
<Space wrap size={[4, 4]}>
|
||||||
{item?.label || key}
|
{roleInheritedKeys.map((key) => {
|
||||||
</Tag>
|
const item = HQ_PERMISSION_CATALOG.find((p) => p.key === key);
|
||||||
);
|
return (
|
||||||
})}
|
<Tag key={key} color="blue">
|
||||||
</Space>
|
{item?.label || key}
|
||||||
|
</Tag>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
{!roleInheritedKeys.length ? (
|
||||||
|
<Typography.Text type="secondary">无</Typography.Text>
|
||||||
|
) : null}
|
||||||
|
</Space>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
<Typography.Paragraph type="secondary">
|
<Typography.Paragraph type="secondary">
|
||||||
下方勾选为用户专属追加权限(保存后与角色权限合并生效)。
|
下方勾选为用户专属追加权限(保存后与角色权限合并生效)。危险操作(删除用户/订单/城市)默认不授予,需在此勾选。
|
||||||
</Typography.Paragraph>
|
</Typography.Paragraph>
|
||||||
<PermissionChecklist value={accountKeys} onChange={setAccountKeys} />
|
<PermissionChecklist value={accountKeys} onChange={setAccountKeys} />
|
||||||
<Space wrap style={{ marginTop: 12 }}>
|
<div style={{ marginTop: 12 }}>
|
||||||
<span>合并生效:</span>
|
<span style={{ marginRight: 8 }}>合并生效:</span>
|
||||||
{previewEffectiveKeys.map((key) => {
|
{selectedIsSuperAdmin ? (
|
||||||
const item = HQ_PERMISSION_CATALOG.find((p) => p.key === (key as HqPermissionKey));
|
<Space wrap size={[4, 4]}>
|
||||||
return <Tag key={key}>{item?.label || key}</Tag>;
|
<Tag>基础权限(全部)</Tag>
|
||||||
})}
|
{accountKeys.map((key) => {
|
||||||
</Space>
|
const item = HQ_PERMISSION_CATALOG.find((p) => p.key === (key as HqPermissionKey));
|
||||||
|
return (
|
||||||
|
<Tag key={key} color="orange">
|
||||||
|
{item?.label || key}
|
||||||
|
</Tag>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</Space>
|
||||||
|
) : (
|
||||||
|
<Space wrap size={[4, 4]}>
|
||||||
|
{previewEffectiveKeys.map((key) => {
|
||||||
|
const item = HQ_PERMISSION_CATALOG.find((p) => p.key === (key as HqPermissionKey));
|
||||||
|
return (
|
||||||
|
<Tag key={key}>
|
||||||
|
{item?.label || key}
|
||||||
|
</Tag>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</Space>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
<div style={{ marginTop: 16 }}>
|
<div style={{ marginTop: 16 }}>
|
||||||
<Button type="primary" loading={accountSaving} onClick={() => void saveAccountPermissions()}>
|
<Button type="primary" loading={accountSaving} onClick={() => void saveAccountPermissions()}>
|
||||||
保存用户权限
|
保存用户权限
|
||||||
|
|||||||
@@ -1,11 +1,14 @@
|
|||||||
import { useState } from 'react';
|
import { useEffect, useRef, useState } from 'react';
|
||||||
|
import { useSearchParams } from 'react-router-dom';
|
||||||
import {
|
import {
|
||||||
Button,
|
Button,
|
||||||
Descriptions,
|
Descriptions,
|
||||||
Drawer,
|
Drawer,
|
||||||
Form,
|
Form,
|
||||||
Input,
|
Input,
|
||||||
|
Modal,
|
||||||
Select,
|
Select,
|
||||||
|
Space,
|
||||||
Table,
|
Table,
|
||||||
Tag,
|
Tag,
|
||||||
Typography,
|
Typography,
|
||||||
@@ -14,9 +17,11 @@ import {
|
|||||||
} from 'antd';
|
} from 'antd';
|
||||||
import type { ColumnsType } from 'antd/es/table';
|
import type { ColumnsType } from 'antd/es/table';
|
||||||
import {
|
import {
|
||||||
|
INVOICE_CATEGORY_LABELS,
|
||||||
INVOICE_KIND_LABELS,
|
INVOICE_KIND_LABELS,
|
||||||
INVOICE_STATUS_LABELS,
|
INVOICE_STATUS_LABELS,
|
||||||
INVOICE_TITLE_TYPE_LABELS,
|
INVOICE_TITLE_TYPE_LABELS,
|
||||||
|
type InvoiceCategory,
|
||||||
type InvoiceKind,
|
type InvoiceKind,
|
||||||
type InvoiceStatus,
|
type InvoiceStatus,
|
||||||
type InvoiceTitleType,
|
type InvoiceTitleType,
|
||||||
@@ -32,6 +37,7 @@ type Row = {
|
|||||||
orderNo?: string;
|
orderNo?: string;
|
||||||
titleType: InvoiceTitleType;
|
titleType: InvoiceTitleType;
|
||||||
invoiceKind: InvoiceKind;
|
invoiceKind: InvoiceKind;
|
||||||
|
invoiceCategory?: InvoiceCategory;
|
||||||
titleName: string;
|
titleName: string;
|
||||||
status: InvoiceStatus;
|
status: InvoiceStatus;
|
||||||
overdue?: boolean;
|
overdue?: boolean;
|
||||||
@@ -47,13 +53,37 @@ type Row = {
|
|||||||
remark?: string;
|
remark?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
type CreateFormValues = {
|
||||||
|
orderNo: string;
|
||||||
|
titleType: InvoiceTitleType;
|
||||||
|
invoiceKind: InvoiceKind;
|
||||||
|
invoiceCategory?: InvoiceCategory;
|
||||||
|
titleName: string;
|
||||||
|
taxNo?: string;
|
||||||
|
addressPhone?: string;
|
||||||
|
bankAccount?: string;
|
||||||
|
email: string;
|
||||||
|
phone: string;
|
||||||
|
remark?: string;
|
||||||
|
};
|
||||||
|
|
||||||
export default function InvoicesPage() {
|
export default function InvoicesPage() {
|
||||||
const [filters, setFilters] = useState<Record<string, string>>({});
|
const [searchParams] = useSearchParams();
|
||||||
|
const initialStatus = searchParams.get('status')?.trim() || '';
|
||||||
|
const initialInvoiceNo = searchParams.get('invoiceNo')?.trim() || '';
|
||||||
|
const [filterForm] = Form.useForm();
|
||||||
|
const [filters, setFilters] = useState<Record<string, string>>(() => {
|
||||||
|
const init: Record<string, string> = {};
|
||||||
|
if (initialStatus) init.status = initialStatus;
|
||||||
|
if (initialInvoiceNo) init.invoiceNo = initialInvoiceNo;
|
||||||
|
return init;
|
||||||
|
});
|
||||||
const { data, loading, page, pageSize, setPage, setPageSize, reload } = useAdminList<Row>(
|
const { data, loading, page, pageSize, setPage, setPageSize, reload } = useAdminList<Row>(
|
||||||
'/admin/invoices',
|
'/admin/invoices',
|
||||||
() => {
|
() => {
|
||||||
const qs = new URLSearchParams();
|
const qs = new URLSearchParams();
|
||||||
if (filters.status) qs.set('status', filters.status);
|
if (filters.status) qs.set('status', filters.status);
|
||||||
|
if (filters.invoiceNo) qs.set('invoiceNo', filters.invoiceNo);
|
||||||
return qs;
|
return qs;
|
||||||
},
|
},
|
||||||
[filters],
|
[filters],
|
||||||
@@ -61,12 +91,34 @@ export default function InvoicesPage() {
|
|||||||
const [detail, setDetail] = useState<Row | null>(null);
|
const [detail, setDetail] = useState<Row | null>(null);
|
||||||
const [drawerOpen, setDrawerOpen] = useState(false);
|
const [drawerOpen, setDrawerOpen] = useState(false);
|
||||||
const [uploading, setUploading] = useState(false);
|
const [uploading, setUploading] = useState(false);
|
||||||
|
const [createOpen, setCreateOpen] = useState(false);
|
||||||
|
const [creating, setCreating] = useState(false);
|
||||||
|
const [createForm] = Form.useForm<CreateFormValues>();
|
||||||
|
const invoiceKind = Form.useWatch('invoiceKind', createForm);
|
||||||
|
const titleType = Form.useWatch('titleType', createForm);
|
||||||
|
const deepLinkOpenedRef = useRef(false);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
filterForm.setFieldsValue({
|
||||||
|
status: filters.status || undefined,
|
||||||
|
invoiceNo: filters.invoiceNo || undefined,
|
||||||
|
});
|
||||||
|
}, [filterForm, filters.invoiceNo, filters.status]);
|
||||||
|
|
||||||
async function openDetail(id: string) {
|
async function openDetail(id: string) {
|
||||||
setDetail(await request(`/admin/invoices/${id}`));
|
setDetail(await request(`/admin/invoices/${id}`));
|
||||||
setDrawerOpen(true);
|
setDrawerOpen(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!initialInvoiceNo || deepLinkOpenedRef.current || loading) return;
|
||||||
|
const first = data?.items?.[0];
|
||||||
|
if (first && String(first.invoiceNo) === initialInvoiceNo) {
|
||||||
|
deepLinkOpenedRef.current = true;
|
||||||
|
void openDetail(first.id);
|
||||||
|
}
|
||||||
|
}, [data, initialInvoiceNo, loading]);
|
||||||
|
|
||||||
async function issueWithFile(file: File) {
|
async function issueWithFile(file: File) {
|
||||||
if (!detail) return false;
|
if (!detail) return false;
|
||||||
setUploading(true);
|
setUploading(true);
|
||||||
@@ -98,6 +150,37 @@ export default function InvoicesPage() {
|
|||||||
setDrawerOpen(false);
|
setDrawerOpen(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function submitCreate() {
|
||||||
|
const values = await createForm.validateFields();
|
||||||
|
setCreating(true);
|
||||||
|
try {
|
||||||
|
await request('/admin/invoices', {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify({
|
||||||
|
orderNo: values.orderNo.trim(),
|
||||||
|
titleType: values.titleType,
|
||||||
|
invoiceKind: values.invoiceKind,
|
||||||
|
invoiceCategory: values.invoiceCategory,
|
||||||
|
titleName: values.titleName.trim(),
|
||||||
|
taxNo: values.taxNo?.trim() || undefined,
|
||||||
|
addressPhone: values.addressPhone?.trim() || undefined,
|
||||||
|
bankAccount: values.bankAccount?.trim() || undefined,
|
||||||
|
email: values.email.trim(),
|
||||||
|
phone: values.phone.trim(),
|
||||||
|
remark: values.remark?.trim() || undefined,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
message.success('发票申请已创建');
|
||||||
|
setCreateOpen(false);
|
||||||
|
createForm.resetFields();
|
||||||
|
reload();
|
||||||
|
} catch (e) {
|
||||||
|
message.error(e instanceof Error ? e.message : '创建失败');
|
||||||
|
} finally {
|
||||||
|
setCreating(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const columns: ColumnsType<Row> = [
|
const columns: ColumnsType<Row> = [
|
||||||
{ title: '申请单号', dataIndex: 'invoiceNo', width: 180 },
|
{ title: '申请单号', dataIndex: 'invoiceNo', width: 180 },
|
||||||
{ title: '订单号', dataIndex: 'orderNo', width: 160 },
|
{ title: '订单号', dataIndex: 'orderNo', width: 160 },
|
||||||
@@ -108,9 +191,17 @@ export default function InvoicesPage() {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: '票种',
|
title: '票种',
|
||||||
width: 120,
|
width: 140,
|
||||||
render: (_, r) => INVOICE_KIND_LABELS[r.invoiceKind] ?? r.invoiceKind,
|
render: (_, r) => INVOICE_KIND_LABELS[r.invoiceKind] ?? r.invoiceKind,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
title: '类型',
|
||||||
|
width: 88,
|
||||||
|
render: (_, r) =>
|
||||||
|
r.invoiceCategory
|
||||||
|
? INVOICE_CATEGORY_LABELS[r.invoiceCategory] ?? r.invoiceCategory
|
||||||
|
: '—',
|
||||||
|
},
|
||||||
{ title: '名称', dataIndex: 'titleName', ellipsis: true },
|
{ title: '名称', dataIndex: 'titleName', ellipsis: true },
|
||||||
{
|
{
|
||||||
title: '状态',
|
title: '状态',
|
||||||
@@ -138,8 +229,33 @@ export default function InvoicesPage() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<Typography.Title level={4}>发票管理</Typography.Title>
|
<div
|
||||||
|
style={{
|
||||||
|
display: 'flex',
|
||||||
|
justifyContent: 'space-between',
|
||||||
|
alignItems: 'center',
|
||||||
|
marginBottom: 16,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Typography.Title level={4} style={{ margin: 0 }}>
|
||||||
|
发票管理
|
||||||
|
</Typography.Title>
|
||||||
|
<Button
|
||||||
|
type="primary"
|
||||||
|
onClick={() => {
|
||||||
|
createForm.setFieldsValue({
|
||||||
|
titleType: 'PERSONAL',
|
||||||
|
invoiceKind: 'NORMAL',
|
||||||
|
invoiceCategory: 'LIQUOR',
|
||||||
|
});
|
||||||
|
setCreateOpen(true);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
创建发票申请
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
<Form
|
<Form
|
||||||
|
form={filterForm}
|
||||||
layout="inline"
|
layout="inline"
|
||||||
style={{ marginBottom: 16 }}
|
style={{ marginBottom: 16 }}
|
||||||
onFinish={(v) => {
|
onFinish={(v) => {
|
||||||
@@ -158,6 +274,9 @@ export default function InvoicesPage() {
|
|||||||
]}
|
]}
|
||||||
/>
|
/>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
|
<Form.Item name="invoiceNo" label="申请单号">
|
||||||
|
<Input allowClear placeholder="发票申请单号" />
|
||||||
|
</Form.Item>
|
||||||
<Button type="primary" htmlType="submit">
|
<Button type="primary" htmlType="submit">
|
||||||
筛选
|
筛选
|
||||||
</Button>
|
</Button>
|
||||||
@@ -187,7 +306,7 @@ export default function InvoicesPage() {
|
|||||||
onClose={() => setDrawerOpen(false)}
|
onClose={() => setDrawerOpen(false)}
|
||||||
extra={
|
extra={
|
||||||
detail?.status === 'PENDING' ? (
|
detail?.status === 'PENDING' ? (
|
||||||
<>
|
<Space>
|
||||||
<Upload
|
<Upload
|
||||||
accept="image/*,.pdf"
|
accept="image/*,.pdf"
|
||||||
showUploadList={false}
|
showUploadList={false}
|
||||||
@@ -196,14 +315,14 @@ export default function InvoicesPage() {
|
|||||||
return false;
|
return false;
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Button type="primary" loading={uploading} style={{ marginRight: 8 }}>
|
<Button type="primary" loading={uploading}>
|
||||||
上传并开票
|
上传并开票
|
||||||
</Button>
|
</Button>
|
||||||
</Upload>
|
</Upload>
|
||||||
<Button danger onClick={() => void reject()}>
|
<Button danger onClick={() => void reject()}>
|
||||||
驳回
|
驳回
|
||||||
</Button>
|
</Button>
|
||||||
</>
|
</Space>
|
||||||
) : null
|
) : null
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
@@ -219,6 +338,11 @@ export default function InvoicesPage() {
|
|||||||
<Descriptions.Item label="发票类型">
|
<Descriptions.Item label="发票类型">
|
||||||
{INVOICE_KIND_LABELS[detail.invoiceKind]}
|
{INVOICE_KIND_LABELS[detail.invoiceKind]}
|
||||||
</Descriptions.Item>
|
</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="类型">
|
||||||
|
{detail.invoiceCategory
|
||||||
|
? INVOICE_CATEGORY_LABELS[detail.invoiceCategory]
|
||||||
|
: '—'}
|
||||||
|
</Descriptions.Item>
|
||||||
<Descriptions.Item label="抬头名称">{detail.titleName}</Descriptions.Item>
|
<Descriptions.Item label="抬头名称">{detail.titleName}</Descriptions.Item>
|
||||||
<Descriptions.Item label="税号">{detail.taxNo ?? '—'}</Descriptions.Item>
|
<Descriptions.Item label="税号">{detail.taxNo ?? '—'}</Descriptions.Item>
|
||||||
<Descriptions.Item label="地址电话">{detail.addressPhone ?? '—'}</Descriptions.Item>
|
<Descriptions.Item label="地址电话">{detail.addressPhone ?? '—'}</Descriptions.Item>
|
||||||
@@ -242,6 +366,122 @@ export default function InvoicesPage() {
|
|||||||
</Descriptions>
|
</Descriptions>
|
||||||
)}
|
)}
|
||||||
</Drawer>
|
</Drawer>
|
||||||
|
|
||||||
|
<Modal
|
||||||
|
title="创建发票申请"
|
||||||
|
open={createOpen}
|
||||||
|
onCancel={() => setCreateOpen(false)}
|
||||||
|
onOk={() => void submitCreate()}
|
||||||
|
confirmLoading={creating}
|
||||||
|
destroyOnClose
|
||||||
|
okText="提交"
|
||||||
|
width={520}
|
||||||
|
>
|
||||||
|
<Form form={createForm} layout="vertical">
|
||||||
|
<Form.Item
|
||||||
|
name="orderNo"
|
||||||
|
label="订单号"
|
||||||
|
rules={[{ required: true, message: '请填写已完成订单号' }]}
|
||||||
|
extra="仅已完成订单可开票"
|
||||||
|
>
|
||||||
|
<Input placeholder="订单号" allowClear />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item
|
||||||
|
name="invoiceKind"
|
||||||
|
label="发票类型"
|
||||||
|
rules={[{ required: true, message: '请选择发票类型' }]}
|
||||||
|
>
|
||||||
|
<Select
|
||||||
|
options={(Object.keys(INVOICE_KIND_LABELS) as InvoiceKind[]).map((k) => ({
|
||||||
|
value: k,
|
||||||
|
label: INVOICE_KIND_LABELS[k],
|
||||||
|
}))}
|
||||||
|
onChange={(k: InvoiceKind) => {
|
||||||
|
if (k === 'SPECIAL') createForm.setFieldValue('titleType', 'ENTERPRISE');
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item
|
||||||
|
name="invoiceCategory"
|
||||||
|
label="类型"
|
||||||
|
rules={[{ required: true, message: '请选择类型' }]}
|
||||||
|
>
|
||||||
|
<Select
|
||||||
|
options={(Object.keys(INVOICE_CATEGORY_LABELS) as InvoiceCategory[]).map((k) => ({
|
||||||
|
value: k,
|
||||||
|
label: INVOICE_CATEGORY_LABELS[k],
|
||||||
|
}))}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item
|
||||||
|
name="titleType"
|
||||||
|
label="抬头类型"
|
||||||
|
rules={[{ required: true, message: '请选择抬头类型' }]}
|
||||||
|
>
|
||||||
|
<Select
|
||||||
|
options={(Object.keys(INVOICE_TITLE_TYPE_LABELS) as InvoiceTitleType[]).map((t) => ({
|
||||||
|
value: t,
|
||||||
|
label: INVOICE_TITLE_TYPE_LABELS[t],
|
||||||
|
disabled: invoiceKind === 'SPECIAL' && t === 'PERSONAL',
|
||||||
|
}))}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item
|
||||||
|
name="titleName"
|
||||||
|
label="抬头名称"
|
||||||
|
rules={[{ required: true, message: '请填写抬头名称' }]}
|
||||||
|
>
|
||||||
|
<Input placeholder="个人姓名或企业全称" />
|
||||||
|
</Form.Item>
|
||||||
|
{(titleType === 'ENTERPRISE' || invoiceKind === 'SPECIAL') && (
|
||||||
|
<Form.Item
|
||||||
|
name="taxNo"
|
||||||
|
label="税号"
|
||||||
|
rules={[{ required: true, message: '企业抬头须填写税号' }]}
|
||||||
|
>
|
||||||
|
<Input placeholder="纳税人识别号" />
|
||||||
|
</Form.Item>
|
||||||
|
)}
|
||||||
|
{invoiceKind === 'SPECIAL' && (
|
||||||
|
<>
|
||||||
|
<Form.Item
|
||||||
|
name="addressPhone"
|
||||||
|
label="地址电话"
|
||||||
|
rules={[{ required: true, message: '专用发票须填写地址电话' }]}
|
||||||
|
>
|
||||||
|
<Input placeholder="注册地址及电话" />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item
|
||||||
|
name="bankAccount"
|
||||||
|
label="开户行账号"
|
||||||
|
rules={[{ required: true, message: '专用发票须填写开户行账号' }]}
|
||||||
|
>
|
||||||
|
<Input placeholder="开户行及账号" />
|
||||||
|
</Form.Item>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
<Form.Item
|
||||||
|
name="email"
|
||||||
|
label="接收邮箱"
|
||||||
|
rules={[
|
||||||
|
{ required: true, message: '请填写邮箱' },
|
||||||
|
{ type: 'email', message: '邮箱格式不正确' },
|
||||||
|
]}
|
||||||
|
>
|
||||||
|
<Input placeholder="发票发送邮箱" />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item
|
||||||
|
name="phone"
|
||||||
|
label="手机号"
|
||||||
|
rules={[{ required: true, message: '请填写手机号' }]}
|
||||||
|
>
|
||||||
|
<Input placeholder="联系手机" />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="remark" label="备注">
|
||||||
|
<Input.TextArea rows={2} maxLength={512} showCount />
|
||||||
|
</Form.Item>
|
||||||
|
</Form>
|
||||||
|
</Modal>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,476 @@
|
|||||||
|
import { useState } from 'react';
|
||||||
|
import {
|
||||||
|
Button,
|
||||||
|
Drawer,
|
||||||
|
Form,
|
||||||
|
Input,
|
||||||
|
Modal,
|
||||||
|
Popconfirm,
|
||||||
|
Space,
|
||||||
|
Switch,
|
||||||
|
Table,
|
||||||
|
Tag,
|
||||||
|
Typography,
|
||||||
|
Upload,
|
||||||
|
message,
|
||||||
|
} from 'antd';
|
||||||
|
import type { ColumnsType } from 'antd/es/table';
|
||||||
|
import { UploadOutlined } from '@ant-design/icons';
|
||||||
|
import type {
|
||||||
|
KnowledgeBaseDto,
|
||||||
|
KnowledgeDocumentDetailDto,
|
||||||
|
KnowledgeDocumentDto,
|
||||||
|
} from '@dukang/shared-types';
|
||||||
|
import { request } from '../lib/api';
|
||||||
|
import { fmtTime } from '../lib/constants';
|
||||||
|
import { useAdminList } from '../lib/useAdminList';
|
||||||
|
import { uploadFileToOss } from '../lib/upload';
|
||||||
|
|
||||||
|
type FormValues = {
|
||||||
|
name: string;
|
||||||
|
description?: string;
|
||||||
|
enabled: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
type DocForm = {
|
||||||
|
title: string;
|
||||||
|
contentText?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function KnowledgeBasesPage() {
|
||||||
|
const [filterForm] = Form.useForm();
|
||||||
|
const [form] = Form.useForm<FormValues>();
|
||||||
|
const [docForm] = Form.useForm<DocForm>();
|
||||||
|
const [filters, setFilters] = useState<Record<string, string>>({});
|
||||||
|
const [modalOpen, setModalOpen] = useState(false);
|
||||||
|
const [editing, setEditing] = useState<KnowledgeBaseDto | null>(null);
|
||||||
|
const [saving, setSaving] = useState(false);
|
||||||
|
const [drawerKb, setDrawerKb] = useState<KnowledgeBaseDto | null>(null);
|
||||||
|
const [docs, setDocs] = useState<KnowledgeDocumentDto[]>([]);
|
||||||
|
const [docsLoading, setDocsLoading] = useState(false);
|
||||||
|
const [docModalOpen, setDocModalOpen] = useState(false);
|
||||||
|
const [docSaving, setDocSaving] = useState(false);
|
||||||
|
const [editingDoc, setEditingDoc] = useState<KnowledgeDocumentDto | null>(null);
|
||||||
|
const [editDocModalOpen, setEditDocModalOpen] = useState(false);
|
||||||
|
const [editDocSaving, setEditDocSaving] = useState(false);
|
||||||
|
const [editDocForm] = Form.useForm<DocForm>();
|
||||||
|
|
||||||
|
const { data, loading, page, pageSize, setPage, setPageSize, reload } =
|
||||||
|
useAdminList<KnowledgeBaseDto>(
|
||||||
|
'/admin/knowledge-bases',
|
||||||
|
() => {
|
||||||
|
const qs = new URLSearchParams();
|
||||||
|
if (filters.name) qs.set('name', filters.name);
|
||||||
|
if (filters.enabled) qs.set('enabled', filters.enabled);
|
||||||
|
return qs;
|
||||||
|
},
|
||||||
|
[filters],
|
||||||
|
);
|
||||||
|
|
||||||
|
const loadDocs = async (kb: KnowledgeBaseDto) => {
|
||||||
|
setDrawerKb(kb);
|
||||||
|
setDocsLoading(true);
|
||||||
|
try {
|
||||||
|
const res = await request<{ items: KnowledgeDocumentDto[] }>(
|
||||||
|
`/admin/knowledge-bases/${kb.id}/documents`,
|
||||||
|
);
|
||||||
|
setDocs(res.items);
|
||||||
|
} catch (e) {
|
||||||
|
message.error(e instanceof Error ? e.message : String(e));
|
||||||
|
} finally {
|
||||||
|
setDocsLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const openCreate = () => {
|
||||||
|
setEditing(null);
|
||||||
|
form.setFieldsValue({ name: '', description: '', enabled: true });
|
||||||
|
setModalOpen(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
const openEdit = (row: KnowledgeBaseDto) => {
|
||||||
|
setEditing(row);
|
||||||
|
form.setFieldsValue({
|
||||||
|
name: row.name,
|
||||||
|
description: row.description || '',
|
||||||
|
enabled: row.enabled,
|
||||||
|
});
|
||||||
|
setModalOpen(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
const onSave = async () => {
|
||||||
|
const values = await form.validateFields();
|
||||||
|
setSaving(true);
|
||||||
|
try {
|
||||||
|
if (editing) {
|
||||||
|
await request(`/admin/knowledge-bases/${editing.id}`, {
|
||||||
|
method: 'PUT',
|
||||||
|
body: JSON.stringify(values),
|
||||||
|
});
|
||||||
|
message.success('已保存');
|
||||||
|
} else {
|
||||||
|
await request('/admin/knowledge-bases', {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify(values),
|
||||||
|
});
|
||||||
|
message.success('已创建');
|
||||||
|
}
|
||||||
|
setModalOpen(false);
|
||||||
|
reload();
|
||||||
|
} catch (e) {
|
||||||
|
message.error(e instanceof Error ? e.message : String(e));
|
||||||
|
} finally {
|
||||||
|
setSaving(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const columns: ColumnsType<KnowledgeBaseDto> = [
|
||||||
|
{ title: '名称', dataIndex: 'name' },
|
||||||
|
{ title: '说明', dataIndex: 'description', ellipsis: true },
|
||||||
|
{ title: '文档数', dataIndex: 'documentCount', width: 90 },
|
||||||
|
{
|
||||||
|
title: '启用',
|
||||||
|
dataIndex: 'enabled',
|
||||||
|
width: 90,
|
||||||
|
render: (v: boolean) => (v ? <Tag color="green">开</Tag> : <Tag>关</Tag>),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '创建人',
|
||||||
|
dataIndex: 'createdByName',
|
||||||
|
width: 100,
|
||||||
|
render: (v: string | null, row) => v || row.createdByHqAccountId,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '更新时间',
|
||||||
|
dataIndex: 'updatedAt',
|
||||||
|
width: 170,
|
||||||
|
render: (t: string) => fmtTime(t),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '操作',
|
||||||
|
width: 240,
|
||||||
|
render: (_, row) => (
|
||||||
|
<Space>
|
||||||
|
<Button type="link" size="small" onClick={() => void loadDocs(row)}>
|
||||||
|
文档
|
||||||
|
</Button>
|
||||||
|
{row.canEditFull ? (
|
||||||
|
<Button type="link" size="small" onClick={() => openEdit(row)}>
|
||||||
|
编辑
|
||||||
|
</Button>
|
||||||
|
) : null}
|
||||||
|
{row.canEditFull ? (
|
||||||
|
<Popconfirm
|
||||||
|
title="确认删除知识库及全部文档?"
|
||||||
|
onConfirm={async () => {
|
||||||
|
try {
|
||||||
|
await request(`/admin/knowledge-bases/${row.id}`, { method: 'DELETE' });
|
||||||
|
message.success('已删除');
|
||||||
|
reload();
|
||||||
|
} catch (e) {
|
||||||
|
message.error(e instanceof Error ? e.message : String(e));
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Button type="link" size="small" danger>
|
||||||
|
删除
|
||||||
|
</Button>
|
||||||
|
</Popconfirm>
|
||||||
|
) : null}
|
||||||
|
</Space>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const docColumns: ColumnsType<KnowledgeDocumentDto> = [
|
||||||
|
{ title: '标题', dataIndex: 'title' },
|
||||||
|
{ title: '文件', dataIndex: 'fileName', ellipsis: true },
|
||||||
|
{
|
||||||
|
title: '状态',
|
||||||
|
dataIndex: 'status',
|
||||||
|
width: 90,
|
||||||
|
render: (s: string) =>
|
||||||
|
s === 'READY' ? <Tag color="green">可检索</Tag> : s === 'FAILED' ? <Tag color="red">失败</Tag> : <Tag>无正文</Tag>,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '时间',
|
||||||
|
dataIndex: 'createdAt',
|
||||||
|
width: 170,
|
||||||
|
render: (t: string) => fmtTime(t),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '操作',
|
||||||
|
width: 140,
|
||||||
|
render: (_, row) =>
|
||||||
|
drawerKb?.canEditFull ? (
|
||||||
|
<Space>
|
||||||
|
<Button
|
||||||
|
type="link"
|
||||||
|
size="small"
|
||||||
|
onClick={async () => {
|
||||||
|
if (!drawerKb) return;
|
||||||
|
try {
|
||||||
|
const detail = await request<KnowledgeDocumentDetailDto>(
|
||||||
|
`/admin/knowledge-bases/${drawerKb.id}/documents/${row.id}`,
|
||||||
|
);
|
||||||
|
setEditingDoc(row);
|
||||||
|
editDocForm.setFieldsValue({
|
||||||
|
title: detail.title,
|
||||||
|
contentText: detail.contentText || '',
|
||||||
|
});
|
||||||
|
setEditDocModalOpen(true);
|
||||||
|
} catch (e) {
|
||||||
|
message.error(e instanceof Error ? e.message : String(e));
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
编辑
|
||||||
|
</Button>
|
||||||
|
<Popconfirm
|
||||||
|
title="删除文档?"
|
||||||
|
onConfirm={async () => {
|
||||||
|
try {
|
||||||
|
await request(`/admin/knowledge-bases/${drawerKb.id}/documents/${row.id}`, {
|
||||||
|
method: 'DELETE',
|
||||||
|
});
|
||||||
|
message.success('已删除');
|
||||||
|
void loadDocs(drawerKb);
|
||||||
|
reload();
|
||||||
|
} catch (e) {
|
||||||
|
message.error(e instanceof Error ? e.message : String(e));
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Button type="link" size="small" danger>
|
||||||
|
删除
|
||||||
|
</Button>
|
||||||
|
</Popconfirm>
|
||||||
|
</Space>
|
||||||
|
) : null,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<Space style={{ marginBottom: 16 }} wrap>
|
||||||
|
<Typography.Title level={4} style={{ margin: 0 }}>
|
||||||
|
知识库
|
||||||
|
</Typography.Title>
|
||||||
|
<Typography.Text type="secondary">
|
||||||
|
支持粘贴文本或上传 .txt/.md;可绑定到企微机器人供 AI 检索
|
||||||
|
</Typography.Text>
|
||||||
|
</Space>
|
||||||
|
|
||||||
|
<Form
|
||||||
|
form={filterForm}
|
||||||
|
layout="inline"
|
||||||
|
style={{ marginBottom: 16 }}
|
||||||
|
onFinish={(v) =>
|
||||||
|
setFilters({
|
||||||
|
name: v.name || '',
|
||||||
|
enabled: v.enabled === undefined || v.enabled === null ? '' : String(v.enabled),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<Form.Item name="name" label="名称">
|
||||||
|
<Input allowClear />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item>
|
||||||
|
<Button type="primary" htmlType="submit">
|
||||||
|
查询
|
||||||
|
</Button>
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item>
|
||||||
|
<Button type="primary" onClick={openCreate}>
|
||||||
|
新建知识库
|
||||||
|
</Button>
|
||||||
|
</Form.Item>
|
||||||
|
</Form>
|
||||||
|
|
||||||
|
<Table
|
||||||
|
rowKey="id"
|
||||||
|
loading={loading}
|
||||||
|
columns={columns}
|
||||||
|
dataSource={data?.items}
|
||||||
|
pagination={{
|
||||||
|
current: page,
|
||||||
|
pageSize,
|
||||||
|
total: data?.total,
|
||||||
|
showSizeChanger: true,
|
||||||
|
onChange: (p, ps) => {
|
||||||
|
setPage(p);
|
||||||
|
setPageSize(ps);
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Modal
|
||||||
|
title={editing ? '编辑知识库' : '新建知识库'}
|
||||||
|
open={modalOpen}
|
||||||
|
onCancel={() => setModalOpen(false)}
|
||||||
|
onOk={() => void onSave()}
|
||||||
|
confirmLoading={saving}
|
||||||
|
destroyOnClose
|
||||||
|
>
|
||||||
|
<Form form={form} layout="vertical">
|
||||||
|
<Form.Item name="name" label="名称" rules={[{ required: true }]}>
|
||||||
|
<Input />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="description" label="说明">
|
||||||
|
<Input.TextArea rows={2} />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="enabled" label="启用" valuePropName="checked">
|
||||||
|
<Switch />
|
||||||
|
</Form.Item>
|
||||||
|
</Form>
|
||||||
|
</Modal>
|
||||||
|
|
||||||
|
<Drawer
|
||||||
|
title={drawerKb ? `文档 · ${drawerKb.name}` : '文档'}
|
||||||
|
open={!!drawerKb}
|
||||||
|
width={720}
|
||||||
|
onClose={() => setDrawerKb(null)}
|
||||||
|
extra={
|
||||||
|
drawerKb?.canEditFull ? (
|
||||||
|
<Button type="primary" onClick={() => { docForm.resetFields(); setDocModalOpen(true); }}>
|
||||||
|
上传/粘贴
|
||||||
|
</Button>
|
||||||
|
) : null
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<Table
|
||||||
|
rowKey="id"
|
||||||
|
size="small"
|
||||||
|
loading={docsLoading}
|
||||||
|
columns={docColumns}
|
||||||
|
dataSource={docs}
|
||||||
|
pagination={false}
|
||||||
|
/>
|
||||||
|
</Drawer>
|
||||||
|
|
||||||
|
<Modal
|
||||||
|
title="添加知识文档"
|
||||||
|
open={docModalOpen}
|
||||||
|
onCancel={() => setDocModalOpen(false)}
|
||||||
|
confirmLoading={docSaving}
|
||||||
|
onOk={async () => {
|
||||||
|
if (!drawerKb) return;
|
||||||
|
const values = await docForm.validateFields();
|
||||||
|
setDocSaving(true);
|
||||||
|
try {
|
||||||
|
await request(`/admin/knowledge-bases/${drawerKb.id}/documents`, {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify({
|
||||||
|
title: values.title,
|
||||||
|
contentText: values.contentText || null,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
message.success('已添加');
|
||||||
|
setDocModalOpen(false);
|
||||||
|
void loadDocs(drawerKb);
|
||||||
|
reload();
|
||||||
|
} catch (e) {
|
||||||
|
message.error(e instanceof Error ? e.message : String(e));
|
||||||
|
} finally {
|
||||||
|
setDocSaving(false);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
destroyOnClose
|
||||||
|
width={640}
|
||||||
|
>
|
||||||
|
<Form form={docForm} layout="vertical">
|
||||||
|
<Form.Item name="title" label="标题" rules={[{ required: true }]}>
|
||||||
|
<Input />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="contentText" label="正文(可粘贴)">
|
||||||
|
<Input.TextArea rows={8} placeholder="支持 Markdown / 纯文本" />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item label="或上传文本文件">
|
||||||
|
<Upload
|
||||||
|
accept=".txt,.md,.markdown,.csv,.json,.log,text/*"
|
||||||
|
maxCount={1}
|
||||||
|
customRequest={async ({ file, onSuccess, onError }) => {
|
||||||
|
if (!drawerKb) return;
|
||||||
|
try {
|
||||||
|
const raw = file as File;
|
||||||
|
const uploaded = await uploadFileToOss(raw, {
|
||||||
|
bizType: 'KB_DOCUMENT',
|
||||||
|
mediaType: 'FILE',
|
||||||
|
});
|
||||||
|
const title =
|
||||||
|
docForm.getFieldValue('title') || raw.name.replace(/\.[^.]+$/, '');
|
||||||
|
await request(`/admin/knowledge-bases/${drawerKb.id}/documents`, {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify({
|
||||||
|
title,
|
||||||
|
fileName: raw.name,
|
||||||
|
fileUrl: uploaded.url,
|
||||||
|
mimeType: raw.type || null,
|
||||||
|
sizeBytes: raw.size,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
message.success('上传成功');
|
||||||
|
setDocModalOpen(false);
|
||||||
|
void loadDocs(drawerKb);
|
||||||
|
reload();
|
||||||
|
onSuccess?.(uploaded);
|
||||||
|
} catch (e) {
|
||||||
|
const err = e instanceof Error ? e : new Error(String(e));
|
||||||
|
message.error(err.message);
|
||||||
|
onError?.(err);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
showUploadList={false}
|
||||||
|
>
|
||||||
|
<Button icon={<UploadOutlined />}>上传到 OSS 并入库</Button>
|
||||||
|
</Upload>
|
||||||
|
</Form.Item>
|
||||||
|
</Form>
|
||||||
|
</Modal>
|
||||||
|
|
||||||
|
<Modal
|
||||||
|
title="编辑知识文档"
|
||||||
|
open={editDocModalOpen}
|
||||||
|
onCancel={() => {
|
||||||
|
setEditDocModalOpen(false);
|
||||||
|
setEditingDoc(null);
|
||||||
|
}}
|
||||||
|
confirmLoading={editDocSaving}
|
||||||
|
onOk={async () => {
|
||||||
|
if (!drawerKb || !editingDoc) return;
|
||||||
|
const values = await editDocForm.validateFields();
|
||||||
|
setEditDocSaving(true);
|
||||||
|
try {
|
||||||
|
await request(`/admin/knowledge-bases/${drawerKb.id}/documents/${editingDoc.id}`, {
|
||||||
|
method: 'PUT',
|
||||||
|
body: JSON.stringify({
|
||||||
|
title: values.title,
|
||||||
|
contentText: values.contentText || null,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
message.success('已保存');
|
||||||
|
setEditDocModalOpen(false);
|
||||||
|
setEditingDoc(null);
|
||||||
|
void loadDocs(drawerKb);
|
||||||
|
reload();
|
||||||
|
} catch (e) {
|
||||||
|
message.error(e instanceof Error ? e.message : String(e));
|
||||||
|
} finally {
|
||||||
|
setEditDocSaving(false);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
destroyOnClose
|
||||||
|
width={640}
|
||||||
|
>
|
||||||
|
<Form form={editDocForm} layout="vertical">
|
||||||
|
<Form.Item name="title" label="标题" rules={[{ required: true }]}>
|
||||||
|
<Input />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="contentText" label="正文(可粘贴)">
|
||||||
|
<Input.TextArea rows={8} placeholder="支持 Markdown / 纯文本" />
|
||||||
|
</Form.Item>
|
||||||
|
</Form>
|
||||||
|
</Modal>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,380 @@
|
|||||||
|
import { useEffect, useState } from 'react';
|
||||||
|
import {
|
||||||
|
Button,
|
||||||
|
Form,
|
||||||
|
Input,
|
||||||
|
InputNumber,
|
||||||
|
Modal,
|
||||||
|
Popconfirm,
|
||||||
|
Select,
|
||||||
|
Space,
|
||||||
|
Switch,
|
||||||
|
Table,
|
||||||
|
Tag,
|
||||||
|
Typography,
|
||||||
|
message,
|
||||||
|
} from 'antd';
|
||||||
|
import type { ColumnsType } from 'antd/es/table';
|
||||||
|
import {
|
||||||
|
LLM_PROVIDERS,
|
||||||
|
LLM_PROVIDER_LABELS,
|
||||||
|
LLM_PROVIDER_PRESETS,
|
||||||
|
type LlmApiConfigDto,
|
||||||
|
type LlmProvider,
|
||||||
|
} from '@dukang/shared-types';
|
||||||
|
import { request } from '../lib/api';
|
||||||
|
import { fmtTime } from '../lib/constants';
|
||||||
|
import { useAdminList } from '../lib/useAdminList';
|
||||||
|
|
||||||
|
type FormValues = {
|
||||||
|
name: string;
|
||||||
|
provider: LlmProvider;
|
||||||
|
baseUrl?: string;
|
||||||
|
apiKey?: string;
|
||||||
|
modelName?: string;
|
||||||
|
temperature?: number | null;
|
||||||
|
maxTokens?: number | null;
|
||||||
|
systemPrompt?: string;
|
||||||
|
enabled: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function LlmConfigsPage() {
|
||||||
|
const [filterForm] = Form.useForm();
|
||||||
|
const [form] = Form.useForm<FormValues>();
|
||||||
|
const [filters, setFilters] = useState<Record<string, string>>({});
|
||||||
|
const [modalOpen, setModalOpen] = useState(false);
|
||||||
|
const [editing, setEditing] = useState<LlmApiConfigDto | null>(null);
|
||||||
|
const [saving, setSaving] = useState(false);
|
||||||
|
const providerWatch = Form.useWatch('provider', form);
|
||||||
|
|
||||||
|
const { data, loading, page, pageSize, setPage, setPageSize, reload } = useAdminList<LlmApiConfigDto>(
|
||||||
|
'/admin/llm-configs',
|
||||||
|
() => {
|
||||||
|
const qs = new URLSearchParams();
|
||||||
|
if (filters.name) qs.set('name', filters.name);
|
||||||
|
if (filters.enabled) qs.set('enabled', filters.enabled);
|
||||||
|
return qs;
|
||||||
|
},
|
||||||
|
[filters],
|
||||||
|
);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!providerWatch || editing) return;
|
||||||
|
const preset = LLM_PROVIDER_PRESETS[providerWatch as LlmProvider];
|
||||||
|
if (!preset) return;
|
||||||
|
form.setFieldsValue({
|
||||||
|
baseUrl: preset.defaultBaseUrl || undefined,
|
||||||
|
modelName: preset.defaultModel || undefined,
|
||||||
|
});
|
||||||
|
}, [providerWatch, editing, form]);
|
||||||
|
|
||||||
|
const openCreate = () => {
|
||||||
|
setEditing(null);
|
||||||
|
form.setFieldsValue({
|
||||||
|
name: '',
|
||||||
|
provider: 'DEEPSEEK',
|
||||||
|
baseUrl: LLM_PROVIDER_PRESETS.DEEPSEEK.defaultBaseUrl,
|
||||||
|
apiKey: '',
|
||||||
|
modelName: LLM_PROVIDER_PRESETS.DEEPSEEK.defaultModel,
|
||||||
|
temperature: 0.3,
|
||||||
|
maxTokens: 1024,
|
||||||
|
systemPrompt: '',
|
||||||
|
enabled: true,
|
||||||
|
});
|
||||||
|
setModalOpen(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
const openEdit = (row: LlmApiConfigDto) => {
|
||||||
|
setEditing(row);
|
||||||
|
form.setFieldsValue({
|
||||||
|
name: row.name,
|
||||||
|
provider: row.provider,
|
||||||
|
baseUrl: row.baseUrl,
|
||||||
|
apiKey: '',
|
||||||
|
modelName: row.modelName,
|
||||||
|
temperature: row.temperature,
|
||||||
|
maxTokens: row.maxTokens,
|
||||||
|
systemPrompt: row.systemPrompt || '',
|
||||||
|
enabled: row.enabled,
|
||||||
|
});
|
||||||
|
setModalOpen(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
const onSave = async () => {
|
||||||
|
const values = await form.validateFields();
|
||||||
|
setSaving(true);
|
||||||
|
try {
|
||||||
|
if (editing) {
|
||||||
|
if (!editing.canEditFull) {
|
||||||
|
await request(`/admin/llm-configs/${editing.id}`, {
|
||||||
|
method: 'PUT',
|
||||||
|
body: JSON.stringify({ enabled: values.enabled }),
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
await request(`/admin/llm-configs/${editing.id}`, {
|
||||||
|
method: 'PUT',
|
||||||
|
body: JSON.stringify({
|
||||||
|
name: values.name,
|
||||||
|
provider: values.provider,
|
||||||
|
baseUrl: values.baseUrl,
|
||||||
|
apiKey: values.apiKey || undefined,
|
||||||
|
modelName: values.modelName,
|
||||||
|
temperature: values.temperature ?? null,
|
||||||
|
maxTokens: values.maxTokens ?? null,
|
||||||
|
systemPrompt: values.systemPrompt || null,
|
||||||
|
enabled: values.enabled,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
message.success('已保存');
|
||||||
|
} else {
|
||||||
|
await request('/admin/llm-configs', {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify({
|
||||||
|
name: values.name,
|
||||||
|
provider: values.provider,
|
||||||
|
baseUrl: values.baseUrl,
|
||||||
|
apiKey: values.apiKey,
|
||||||
|
modelName: values.modelName,
|
||||||
|
temperature: values.temperature ?? null,
|
||||||
|
maxTokens: values.maxTokens ?? null,
|
||||||
|
systemPrompt: values.systemPrompt || null,
|
||||||
|
enabled: values.enabled,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
message.success('已创建');
|
||||||
|
}
|
||||||
|
setModalOpen(false);
|
||||||
|
reload();
|
||||||
|
} catch (e) {
|
||||||
|
message.error(e instanceof Error ? e.message : String(e));
|
||||||
|
} finally {
|
||||||
|
setSaving(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const columns: ColumnsType<LlmApiConfigDto> = [
|
||||||
|
{ title: '名称', dataIndex: 'name' },
|
||||||
|
{
|
||||||
|
title: '提供商',
|
||||||
|
dataIndex: 'provider',
|
||||||
|
width: 120,
|
||||||
|
render: (p: LlmProvider) => LLM_PROVIDER_LABELS[p] || p,
|
||||||
|
},
|
||||||
|
{ title: '模型', dataIndex: 'modelName', ellipsis: true },
|
||||||
|
{
|
||||||
|
title: 'Key',
|
||||||
|
dataIndex: 'apiKeyConfigured',
|
||||||
|
width: 80,
|
||||||
|
render: (v: boolean) => (v ? <Tag color="green">已配</Tag> : <Tag>无</Tag>),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '生效',
|
||||||
|
dataIndex: 'enabled',
|
||||||
|
width: 90,
|
||||||
|
render: (v: boolean, row) => (
|
||||||
|
<Switch
|
||||||
|
checked={v}
|
||||||
|
disabled={!row.isOwner && !row.canEditFull}
|
||||||
|
onChange={async (checked) => {
|
||||||
|
try {
|
||||||
|
await request(`/admin/llm-configs/${row.id}`, {
|
||||||
|
method: 'PUT',
|
||||||
|
body: JSON.stringify({ enabled: checked }),
|
||||||
|
});
|
||||||
|
message.success(checked ? '已启用' : '已停用');
|
||||||
|
reload();
|
||||||
|
} catch (e) {
|
||||||
|
message.error(e instanceof Error ? e.message : String(e));
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '创建人',
|
||||||
|
dataIndex: 'createdByName',
|
||||||
|
width: 100,
|
||||||
|
render: (v: string | null, row) => v || row.createdByHqAccountId,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '更新时间',
|
||||||
|
dataIndex: 'updatedAt',
|
||||||
|
width: 170,
|
||||||
|
render: (t: string) => fmtTime(t),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '操作',
|
||||||
|
width: 220,
|
||||||
|
render: (_, row) => (
|
||||||
|
<Space>
|
||||||
|
<Button
|
||||||
|
type="link"
|
||||||
|
size="small"
|
||||||
|
onClick={() => openEdit(row)}
|
||||||
|
>
|
||||||
|
{row.canEditFull ? '编辑' : '开关'}
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
type="link"
|
||||||
|
size="small"
|
||||||
|
onClick={async () => {
|
||||||
|
try {
|
||||||
|
const res = await request<{ reply: string }>(`/admin/llm-configs/${row.id}/test`, {
|
||||||
|
method: 'POST',
|
||||||
|
body: '{}',
|
||||||
|
});
|
||||||
|
message.success(res.reply || '测试成功');
|
||||||
|
} catch (e) {
|
||||||
|
message.error(e instanceof Error ? e.message : String(e));
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
测试
|
||||||
|
</Button>
|
||||||
|
{row.canEditFull ? (
|
||||||
|
<Popconfirm
|
||||||
|
title="确认删除?"
|
||||||
|
onConfirm={async () => {
|
||||||
|
try {
|
||||||
|
await request(`/admin/llm-configs/${row.id}`, { method: 'DELETE' });
|
||||||
|
message.success('已删除');
|
||||||
|
reload();
|
||||||
|
} catch (e) {
|
||||||
|
message.error(e instanceof Error ? e.message : String(e));
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Button type="link" size="small" danger>
|
||||||
|
删除
|
||||||
|
</Button>
|
||||||
|
</Popconfirm>
|
||||||
|
) : null}
|
||||||
|
</Space>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const fullEdit = !editing || editing.canEditFull;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<Space style={{ marginBottom: 16 }} wrap>
|
||||||
|
<Typography.Title level={4} style={{ margin: 0 }}>
|
||||||
|
语言模型配置
|
||||||
|
</Typography.Title>
|
||||||
|
<Typography.Text type="secondary">
|
||||||
|
非超管仅可见自己创建的配置,且创建后只能改是否生效
|
||||||
|
</Typography.Text>
|
||||||
|
</Space>
|
||||||
|
|
||||||
|
<Form
|
||||||
|
form={filterForm}
|
||||||
|
layout="inline"
|
||||||
|
style={{ marginBottom: 16 }}
|
||||||
|
onFinish={(v) =>
|
||||||
|
setFilters({
|
||||||
|
name: v.name || '',
|
||||||
|
enabled: v.enabled === undefined || v.enabled === null ? '' : String(v.enabled),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<Form.Item name="name" label="名称">
|
||||||
|
<Input allowClear placeholder="搜索" />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="enabled" label="生效">
|
||||||
|
<Select
|
||||||
|
allowClear
|
||||||
|
style={{ width: 100 }}
|
||||||
|
options={[
|
||||||
|
{ value: true, label: '开' },
|
||||||
|
{ value: false, label: '关' },
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item>
|
||||||
|
<Button type="primary" htmlType="submit">
|
||||||
|
查询
|
||||||
|
</Button>
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item>
|
||||||
|
<Button type="primary" onClick={openCreate}>
|
||||||
|
新建配置
|
||||||
|
</Button>
|
||||||
|
</Form.Item>
|
||||||
|
</Form>
|
||||||
|
|
||||||
|
<Table
|
||||||
|
rowKey="id"
|
||||||
|
loading={loading}
|
||||||
|
columns={columns}
|
||||||
|
dataSource={data?.items}
|
||||||
|
pagination={{
|
||||||
|
current: page,
|
||||||
|
pageSize,
|
||||||
|
total: data?.total,
|
||||||
|
showSizeChanger: true,
|
||||||
|
onChange: (p, ps) => {
|
||||||
|
setPage(p);
|
||||||
|
setPageSize(ps);
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Modal
|
||||||
|
title={editing ? (fullEdit ? '编辑语言模型' : '修改是否生效') : '新建语言模型'}
|
||||||
|
open={modalOpen}
|
||||||
|
onCancel={() => setModalOpen(false)}
|
||||||
|
onOk={() => void onSave()}
|
||||||
|
confirmLoading={saving}
|
||||||
|
destroyOnClose
|
||||||
|
width={640}
|
||||||
|
>
|
||||||
|
<Form form={form} layout="vertical">
|
||||||
|
<Form.Item name="name" label="名称" rules={[{ required: true, message: '必填' }]}>
|
||||||
|
<Input disabled={!fullEdit} />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="provider" label="提供商" rules={[{ required: true }]}>
|
||||||
|
<Select
|
||||||
|
disabled={!fullEdit}
|
||||||
|
options={LLM_PROVIDERS.map((p) => ({ value: p, label: LLM_PROVIDER_LABELS[p] }))}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item
|
||||||
|
name="baseUrl"
|
||||||
|
label="Base URL"
|
||||||
|
rules={[{ required: fullEdit, message: '必填' }]}
|
||||||
|
extra="填主机根地址即可,如 https://api.deepseek.com(不要带 /v1)"
|
||||||
|
>
|
||||||
|
<Input disabled={!fullEdit} placeholder="https://api.deepseek.com" />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item
|
||||||
|
name="apiKey"
|
||||||
|
label="API Key"
|
||||||
|
rules={editing ? [] : [{ required: true, message: '必填' }]}
|
||||||
|
extra={editing ? '留空表示不修改' : undefined}
|
||||||
|
>
|
||||||
|
<Input.Password disabled={!fullEdit} />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="modelName" label="模型名" rules={[{ required: fullEdit, message: '必填' }]}>
|
||||||
|
<Input disabled={!fullEdit} />
|
||||||
|
</Form.Item>
|
||||||
|
<Space style={{ display: 'flex' }} size="large">
|
||||||
|
<Form.Item name="temperature" label="Temperature">
|
||||||
|
<InputNumber disabled={!fullEdit} min={0} max={2} step={0.1} style={{ width: 120 }} />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="maxTokens" label="Max Tokens">
|
||||||
|
<InputNumber disabled={!fullEdit} min={1} max={128000} style={{ width: 140 }} />
|
||||||
|
</Form.Item>
|
||||||
|
</Space>
|
||||||
|
<Form.Item name="systemPrompt" label="系统提示词">
|
||||||
|
<Input.TextArea disabled={!fullEdit} rows={3} />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="enabled" label="生效" valuePropName="checked">
|
||||||
|
<Switch />
|
||||||
|
</Form.Item>
|
||||||
|
</Form>
|
||||||
|
</Modal>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import { useNavigate } from 'react-router-dom';
|
import { useNavigate } from 'react-router-dom';
|
||||||
import { Button, Card, Form, Input, Tabs, message, Typography } from 'antd';
|
import { Button, Card, Form, Input, Tabs, message, Typography } from 'antd';
|
||||||
|
import { MOCK_SMS_FIXED_CODE } from '@dukang/shared-types';
|
||||||
import { saveAuth, request } from '../lib/api';
|
import { saveAuth, request } from '../lib/api';
|
||||||
|
|
||||||
type LoginResult = { accessToken: string; refreshToken: string };
|
type LoginResult = { accessToken: string; refreshToken: string };
|
||||||
@@ -117,14 +118,14 @@ export default function LoginPage() {
|
|||||||
form={smsForm}
|
form={smsForm}
|
||||||
layout="vertical"
|
layout="vertical"
|
||||||
onFinish={onSmsFinish}
|
onFinish={onSmsFinish}
|
||||||
initialValues={{ phone: '13600000001', code: '123456' }}
|
initialValues={{ phone: '13600000001', code: MOCK_SMS_FIXED_CODE }}
|
||||||
>
|
>
|
||||||
<Form.Item name="phone" label="手机号" rules={[{ required: true, message: '请输入手机号' }]}>
|
<Form.Item name="phone" label="手机号" rules={[{ required: true, message: '请输入手机号' }]}>
|
||||||
<Input placeholder="13600000001" maxLength={11} />
|
<Input placeholder="13600000001" maxLength={11} />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item name="code" label="验证码" rules={[{ required: true, message: '请输入验证码' }]}>
|
<Form.Item name="code" label="验证码" rules={[{ required: true, message: '请输入验证码' }]}>
|
||||||
<Input
|
<Input
|
||||||
placeholder="123456"
|
placeholder={MOCK_SMS_FIXED_CODE}
|
||||||
addonAfter={
|
addonAfter={
|
||||||
<Button type="link" size="small" disabled={codeCooldown > 0} onClick={() => void sendCode()}>
|
<Button type="link" size="small" disabled={codeCooldown > 0} onClick={() => void sendCode()}>
|
||||||
{codeCooldown > 0 ? `${codeCooldown}s` : '获取验证码'}
|
{codeCooldown > 0 ? `${codeCooldown}s` : '获取验证码'}
|
||||||
|
|||||||
@@ -0,0 +1,625 @@
|
|||||||
|
import { useEffect, useState } from 'react';
|
||||||
|
import {
|
||||||
|
Button,
|
||||||
|
Card,
|
||||||
|
DatePicker,
|
||||||
|
Descriptions,
|
||||||
|
Drawer,
|
||||||
|
Form,
|
||||||
|
Input,
|
||||||
|
InputNumber,
|
||||||
|
Modal,
|
||||||
|
Select,
|
||||||
|
Space,
|
||||||
|
Statistic,
|
||||||
|
Table,
|
||||||
|
Tabs,
|
||||||
|
Tag,
|
||||||
|
Typography,
|
||||||
|
message,
|
||||||
|
} from 'antd';
|
||||||
|
import type { ColumnsType } from 'antd/es/table';
|
||||||
|
import type { Dayjs } from 'dayjs';
|
||||||
|
import dayjs from 'dayjs';
|
||||||
|
import {
|
||||||
|
LOGISTICS_SETTLEMENT_METHOD_LABELS,
|
||||||
|
type LogisticsSettlementMethod,
|
||||||
|
} from '@dukang/shared-types';
|
||||||
|
import { fmtTime } from '../lib/constants';
|
||||||
|
import { downloadExcelCsv } from '../lib/exportExcel';
|
||||||
|
import { request } from '../lib/api';
|
||||||
|
import { useAdminList } from '../lib/useAdminList';
|
||||||
|
|
||||||
|
type BillRow = {
|
||||||
|
id: string;
|
||||||
|
billNo: string;
|
||||||
|
fulfillmentProviderId: string;
|
||||||
|
providerCode?: string;
|
||||||
|
providerName?: string;
|
||||||
|
periodStart: string;
|
||||||
|
periodEnd: string;
|
||||||
|
orderCount: number;
|
||||||
|
bottleCount: number;
|
||||||
|
logisticsAmount: number;
|
||||||
|
settlementMethod: string;
|
||||||
|
status: string;
|
||||||
|
paidAt?: string | null;
|
||||||
|
};
|
||||||
|
|
||||||
|
type BillItem = {
|
||||||
|
id: string;
|
||||||
|
orderNo: string;
|
||||||
|
quantity: number;
|
||||||
|
logisticsAmount: number;
|
||||||
|
shippedAt: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
type ProviderSummary = {
|
||||||
|
providerId: string;
|
||||||
|
providerCode: string;
|
||||||
|
providerName: string;
|
||||||
|
settlementMethod: string;
|
||||||
|
prepaidBalance: number;
|
||||||
|
bankAccountName?: string | null;
|
||||||
|
bankName?: string | null;
|
||||||
|
bankAccountNo?: string | null;
|
||||||
|
orderCount: number;
|
||||||
|
bottleCount: number;
|
||||||
|
logisticsAmount: number;
|
||||||
|
billId?: string | null;
|
||||||
|
billStatus?: string | null;
|
||||||
|
pricingRules?: {
|
||||||
|
baseBottles: number;
|
||||||
|
baseFee: number;
|
||||||
|
extraBottleFee: number;
|
||||||
|
boxBottles?: number;
|
||||||
|
boxFee?: number;
|
||||||
|
} | null;
|
||||||
|
};
|
||||||
|
|
||||||
|
const STATUS_LABELS: Record<string, string> = {
|
||||||
|
UNPAID: '未结算',
|
||||||
|
PAID: '已结算',
|
||||||
|
};
|
||||||
|
|
||||||
|
const STATUS_COLORS: Record<string, string> = {
|
||||||
|
UNPAID: 'red',
|
||||||
|
PAID: 'green',
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function LogisticsBillsPage() {
|
||||||
|
const [form] = Form.useForm();
|
||||||
|
const [summaryForm] = Form.useForm();
|
||||||
|
const [filters, setFilters] = useState<Record<string, string>>({});
|
||||||
|
const { data, loading, page, pageSize, setPage, setPageSize, reload } = useAdminList<BillRow>(
|
||||||
|
'/admin/logistics-bills',
|
||||||
|
() => {
|
||||||
|
const qs = new URLSearchParams();
|
||||||
|
if (filters.status) qs.set('status', filters.status);
|
||||||
|
if (filters.providerId) qs.set('providerId', filters.providerId);
|
||||||
|
if (filters.year) qs.set('year', filters.year);
|
||||||
|
if (filters.month) qs.set('month', filters.month);
|
||||||
|
return qs;
|
||||||
|
},
|
||||||
|
[filters],
|
||||||
|
);
|
||||||
|
const [exporting, setExporting] = useState(false);
|
||||||
|
const [selectedKeys, setSelectedKeys] = useState<React.Key[]>([]);
|
||||||
|
const [detail, setDetail] = useState<(BillRow & { items?: BillItem[] }) | null>(null);
|
||||||
|
const [drawerOpen, setDrawerOpen] = useState(false);
|
||||||
|
const [providers, setProviders] = useState<Array<{ id: string; code: string; name: string }>>([]);
|
||||||
|
const [summaryRows, setSummaryRows] = useState<ProviderSummary[]>([]);
|
||||||
|
const [summaryLoading, setSummaryLoading] = useState(false);
|
||||||
|
const [summaryPeriod, setSummaryPeriod] = useState(() => dayjs().subtract(1, 'month'));
|
||||||
|
const [genOpen, setGenOpen] = useState(false);
|
||||||
|
const [genForm] = Form.useForm();
|
||||||
|
const [rechargeOpen, setRechargeOpen] = useState(false);
|
||||||
|
const [rechargeTarget, setRechargeTarget] = useState<ProviderSummary | null>(null);
|
||||||
|
const [rechargeForm] = Form.useForm();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
request<Array<{ id: string; code: string; name: string }>>('/admin/fulfillment-providers')
|
||||||
|
.then((rows) => setProviders(rows.map((r) => ({ id: r.id, code: r.code, name: r.name }))))
|
||||||
|
.catch(() => {});
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
async function loadSummary(period: Dayjs) {
|
||||||
|
setSummaryLoading(true);
|
||||||
|
try {
|
||||||
|
const res = await request<{ items: ProviderSummary[] }>(
|
||||||
|
`/admin/logistics-bills/provider-summary?year=${period.year()}&month=${period.month() + 1}`,
|
||||||
|
);
|
||||||
|
setSummaryRows(res.items ?? []);
|
||||||
|
} finally {
|
||||||
|
setSummaryLoading(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
void loadSummary(summaryPeriod);
|
||||||
|
}, [summaryPeriod]);
|
||||||
|
|
||||||
|
function confirmPay(ids: string[], amountHint?: number) {
|
||||||
|
Modal.confirm({
|
||||||
|
title: '确认结算?',
|
||||||
|
content: `将确认 ${ids.length} 笔物流对账单${amountHint != null ? `,合计约 ¥${amountHint.toFixed(2)}` : ''}。充值模式将扣减余额,挂账模式标记已打款。`,
|
||||||
|
okText: '确认结算',
|
||||||
|
cancelText: '取消',
|
||||||
|
onOk: async () => {
|
||||||
|
if (ids.length === 1) {
|
||||||
|
await request(`/admin/logistics-bills/${ids[0]}/confirm`, { method: 'POST' });
|
||||||
|
} else {
|
||||||
|
await request('/admin/logistics-bills/batch-confirm', {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify({ ids }),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
message.success('已确认结算');
|
||||||
|
setSelectedKeys([]);
|
||||||
|
reload();
|
||||||
|
void loadSummary(summaryPeriod);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async function openDetail(id: string) {
|
||||||
|
const d = await request<BillRow & { items?: BillItem[] }>(`/admin/logistics-bills/${id}`);
|
||||||
|
setDetail(d);
|
||||||
|
setDrawerOpen(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function exportExcel() {
|
||||||
|
setExporting(true);
|
||||||
|
try {
|
||||||
|
const qs = new URLSearchParams();
|
||||||
|
if (filters.status) qs.set('status', filters.status);
|
||||||
|
if (filters.providerId) qs.set('providerId', filters.providerId);
|
||||||
|
if (filters.year) qs.set('year', filters.year);
|
||||||
|
if (filters.month) qs.set('month', filters.month);
|
||||||
|
const result = await request<{ csv: string; count: number }>(
|
||||||
|
`/admin/logistics-bills/export?${qs}`,
|
||||||
|
);
|
||||||
|
const suffix = filters.year && filters.month ? `${filters.year}-${filters.month}` : 'all';
|
||||||
|
downloadExcelCsv(result.csv, `物流对账单_${suffix}.csv`);
|
||||||
|
message.success(`已导出 ${result.count} 条`);
|
||||||
|
} finally {
|
||||||
|
setExporting(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function generateBills() {
|
||||||
|
const v = await genForm.validateFields();
|
||||||
|
const month = v.month as Dayjs;
|
||||||
|
await request('/admin/logistics-bills/generate', {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify({
|
||||||
|
year: month.year(),
|
||||||
|
month: month.month() + 1,
|
||||||
|
providerId: v.providerId || undefined,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
message.success('已生成物流对账单');
|
||||||
|
setGenOpen(false);
|
||||||
|
reload();
|
||||||
|
void loadSummary(summaryPeriod);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function submitRecharge() {
|
||||||
|
if (!rechargeTarget) return;
|
||||||
|
const v = await rechargeForm.validateFields();
|
||||||
|
await request(`/admin/fulfillment-providers/${rechargeTarget.providerId}/recharge`, {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify({ amount: v.amount, remark: v.remark }),
|
||||||
|
});
|
||||||
|
message.success('充值成功');
|
||||||
|
setRechargeOpen(false);
|
||||||
|
void loadSummary(summaryPeriod);
|
||||||
|
}
|
||||||
|
|
||||||
|
const summary = data?.summary;
|
||||||
|
const selectedRows = (data?.items ?? []).filter((r) => selectedKeys.includes(r.id));
|
||||||
|
const selectedAmount = selectedRows.reduce((s, r) => s + Number(r.logisticsAmount), 0);
|
||||||
|
|
||||||
|
const billColumns: ColumnsType<BillRow> = [
|
||||||
|
{ title: '账单号', dataIndex: 'billNo', width: 170, ellipsis: true },
|
||||||
|
{
|
||||||
|
title: '承运商',
|
||||||
|
width: 140,
|
||||||
|
render: (_, r) => `${r.providerName || ''} (${r.providerCode || ''})`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '账期',
|
||||||
|
width: 200,
|
||||||
|
render: (_, r) =>
|
||||||
|
`${String(r.periodStart || '').slice(0, 10)} ~ ${String(r.periodEnd || '').slice(0, 10)}`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '结算方式',
|
||||||
|
dataIndex: 'settlementMethod',
|
||||||
|
width: 100,
|
||||||
|
render: (v) =>
|
||||||
|
LOGISTICS_SETTLEMENT_METHOD_LABELS[v as LogisticsSettlementMethod] || v,
|
||||||
|
},
|
||||||
|
{ title: '订单数', dataIndex: 'orderCount', width: 80 },
|
||||||
|
{ title: '瓶数', dataIndex: 'bottleCount', width: 80 },
|
||||||
|
{
|
||||||
|
title: '物流费',
|
||||||
|
dataIndex: 'logisticsAmount',
|
||||||
|
width: 110,
|
||||||
|
render: (v) => `¥${Number(v).toFixed(2)}`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '状态',
|
||||||
|
dataIndex: 'status',
|
||||||
|
width: 90,
|
||||||
|
render: (s) => <Tag color={STATUS_COLORS[s] || 'default'}>{STATUS_LABELS[s] || s}</Tag>,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '操作',
|
||||||
|
width: 160,
|
||||||
|
fixed: 'right',
|
||||||
|
render: (_, row) => (
|
||||||
|
<Space size={0}>
|
||||||
|
<Button type="link" size="small" onClick={() => void openDetail(row.id)}>
|
||||||
|
明细
|
||||||
|
</Button>
|
||||||
|
{row.status === 'UNPAID' && (
|
||||||
|
<Button
|
||||||
|
type="link"
|
||||||
|
size="small"
|
||||||
|
onClick={() => confirmPay([row.id], Number(row.logisticsAmount))}
|
||||||
|
>
|
||||||
|
确认结算
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
</Space>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const summaryColumns: ColumnsType<ProviderSummary> = [
|
||||||
|
{
|
||||||
|
title: '承运商',
|
||||||
|
render: (_, r) => `${r.providerName} (${r.providerCode})`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '结算方式',
|
||||||
|
dataIndex: 'settlementMethod',
|
||||||
|
width: 110,
|
||||||
|
render: (v) =>
|
||||||
|
LOGISTICS_SETTLEMENT_METHOD_LABELS[v as LogisticsSettlementMethod] || v,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '计价标准',
|
||||||
|
width: 220,
|
||||||
|
render: (_, r) => {
|
||||||
|
const p = r.pricingRules;
|
||||||
|
if (!p) return '—';
|
||||||
|
return `${p.baseBottles}瓶¥${p.baseFee},加瓶¥${p.extraBottleFee}${
|
||||||
|
p.boxBottles ? `,${p.boxBottles}瓶箱¥${p.boxFee}` : ''
|
||||||
|
}`;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '银行账户',
|
||||||
|
width: 180,
|
||||||
|
ellipsis: true,
|
||||||
|
render: (_, r) =>
|
||||||
|
r.bankAccountName
|
||||||
|
? `${r.bankAccountName} / ${r.bankName || ''} ${r.bankAccountNo || ''}`
|
||||||
|
: '—',
|
||||||
|
},
|
||||||
|
{ title: '订单数', dataIndex: 'orderCount', width: 80 },
|
||||||
|
{ title: '瓶数', dataIndex: 'bottleCount', width: 80 },
|
||||||
|
{
|
||||||
|
title: '应付物流费',
|
||||||
|
dataIndex: 'logisticsAmount',
|
||||||
|
width: 110,
|
||||||
|
render: (v) => `¥${Number(v).toFixed(2)}`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '充值余额',
|
||||||
|
dataIndex: 'prepaidBalance',
|
||||||
|
width: 110,
|
||||||
|
render: (v) => `¥${Number(v).toFixed(2)}`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '账单',
|
||||||
|
width: 100,
|
||||||
|
render: (_, r) =>
|
||||||
|
r.billStatus ? (
|
||||||
|
<Tag color={STATUS_COLORS[r.billStatus] || 'default'}>
|
||||||
|
{STATUS_LABELS[r.billStatus] || r.billStatus}
|
||||||
|
</Tag>
|
||||||
|
) : (
|
||||||
|
'未生成'
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '操作',
|
||||||
|
width: 100,
|
||||||
|
render: (_, r) =>
|
||||||
|
r.settlementMethod === 'PREPAID' ? (
|
||||||
|
<Button
|
||||||
|
type="link"
|
||||||
|
size="small"
|
||||||
|
onClick={() => {
|
||||||
|
setRechargeTarget(r);
|
||||||
|
rechargeForm.resetFields();
|
||||||
|
setRechargeOpen(true);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
充值
|
||||||
|
</Button>
|
||||||
|
) : null,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<Space direction="vertical" size={0} style={{ marginBottom: 16 }}>
|
||||||
|
<Typography.Title level={4} style={{ margin: 0 }}>
|
||||||
|
物流对账
|
||||||
|
</Typography.Title>
|
||||||
|
<Typography.Text type="secondary">
|
||||||
|
按快递承运商汇总月度物流费;计价与银行账户在「仓配管理」配置。前期充值扣款,后期可切挂账月结。
|
||||||
|
</Typography.Text>
|
||||||
|
</Space>
|
||||||
|
|
||||||
|
<Tabs
|
||||||
|
items={[
|
||||||
|
{
|
||||||
|
key: 'summary',
|
||||||
|
label: '按承运商汇总',
|
||||||
|
children: (
|
||||||
|
<>
|
||||||
|
<Form
|
||||||
|
form={summaryForm}
|
||||||
|
layout="inline"
|
||||||
|
style={{ marginBottom: 16 }}
|
||||||
|
initialValues={{ month: summaryPeriod }}
|
||||||
|
onFinish={(v: { month?: Dayjs }) => {
|
||||||
|
const m = v.month || dayjs().subtract(1, 'month');
|
||||||
|
setSummaryPeriod(m);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Form.Item name="month" label="账期">
|
||||||
|
<DatePicker picker="month" allowClear={false} />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item>
|
||||||
|
<Button type="primary" htmlType="submit">
|
||||||
|
查询
|
||||||
|
</Button>
|
||||||
|
</Form.Item>
|
||||||
|
</Form>
|
||||||
|
<Table
|
||||||
|
rowKey="providerId"
|
||||||
|
loading={summaryLoading}
|
||||||
|
columns={summaryColumns}
|
||||||
|
dataSource={summaryRows}
|
||||||
|
pagination={false}
|
||||||
|
scroll={{ x: 1200 }}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'bills',
|
||||||
|
label: '月账单',
|
||||||
|
children: (
|
||||||
|
<>
|
||||||
|
{summary && (
|
||||||
|
<Card size="small" style={{ marginBottom: 16 }}>
|
||||||
|
<Space size="large" wrap>
|
||||||
|
<Statistic title="账单数" value={summary.count} />
|
||||||
|
<Statistic
|
||||||
|
title="瓶数合计"
|
||||||
|
value={summary.bottleCount ?? 0}
|
||||||
|
/>
|
||||||
|
<Statistic
|
||||||
|
title="物流费合计"
|
||||||
|
value={summary.logisticsAmount ?? summary.totalAmount ?? 0}
|
||||||
|
prefix="¥"
|
||||||
|
precision={2}
|
||||||
|
/>
|
||||||
|
</Space>
|
||||||
|
</Card>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<Form
|
||||||
|
form={form}
|
||||||
|
layout="inline"
|
||||||
|
style={{ marginBottom: 16 }}
|
||||||
|
onFinish={(v: {
|
||||||
|
status?: string;
|
||||||
|
providerId?: string;
|
||||||
|
month?: Dayjs;
|
||||||
|
}) => {
|
||||||
|
setFilters({
|
||||||
|
status: v.status || '',
|
||||||
|
providerId: v.providerId || '',
|
||||||
|
year: v.month ? String(v.month.year()) : '',
|
||||||
|
month: v.month ? String(v.month.month() + 1) : '',
|
||||||
|
});
|
||||||
|
setPage(1);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Form.Item name="status" label="状态">
|
||||||
|
<Select
|
||||||
|
allowClear
|
||||||
|
style={{ width: 120 }}
|
||||||
|
options={[
|
||||||
|
{ value: 'UNPAID', label: '未结算' },
|
||||||
|
{ value: 'PAID', label: '已结算' },
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="providerId" label="承运商">
|
||||||
|
<Select
|
||||||
|
allowClear
|
||||||
|
style={{ width: 180 }}
|
||||||
|
options={providers.map((p) => ({
|
||||||
|
value: p.id,
|
||||||
|
label: `${p.name} (${p.code})`,
|
||||||
|
}))}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="month" label="账期">
|
||||||
|
<DatePicker picker="month" />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item>
|
||||||
|
<Space>
|
||||||
|
<Button type="primary" htmlType="submit">
|
||||||
|
查询
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
onClick={() => {
|
||||||
|
genForm.setFieldsValue({ month: dayjs().subtract(1, 'month') });
|
||||||
|
setGenOpen(true);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
生成账单
|
||||||
|
</Button>
|
||||||
|
<Button loading={exporting} onClick={() => void exportExcel()}>
|
||||||
|
导出
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
disabled={!selectedKeys.length}
|
||||||
|
onClick={() =>
|
||||||
|
confirmPay(
|
||||||
|
selectedKeys.map(String),
|
||||||
|
selectedAmount,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
>
|
||||||
|
批量结算
|
||||||
|
</Button>
|
||||||
|
</Space>
|
||||||
|
</Form.Item>
|
||||||
|
</Form>
|
||||||
|
|
||||||
|
<Table
|
||||||
|
rowKey="id"
|
||||||
|
loading={loading}
|
||||||
|
columns={billColumns}
|
||||||
|
dataSource={data?.items ?? []}
|
||||||
|
rowSelection={{
|
||||||
|
selectedRowKeys: selectedKeys,
|
||||||
|
onChange: setSelectedKeys,
|
||||||
|
getCheckboxProps: (r) => ({ disabled: r.status !== 'UNPAID' }),
|
||||||
|
}}
|
||||||
|
pagination={{
|
||||||
|
current: page,
|
||||||
|
pageSize,
|
||||||
|
total: data?.total ?? 0,
|
||||||
|
onChange: (p, ps) => {
|
||||||
|
setPage(p);
|
||||||
|
setPageSize(ps);
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
scroll={{ x: 1100 }}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Drawer
|
||||||
|
title="物流对账明细"
|
||||||
|
width={640}
|
||||||
|
open={drawerOpen}
|
||||||
|
onClose={() => setDrawerOpen(false)}
|
||||||
|
>
|
||||||
|
{detail && (
|
||||||
|
<>
|
||||||
|
<Descriptions column={1} size="small" style={{ marginBottom: 16 }}>
|
||||||
|
<Descriptions.Item label="账单号">{detail.billNo}</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="承运商">
|
||||||
|
{detail.providerName} ({detail.providerCode})
|
||||||
|
</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="账期">
|
||||||
|
{String(detail.periodStart).slice(0, 10)} ~ {String(detail.periodEnd).slice(0, 10)}
|
||||||
|
</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="物流费">
|
||||||
|
¥{Number(detail.logisticsAmount).toFixed(2)}
|
||||||
|
</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="状态">
|
||||||
|
{STATUS_LABELS[detail.status] || detail.status}
|
||||||
|
</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="结算时间">
|
||||||
|
{detail.paidAt ? fmtTime(detail.paidAt) : '—'}
|
||||||
|
</Descriptions.Item>
|
||||||
|
</Descriptions>
|
||||||
|
<Table
|
||||||
|
rowKey="id"
|
||||||
|
size="small"
|
||||||
|
pagination={false}
|
||||||
|
dataSource={detail.items ?? []}
|
||||||
|
columns={[
|
||||||
|
{ title: '订单号', dataIndex: 'orderNo' },
|
||||||
|
{ title: '瓶数', dataIndex: 'quantity', width: 70 },
|
||||||
|
{
|
||||||
|
title: '物流费',
|
||||||
|
dataIndex: 'logisticsAmount',
|
||||||
|
width: 90,
|
||||||
|
render: (v) => `¥${Number(v).toFixed(2)}`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '发货时间',
|
||||||
|
dataIndex: 'shippedAt',
|
||||||
|
width: 160,
|
||||||
|
render: fmtTime,
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</Drawer>
|
||||||
|
|
||||||
|
<Modal
|
||||||
|
title="生成物流月账单"
|
||||||
|
open={genOpen}
|
||||||
|
onCancel={() => setGenOpen(false)}
|
||||||
|
onOk={() => void generateBills()}
|
||||||
|
destroyOnClose
|
||||||
|
>
|
||||||
|
<Form form={genForm} layout="vertical">
|
||||||
|
<Form.Item name="month" label="账期月" rules={[{ required: true }]}>
|
||||||
|
<DatePicker picker="month" style={{ width: '100%' }} />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="providerId" label="承运商(空=全部)">
|
||||||
|
<Select
|
||||||
|
allowClear
|
||||||
|
options={providers.map((p) => ({
|
||||||
|
value: p.id,
|
||||||
|
label: `${p.name} (${p.code})`,
|
||||||
|
}))}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
</Form>
|
||||||
|
</Modal>
|
||||||
|
|
||||||
|
<Modal
|
||||||
|
title={rechargeTarget ? `充值 · ${rechargeTarget.providerName}` : '充值'}
|
||||||
|
open={rechargeOpen}
|
||||||
|
onCancel={() => setRechargeOpen(false)}
|
||||||
|
onOk={() => void submitRecharge()}
|
||||||
|
destroyOnClose
|
||||||
|
>
|
||||||
|
<Form form={rechargeForm} layout="vertical">
|
||||||
|
<Form.Item
|
||||||
|
name="amount"
|
||||||
|
label="金额"
|
||||||
|
rules={[{ required: true, message: '请输入充值金额' }]}
|
||||||
|
>
|
||||||
|
<InputNumber min={0.01} precision={2} style={{ width: '100%' }} prefix="¥" />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="remark" label="备注">
|
||||||
|
<Input placeholder="可选,如预充运费" />
|
||||||
|
</Form.Item>
|
||||||
|
</Form>
|
||||||
|
</Modal>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,7 +1,9 @@
|
|||||||
import { useCallback, useEffect, useMemo, useState } from 'react';
|
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
||||||
|
import { Link, useSearchParams } from 'react-router-dom';
|
||||||
import {
|
import {
|
||||||
Alert,
|
Alert,
|
||||||
Button,
|
Button,
|
||||||
|
Checkbox,
|
||||||
Collapse,
|
Collapse,
|
||||||
Descriptions,
|
Descriptions,
|
||||||
Drawer,
|
Drawer,
|
||||||
@@ -18,14 +20,18 @@ import {
|
|||||||
message,
|
message,
|
||||||
} from 'antd';
|
} from 'antd';
|
||||||
import type { ColumnsType } from 'antd/es/table';
|
import type { ColumnsType } from 'antd/es/table';
|
||||||
import { request, type AdminOrderItem, type AdminOrderRow, type Paginated } from '../lib/api';
|
import { request, type AdminOrderItem, type AdminOrderRow, type HqProfile, type Paginated } from '../lib/api';
|
||||||
import {
|
import {
|
||||||
ADMIN_OPTIONS_PAGE_SIZE,
|
ADMIN_OPTIONS_PAGE_SIZE,
|
||||||
DELIVERY_PROVIDER_LABELS,
|
DELIVERY_PROVIDER_LABELS,
|
||||||
ORDER_STATUS_COLORS,
|
ORDER_STATUS_COLORS,
|
||||||
ORDER_STATUS_LABELS,
|
ORDER_STATUS_LABELS,
|
||||||
|
ORDER_STATUS_OPERATOR_LABELS,
|
||||||
fmtTime,
|
fmtTime,
|
||||||
} from '../lib/constants';
|
} from '../lib/constants';
|
||||||
|
import { FULFILLMENT_HOLD_REASON_LABELS } from '@dukang/shared-types';
|
||||||
|
import ProxyOrderModal from '../components/ProxyOrderModal';
|
||||||
|
import OrderTrackDrawer from '../components/OrderTrackDrawer';
|
||||||
|
|
||||||
type ShipDefaults = {
|
type ShipDefaults = {
|
||||||
provider: string;
|
provider: string;
|
||||||
@@ -55,6 +61,28 @@ type WarehouseOption = {
|
|||||||
lat?: number | null;
|
lat?: number | null;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
type OrderRedeemRecord = {
|
||||||
|
id: string;
|
||||||
|
redeemNo: string;
|
||||||
|
amount: number;
|
||||||
|
settleAmount: number;
|
||||||
|
/** 本单权益券在该核销单中的分摊额 */
|
||||||
|
couponAmount?: number;
|
||||||
|
role?: 'PRIMARY' | 'SECONDARY';
|
||||||
|
createdAt: string;
|
||||||
|
store?: { id: string; name: string; cityName?: string | null } | null;
|
||||||
|
};
|
||||||
|
|
||||||
|
type OrderRedeemSummary = {
|
||||||
|
couponNo: string;
|
||||||
|
totalAmount: number;
|
||||||
|
usedAmount: number;
|
||||||
|
balance: number;
|
||||||
|
status: string;
|
||||||
|
redeemCount: number;
|
||||||
|
redeemRecordSum: number;
|
||||||
|
};
|
||||||
|
|
||||||
type OrderDetail = AdminOrderRow & {
|
type OrderDetail = AdminOrderRow & {
|
||||||
receiverAddress?: string;
|
receiverAddress?: string;
|
||||||
receiverProvince?: string;
|
receiverProvince?: string;
|
||||||
@@ -79,8 +107,16 @@ type OrderDetail = AdminOrderRow & {
|
|||||||
listUnitPrice?: number;
|
listUnitPrice?: number;
|
||||||
items?: AdminOrderItem[];
|
items?: AdminOrderItem[];
|
||||||
payment?: Record<string, unknown> | null;
|
payment?: Record<string, unknown> | null;
|
||||||
statusLogs?: Array<{ fromStatus: string | null; toStatus: string; createdAt: string }>;
|
statusLogs?: Array<{
|
||||||
|
fromStatus: string | null;
|
||||||
|
toStatus: string;
|
||||||
|
operator?: string | null;
|
||||||
|
remark?: string | null;
|
||||||
|
createdAt: string;
|
||||||
|
}>;
|
||||||
benefitCoupons?: Array<Record<string, unknown>>;
|
benefitCoupons?: Array<Record<string, unknown>>;
|
||||||
|
redeemSummary?: OrderRedeemSummary | null;
|
||||||
|
redeemRecords?: OrderRedeemRecord[];
|
||||||
fulfillmentWarehouse?: {
|
fulfillmentWarehouse?: {
|
||||||
id: string;
|
id: string;
|
||||||
name: string;
|
name: string;
|
||||||
@@ -126,18 +162,26 @@ function warehouseToDefaults(wh: WarehouseOption, base?: ShipDefaults | null): S
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default function OrdersPage() {
|
export default function OrdersPage() {
|
||||||
|
const [searchParams] = useSearchParams();
|
||||||
|
const initialOrderNo = searchParams.get('orderNo')?.trim() || '';
|
||||||
const [form] = Form.useForm();
|
const [form] = Form.useForm();
|
||||||
const [shipForm] = Form.useForm();
|
const [shipForm] = Form.useForm();
|
||||||
const [logisticsForm] = Form.useForm();
|
const [logisticsForm] = Form.useForm();
|
||||||
|
const [profile, setProfile] = useState<HqProfile | null>(null);
|
||||||
const [data, setData] = useState<Paginated<AdminOrderRow> | null>(null);
|
const [data, setData] = useState<Paginated<AdminOrderRow> | null>(null);
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const [page, setPage] = useState(1);
|
const [page, setPage] = useState(1);
|
||||||
const [pageSize, setPageSize] = useState(20);
|
const [pageSize, setPageSize] = useState(20);
|
||||||
const [detail, setDetail] = useState<OrderDetail | null>(null);
|
const [detail, setDetail] = useState<OrderDetail | null>(null);
|
||||||
const [drawerOpen, setDrawerOpen] = useState(false);
|
const [drawerOpen, setDrawerOpen] = useState(false);
|
||||||
|
const deepLinkOpenedRef = useRef(false);
|
||||||
|
const [redeemDetail, setRedeemDetail] = useState<Record<string, unknown> | null>(null);
|
||||||
|
const [redeemDrawerOpen, setRedeemDrawerOpen] = useState(false);
|
||||||
|
const [redeemDetailLoading, setRedeemDetailLoading] = useState(false);
|
||||||
const [selectedRowKeys, setSelectedRowKeys] = useState<string[]>([]);
|
const [selectedRowKeys, setSelectedRowKeys] = useState<string[]>([]);
|
||||||
const [batchDeleteOpen, setBatchDeleteOpen] = useState(false);
|
const [batchDeleteOpen, setBatchDeleteOpen] = useState(false);
|
||||||
const [batchDeleting, setBatchDeleting] = useState(false);
|
const [batchDeleting, setBatchDeleting] = useState(false);
|
||||||
|
const [deletingId, setDeletingId] = useState<string | null>(null);
|
||||||
const [shipDefaults, setShipDefaults] = useState<ShipDefaults | null>(null);
|
const [shipDefaults, setShipDefaults] = useState<ShipDefaults | null>(null);
|
||||||
const [shipping, setShipping] = useState(false);
|
const [shipping, setShipping] = useState(false);
|
||||||
const [logisticsShipping, setLogisticsShipping] = useState(false);
|
const [logisticsShipping, setLogisticsShipping] = useState(false);
|
||||||
@@ -146,12 +190,49 @@ export default function OrdersPage() {
|
|||||||
const [shipTarget, setShipTarget] = useState<OrderDetail | null>(null);
|
const [shipTarget, setShipTarget] = useState<OrderDetail | null>(null);
|
||||||
const [shipMode, setShipMode] = useState<ShipMode>('EXPRESS');
|
const [shipMode, setShipMode] = useState<ShipMode>('EXPRESS');
|
||||||
const [warehouses, setWarehouses] = useState<WarehouseOption[]>([]);
|
const [warehouses, setWarehouses] = useState<WarehouseOption[]>([]);
|
||||||
|
const [proxyOpen, setProxyOpen] = useState(false);
|
||||||
|
const [trackOpen, setTrackOpen] = useState(false);
|
||||||
|
const canDeleteOrders = (profile?.permissionKeys ?? []).includes('orders_delete');
|
||||||
|
const canProxyOrder = (profile?.permissionKeys ?? []).includes('orders');
|
||||||
|
|
||||||
const selectedOrders = useMemo(
|
const selectedOrders = useMemo(
|
||||||
() => (data?.items ?? []).filter((row) => selectedRowKeys.includes(row.id)),
|
() => (data?.items ?? []).filter((row) => selectedRowKeys.includes(row.id)),
|
||||||
[data?.items, selectedRowKeys],
|
[data?.items, selectedRowKeys],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
request<HqProfile>('/admin/auth/me').then(setProfile).catch(() => {});
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (initialOrderNo) {
|
||||||
|
form.setFieldsValue({ orderNo: initialOrderNo });
|
||||||
|
}
|
||||||
|
}, [form, initialOrderNo]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!initialOrderNo || deepLinkOpenedRef.current || loading) return;
|
||||||
|
const first = data?.items?.[0];
|
||||||
|
if (first && String(first.orderNo) === initialOrderNo) {
|
||||||
|
deepLinkOpenedRef.current = true;
|
||||||
|
void openDetail(first.id);
|
||||||
|
}
|
||||||
|
}, [data, initialOrderNo, loading]);
|
||||||
|
|
||||||
|
async function openRedeemDetail(redeemId: string) {
|
||||||
|
setRedeemDetailLoading(true);
|
||||||
|
setRedeemDrawerOpen(true);
|
||||||
|
try {
|
||||||
|
const res = await request<Record<string, unknown>>(`/admin/redeem-records/${redeemId}`);
|
||||||
|
setRedeemDetail(res);
|
||||||
|
} catch (e) {
|
||||||
|
message.error(e instanceof Error ? e.message : '加载核销详情失败');
|
||||||
|
setRedeemDrawerOpen(false);
|
||||||
|
} finally {
|
||||||
|
setRedeemDetailLoading(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const load = useCallback(async () => {
|
const load = useCallback(async () => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
try {
|
try {
|
||||||
@@ -159,8 +240,11 @@ export default function OrdersPage() {
|
|||||||
const qs = new URLSearchParams({ page: String(page), pageSize: String(pageSize) });
|
const qs = new URLSearchParams({ page: String(page), pageSize: String(pageSize) });
|
||||||
if (values.orderNo) qs.set('orderNo', values.orderNo);
|
if (values.orderNo) qs.set('orderNo', values.orderNo);
|
||||||
if (values.status) qs.set('status', values.status);
|
if (values.status) qs.set('status', values.status);
|
||||||
|
if (values.orderType) qs.set('orderType', values.orderType);
|
||||||
if (values.cityId) qs.set('cityId', values.cityId);
|
if (values.cityId) qs.set('cityId', values.cityId);
|
||||||
if (values.receiverPhone) qs.set('receiverPhone', values.receiverPhone);
|
if (values.receiverPhone) qs.set('receiverPhone', values.receiverPhone);
|
||||||
|
if (values.fulfillmentHold) qs.set('fulfillmentHold', 'true');
|
||||||
|
if (values.excludeTest) qs.set('excludeTest', 'true');
|
||||||
const res = await request<Paginated<AdminOrderRow>>(`/admin/orders?${qs}`);
|
const res = await request<Paginated<AdminOrderRow>>(`/admin/orders?${qs}`);
|
||||||
setData(res);
|
setData(res);
|
||||||
} finally {
|
} finally {
|
||||||
@@ -330,8 +414,55 @@ export default function OrdersPage() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function askDeleteOrder(id: string, orderNo?: string) {
|
||||||
|
Modal.confirm({
|
||||||
|
title: '确认删除订单?',
|
||||||
|
content: (
|
||||||
|
<div>
|
||||||
|
<p>将永久删除订单{orderNo ? ` ${orderNo}` : ''} 及其配送、权益券、核销、发票等关联数据。</p>
|
||||||
|
<p style={{ color: 'var(--ant-color-error)', marginBottom: 0 }}>此操作不可恢复,请确认不是真实线上订单。</p>
|
||||||
|
</div>
|
||||||
|
),
|
||||||
|
okText: '确认删除',
|
||||||
|
okType: 'danger',
|
||||||
|
cancelText: '取消',
|
||||||
|
onOk: () => deleteOrder(id),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async function deleteOrder(id: string) {
|
||||||
|
setDeletingId(id);
|
||||||
|
try {
|
||||||
|
const res = await request<{ deleted: number; message: string }>(`/admin/orders/${id}`, {
|
||||||
|
method: 'DELETE',
|
||||||
|
});
|
||||||
|
message.success(res.message || '订单已删除');
|
||||||
|
if (detail?.id === id) {
|
||||||
|
setDrawerOpen(false);
|
||||||
|
setDetail(null);
|
||||||
|
}
|
||||||
|
setSelectedRowKeys((prev) => prev.filter((k) => k !== id));
|
||||||
|
void load();
|
||||||
|
} catch (e) {
|
||||||
|
message.error(e instanceof Error ? e.message : '删除失败');
|
||||||
|
throw e;
|
||||||
|
} finally {
|
||||||
|
setDeletingId(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const columns: ColumnsType<AdminOrderRow> = [
|
const columns: ColumnsType<AdminOrderRow> = [
|
||||||
{ title: '订单号', dataIndex: 'orderNo', width: 180 },
|
{
|
||||||
|
title: '订单号',
|
||||||
|
dataIndex: 'orderNo',
|
||||||
|
width: 200,
|
||||||
|
render: (v, row) => (
|
||||||
|
<Space size={4}>
|
||||||
|
<span>{v}</span>
|
||||||
|
{row.isTest ? <Tag color="orange">测试</Tag> : null}
|
||||||
|
</Space>
|
||||||
|
),
|
||||||
|
},
|
||||||
{
|
{
|
||||||
title: '城市',
|
title: '城市',
|
||||||
width: 90,
|
width: 90,
|
||||||
@@ -354,16 +485,25 @@ export default function OrdersPage() {
|
|||||||
{
|
{
|
||||||
title: '状态',
|
title: '状态',
|
||||||
dataIndex: 'status',
|
dataIndex: 'status',
|
||||||
width: 100,
|
width: 140,
|
||||||
render: (s) => (
|
render: (s, row) => (
|
||||||
<Tag color={ORDER_STATUS_COLORS[s] || 'default'}>{ORDER_STATUS_LABELS[s] || s}</Tag>
|
<Space size={4} wrap>
|
||||||
|
<Tag color={ORDER_STATUS_COLORS[s] || 'default'}>{ORDER_STATUS_LABELS[s] || s}</Tag>
|
||||||
|
{row.fulfillmentHold ? <Tag color="orange">大单待确认</Tag> : null}
|
||||||
|
{row.orderType === 'PROXY' || row.isProxyOrder ? (
|
||||||
|
<Tag color="purple" title={row.proxyPartnerName || undefined}>
|
||||||
|
代下单
|
||||||
|
</Tag>
|
||||||
|
) : null}
|
||||||
|
</Space>
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: '配送',
|
title: '配送',
|
||||||
dataIndex: 'deliveryType',
|
dataIndex: 'deliveryType',
|
||||||
width: 90,
|
width: 90,
|
||||||
render: (v) => (v === 'LOCAL' ? '同城' : '跨城'),
|
render: (v) =>
|
||||||
|
v === 'ON_SITE_PICKUP' ? '现场提货' : v === 'LOCAL' ? '同城' : '跨城',
|
||||||
},
|
},
|
||||||
{ title: '实付', dataIndex: 'payAmount', width: 90, render: (v) => `¥${v}` },
|
{ title: '实付', dataIndex: 'payAmount', width: 90, render: (v) => `¥${v}` },
|
||||||
{ title: '收货人', dataIndex: 'receiverName', width: 90 },
|
{ title: '收货人', dataIndex: 'receiverName', width: 90 },
|
||||||
@@ -387,7 +527,7 @@ export default function OrdersPage() {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: '操作',
|
title: '操作',
|
||||||
width: 140,
|
width: 180,
|
||||||
fixed: 'right',
|
fixed: 'right',
|
||||||
render: (_, row) => (
|
render: (_, row) => (
|
||||||
<Space size={0}>
|
<Space size={0}>
|
||||||
@@ -399,6 +539,17 @@ export default function OrdersPage() {
|
|||||||
配送
|
配送
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
|
{canDeleteOrders && (
|
||||||
|
<Button
|
||||||
|
type="link"
|
||||||
|
size="small"
|
||||||
|
danger
|
||||||
|
loading={deletingId === row.id}
|
||||||
|
onClick={() => askDeleteOrder(row.id, row.orderNo)}
|
||||||
|
>
|
||||||
|
删除
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
</Space>
|
</Space>
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
@@ -408,14 +559,39 @@ export default function OrdersPage() {
|
|||||||
<div>
|
<div>
|
||||||
<Space style={{ marginBottom: 16, width: '100%', justifyContent: 'space-between' }}>
|
<Space style={{ marginBottom: 16, width: '100%', justifyContent: 'space-between' }}>
|
||||||
<Typography.Title level={4} style={{ margin: 0 }}>订单监控</Typography.Title>
|
<Typography.Title level={4} style={{ margin: 0 }}>订单监控</Typography.Title>
|
||||||
<Button
|
<Space>
|
||||||
danger
|
<Button onClick={() => window.open('/orders/big-screen', 'dukang-big-screen')}>大屏</Button>
|
||||||
disabled={!selectedRowKeys.length}
|
{canProxyOrder ? (
|
||||||
onClick={() => setBatchDeleteOpen(true)}
|
<Button type="primary" onClick={() => setProxyOpen(true)}>
|
||||||
>
|
代下单
|
||||||
批量删除{selectedRowKeys.length ? ` (${selectedRowKeys.length})` : ''}
|
</Button>
|
||||||
</Button>
|
) : null}
|
||||||
|
{canDeleteOrders ? (
|
||||||
|
<Button
|
||||||
|
danger
|
||||||
|
disabled={!selectedRowKeys.length}
|
||||||
|
onClick={() => setBatchDeleteOpen(true)}
|
||||||
|
>
|
||||||
|
批量删除{selectedRowKeys.length ? ` (${selectedRowKeys.length})` : ''}
|
||||||
|
</Button>
|
||||||
|
) : null}
|
||||||
|
</Space>
|
||||||
</Space>
|
</Space>
|
||||||
|
|
||||||
|
{!canDeleteOrders && profile ? (
|
||||||
|
<Alert
|
||||||
|
type="info"
|
||||||
|
showIcon
|
||||||
|
style={{ marginBottom: 16 }}
|
||||||
|
message="当前账号无「删除订单」权限"
|
||||||
|
description={
|
||||||
|
<span>
|
||||||
|
非超管账号需在 <Link to="/hq-permissions">权限分配</Link> 中勾选危险操作「删除订单」。
|
||||||
|
</span>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
) : null}
|
||||||
|
|
||||||
<Form form={form} layout="inline" style={{ marginBottom: 16 }} onFinish={() => { setPage(1); void load(); }}>
|
<Form form={form} layout="inline" style={{ marginBottom: 16 }} onFinish={() => { setPage(1); void load(); }}>
|
||||||
<Form.Item name="orderNo" label="订单号">
|
<Form.Item name="orderNo" label="订单号">
|
||||||
<Input placeholder="DK..." allowClear />
|
<Input placeholder="DK..." allowClear />
|
||||||
@@ -423,6 +599,17 @@ export default function OrdersPage() {
|
|||||||
<Form.Item name="status" label="状态">
|
<Form.Item name="status" label="状态">
|
||||||
<Select allowClear style={{ width: 120 }} options={Object.entries(ORDER_STATUS_LABELS).map(([value, label]) => ({ value, label }))} />
|
<Select allowClear style={{ width: 120 }} options={Object.entries(ORDER_STATUS_LABELS).map(([value, label]) => ({ value, label }))} />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
|
<Form.Item name="orderType" label="类型">
|
||||||
|
<Select
|
||||||
|
allowClear
|
||||||
|
style={{ width: 120 }}
|
||||||
|
placeholder="全部"
|
||||||
|
options={[
|
||||||
|
{ value: 'NORMAL', label: '普通订单' },
|
||||||
|
{ value: 'PROXY', label: '代下单' },
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
<Form.Item name="cityId" label="城市">
|
<Form.Item name="cityId" label="城市">
|
||||||
<Select
|
<Select
|
||||||
allowClear
|
allowClear
|
||||||
@@ -436,6 +623,17 @@ export default function OrdersPage() {
|
|||||||
<Form.Item name="receiverPhone" label="收货手机">
|
<Form.Item name="receiverPhone" label="收货手机">
|
||||||
<Input allowClear />
|
<Input allowClear />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
|
<Form.Item name="fulfillmentHold" label="大单拦截" valuePropName="checked">
|
||||||
|
<Select
|
||||||
|
allowClear
|
||||||
|
style={{ width: 140 }}
|
||||||
|
placeholder="全部"
|
||||||
|
options={[{ value: true, label: '仅待确认大单' }]}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="excludeTest" valuePropName="checked">
|
||||||
|
<Checkbox>过滤测试账号</Checkbox>
|
||||||
|
</Form.Item>
|
||||||
<Form.Item>
|
<Form.Item>
|
||||||
<Space>
|
<Space>
|
||||||
<Button type="primary" htmlType="submit">查询</Button>
|
<Button type="primary" htmlType="submit">查询</Button>
|
||||||
@@ -450,10 +648,10 @@ export default function OrdersPage() {
|
|||||||
columns={columns}
|
columns={columns}
|
||||||
dataSource={data?.items ?? []}
|
dataSource={data?.items ?? []}
|
||||||
scroll={{ x: 1500 }}
|
scroll={{ x: 1500 }}
|
||||||
rowSelection={{
|
rowSelection={canDeleteOrders ? {
|
||||||
selectedRowKeys,
|
selectedRowKeys,
|
||||||
onChange: (keys) => setSelectedRowKeys(keys as string[]),
|
onChange: (keys) => setSelectedRowKeys(keys as string[]),
|
||||||
}}
|
} : undefined}
|
||||||
pagination={{
|
pagination={{
|
||||||
current: page,
|
current: page,
|
||||||
pageSize,
|
pageSize,
|
||||||
@@ -468,7 +666,7 @@ export default function OrdersPage() {
|
|||||||
|
|
||||||
<Drawer
|
<Drawer
|
||||||
title="订单详情"
|
title="订单详情"
|
||||||
width={640}
|
width={720}
|
||||||
open={drawerOpen}
|
open={drawerOpen}
|
||||||
onClose={() => setDrawerOpen(false)}
|
onClose={() => setDrawerOpen(false)}
|
||||||
extra={detail && (
|
extra={detail && (
|
||||||
@@ -478,6 +676,15 @@ export default function OrdersPage() {
|
|||||||
配送发货
|
配送发货
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
|
{canDeleteOrders && (
|
||||||
|
<Button
|
||||||
|
danger
|
||||||
|
loading={deletingId === detail.id}
|
||||||
|
onClick={() => askDeleteOrder(detail.id, detail.orderNo)}
|
||||||
|
>
|
||||||
|
删除订单
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
<Typography.Text type="secondary">调试改状态</Typography.Text>
|
<Typography.Text type="secondary">调试改状态</Typography.Text>
|
||||||
<Select
|
<Select
|
||||||
value={detail.status}
|
value={detail.status}
|
||||||
@@ -509,10 +716,26 @@ export default function OrdersPage() {
|
|||||||
{detail.fulfillmentWarehouse?.name || '未分配'}
|
{detail.fulfillmentWarehouse?.name || '未分配'}
|
||||||
</Descriptions.Item>
|
</Descriptions.Item>
|
||||||
<Descriptions.Item label="状态">
|
<Descriptions.Item label="状态">
|
||||||
<Tag color={ORDER_STATUS_COLORS[detail.status] || 'default'}>
|
<Space>
|
||||||
{ORDER_STATUS_LABELS[detail.status] || detail.status}
|
<Tag color={ORDER_STATUS_COLORS[detail.status] || 'default'}>
|
||||||
</Tag>
|
{ORDER_STATUS_LABELS[detail.status] || detail.status}
|
||||||
|
</Tag>
|
||||||
|
{detail.fulfillmentHold ? (
|
||||||
|
<Tag color="orange">
|
||||||
|
{FULFILLMENT_HOLD_REASON_LABELS[detail.fulfillmentHoldReason || ''] ||
|
||||||
|
'大单待确认'}
|
||||||
|
</Tag>
|
||||||
|
) : null}
|
||||||
|
{detail.orderType === 'PROXY' || detail.isProxyOrder ? (
|
||||||
|
<Tag color="purple">代下单</Tag>
|
||||||
|
) : null}
|
||||||
|
</Space>
|
||||||
</Descriptions.Item>
|
</Descriptions.Item>
|
||||||
|
{detail.orderType === 'PROXY' || detail.isProxyOrder || detail.proxyPartnerName ? (
|
||||||
|
<Descriptions.Item label="代下单人">
|
||||||
|
{[detail.proxyPartnerName, detail.proxyPartnerPhone].filter(Boolean).join(' / ') || '—'}
|
||||||
|
</Descriptions.Item>
|
||||||
|
) : null}
|
||||||
<Descriptions.Item label="用户">{detail.user?.userNo} / {detail.user?.nickname}</Descriptions.Item>
|
<Descriptions.Item label="用户">{detail.user?.userNo} / {detail.user?.nickname}</Descriptions.Item>
|
||||||
<Descriptions.Item label="商品额">¥{detail.productAmount}</Descriptions.Item>
|
<Descriptions.Item label="商品额">¥{detail.productAmount}</Descriptions.Item>
|
||||||
<Descriptions.Item label="实付">¥{detail.payAmount}</Descriptions.Item>
|
<Descriptions.Item label="实付">¥{detail.payAmount}</Descriptions.Item>
|
||||||
@@ -570,6 +793,98 @@ export default function OrdersPage() {
|
|||||||
<Descriptions.Item label="地址">{detail.receiverAddress}</Descriptions.Item>
|
<Descriptions.Item label="地址">{detail.receiverAddress}</Descriptions.Item>
|
||||||
</Descriptions>
|
</Descriptions>
|
||||||
|
|
||||||
|
<Typography.Title level={5} style={{ marginTop: 16, marginBottom: 8 }}>
|
||||||
|
权益核销
|
||||||
|
</Typography.Title>
|
||||||
|
{detail.redeemSummary ? (
|
||||||
|
<>
|
||||||
|
<Descriptions column={2} bordered size="small" style={{ marginBottom: 12 }}>
|
||||||
|
<Descriptions.Item label="权益券号">{detail.redeemSummary.couponNo}</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="券状态">{detail.redeemSummary.status}</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="权益总额">
|
||||||
|
¥{Number(detail.redeemSummary.totalAmount).toFixed(2)}
|
||||||
|
</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="已核销">
|
||||||
|
<Typography.Text type="danger" strong>
|
||||||
|
¥{Number(detail.redeemSummary.usedAmount).toFixed(2)}
|
||||||
|
</Typography.Text>
|
||||||
|
<Typography.Text type="secondary" style={{ marginLeft: 8 }}>
|
||||||
|
({detail.redeemSummary.redeemCount} 笔核销单)
|
||||||
|
</Typography.Text>
|
||||||
|
</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="剩余余额">
|
||||||
|
¥{Number(detail.redeemSummary.balance).toFixed(2)}
|
||||||
|
</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="核销单合计额">
|
||||||
|
¥{Number(detail.redeemSummary.redeemRecordSum).toFixed(2)}
|
||||||
|
<Typography.Text type="secondary" style={{ marginLeft: 8 }}>
|
||||||
|
(本券分摊合计)
|
||||||
|
</Typography.Text>
|
||||||
|
</Descriptions.Item>
|
||||||
|
</Descriptions>
|
||||||
|
<Table
|
||||||
|
size="small"
|
||||||
|
rowKey="id"
|
||||||
|
pagination={false}
|
||||||
|
locale={{ emptyText: '暂无关联核销单' }}
|
||||||
|
dataSource={detail.redeemRecords ?? []}
|
||||||
|
columns={[
|
||||||
|
{ title: '核销号', dataIndex: 'redeemNo', width: 160, ellipsis: true },
|
||||||
|
{
|
||||||
|
title: '角色',
|
||||||
|
dataIndex: 'role',
|
||||||
|
width: 70,
|
||||||
|
render: (v: string | undefined) =>
|
||||||
|
v === 'SECONDARY' ? <Tag color="orange">次券</Tag> : <Tag color="blue">主券</Tag>,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '门店',
|
||||||
|
dataIndex: ['store', 'name'],
|
||||||
|
ellipsis: true,
|
||||||
|
render: (v: string | undefined, row) =>
|
||||||
|
v ? `${v}${row.store?.cityName ? `(${row.store.cityName})` : ''}` : '—',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '本券分摊',
|
||||||
|
dataIndex: 'couponAmount',
|
||||||
|
width: 95,
|
||||||
|
render: (v: number | undefined, row) =>
|
||||||
|
`¥${Number(v ?? row.amount).toFixed(2)}`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '核销总额',
|
||||||
|
dataIndex: 'amount',
|
||||||
|
width: 90,
|
||||||
|
render: (v: number) => `¥${Number(v).toFixed(2)}`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '结算额',
|
||||||
|
dataIndex: 'settleAmount',
|
||||||
|
width: 90,
|
||||||
|
render: (v: number) => `¥${Number(v).toFixed(2)}`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '时间',
|
||||||
|
dataIndex: 'createdAt',
|
||||||
|
width: 150,
|
||||||
|
render: (v: string) => fmtTime(v),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '操作',
|
||||||
|
width: 70,
|
||||||
|
render: (_, row) => (
|
||||||
|
<Button type="link" size="small" onClick={() => void openRedeemDetail(row.id)}>
|
||||||
|
详情
|
||||||
|
</Button>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<Typography.Text type="secondary">该订单尚未生成权益券,无核销记录</Typography.Text>
|
||||||
|
)}
|
||||||
|
|
||||||
<Descriptions column={1} bordered size="small" title="位置快照(方案C)" style={{ marginTop: 16 }}>
|
<Descriptions column={1} bordered size="small" title="位置快照(方案C)" style={{ marginTop: 16 }}>
|
||||||
<Descriptions.Item label="clientIp">{detail.clientIp || '—'}</Descriptions.Item>
|
<Descriptions.Item label="clientIp">{detail.clientIp || '—'}</Descriptions.Item>
|
||||||
<Descriptions.Item label="IP解析">{[detail.ipProvince, detail.ipCity, detail.ipDistrict].filter(Boolean).join(' / ') || '—'}</Descriptions.Item>
|
<Descriptions.Item label="IP解析">{[detail.ipProvince, detail.ipCity, detail.ipDistrict].filter(Boolean).join(' / ') || '—'}</Descriptions.Item>
|
||||||
@@ -580,7 +895,20 @@ export default function OrdersPage() {
|
|||||||
</Descriptions>
|
</Descriptions>
|
||||||
|
|
||||||
{detail.delivery && (
|
{detail.delivery && (
|
||||||
<Descriptions column={1} bordered size="small" title="配送" style={{ marginTop: 16 }}>
|
<Descriptions
|
||||||
|
column={1}
|
||||||
|
bordered
|
||||||
|
size="small"
|
||||||
|
title={
|
||||||
|
<Space>
|
||||||
|
<span>配送</span>
|
||||||
|
<Button type="link" size="small" style={{ padding: 0 }} onClick={() => setTrackOpen(true)}>
|
||||||
|
查看路由
|
||||||
|
</Button>
|
||||||
|
</Space>
|
||||||
|
}
|
||||||
|
style={{ marginTop: 16 }}
|
||||||
|
>
|
||||||
<Descriptions.Item label="快递公司">
|
<Descriptions.Item label="快递公司">
|
||||||
{detail.delivery.logisticsCompany ||
|
{detail.delivery.logisticsCompany ||
|
||||||
DELIVERY_PROVIDER_LABELS[detail.delivery.provider] ||
|
DELIVERY_PROVIDER_LABELS[detail.delivery.provider] ||
|
||||||
@@ -603,13 +931,40 @@ export default function OrdersPage() {
|
|||||||
<Typography.Title level={5} style={{ marginTop: 16 }}>状态流转</Typography.Title>
|
<Typography.Title level={5} style={{ marginTop: 16 }}>状态流转</Typography.Title>
|
||||||
<Table
|
<Table
|
||||||
size="small"
|
size="small"
|
||||||
rowKey="createdAt"
|
rowKey={(_, i) => String(i)}
|
||||||
pagination={false}
|
pagination={false}
|
||||||
dataSource={detail.statusLogs}
|
dataSource={detail.statusLogs}
|
||||||
columns={[
|
columns={[
|
||||||
{ title: '从', dataIndex: 'fromStatus', render: (v) => v || '—' },
|
{
|
||||||
{ title: '到', dataIndex: 'toStatus', render: (v) => ORDER_STATUS_LABELS[v] || v },
|
title: '从',
|
||||||
{ title: '时间', dataIndex: 'createdAt', render: (v) => new Date(v).toLocaleString('zh-CN') },
|
dataIndex: 'fromStatus',
|
||||||
|
width: 100,
|
||||||
|
render: (v) => (v ? ORDER_STATUS_LABELS[v] || v : '—'),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '到',
|
||||||
|
dataIndex: 'toStatus',
|
||||||
|
width: 100,
|
||||||
|
render: (v) => ORDER_STATUS_LABELS[v] || v,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '操作人',
|
||||||
|
dataIndex: 'operator',
|
||||||
|
width: 120,
|
||||||
|
render: (v) => ORDER_STATUS_OPERATOR_LABELS[v] || v || '—',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '备注',
|
||||||
|
dataIndex: 'remark',
|
||||||
|
ellipsis: true,
|
||||||
|
render: (v) => v || '—',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '时间',
|
||||||
|
dataIndex: 'createdAt',
|
||||||
|
width: 170,
|
||||||
|
render: (v) => new Date(v).toLocaleString('zh-CN'),
|
||||||
|
},
|
||||||
]}
|
]}
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
@@ -618,6 +973,95 @@ export default function OrdersPage() {
|
|||||||
)}
|
)}
|
||||||
</Drawer>
|
</Drawer>
|
||||||
|
|
||||||
|
<Drawer
|
||||||
|
title="核销单详情"
|
||||||
|
width={520}
|
||||||
|
open={redeemDrawerOpen}
|
||||||
|
onClose={() => {
|
||||||
|
setRedeemDrawerOpen(false);
|
||||||
|
setRedeemDetail(null);
|
||||||
|
}}
|
||||||
|
destroyOnClose
|
||||||
|
>
|
||||||
|
{redeemDetailLoading ? (
|
||||||
|
<Typography.Text type="secondary">加载中…</Typography.Text>
|
||||||
|
) : redeemDetail ? (
|
||||||
|
<Descriptions column={1} bordered size="small">
|
||||||
|
<Descriptions.Item label="核销号">{String(redeemDetail.redeemNo ?? '—')}</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="核销额">
|
||||||
|
¥{Number(redeemDetail.amount ?? 0).toFixed(2)}
|
||||||
|
</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="结算额">
|
||||||
|
¥{Number(redeemDetail.settleAmount ?? 0).toFixed(2)}
|
||||||
|
</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="时间">{fmtTime(String(redeemDetail.createdAt ?? ''))}</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="用户">
|
||||||
|
{String((redeemDetail.user as { userNo?: string } | undefined)?.userNo ?? '—')}
|
||||||
|
{(redeemDetail.user as { phone?: string | null } | undefined)?.phone
|
||||||
|
? ` / ${(redeemDetail.user as { phone?: string | null }).phone}`
|
||||||
|
: ''}
|
||||||
|
</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="门店">
|
||||||
|
{String((redeemDetail.store as { name?: string } | undefined)?.name ?? '—')}
|
||||||
|
{(redeemDetail.store as { cityName?: string } | undefined)?.cityName
|
||||||
|
? `(${(redeemDetail.store as { cityName?: string }).cityName})`
|
||||||
|
: ''}
|
||||||
|
</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="门店地址">
|
||||||
|
{String((redeemDetail.store as { address?: string } | undefined)?.address ?? '—')}
|
||||||
|
</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="合伙人">
|
||||||
|
{String(
|
||||||
|
(redeemDetail.store as { partnerAccount?: { companyName?: string } } | undefined)
|
||||||
|
?.partnerAccount?.companyName ?? '—',
|
||||||
|
)}
|
||||||
|
</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="权益券号">
|
||||||
|
{String((redeemDetail.coupon as { couponNo?: string } | undefined)?.couponNo ?? '—')}
|
||||||
|
</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="关联订单">
|
||||||
|
{String(
|
||||||
|
(redeemDetail.coupon as { order?: { orderNo?: string } } | undefined)?.order?.orderNo ??
|
||||||
|
'—',
|
||||||
|
)}
|
||||||
|
</Descriptions.Item>
|
||||||
|
{Array.isArray(redeemDetail.allocations) &&
|
||||||
|
(redeemDetail.allocations as unknown[]).length > 0 ? (
|
||||||
|
<Descriptions.Item label="券分摊">
|
||||||
|
{(
|
||||||
|
redeemDetail.allocations as Array<{
|
||||||
|
couponNo?: string;
|
||||||
|
orderNo?: string | null;
|
||||||
|
amount?: number;
|
||||||
|
sortOrder?: number;
|
||||||
|
}>
|
||||||
|
)
|
||||||
|
.map((a, idx) => {
|
||||||
|
const role = idx === 0 ? '主' : '次';
|
||||||
|
return `${role} ${a.couponNo ?? '—'}¥${Number(a.amount ?? 0).toFixed(2)}${
|
||||||
|
a.orderNo ? `(订单 ${a.orderNo})` : ''
|
||||||
|
}`;
|
||||||
|
})
|
||||||
|
.join(';')}
|
||||||
|
</Descriptions.Item>
|
||||||
|
) : null}
|
||||||
|
{redeemDetail.payout ? (
|
||||||
|
<Descriptions.Item label="门店结算单">
|
||||||
|
¥{Number((redeemDetail.payout as { settleAmount?: number }).settleAmount ?? 0).toFixed(2)}
|
||||||
|
{' / '}
|
||||||
|
{String((redeemDetail.payout as { status?: string }).status ?? '—')}
|
||||||
|
</Descriptions.Item>
|
||||||
|
) : null}
|
||||||
|
{redeemDetail.rating ? (
|
||||||
|
<Descriptions.Item label="评价">
|
||||||
|
服务 {(redeemDetail.rating as { serviceScore?: number }).serviceScore ?? '—'} 分 / 环境{' '}
|
||||||
|
{(redeemDetail.rating as { envScore?: number }).envScore ?? '—'} 分
|
||||||
|
</Descriptions.Item>
|
||||||
|
) : null}
|
||||||
|
</Descriptions>
|
||||||
|
) : null}
|
||||||
|
</Drawer>
|
||||||
|
|
||||||
<Modal
|
<Modal
|
||||||
title={shipTarget ? `配送发货 · ${shipTarget.orderNo}` : '配送发货'}
|
title={shipTarget ? `配送发货 · ${shipTarget.orderNo}` : '配送发货'}
|
||||||
open={shipModalOpen}
|
open={shipModalOpen}
|
||||||
@@ -642,6 +1086,18 @@ export default function OrdersPage() {
|
|||||||
>
|
>
|
||||||
{shipTarget && (
|
{shipTarget && (
|
||||||
<>
|
<>
|
||||||
|
{shipTarget.fulfillmentHold ? (
|
||||||
|
<Alert
|
||||||
|
type="warning"
|
||||||
|
showIcon
|
||||||
|
style={{ marginBottom: 12 }}
|
||||||
|
message="大单已拦截自动推小飞侠"
|
||||||
|
description={
|
||||||
|
FULFILLMENT_HOLD_REASON_LABELS[shipTarget.fulfillmentHoldReason || ''] ||
|
||||||
|
'≥10箱订单需总部确认:可选仓推小飞侠,或改用快递自配送。'
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
) : null}
|
||||||
<Descriptions size="small" column={1} style={{ marginBottom: 16 }}>
|
<Descriptions size="small" column={1} style={{ marginBottom: 16 }}>
|
||||||
<Descriptions.Item label="城市">{shipTarget.city?.name || '—'}</Descriptions.Item>
|
<Descriptions.Item label="城市">{shipTarget.city?.name || '—'}</Descriptions.Item>
|
||||||
<Descriptions.Item label="收货">
|
<Descriptions.Item label="收货">
|
||||||
@@ -815,6 +1271,24 @@ export default function OrdersPage() {
|
|||||||
]}
|
]}
|
||||||
/>
|
/>
|
||||||
</Modal>
|
</Modal>
|
||||||
|
|
||||||
|
<ProxyOrderModal
|
||||||
|
open={proxyOpen}
|
||||||
|
onClose={() => setProxyOpen(false)}
|
||||||
|
onSuccess={(order) => {
|
||||||
|
setProxyOpen(false);
|
||||||
|
void load();
|
||||||
|
void openDetail(order.id);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<OrderTrackDrawer
|
||||||
|
open={trackOpen}
|
||||||
|
orderId={detail?.id ?? null}
|
||||||
|
orderNo={detail?.orderNo}
|
||||||
|
orderStatus={detail?.status}
|
||||||
|
onClose={() => setTrackOpen(false)}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,15 +38,17 @@ type Row = {
|
|||||||
type PartnerOption = { id: string; companyName: string; phone?: string };
|
type PartnerOption = { id: string; companyName: string; phone?: string };
|
||||||
|
|
||||||
const STATUS_LABELS: Record<string, string> = {
|
const STATUS_LABELS: Record<string, string> = {
|
||||||
DRAFT: '待合伙人确认',
|
PENDING_REVIEW: '待审核',
|
||||||
CONFIRMED: '待打款审核',
|
AWAITING_CONFIRM: '待合伙人确认',
|
||||||
|
UNPAID: '未打款',
|
||||||
PAID: '已打款',
|
PAID: '已打款',
|
||||||
REJECTED: '已驳回',
|
REJECTED: '已驳回',
|
||||||
};
|
};
|
||||||
|
|
||||||
const STATUS_COLORS: Record<string, string> = {
|
const STATUS_COLORS: Record<string, string> = {
|
||||||
DRAFT: 'default',
|
PENDING_REVIEW: 'gold',
|
||||||
CONFIRMED: 'orange',
|
AWAITING_CONFIRM: 'blue',
|
||||||
|
UNPAID: 'red',
|
||||||
PAID: 'green',
|
PAID: 'green',
|
||||||
REJECTED: 'red',
|
REJECTED: 'red',
|
||||||
};
|
};
|
||||||
@@ -74,6 +76,7 @@ export default function PartnerBillsPage() {
|
|||||||
const [rejectTarget, setRejectTarget] = useState<Row | null>(null);
|
const [rejectTarget, setRejectTarget] = useState<Row | null>(null);
|
||||||
const [rejectForm] = Form.useForm();
|
const [rejectForm] = Form.useForm();
|
||||||
const [rejecting, setRejecting] = useState(false);
|
const [rejecting, setRejecting] = useState(false);
|
||||||
|
const [selectedKeys, setSelectedKeys] = useState<React.Key[]>([]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
void request<Paginated<PartnerOption>>(`/admin/partners?pageSize=${ADMIN_OPTIONS_PAGE_SIZE}`)
|
void request<Paginated<PartnerOption>>(`/admin/partners?pageSize=${ADMIN_OPTIONS_PAGE_SIZE}`)
|
||||||
@@ -81,10 +84,10 @@ export default function PartnerBillsPage() {
|
|||||||
.catch(() => {});
|
.catch(() => {});
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
async function generateBill(values: { partnerId?: string; month: Dayjs; all?: boolean }) {
|
async function generateBill(values: { partnerId?: string; month: Dayjs }) {
|
||||||
const year = values.month.year();
|
const year = values.month.year();
|
||||||
const month = values.month.month() + 1;
|
const month = values.month.month() + 1;
|
||||||
if (values.all || !values.partnerId) {
|
if (!values.partnerId) {
|
||||||
const result = await request<{ success: number; failed: number; total: number }>(
|
const result = await request<{ success: number; failed: number; total: number }>(
|
||||||
'/admin/partner-bills/generate-all',
|
'/admin/partner-bills/generate-all',
|
||||||
{ method: 'POST', body: JSON.stringify({ year, month }) },
|
{ method: 'POST', body: JSON.stringify({ year, month }) },
|
||||||
@@ -95,31 +98,71 @@ export default function PartnerBillsPage() {
|
|||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: JSON.stringify({ partnerId: values.partnerId, year, month }),
|
body: JSON.stringify({ partnerId: values.partnerId, year, month }),
|
||||||
});
|
});
|
||||||
message.success('账单已生成');
|
message.success('账单已生成(待审核)');
|
||||||
}
|
}
|
||||||
setGenOpen(false);
|
setGenOpen(false);
|
||||||
reload();
|
reload();
|
||||||
}
|
}
|
||||||
|
|
||||||
async function confirmBill(id: string) {
|
function sendBills(ids: string[]) {
|
||||||
await request(`/admin/partner-bills/${id}/confirm`, { method: 'POST' });
|
Modal.confirm({
|
||||||
message.success('已代确认,进入待打款审核');
|
title: '发送给合伙人?',
|
||||||
reload();
|
content: `将发送 ${ids.length} 笔账单到合伙人端,状态变为「待合伙人确认」。`,
|
||||||
|
okText: '确认发送',
|
||||||
|
cancelText: '取消',
|
||||||
|
onOk: async () => {
|
||||||
|
if (ids.length === 1) {
|
||||||
|
await request(`/admin/partner-bills/${ids[0]}/send`, { method: 'POST' });
|
||||||
|
} else {
|
||||||
|
await request('/admin/partner-bills/batch-send', {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify({ ids }),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
message.success('已发送');
|
||||||
|
setSelectedKeys([]);
|
||||||
|
reload();
|
||||||
|
},
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function markPaid(id: string) {
|
function markPaid(ids: string[], amountHint?: number) {
|
||||||
await request(`/admin/partner-bills/${id}/mark-paid`, {
|
Modal.confirm({
|
||||||
method: 'POST',
|
title: '确认打款?',
|
||||||
body: JSON.stringify({ paymentRef: `PAY-${Date.now()}` }),
|
content: `将标记 ${ids.length} 笔账单为已打款${amountHint != null ? `,合计约 ¥${amountHint.toFixed(2)}` : ''}。`,
|
||||||
|
okText: '确认打款',
|
||||||
|
cancelText: '取消',
|
||||||
|
onOk: async () => {
|
||||||
|
if (ids.length === 1) {
|
||||||
|
await request(`/admin/partner-bills/${ids[0]}/mark-paid`, {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify({ paymentRef: `PAY-${Date.now()}` }),
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
await request('/admin/partner-bills/batch-mark-paid', {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify({ ids }),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
message.success('已标记打款');
|
||||||
|
setSelectedKeys([]);
|
||||||
|
reload();
|
||||||
|
},
|
||||||
});
|
});
|
||||||
message.success('已通过并标记打款');
|
|
||||||
reload();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function openReject(row: Row) {
|
function openReject(row: Row) {
|
||||||
setRejectTarget(row);
|
Modal.confirm({
|
||||||
rejectForm.resetFields();
|
title: '驳回该账单?',
|
||||||
setRejectOpen(true);
|
content: '驳回后合伙人需重新等待总部发送。请在下一步填写理由。',
|
||||||
|
okText: '继续填写理由',
|
||||||
|
cancelText: '取消',
|
||||||
|
onOk: () => {
|
||||||
|
setRejectTarget(row);
|
||||||
|
rejectForm.resetFields();
|
||||||
|
setRejectOpen(true);
|
||||||
|
},
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function submitReject(values: { reason: string }) {
|
async function submitReject(values: { reason: string }) {
|
||||||
@@ -130,7 +173,7 @@ export default function PartnerBillsPage() {
|
|||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: JSON.stringify({ reason: values.reason.trim() }),
|
body: JSON.stringify({ reason: values.reason.trim() }),
|
||||||
});
|
});
|
||||||
message.success('已驳回打款申请');
|
message.success('已驳回');
|
||||||
setRejectOpen(false);
|
setRejectOpen(false);
|
||||||
setRejectTarget(null);
|
setRejectTarget(null);
|
||||||
reload();
|
reload();
|
||||||
@@ -158,6 +201,10 @@ export default function PartnerBillsPage() {
|
|||||||
|
|
||||||
const summary = data?.summary;
|
const summary = data?.summary;
|
||||||
const partnerName = (r: Row) => r.partner?.companyName || r.partnerAccount?.companyName || '—';
|
const partnerName = (r: Row) => r.partner?.companyName || r.partnerAccount?.companyName || '—';
|
||||||
|
const selectedRows = (data?.items ?? []).filter((r) => selectedKeys.includes(r.id));
|
||||||
|
const canSend = selectedRows.filter((r) => r.status === 'PENDING_REVIEW' || r.status === 'REJECTED');
|
||||||
|
const canPay = selectedRows.filter((r) => r.status === 'UNPAID');
|
||||||
|
const payAmount = canPay.reduce((s, r) => s + Number(r.totalAmount), 0);
|
||||||
|
|
||||||
const columns: ColumnsType<Row> = [
|
const columns: ColumnsType<Row> = [
|
||||||
{ title: '账单号', dataIndex: 'billNo', width: 180, ellipsis: true },
|
{ title: '账单号', dataIndex: 'billNo', width: 180, ellipsis: true },
|
||||||
@@ -194,7 +241,7 @@ export default function PartnerBillsPage() {
|
|||||||
{
|
{
|
||||||
title: '状态',
|
title: '状态',
|
||||||
dataIndex: 'status',
|
dataIndex: 'status',
|
||||||
width: 120,
|
width: 130,
|
||||||
render: (s, row) => (
|
render: (s, row) => (
|
||||||
<Space direction="vertical" size={0}>
|
<Space direction="vertical" size={0}>
|
||||||
<Tag color={STATUS_COLORS[s] || 'default'}>{STATUS_LABELS[s] || s}</Tag>
|
<Tag color={STATUS_COLORS[s] || 'default'}>{STATUS_LABELS[s] || s}</Tag>
|
||||||
@@ -212,21 +259,26 @@ export default function PartnerBillsPage() {
|
|||||||
fixed: 'right',
|
fixed: 'right',
|
||||||
render: (_, row) => (
|
render: (_, row) => (
|
||||||
<Space size={0} wrap>
|
<Space size={0} wrap>
|
||||||
{row.status === 'DRAFT' && (
|
{(row.status === 'PENDING_REVIEW' || row.status === 'REJECTED') && (
|
||||||
<Button type="link" size="small" onClick={() => void confirmBill(row.id)}>
|
<Button type="link" size="small" onClick={() => sendBills([row.id])}>
|
||||||
代确认
|
发送
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
{row.status === 'CONFIRMED' && (
|
{row.status === 'UNPAID' && (
|
||||||
<>
|
<>
|
||||||
<Button type="link" size="small" onClick={() => void markPaid(row.id)}>
|
<Button type="link" size="small" onClick={() => markPaid([row.id], Number(row.totalAmount))}>
|
||||||
通过打款
|
确认打款
|
||||||
</Button>
|
</Button>
|
||||||
<Button type="link" size="small" danger onClick={() => openReject(row)}>
|
<Button type="link" size="small" danger onClick={() => openReject(row)}>
|
||||||
驳回
|
驳回
|
||||||
</Button>
|
</Button>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
{row.status === 'AWAITING_CONFIRM' && (
|
||||||
|
<Button type="link" size="small" danger onClick={() => openReject(row)}>
|
||||||
|
驳回
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
</Space>
|
</Space>
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
@@ -239,7 +291,7 @@ export default function PartnerBillsPage() {
|
|||||||
合伙人账单
|
合伙人账单
|
||||||
</Typography.Title>
|
</Typography.Title>
|
||||||
<Typography.Text type="secondary">
|
<Typography.Text type="secondary">
|
||||||
T+30 结算:合伙人确认并申请打款后,总部在此审核通过或驳回(驳回须填写理由)
|
每月 1 日 8:00 自动生成上月账单(待审核)→ 发送合伙人确认 → 未打款 → 已打款
|
||||||
</Typography.Text>
|
</Typography.Text>
|
||||||
</Space>
|
</Space>
|
||||||
|
|
||||||
@@ -287,7 +339,7 @@ export default function PartnerBillsPage() {
|
|||||||
<Form.Item name="status" label="状态">
|
<Form.Item name="status" label="状态">
|
||||||
<Select
|
<Select
|
||||||
allowClear
|
allowClear
|
||||||
style={{ width: 140 }}
|
style={{ width: 150 }}
|
||||||
options={Object.entries(STATUS_LABELS).map(([value, label]) => ({ value, label }))}
|
options={Object.entries(STATUS_LABELS).map(([value, label]) => ({ value, label }))}
|
||||||
/>
|
/>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
@@ -317,6 +369,20 @@ export default function PartnerBillsPage() {
|
|||||||
导出 Excel
|
导出 Excel
|
||||||
</Button>
|
</Button>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
|
<Form.Item>
|
||||||
|
<Button disabled={!canSend.length} onClick={() => sendBills(canSend.map((r) => r.id))}>
|
||||||
|
批量发送 ({canSend.length})
|
||||||
|
</Button>
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item>
|
||||||
|
<Button
|
||||||
|
type="primary"
|
||||||
|
disabled={!canPay.length}
|
||||||
|
onClick={() => markPaid(canPay.map((r) => r.id), payAmount)}
|
||||||
|
>
|
||||||
|
批量打款 ({canPay.length})
|
||||||
|
</Button>
|
||||||
|
</Form.Item>
|
||||||
</Form>
|
</Form>
|
||||||
|
|
||||||
<Table
|
<Table
|
||||||
@@ -325,6 +391,10 @@ export default function PartnerBillsPage() {
|
|||||||
loading={loading}
|
loading={loading}
|
||||||
columns={columns}
|
columns={columns}
|
||||||
dataSource={data?.items ?? []}
|
dataSource={data?.items ?? []}
|
||||||
|
rowSelection={{
|
||||||
|
selectedRowKeys: selectedKeys,
|
||||||
|
onChange: setSelectedKeys,
|
||||||
|
}}
|
||||||
scroll={{ x: 1280 }}
|
scroll={{ x: 1280 }}
|
||||||
pagination={{
|
pagination={{
|
||||||
current: page,
|
current: page,
|
||||||
@@ -338,7 +408,7 @@ export default function PartnerBillsPage() {
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Modal title="生成合伙人账单(T+30)" open={genOpen} onCancel={() => setGenOpen(false)} footer={null}>
|
<Modal title="生成合伙人账单" open={genOpen} onCancel={() => setGenOpen(false)} footer={null}>
|
||||||
<Form
|
<Form
|
||||||
form={genForm}
|
form={genForm}
|
||||||
layout="vertical"
|
layout="vertical"
|
||||||
@@ -361,7 +431,7 @@ export default function PartnerBillsPage() {
|
|||||||
/>
|
/>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Button type="primary" htmlType="submit" block>
|
<Button type="primary" htmlType="submit" block>
|
||||||
生成
|
生成(待审核)
|
||||||
</Button>
|
</Button>
|
||||||
</Form>
|
</Form>
|
||||||
</Modal>
|
</Modal>
|
||||||
@@ -378,8 +448,6 @@ export default function PartnerBillsPage() {
|
|||||||
>
|
>
|
||||||
<Typography.Paragraph type="secondary" style={{ marginBottom: 12 }}>
|
<Typography.Paragraph type="secondary" style={{ marginBottom: 12 }}>
|
||||||
账单 {rejectTarget?.billNo} · {rejectTarget ? partnerName(rejectTarget) : ''}
|
账单 {rejectTarget?.billNo} · {rejectTarget ? partnerName(rejectTarget) : ''}
|
||||||
<br />
|
|
||||||
驳回理由将展示在合伙人 H5 账单页。
|
|
||||||
</Typography.Paragraph>
|
</Typography.Paragraph>
|
||||||
<Form form={rejectForm} layout="vertical" onFinish={(v) => void submitReject(v)}>
|
<Form form={rejectForm} layout="vertical" onFinish={(v) => void submitReject(v)}>
|
||||||
<Form.Item
|
<Form.Item
|
||||||
@@ -390,7 +458,7 @@ export default function PartnerBillsPage() {
|
|||||||
{ max: 500, message: '不超过 500 字' },
|
{ max: 500, message: '不超过 500 字' },
|
||||||
]}
|
]}
|
||||||
>
|
>
|
||||||
<Input.TextArea rows={4} placeholder="请说明驳回原因,便于合伙人核对后重新申请" maxLength={500} showCount />
|
<Input.TextArea rows={4} placeholder="请说明驳回原因" maxLength={500} showCount />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Button type="primary" danger htmlType="submit" block loading={rejecting}>
|
<Button type="primary" danger htmlType="submit" block loading={rejecting}>
|
||||||
确认驳回
|
确认驳回
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import { useCallback, useEffect, useState } from 'react';
|
import { useCallback, useEffect, useState } from 'react';
|
||||||
import {
|
import {
|
||||||
Button,
|
Button,
|
||||||
Cascader,
|
|
||||||
Drawer,
|
Drawer,
|
||||||
Form,
|
Form,
|
||||||
Input,
|
Input,
|
||||||
@@ -24,9 +23,10 @@ import {
|
|||||||
type PartnerPermissionKey,
|
type PartnerPermissionKey,
|
||||||
} from '@dukang/shared-types';
|
} from '@dukang/shared-types';
|
||||||
import { request, type Paginated } from '../lib/api';
|
import { request, type Paginated } from '../lib/api';
|
||||||
import { CHINA_REGION_OPTIONS } from '../lib/china-region';
|
import { districtCodeLabel, formatDistrictLabels } from '../lib/china-region';
|
||||||
import { ADMIN_OPTIONS_PAGE_SIZE, fmtTime } from '../lib/constants';
|
import { ADMIN_OPTIONS_PAGE_SIZE, fmtTime } from '../lib/constants';
|
||||||
import { useAdminList } from '../lib/useAdminList';
|
import { useAdminList } from '../lib/useAdminList';
|
||||||
|
import CityDistrictMultiSelect from '../components/CityDistrictMultiSelect';
|
||||||
|
|
||||||
type Row = {
|
type Row = {
|
||||||
id: string;
|
id: string;
|
||||||
@@ -37,6 +37,7 @@ type Row = {
|
|||||||
cityId?: string | null;
|
cityId?: string | null;
|
||||||
cityName?: string | null;
|
cityName?: string | null;
|
||||||
scopeType?: string;
|
scopeType?: string;
|
||||||
|
districtCodes?: string[] | null;
|
||||||
orderCommissionRate?: number;
|
orderCommissionRate?: number;
|
||||||
redeemCommissionRate?: number;
|
redeemCommissionRate?: number;
|
||||||
storeCount: number;
|
storeCount: number;
|
||||||
@@ -102,6 +103,18 @@ export default function PartnersPage() {
|
|||||||
const [editScopeType, setEditScopeType] = useState<CityPartnerScopeType>(CityPartnerScopeType.CITY_WIDE);
|
const [editScopeType, setEditScopeType] = useState<CityPartnerScopeType>(CityPartnerScopeType.CITY_WIDE);
|
||||||
const [createCityId, setCreateCityId] = useState<string | undefined>();
|
const [createCityId, setCreateCityId] = useState<string | undefined>();
|
||||||
|
|
||||||
|
const createCityCode = createCityId ? cities.find((c) => c.id === createCityId)?.code : undefined;
|
||||||
|
const editCityCode = detail?.cityId ? cities.find((c) => c.id === detail.cityId)?.code : undefined;
|
||||||
|
|
||||||
|
function formatApiError(err: unknown): string | null {
|
||||||
|
if (err && typeof err === 'object' && 'errorFields' in err) return null;
|
||||||
|
if (!(err instanceof Error)) return '操作失败';
|
||||||
|
return err.message.replace(/\b(\d{6})\b/g, (code) => {
|
||||||
|
const label = districtCodeLabel(code);
|
||||||
|
return label !== code ? `${label}(${code})` : code;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const loadCities = useCallback(async () => {
|
const loadCities = useCallback(async () => {
|
||||||
const res = await request<Paginated<CityOption>>(`/admin/cities?pageSize=${ADMIN_OPTIONS_PAGE_SIZE}`);
|
const res = await request<Paginated<CityOption>>(`/admin/cities?pageSize=${ADMIN_OPTIONS_PAGE_SIZE}`);
|
||||||
setCities(res.items);
|
setCities(res.items);
|
||||||
@@ -142,22 +155,35 @@ export default function PartnersPage() {
|
|||||||
|
|
||||||
async function savePartner() {
|
async function savePartner() {
|
||||||
if (!detail) return;
|
if (!detail) return;
|
||||||
const v = await editForm.validateFields();
|
try {
|
||||||
const body = {
|
const v = await editForm.validateFields();
|
||||||
...v,
|
const body = {
|
||||||
orderCommissionRate: Number(v.orderCommissionRate ?? 0) / 100,
|
...v,
|
||||||
redeemCommissionRate: Number(v.redeemCommissionRate ?? 3) / 100,
|
orderCommissionRate: Number(v.orderCommissionRate ?? 0) / 100,
|
||||||
districtCodes: editScopeType === CityPartnerScopeType.DISTRICT ? flattenDistrictCodes(v.districtCodes) : undefined,
|
redeemCommissionRate: Number(v.redeemCommissionRate ?? 3) / 100,
|
||||||
};
|
districtCodes: editScopeType === CityPartnerScopeType.DISTRICT ? flattenDistrictCodes(v.districtCodes) : undefined,
|
||||||
await request(`/admin/partners/${detail.id}`, { method: 'PUT', body: JSON.stringify(body) });
|
};
|
||||||
message.success('已保存');
|
await request(`/admin/partners/${detail.id}`, { method: 'PUT', body: JSON.stringify(body) });
|
||||||
setDrawerOpen(false);
|
message.success('已保存');
|
||||||
void reload();
|
setDrawerOpen(false);
|
||||||
|
void reload();
|
||||||
|
} catch (e) {
|
||||||
|
const msg = formatApiError(e);
|
||||||
|
if (msg) message.error(msg);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const columns: ColumnsType<Row> = [
|
const columns: ColumnsType<Row> = [
|
||||||
{ title: '公司名', dataIndex: 'companyName', ellipsis: true },
|
|
||||||
{ title: '城市', dataIndex: 'cityName', width: 100 },
|
{ title: '城市', dataIndex: 'cityName', width: 100 },
|
||||||
|
{
|
||||||
|
title: '区县',
|
||||||
|
dataIndex: 'districtCodes',
|
||||||
|
width: 160,
|
||||||
|
ellipsis: true,
|
||||||
|
render: (codes: string[] | null | undefined, row) =>
|
||||||
|
row.scopeType === CityPartnerScopeType.CITY_WIDE ? '全城' : formatDistrictLabels(codes),
|
||||||
|
},
|
||||||
|
{ title: '公司名', dataIndex: 'companyName', ellipsis: true },
|
||||||
{ title: '主账号', dataIndex: 'phone', width: 130 },
|
{ title: '主账号', dataIndex: 'phone', width: 130 },
|
||||||
{
|
{
|
||||||
title: '管辖',
|
title: '管辖',
|
||||||
@@ -222,17 +248,21 @@ export default function PartnersPage() {
|
|||||||
label: '基本信息',
|
label: '基本信息',
|
||||||
children: (
|
children: (
|
||||||
<Form form={editForm} layout="vertical">
|
<Form form={editForm} layout="vertical">
|
||||||
<Form.Item name="companyName" label="公司名" rules={[{ required: true }]}><Input /></Form.Item>
|
<Form.Item name="companyName" label="公司名"><Input placeholder="选填" /></Form.Item>
|
||||||
<Form.Item name="name" label="主账号姓名" rules={[{ required: true }]}><Input /></Form.Item>
|
<Form.Item name="name" label="主账号姓名" rules={[{ required: true }]}><Input /></Form.Item>
|
||||||
<Form.Item name="phone" label="登录手机号" rules={[{ required: true }]}><Input /></Form.Item>
|
<Form.Item name="phone" label="登录手机号" rules={[{ required: true }]}><Input /></Form.Item>
|
||||||
<Form.Item name="contactPhone" label="业务联系电话"><Input /></Form.Item>
|
<Form.Item name="contactPhone" label="业务联系电话"><Input /></Form.Item>
|
||||||
<Form.Item name="address" label="地址" rules={[{ required: true }]}><Input /></Form.Item>
|
<Form.Item name="address" label="地址"><Input placeholder="选填" /></Form.Item>
|
||||||
<Form.Item name="scopeType" label="管辖类型" rules={[{ required: true }]}>
|
<Form.Item name="scopeType" label="管辖类型" rules={[{ required: true }]}>
|
||||||
<Select options={SCOPE_OPTIONS} onChange={(v) => setEditScopeType(v)} />
|
<Select options={SCOPE_OPTIONS} onChange={(v) => setEditScopeType(v)} />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
{editScopeType === CityPartnerScopeType.DISTRICT && (
|
{editScopeType === CityPartnerScopeType.DISTRICT && (
|
||||||
<Form.Item name="districtCodes" label="区县">
|
<Form.Item
|
||||||
<Cascader options={CHINA_REGION_OPTIONS} multiple changeOnSelect />
|
name="districtCodes"
|
||||||
|
label="区县"
|
||||||
|
extra="仅作标识,可多选当前城市下的区县(不做互斥)"
|
||||||
|
>
|
||||||
|
<CityDistrictMultiSelect cityCode={editCityCode} />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
)}
|
)}
|
||||||
<Space style={{ width: '100%' }} size="large">
|
<Space style={{ width: '100%' }} size="large">
|
||||||
@@ -286,39 +316,52 @@ export default function PartnersPage() {
|
|||||||
width={560}
|
width={560}
|
||||||
onCancel={() => setCreateOpen(false)}
|
onCancel={() => setCreateOpen(false)}
|
||||||
onOk={async () => {
|
onOk={async () => {
|
||||||
const v = await createForm.validateFields();
|
try {
|
||||||
await request('/admin/partners', {
|
const v = await createForm.validateFields();
|
||||||
method: 'POST',
|
await request('/admin/partners', {
|
||||||
body: JSON.stringify({
|
method: 'POST',
|
||||||
...v,
|
body: JSON.stringify({
|
||||||
orderCommissionRate: Number(v.orderCommissionRate ?? 0) / 100,
|
...v,
|
||||||
redeemCommissionRate: Number(v.redeemCommissionRate ?? 3) / 100,
|
orderCommissionRate: Number(v.orderCommissionRate ?? 0) / 100,
|
||||||
districtCodes: createScopeType === CityPartnerScopeType.DISTRICT ? flattenDistrictCodes(v.districtCodes) : undefined,
|
redeemCommissionRate: Number(v.redeemCommissionRate ?? 3) / 100,
|
||||||
}),
|
districtCodes: createScopeType === CityPartnerScopeType.DISTRICT ? flattenDistrictCodes(v.districtCodes) : undefined,
|
||||||
});
|
}),
|
||||||
message.success('已创建');
|
});
|
||||||
setCreateOpen(false);
|
message.success('已创建');
|
||||||
createForm.resetFields();
|
setCreateOpen(false);
|
||||||
void reload();
|
createForm.resetFields();
|
||||||
|
void reload();
|
||||||
|
} catch (e) {
|
||||||
|
const msg = formatApiError(e);
|
||||||
|
if (msg) message.error(msg);
|
||||||
|
}
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Form form={createForm} layout="vertical" initialValues={{ orderCommissionRate: 0, redeemCommissionRate: 3, scopeType: CityPartnerScopeType.CITY_WIDE }}>
|
<Form form={createForm} layout="vertical" initialValues={{ orderCommissionRate: 0, redeemCommissionRate: 3, scopeType: CityPartnerScopeType.CITY_WIDE }}>
|
||||||
<Form.Item name="cityId" label="开城城市" rules={[{ required: true }]}>
|
<Form.Item name="cityId" label="开城城市" rules={[{ required: true }]}>
|
||||||
<Select
|
<Select
|
||||||
options={cities.map((c) => ({ value: c.id, label: `${c.name} (${c.code})` }))}
|
options={cities.map((c) => ({ value: c.id, label: `${c.name} (${c.code})` }))}
|
||||||
onChange={(id) => { setCreateCityId(id); void loadWarehouses(id); }}
|
onChange={(id) => {
|
||||||
|
setCreateCityId(id);
|
||||||
|
createForm.setFieldsValue({ districtCodes: undefined });
|
||||||
|
void loadWarehouses(id);
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item name="companyName" label="公司名" rules={[{ required: true }]}><Input /></Form.Item>
|
<Form.Item name="companyName" label="公司名"><Input placeholder="选填" /></Form.Item>
|
||||||
<Form.Item name="name" label="主账号姓名" rules={[{ required: true }]}><Input /></Form.Item>
|
<Form.Item name="name" label="主账号姓名" rules={[{ required: true }]}><Input /></Form.Item>
|
||||||
<Form.Item name="phone" label="登录手机号" rules={[{ required: true }]}><Input /></Form.Item>
|
<Form.Item name="phone" label="登录手机号" rules={[{ required: true }]}><Input /></Form.Item>
|
||||||
<Form.Item name="address" label="地址" rules={[{ required: true }]}><Input /></Form.Item>
|
<Form.Item name="address" label="地址"><Input placeholder="选填" /></Form.Item>
|
||||||
<Form.Item name="scopeType" label="管辖类型" rules={[{ required: true }]}>
|
<Form.Item name="scopeType" label="管辖类型" rules={[{ required: true }]}>
|
||||||
<Select options={SCOPE_OPTIONS} onChange={(v) => setCreateScopeType(v)} />
|
<Select options={SCOPE_OPTIONS} onChange={(v) => setCreateScopeType(v)} />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
{createScopeType === CityPartnerScopeType.DISTRICT && (
|
{createScopeType === CityPartnerScopeType.DISTRICT && (
|
||||||
<Form.Item name="districtCodes" label="区县" rules={[{ required: true }]}>
|
<Form.Item
|
||||||
<Cascader options={CHINA_REGION_OPTIONS} multiple changeOnSelect />
|
name="districtCodes"
|
||||||
|
label="区县"
|
||||||
|
extra="选填;仅作标识,可多选当前城市下的区县(不做互斥)"
|
||||||
|
>
|
||||||
|
<CityDistrictMultiSelect cityCode={createCityCode} />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
)}
|
)}
|
||||||
<Space style={{ width: '100%' }} size="large">
|
<Space style={{ width: '100%' }} size="large">
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ function mapToForm(d: Record<string, unknown>) {
|
|||||||
const row = d as Row;
|
const row = d as Row;
|
||||||
return {
|
return {
|
||||||
...row,
|
...row,
|
||||||
detailImageUrls: row.detailImageUrls?.length ? row.detailImageUrls : [''],
|
detailImageUrls: row.detailImageUrls?.length ? row.detailImageUrls : [],
|
||||||
features: row.features?.length
|
features: row.features?.length
|
||||||
? row.features
|
? row.features
|
||||||
: [{ icon: 'star', title: '', desc: '' }],
|
: [{ icon: 'star', title: '', desc: '' }],
|
||||||
@@ -68,12 +68,14 @@ function buildPayload(v: TemplateFormValues) {
|
|||||||
function TemplateContentFields() {
|
function TemplateContentFields() {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Typography.Text type="secondary">模板详情长图(套用商品时可逐张修改)</Typography.Text>
|
<Typography.Text type="secondary">模板详情长图(套用商品时可逐张修改,支持批量上传)</Typography.Text>
|
||||||
<DetailImageUrlList
|
<Form.Item name="detailImageUrls" style={{ marginBottom: 0 }}>
|
||||||
label="详情图"
|
<DetailImageUrlList
|
||||||
bizType="DETAIL_TEMPLATE"
|
label="详情图"
|
||||||
maxCount={TEMPLATE_MAX_DETAIL_IMAGES}
|
bizType="DETAIL_TEMPLATE"
|
||||||
/>
|
maxCount={TEMPLATE_MAX_DETAIL_IMAGES}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
<Divider />
|
<Divider />
|
||||||
<Form.Item name="storyTitle" label="故事标题">
|
<Form.Item name="storyTitle" label="故事标题">
|
||||||
<Input placeholder="如:千年杜康 · 唯有此处" />
|
<Input placeholder="如:千年杜康 · 唯有此处" />
|
||||||
@@ -228,7 +230,7 @@ export default function ProductDetailTemplatesPage() {
|
|||||||
}} width={640}>
|
}} width={640}>
|
||||||
<Form form={createForm} layout="vertical" initialValues={{
|
<Form form={createForm} layout="vertical" initialValues={{
|
||||||
status: 'ACTIVE', sortOrder: 0,
|
status: 'ACTIVE', sortOrder: 0,
|
||||||
detailImageUrls: [''],
|
detailImageUrls: [],
|
||||||
features: [{ icon: 'water_drop', title: '', desc: '' }],
|
features: [{ icon: 'water_drop', title: '', desc: '' }],
|
||||||
}}>
|
}}>
|
||||||
<Form.Item name="code" label="编码" rules={[{ required: true }]} extra="唯一标识,如 dukang-classic">
|
<Form.Item name="code" label="编码" rules={[{ required: true }]} extra="唯一标识,如 dukang-classic">
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { useState } from 'react';
|
import { useMemo, useState } from 'react';
|
||||||
import {
|
import {
|
||||||
Button, Descriptions, Divider, Drawer, Form, Input, InputNumber, Modal, Popconfirm, Select, Space,
|
Button, Descriptions, Divider, Drawer, Form, Input, InputNumber, Modal, Popconfirm, Select, Space,
|
||||||
Table, Tabs, Tag, Typography, message,
|
Switch, Table, Tabs, Tag, Typography, message,
|
||||||
} from 'antd';
|
} from 'antd';
|
||||||
import { MinusCircleOutlined, PlusOutlined } from '@ant-design/icons';
|
import { MinusCircleOutlined, PlusOutlined } from '@ant-design/icons';
|
||||||
import type { ColumnsType } from 'antd/es/table';
|
import type { ColumnsType } from 'antd/es/table';
|
||||||
@@ -9,8 +9,10 @@ import { request } from '../lib/api';
|
|||||||
import { AROMA_TYPE_LABELS, PRODUCT_STATUS_LABELS, fmtTime } from '../lib/constants';
|
import { AROMA_TYPE_LABELS, PRODUCT_STATUS_LABELS, fmtTime } from '../lib/constants';
|
||||||
import { useAdminList } from '../lib/useAdminList';
|
import { useAdminList } from '../lib/useAdminList';
|
||||||
import OssUpload from '../components/OssUpload';
|
import OssUpload from '../components/OssUpload';
|
||||||
|
import MultiImageUpload from '../components/MultiImageUpload';
|
||||||
import DetailImageUrlList from '../components/DetailImageUrlList';
|
import DetailImageUrlList from '../components/DetailImageUrlList';
|
||||||
import ProductDetailTemplatePicker from '../components/ProductDetailTemplatePicker';
|
import ProductDetailTemplatePicker from '../components/ProductDetailTemplatePicker';
|
||||||
|
import ProductSpecsEditor from '../components/ProductSpecsEditor';
|
||||||
import type { FormInstance } from 'antd/es/form';
|
import type { FormInstance } from 'antd/es/form';
|
||||||
|
|
||||||
type ProductDetailContentDto = {
|
type ProductDetailContentDto = {
|
||||||
@@ -31,6 +33,11 @@ type Row = {
|
|||||||
benefitAmount: number;
|
benefitAmount: number;
|
||||||
status: string;
|
status: string;
|
||||||
sortOrder: number;
|
sortOrder: number;
|
||||||
|
allowOnSitePickup?: boolean;
|
||||||
|
allowOnlinePurchase?: boolean;
|
||||||
|
allowCrossCityDelivery?: boolean;
|
||||||
|
visibilityWhitelistEnabled?: boolean;
|
||||||
|
visibilityPhones?: string[];
|
||||||
mainImageUrl?: string | null;
|
mainImageUrl?: string | null;
|
||||||
carouselUrls?: string[];
|
carouselUrls?: string[];
|
||||||
detailImageUrls?: string[];
|
detailImageUrls?: string[];
|
||||||
@@ -49,6 +56,11 @@ type ProductFormValues = {
|
|||||||
benefitAmount?: number;
|
benefitAmount?: number;
|
||||||
status?: string;
|
status?: string;
|
||||||
sortOrder?: number;
|
sortOrder?: number;
|
||||||
|
allowOnSitePickup?: boolean;
|
||||||
|
allowOnlinePurchase?: boolean;
|
||||||
|
allowCrossCityDelivery?: boolean;
|
||||||
|
visibilityWhitelistEnabled?: boolean;
|
||||||
|
visibilityPhones?: string[];
|
||||||
coverUrl?: string;
|
coverUrl?: string;
|
||||||
carouselUrls?: string[];
|
carouselUrls?: string[];
|
||||||
detailImageUrls?: string[];
|
detailImageUrls?: string[];
|
||||||
@@ -59,11 +71,17 @@ type ProductFormValues = {
|
|||||||
|
|
||||||
function mapDetailToForm(d: Record<string, unknown>) {
|
function mapDetailToForm(d: Record<string, unknown>) {
|
||||||
const detail = (d.detailContent ?? {}) as ProductDetailContentDto;
|
const detail = (d.detailContent ?? {}) as ProductDetailContentDto;
|
||||||
|
const row = d as Row;
|
||||||
return {
|
return {
|
||||||
...d,
|
...d,
|
||||||
coverUrl: (d as { mainImageUrl?: string }).mainImageUrl,
|
coverUrl: (d as { mainImageUrl?: string }).mainImageUrl,
|
||||||
carouselUrls: ((d as Row).carouselUrls?.length ? (d as Row).carouselUrls : ['']) as string[],
|
carouselUrls: (row.carouselUrls?.length ? row.carouselUrls : []) as string[],
|
||||||
detailImageUrls: ((d as Row).detailImageUrls?.length ? (d as Row).detailImageUrls : ['']) as string[],
|
detailImageUrls: (row.detailImageUrls?.length ? row.detailImageUrls : []) as string[],
|
||||||
|
allowOnlinePurchase: row.allowOnlinePurchase !== false,
|
||||||
|
allowCrossCityDelivery: row.allowOnlinePurchase === false ? false : row.allowCrossCityDelivery !== false,
|
||||||
|
allowOnSitePickup: !!row.allowOnSitePickup,
|
||||||
|
visibilityWhitelistEnabled: !!row.visibilityWhitelistEnabled,
|
||||||
|
visibilityPhones: (row.visibilityPhones ?? []) as string[],
|
||||||
storyTitle: detail.storyTitle ?? '',
|
storyTitle: detail.storyTitle ?? '',
|
||||||
storyText: detail.storyText ?? '',
|
storyText: detail.storyText ?? '',
|
||||||
features: detail.features?.length
|
features: detail.features?.length
|
||||||
@@ -90,7 +108,6 @@ function buildProductPayload(v: ProductFormValues) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
skuCode: v.skuCode,
|
|
||||||
barcode69: v.barcode69,
|
barcode69: v.barcode69,
|
||||||
name: v.name,
|
name: v.name,
|
||||||
subtitle: v.subtitle,
|
subtitle: v.subtitle,
|
||||||
@@ -100,6 +117,11 @@ function buildProductPayload(v: ProductFormValues) {
|
|||||||
benefitAmount: v.benefitAmount,
|
benefitAmount: v.benefitAmount,
|
||||||
status: v.status,
|
status: v.status,
|
||||||
sortOrder: v.sortOrder,
|
sortOrder: v.sortOrder,
|
||||||
|
allowOnSitePickup: !!v.allowOnSitePickup,
|
||||||
|
allowOnlinePurchase: v.allowOnlinePurchase !== false,
|
||||||
|
allowCrossCityDelivery:
|
||||||
|
v.allowOnlinePurchase === false ? false : v.allowCrossCityDelivery !== false,
|
||||||
|
visibilityWhitelistEnabled: !!v.visibilityWhitelistEnabled,
|
||||||
coverUrl: v.coverUrl,
|
coverUrl: v.coverUrl,
|
||||||
carouselUrls,
|
carouselUrls,
|
||||||
detailImageUrls,
|
detailImageUrls,
|
||||||
@@ -109,25 +131,13 @@ function buildProductPayload(v: ProductFormValues) {
|
|||||||
|
|
||||||
function ImageUrlList({ name, label, bizType }: { name: string; label: string; bizType: string }) {
|
function ImageUrlList({ name, label, bizType }: { name: string; label: string; bizType: string }) {
|
||||||
return (
|
return (
|
||||||
<Form.List name={name}>
|
<Form.Item name={name} style={{ marginBottom: 0 }}>
|
||||||
{(fields, { add, remove }) => (
|
<MultiImageUpload
|
||||||
<>
|
bizType={bizType}
|
||||||
{fields.map((field) => (
|
mediaType="IMAGE"
|
||||||
<Space key={field.key} align="start" style={{ display: 'flex', marginBottom: 8 }}>
|
tip={`${label}支持一次选择多张批量上传`}
|
||||||
<Form.Item {...field} style={{ flex: 1, marginBottom: 0 }}>
|
/>
|
||||||
<OssUpload bizType={bizType} mediaType="IMAGE" />
|
</Form.Item>
|
||||||
</Form.Item>
|
|
||||||
{fields.length > 1 && (
|
|
||||||
<MinusCircleOutlined onClick={() => remove(field.name)} style={{ marginTop: 8 }} />
|
|
||||||
)}
|
|
||||||
</Space>
|
|
||||||
))}
|
|
||||||
<Button type="dashed" onClick={() => add('')} block icon={<PlusOutlined />}>
|
|
||||||
添加{label}
|
|
||||||
</Button>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</Form.List>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -136,11 +146,13 @@ function ProductDetailFields({ form, aromaType }: { form: FormInstance; aromaTyp
|
|||||||
<>
|
<>
|
||||||
<ProductDetailTemplatePicker form={form} aromaType={aromaType} />
|
<ProductDetailTemplatePicker form={form} aromaType={aromaType} />
|
||||||
<Divider />
|
<Divider />
|
||||||
<Typography.Text type="secondary">详情页轮播(CAROUSEL)</Typography.Text>
|
<Typography.Text type="secondary">详情页轮播(CAROUSEL,支持批量上传,单张最大 10MB)</Typography.Text>
|
||||||
<ImageUrlList name="carouselUrls" label="轮播图" bizType="CAROUSEL" />
|
<ImageUrlList name="carouselUrls" label="轮播图" bizType="CAROUSEL" />
|
||||||
<Divider />
|
<Divider />
|
||||||
<Typography.Text type="secondary">详情长图(DETAIL,可逐张修改)</Typography.Text>
|
<Typography.Text type="secondary">详情长图(DETAIL,支持批量上传,单张最大 10MB)</Typography.Text>
|
||||||
<DetailImageUrlList label="详情图" bizType="DETAIL" />
|
<Form.Item name="detailImageUrls" style={{ marginBottom: 0 }}>
|
||||||
|
<DetailImageUrlList label="详情图" bizType="DETAIL" />
|
||||||
|
</Form.Item>
|
||||||
<Divider />
|
<Divider />
|
||||||
<Form.Item name="storyTitle" label="故事标题">
|
<Form.Item name="storyTitle" label="故事标题">
|
||||||
<Input placeholder="如:千年杜康 · 唯有此处" />
|
<Input placeholder="如:千年杜康 · 唯有此处" />
|
||||||
@@ -180,16 +192,43 @@ function ProductDetailFields({ form, aromaType }: { form: FormInstance; aromaTyp
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function BaseInfoFields({ mode }: { mode: 'create' | 'edit' }) {
|
function VisibilityWhitelistFields({ form }: { form: FormInstance }) {
|
||||||
|
const enabled = Form.useWatch('visibilityWhitelistEnabled', form);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Form.Item
|
||||||
|
name="visibilityWhitelistEnabled"
|
||||||
|
label="可见白名单"
|
||||||
|
valuePropName="checked"
|
||||||
|
extra="开启后仅全局测试白名单内手机号在 C 端可见/可购,用于在线测试"
|
||||||
|
>
|
||||||
|
<Switch checkedChildren="开" unCheckedChildren="关" />
|
||||||
|
</Form.Item>
|
||||||
|
{enabled ? (
|
||||||
|
<Typography.Text type="secondary" style={{ display: 'block', marginBottom: 16 }}>
|
||||||
|
可见手机号见白名单管理
|
||||||
|
</Typography.Text>
|
||||||
|
) : null}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function BaseInfoFields({ mode, form }: { mode: 'create' | 'edit'; form: FormInstance }) {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{mode === 'create' && (
|
{mode === 'create' && (
|
||||||
<>
|
<>
|
||||||
<Form.Item name="skuCode" label="SKU" rules={[{ required: true }]}>
|
<Form.Item label="SKU">
|
||||||
<Input />
|
<Input disabled placeholder="保存后自动生成" />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item name="barcode69" label="69码" rules={[{ required: true }]}>
|
<Form.Item
|
||||||
<Input />
|
name="barcode69"
|
||||||
|
label="69码"
|
||||||
|
rules={[{ required: true, message: '请填写默认规格 69 码' }]}
|
||||||
|
extra="默认规格的 69 码;若有多种规格,保存后请到「规格与 SKU」为每个规格分别填写不同 69 码"
|
||||||
|
>
|
||||||
|
<Input placeholder="默认规格 69 码" />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item name="aromaType" label="香型" rules={[{ required: true }]}>
|
<Form.Item name="aromaType" label="香型" rules={[{ required: true }]}>
|
||||||
<Select options={Object.entries(AROMA_TYPE_LABELS).map(([value, label]) => ({ value, label }))} />
|
<Select options={Object.entries(AROMA_TYPE_LABELS).map(([value, label]) => ({ value, label }))} />
|
||||||
@@ -217,6 +256,40 @@ function BaseInfoFields({ mode }: { mode: 'create' | 'edit' }) {
|
|||||||
<Form.Item name="sortOrder" label="排序">
|
<Form.Item name="sortOrder" label="排序">
|
||||||
<InputNumber min={0} style={{ width: '100%' }} />
|
<InputNumber min={0} style={{ width: '100%' }} />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
|
<Form.Item
|
||||||
|
name="allowOnlinePurchase"
|
||||||
|
label="允许线上购买"
|
||||||
|
valuePropName="checked"
|
||||||
|
extra="配送到址(同城)"
|
||||||
|
>
|
||||||
|
<Switch
|
||||||
|
checkedChildren="开"
|
||||||
|
unCheckedChildren="关"
|
||||||
|
onChange={(checked) => {
|
||||||
|
if (!checked) form.setFieldsValue({ allowCrossCityDelivery: false });
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item noStyle shouldUpdate={(prev, cur) => prev.allowOnlinePurchase !== cur.allowOnlinePurchase}>
|
||||||
|
{() => (
|
||||||
|
<Form.Item
|
||||||
|
name="allowCrossCityDelivery"
|
||||||
|
label="允许跨城配送"
|
||||||
|
valuePropName="checked"
|
||||||
|
extra="须先开启线上购买"
|
||||||
|
>
|
||||||
|
<Switch
|
||||||
|
checkedChildren="开"
|
||||||
|
unCheckedChildren="关"
|
||||||
|
disabled={!form.getFieldValue('allowOnlinePurchase')}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
)}
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="allowOnSitePickup" label="允许现场取货" valuePropName="checked">
|
||||||
|
<Switch checkedChildren="开" unCheckedChildren="关" />
|
||||||
|
</Form.Item>
|
||||||
|
<VisibilityWhitelistFields form={form} />
|
||||||
<Form.Item name="coverUrl" label="封面">
|
<Form.Item name="coverUrl" label="封面">
|
||||||
<OssUpload bizType="COVER" mediaType="IMAGE" />
|
<OssUpload bizType="COVER" mediaType="IMAGE" />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
@@ -258,14 +331,38 @@ export default function ProductsPage() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const columns: ColumnsType<Row> = [
|
const columns: ColumnsType<Row> = useMemo(() => [
|
||||||
{ title: 'SKU', dataIndex: 'skuCode', width: 90 },
|
{ title: 'SKU', dataIndex: 'skuCode', width: 90 },
|
||||||
{ title: '商品名', dataIndex: 'name', width: 180, ellipsis: true },
|
{ title: '商品名', dataIndex: 'name', width: 180, ellipsis: true },
|
||||||
{ title: '香型', dataIndex: 'aromaType', width: 80, render: (v) => AROMA_TYPE_LABELS[v] || v },
|
{ title: '香型', dataIndex: 'aromaType', width: 80, render: (v) => AROMA_TYPE_LABELS[v] || v },
|
||||||
{ title: '规格', dataIndex: 'spec', width: 120, ellipsis: true },
|
{ title: '规格', dataIndex: 'spec', width: 120, ellipsis: true },
|
||||||
{ title: '售价', dataIndex: 'price', width: 80, render: (v) => `¥${v}` },
|
{ title: '售价', dataIndex: 'price', width: 80, render: (v) => `¥${v}` },
|
||||||
{ title: '权益额', dataIndex: 'benefitAmount', width: 80, render: (v) => `¥${v}` },
|
{ title: '权益额', dataIndex: 'benefitAmount', width: 80, render: (v) => `¥${v}` },
|
||||||
{ title: '状态', dataIndex: 'status', width: 80, render: (s) => <Tag>{PRODUCT_STATUS_LABELS[s] || s}</Tag> },
|
{ title: '状态', dataIndex: 'status', width: 80, render: (s) => (
|
||||||
|
<Tag color={s === 'ON_SALE' ? 'green' : undefined}>{PRODUCT_STATUS_LABELS[s] || s}</Tag>
|
||||||
|
) },
|
||||||
|
{
|
||||||
|
title: '白名单',
|
||||||
|
dataIndex: 'visibilityWhitelistEnabled',
|
||||||
|
width: 90,
|
||||||
|
render: (v: boolean) =>
|
||||||
|
v ? <Tag color="orange">限测</Tag> : <Tag>公开</Tag>,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '履约',
|
||||||
|
key: 'fulfillment',
|
||||||
|
width: 160,
|
||||||
|
render: (_, row) => (
|
||||||
|
<Space size={[0, 4]} wrap>
|
||||||
|
{row.allowOnlinePurchase !== false ? <Tag color="blue">线上</Tag> : null}
|
||||||
|
{row.allowOnlinePurchase !== false && row.allowCrossCityDelivery !== false ? (
|
||||||
|
<Tag color="cyan">跨城</Tag>
|
||||||
|
) : null}
|
||||||
|
{row.allowOnSitePickup ? <Tag color="green">现场</Tag> : null}
|
||||||
|
{row.allowOnlinePurchase === false && !row.allowOnSitePickup ? <Tag>无</Tag> : null}
|
||||||
|
</Space>
|
||||||
|
),
|
||||||
|
},
|
||||||
{ title: '排序', dataIndex: 'sortOrder', width: 60 },
|
{ title: '排序', dataIndex: 'sortOrder', width: 60 },
|
||||||
{ title: '创建', dataIndex: 'createdAt', width: 160, render: fmtTime },
|
{ title: '创建', dataIndex: 'createdAt', width: 160, render: fmtTime },
|
||||||
{
|
{
|
||||||
@@ -291,7 +388,7 @@ export default function ProductsPage() {
|
|||||||
</Space>
|
</Space>
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
];
|
], [detail, editForm]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
@@ -309,12 +406,16 @@ export default function ProductsPage() {
|
|||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item><Button type="primary" htmlType="submit">查询</Button></Form.Item>
|
<Form.Item><Button type="primary" htmlType="submit">查询</Button></Form.Item>
|
||||||
</Form>
|
</Form>
|
||||||
<Table rowKey="id" className="admin-table-nowrap" loading={loading} columns={columns} dataSource={data?.items ?? []} scroll={{ x: 1140 }}
|
<Table rowKey="id" className="admin-table-nowrap" loading={loading} columns={columns} dataSource={data?.items ?? []} scroll={{ x: 1320 }}
|
||||||
pagination={{ current: page, pageSize, total: data?.total ?? 0, showSizeChanger: true, onChange: (p, ps) => { setPage(p); setPageSize(ps); } }} />
|
pagination={{ current: page, pageSize, total: data?.total ?? 0, showSizeChanger: true, onChange: (p, ps) => { setPage(p); setPageSize(ps); } }} />
|
||||||
<Drawer title="编辑商品" width={720} open={drawerOpen} onClose={() => setDrawerOpen(false)}
|
<Drawer title="编辑商品" width={1100} open={drawerOpen} onClose={() => setDrawerOpen(false)}
|
||||||
extra={detail && (
|
extra={detail && (
|
||||||
<Button type="primary" onClick={async () => {
|
<Button type="primary" onClick={async () => {
|
||||||
const v = await editForm.validateFields();
|
const v = await editForm.validateFields();
|
||||||
|
if (!v.allowOnlinePurchase && !v.allowOnSitePickup) {
|
||||||
|
message.error('请至少勾选「允许线上购买」或「允许现场取货」之一');
|
||||||
|
return;
|
||||||
|
}
|
||||||
const payload = buildProductPayload(v);
|
const payload = buildProductPayload(v);
|
||||||
await request(`/admin/products/${detail.id}`, { method: 'PUT', body: JSON.stringify(payload) });
|
await request(`/admin/products/${detail.id}`, { method: 'PUT', body: JSON.stringify(payload) });
|
||||||
message.success('已保存');
|
message.success('已保存');
|
||||||
@@ -325,13 +426,13 @@ export default function ProductsPage() {
|
|||||||
{detail && (
|
{detail && (
|
||||||
<>
|
<>
|
||||||
<Descriptions column={1} bordered size="small" style={{ marginBottom: 16 }}>
|
<Descriptions column={1} bordered size="small" style={{ marginBottom: 16 }}>
|
||||||
<Descriptions.Item label="SKU">{String(detail.skuCode)}</Descriptions.Item>
|
<Descriptions.Item label="SKU">{String(detail.skuCode)}(系统生成)</Descriptions.Item>
|
||||||
<Descriptions.Item label="69码">{String(detail.barcode69)}</Descriptions.Item>
|
<Descriptions.Item label="默认 69 码">{String(detail.barcode69)}</Descriptions.Item>
|
||||||
<Descriptions.Item label="香型">{AROMA_TYPE_LABELS[String(detail.aromaType)] || String(detail.aromaType)}</Descriptions.Item>
|
<Descriptions.Item label="香型">{AROMA_TYPE_LABELS[String(detail.aromaType)] || String(detail.aromaType)}</Descriptions.Item>
|
||||||
</Descriptions>
|
</Descriptions>
|
||||||
<Form form={editForm} layout="vertical">
|
<Form form={editForm} layout="vertical">
|
||||||
<Tabs items={[
|
<Tabs items={[
|
||||||
{ key: 'base', label: '基础信息', children: <BaseInfoFields mode="edit" /> },
|
{ key: 'base', label: '基础信息', children: <BaseInfoFields mode="edit" form={editForm} /> },
|
||||||
{
|
{
|
||||||
key: 'detail',
|
key: 'detail',
|
||||||
label: '详情页',
|
label: '详情页',
|
||||||
@@ -342,6 +443,23 @@ export default function ProductsPage() {
|
|||||||
/>
|
/>
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
key: 'specs',
|
||||||
|
label: '规格与 SKU',
|
||||||
|
children: (
|
||||||
|
<ProductSpecsEditor
|
||||||
|
productId={String(detail.id)}
|
||||||
|
initialAttrs={(detail.specAttrs as never) ?? []}
|
||||||
|
initialSkus={(detail.skus as never) ?? []}
|
||||||
|
onSaved={async () => {
|
||||||
|
const d = await request<Record<string, unknown>>(`/admin/products/${detail.id}`);
|
||||||
|
setDetail(d);
|
||||||
|
editForm.setFieldsValue(mapDetailToForm(d));
|
||||||
|
void reload();
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
),
|
||||||
|
},
|
||||||
]} />
|
]} />
|
||||||
</Form>
|
</Form>
|
||||||
</>
|
</>
|
||||||
@@ -349,6 +467,10 @@ export default function ProductsPage() {
|
|||||||
</Drawer>
|
</Drawer>
|
||||||
<Modal title="新建商品" open={createOpen} onCancel={() => setCreateOpen(false)} onOk={async () => {
|
<Modal title="新建商品" open={createOpen} onCancel={() => setCreateOpen(false)} onOk={async () => {
|
||||||
const v = await createForm.validateFields();
|
const v = await createForm.validateFields();
|
||||||
|
if (!v.allowOnlinePurchase && !v.allowOnSitePickup) {
|
||||||
|
message.error('请至少勾选「允许线上购买」或「允许现场取货」之一');
|
||||||
|
return;
|
||||||
|
}
|
||||||
const payload = buildProductPayload(v);
|
const payload = buildProductPayload(v);
|
||||||
await request('/admin/products', { method: 'POST', body: JSON.stringify(payload) });
|
await request('/admin/products', { method: 'POST', body: JSON.stringify(payload) });
|
||||||
message.success('已创建');
|
message.success('已创建');
|
||||||
@@ -358,11 +480,13 @@ export default function ProductsPage() {
|
|||||||
}} width={720}>
|
}} width={720}>
|
||||||
<Form form={createForm} layout="vertical" initialValues={{
|
<Form form={createForm} layout="vertical" initialValues={{
|
||||||
aromaType: 'QINGXIANG', status: 'DRAFT', sortOrder: 0,
|
aromaType: 'QINGXIANG', status: 'DRAFT', sortOrder: 0,
|
||||||
carouselUrls: [''], detailImageUrls: [''],
|
allowOnlinePurchase: true, allowCrossCityDelivery: true, allowOnSitePickup: false,
|
||||||
|
visibilityWhitelistEnabled: false, visibilityPhones: [],
|
||||||
|
carouselUrls: [], detailImageUrls: [],
|
||||||
features: [{ icon: 'water_drop', title: '', desc: '' }],
|
features: [{ icon: 'water_drop', title: '', desc: '' }],
|
||||||
}}>
|
}}>
|
||||||
<Tabs items={[
|
<Tabs items={[
|
||||||
{ key: 'base', label: '基础信息', children: <BaseInfoFields mode="create" /> },
|
{ key: 'base', label: '基础信息', children: <BaseInfoFields mode="create" form={createForm} /> },
|
||||||
{
|
{
|
||||||
key: 'detail',
|
key: 'detail',
|
||||||
label: '详情页',
|
label: '详情页',
|
||||||
|
|||||||
@@ -1,236 +1,244 @@
|
|||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
|
import { useNavigate } from 'react-router-dom';
|
||||||
import { useNavigate } from 'react-router-dom';
|
import {
|
||||||
|
Button, Form, Input, Modal, Select, Space, Table, Tag, Typography, message,
|
||||||
import {
|
} from 'antd';
|
||||||
|
import type { ColumnsType } from 'antd/es/table';
|
||||||
Button, Form, Input, Modal, Select, Space, Table, Tag, Typography, message,
|
import {
|
||||||
|
PROMO_CODE_SCENE_LABELS,
|
||||||
} from 'antd';
|
PROMO_CODE_STATUS_LABELS,
|
||||||
|
promoConversion,
|
||||||
import type { ColumnsType } from 'antd/es/table';
|
type PromoCodeItem,
|
||||||
|
type PromoCodeScene,
|
||||||
import {
|
} from '@dukang/shared-types';
|
||||||
|
import { request } from '../lib/api';
|
||||||
PROMO_CODE_SCENE_LABELS,
|
import { fmtTime } from '../lib/constants';
|
||||||
|
import { useAdminList } from '../lib/useAdminList';
|
||||||
PROMO_CODE_STATUS_LABELS,
|
|
||||||
|
type Row = PromoCodeItem;
|
||||||
promoConversion,
|
|
||||||
|
type SceneOption = { value: PromoCodeScene; label: string };
|
||||||
type PromoCodeItem,
|
|
||||||
|
async function downloadQrcode(url: string, filename: string) {
|
||||||
type PromoCodeScene,
|
try {
|
||||||
|
const res = await fetch(url);
|
||||||
} from '@dukang/shared-types';
|
const blob = await res.blob();
|
||||||
|
const objectUrl = URL.createObjectURL(blob);
|
||||||
import { request } from '../lib/api';
|
const a = document.createElement('a');
|
||||||
|
a.href = objectUrl;
|
||||||
import { fmtTime } from '../lib/constants';
|
a.download = filename;
|
||||||
|
a.click();
|
||||||
import { useAdminList } from '../lib/useAdminList';
|
URL.revokeObjectURL(objectUrl);
|
||||||
|
} catch {
|
||||||
|
window.open(url, '_blank');
|
||||||
|
}
|
||||||
type Row = PromoCodeItem;
|
}
|
||||||
|
|
||||||
|
export default function PromoCodesPage() {
|
||||||
|
const navigate = useNavigate();
|
||||||
type SceneOption = { value: PromoCodeScene; label: string };
|
const [filterForm] = Form.useForm();
|
||||||
|
const [createForm] = Form.useForm();
|
||||||
|
const [filters, setFilters] = useState<Record<string, string>>({});
|
||||||
|
const [scenes, setScenes] = useState<SceneOption[]>(
|
||||||
async function downloadQrcode(url: string, filename: string) {
|
Object.entries(PROMO_CODE_SCENE_LABELS).map(([value, label]) => ({
|
||||||
|
value: value as PromoCodeScene,
|
||||||
try {
|
label,
|
||||||
|
})),
|
||||||
const res = await fetch(url);
|
);
|
||||||
|
const [createOpen, setCreateOpen] = useState(false);
|
||||||
const blob = await res.blob();
|
const [creating, setCreating] = useState(false);
|
||||||
|
|
||||||
const objectUrl = URL.createObjectURL(blob);
|
const { data, loading, page, pageSize, setPage, setPageSize, reload } = useAdminList<Row>(
|
||||||
|
'/admin/promo-codes',
|
||||||
const a = document.createElement('a');
|
() => {
|
||||||
|
const qs = new URLSearchParams();
|
||||||
a.href = objectUrl;
|
if (filters.name) qs.set('name', filters.name);
|
||||||
|
if (filters.code) qs.set('code', filters.code);
|
||||||
a.download = filename;
|
if (filters.status) qs.set('status', filters.status);
|
||||||
|
if (filters.scene) qs.set('scene', filters.scene);
|
||||||
a.click();
|
return qs;
|
||||||
|
},
|
||||||
URL.revokeObjectURL(objectUrl);
|
[filters],
|
||||||
|
);
|
||||||
} catch {
|
|
||||||
|
async function loadScenes() {
|
||||||
window.open(url, '_blank');
|
try {
|
||||||
|
const list = await request<SceneOption[]>('/admin/promo-codes/scenes');
|
||||||
}
|
if (list.length) setScenes(list);
|
||||||
|
} catch {
|
||||||
}
|
/* 使用本地默认场景 */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export default function PromoCodesPage() {
|
useEffect(() => {
|
||||||
|
void loadScenes();
|
||||||
const navigate = useNavigate();
|
}, []);
|
||||||
|
|
||||||
const [filterForm] = Form.useForm();
|
const columns: ColumnsType<Row> = [
|
||||||
|
{ title: '名称', dataIndex: 'name', width: 160, ellipsis: true },
|
||||||
const [createForm] = Form.useForm();
|
{ title: '码值', dataIndex: 'code', width: 110 },
|
||||||
|
{
|
||||||
const [filters, setFilters] = useState<Record<string, string>>({});
|
title: '场景',
|
||||||
|
dataIndex: 'scene',
|
||||||
const [scenes, setScenes] = useState<SceneOption[]>(
|
width: 110,
|
||||||
|
render: (s: PromoCodeScene) => PROMO_CODE_SCENE_LABELS[s] || s,
|
||||||
Object.entries(PROMO_CODE_SCENE_LABELS).map(([value, label]) => ({
|
},
|
||||||
|
{
|
||||||
value: value as PromoCodeScene,
|
title: '状态',
|
||||||
|
dataIndex: 'status',
|
||||||
label,
|
width: 90,
|
||||||
|
render: (s) => (
|
||||||
})),
|
<Tag color={s === 'ACTIVE' ? 'green' : 'default'}>
|
||||||
|
{PROMO_CODE_STATUS_LABELS[s as keyof typeof PROMO_CODE_STATUS_LABELS] || s}
|
||||||
);
|
</Tag>
|
||||||
|
),
|
||||||
const [createOpen, setCreateOpen] = useState(false);
|
},
|
||||||
|
{ title: '扫码', dataIndex: 'scanCount', width: 70 },
|
||||||
const [creating, setCreating] = useState(false);
|
{ title: '订单', dataIndex: 'orderCount', width: 70 },
|
||||||
|
{
|
||||||
|
title: '转化率',
|
||||||
|
width: 90,
|
||||||
const { data, loading, page, pageSize, setPage, setPageSize, reload } = useAdminList<Row>(
|
render: (_, row) => promoConversion(row.scanCount, row.orderCount),
|
||||||
|
},
|
||||||
'/admin/promo-codes',
|
{
|
||||||
|
title: '渠道负责人',
|
||||||
() => {
|
width: 120,
|
||||||
|
render: (_, row) => row.ownerUser?.userNo || row.ownerUser?.phone || '—',
|
||||||
const qs = new URLSearchParams();
|
},
|
||||||
|
{ title: '创建', dataIndex: 'createdAt', width: 160, render: fmtTime },
|
||||||
if (filters.name) qs.set('name', filters.name);
|
{
|
||||||
|
title: '操作',
|
||||||
if (filters.code) qs.set('code', filters.code);
|
width: 220,
|
||||||
|
fixed: 'right',
|
||||||
if (filters.status) qs.set('status', filters.status);
|
render: (_, row) => (
|
||||||
|
<Space size="small" wrap>
|
||||||
if (filters.scene) qs.set('scene', filters.scene);
|
<Button type="link" size="small" onClick={() => navigate(`/promo-codes/${row.id}`)}>
|
||||||
|
详情
|
||||||
return qs;
|
</Button>
|
||||||
|
<Button
|
||||||
},
|
type="link"
|
||||||
|
size="small"
|
||||||
[filters],
|
disabled={!row.qrcodeUrl}
|
||||||
|
onClick={() => {
|
||||||
);
|
if (!row.qrcodeUrl) return;
|
||||||
|
void downloadQrcode(row.qrcodeUrl, `${row.code}-wxacode.png`);
|
||||||
|
}}
|
||||||
|
>
|
||||||
async function loadScenes() {
|
下载小程序码
|
||||||
|
</Button>
|
||||||
try {
|
<Button type="link" size="small" onClick={() => navigate(`/promo-codes/${row.id}/users`)}>
|
||||||
|
关联用户
|
||||||
const list = await request<SceneOption[]>('/admin/promo-codes/scenes');
|
</Button>
|
||||||
|
</Space>
|
||||||
if (list.length) setScenes(list);
|
),
|
||||||
|
},
|
||||||
} catch {
|
];
|
||||||
|
|
||||||
/* 使用本地默认场景 */
|
async function handleCreate(values: Record<string, string>) {
|
||||||
|
setCreating(true);
|
||||||
}
|
try {
|
||||||
|
const created = await request<PromoCodeItem>('/admin/promo-codes', {
|
||||||
}
|
method: 'POST',
|
||||||
|
body: JSON.stringify({
|
||||||
|
name: values.name,
|
||||||
|
code: values.code?.trim() || undefined,
|
||||||
useEffect(() => {
|
scene: values.scene,
|
||||||
|
ownerUserId: values.ownerUserId?.trim() || undefined,
|
||||||
void loadScenes();
|
remark: values.remark?.trim() || undefined,
|
||||||
|
page: values.page?.trim() || undefined,
|
||||||
}, []);
|
}),
|
||||||
|
});
|
||||||
|
message.success('推广码已创建');
|
||||||
|
setCreateOpen(false);
|
||||||
const columns: ColumnsType<Row> = [
|
createForm.resetFields();
|
||||||
|
void reload();
|
||||||
{ title: '名称', dataIndex: 'name', width: 160, ellipsis: true },
|
navigate(`/promo-codes/${created.id}`);
|
||||||
|
} catch (e) {
|
||||||
{ title: '码值', dataIndex: 'code', width: 110 },
|
message.error(e instanceof Error ? e.message : '创建失败');
|
||||||
|
} finally {
|
||||||
{
|
setCreating(false);
|
||||||
|
}
|
||||||
title: '场景',
|
}
|
||||||
|
|
||||||
dataIndex: 'scene',
|
return (
|
||||||
|
<div>
|
||||||
width: 110,
|
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 16 }}>
|
||||||
|
<Typography.Title level={4} style={{ margin: 0 }}>推广码管理</Typography.Title>
|
||||||
render: (s: PromoCodeScene) => PROMO_CODE_SCENE_LABELS[s] || s,
|
<Button type="primary" onClick={() => setCreateOpen(true)}>创建推广码</Button>
|
||||||
|
</div>
|
||||||
},
|
|
||||||
|
<Form
|
||||||
{
|
form={filterForm}
|
||||||
|
layout="inline"
|
||||||
title: '状态',
|
style={{ marginBottom: 16 }}
|
||||||
|
onFinish={(v) => { setFilters(v); setPage(1); }}
|
||||||
dataIndex: 'status',
|
>
|
||||||
|
<Form.Item name="name" label="名称"><Input allowClear /></Form.Item>
|
||||||
width: 90,
|
<Form.Item name="code" label="码值"><Input allowClear /></Form.Item>
|
||||||
|
<Form.Item name="scene" label="场景">
|
||||||
render: (s) => (
|
<Select allowClear style={{ width: 130 }} options={scenes} />
|
||||||
|
</Form.Item>
|
||||||
<Tag color={s === 'ACTIVE' ? 'green' : 'default'}>
|
<Form.Item name="status" label="状态">
|
||||||
|
<Select
|
||||||
{PROMO_CODE_STATUS_LABELS[s as keyof typeof PROMO_CODE_STATUS_LABELS] || s}
|
allowClear
|
||||||
|
style={{ width: 100 }}
|
||||||
</Tag>
|
options={Object.entries(PROMO_CODE_STATUS_LABELS).map(([value, label]) => ({ value, label }))}
|
||||||
|
/>
|
||||||
),
|
</Form.Item>
|
||||||
|
<Form.Item><Button type="primary" htmlType="submit">查询</Button></Form.Item>
|
||||||
},
|
</Form>
|
||||||
|
|
||||||
{ title: '扫码', dataIndex: 'scanCount', width: 70 },
|
<Table
|
||||||
|
rowKey="id"
|
||||||
{ title: '订单', dataIndex: 'orderCount', width: 70 },
|
className="admin-table-nowrap"
|
||||||
|
loading={loading}
|
||||||
{
|
columns={columns}
|
||||||
|
dataSource={data?.items ?? []}
|
||||||
title: '转化率',
|
scroll={{ x: 1200 }}
|
||||||
|
pagination={{
|
||||||
width: 90,
|
current: page,
|
||||||
|
pageSize,
|
||||||
render: (_, row) => promoConversion(row.scanCount, row.orderCount),
|
total: data?.total ?? 0,
|
||||||
|
showSizeChanger: true,
|
||||||
},
|
onChange: (p, ps) => { setPage(p); setPageSize(ps); },
|
||||||
|
}}
|
||||||
{
|
/>
|
||||||
|
|
||||||
title: '渠道负责人',
|
<Modal
|
||||||
|
title="创建推广码"
|
||||||
width: 120,
|
open={createOpen}
|
||||||
|
onCancel={() => setCreateOpen(false)}
|
||||||
render: (_, row) => row.ownerUser?.userNo || row.ownerUser?.phone || '—',
|
footer={null}
|
||||||
|
destroyOnClose
|
||||||
},
|
>
|
||||||
|
<Form form={createForm} layout="vertical" onFinish={handleCreate} initialValues={{ scene: 'ONLINE_LINK' }}>
|
||||||
{ title: '创建', dataIndex: 'createdAt', width: 160, render: fmtTime },
|
<Form.Item name="name" label="推广码名称" rules={[{ required: true, message: '请填写名称' }]}>
|
||||||
|
<Input placeholder="如:郑州品鉴会、门店地推" />
|
||||||
{
|
</Form.Item>
|
||||||
|
<Form.Item name="scene" label="场景" rules={[{ required: true }]}>
|
||||||
title: '操作',
|
<Select options={scenes} />
|
||||||
|
</Form.Item>
|
||||||
width: 220,
|
<Form.Item name="code" label="自定义码值(选填)">
|
||||||
|
<Input placeholder="留空自动生成,如 DKDEMO1" />
|
||||||
fixed: 'right',
|
</Form.Item>
|
||||||
|
<Form.Item
|
||||||
render: (_, row) => (
|
name="page"
|
||||||
|
label="小程序落地页(选填)"
|
||||||
<Space size="small" wrap>
|
extra="如 pages/home/index;留空则使用服务端环境变量 WX_MINI_PROMO_PAGE"
|
||||||
|
>
|
||||||
<Button type="link" size="small" onClick={() => navigate(`/promo-codes/${row.id}`)}>
|
<Input placeholder="pages/home/index" />
|
||||||
|
</Form.Item>
|
||||||
详情
|
<Form.Item name="ownerUserId" label="关联用户 ID(选填)">
|
||||||
|
<Input placeholder="渠道负责人,填写用户数据库 ID" />
|
||||||
</Button>
|
</Form.Item>
|
||||||
|
<Form.Item name="remark" label="备注">
|
||||||
<Button
|
<Input.TextArea rows={2} placeholder="渠道说明、活动备注等" />
|
||||||
|
</Form.Item>
|
||||||
|
<Button type="primary" htmlType="submit" loading={creating} block>
|
||||||
|
创建并生成小程序码
|
||||||
|
</Button>
|
||||||
|
</Form>
|
||||||
|
</Modal>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { useState } from 'react';
|
|||||||
import {
|
import {
|
||||||
Button, Card, Col, Form, Input, InputNumber, Row, Space, Tabs, Typography, message,
|
Button, Card, Col, Form, Input, InputNumber, Row, Space, Tabs, Typography, message,
|
||||||
} from 'antd';
|
} from 'antd';
|
||||||
|
import { MOCK_SMS_FIXED_CODE } from '@dukang/shared-types';
|
||||||
import { request } from '../lib/api';
|
import { request } from '../lib/api';
|
||||||
|
|
||||||
type ApiResult = Record<string, unknown>;
|
type ApiResult = Record<string, unknown>;
|
||||||
@@ -255,7 +256,7 @@ export default function RedeemDebugPage() {
|
|||||||
<Input />
|
<Input />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item name="code" label="验证码" rules={[{ required: true }]}>
|
<Form.Item name="code" label="验证码" rules={[{ required: true }]}>
|
||||||
<Input placeholder="Mock 默认 123456" />
|
<Input placeholder={`Mock 默认 ${MOCK_SMS_FIXED_CODE}`} />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Button
|
<Button
|
||||||
loading={loading}
|
loading={loading}
|
||||||
@@ -335,7 +336,7 @@ export default function RedeemDebugPage() {
|
|||||||
<Input />
|
<Input />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item name="code" label="核销确认验证码" rules={[{ required: true }]}>
|
<Form.Item name="code" label="核销确认验证码" rules={[{ required: true }]}>
|
||||||
<Input placeholder="Mock 默认 123456" />
|
<Input placeholder={`Mock 默认 ${MOCK_SMS_FIXED_CODE}`} />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Button
|
<Button
|
||||||
type="primary"
|
type="primary"
|
||||||
|
|||||||
@@ -1,48 +1,134 @@
|
|||||||
import { useState } from 'react';
|
import { useEffect, useRef, useState } from 'react';
|
||||||
import { Button, Descriptions, Drawer, Form, Input, Table, Typography } from 'antd';
|
import { useSearchParams } from 'react-router-dom';
|
||||||
|
import { Button, Checkbox, Drawer, Form, Input, Select, Table, Tag, Typography } from 'antd';
|
||||||
import type { ColumnsType } from 'antd/es/table';
|
import type { ColumnsType } from 'antd/es/table';
|
||||||
|
import { REDEEM_CHANNEL_LABELS, type RedeemChannel } from '@dukang/shared-types';
|
||||||
|
import RedeemRecordDetailDescriptions from '../components/RedeemRecordDetailDescriptions';
|
||||||
import { request } from '../lib/api';
|
import { request } from '../lib/api';
|
||||||
import { fmtTime } from '../lib/constants';
|
import { fmtTime } from '../lib/constants';
|
||||||
import { useAdminList } from '../lib/useAdminList';
|
import { useAdminList } from '../lib/useAdminList';
|
||||||
|
|
||||||
type Row = {
|
type Row = {
|
||||||
id: string; redeemNo: string; amount: number; settleAmount: number; createdAt: string;
|
id: string;
|
||||||
user?: { userNo: string; phone: string | null };
|
redeemNo: string;
|
||||||
|
amount: number;
|
||||||
|
settleAmount: number;
|
||||||
|
channel?: RedeemChannel;
|
||||||
|
createdAt: string;
|
||||||
|
isTest?: boolean;
|
||||||
|
user?: { userNo: string; phone: string | null; nickname?: string | null };
|
||||||
store?: { name: string; cityName: string };
|
store?: { name: string; cityName: string };
|
||||||
coupon?: { couponNo: string };
|
coupon?: { couponNo: string };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function maskPhone(phone: string | null | undefined) {
|
||||||
|
if (!phone || phone.length < 7) return phone ?? '—';
|
||||||
|
return `${phone.slice(0, 3)}****${phone.slice(-4)}`;
|
||||||
|
}
|
||||||
|
|
||||||
export default function RedeemRecordsPage() {
|
export default function RedeemRecordsPage() {
|
||||||
|
const [searchParams] = useSearchParams();
|
||||||
|
const initialRedeemNo = searchParams.get('redeemNo')?.trim() || '';
|
||||||
const [form] = Form.useForm();
|
const [form] = Form.useForm();
|
||||||
const [filters, setFilters] = useState<Record<string, string>>({});
|
const [filters, setFilters] = useState<Record<string, string | boolean>>(() => {
|
||||||
|
const init: Record<string, string | boolean> = {};
|
||||||
|
if (initialRedeemNo) init.redeemNo = initialRedeemNo;
|
||||||
|
return init;
|
||||||
|
});
|
||||||
const { data, loading, page, pageSize, setPage, setPageSize } = useAdminList<Row>(
|
const { data, loading, page, pageSize, setPage, setPageSize } = useAdminList<Row>(
|
||||||
'/admin/redeem-records',
|
'/admin/redeem-records',
|
||||||
() => {
|
() => {
|
||||||
const qs = new URLSearchParams();
|
const qs = new URLSearchParams();
|
||||||
if (filters.redeemNo) qs.set('redeemNo', filters.redeemNo);
|
if (filters.redeemNo) qs.set('redeemNo', String(filters.redeemNo));
|
||||||
if (filters.storeId) qs.set('storeId', filters.storeId);
|
if (filters.storeId) qs.set('storeId', String(filters.storeId));
|
||||||
|
if (filters.channel) qs.set('channel', String(filters.channel));
|
||||||
|
if (filters.excludeTest) qs.set('excludeTest', 'true');
|
||||||
return qs;
|
return qs;
|
||||||
},
|
},
|
||||||
[filters],
|
[filters],
|
||||||
);
|
);
|
||||||
const [detail, setDetail] = useState<Record<string, unknown> | null>(null);
|
const [detail, setDetail] = useState<Record<string, unknown> | null>(null);
|
||||||
const [drawerOpen, setDrawerOpen] = useState(false);
|
const [drawerOpen, setDrawerOpen] = useState(false);
|
||||||
|
const [detailLoading, setDetailLoading] = useState(false);
|
||||||
|
const deepLinkOpenedRef = useRef(false);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (initialRedeemNo) form.setFieldsValue({ redeemNo: initialRedeemNo });
|
||||||
|
}, [form, initialRedeemNo]);
|
||||||
|
|
||||||
|
async function openDetail(id: string) {
|
||||||
|
setDetailLoading(true);
|
||||||
|
setDrawerOpen(true);
|
||||||
|
try {
|
||||||
|
setDetail(await request(`/admin/redeem-records/${id}`));
|
||||||
|
} finally {
|
||||||
|
setDetailLoading(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!initialRedeemNo || deepLinkOpenedRef.current || loading) return;
|
||||||
|
const first = data?.items?.[0];
|
||||||
|
if (first && String(first.redeemNo) === initialRedeemNo) {
|
||||||
|
deepLinkOpenedRef.current = true;
|
||||||
|
void openDetail(first.id);
|
||||||
|
}
|
||||||
|
}, [data, initialRedeemNo, loading]);
|
||||||
|
|
||||||
const columns: ColumnsType<Row> = [
|
const columns: ColumnsType<Row> = [
|
||||||
{ title: '核销号', dataIndex: 'redeemNo', width: 180 },
|
{
|
||||||
{ title: '用户', dataIndex: ['user', 'userNo'], width: 110 },
|
title: '核销号',
|
||||||
|
dataIndex: 'redeemNo',
|
||||||
|
width: 200,
|
||||||
|
render: (v, row) => (
|
||||||
|
<span>
|
||||||
|
{v}
|
||||||
|
{row.isTest ? (
|
||||||
|
<Tag color="orange" style={{ marginLeft: 6 }}>
|
||||||
|
测试
|
||||||
|
</Tag>
|
||||||
|
) : null}
|
||||||
|
</span>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '方式',
|
||||||
|
dataIndex: 'channel',
|
||||||
|
width: 110,
|
||||||
|
render: (v: RedeemChannel | undefined) => {
|
||||||
|
const channel = v === 'PHONE' ? 'PHONE' : 'SCAN';
|
||||||
|
return (
|
||||||
|
<Tag color={channel === 'PHONE' ? 'purple' : 'blue'}>
|
||||||
|
{REDEEM_CHANNEL_LABELS[channel]}
|
||||||
|
</Tag>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{ title: '用户编号', dataIndex: ['user', 'userNo'], width: 110 },
|
||||||
|
{
|
||||||
|
title: '用户昵称',
|
||||||
|
dataIndex: ['user', 'nickname'],
|
||||||
|
width: 100,
|
||||||
|
render: (v: string | null | undefined) => v || '—',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '用户手机',
|
||||||
|
dataIndex: ['user', 'phone'],
|
||||||
|
width: 120,
|
||||||
|
render: (v: string | null | undefined) => maskPhone(v),
|
||||||
|
},
|
||||||
{ title: '门店', dataIndex: ['store', 'name'] },
|
{ title: '门店', dataIndex: ['store', 'name'] },
|
||||||
{ title: '核销额', dataIndex: 'amount', width: 90, render: (v) => `¥${v}` },
|
{ title: '核销额', dataIndex: 'amount', width: 90, render: (v) => `¥${v}` },
|
||||||
{ title: '结算额', dataIndex: 'settleAmount', width: 90, render: (v) => `¥${v}` },
|
{ title: '结算额', dataIndex: 'settleAmount', width: 90, render: (v) => `¥${v}` },
|
||||||
{ title: '券号', dataIndex: ['coupon', 'couponNo'], width: 160 },
|
{ title: '券号', dataIndex: ['coupon', 'couponNo'], width: 160 },
|
||||||
{ title: '时间', dataIndex: 'createdAt', width: 160, render: fmtTime },
|
{ title: '时间', dataIndex: 'createdAt', width: 160, render: fmtTime },
|
||||||
{
|
{
|
||||||
title: '操作', width: 80,
|
title: '操作',
|
||||||
|
width: 80,
|
||||||
render: (_, row) => (
|
render: (_, row) => (
|
||||||
<Button type="link" size="small" onClick={async () => {
|
<Button type="link" size="small" onClick={() => void openDetail(row.id)}>
|
||||||
setDetail(await request(`/admin/redeem-records/${row.id}`));
|
详情
|
||||||
setDrawerOpen(true);
|
</Button>
|
||||||
}}>详情</Button>
|
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
@@ -50,21 +136,72 @@ export default function RedeemRecordsPage() {
|
|||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<Typography.Title level={4}>核销记录</Typography.Title>
|
<Typography.Title level={4}>核销记录</Typography.Title>
|
||||||
<Form form={form} layout="inline" style={{ marginBottom: 16 }} onFinish={(v) => { setFilters(v); setPage(1); }}>
|
<Form
|
||||||
<Form.Item name="redeemNo" label="核销号"><Input allowClear /></Form.Item>
|
form={form}
|
||||||
<Form.Item name="storeId" label="门店ID"><Input allowClear /></Form.Item>
|
layout="inline"
|
||||||
|
style={{ marginBottom: 16 }}
|
||||||
|
onFinish={(v) => {
|
||||||
|
setFilters(v);
|
||||||
|
setPage(1);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Form.Item name="redeemNo" label="核销号">
|
||||||
|
<Input allowClear />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="storeId" label="门店ID">
|
||||||
|
<Input allowClear />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="channel" label="方式">
|
||||||
|
<Select
|
||||||
|
allowClear
|
||||||
|
style={{ width: 140 }}
|
||||||
|
options={[
|
||||||
|
{ value: 'SCAN', label: '扫码核销' },
|
||||||
|
{ value: 'PHONE', label: '手机号核销' },
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="excludeTest" valuePropName="checked">
|
||||||
|
<Checkbox>过滤测试账号</Checkbox>
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item>
|
||||||
|
<Button type="primary" htmlType="submit">
|
||||||
|
查询
|
||||||
|
</Button>
|
||||||
|
</Form.Item>
|
||||||
</Form>
|
</Form>
|
||||||
<Table rowKey="id" loading={loading} columns={columns} dataSource={data?.items ?? []} scroll={{ x: 1000 }}
|
<Table
|
||||||
pagination={{ current: page, pageSize, total: data?.total ?? 0, showSizeChanger: true, onChange: (p, ps) => { setPage(p); setPageSize(ps); } }} />
|
rowKey="id"
|
||||||
<Drawer title="核销详情" width={520} open={drawerOpen} onClose={() => setDrawerOpen(false)}>
|
loading={loading}
|
||||||
{detail && (
|
columns={columns}
|
||||||
<Descriptions column={1} bordered size="small">
|
dataSource={data?.items ?? []}
|
||||||
<Descriptions.Item label="核销号">{String(detail.redeemNo)}</Descriptions.Item>
|
scroll={{ x: 1300 }}
|
||||||
<Descriptions.Item label="核销额">¥{String(detail.amount)}</Descriptions.Item>
|
pagination={{
|
||||||
<Descriptions.Item label="结算额">¥{String(detail.settleAmount)}</Descriptions.Item>
|
current: page,
|
||||||
<Descriptions.Item label="时间">{fmtTime(String(detail.createdAt))}</Descriptions.Item>
|
pageSize,
|
||||||
</Descriptions>
|
total: data?.total ?? 0,
|
||||||
)}
|
showSizeChanger: true,
|
||||||
|
onChange: (p, ps) => {
|
||||||
|
setPage(p);
|
||||||
|
setPageSize(ps);
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<Drawer
|
||||||
|
title="核销详情"
|
||||||
|
width={640}
|
||||||
|
open={drawerOpen}
|
||||||
|
onClose={() => {
|
||||||
|
setDrawerOpen(false);
|
||||||
|
setDetail(null);
|
||||||
|
}}
|
||||||
|
destroyOnClose
|
||||||
|
>
|
||||||
|
{detailLoading ? (
|
||||||
|
<Typography.Text type="secondary">加载中…</Typography.Text>
|
||||||
|
) : detail ? (
|
||||||
|
<RedeemRecordDetailDescriptions detail={detail} />
|
||||||
|
) : null}
|
||||||
</Drawer>
|
</Drawer>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import {
|
import {
|
||||||
Button, Descriptions, Drawer, Form, Input, Modal, Select, Space, Table, Tag, Typography, message,
|
Button, Checkbox, Descriptions, Drawer, Form, Input, Modal, Popconfirm, Select, Space, Table, Tag, Typography, message,
|
||||||
} from 'antd';
|
} from 'antd';
|
||||||
import type { ColumnsType } from 'antd/es/table';
|
import type { ColumnsType } from 'antd/es/table';
|
||||||
import { request, type Paginated } from '../lib/api';
|
import { request, type Paginated } from '../lib/api';
|
||||||
@@ -15,6 +15,7 @@ type Row = {
|
|||||||
name: string;
|
name: string;
|
||||||
status: string;
|
status: string;
|
||||||
createdAt: string;
|
createdAt: string;
|
||||||
|
isTest?: boolean;
|
||||||
storeCount?: number;
|
storeCount?: number;
|
||||||
staffCount?: number;
|
staffCount?: number;
|
||||||
bankAccountName?: string | null;
|
bankAccountName?: string | null;
|
||||||
@@ -30,13 +31,14 @@ type StoreOption = { id: string; name: string };
|
|||||||
export default function StoreAccountsPage() {
|
export default function StoreAccountsPage() {
|
||||||
const [form] = Form.useForm();
|
const [form] = Form.useForm();
|
||||||
const [createForm] = Form.useForm();
|
const [createForm] = Form.useForm();
|
||||||
const [filters, setFilters] = useState<Record<string, string>>({});
|
const [filters, setFilters] = useState<Record<string, string | boolean>>({});
|
||||||
const { data, loading, page, pageSize, setPage, setPageSize, reload } = useAdminList<Row>(
|
const { data, loading, page, pageSize, setPage, setPageSize, reload } = useAdminList<Row>(
|
||||||
'/admin/store-accounts',
|
'/admin/store-accounts',
|
||||||
() => {
|
() => {
|
||||||
const qs = new URLSearchParams();
|
const qs = new URLSearchParams();
|
||||||
if (filters.phone) qs.set('phone', filters.phone);
|
if (filters.phone) qs.set('phone', String(filters.phone));
|
||||||
if (filters.status) qs.set('status', filters.status);
|
if (filters.status) qs.set('status', String(filters.status));
|
||||||
|
if (filters.excludeTest) qs.set('excludeTest', 'true');
|
||||||
return qs;
|
return qs;
|
||||||
},
|
},
|
||||||
[filters],
|
[filters],
|
||||||
@@ -45,14 +47,45 @@ export default function StoreAccountsPage() {
|
|||||||
const [drawerOpen, setDrawerOpen] = useState(false);
|
const [drawerOpen, setDrawerOpen] = useState(false);
|
||||||
const [createOpen, setCreateOpen] = useState(false);
|
const [createOpen, setCreateOpen] = useState(false);
|
||||||
const [stores, setStores] = useState<StoreOption[]>([]);
|
const [stores, setStores] = useState<StoreOption[]>([]);
|
||||||
|
const [deletingStaffId, setDeletingStaffId] = useState<string | null>(null);
|
||||||
|
|
||||||
async function loadStores() {
|
async function loadStores() {
|
||||||
const res = await request<Paginated<StoreOption>>(`/admin/stores?pageSize=${ADMIN_OPTIONS_PAGE_SIZE}`);
|
const res = await request<Paginated<StoreOption>>(`/admin/stores?pageSize=${ADMIN_OPTIONS_PAGE_SIZE}`);
|
||||||
setStores(res.items);
|
setStores(res.items);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function refreshDetail(accountId: string) {
|
||||||
|
const d = await request<Row>(`/admin/store-accounts/${accountId}`);
|
||||||
|
setDetail(d);
|
||||||
|
void reload();
|
||||||
|
}
|
||||||
|
|
||||||
|
async function deleteStaff(staffId: string) {
|
||||||
|
if (!detail) return;
|
||||||
|
setDeletingStaffId(staffId);
|
||||||
|
try {
|
||||||
|
await request(`/admin/store-accounts/${detail.id}/staff/${staffId}`, { method: 'DELETE' });
|
||||||
|
message.success('子账号已删除');
|
||||||
|
await refreshDetail(detail.id);
|
||||||
|
} catch (e) {
|
||||||
|
message.error(e instanceof Error ? e.message : '删除失败');
|
||||||
|
} finally {
|
||||||
|
setDeletingStaffId(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const columns: ColumnsType<Row> = [
|
const columns: ColumnsType<Row> = [
|
||||||
{ title: '姓名', dataIndex: 'name', width: 100 },
|
{
|
||||||
|
title: '姓名',
|
||||||
|
dataIndex: 'name',
|
||||||
|
width: 120,
|
||||||
|
render: (v, row) => (
|
||||||
|
<Space size={4}>
|
||||||
|
<span>{v}</span>
|
||||||
|
{row.isTest ? <Tag color="orange">测试</Tag> : null}
|
||||||
|
</Space>
|
||||||
|
),
|
||||||
|
},
|
||||||
{ title: '手机', dataIndex: 'phone', width: 120 },
|
{ title: '手机', dataIndex: 'phone', width: 120 },
|
||||||
{
|
{
|
||||||
title: '绑定门店',
|
title: '绑定门店',
|
||||||
@@ -141,6 +174,9 @@ export default function StoreAccountsPage() {
|
|||||||
options={Object.entries(ACCOUNT_STATUS_LABELS).map(([value, label]) => ({ value, label }))}
|
options={Object.entries(ACCOUNT_STATUS_LABELS).map(([value, label]) => ({ value, label }))}
|
||||||
/>
|
/>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
|
<Form.Item name="excludeTest" valuePropName="checked">
|
||||||
|
<Checkbox>过滤测试账号</Checkbox>
|
||||||
|
</Form.Item>
|
||||||
<Form.Item><Button type="primary" htmlType="submit">查询</Button></Form.Item>
|
<Form.Item><Button type="primary" htmlType="submit">查询</Button></Form.Item>
|
||||||
</Form>
|
</Form>
|
||||||
<Table
|
<Table
|
||||||
@@ -218,10 +254,32 @@ export default function StoreAccountsPage() {
|
|||||||
dataIndex: 'status',
|
dataIndex: 'status',
|
||||||
render: (s) => <Tag>{ACCOUNT_STATUS_LABELS[s] || s}</Tag>,
|
render: (s) => <Tag>{ACCOUNT_STATUS_LABELS[s] || s}</Tag>,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
title: '操作',
|
||||||
|
width: 80,
|
||||||
|
render: (_, staff) => (
|
||||||
|
<Popconfirm
|
||||||
|
title="确认删除该子账号?"
|
||||||
|
description={`${staff.name}(${staff.phone})删除后将无法登录门店端`}
|
||||||
|
okText="删除"
|
||||||
|
okButtonProps={{ danger: true, loading: deletingStaffId === staff.id }}
|
||||||
|
cancelText="取消"
|
||||||
|
onConfirm={() => void deleteStaff(staff.id)}
|
||||||
|
>
|
||||||
|
<Button type="link" size="small" danger>
|
||||||
|
删除
|
||||||
|
</Button>
|
||||||
|
</Popconfirm>
|
||||||
|
),
|
||||||
|
},
|
||||||
]}
|
]}
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
) : null}
|
) : (
|
||||||
|
<Typography.Paragraph type="secondary" style={{ marginTop: 24, marginBottom: 0 }}>
|
||||||
|
暂无子账号
|
||||||
|
</Typography.Paragraph>
|
||||||
|
)}
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</Drawer>
|
</Drawer>
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
|
import { useSearchParams } from 'react-router-dom';
|
||||||
import {
|
import {
|
||||||
Button,
|
Button,
|
||||||
Card,
|
Card,
|
||||||
@@ -6,6 +7,8 @@ import {
|
|||||||
Descriptions,
|
Descriptions,
|
||||||
Drawer,
|
Drawer,
|
||||||
Form,
|
Form,
|
||||||
|
Input,
|
||||||
|
Modal,
|
||||||
Select,
|
Select,
|
||||||
Space,
|
Space,
|
||||||
Statistic,
|
Statistic,
|
||||||
@@ -16,44 +19,66 @@ import {
|
|||||||
} from 'antd';
|
} from 'antd';
|
||||||
import type { ColumnsType } from 'antd/es/table';
|
import type { ColumnsType } from 'antd/es/table';
|
||||||
import type { Dayjs } from 'dayjs';
|
import type { Dayjs } from 'dayjs';
|
||||||
|
import {
|
||||||
|
STORE_SETTLEMENT_KIND_LABELS,
|
||||||
|
STORE_SETTLEMENT_STATUS_LABELS,
|
||||||
|
storeSettlementStatusLabel,
|
||||||
|
type StoreSettlementKind,
|
||||||
|
type StoreSettlementStatus,
|
||||||
|
} from '@dukang/shared-types';
|
||||||
import { request, type Paginated } from '../lib/api';
|
import { request, type Paginated } from '../lib/api';
|
||||||
import { ADMIN_OPTIONS_PAGE_SIZE, fmtTime } from '../lib/constants';
|
import { ADMIN_OPTIONS_PAGE_SIZE, fmtTime } from '../lib/constants';
|
||||||
import { downloadExcelCsv } from '../lib/exportExcel';
|
import { downloadExcelCsv } from '../lib/exportExcel';
|
||||||
import { useAdminList } from '../lib/useAdminList';
|
import { useAdminList } from '../lib/useAdminList';
|
||||||
|
|
||||||
type Row = {
|
type Row = {
|
||||||
|
kind: StoreSettlementKind;
|
||||||
id: string;
|
id: string;
|
||||||
redeemAmount: number;
|
billNo: string;
|
||||||
payoutAmount: number;
|
amount: number;
|
||||||
settlementRate: number;
|
status: StoreSettlementStatus;
|
||||||
status: string;
|
date: string;
|
||||||
expectedPayAt: string;
|
overdue?: boolean;
|
||||||
paidAt?: string;
|
redeemCount?: number | null;
|
||||||
createdAt: string;
|
redeemAmount?: number | null;
|
||||||
store?: { id: string; name: string; cityName: string; phone?: string };
|
settlementRate?: number | null;
|
||||||
redeemRecord?: { redeemNo: string; amount?: number; createdAt?: string };
|
payoutCount?: number | null;
|
||||||
|
store?: { id: string; name: string; cityName: string; phone?: string | null };
|
||||||
};
|
};
|
||||||
|
|
||||||
type StoreOption = { id: string; name: string; phone: string };
|
type StoreOption = { id: string; name: string; phone: string };
|
||||||
|
|
||||||
const PAYOUT_STATUS_LABELS: Record<string, string> = {
|
const STATUS_COLORS: Record<string, string> = {
|
||||||
PENDING: '待打款',
|
UNPAID: 'red',
|
||||||
PAID: '已打款',
|
PAID: 'green',
|
||||||
|
PENDING_REVIEW: 'orange',
|
||||||
|
REJECTED: 'red',
|
||||||
};
|
};
|
||||||
|
|
||||||
const PAYOUT_STATUS_COLORS: Record<string, string> = {
|
const KIND_COLORS: Record<StoreSettlementKind, string> = {
|
||||||
PENDING: 'orange',
|
T1_BILL: 'blue',
|
||||||
PAID: 'green',
|
WITHDRAW: 'purple',
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function StoreBillsPage() {
|
export default function StoreBillsPage() {
|
||||||
|
const [searchParams] = useSearchParams();
|
||||||
|
const initialKind = searchParams.get('kind') === 'WITHDRAW' ? 'WITHDRAW' : '';
|
||||||
|
const initialStoreId = searchParams.get('storeId') || '';
|
||||||
|
const initialStatus =
|
||||||
|
searchParams.get('status')?.trim() ||
|
||||||
|
(initialKind === 'WITHDRAW' ? 'PENDING_REVIEW' : '');
|
||||||
const [form] = Form.useForm();
|
const [form] = Form.useForm();
|
||||||
const [filters, setFilters] = useState<Record<string, string>>({});
|
const [filters, setFilters] = useState<Record<string, string>>({
|
||||||
|
kind: initialKind,
|
||||||
|
status: initialStatus,
|
||||||
|
storeId: initialStoreId,
|
||||||
|
});
|
||||||
const [stores, setStores] = useState<StoreOption[]>([]);
|
const [stores, setStores] = useState<StoreOption[]>([]);
|
||||||
const { data, loading, page, pageSize, setPage, setPageSize, reload } = useAdminList<Row>(
|
const { data, loading, page, pageSize, setPage, setPageSize, reload } = useAdminList<Row>(
|
||||||
'/admin/store-payouts',
|
'/admin/store-settlements',
|
||||||
() => {
|
() => {
|
||||||
const qs = new URLSearchParams();
|
const qs = new URLSearchParams();
|
||||||
|
if (filters.kind) qs.set('kind', filters.kind);
|
||||||
if (filters.status) qs.set('status', filters.status);
|
if (filters.status) qs.set('status', filters.status);
|
||||||
if (filters.storeId) qs.set('storeId', filters.storeId);
|
if (filters.storeId) qs.set('storeId', filters.storeId);
|
||||||
if (filters.dateFrom) qs.set('dateFrom', filters.dateFrom);
|
if (filters.dateFrom) qs.set('dateFrom', filters.dateFrom);
|
||||||
@@ -63,22 +88,132 @@ export default function StoreBillsPage() {
|
|||||||
[filters],
|
[filters],
|
||||||
);
|
);
|
||||||
const [detail, setDetail] = useState<Record<string, unknown> | null>(null);
|
const [detail, setDetail] = useState<Record<string, unknown> | null>(null);
|
||||||
|
const [detailKind, setDetailKind] = useState<StoreSettlementKind | null>(null);
|
||||||
const [drawerOpen, setDrawerOpen] = useState(false);
|
const [drawerOpen, setDrawerOpen] = useState(false);
|
||||||
const [exporting, setExporting] = useState(false);
|
const [exporting, setExporting] = useState(false);
|
||||||
|
const [selectedKeys, setSelectedKeys] = useState<React.Key[]>([]);
|
||||||
|
const [batchLoading, setBatchLoading] = useState(false);
|
||||||
|
const [overdueSummary, setOverdueSummary] = useState<{
|
||||||
|
pendingCount: number;
|
||||||
|
overdueCount: number;
|
||||||
|
} | null>(null);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
form.setFieldsValue({
|
||||||
|
kind: filters.kind || undefined,
|
||||||
|
status: filters.status || undefined,
|
||||||
|
storeId: filters.storeId || undefined,
|
||||||
|
});
|
||||||
|
}, [filters.kind, filters.status, filters.storeId, form]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
void request<Paginated<StoreOption>>(`/admin/stores?pageSize=${ADMIN_OPTIONS_PAGE_SIZE}`)
|
void request<Paginated<StoreOption>>(`/admin/stores?pageSize=${ADMIN_OPTIONS_PAGE_SIZE}`)
|
||||||
.then((res) => setStores(res.items))
|
.then((res) => setStores(res.items))
|
||||||
.catch(() => {});
|
.catch(() => {});
|
||||||
|
void request<{ pendingCount: number; overdueCount: number }>(
|
||||||
|
'/admin/store-withdrawals/overdue-summary',
|
||||||
|
)
|
||||||
|
.then(setOverdueSummary)
|
||||||
|
.catch(() => {});
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
async function confirmPayout(id: string) {
|
function confirmPay(ids: string[], amountHint?: number) {
|
||||||
await request(`/admin/store-payouts/${id}/confirm`, {
|
Modal.confirm({
|
||||||
method: 'POST',
|
title: '确认打款?',
|
||||||
body: JSON.stringify({ remark: '财务确认打款' }),
|
content: `将确认 ${ids.length} 笔 T+1 门店对账单${amountHint != null ? `,合计约 ¥${amountHint.toFixed(2)}` : ''}。此操作不可撤销。`,
|
||||||
|
okText: '确认打款',
|
||||||
|
cancelText: '取消',
|
||||||
|
onOk: async () => {
|
||||||
|
if (ids.length === 1) {
|
||||||
|
await request(`/admin/store-bills/${ids[0]}/confirm`, { method: 'POST' });
|
||||||
|
} else {
|
||||||
|
setBatchLoading(true);
|
||||||
|
try {
|
||||||
|
await request('/admin/store-bills/batch-confirm', {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify({ ids }),
|
||||||
|
});
|
||||||
|
} finally {
|
||||||
|
setBatchLoading(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
message.success('已确认打款');
|
||||||
|
setSelectedKeys([]);
|
||||||
|
reload();
|
||||||
|
},
|
||||||
});
|
});
|
||||||
message.success('已确认打款');
|
}
|
||||||
reload();
|
|
||||||
|
function approveWithdraw(id: string) {
|
||||||
|
let paymentRef = '';
|
||||||
|
Modal.confirm({
|
||||||
|
title: '审核通过并标记已结算?',
|
||||||
|
content: (
|
||||||
|
<Input
|
||||||
|
placeholder="打款凭证号(可选)"
|
||||||
|
onChange={(e) => {
|
||||||
|
paymentRef = e.target.value;
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
),
|
||||||
|
okText: '通过并结算',
|
||||||
|
cancelText: '取消',
|
||||||
|
onOk: async () => {
|
||||||
|
await request(`/admin/store-withdrawals/${id}/approve`, {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify({ paymentRef: paymentRef.trim() || undefined }),
|
||||||
|
});
|
||||||
|
message.success('已通过并标记已结算');
|
||||||
|
setDrawerOpen(false);
|
||||||
|
reload();
|
||||||
|
void request<{ pendingCount: number; overdueCount: number }>(
|
||||||
|
'/admin/store-withdrawals/overdue-summary',
|
||||||
|
)
|
||||||
|
.then(setOverdueSummary)
|
||||||
|
.catch(() => {});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function rejectWithdraw(id: string) {
|
||||||
|
let reason = '';
|
||||||
|
Modal.confirm({
|
||||||
|
title: '驳回提现申请?',
|
||||||
|
content: (
|
||||||
|
<Input.TextArea
|
||||||
|
rows={3}
|
||||||
|
placeholder="请填写驳回理由"
|
||||||
|
onChange={(e) => {
|
||||||
|
reason = e.target.value;
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
),
|
||||||
|
okText: '确认驳回',
|
||||||
|
okButtonProps: { danger: true },
|
||||||
|
cancelText: '取消',
|
||||||
|
onOk: async () => {
|
||||||
|
if (!reason.trim()) {
|
||||||
|
message.error('请填写驳回理由');
|
||||||
|
throw new Error('reason required');
|
||||||
|
}
|
||||||
|
await request(`/admin/store-withdrawals/${id}/reject`, {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify({ reason: reason.trim() }),
|
||||||
|
});
|
||||||
|
message.success('已驳回');
|
||||||
|
setDrawerOpen(false);
|
||||||
|
reload();
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async function openDetail(row: Row) {
|
||||||
|
const path =
|
||||||
|
row.kind === 'WITHDRAW' ? `/admin/store-withdrawals/${row.id}` : `/admin/store-bills/${row.id}`;
|
||||||
|
const d = await request<Record<string, unknown>>(path);
|
||||||
|
setDetail(d);
|
||||||
|
setDetailKind(row.kind);
|
||||||
|
setDrawerOpen(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function exportExcel() {
|
async function exportExcel() {
|
||||||
@@ -89,81 +224,114 @@ export default function StoreBillsPage() {
|
|||||||
if (filters.storeId) qs.set('storeId', filters.storeId);
|
if (filters.storeId) qs.set('storeId', filters.storeId);
|
||||||
if (filters.dateFrom) qs.set('dateFrom', filters.dateFrom);
|
if (filters.dateFrom) qs.set('dateFrom', filters.dateFrom);
|
||||||
if (filters.dateTo) qs.set('dateTo', filters.dateTo);
|
if (filters.dateTo) qs.set('dateTo', filters.dateTo);
|
||||||
const result = await request<{ csv: string; count: number }>(
|
const result = await request<{ csv: string; count: number }>(`/admin/store-bills/export?${qs}`);
|
||||||
`/admin/store-payouts/export?${qs}`,
|
downloadExcelCsv(result.csv, `门店对账单_${filters.dateFrom || 'all'}_${filters.dateTo || 'all'}.csv`);
|
||||||
);
|
message.success(`已导出 ${result.count} 条 T+1 账单`);
|
||||||
downloadExcelCsv(result.csv, `门店账单_${filters.dateFrom || 'all'}_${filters.dateTo || 'all'}.csv`);
|
|
||||||
message.success(`已导出 ${result.count} 条`);
|
|
||||||
} finally {
|
} finally {
|
||||||
setExporting(false);
|
setExporting(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const summary = data?.summary;
|
const summary = data?.summary;
|
||||||
|
const selectedRows = (data?.items ?? []).filter(
|
||||||
|
(r) =>
|
||||||
|
selectedKeys.includes(`${r.kind}-${r.id}`) &&
|
||||||
|
r.kind === 'T1_BILL' &&
|
||||||
|
r.status === 'UNPAID',
|
||||||
|
);
|
||||||
|
const selectedAmount = selectedRows.reduce((s, r) => s + Number(r.amount), 0);
|
||||||
|
|
||||||
const columns: ColumnsType<Row> = [
|
const columns: ColumnsType<Row> = [
|
||||||
{
|
{
|
||||||
title: '核销日期',
|
title: '类型',
|
||||||
width: 110,
|
dataIndex: 'kind',
|
||||||
render: (_, r) =>
|
width: 100,
|
||||||
(r.redeemRecord?.createdAt || r.createdAt || '').toString().slice(0, 10) || '—',
|
render: (k: StoreSettlementKind) => (
|
||||||
|
<Tag color={KIND_COLORS[k]}>{STORE_SETTLEMENT_KIND_LABELS[k] ?? k}</Tag>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '单号',
|
||||||
|
dataIndex: 'billNo',
|
||||||
|
width: 180,
|
||||||
|
ellipsis: true,
|
||||||
|
render: (v, row) => (
|
||||||
|
<Space>
|
||||||
|
<span>{v}</span>
|
||||||
|
{row.overdue ? <Tag color="magenta">超时</Tag> : null}
|
||||||
|
</Space>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '日期',
|
||||||
|
dataIndex: 'date',
|
||||||
|
width: 160,
|
||||||
|
render: (v, row) => (row.kind === 'T1_BILL' ? String(v || '').slice(0, 10) : fmtTime(v)),
|
||||||
},
|
},
|
||||||
{ title: '门店', dataIndex: ['store', 'name'], width: 140, ellipsis: true },
|
{ title: '门店', dataIndex: ['store', 'name'], width: 140, ellipsis: true },
|
||||||
{ title: '登录手机', dataIndex: ['store', 'phone'], width: 120, render: (v) => v || '—' },
|
{ title: '登录手机', dataIndex: ['store', 'phone'], width: 120, render: (v) => v || '—' },
|
||||||
{ title: '城市', dataIndex: ['store', 'cityName'], width: 90 },
|
{ title: '城市', dataIndex: ['store', 'cityName'], width: 90 },
|
||||||
{
|
{
|
||||||
title: '核销单号',
|
title: '笔数',
|
||||||
dataIndex: ['redeemRecord', 'redeemNo'],
|
width: 80,
|
||||||
width: 160,
|
render: (_, row) =>
|
||||||
ellipsis: true,
|
row.kind === 'T1_BILL' ? (row.redeemCount ?? '—') : (row.payoutCount ?? '—'),
|
||||||
render: (v) => v || '—',
|
|
||||||
},
|
|
||||||
{ title: '核销面额', dataIndex: 'redeemAmount', width: 100, render: (v) => `¥${v}` },
|
|
||||||
{
|
|
||||||
title: '核销比例',
|
|
||||||
dataIndex: 'settlementRate',
|
|
||||||
width: 90,
|
|
||||||
render: (v) => (v != null ? `${Math.round(Number(v) * 100)}%` : '—'),
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: '应付门店',
|
title: '应付金额',
|
||||||
dataIndex: 'payoutAmount',
|
dataIndex: 'amount',
|
||||||
width: 100,
|
width: 110,
|
||||||
render: (v) => `¥${v}`,
|
render: (v) => `¥${Number(v).toFixed(2)}`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: '打款状态',
|
title: '状态',
|
||||||
dataIndex: 'status',
|
dataIndex: 'status',
|
||||||
width: 100,
|
width: 100,
|
||||||
render: (s) => <Tag color={PAYOUT_STATUS_COLORS[s] || 'default'}>{PAYOUT_STATUS_LABELS[s] || s}</Tag>,
|
render: (s: string, row) => (
|
||||||
|
<Tag color={STATUS_COLORS[s] || 'default'}>{storeSettlementStatusLabel(row.kind, s)}</Tag>
|
||||||
|
),
|
||||||
},
|
},
|
||||||
{ title: '预计打款(T+1)', dataIndex: 'expectedPayAt', width: 160, render: fmtTime },
|
|
||||||
{
|
{
|
||||||
title: '操作',
|
title: '操作',
|
||||||
width: 140,
|
width: 200,
|
||||||
fixed: 'right',
|
fixed: 'right',
|
||||||
render: (_, row) => (
|
render: (_, row) => (
|
||||||
<Space size={0}>
|
<Space size={0}>
|
||||||
<Button
|
<Button type="link" size="small" onClick={() => void openDetail(row)}>
|
||||||
type="link"
|
明细
|
||||||
size="small"
|
|
||||||
onClick={async () => {
|
|
||||||
setDetail(await request(`/admin/store-payouts/${row.id}`));
|
|
||||||
setDrawerOpen(true);
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
详情
|
|
||||||
</Button>
|
</Button>
|
||||||
{row.status === 'PENDING' && (
|
{row.kind === 'T1_BILL' && row.status === 'UNPAID' && (
|
||||||
<Button type="link" size="small" onClick={() => void confirmPayout(row.id)}>
|
<Button type="link" size="small" onClick={() => confirmPay([row.id], Number(row.amount))}>
|
||||||
确认打款
|
确认打款
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
|
{row.kind === 'WITHDRAW' && row.status === 'PENDING_REVIEW' && (
|
||||||
|
<>
|
||||||
|
<Button type="link" size="small" onClick={() => approveWithdraw(row.id)}>
|
||||||
|
通过
|
||||||
|
</Button>
|
||||||
|
<Button type="link" size="small" danger onClick={() => rejectWithdraw(row.id)}>
|
||||||
|
驳回
|
||||||
|
</Button>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
</Space>
|
</Space>
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
const withdrawDetailItems =
|
||||||
|
(detail?.items as Array<Record<string, unknown>> | undefined) ?? [];
|
||||||
|
const storeAccount = detail?.storeAccount as
|
||||||
|
| {
|
||||||
|
name?: string;
|
||||||
|
phone?: string;
|
||||||
|
bankAccountName?: string;
|
||||||
|
bankAccountNo?: string;
|
||||||
|
bankBranch?: string;
|
||||||
|
}
|
||||||
|
| undefined;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<Space direction="vertical" size={0} style={{ marginBottom: 16 }}>
|
<Space direction="vertical" size={0} style={{ marginBottom: 16 }}>
|
||||||
@@ -171,16 +339,21 @@ export default function StoreBillsPage() {
|
|||||||
门店账单
|
门店账单
|
||||||
</Typography.Title>
|
</Typography.Title>
|
||||||
<Typography.Text type="secondary">
|
<Typography.Text type="secondary">
|
||||||
T+1 结算:按日列出门店核销订单,应付 = 核销面额 × 门店核销比例
|
含 T+1 自动出账与门店手动提现;按类型筛选,详情与审核动作沿用原接口
|
||||||
</Typography.Text>
|
</Typography.Text>
|
||||||
|
{overdueSummary && overdueSummary.overdueCount > 0 ? (
|
||||||
|
<Typography.Text type="danger">
|
||||||
|
手动提现超时未审 {overdueSummary.overdueCount} 笔(待审共 {overdueSummary.pendingCount})
|
||||||
|
</Typography.Text>
|
||||||
|
) : null}
|
||||||
</Space>
|
</Space>
|
||||||
|
|
||||||
{summary && (
|
{summary && (
|
||||||
<Card size="small" style={{ marginBottom: 16 }}>
|
<Card size="small" style={{ marginBottom: 16 }}>
|
||||||
<Space size="large" wrap>
|
<Space size="large" wrap>
|
||||||
<Statistic title="明细笔数" value={summary.count} />
|
<Statistic title="记录数" value={summary.count} />
|
||||||
<Statistic title="核销面额合计" value={summary.redeemAmount ?? 0} prefix="¥" precision={2} />
|
<Statistic title="核销金额合计" value={summary.redeemAmount ?? 0} prefix="¥" precision={2} />
|
||||||
<Statistic title="应付门店合计" value={summary.payoutAmount ?? summary.totalAmount} prefix="¥" precision={2} />
|
<Statistic title="应付合计" value={summary.payoutAmount ?? summary.totalAmount ?? 0} prefix="¥" precision={2} />
|
||||||
</Space>
|
</Space>
|
||||||
</Card>
|
</Card>
|
||||||
)}
|
)}
|
||||||
@@ -189,20 +362,38 @@ export default function StoreBillsPage() {
|
|||||||
form={form}
|
form={form}
|
||||||
layout="inline"
|
layout="inline"
|
||||||
style={{ marginBottom: 16 }}
|
style={{ marginBottom: 16 }}
|
||||||
|
initialValues={{
|
||||||
|
kind: filters.kind || undefined,
|
||||||
|
status: filters.status || undefined,
|
||||||
|
storeId: filters.storeId || undefined,
|
||||||
|
}}
|
||||||
onFinish={(v: {
|
onFinish={(v: {
|
||||||
|
kind?: string;
|
||||||
storeId?: string;
|
storeId?: string;
|
||||||
status?: string;
|
status?: string;
|
||||||
dateRange?: [Dayjs, Dayjs];
|
range?: [Dayjs, Dayjs];
|
||||||
}) => {
|
}) => {
|
||||||
setFilters({
|
setFilters({
|
||||||
|
kind: v.kind || '',
|
||||||
storeId: v.storeId || '',
|
storeId: v.storeId || '',
|
||||||
status: v.status || '',
|
status: v.status || '',
|
||||||
dateFrom: v.dateRange?.[0]?.format('YYYY-MM-DD') || '',
|
dateFrom: v.range?.[0] ? v.range[0].format('YYYY-MM-DD') : '',
|
||||||
dateTo: v.dateRange?.[1]?.format('YYYY-MM-DD') || '',
|
dateTo: v.range?.[1] ? v.range[1].format('YYYY-MM-DD') : '',
|
||||||
});
|
});
|
||||||
setPage(1);
|
setPage(1);
|
||||||
|
setSelectedKeys([]);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
<Form.Item name="kind" label="类型">
|
||||||
|
<Select
|
||||||
|
allowClear
|
||||||
|
style={{ width: 140 }}
|
||||||
|
options={Object.entries(STORE_SETTLEMENT_KIND_LABELS).map(([value, label]) => ({
|
||||||
|
value,
|
||||||
|
label,
|
||||||
|
}))}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
<Form.Item name="storeId" label="门店">
|
<Form.Item name="storeId" label="门店">
|
||||||
<Select
|
<Select
|
||||||
allowClear
|
allowClear
|
||||||
@@ -210,21 +401,23 @@ export default function StoreBillsPage() {
|
|||||||
placeholder="全部门店"
|
placeholder="全部门店"
|
||||||
style={{ width: 200 }}
|
style={{ width: 200 }}
|
||||||
optionFilterProp="label"
|
optionFilterProp="label"
|
||||||
options={stores.map((s) => ({
|
options={stores.map((s) => ({ value: s.id, label: s.name || s.phone || s.id }))}
|
||||||
value: s.id,
|
|
||||||
label: `${s.name}(${s.phone})`,
|
|
||||||
}))}
|
|
||||||
/>
|
/>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item name="status" label="打款状态">
|
<Form.Item name="status" label="状态">
|
||||||
<Select
|
<Select
|
||||||
allowClear
|
allowClear
|
||||||
style={{ width: 120 }}
|
style={{ width: 120 }}
|
||||||
placeholder="全部"
|
options={Object.entries(STORE_SETTLEMENT_STATUS_LABELS).map(([value, label]) => ({
|
||||||
options={Object.entries(PAYOUT_STATUS_LABELS).map(([value, label]) => ({ value, label }))}
|
value,
|
||||||
|
label:
|
||||||
|
value === 'PAID'
|
||||||
|
? '已打款/已结算'
|
||||||
|
: label,
|
||||||
|
}))}
|
||||||
/>
|
/>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item name="dateRange" label="核销日期">
|
<Form.Item name="range" label="日期">
|
||||||
<DatePicker.RangePicker />
|
<DatePicker.RangePicker />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item>
|
<Form.Item>
|
||||||
@@ -238,6 +431,7 @@ export default function StoreBillsPage() {
|
|||||||
form.resetFields();
|
form.resetFields();
|
||||||
setFilters({});
|
setFilters({});
|
||||||
setPage(1);
|
setPage(1);
|
||||||
|
setSelectedKeys([]);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
重置
|
重置
|
||||||
@@ -245,17 +439,35 @@ export default function StoreBillsPage() {
|
|||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item>
|
<Form.Item>
|
||||||
<Button loading={exporting} onClick={() => void exportExcel()}>
|
<Button loading={exporting} onClick={() => void exportExcel()}>
|
||||||
导出 Excel
|
导出 T+1 Excel
|
||||||
|
</Button>
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item>
|
||||||
|
<Button
|
||||||
|
type="primary"
|
||||||
|
disabled={!selectedRows.length}
|
||||||
|
loading={batchLoading}
|
||||||
|
onClick={() => confirmPay(selectedRows.map((r) => r.id), selectedAmount)}
|
||||||
|
>
|
||||||
|
批量确认打款 ({selectedRows.length})
|
||||||
</Button>
|
</Button>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
</Form>
|
</Form>
|
||||||
|
|
||||||
<Table
|
<Table
|
||||||
rowKey="id"
|
rowKey={(r) => `${r.kind}-${r.id}`}
|
||||||
className="admin-table-nowrap"
|
className="admin-table-nowrap"
|
||||||
loading={loading}
|
loading={loading}
|
||||||
columns={columns}
|
columns={columns}
|
||||||
dataSource={data?.items ?? []}
|
dataSource={data?.items ?? []}
|
||||||
|
rowClassName={(row) => (row.overdue ? 'ant-table-row-selected' : '')}
|
||||||
|
rowSelection={{
|
||||||
|
selectedRowKeys: selectedKeys,
|
||||||
|
onChange: setSelectedKeys,
|
||||||
|
getCheckboxProps: (r) => ({
|
||||||
|
disabled: !(r.kind === 'T1_BILL' && r.status === 'UNPAID'),
|
||||||
|
}),
|
||||||
|
}}
|
||||||
scroll={{ x: 1300 }}
|
scroll={{ x: 1300 }}
|
||||||
pagination={{
|
pagination={{
|
||||||
current: page,
|
current: page,
|
||||||
@@ -269,28 +481,133 @@ export default function StoreBillsPage() {
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Drawer title="账单详情" width={520} open={drawerOpen} onClose={() => setDrawerOpen(false)}>
|
<Drawer
|
||||||
{detail && (
|
title={detailKind === 'WITHDRAW' ? '手动提现明细' : 'T+1 对账单明细'}
|
||||||
<Descriptions column={1} bordered size="small">
|
open={drawerOpen}
|
||||||
<Descriptions.Item label="门店">
|
onClose={() => setDrawerOpen(false)}
|
||||||
{String((detail.store as { name?: string })?.name ?? '—')}
|
width={detailKind === 'WITHDRAW' ? 640 : 520}
|
||||||
</Descriptions.Item>
|
>
|
||||||
<Descriptions.Item label="核销单号">
|
{detail && detailKind === 'T1_BILL' && (
|
||||||
{String((detail.redeemRecord as { redeemNo?: string })?.redeemNo ?? '—')}
|
<>
|
||||||
</Descriptions.Item>
|
<Descriptions column={1} size="small" bordered>
|
||||||
<Descriptions.Item label="核销面额">¥{String(detail.redeemAmount)}</Descriptions.Item>
|
<Descriptions.Item label="账单号">{String(detail.billNo)}</Descriptions.Item>
|
||||||
<Descriptions.Item label="应付金额">¥{String(detail.payoutAmount)}</Descriptions.Item>
|
<Descriptions.Item label="账单日">
|
||||||
<Descriptions.Item label="结算比例">
|
{String(detail.billDate || '').slice(0, 10)}
|
||||||
{detail.settlementRate ? `${Math.round(Number(detail.settlementRate) * 100)}%` : '—'}
|
</Descriptions.Item>
|
||||||
</Descriptions.Item>
|
<Descriptions.Item label="应付">
|
||||||
<Descriptions.Item label="状态">
|
¥{Number(detail.payoutAmount ?? 0).toFixed(2)}
|
||||||
{PAYOUT_STATUS_LABELS[String(detail.status)] || String(detail.status)}
|
</Descriptions.Item>
|
||||||
</Descriptions.Item>
|
<Descriptions.Item label="状态">
|
||||||
<Descriptions.Item label="预计打款">{fmtTime(String(detail.expectedPayAt))}</Descriptions.Item>
|
{storeSettlementStatusLabel('T1_BILL', String(detail.status))}
|
||||||
<Descriptions.Item label="实际打款">
|
</Descriptions.Item>
|
||||||
{detail.paidAt ? fmtTime(String(detail.paidAt)) : '—'}
|
<Descriptions.Item label="打款时间">
|
||||||
</Descriptions.Item>
|
{detail.paidAt ? fmtTime(String(detail.paidAt)) : '—'}
|
||||||
</Descriptions>
|
</Descriptions.Item>
|
||||||
|
</Descriptions>
|
||||||
|
<Typography.Title level={5} style={{ marginTop: 16 }}>
|
||||||
|
核销明细
|
||||||
|
</Typography.Title>
|
||||||
|
<Table
|
||||||
|
size="small"
|
||||||
|
rowKey="id"
|
||||||
|
pagination={false}
|
||||||
|
dataSource={(detail.payouts as Array<Record<string, unknown>>) || []}
|
||||||
|
columns={[
|
||||||
|
{
|
||||||
|
title: '核销单号',
|
||||||
|
render: (_, r) =>
|
||||||
|
String((r.redeemRecord as { redeemNo?: string })?.redeemNo || '—'),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '金额',
|
||||||
|
dataIndex: 'payoutAmount',
|
||||||
|
render: (v) => `¥${Number(v).toFixed(2)}`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '状态',
|
||||||
|
dataIndex: 'status',
|
||||||
|
render: (s) => (s === 'PAID' ? '已打款' : '未打款'),
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
{detail && detailKind === 'WITHDRAW' && (
|
||||||
|
<>
|
||||||
|
<Descriptions column={1} size="small" bordered>
|
||||||
|
<Descriptions.Item label="提现单号">{String(detail.withdrawNo)}</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="金额">
|
||||||
|
¥{Number(detail.amount ?? 0).toFixed(2)}
|
||||||
|
</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="状态">
|
||||||
|
{storeSettlementStatusLabel('WITHDRAW', String(detail.status))}
|
||||||
|
</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="申请时间">
|
||||||
|
{detail.appliedAt ? fmtTime(String(detail.appliedAt)) : '—'}
|
||||||
|
</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="驳回理由">
|
||||||
|
{detail.rejectReason ? String(detail.rejectReason) : '—'}
|
||||||
|
</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="打款凭证">
|
||||||
|
{detail.paymentRef ? String(detail.paymentRef) : '—'}
|
||||||
|
</Descriptions.Item>
|
||||||
|
</Descriptions>
|
||||||
|
{storeAccount ? (
|
||||||
|
<>
|
||||||
|
<Typography.Title level={5} style={{ marginTop: 16 }}>
|
||||||
|
收款账户
|
||||||
|
</Typography.Title>
|
||||||
|
<Descriptions column={1} size="small" bordered>
|
||||||
|
<Descriptions.Item label="户名">
|
||||||
|
{storeAccount.bankAccountName || '—'}
|
||||||
|
</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="账号">
|
||||||
|
{storeAccount.bankAccountNo || '—'}
|
||||||
|
</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="开户行">
|
||||||
|
{storeAccount.bankBranch || '—'}
|
||||||
|
</Descriptions.Item>
|
||||||
|
</Descriptions>
|
||||||
|
</>
|
||||||
|
) : null}
|
||||||
|
<Typography.Title level={5} style={{ marginTop: 16 }}>
|
||||||
|
提现明细
|
||||||
|
</Typography.Title>
|
||||||
|
<Table
|
||||||
|
size="small"
|
||||||
|
rowKey="id"
|
||||||
|
pagination={false}
|
||||||
|
dataSource={withdrawDetailItems}
|
||||||
|
columns={[
|
||||||
|
{
|
||||||
|
title: '核销单号',
|
||||||
|
render: (_, r) => {
|
||||||
|
const payout = r.storePayout as
|
||||||
|
| { redeemRecord?: { redeemNo?: string }; payoutAmount?: number }
|
||||||
|
| undefined;
|
||||||
|
return String(payout?.redeemRecord?.redeemNo || '—');
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '应付',
|
||||||
|
render: (_, r) => {
|
||||||
|
const payout = r.storePayout as { payoutAmount?: number } | undefined;
|
||||||
|
return `¥${Number(payout?.payoutAmount ?? 0).toFixed(2)}`;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
{String(detail.status) === 'PENDING_REVIEW' ? (
|
||||||
|
<Space style={{ marginTop: 16 }}>
|
||||||
|
<Button type="primary" onClick={() => approveWithdraw(String(detail.id))}>
|
||||||
|
通过
|
||||||
|
</Button>
|
||||||
|
<Button danger onClick={() => rejectWithdraw(String(detail.id))}>
|
||||||
|
驳回
|
||||||
|
</Button>
|
||||||
|
</Space>
|
||||||
|
) : null}
|
||||||
|
</>
|
||||||
)}
|
)}
|
||||||
</Drawer>
|
</Drawer>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -0,0 +1,233 @@
|
|||||||
|
import { useEffect, useMemo, useState } from 'react';
|
||||||
|
import {
|
||||||
|
Button, Form, Input, InputNumber, Modal, Popconfirm, Select, Space, Table, Tag, Typography, message,
|
||||||
|
} from 'antd';
|
||||||
|
import type { ColumnsType } from 'antd/es/table';
|
||||||
|
import { request } from '../lib/api';
|
||||||
|
|
||||||
|
type CategoryNode = {
|
||||||
|
id: string;
|
||||||
|
code: string;
|
||||||
|
name: string;
|
||||||
|
sort: number;
|
||||||
|
parentId: string | null;
|
||||||
|
status: string;
|
||||||
|
children?: CategoryNode[];
|
||||||
|
};
|
||||||
|
|
||||||
|
type FlatRow = CategoryNode & { level: 1 | 2; parentName?: string };
|
||||||
|
|
||||||
|
function flattenTree(tree: CategoryNode[]): FlatRow[] {
|
||||||
|
const rows: FlatRow[] = [];
|
||||||
|
for (const root of tree) {
|
||||||
|
rows.push({ ...root, level: 1, children: undefined });
|
||||||
|
for (const child of root.children ?? []) {
|
||||||
|
rows.push({
|
||||||
|
...child,
|
||||||
|
level: 2,
|
||||||
|
parentName: root.name,
|
||||||
|
children: undefined,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return rows;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function StoreCategoriesPage() {
|
||||||
|
const [tree, setTree] = useState<CategoryNode[]>([]);
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
const [modalOpen, setModalOpen] = useState(false);
|
||||||
|
const [editing, setEditing] = useState<FlatRow | null>(null);
|
||||||
|
const [form] = Form.useForm();
|
||||||
|
|
||||||
|
const rows = useMemo(() => flattenTree(tree), [tree]);
|
||||||
|
const rootOptions = useMemo(
|
||||||
|
() => tree.filter((n) => n.status === 'ACTIVE').map((n) => ({ value: n.id, label: n.name })),
|
||||||
|
[tree],
|
||||||
|
);
|
||||||
|
|
||||||
|
async function reload() {
|
||||||
|
setLoading(true);
|
||||||
|
try {
|
||||||
|
const data = await request<CategoryNode[]>('/admin/store-categories');
|
||||||
|
setTree(Array.isArray(data) ? data : []);
|
||||||
|
} catch (e) {
|
||||||
|
message.error(e instanceof Error ? e.message : '加载失败');
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
void reload();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
function openCreate(parentId?: string) {
|
||||||
|
setEditing(null);
|
||||||
|
form.setFieldsValue({
|
||||||
|
code: '',
|
||||||
|
name: '',
|
||||||
|
sort: 0,
|
||||||
|
parentId: parentId || undefined,
|
||||||
|
status: 'ACTIVE',
|
||||||
|
});
|
||||||
|
setModalOpen(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
function openEdit(row: FlatRow) {
|
||||||
|
setEditing(row);
|
||||||
|
form.setFieldsValue({
|
||||||
|
code: row.code,
|
||||||
|
name: row.name,
|
||||||
|
sort: row.sort,
|
||||||
|
parentId: row.parentId || undefined,
|
||||||
|
status: row.status,
|
||||||
|
});
|
||||||
|
setModalOpen(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function submit() {
|
||||||
|
const values = await form.validateFields();
|
||||||
|
const payload = {
|
||||||
|
code: String(values.code).trim().toUpperCase(),
|
||||||
|
name: String(values.name).trim(),
|
||||||
|
sort: Number(values.sort ?? 0),
|
||||||
|
parentId: values.parentId || null,
|
||||||
|
status: values.status || 'ACTIVE',
|
||||||
|
};
|
||||||
|
if (editing) {
|
||||||
|
await request(`/admin/store-categories/${editing.id}`, {
|
||||||
|
method: 'PUT',
|
||||||
|
body: JSON.stringify(payload),
|
||||||
|
});
|
||||||
|
message.success('已保存');
|
||||||
|
} else {
|
||||||
|
await request('/admin/store-categories', {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify(payload),
|
||||||
|
});
|
||||||
|
message.success('已创建');
|
||||||
|
}
|
||||||
|
setModalOpen(false);
|
||||||
|
void reload();
|
||||||
|
}
|
||||||
|
|
||||||
|
const columns: ColumnsType<FlatRow> = [
|
||||||
|
{
|
||||||
|
title: '层级',
|
||||||
|
dataIndex: 'level',
|
||||||
|
width: 80,
|
||||||
|
render: (level) => (level === 1 ? <Tag color="blue">一级</Tag> : <Tag>二级</Tag>),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '名称',
|
||||||
|
dataIndex: 'name',
|
||||||
|
render: (name, row) => (
|
||||||
|
<span style={{ paddingLeft: row.level === 2 ? 24 : 0 }}>
|
||||||
|
{row.level === 2 ? `${row.parentName || ''} / ` : ''}
|
||||||
|
{name}
|
||||||
|
</span>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{ title: '编码', dataIndex: 'code', width: 140 },
|
||||||
|
{ title: '排序', dataIndex: 'sort', width: 80 },
|
||||||
|
{
|
||||||
|
title: '状态',
|
||||||
|
dataIndex: 'status',
|
||||||
|
width: 90,
|
||||||
|
render: (s) => (
|
||||||
|
<Tag color={s === 'ACTIVE' ? 'green' : 'default'}>{s === 'ACTIVE' ? '启用' : '停用'}</Tag>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '操作',
|
||||||
|
width: 220,
|
||||||
|
render: (_, row) => (
|
||||||
|
<Space wrap>
|
||||||
|
<Button type="link" size="small" onClick={() => openEdit(row)}>编辑</Button>
|
||||||
|
{row.level === 1 ? (
|
||||||
|
<Button type="link" size="small" onClick={() => openCreate(row.id)}>加二级</Button>
|
||||||
|
) : null}
|
||||||
|
<Popconfirm
|
||||||
|
title={row.level === 1 ? '删除一级分类?若有门店占用将改为停用' : '删除该分类?若有门店占用将改为停用'}
|
||||||
|
onConfirm={async () => {
|
||||||
|
await request(`/admin/store-categories/${row.id}`, { method: 'DELETE' });
|
||||||
|
message.success('已处理');
|
||||||
|
void reload();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Button type="link" size="small" danger>删除</Button>
|
||||||
|
</Popconfirm>
|
||||||
|
</Space>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<Space style={{ marginBottom: 16, width: '100%', justifyContent: 'space-between' }}>
|
||||||
|
<Space direction="vertical" size={0}>
|
||||||
|
<Typography.Title level={4} style={{ margin: 0 }}>门店分类</Typography.Title>
|
||||||
|
<Typography.Text type="secondary">两级分类:一级(餐饮/住宿/娱乐)→ 二级业态,供合伙人开店选择</Typography.Text>
|
||||||
|
</Space>
|
||||||
|
<Space>
|
||||||
|
<Button
|
||||||
|
onClick={async () => {
|
||||||
|
await request('/admin/store-categories/ensure-defaults', { method: 'POST' });
|
||||||
|
message.success('已同步默认分类');
|
||||||
|
void reload();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
同步默认分类
|
||||||
|
</Button>
|
||||||
|
<Button type="primary" onClick={() => openCreate()}>新增一级</Button>
|
||||||
|
</Space>
|
||||||
|
</Space>
|
||||||
|
|
||||||
|
<Table
|
||||||
|
rowKey="id"
|
||||||
|
loading={loading}
|
||||||
|
columns={columns}
|
||||||
|
dataSource={rows}
|
||||||
|
pagination={false}
|
||||||
|
className="admin-table-nowrap"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Modal
|
||||||
|
title={editing ? '编辑分类' : '新增分类'}
|
||||||
|
open={modalOpen}
|
||||||
|
onCancel={() => setModalOpen(false)}
|
||||||
|
onOk={() => void submit()}
|
||||||
|
destroyOnClose
|
||||||
|
>
|
||||||
|
<Form form={form} layout="vertical">
|
||||||
|
<Form.Item name="code" label="编码" rules={[{ required: true, message: '请填写编码' }]}>
|
||||||
|
<Input placeholder="如 DINING / HOTPOT" disabled={!!editing} />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="name" label="名称" rules={[{ required: true, message: '请填写名称' }]}>
|
||||||
|
<Input placeholder="分类名称" />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="parentId" label="上级分类(空=一级)">
|
||||||
|
<Select
|
||||||
|
allowClear
|
||||||
|
placeholder="不选则为一级分类"
|
||||||
|
options={rootOptions.filter((o) => o.value !== editing?.id)}
|
||||||
|
disabled={editing?.level === 1 && (tree.find((t) => t.id === editing.id)?.children?.length ?? 0) > 0}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="sort" label="排序" initialValue={0}>
|
||||||
|
<InputNumber style={{ width: '100%' }} />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="status" label="状态" initialValue="ACTIVE">
|
||||||
|
<Select
|
||||||
|
options={[
|
||||||
|
{ value: 'ACTIVE', label: '启用' },
|
||||||
|
{ value: 'DISABLED', label: '停用' },
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
</Form>
|
||||||
|
</Modal>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,600 @@
|
|||||||
|
import { useEffect, useState } from 'react';
|
||||||
|
import { useSearchParams } from 'react-router-dom';
|
||||||
|
import {
|
||||||
|
Badge,
|
||||||
|
Button,
|
||||||
|
Descriptions,
|
||||||
|
Drawer,
|
||||||
|
Image,
|
||||||
|
Input,
|
||||||
|
Modal,
|
||||||
|
Space,
|
||||||
|
Table,
|
||||||
|
Tabs,
|
||||||
|
Tag,
|
||||||
|
Typography,
|
||||||
|
message,
|
||||||
|
} from 'antd';
|
||||||
|
import type { ColumnsType } from 'antd/es/table';
|
||||||
|
import type {
|
||||||
|
StoreInfoChangeFieldDiff,
|
||||||
|
StoreInfoChangeRequestDto,
|
||||||
|
StoreInfoChangeStatus,
|
||||||
|
StorePackageAuditSummaryDto,
|
||||||
|
StorePackageChangeRequestDto,
|
||||||
|
StorePackageChangeStatus,
|
||||||
|
} from '@dukang/shared-types';
|
||||||
|
import {
|
||||||
|
STORE_INFO_CHANGE_STATUS_LABELS,
|
||||||
|
STORE_INFO_CHANGEABLE_FIELD_LABELS,
|
||||||
|
} from '@dukang/shared-types';
|
||||||
|
import { request, type Paginated } from '../lib/api';
|
||||||
|
import { notifyPackageAuditChanged } from '../lib/admin-events';
|
||||||
|
import { fmtTime } from '../lib/constants';
|
||||||
|
import StorePackageAuditPanel from '../components/StorePackageAuditPanel';
|
||||||
|
|
||||||
|
const HQ_PACKAGE_STATUS_LABELS: Record<StorePackageChangeStatus, string> = {
|
||||||
|
PENDING: '待审核',
|
||||||
|
APPROVED: '已通过',
|
||||||
|
REJECTED: '已驳回',
|
||||||
|
};
|
||||||
|
|
||||||
|
function fmtFieldValue(field: string, v: unknown): string {
|
||||||
|
if (v == null || String(v).trim() === '') return '(空)';
|
||||||
|
if (field === 'avgPrice' || field === 'latitude' || field === 'longitude') {
|
||||||
|
return String(v);
|
||||||
|
}
|
||||||
|
if (field === 'envPhotoUrls' && Array.isArray(v)) {
|
||||||
|
return `${v.length} 张`;
|
||||||
|
}
|
||||||
|
if (field === 'coverUrl') return '见对比图';
|
||||||
|
return String(v);
|
||||||
|
}
|
||||||
|
|
||||||
|
function InfoChangeImageDiff({
|
||||||
|
field,
|
||||||
|
live,
|
||||||
|
proposed,
|
||||||
|
}: {
|
||||||
|
field: string;
|
||||||
|
live: unknown;
|
||||||
|
proposed: unknown;
|
||||||
|
}) {
|
||||||
|
const liveUrls =
|
||||||
|
field === 'coverUrl'
|
||||||
|
? [String(live || '').trim()].filter(Boolean)
|
||||||
|
: Array.isArray(live)
|
||||||
|
? live.map((u) => String(u || '').trim()).filter(Boolean)
|
||||||
|
: [];
|
||||||
|
const proposedUrls =
|
||||||
|
field === 'coverUrl'
|
||||||
|
? [String(proposed || '').trim()].filter(Boolean)
|
||||||
|
: Array.isArray(proposed)
|
||||||
|
? proposed.map((u) => String(u || '').trim()).filter(Boolean)
|
||||||
|
: [];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div style={{ display: 'flex', gap: 16, flexWrap: 'wrap' }}>
|
||||||
|
<div>
|
||||||
|
<Typography.Text type="secondary" style={{ display: 'block', marginBottom: 6 }}>
|
||||||
|
变更前
|
||||||
|
</Typography.Text>
|
||||||
|
{liveUrls.length ? (
|
||||||
|
<Image.PreviewGroup>
|
||||||
|
<Space wrap size={8}>
|
||||||
|
{liveUrls.map((url) => (
|
||||||
|
<Image key={`live-${url}`} src={url} width={72} height={72} style={{ objectFit: 'cover', borderRadius: 4 }} />
|
||||||
|
))}
|
||||||
|
</Space>
|
||||||
|
</Image.PreviewGroup>
|
||||||
|
) : (
|
||||||
|
<Typography.Text type="secondary">(空)</Typography.Text>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<Typography.Text type="secondary" style={{ display: 'block', marginBottom: 6 }}>
|
||||||
|
变更后
|
||||||
|
</Typography.Text>
|
||||||
|
{proposedUrls.length ? (
|
||||||
|
<Image.PreviewGroup>
|
||||||
|
<Space wrap size={8}>
|
||||||
|
{proposedUrls.map((url) => (
|
||||||
|
<Image key={`new-${url}`} src={url} width={72} height={72} style={{ objectFit: 'cover', borderRadius: 4 }} />
|
||||||
|
))}
|
||||||
|
</Space>
|
||||||
|
</Image.PreviewGroup>
|
||||||
|
) : (
|
||||||
|
<Typography.Text type="secondary">(空)</Typography.Text>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function InfoChangeAuditPanel({
|
||||||
|
initialRequestId,
|
||||||
|
}: {
|
||||||
|
initialRequestId?: string | null;
|
||||||
|
}) {
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
const [items, setItems] = useState<StoreInfoChangeRequestDto[]>([]);
|
||||||
|
const [total, setTotal] = useState(0);
|
||||||
|
const [page, setPage] = useState(1);
|
||||||
|
const [status, setStatus] = useState<string>('PENDING');
|
||||||
|
const [pendingCount, setPendingCount] = useState(0);
|
||||||
|
const [detailOpen, setDetailOpen] = useState(false);
|
||||||
|
const [detailLoading, setDetailLoading] = useState(false);
|
||||||
|
const [detail, setDetail] = useState<(StoreInfoChangeRequestDto & { diffs?: StoreInfoChangeFieldDiff[] }) | null>(null);
|
||||||
|
const [rejectOpen, setRejectOpen] = useState(false);
|
||||||
|
const [rejectReason, setRejectReason] = useState('');
|
||||||
|
const [activeId, setActiveId] = useState<string | null>(null);
|
||||||
|
|
||||||
|
async function reload(nextPage = page, nextStatus = status) {
|
||||||
|
setLoading(true);
|
||||||
|
try {
|
||||||
|
const qs = new URLSearchParams({ page: String(nextPage), pageSize: '20' });
|
||||||
|
if (nextStatus) qs.set('status', nextStatus);
|
||||||
|
const [data, summary] = await Promise.all([
|
||||||
|
request<{ items: StoreInfoChangeRequestDto[]; total: number; page?: number }>(
|
||||||
|
`/admin/store-info-change-requests?${qs}`,
|
||||||
|
),
|
||||||
|
request<{ pendingCount: number }>('/admin/store-info-change-requests/summary'),
|
||||||
|
]);
|
||||||
|
setItems(data.items);
|
||||||
|
setTotal(data.total);
|
||||||
|
setPage(data.page ?? nextPage);
|
||||||
|
setPendingCount(summary.pendingCount ?? 0);
|
||||||
|
} catch (e) {
|
||||||
|
message.error(e instanceof Error ? e.message : '加载失败');
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
void reload(1, status);
|
||||||
|
}, [status]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (initialRequestId) void openDetail(initialRequestId);
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
async function openDetail(id: string) {
|
||||||
|
setDetailOpen(true);
|
||||||
|
setDetailLoading(true);
|
||||||
|
setDetail(null);
|
||||||
|
try {
|
||||||
|
const data = await request<StoreInfoChangeRequestDto & { diffs?: StoreInfoChangeFieldDiff[] }>(
|
||||||
|
`/admin/store-info-change-requests/${id}`,
|
||||||
|
);
|
||||||
|
setDetail(data);
|
||||||
|
} catch (e) {
|
||||||
|
message.error(e instanceof Error ? e.message : '加载详情失败');
|
||||||
|
setDetailOpen(false);
|
||||||
|
} finally {
|
||||||
|
setDetailLoading(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function audit(id: string, action: 'APPROVE' | 'REJECT', reason?: string) {
|
||||||
|
try {
|
||||||
|
await request(`/admin/store-info-change-requests/${id}/audit`, {
|
||||||
|
method: 'PUT',
|
||||||
|
body: JSON.stringify(
|
||||||
|
action === 'REJECT' ? { action, rejectReason: reason } : { action },
|
||||||
|
),
|
||||||
|
});
|
||||||
|
message.success(action === 'APPROVE' ? '已通过' : '已驳回');
|
||||||
|
setDetailOpen(false);
|
||||||
|
notifyPackageAuditChanged();
|
||||||
|
void reload(page, status);
|
||||||
|
} catch (e) {
|
||||||
|
message.error(e instanceof Error ? e.message : '操作失败');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const columns: ColumnsType<StoreInfoChangeRequestDto> = [
|
||||||
|
{ title: '门店', dataIndex: 'storeName', render: (_, row) => row.storeName || row.storeId },
|
||||||
|
{
|
||||||
|
title: '状态',
|
||||||
|
dataIndex: 'status',
|
||||||
|
render: (v: StoreInfoChangeStatus) => (
|
||||||
|
<Tag>{STORE_INFO_CHANGE_STATUS_LABELS[v] ?? v}</Tag>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '变更字段',
|
||||||
|
render: (_, row) =>
|
||||||
|
row.changedFields?.length
|
||||||
|
? row.changedFields.map((f) => (
|
||||||
|
<Tag key={f}>{STORE_INFO_CHANGEABLE_FIELD_LABELS[f as keyof typeof STORE_INFO_CHANGEABLE_FIELD_LABELS] ?? f}</Tag>
|
||||||
|
))
|
||||||
|
: '—',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '提交方',
|
||||||
|
render: (_, row) =>
|
||||||
|
row.submitterType === 'PARTNER' ? '合伙人' : row.submitterType === 'SHOP' ? '门店' : '总部',
|
||||||
|
},
|
||||||
|
{ title: '提交时间', dataIndex: 'createdAt', render: (v) => fmtTime(String(v)) },
|
||||||
|
{
|
||||||
|
title: '操作',
|
||||||
|
render: (_, row) => (
|
||||||
|
<Space>
|
||||||
|
<Button type="link" onClick={() => void openDetail(row.id)}>
|
||||||
|
查看
|
||||||
|
</Button>
|
||||||
|
{row.status === 'PENDING' ? (
|
||||||
|
<>
|
||||||
|
<Button type="link" onClick={() => void audit(row.id, 'APPROVE')}>
|
||||||
|
通过
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
type="link"
|
||||||
|
danger
|
||||||
|
onClick={() => {
|
||||||
|
setActiveId(row.id);
|
||||||
|
setRejectReason('');
|
||||||
|
setRejectOpen(true);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
驳回
|
||||||
|
</Button>
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
row.rejectReason || null
|
||||||
|
)}
|
||||||
|
</Space>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<Space style={{ marginBottom: 16 }}>
|
||||||
|
{(['PENDING', 'APPROVED', 'REJECTED', ''] as const).map((s) => (
|
||||||
|
<Button
|
||||||
|
key={s || 'all'}
|
||||||
|
type={status === s ? 'primary' : 'default'}
|
||||||
|
onClick={() => setStatus(s)}
|
||||||
|
>
|
||||||
|
{s === 'PENDING' ? (
|
||||||
|
<Badge count={pendingCount} size="small" offset={[8, -2]}>
|
||||||
|
{STORE_INFO_CHANGE_STATUS_LABELS.PENDING}
|
||||||
|
</Badge>
|
||||||
|
) : s ? (
|
||||||
|
STORE_INFO_CHANGE_STATUS_LABELS[s]
|
||||||
|
) : (
|
||||||
|
'全部'
|
||||||
|
)}
|
||||||
|
</Button>
|
||||||
|
))}
|
||||||
|
</Space>
|
||||||
|
<Table
|
||||||
|
rowKey="id"
|
||||||
|
loading={loading}
|
||||||
|
columns={columns}
|
||||||
|
dataSource={items}
|
||||||
|
pagination={{
|
||||||
|
current: page,
|
||||||
|
total,
|
||||||
|
pageSize: 20,
|
||||||
|
onChange: (p) => void reload(p, status),
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Drawer
|
||||||
|
title={detail ? `${detail.storeName || detail.storeId} · 信息变更` : '信息变更详情'}
|
||||||
|
width={680}
|
||||||
|
open={detailOpen}
|
||||||
|
onClose={() => setDetailOpen(false)}
|
||||||
|
extra={
|
||||||
|
detail?.status === 'PENDING' ? (
|
||||||
|
<Space>
|
||||||
|
<Button onClick={() => void audit(detail.id, 'APPROVE')}>通过</Button>
|
||||||
|
<Button
|
||||||
|
danger
|
||||||
|
onClick={() => {
|
||||||
|
setActiveId(detail.id);
|
||||||
|
setRejectReason('');
|
||||||
|
setRejectOpen(true);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
驳回
|
||||||
|
</Button>
|
||||||
|
</Space>
|
||||||
|
) : null
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{detailLoading ? (
|
||||||
|
<Typography.Text type="secondary">加载中…</Typography.Text>
|
||||||
|
) : detail ? (
|
||||||
|
<>
|
||||||
|
<Space style={{ marginBottom: 16 }} wrap>
|
||||||
|
<Tag>{STORE_INFO_CHANGE_STATUS_LABELS[detail.status]}</Tag>
|
||||||
|
<Typography.Text type="secondary">
|
||||||
|
提交方:{detail.submitterType === 'PARTNER' ? '合伙人' : detail.submitterType === 'SHOP' ? '门店' : '总部'} · {fmtTime(detail.createdAt)}
|
||||||
|
</Typography.Text>
|
||||||
|
</Space>
|
||||||
|
{detail.rejectReason ? (
|
||||||
|
<Typography.Paragraph type="danger">驳回原因:{detail.rejectReason}</Typography.Paragraph>
|
||||||
|
) : null}
|
||||||
|
{detail.diffs && detail.diffs.length ? (
|
||||||
|
<Descriptions column={1} bordered size="small">
|
||||||
|
{detail.diffs.map((d) => (
|
||||||
|
<Descriptions.Item
|
||||||
|
key={d.field}
|
||||||
|
label={STORE_INFO_CHANGEABLE_FIELD_LABELS[d.field] ?? d.field}
|
||||||
|
>
|
||||||
|
{d.field === 'coverUrl' || d.field === 'envPhotoUrls' ? (
|
||||||
|
<InfoChangeImageDiff field={d.field} live={d.live} proposed={d.proposed} />
|
||||||
|
) : (
|
||||||
|
<span>
|
||||||
|
<Typography.Text delete type="secondary">
|
||||||
|
{fmtFieldValue(d.field, d.live)}
|
||||||
|
</Typography.Text>
|
||||||
|
<Typography.Text type="secondary"> → </Typography.Text>
|
||||||
|
<Typography.Text strong>
|
||||||
|
{fmtFieldValue(d.field, d.proposed)}
|
||||||
|
</Typography.Text>
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</Descriptions.Item>
|
||||||
|
))}
|
||||||
|
</Descriptions>
|
||||||
|
) : (
|
||||||
|
<Typography.Text type="secondary">无变更字段明细</Typography.Text>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
) : null}
|
||||||
|
</Drawer>
|
||||||
|
|
||||||
|
<Modal
|
||||||
|
title="驳回信息变更"
|
||||||
|
open={rejectOpen}
|
||||||
|
onCancel={() => setRejectOpen(false)}
|
||||||
|
onOk={() => {
|
||||||
|
if (!activeId) return;
|
||||||
|
if (!rejectReason.trim()) {
|
||||||
|
message.warning('请填写驳回原因');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
void audit(activeId, 'REJECT', rejectReason.trim());
|
||||||
|
setRejectOpen(false);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Input.TextArea
|
||||||
|
rows={3}
|
||||||
|
value={rejectReason}
|
||||||
|
placeholder="驳回原因"
|
||||||
|
onChange={(e) => setRejectReason(e.target.value)}
|
||||||
|
/>
|
||||||
|
</Modal>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function StorePackageAuditsPage() {
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
const [items, setItems] = useState<StorePackageChangeRequestDto[]>([]);
|
||||||
|
const [total, setTotal] = useState(0);
|
||||||
|
const [page, setPage] = useState(1);
|
||||||
|
const [status, setStatus] = useState<string>('PENDING');
|
||||||
|
const [pendingCount, setPendingCount] = useState(0);
|
||||||
|
const [rejectOpen, setRejectOpen] = useState(false);
|
||||||
|
const [rejectReason, setRejectReason] = useState('');
|
||||||
|
const [activeId, setActiveId] = useState<string | null>(null);
|
||||||
|
const [detailOpen, setDetailOpen] = useState(false);
|
||||||
|
const [activeRequestId, setActiveRequestId] = useState<string | null>(null);
|
||||||
|
const [drawerTitle, setDrawerTitle] = useState('套餐变更详情');
|
||||||
|
|
||||||
|
async function reload(nextPage = page, nextStatus = status) {
|
||||||
|
setLoading(true);
|
||||||
|
try {
|
||||||
|
const qs = new URLSearchParams({
|
||||||
|
page: String(nextPage),
|
||||||
|
pageSize: '20',
|
||||||
|
});
|
||||||
|
if (nextStatus) qs.set('status', nextStatus);
|
||||||
|
const [data, summary] = await Promise.all([
|
||||||
|
request<Paginated<StorePackageChangeRequestDto>>(`/admin/store-package-audits?${qs}`),
|
||||||
|
request<StorePackageAuditSummaryDto>('/admin/store-package-audits/summary'),
|
||||||
|
]);
|
||||||
|
setItems(data.items);
|
||||||
|
setTotal(data.total);
|
||||||
|
setPage(data.page);
|
||||||
|
setPendingCount(summary.pendingCount ?? 0);
|
||||||
|
} catch (e) {
|
||||||
|
message.error(e instanceof Error ? e.message : '加载失败');
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
void reload(1, status);
|
||||||
|
}, [status]);
|
||||||
|
|
||||||
|
const [searchParams] = useSearchParams();
|
||||||
|
const initialTab = searchParams.get('tab') === 'info' ? 'info' : 'package';
|
||||||
|
const [activeTab, setActiveTab] = useState<string>(initialTab);
|
||||||
|
const infoRequestId = searchParams.get('infoRequestId');
|
||||||
|
useEffect(() => {
|
||||||
|
const rid = searchParams.get('requestId');
|
||||||
|
if (rid) {
|
||||||
|
setActiveRequestId(rid);
|
||||||
|
setDetailOpen(true);
|
||||||
|
}
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
function openDetail(id: string) {
|
||||||
|
setActiveRequestId(id);
|
||||||
|
setDrawerTitle('套餐变更详情');
|
||||||
|
setDetailOpen(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function audit(id: string, action: 'APPROVE' | 'REJECT', reason?: string) {
|
||||||
|
try {
|
||||||
|
await request(`/admin/store-package-audits/${id}/audit`, {
|
||||||
|
method: 'PUT',
|
||||||
|
body: JSON.stringify(
|
||||||
|
action === 'REJECT' ? { action, rejectReason: reason } : { action },
|
||||||
|
),
|
||||||
|
});
|
||||||
|
message.success(action === 'APPROVE' ? '已通过' : '已驳回');
|
||||||
|
setDetailOpen(false);
|
||||||
|
notifyPackageAuditChanged();
|
||||||
|
void reload(page, status);
|
||||||
|
} catch (e) {
|
||||||
|
message.error(e instanceof Error ? e.message : '操作失败');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const columns: ColumnsType<StorePackageChangeRequestDto> = [
|
||||||
|
{ title: '门店', dataIndex: 'storeName', render: (_, row) => row.storeName || row.storeId },
|
||||||
|
{
|
||||||
|
title: '状态',
|
||||||
|
dataIndex: 'status',
|
||||||
|
render: (v: StorePackageChangeRequestDto['status']) => (
|
||||||
|
<Tag>{HQ_PACKAGE_STATUS_LABELS[v] ?? v}</Tag>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '套餐数',
|
||||||
|
render: (_, row) => row.packages?.length ?? 0,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '提交方',
|
||||||
|
render: (_, row) => (row.submitterType === 'PARTNER' ? '合伙人' : '门店'),
|
||||||
|
},
|
||||||
|
{ title: '提交时间', dataIndex: 'createdAt', render: (v) => fmtTime(String(v)) },
|
||||||
|
{
|
||||||
|
title: '操作',
|
||||||
|
render: (_, row) => (
|
||||||
|
<Space>
|
||||||
|
<Button type="link" onClick={() => openDetail(row.id)}>
|
||||||
|
查看变更
|
||||||
|
</Button>
|
||||||
|
{row.status === 'PENDING' ? (
|
||||||
|
<>
|
||||||
|
<Button type="link" onClick={() => void audit(row.id, 'APPROVE')}>
|
||||||
|
通过
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
type="link"
|
||||||
|
danger
|
||||||
|
onClick={() => {
|
||||||
|
setActiveId(row.id);
|
||||||
|
setRejectReason('');
|
||||||
|
setRejectOpen(true);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
驳回
|
||||||
|
</Button>
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
row.rejectReason || null
|
||||||
|
)}
|
||||||
|
</Space>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<Typography.Title level={4}>审核通知</Typography.Title>
|
||||||
|
<Tabs
|
||||||
|
activeKey={activeTab}
|
||||||
|
onChange={setActiveTab}
|
||||||
|
items={[
|
||||||
|
{
|
||||||
|
key: 'package',
|
||||||
|
label: '套餐审核',
|
||||||
|
children: (
|
||||||
|
<>
|
||||||
|
<Space style={{ marginBottom: 16 }}>
|
||||||
|
{(['PENDING', 'APPROVED', 'REJECTED', ''] as const).map((s) => (
|
||||||
|
<Button key={s || 'all'} type={status === s ? 'primary' : 'default'} onClick={() => setStatus(s)}>
|
||||||
|
{s === 'PENDING' ? (
|
||||||
|
<Badge count={pendingCount} size="small" offset={[8, -2]}>
|
||||||
|
{HQ_PACKAGE_STATUS_LABELS.PENDING}
|
||||||
|
</Badge>
|
||||||
|
) : s ? (
|
||||||
|
HQ_PACKAGE_STATUS_LABELS[s]
|
||||||
|
) : (
|
||||||
|
'全部'
|
||||||
|
)}
|
||||||
|
</Button>
|
||||||
|
))}
|
||||||
|
</Space>
|
||||||
|
<Table
|
||||||
|
rowKey="id"
|
||||||
|
loading={loading}
|
||||||
|
columns={columns}
|
||||||
|
dataSource={items}
|
||||||
|
pagination={{
|
||||||
|
current: page,
|
||||||
|
total,
|
||||||
|
pageSize: 20,
|
||||||
|
onChange: (p) => void reload(p, status),
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'info',
|
||||||
|
label: '信息变更',
|
||||||
|
children: <InfoChangeAuditPanel initialRequestId={infoRequestId} />,
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Drawer
|
||||||
|
title={drawerTitle}
|
||||||
|
width={880}
|
||||||
|
open={detailOpen}
|
||||||
|
onClose={() => setDetailOpen(false)}
|
||||||
|
destroyOnClose
|
||||||
|
>
|
||||||
|
{activeRequestId ? (
|
||||||
|
<StorePackageAuditPanel
|
||||||
|
requestId={activeRequestId}
|
||||||
|
onAudited={() => {
|
||||||
|
setDetailOpen(false);
|
||||||
|
void reload(page, status);
|
||||||
|
}}
|
||||||
|
onDetailLoaded={(d) => {
|
||||||
|
if (d) setDrawerTitle(`${d.storeName || d.storeId} · 套餐变更`);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
) : null}
|
||||||
|
</Drawer>
|
||||||
|
|
||||||
|
<Modal
|
||||||
|
title="驳回套餐变更"
|
||||||
|
open={rejectOpen}
|
||||||
|
onCancel={() => setRejectOpen(false)}
|
||||||
|
onOk={() => {
|
||||||
|
if (!activeId) return;
|
||||||
|
if (!rejectReason.trim()) {
|
||||||
|
message.warning('请填写驳回原因');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
void audit(activeId, 'REJECT', rejectReason.trim());
|
||||||
|
setRejectOpen(false);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Input.TextArea
|
||||||
|
rows={3}
|
||||||
|
value={rejectReason}
|
||||||
|
placeholder="驳回原因"
|
||||||
|
onChange={(e) => setRejectReason(e.target.value)}
|
||||||
|
/>
|
||||||
|
</Modal>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,104 @@
|
|||||||
|
import { useState } from 'react';
|
||||||
|
import { Button, Form, Input, Table, Typography } from 'antd';
|
||||||
|
import type { ColumnsType } from 'antd/es/table';
|
||||||
|
import { useSearchParams } from 'react-router-dom';
|
||||||
|
import { fmtTime } from '../lib/constants';
|
||||||
|
import { useAdminList } from '../lib/useAdminList';
|
||||||
|
|
||||||
|
type Row = {
|
||||||
|
id: string;
|
||||||
|
serviceScore: number;
|
||||||
|
envScore: number;
|
||||||
|
createdAt: string;
|
||||||
|
redeemNo: string;
|
||||||
|
redeemAmount: number;
|
||||||
|
store?: { id: string; name: string; cityName?: string };
|
||||||
|
user?: { userNo: string; phone: string | null; nickname: string | null };
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function StoreRatingsPage() {
|
||||||
|
const [searchParams] = useSearchParams();
|
||||||
|
const initialStoreId = searchParams.get('storeId') || '';
|
||||||
|
const [form] = Form.useForm();
|
||||||
|
const [filters, setFilters] = useState<Record<string, string>>({
|
||||||
|
...(initialStoreId ? { storeId: initialStoreId } : {}),
|
||||||
|
});
|
||||||
|
|
||||||
|
const { data, loading, page, pageSize, setPage, setPageSize } = useAdminList<Row>(
|
||||||
|
'/admin/store-ratings',
|
||||||
|
() => {
|
||||||
|
const qs = new URLSearchParams();
|
||||||
|
if (filters.storeId) qs.set('storeId', filters.storeId);
|
||||||
|
if (filters.redeemNo) qs.set('redeemNo', filters.redeemNo);
|
||||||
|
return qs;
|
||||||
|
},
|
||||||
|
[filters],
|
||||||
|
);
|
||||||
|
|
||||||
|
const columns: ColumnsType<Row> = [
|
||||||
|
{ title: '核销号', dataIndex: 'redeemNo', width: 180 },
|
||||||
|
{
|
||||||
|
title: '门店',
|
||||||
|
dataIndex: ['store', 'name'],
|
||||||
|
render: (v, row) => (row.store?.cityName ? `${v}(${row.store.cityName})` : v),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '用户',
|
||||||
|
width: 140,
|
||||||
|
render: (_, row) => row.user?.phone || row.user?.userNo || '-',
|
||||||
|
},
|
||||||
|
{ title: '核销额', dataIndex: 'redeemAmount', width: 90, render: (v) => `¥${v}` },
|
||||||
|
{ title: '服务分', dataIndex: 'serviceScore', width: 80 },
|
||||||
|
{ title: '环境分', dataIndex: 'envScore', width: 80 },
|
||||||
|
{ title: '评价时间', dataIndex: 'createdAt', width: 170, render: fmtTime },
|
||||||
|
];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<Typography.Title level={4} style={{ marginTop: 0 }}>
|
||||||
|
门店评价
|
||||||
|
</Typography.Title>
|
||||||
|
<Form
|
||||||
|
form={form}
|
||||||
|
layout="inline"
|
||||||
|
style={{ marginBottom: 16 }}
|
||||||
|
initialValues={filters}
|
||||||
|
onFinish={(v) => {
|
||||||
|
setFilters({
|
||||||
|
storeId: v.storeId || '',
|
||||||
|
redeemNo: v.redeemNo || '',
|
||||||
|
});
|
||||||
|
setPage(1);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Form.Item name="storeId" label="门店ID">
|
||||||
|
<Input allowClear placeholder="storeId" />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="redeemNo" label="核销号">
|
||||||
|
<Input allowClear />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item>
|
||||||
|
<Button type="primary" htmlType="submit">
|
||||||
|
查询
|
||||||
|
</Button>
|
||||||
|
</Form.Item>
|
||||||
|
</Form>
|
||||||
|
<Table
|
||||||
|
rowKey="id"
|
||||||
|
loading={loading}
|
||||||
|
columns={columns}
|
||||||
|
dataSource={data?.items ?? []}
|
||||||
|
pagination={{
|
||||||
|
current: page,
|
||||||
|
pageSize,
|
||||||
|
total: data?.total ?? 0,
|
||||||
|
showSizeChanger: true,
|
||||||
|
onChange: (p, ps) => {
|
||||||
|
setPage(p);
|
||||||
|
setPageSize(ps);
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,394 @@
|
|||||||
|
import { useEffect, useState } from 'react';
|
||||||
|
import {
|
||||||
|
Button,
|
||||||
|
DatePicker,
|
||||||
|
Descriptions,
|
||||||
|
Drawer,
|
||||||
|
Form,
|
||||||
|
Input,
|
||||||
|
Modal,
|
||||||
|
Select,
|
||||||
|
Space,
|
||||||
|
Table,
|
||||||
|
Tag,
|
||||||
|
Typography,
|
||||||
|
message,
|
||||||
|
} from 'antd';
|
||||||
|
import type { ColumnsType } from 'antd/es/table';
|
||||||
|
import type { Dayjs } from 'dayjs';
|
||||||
|
import { STORE_WITHDRAW_STATUS_LABELS, type StoreWithdrawStatus } from '@dukang/shared-types';
|
||||||
|
import { request, type Paginated } from '../lib/api';
|
||||||
|
import { ADMIN_OPTIONS_PAGE_SIZE, fmtTime } from '../lib/constants';
|
||||||
|
import { useAdminList } from '../lib/useAdminList';
|
||||||
|
|
||||||
|
type Row = {
|
||||||
|
id: string;
|
||||||
|
withdrawNo: string;
|
||||||
|
amount: number;
|
||||||
|
payoutCount: number;
|
||||||
|
status: StoreWithdrawStatus;
|
||||||
|
appliedAt: string;
|
||||||
|
reviewedAt?: string | null;
|
||||||
|
paidAt?: string | null;
|
||||||
|
paymentRef?: string | null;
|
||||||
|
rejectReason?: string | null;
|
||||||
|
overdue?: boolean;
|
||||||
|
store?: { id: string; name: string; cityName: string; phone?: string };
|
||||||
|
};
|
||||||
|
|
||||||
|
type StoreOption = { id: string; name: string; phone: string };
|
||||||
|
|
||||||
|
const STATUS_COLORS: Record<string, string> = {
|
||||||
|
PENDING_REVIEW: 'orange',
|
||||||
|
REJECTED: 'red',
|
||||||
|
PAID: 'green',
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function StoreWithdrawalsPage() {
|
||||||
|
const [form] = Form.useForm();
|
||||||
|
const [filters, setFilters] = useState<Record<string, string>>({ status: 'PENDING_REVIEW' });
|
||||||
|
const [stores, setStores] = useState<StoreOption[]>([]);
|
||||||
|
const { data, loading, page, pageSize, setPage, setPageSize, reload } = useAdminList<Row>(
|
||||||
|
'/admin/store-withdrawals',
|
||||||
|
() => {
|
||||||
|
const qs = new URLSearchParams();
|
||||||
|
if (filters.status) qs.set('status', filters.status);
|
||||||
|
if (filters.storeId) qs.set('storeId', filters.storeId);
|
||||||
|
if (filters.dateFrom) qs.set('dateFrom', filters.dateFrom);
|
||||||
|
if (filters.dateTo) qs.set('dateTo', filters.dateTo);
|
||||||
|
return qs;
|
||||||
|
},
|
||||||
|
[filters],
|
||||||
|
);
|
||||||
|
const [detail, setDetail] = useState<Record<string, unknown> | null>(null);
|
||||||
|
const [drawerOpen, setDrawerOpen] = useState(false);
|
||||||
|
const [overdueSummary, setOverdueSummary] = useState<{
|
||||||
|
pendingCount: number;
|
||||||
|
overdueCount: number;
|
||||||
|
} | null>(null);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
void request<Paginated<StoreOption>>(`/admin/stores?pageSize=${ADMIN_OPTIONS_PAGE_SIZE}`)
|
||||||
|
.then((res) => setStores(res.items))
|
||||||
|
.catch(() => {});
|
||||||
|
void request<{ pendingCount: number; overdueCount: number }>(
|
||||||
|
'/admin/store-withdrawals/overdue-summary',
|
||||||
|
)
|
||||||
|
.then(setOverdueSummary)
|
||||||
|
.catch(() => {});
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
async function openDetail(id: string) {
|
||||||
|
const d = await request<Record<string, unknown>>(`/admin/store-withdrawals/${id}`);
|
||||||
|
setDetail(d);
|
||||||
|
setDrawerOpen(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
function approve(id: string) {
|
||||||
|
let paymentRef = '';
|
||||||
|
Modal.confirm({
|
||||||
|
title: '审核通过并标记已结算?',
|
||||||
|
content: (
|
||||||
|
<Input
|
||||||
|
placeholder="打款凭证号(可选)"
|
||||||
|
onChange={(e) => {
|
||||||
|
paymentRef = e.target.value;
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
),
|
||||||
|
okText: '通过并结算',
|
||||||
|
cancelText: '取消',
|
||||||
|
onOk: async () => {
|
||||||
|
await request(`/admin/store-withdrawals/${id}/approve`, {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify({ paymentRef: paymentRef.trim() || undefined }),
|
||||||
|
});
|
||||||
|
message.success('已通过并标记已结算');
|
||||||
|
setDrawerOpen(false);
|
||||||
|
reload();
|
||||||
|
void request<{ pendingCount: number; overdueCount: number }>(
|
||||||
|
'/admin/store-withdrawals/overdue-summary',
|
||||||
|
)
|
||||||
|
.then(setOverdueSummary)
|
||||||
|
.catch(() => {});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function reject(id: string) {
|
||||||
|
let reason = '';
|
||||||
|
Modal.confirm({
|
||||||
|
title: '驳回提现申请?',
|
||||||
|
content: (
|
||||||
|
<Input.TextArea
|
||||||
|
rows={3}
|
||||||
|
placeholder="请填写驳回理由"
|
||||||
|
onChange={(e) => {
|
||||||
|
reason = e.target.value;
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
),
|
||||||
|
okText: '确认驳回',
|
||||||
|
okButtonProps: { danger: true },
|
||||||
|
cancelText: '取消',
|
||||||
|
onOk: async () => {
|
||||||
|
if (!reason.trim()) {
|
||||||
|
message.error('请填写驳回理由');
|
||||||
|
throw new Error('reason required');
|
||||||
|
}
|
||||||
|
await request(`/admin/store-withdrawals/${id}/reject`, {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify({ reason: reason.trim() }),
|
||||||
|
});
|
||||||
|
message.success('已驳回');
|
||||||
|
setDrawerOpen(false);
|
||||||
|
reload();
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const columns: ColumnsType<Row> = [
|
||||||
|
{
|
||||||
|
title: '提现单号',
|
||||||
|
dataIndex: 'withdrawNo',
|
||||||
|
width: 180,
|
||||||
|
render: (v, row) => (
|
||||||
|
<Space>
|
||||||
|
<Typography.Link onClick={() => void openDetail(row.id)}>{v}</Typography.Link>
|
||||||
|
{row.overdue ? <Tag color="magenta">超时</Tag> : null}
|
||||||
|
</Space>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '门店',
|
||||||
|
dataIndex: ['store', 'name'],
|
||||||
|
width: 160,
|
||||||
|
render: (_, row) => (
|
||||||
|
<div>
|
||||||
|
<div>{row.store?.name || '—'}</div>
|
||||||
|
<Typography.Text type="secondary" style={{ fontSize: 12 }}>
|
||||||
|
{row.store?.cityName} {row.store?.phone}
|
||||||
|
</Typography.Text>
|
||||||
|
</div>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '金额',
|
||||||
|
dataIndex: 'amount',
|
||||||
|
width: 110,
|
||||||
|
render: (v) => `¥${Number(v).toFixed(2)}`,
|
||||||
|
},
|
||||||
|
{ title: '明细笔数', dataIndex: 'payoutCount', width: 90 },
|
||||||
|
{
|
||||||
|
title: '状态',
|
||||||
|
dataIndex: 'status',
|
||||||
|
width: 100,
|
||||||
|
render: (v: StoreWithdrawStatus) => (
|
||||||
|
<Tag color={STATUS_COLORS[v]}>{STORE_WITHDRAW_STATUS_LABELS[v] ?? v}</Tag>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '申请时间',
|
||||||
|
dataIndex: 'appliedAt',
|
||||||
|
width: 170,
|
||||||
|
render: (v) => fmtTime(v),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '操作',
|
||||||
|
key: 'actions',
|
||||||
|
width: 180,
|
||||||
|
fixed: 'right',
|
||||||
|
render: (_, row) => (
|
||||||
|
<Space>
|
||||||
|
<Button size="small" onClick={() => void openDetail(row.id)}>
|
||||||
|
详情
|
||||||
|
</Button>
|
||||||
|
{row.status === 'PENDING_REVIEW' ? (
|
||||||
|
<>
|
||||||
|
<Button size="small" type="primary" onClick={() => approve(row.id)}>
|
||||||
|
通过
|
||||||
|
</Button>
|
||||||
|
<Button size="small" danger onClick={() => reject(row.id)}>
|
||||||
|
驳回
|
||||||
|
</Button>
|
||||||
|
</>
|
||||||
|
) : null}
|
||||||
|
</Space>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const detailItems = (detail?.items as Array<Record<string, unknown>> | undefined) ?? [];
|
||||||
|
const storeAccount = detail?.storeAccount as
|
||||||
|
| {
|
||||||
|
name?: string;
|
||||||
|
phone?: string;
|
||||||
|
bankAccountName?: string;
|
||||||
|
bankAccountNo?: string;
|
||||||
|
bankBranch?: string;
|
||||||
|
}
|
||||||
|
| undefined;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<Typography.Title level={4} style={{ marginTop: 0 }}>
|
||||||
|
门店提现审
|
||||||
|
</Typography.Title>
|
||||||
|
{overdueSummary ? (
|
||||||
|
<Typography.Paragraph type="secondary">
|
||||||
|
待审 {overdueSummary.pendingCount} 笔
|
||||||
|
{overdueSummary.overdueCount > 0 ? (
|
||||||
|
<Typography.Text type="danger">
|
||||||
|
{' '}
|
||||||
|
· 超时未审 {overdueSummary.overdueCount} 笔(FIN-003)
|
||||||
|
</Typography.Text>
|
||||||
|
) : null}
|
||||||
|
</Typography.Paragraph>
|
||||||
|
) : null}
|
||||||
|
|
||||||
|
<Form
|
||||||
|
form={form}
|
||||||
|
layout="inline"
|
||||||
|
style={{ marginBottom: 16, gap: 8 }}
|
||||||
|
initialValues={{ status: 'PENDING_REVIEW' }}
|
||||||
|
onFinish={(v) => {
|
||||||
|
const range = v.range as [Dayjs, Dayjs] | undefined;
|
||||||
|
setFilters({
|
||||||
|
status: v.status || '',
|
||||||
|
storeId: v.storeId || '',
|
||||||
|
dateFrom: range?.[0]?.format('YYYY-MM-DD') || '',
|
||||||
|
dateTo: range?.[1]?.format('YYYY-MM-DD') || '',
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Form.Item name="status" label="状态">
|
||||||
|
<Select
|
||||||
|
allowClear
|
||||||
|
style={{ width: 140 }}
|
||||||
|
options={[
|
||||||
|
{ value: 'PENDING_REVIEW', label: '待审核' },
|
||||||
|
{ value: 'PAID', label: '已结算' },
|
||||||
|
{ value: 'REJECTED', label: '已驳回' },
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="storeId" label="门店">
|
||||||
|
<Select
|
||||||
|
allowClear
|
||||||
|
showSearch
|
||||||
|
optionFilterProp="label"
|
||||||
|
style={{ width: 220 }}
|
||||||
|
options={stores.map((s) => ({
|
||||||
|
value: s.id,
|
||||||
|
label: `${s.name} (${s.phone})`,
|
||||||
|
}))}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="range" label="申请日">
|
||||||
|
<DatePicker.RangePicker />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item>
|
||||||
|
<Button type="primary" htmlType="submit">
|
||||||
|
查询
|
||||||
|
</Button>
|
||||||
|
</Form.Item>
|
||||||
|
</Form>
|
||||||
|
|
||||||
|
<Table
|
||||||
|
rowKey="id"
|
||||||
|
loading={loading}
|
||||||
|
columns={columns}
|
||||||
|
dataSource={data?.items ?? []}
|
||||||
|
scroll={{ x: 1100 }}
|
||||||
|
rowClassName={(row) => (row.overdue ? 'ant-table-row-selected' : '')}
|
||||||
|
pagination={{
|
||||||
|
current: page,
|
||||||
|
pageSize,
|
||||||
|
total: data?.total ?? 0,
|
||||||
|
showSizeChanger: true,
|
||||||
|
onChange: (p, ps) => {
|
||||||
|
setPage(p);
|
||||||
|
setPageSize(ps);
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Drawer
|
||||||
|
title="提现详情"
|
||||||
|
width={640}
|
||||||
|
open={drawerOpen}
|
||||||
|
onClose={() => setDrawerOpen(false)}
|
||||||
|
extra={
|
||||||
|
detail?.status === 'PENDING_REVIEW' ? (
|
||||||
|
<Space>
|
||||||
|
<Button type="primary" onClick={() => approve(String(detail.id))}>
|
||||||
|
通过
|
||||||
|
</Button>
|
||||||
|
<Button danger onClick={() => reject(String(detail.id))}>
|
||||||
|
驳回
|
||||||
|
</Button>
|
||||||
|
</Space>
|
||||||
|
) : null
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{detail ? (
|
||||||
|
<>
|
||||||
|
<Descriptions column={1} size="small" bordered>
|
||||||
|
<Descriptions.Item label="提现单号">{String(detail.withdrawNo)}</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="状态">
|
||||||
|
<Tag color={STATUS_COLORS[String(detail.status)]}>
|
||||||
|
{STORE_WITHDRAW_STATUS_LABELS[detail.status as StoreWithdrawStatus] ??
|
||||||
|
String(detail.status)}
|
||||||
|
</Tag>
|
||||||
|
{detail.overdue ? <Tag color="magenta">超时</Tag> : null}
|
||||||
|
</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="金额">¥{Number(detail.amount).toFixed(2)}</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="明细笔数">{String(detail.payoutCount)}</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="申请时间">{fmtTime(String(detail.appliedAt))}</Descriptions.Item>
|
||||||
|
{detail.rejectReason ? (
|
||||||
|
<Descriptions.Item label="驳回理由">{String(detail.rejectReason)}</Descriptions.Item>
|
||||||
|
) : null}
|
||||||
|
{detail.paymentRef ? (
|
||||||
|
<Descriptions.Item label="打款凭证">{String(detail.paymentRef)}</Descriptions.Item>
|
||||||
|
) : null}
|
||||||
|
<Descriptions.Item label="收款户名">
|
||||||
|
{storeAccount?.bankAccountName || '—'}
|
||||||
|
</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="收款账号">
|
||||||
|
{storeAccount?.bankAccountNo || '—'}
|
||||||
|
</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="开户行">{storeAccount?.bankBranch || '—'}</Descriptions.Item>
|
||||||
|
</Descriptions>
|
||||||
|
|
||||||
|
<Typography.Title level={5} style={{ marginTop: 24 }}>
|
||||||
|
关联结算明细
|
||||||
|
</Typography.Title>
|
||||||
|
<Table
|
||||||
|
size="small"
|
||||||
|
rowKey={(r) => String((r as { id?: string }).id)}
|
||||||
|
pagination={false}
|
||||||
|
dataSource={detailItems}
|
||||||
|
columns={[
|
||||||
|
{
|
||||||
|
title: '核销单号',
|
||||||
|
render: (_, r) => {
|
||||||
|
const payout = (r as { storePayout?: { redeemRecord?: { redeemNo?: string } } })
|
||||||
|
.storePayout;
|
||||||
|
return payout?.redeemRecord?.redeemNo || '—';
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '结算额',
|
||||||
|
render: (_, r) => {
|
||||||
|
const payout = (r as { storePayout?: { payoutAmount?: number } }).storePayout;
|
||||||
|
return `¥${Number(payout?.payoutAmount ?? 0).toFixed(2)}`;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
) : null}
|
||||||
|
</Drawer>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
+1212
-131
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,283 +1,182 @@
|
|||||||
import { useEffect, useMemo, useState, type ReactNode } from 'react';
|
import { useEffect, useMemo, useRef, useState, type ReactNode } from 'react';
|
||||||
|
import { useNavigate } from 'react-router-dom';
|
||||||
import {
|
import {
|
||||||
|
|
||||||
Alert,
|
Alert,
|
||||||
|
|
||||||
Button,
|
Button,
|
||||||
|
|
||||||
Card,
|
Card,
|
||||||
|
|
||||||
Collapse,
|
Collapse,
|
||||||
|
|
||||||
Form,
|
Form,
|
||||||
|
|
||||||
Input,
|
Input,
|
||||||
|
|
||||||
InputNumber,
|
InputNumber,
|
||||||
|
Modal,
|
||||||
Space,
|
Space,
|
||||||
|
|
||||||
Switch,
|
Switch,
|
||||||
|
|
||||||
Table,
|
Table,
|
||||||
|
|
||||||
Tag,
|
Tag,
|
||||||
|
|
||||||
Typography,
|
Typography,
|
||||||
|
|
||||||
message,
|
message,
|
||||||
|
|
||||||
} from 'antd';
|
} from 'antd';
|
||||||
|
|
||||||
import type { MockSmsCodeItem, SystemConfigFieldMeta, SystemConfigFormResponse } from '@dukang/shared-types';
|
import type { MockSmsCodeItem, SystemConfigFieldMeta, SystemConfigFormResponse } from '@dukang/shared-types';
|
||||||
|
import { request, type HqProfile } from '../lib/api';
|
||||||
import { request } from '../lib/api';
|
import { ConfigImageField, ConfigImageListField } from '../components/ConfigMediaFields';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const { TextArea } = Input;
|
const { TextArea } = Input;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function MockSmsCodePanel({ codes, loading }: { codes: MockSmsCodeItem[]; loading?: boolean }) {
|
function MockSmsCodePanel({ codes, loading }: { codes: MockSmsCodeItem[]; loading?: boolean }) {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
||||||
<div style={{ marginTop: -8, marginBottom: 16, marginLeft: 0 }}>
|
<div style={{ marginTop: -8, marginBottom: 16, marginLeft: 0 }}>
|
||||||
|
|
||||||
<Typography.Text type="secondary" style={{ display: 'block', marginBottom: 8 }}>
|
<Typography.Text type="secondary" style={{ display: 'block', marginBottom: 8 }}>
|
||||||
|
|
||||||
最近 Mock 验证码(写入数据库,最新 50 条)
|
最近 Mock 验证码(写入数据库,最新 50 条)
|
||||||
|
|
||||||
</Typography.Text>
|
</Typography.Text>
|
||||||
|
|
||||||
<Table<MockSmsCodeItem>
|
<Table<MockSmsCodeItem>
|
||||||
|
|
||||||
size="small"
|
size="small"
|
||||||
|
|
||||||
rowKey="id"
|
rowKey="id"
|
||||||
|
|
||||||
loading={loading}
|
loading={loading}
|
||||||
|
|
||||||
pagination={false}
|
pagination={false}
|
||||||
|
|
||||||
scroll={{ y: 240 }}
|
scroll={{ y: 240 }}
|
||||||
|
|
||||||
locale={{ emptyText: '暂无记录,触发短信发送后将显示在此' }}
|
locale={{ emptyText: '暂无记录,触发短信发送后将显示在此' }}
|
||||||
|
|
||||||
columns={[
|
columns={[
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
||||||
title: '时间',
|
title: '时间',
|
||||||
|
|
||||||
dataIndex: 'createdAt',
|
dataIndex: 'createdAt',
|
||||||
|
|
||||||
width: 168,
|
width: 168,
|
||||||
|
|
||||||
render: (v: string) => new Date(v).toLocaleString(),
|
render: (v: string) => new Date(v).toLocaleString(),
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
{ title: '手机号', dataIndex: 'phone', width: 120 },
|
{ title: '手机号', dataIndex: 'phone', width: 120 },
|
||||||
|
|
||||||
{ title: '场景', dataIndex: 'scene', width: 160 },
|
{ title: '场景', dataIndex: 'scene', width: 160 },
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
||||||
title: '验证码',
|
title: '验证码',
|
||||||
|
|
||||||
dataIndex: 'code',
|
dataIndex: 'code',
|
||||||
|
|
||||||
width: 88,
|
width: 88,
|
||||||
|
|
||||||
render: (code: string) => (
|
render: (code: string) => (
|
||||||
|
|
||||||
<Typography.Text copyable strong>
|
<Typography.Text copyable strong>
|
||||||
|
|
||||||
{code}
|
{code}
|
||||||
|
|
||||||
</Typography.Text>
|
</Typography.Text>
|
||||||
|
|
||||||
),
|
),
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
]}
|
]}
|
||||||
|
|
||||||
dataSource={codes}
|
dataSource={codes}
|
||||||
|
|
||||||
/>
|
/>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function renderField(
|
function renderField(
|
||||||
|
|
||||||
field: SystemConfigFieldMeta,
|
field: SystemConfigFieldMeta,
|
||||||
|
|
||||||
configuredSecrets: string[],
|
configuredSecrets: string[],
|
||||||
|
|
||||||
extra?: ReactNode,
|
extra?: ReactNode,
|
||||||
|
|
||||||
) {
|
) {
|
||||||
|
|
||||||
const isConfiguredSecret = field.secret && configuredSecrets.includes(field.key);
|
const isConfiguredSecret = field.secret && configuredSecrets.includes(field.key);
|
||||||
|
|
||||||
if (field.type === 'boolean') {
|
if (field.type === 'boolean') {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
||||||
<div key={field.key}>
|
<div key={field.key}>
|
||||||
|
|
||||||
<Form.Item
|
<Form.Item
|
||||||
|
|
||||||
name={field.key}
|
name={field.key}
|
||||||
|
|
||||||
label={
|
label={
|
||||||
|
|
||||||
<Space size={4}>
|
<Space size={4}>
|
||||||
|
|
||||||
<span>{field.label}</span>
|
<span>{field.label}</span>
|
||||||
|
|
||||||
<Typography.Text type="secondary" code style={{ fontSize: 11 }}>
|
<Typography.Text type="secondary" code style={{ fontSize: 11 }}>
|
||||||
|
|
||||||
{field.key}
|
{field.key}
|
||||||
|
|
||||||
</Typography.Text>
|
</Typography.Text>
|
||||||
|
|
||||||
{field.requiresRestart ? <Tag color="orange">需重启</Tag> : <Tag color="green">即时</Tag>}
|
{field.requiresRestart ? <Tag color="orange">需重启</Tag> : <Tag color="green">即时</Tag>}
|
||||||
|
|
||||||
</Space>
|
</Space>
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tooltip={field.description}
|
tooltip={field.description}
|
||||||
|
|
||||||
valuePropName="checked"
|
valuePropName="checked"
|
||||||
|
|
||||||
getValueFromEvent={(checked: boolean) => (checked ? 'true' : 'false')}
|
getValueFromEvent={(checked: boolean) => (checked ? 'true' : 'false')}
|
||||||
|
|
||||||
getValueProps={(v: string) => ({ checked: v === 'true' || v === '1' })}
|
getValueProps={(v: string) => ({ checked: v === 'true' || v === '1' })}
|
||||||
|
|
||||||
>
|
>
|
||||||
|
|
||||||
<Switch />
|
<Switch />
|
||||||
|
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
|
|
||||||
{extra}
|
{extra}
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (field.type === 'image' || field.type === 'imageList') {
|
||||||
|
return (
|
||||||
|
<Form.Item
|
||||||
|
key={field.key}
|
||||||
|
name={field.key}
|
||||||
|
label={
|
||||||
|
<Space size={4} wrap>
|
||||||
|
<span>{field.label}</span>
|
||||||
|
<Typography.Text type="secondary" code style={{ fontSize: 11 }}>
|
||||||
|
{field.key}
|
||||||
|
</Typography.Text>
|
||||||
|
{field.requiresRestart ? <Tag color="orange">需重启</Tag> : <Tag color="green">即时</Tag>}
|
||||||
|
</Space>
|
||||||
|
}
|
||||||
|
tooltip={field.description}
|
||||||
|
trigger="onChange"
|
||||||
|
getValueFromEvent={(v: unknown) => (typeof v === 'string' ? v : '')}
|
||||||
|
normalize={(v) => (typeof v === 'string' ? v : '')}
|
||||||
|
>
|
||||||
|
{field.type === 'image' ? (
|
||||||
|
<ConfigImageField bizType="footer" />
|
||||||
|
) : (
|
||||||
|
<ConfigImageListField bizType="swiper" />
|
||||||
|
)}
|
||||||
|
</Form.Item>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const input =
|
const input =
|
||||||
|
|
||||||
field.type === 'textarea' ? (
|
field.type === 'textarea' ? (
|
||||||
|
|
||||||
<TextArea rows={3} placeholder={field.placeholder} />
|
<TextArea rows={3} placeholder={field.placeholder} />
|
||||||
|
|
||||||
) : field.type === 'number' ? (
|
) : field.type === 'number' ? (
|
||||||
|
|
||||||
<InputNumber style={{ width: '100%' }} placeholder={field.placeholder} />
|
<InputNumber style={{ width: '100%' }} placeholder={field.placeholder} />
|
||||||
|
|
||||||
) : field.secret ? (
|
) : field.secret ? (
|
||||||
|
|
||||||
<Input.Password
|
<Input.Password
|
||||||
|
|
||||||
placeholder={isConfiguredSecret ? '已配置,留空则不修改' : field.placeholder}
|
placeholder={isConfiguredSecret ? '已配置,留空则不修改' : field.placeholder}
|
||||||
|
|
||||||
autoComplete="new-password"
|
autoComplete="new-password"
|
||||||
|
|
||||||
/>
|
/>
|
||||||
|
|
||||||
) : (
|
) : (
|
||||||
|
|
||||||
<Input placeholder={field.placeholder} />
|
<Input placeholder={field.placeholder} />
|
||||||
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
||||||
<Form.Item
|
<Form.Item
|
||||||
|
|
||||||
key={field.key}
|
key={field.key}
|
||||||
|
|
||||||
name={field.key}
|
name={field.key}
|
||||||
|
|
||||||
label={
|
label={
|
||||||
|
|
||||||
<Space size={4} wrap>
|
<Space size={4} wrap>
|
||||||
|
|
||||||
<span>{field.label}</span>
|
<span>{field.label}</span>
|
||||||
|
|
||||||
<Typography.Text type="secondary" code style={{ fontSize: 11 }}>
|
<Typography.Text type="secondary" code style={{ fontSize: 11 }}>
|
||||||
|
|
||||||
{field.key}
|
{field.key}
|
||||||
|
|
||||||
</Typography.Text>
|
</Typography.Text>
|
||||||
|
|
||||||
{field.requiresRestart ? <Tag color="orange">需重启</Tag> : <Tag color="green">即时</Tag>}
|
{field.requiresRestart ? <Tag color="orange">需重启</Tag> : <Tag color="green">即时</Tag>}
|
||||||
|
|
||||||
{isConfiguredSecret ? <Tag>已配置</Tag> : null}
|
{isConfiguredSecret ? <Tag>已配置</Tag> : null}
|
||||||
|
|
||||||
</Space>
|
</Space>
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tooltip={field.description}
|
tooltip={field.description}
|
||||||
|
|
||||||
>
|
>
|
||||||
|
|
||||||
{input}
|
{input}
|
||||||
|
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
|
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export default function SystemSettingsPage() {
|
export default function SystemSettingsPage() {
|
||||||
|
const navigate = useNavigate();
|
||||||
const [form] = Form.useForm<Record<string, string>>();
|
const [form] = Form.useForm<Record<string, string>>();
|
||||||
|
|
||||||
const [meta, setMeta] = useState<SystemConfigFormResponse | null>(null);
|
const [meta, setMeta] = useState<SystemConfigFormResponse | null>(null);
|
||||||
|
const [profile, setProfile] = useState<HqProfile | null>(null);
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
|
|
||||||
const [saving, setSaving] = useState(false);
|
const [saving, setSaving] = useState(false);
|
||||||
|
|
||||||
const [syncing, setSyncing] = useState(false);
|
const [syncing, setSyncing] = useState(false);
|
||||||
|
const [dirty, setDirty] = useState(false);
|
||||||
|
const dirtyRef = useRef(false);
|
||||||
|
const bypassLeaveRef = useRef(false);
|
||||||
const mockSmsEnabled = Form.useWatch('MOCK_SMS', form) === 'true';
|
const mockSmsEnabled = Form.useWatch('MOCK_SMS', form) === 'true';
|
||||||
|
|
||||||
|
dirtyRef.current = dirty;
|
||||||
|
|
||||||
async function load(silent = false) {
|
async function load(silent = false) {
|
||||||
|
|
||||||
if (!silent) setLoading(true);
|
if (!silent) setLoading(true);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
const data = await request<SystemConfigFormResponse>('/admin/system-config');
|
const data = await request<SystemConfigFormResponse>('/admin/system-config');
|
||||||
|
|
||||||
if (silent) {
|
if (silent) {
|
||||||
// 仅刷新 Mock 验证码列表,避免轮询用服务端值覆盖未保存的表单(含 MOCK_SMS 开关)
|
|
||||||
setMeta((prev) =>
|
setMeta((prev) =>
|
||||||
prev
|
prev
|
||||||
? { ...prev, mockSmsCodes: data.mockSmsCodes, updatedAt: data.updatedAt }
|
? { ...prev, mockSmsCodes: data.mockSmsCodes, updatedAt: data.updatedAt }
|
||||||
@@ -285,300 +184,289 @@ export default function SystemSettingsPage() {
|
|||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
setMeta(data);
|
setMeta(data);
|
||||||
|
|
||||||
form.setFieldsValue(data.values);
|
form.setFieldsValue(data.values);
|
||||||
|
setDirty(false);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
||||||
if (!silent) message.error(e instanceof Error ? e.message : '加载失败');
|
if (!silent) message.error(e instanceof Error ? e.message : '加载失败');
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
|
|
||||||
if (!silent) setLoading(false);
|
if (!silent) setLoading(false);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
||||||
void load();
|
void load();
|
||||||
|
request<HqProfile>('/admin/auth/me').then(setProfile).catch(() => {});
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
||||||
// 以表单开关为准展示验证码;轮询只刷列表,不回写表单
|
|
||||||
if (!mockSmsEnabled) return;
|
if (!mockSmsEnabled) return;
|
||||||
|
|
||||||
const timer = window.setInterval(() => void load(true), 5000);
|
const timer = window.setInterval(() => void load(true), 5000);
|
||||||
|
|
||||||
return () => window.clearInterval(timer);
|
return () => window.clearInterval(timer);
|
||||||
|
|
||||||
}, [mockSmsEnabled]);
|
}, [mockSmsEnabled]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const onBeforeUnload = (e: BeforeUnloadEvent) => {
|
||||||
|
if (!dirtyRef.current) return;
|
||||||
|
e.preventDefault();
|
||||||
|
e.returnValue = '';
|
||||||
|
};
|
||||||
|
window.addEventListener('beforeunload', onBeforeUnload);
|
||||||
|
return () => window.removeEventListener('beforeunload', onBeforeUnload);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const onDocClick = (e: MouseEvent) => {
|
||||||
|
if (!dirtyRef.current || bypassLeaveRef.current) return;
|
||||||
|
const target = e.target as HTMLElement | null;
|
||||||
|
const anchor = target?.closest?.('a');
|
||||||
|
if (!anchor || !(anchor instanceof HTMLAnchorElement)) return;
|
||||||
|
if (anchor.target === '_blank' || anchor.hasAttribute('download')) return;
|
||||||
|
const url = new URL(anchor.href, window.location.href);
|
||||||
|
if (url.origin !== window.location.origin) return;
|
||||||
|
if (url.pathname === window.location.pathname && url.search === window.location.search) return;
|
||||||
|
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
Modal.confirm({
|
||||||
|
title: '有未保存的更改',
|
||||||
|
content: '离开前请先保存,否则更改将丢失。',
|
||||||
|
okText: '仍要离开',
|
||||||
|
cancelText: '留下',
|
||||||
|
onOk: () => {
|
||||||
|
bypassLeaveRef.current = true;
|
||||||
|
setDirty(false);
|
||||||
|
navigate(`${url.pathname}${url.search}${url.hash}`);
|
||||||
|
window.setTimeout(() => {
|
||||||
|
bypassLeaveRef.current = false;
|
||||||
|
}, 0);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
document.addEventListener('click', onDocClick, true);
|
||||||
|
return () => document.removeEventListener('click', onDocClick, true);
|
||||||
|
}, [navigate]);
|
||||||
|
|
||||||
const collapseItems = useMemo(() => {
|
const collapseItems = useMemo(() => {
|
||||||
|
|
||||||
if (!meta) return [];
|
if (!meta) return [];
|
||||||
|
const SHARE_SUBGROUP_LABELS: Record<string, string> = {
|
||||||
|
global: '全局',
|
||||||
|
home: '首页',
|
||||||
|
stores: '门店列表',
|
||||||
|
storeDetail: '门店详情',
|
||||||
|
benefit: '权益页',
|
||||||
|
mine: '我的',
|
||||||
|
productDetail: '商品详情',
|
||||||
|
orderDetail: '订单详情',
|
||||||
|
};
|
||||||
|
const SHARE_SUBGROUP_ORDER = [
|
||||||
|
'global',
|
||||||
|
'home',
|
||||||
|
'stores',
|
||||||
|
'storeDetail',
|
||||||
|
'benefit',
|
||||||
|
'mine',
|
||||||
|
'productDetail',
|
||||||
|
'orderDetail',
|
||||||
|
];
|
||||||
|
|
||||||
return meta.groups.map((group) => ({
|
return meta.groups.map((group) => {
|
||||||
|
const fields = meta.fields.filter((f) => f.group === group.key);
|
||||||
key: group.key,
|
const hasSubgroups = fields.some((f) => f.subgroup);
|
||||||
|
|
||||||
label: group.label,
|
|
||||||
|
|
||||||
children: (
|
|
||||||
|
|
||||||
<div style={{ maxWidth: 720 }}>
|
|
||||||
|
|
||||||
{meta.fields
|
|
||||||
|
|
||||||
.filter((f) => f.group === group.key)
|
|
||||||
|
|
||||||
.map((f) =>
|
|
||||||
|
|
||||||
renderField(
|
|
||||||
|
|
||||||
f,
|
|
||||||
|
|
||||||
meta.configuredSecrets,
|
|
||||||
|
|
||||||
f.key === 'MOCK_SMS' && mockSmsEnabled ? (
|
|
||||||
|
|
||||||
<MockSmsCodePanel codes={meta.mockSmsCodes ?? []} loading={loading} />
|
|
||||||
|
|
||||||
) : undefined,
|
|
||||||
|
|
||||||
|
let children: ReactNode;
|
||||||
|
if (group.key === 'wechat_mini_share' && hasSubgroups) {
|
||||||
|
const bySub = new Map<string, SystemConfigFieldMeta[]>();
|
||||||
|
for (const f of fields) {
|
||||||
|
const sk = f.subgroup || 'global';
|
||||||
|
if (!bySub.has(sk)) bySub.set(sk, []);
|
||||||
|
bySub.get(sk)!.push(f);
|
||||||
|
}
|
||||||
|
const orderedKeys = [
|
||||||
|
...SHARE_SUBGROUP_ORDER.filter((k) => bySub.has(k)),
|
||||||
|
...[...bySub.keys()].filter((k) => !SHARE_SUBGROUP_ORDER.includes(k)),
|
||||||
|
];
|
||||||
|
children = (
|
||||||
|
<Collapse
|
||||||
|
defaultActiveKey={[]}
|
||||||
|
items={orderedKeys.map((sk) => ({
|
||||||
|
key: sk,
|
||||||
|
label: SHARE_SUBGROUP_LABELS[sk] || sk,
|
||||||
|
forceRender: true,
|
||||||
|
children: (
|
||||||
|
<div style={{ maxWidth: 720 }}>
|
||||||
|
{(bySub.get(sk) ?? []).map((f) =>
|
||||||
|
renderField(
|
||||||
|
f,
|
||||||
|
meta.configuredSecrets,
|
||||||
|
f.key === 'MOCK_SMS' && mockSmsEnabled ? (
|
||||||
|
<MockSmsCodePanel codes={meta.mockSmsCodes ?? []} loading={loading} />
|
||||||
|
) : undefined,
|
||||||
|
),
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
),
|
||||||
|
}))}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
children = (
|
||||||
|
<div style={{ maxWidth: 720 }}>
|
||||||
|
{fields.map((f) =>
|
||||||
|
renderField(
|
||||||
|
f,
|
||||||
|
meta.configuredSecrets,
|
||||||
|
f.key === 'MOCK_SMS' && mockSmsEnabled ? (
|
||||||
|
<MockSmsCodePanel codes={meta.mockSmsCodes ?? []} loading={loading} />
|
||||||
|
) : undefined,
|
||||||
),
|
),
|
||||||
|
|
||||||
)}
|
)}
|
||||||
|
</div>
|
||||||
</div>
|
);
|
||||||
|
|
||||||
),
|
|
||||||
|
|
||||||
}));
|
|
||||||
|
|
||||||
}, [meta, mockSmsEnabled, loading]);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
async function onSave() {
|
|
||||||
|
|
||||||
const values = await form.validateFields();
|
|
||||||
|
|
||||||
const payload: Record<string, string> = {};
|
|
||||||
|
|
||||||
for (const [k, v] of Object.entries(values)) {
|
|
||||||
|
|
||||||
payload[k] = v === undefined || v === null ? '' : String(v);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
setSaving(true);
|
|
||||||
|
|
||||||
try {
|
|
||||||
|
|
||||||
const res = await request<{ updatedKeys: string[]; requiresRestartKeys: string[] }>(
|
|
||||||
|
|
||||||
'/admin/system-config',
|
|
||||||
|
|
||||||
{ method: 'PUT', body: JSON.stringify({ values: payload }) },
|
|
||||||
|
|
||||||
);
|
|
||||||
|
|
||||||
message.success(`已保存 ${res.updatedKeys.length} 项`);
|
|
||||||
|
|
||||||
if (res.requiresRestartKeys.length) {
|
|
||||||
|
|
||||||
message.warning(`以下配置需重启 API 后生效:${res.requiresRestartKeys.join(', ')}`);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
await load();
|
return {
|
||||||
|
key: group.key,
|
||||||
} catch (e) {
|
label: group.label,
|
||||||
|
forceRender: true,
|
||||||
message.error(e instanceof Error ? e.message : '保存失败');
|
children,
|
||||||
|
};
|
||||||
} finally {
|
});
|
||||||
|
}, [meta, mockSmsEnabled, loading]);
|
||||||
setSaving(false);
|
|
||||||
|
|
||||||
|
async function onSave() {
|
||||||
|
await form.validateFields();
|
||||||
|
const values = form.getFieldsValue(true);
|
||||||
|
const payload: Record<string, string> = {};
|
||||||
|
for (const [k, v] of Object.entries(values)) {
|
||||||
|
payload[k] = v === undefined || v === null ? '' : String(v);
|
||||||
|
}
|
||||||
|
setSaving(true);
|
||||||
|
try {
|
||||||
|
const res = await request<{ updatedKeys: string[]; requiresRestartKeys: string[] }>(
|
||||||
|
'/admin/system-config',
|
||||||
|
{ method: 'PUT', body: JSON.stringify({ values: payload }) },
|
||||||
|
);
|
||||||
|
message.success(`已保存 ${res.updatedKeys.length} 项`);
|
||||||
|
if (res.requiresRestartKeys.length) {
|
||||||
|
message.warning(`以下配置需重启 API 后生效:${res.requiresRestartKeys.join(', ')}`);
|
||||||
|
}
|
||||||
|
setDirty(false);
|
||||||
|
await load();
|
||||||
|
} catch (e) {
|
||||||
|
message.error(e instanceof Error ? e.message : '保存失败');
|
||||||
|
} finally {
|
||||||
|
setSaving(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
async function onSyncEnv() {
|
async function onSyncEnv() {
|
||||||
|
|
||||||
setSyncing(true);
|
setSyncing(true);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
const res = await request<{ message: string; envFilePath: string }>(
|
const res = await request<{ message: string; envFilePath: string }>(
|
||||||
|
|
||||||
'/admin/system-config/sync-env',
|
'/admin/system-config/sync-env',
|
||||||
|
|
||||||
{ method: 'POST' },
|
{ method: 'POST' },
|
||||||
|
|
||||||
);
|
);
|
||||||
|
|
||||||
message.success(res.message || '已同步到 env 文件');
|
message.success(res.message || '已同步到 env 文件');
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
||||||
message.error(e instanceof Error ? e.message : '同步失败');
|
message.error(e instanceof Error ? e.message : '同步失败');
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
|
|
||||||
setSyncing(false);
|
setSyncing(false);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
async function onImportEnv() {
|
async function onImportEnv() {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
const res = await request<{ imported: number }>('/admin/system-config/import-env', {
|
const res = await request<{ imported: number }>('/admin/system-config/import-env', {
|
||||||
|
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
message.success(`已从当前进程环境导入 ${res.imported} 项`);
|
message.success(`已从当前进程环境导入 ${res.imported} 项`);
|
||||||
|
|
||||||
await load();
|
await load();
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
||||||
message.error(e instanceof Error ? e.message : '导入失败');
|
message.error(e instanceof Error ? e.message : '导入失败');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
<div style={{ paddingBottom: 88 }}>
|
||||||
<div>
|
|
||||||
|
|
||||||
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'flex-start', marginBottom: 16 }}>
|
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'flex-start', marginBottom: 16 }}>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
|
|
||||||
<Typography.Title level={4} style={{ margin: 0 }}>
|
<Typography.Title level={4} style={{ margin: 0 }}>
|
||||||
|
|
||||||
系统设置
|
系统设置
|
||||||
|
|
||||||
</Typography.Title>
|
</Typography.Title>
|
||||||
|
|
||||||
<Typography.Paragraph type="secondary" style={{ marginBottom: 0, marginTop: 8 }}>
|
<Typography.Paragraph type="secondary" style={{ marginBottom: 0, marginTop: 8 }}>
|
||||||
|
|
||||||
配置存于 <code>system_config</code> 表;保存后写入进程环境。可同步到{' '}
|
配置存于 <code>system_config</code> 表;保存后写入进程环境。可同步到{' '}
|
||||||
|
|
||||||
<code>{meta?.envFilePath ?? '.env'}</code> 以便部署持久化。
|
<code>{meta?.envFilePath ?? '.env'}</code> 以便部署持久化。
|
||||||
|
|
||||||
</Typography.Paragraph>
|
</Typography.Paragraph>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<Space>
|
<Space>
|
||||||
|
{profile?.adminRole === 'SUPER_ADMIN' ? (
|
||||||
<Button onClick={() => void onImportEnv()}>从环境导入</Button>
|
<>
|
||||||
|
<Button onClick={() => void onImportEnv()}>从环境导入</Button>
|
||||||
<Button loading={syncing} onClick={() => void onSyncEnv()}>
|
<Button loading={syncing} onClick={() => void onSyncEnv()}>
|
||||||
|
同步到 env 文件
|
||||||
同步到 env 文件
|
</Button>
|
||||||
|
</>
|
||||||
</Button>
|
) : null}
|
||||||
|
|
||||||
<Button type="primary" loading={saving} onClick={() => void onSave()}>
|
|
||||||
|
|
||||||
保存
|
|
||||||
|
|
||||||
</Button>
|
|
||||||
|
|
||||||
</Space>
|
</Space>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<Alert
|
<Alert
|
||||||
|
|
||||||
type="info"
|
type="info"
|
||||||
|
|
||||||
showIcon
|
showIcon
|
||||||
|
|
||||||
style={{ marginBottom: 16 }}
|
style={{ marginBottom: 16 }}
|
||||||
|
|
||||||
message="生效说明"
|
message="生效说明"
|
||||||
|
|
||||||
description={
|
description={
|
||||||
|
|
||||||
<ul style={{ margin: '8px 0 0', paddingLeft: 20 }}>
|
<ul style={{ margin: '8px 0 0', paddingLeft: 20 }}>
|
||||||
|
|
||||||
<li>
|
<li>
|
||||||
|
|
||||||
<Tag color="green">即时</Tag>:保存后写入 <code>process.env</code>,Mock 开关、短信模板等可立即生效。
|
<Tag color="green">即时</Tag>:保存后写入 <code>process.env</code>,Mock 开关、短信模板等可立即生效。
|
||||||
|
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
<li>
|
<li>
|
||||||
|
|
||||||
<Tag color="orange">需重启</Tag>:微信/OSS 密钥等集成凭证变更后,<strong>建议重启 API 进程</strong>。
|
<Tag color="orange">需重启</Tag>:微信/OSS 密钥等集成凭证变更后,<strong>建议重启 API 进程</strong>。
|
||||||
|
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
<li>OSS 始终走阿里云配置;凭证缺失时上传接口将直接报错。</li>
|
<li>OSS 始终走阿里云配置;凭证缺失时上传接口将直接报错。</li>
|
||||||
|
<li>修改后请点击右下角「保存」;未保存离开页面将提示确认。</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<Card loading={loading}>
|
<Card loading={loading}>
|
||||||
|
<Form form={form} layout="vertical" onValuesChange={() => setDirty(true)}>
|
||||||
<Form form={form} layout="vertical">
|
<Collapse defaultActiveKey={[]} items={collapseItems} />
|
||||||
|
|
||||||
<Collapse defaultActiveKey={meta?.groups.map((g) => g.key)} items={collapseItems} />
|
|
||||||
|
|
||||||
</Form>
|
</Form>
|
||||||
|
|
||||||
{meta?.updatedAt ? (
|
{meta?.updatedAt ? (
|
||||||
|
|
||||||
<Typography.Text type="secondary" style={{ display: 'block', marginTop: 16 }}>
|
<Typography.Text type="secondary" style={{ display: 'block', marginTop: 16 }}>
|
||||||
|
|
||||||
最近更新:{new Date(meta.updatedAt).toLocaleString()}
|
最近更新:{new Date(meta.updatedAt).toLocaleString()}
|
||||||
|
|
||||||
</Typography.Text>
|
</Typography.Text>
|
||||||
|
|
||||||
) : null}
|
) : null}
|
||||||
|
|
||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
position: 'fixed',
|
||||||
|
right: 32,
|
||||||
|
bottom: 32,
|
||||||
|
zIndex: 1000,
|
||||||
|
display: 'flex',
|
||||||
|
flexDirection: 'column',
|
||||||
|
alignItems: 'flex-end',
|
||||||
|
gap: 8,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{dirty ? <Tag color="orange">有未保存更改</Tag> : null}
|
||||||
|
<Button
|
||||||
|
type="primary"
|
||||||
|
size="large"
|
||||||
|
loading={saving}
|
||||||
|
onClick={() => void onSave()}
|
||||||
|
style={{
|
||||||
|
minWidth: 120,
|
||||||
|
boxShadow: '0 6px 16px rgba(0,0,0,0.18)',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
保存
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,687 @@
|
|||||||
|
import { useCallback, useEffect, useState } from 'react';
|
||||||
|
import {
|
||||||
|
Button,
|
||||||
|
Card,
|
||||||
|
Checkbox,
|
||||||
|
Descriptions,
|
||||||
|
Drawer,
|
||||||
|
Form,
|
||||||
|
Input,
|
||||||
|
Modal,
|
||||||
|
Popconfirm,
|
||||||
|
Select,
|
||||||
|
Space,
|
||||||
|
Table,
|
||||||
|
Tabs,
|
||||||
|
Tag,
|
||||||
|
Typography,
|
||||||
|
message,
|
||||||
|
} from 'antd';
|
||||||
|
import type { ColumnsType } from 'antd/es/table';
|
||||||
|
import { request, type Paginated } from '../lib/api';
|
||||||
|
import { fmtTime } from '../lib/constants';
|
||||||
|
|
||||||
|
const MOCK_KEYS = ['MOCK_SMS', 'MOCK_WECHAT', 'MOCK_PAY'] as const;
|
||||||
|
|
||||||
|
type PhoneRow = {
|
||||||
|
id: string;
|
||||||
|
phone: string;
|
||||||
|
note: string | null;
|
||||||
|
createdByHqId: string | null;
|
||||||
|
createdAt: string;
|
||||||
|
updatedAt: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
type AccountType = 'user' | 'store_account' | 'partner' | 'store' | 'order';
|
||||||
|
|
||||||
|
type LinkedPayload = {
|
||||||
|
phone: PhoneRow;
|
||||||
|
users: Array<{ id: string; userNo: string; phone: string | null; nickname: string | null; isTest: boolean; status: number }>;
|
||||||
|
storeAccounts: Array<{ id: string; phone: string; name: string; isTest: boolean; status: string }>;
|
||||||
|
partners: Array<{ id: string; phone: string; name: string; companyName: string | null; isTest: boolean; status: string }>;
|
||||||
|
stores: Array<{ id: string; name: string; phone: string; isTest: boolean; status: string }>;
|
||||||
|
};
|
||||||
|
|
||||||
|
const ACCOUNT_TYPE_OPTIONS: { value: AccountType; label: string }[] = [
|
||||||
|
{ value: 'user', label: 'C 端用户' },
|
||||||
|
{ value: 'store_account', label: '门店账号' },
|
||||||
|
{ value: 'partner', label: '合伙人' },
|
||||||
|
{ value: 'store', label: '门店' },
|
||||||
|
{ value: 'order', label: '订单' },
|
||||||
|
];
|
||||||
|
|
||||||
|
export default function TestWhitelistPage() {
|
||||||
|
const [mockSms, setMockSms] = useState(false);
|
||||||
|
const [mockWechat, setMockWechat] = useState(false);
|
||||||
|
const [mockPay, setMockPay] = useState(false);
|
||||||
|
const [mockLoading, setMockLoading] = useState(true);
|
||||||
|
const [mockSaving, setMockSaving] = useState(false);
|
||||||
|
|
||||||
|
const [phoneForm] = Form.useForm();
|
||||||
|
const [phones, setPhones] = useState<Paginated<PhoneRow> | null>(null);
|
||||||
|
const [phonesLoading, setPhonesLoading] = useState(false);
|
||||||
|
const [phonePage, setPhonePage] = useState(1);
|
||||||
|
const [phonePageSize, setPhonePageSize] = useState(20);
|
||||||
|
const [phoneFilters, setPhoneFilters] = useState<{ phone?: string }>({});
|
||||||
|
const [addOpen, setAddOpen] = useState(false);
|
||||||
|
const [addForm] = Form.useForm();
|
||||||
|
const [editOpen, setEditOpen] = useState(false);
|
||||||
|
const [editRow, setEditRow] = useState<PhoneRow | null>(null);
|
||||||
|
const [editForm] = Form.useForm();
|
||||||
|
const [migrating, setMigrating] = useState(false);
|
||||||
|
|
||||||
|
const [accountType, setAccountType] = useState<AccountType>('user');
|
||||||
|
const [accountPhone, setAccountPhone] = useState('');
|
||||||
|
const [accounts, setAccounts] = useState<Paginated<Record<string, unknown>> | null>(null);
|
||||||
|
const [accountsLoading, setAccountsLoading] = useState(false);
|
||||||
|
const [accountPage, setAccountPage] = useState(1);
|
||||||
|
const [accountPageSize, setAccountPageSize] = useState(20);
|
||||||
|
|
||||||
|
const [linkedOpen, setLinkedOpen] = useState(false);
|
||||||
|
const [linkedLoading, setLinkedLoading] = useState(false);
|
||||||
|
const [linked, setLinked] = useState<LinkedPayload | null>(null);
|
||||||
|
|
||||||
|
async function loadMockFlags() {
|
||||||
|
setMockLoading(true);
|
||||||
|
try {
|
||||||
|
const cfg = await request<{ mockSms: boolean; mockWechat: boolean; mockPay: boolean }>(
|
||||||
|
'/admin/test-whitelist/mock-flags',
|
||||||
|
);
|
||||||
|
setMockSms(!!cfg.mockSms);
|
||||||
|
setMockWechat(!!cfg.mockWechat);
|
||||||
|
setMockPay(!!cfg.mockPay);
|
||||||
|
} catch (e) {
|
||||||
|
message.error(e instanceof Error ? e.message : '加载 Mock 配置失败');
|
||||||
|
} finally {
|
||||||
|
setMockLoading(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function saveMockFlags(next: { MOCK_SMS?: boolean; MOCK_WECHAT?: boolean; MOCK_PAY?: boolean }) {
|
||||||
|
const body: { mockSms?: boolean; mockWechat?: boolean; mockPay?: boolean } = {};
|
||||||
|
if (next.MOCK_SMS !== undefined) body.mockSms = next.MOCK_SMS;
|
||||||
|
if (next.MOCK_WECHAT !== undefined) body.mockWechat = next.MOCK_WECHAT;
|
||||||
|
if (next.MOCK_PAY !== undefined) body.mockPay = next.MOCK_PAY;
|
||||||
|
setMockSaving(true);
|
||||||
|
try {
|
||||||
|
const cfg = await request<{ mockSms: boolean; mockWechat: boolean; mockPay: boolean }>(
|
||||||
|
'/admin/test-whitelist/mock-flags',
|
||||||
|
{
|
||||||
|
method: 'PUT',
|
||||||
|
body: JSON.stringify(body),
|
||||||
|
},
|
||||||
|
);
|
||||||
|
setMockSms(!!cfg.mockSms);
|
||||||
|
setMockWechat(!!cfg.mockWechat);
|
||||||
|
setMockPay(!!cfg.mockPay);
|
||||||
|
message.success('已保存');
|
||||||
|
} catch (e) {
|
||||||
|
message.error(e instanceof Error ? e.message : '保存失败');
|
||||||
|
await loadMockFlags();
|
||||||
|
} finally {
|
||||||
|
setMockSaving(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const loadPhones = useCallback(async () => {
|
||||||
|
setPhonesLoading(true);
|
||||||
|
try {
|
||||||
|
const qs = new URLSearchParams({
|
||||||
|
page: String(phonePage),
|
||||||
|
pageSize: String(phonePageSize),
|
||||||
|
});
|
||||||
|
if (phoneFilters.phone) qs.set('phone', phoneFilters.phone);
|
||||||
|
const res = await request<Paginated<PhoneRow>>(`/admin/test-whitelist/phones?${qs}`);
|
||||||
|
setPhones(res);
|
||||||
|
} catch (e) {
|
||||||
|
message.error(e instanceof Error ? e.message : '加载手机号名单失败');
|
||||||
|
} finally {
|
||||||
|
setPhonesLoading(false);
|
||||||
|
}
|
||||||
|
}, [phonePage, phonePageSize, phoneFilters]);
|
||||||
|
|
||||||
|
const loadAccounts = useCallback(async () => {
|
||||||
|
setAccountsLoading(true);
|
||||||
|
try {
|
||||||
|
const qs = new URLSearchParams({
|
||||||
|
type: accountType,
|
||||||
|
page: String(accountPage),
|
||||||
|
pageSize: String(accountPageSize),
|
||||||
|
});
|
||||||
|
if (accountPhone.trim()) qs.set('phone', accountPhone.trim());
|
||||||
|
const res = await request<Paginated<Record<string, unknown>>>(
|
||||||
|
`/admin/test-whitelist/accounts?${qs}`,
|
||||||
|
);
|
||||||
|
setAccounts(res);
|
||||||
|
} catch (e) {
|
||||||
|
message.error(e instanceof Error ? e.message : '加载测试账号失败');
|
||||||
|
} finally {
|
||||||
|
setAccountsLoading(false);
|
||||||
|
}
|
||||||
|
}, [accountType, accountPage, accountPageSize, accountPhone]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
void loadMockFlags();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
void loadPhones();
|
||||||
|
}, [loadPhones]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
void loadAccounts();
|
||||||
|
}, [loadAccounts]);
|
||||||
|
|
||||||
|
async function onAddPhone() {
|
||||||
|
const v = await addForm.validateFields();
|
||||||
|
try {
|
||||||
|
await request('/admin/test-whitelist/phones', {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify({ phone: v.phone, note: v.note || undefined }),
|
||||||
|
});
|
||||||
|
message.success('已添加');
|
||||||
|
setAddOpen(false);
|
||||||
|
addForm.resetFields();
|
||||||
|
setPhonePage(1);
|
||||||
|
void loadPhones();
|
||||||
|
void loadAccounts();
|
||||||
|
} catch (e) {
|
||||||
|
message.error(e instanceof Error ? e.message : '添加失败');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function onEditPhone() {
|
||||||
|
if (!editRow) return;
|
||||||
|
const v = await editForm.validateFields();
|
||||||
|
try {
|
||||||
|
await request(`/admin/test-whitelist/phones/${editRow.id}`, {
|
||||||
|
method: 'PATCH',
|
||||||
|
body: JSON.stringify({ note: v.note ?? null }),
|
||||||
|
});
|
||||||
|
message.success('已更新');
|
||||||
|
setEditOpen(false);
|
||||||
|
setEditRow(null);
|
||||||
|
void loadPhones();
|
||||||
|
} catch (e) {
|
||||||
|
message.error(e instanceof Error ? e.message : '更新失败');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function onDeletePhone(id: string) {
|
||||||
|
try {
|
||||||
|
await request(`/admin/test-whitelist/phones/${id}`, { method: 'DELETE' });
|
||||||
|
message.success('已删除');
|
||||||
|
void loadPhones();
|
||||||
|
void loadAccounts();
|
||||||
|
} catch (e) {
|
||||||
|
message.error(e instanceof Error ? e.message : '删除失败');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function onMigrate() {
|
||||||
|
setMigrating(true);
|
||||||
|
try {
|
||||||
|
const res = await request<{ importedCandidates: number; added: number }>(
|
||||||
|
'/admin/test-whitelist/migrate-visibility',
|
||||||
|
{ method: 'POST' },
|
||||||
|
);
|
||||||
|
message.success(
|
||||||
|
`导入完成:候选 ${res.importedCandidates} 个,新增 ${res.added} 个`,
|
||||||
|
);
|
||||||
|
void loadPhones();
|
||||||
|
void loadAccounts();
|
||||||
|
} catch (e) {
|
||||||
|
message.error(e instanceof Error ? e.message : '导入失败');
|
||||||
|
} finally {
|
||||||
|
setMigrating(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function openLinked(row: PhoneRow) {
|
||||||
|
setLinkedOpen(true);
|
||||||
|
setLinkedLoading(true);
|
||||||
|
setLinked(null);
|
||||||
|
try {
|
||||||
|
const res = await request<LinkedPayload>(`/admin/test-whitelist/phones/${row.id}/linked`);
|
||||||
|
setLinked(res);
|
||||||
|
} catch (e) {
|
||||||
|
message.error(e instanceof Error ? e.message : '加载关联失败');
|
||||||
|
setLinkedOpen(false);
|
||||||
|
} finally {
|
||||||
|
setLinkedLoading(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const phoneColumns: ColumnsType<PhoneRow> = [
|
||||||
|
{ title: '手机号', dataIndex: 'phone', width: 140 },
|
||||||
|
{
|
||||||
|
title: '备注',
|
||||||
|
dataIndex: 'note',
|
||||||
|
ellipsis: true,
|
||||||
|
render: (v) => v || '—',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '创建时间',
|
||||||
|
dataIndex: 'createdAt',
|
||||||
|
width: 170,
|
||||||
|
render: fmtTime,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '操作',
|
||||||
|
width: 220,
|
||||||
|
render: (_, row) => (
|
||||||
|
<Space size={0}>
|
||||||
|
<Button type="link" size="small" onClick={() => void openLinked(row)}>
|
||||||
|
关联账号
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
type="link"
|
||||||
|
size="small"
|
||||||
|
onClick={() => {
|
||||||
|
setEditRow(row);
|
||||||
|
editForm.setFieldsValue({ note: row.note ?? '' });
|
||||||
|
setEditOpen(true);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
编辑备注
|
||||||
|
</Button>
|
||||||
|
<Popconfirm
|
||||||
|
title="确认移出白名单?"
|
||||||
|
description="将同步清除该手机号关联账号的测试标记"
|
||||||
|
okText="确认"
|
||||||
|
cancelText="取消"
|
||||||
|
okButtonProps={{ danger: true }}
|
||||||
|
onConfirm={() => void onDeletePhone(row.id)}
|
||||||
|
>
|
||||||
|
<Button type="link" size="small" danger>
|
||||||
|
删除
|
||||||
|
</Button>
|
||||||
|
</Popconfirm>
|
||||||
|
</Space>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
function accountColumns(): ColumnsType<Record<string, unknown>> {
|
||||||
|
if (accountType === 'user') {
|
||||||
|
return [
|
||||||
|
{ title: '用户编号', dataIndex: 'userNo', width: 120 },
|
||||||
|
{ title: '昵称', dataIndex: 'nickname', width: 100, render: (v) => (v as string) || '—' },
|
||||||
|
{ title: '手机', dataIndex: 'phone', width: 120 },
|
||||||
|
{
|
||||||
|
title: '标记',
|
||||||
|
dataIndex: 'isTest',
|
||||||
|
width: 80,
|
||||||
|
render: (v) => (v ? <Tag color="orange">测试</Tag> : '—'),
|
||||||
|
},
|
||||||
|
{ title: '注册', dataIndex: 'createdAt', width: 170, render: (v) => fmtTime(v as string) },
|
||||||
|
];
|
||||||
|
}
|
||||||
|
if (accountType === 'store_account') {
|
||||||
|
return [
|
||||||
|
{ title: '姓名', dataIndex: 'name', width: 100 },
|
||||||
|
{ title: '手机', dataIndex: 'phone', width: 120 },
|
||||||
|
{ title: '状态', dataIndex: 'status', width: 90 },
|
||||||
|
{
|
||||||
|
title: '标记',
|
||||||
|
dataIndex: 'isTest',
|
||||||
|
width: 80,
|
||||||
|
render: (v) => (v ? <Tag color="orange">测试</Tag> : '—'),
|
||||||
|
},
|
||||||
|
{ title: '创建', dataIndex: 'createdAt', width: 170, render: (v) => fmtTime(v as string) },
|
||||||
|
];
|
||||||
|
}
|
||||||
|
if (accountType === 'partner') {
|
||||||
|
return [
|
||||||
|
{ title: '姓名', dataIndex: 'name', width: 100 },
|
||||||
|
{ title: '公司', dataIndex: 'companyName', ellipsis: true, render: (v) => (v as string) || '—' },
|
||||||
|
{ title: '手机', dataIndex: 'phone', width: 120 },
|
||||||
|
{
|
||||||
|
title: '标记',
|
||||||
|
dataIndex: 'isTest',
|
||||||
|
width: 80,
|
||||||
|
render: (v) => (v ? <Tag color="orange">测试</Tag> : '—'),
|
||||||
|
},
|
||||||
|
{ title: '创建', dataIndex: 'createdAt', width: 170, render: (v) => fmtTime(v as string) },
|
||||||
|
];
|
||||||
|
}
|
||||||
|
if (accountType === 'store') {
|
||||||
|
return [
|
||||||
|
{ title: '门店名', dataIndex: 'name', width: 160, ellipsis: true },
|
||||||
|
{ title: '城市', dataIndex: 'cityName', width: 90 },
|
||||||
|
{ title: '电话', dataIndex: 'phone', width: 120 },
|
||||||
|
{ title: '状态', dataIndex: 'status', width: 90 },
|
||||||
|
{
|
||||||
|
title: '标记',
|
||||||
|
dataIndex: 'isTest',
|
||||||
|
width: 80,
|
||||||
|
render: (v) => (v ? <Tag color="orange">测试</Tag> : '—'),
|
||||||
|
},
|
||||||
|
{ title: '创建', dataIndex: 'createdAt', width: 170, render: (v) => fmtTime(v as string) },
|
||||||
|
];
|
||||||
|
}
|
||||||
|
return [
|
||||||
|
{ title: '订单号', dataIndex: 'orderNo', width: 180 },
|
||||||
|
{ title: '状态', dataIndex: 'status', width: 110 },
|
||||||
|
{
|
||||||
|
title: '实付',
|
||||||
|
dataIndex: 'payAmount',
|
||||||
|
width: 90,
|
||||||
|
render: (v) => `¥${v}`,
|
||||||
|
},
|
||||||
|
{ title: '收货手机', dataIndex: 'receiverPhone', width: 120 },
|
||||||
|
{
|
||||||
|
title: '用户手机',
|
||||||
|
width: 120,
|
||||||
|
render: (_, row) =>
|
||||||
|
(row.user as { phone?: string | null } | undefined)?.phone || '—',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '标记',
|
||||||
|
dataIndex: 'isTest',
|
||||||
|
width: 80,
|
||||||
|
render: (v) => (v ? <Tag color="orange">测试</Tag> : '—'),
|
||||||
|
},
|
||||||
|
{ title: '下单', dataIndex: 'createdAt', width: 170, render: (v) => fmtTime(v as string) },
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<Typography.Title level={4} style={{ marginTop: 0 }}>
|
||||||
|
白名单管理
|
||||||
|
</Typography.Title>
|
||||||
|
|
||||||
|
<Card size="small" loading={mockLoading} style={{ marginBottom: 16 }}>
|
||||||
|
<Typography.Text type="secondary" style={{ display: 'block', marginBottom: 12 }}>
|
||||||
|
Mock 开关(与系统设置同源,勾选 = 不做真实验证)
|
||||||
|
</Typography.Text>
|
||||||
|
<Space wrap>
|
||||||
|
<Checkbox
|
||||||
|
checked={mockSms}
|
||||||
|
disabled={mockSaving}
|
||||||
|
onChange={(e) => void saveMockFlags({ MOCK_SMS: e.target.checked })}
|
||||||
|
>
|
||||||
|
短信不做真实验证
|
||||||
|
</Checkbox>
|
||||||
|
<Checkbox
|
||||||
|
checked={mockWechat}
|
||||||
|
disabled={mockSaving}
|
||||||
|
onChange={(e) => void saveMockFlags({ MOCK_WECHAT: e.target.checked })}
|
||||||
|
>
|
||||||
|
微信不做真实验证
|
||||||
|
</Checkbox>
|
||||||
|
<Checkbox
|
||||||
|
checked={mockPay}
|
||||||
|
disabled={mockSaving}
|
||||||
|
onChange={(e) => void saveMockFlags({ MOCK_PAY: e.target.checked })}
|
||||||
|
>
|
||||||
|
支付不做真实验证
|
||||||
|
</Checkbox>
|
||||||
|
</Space>
|
||||||
|
<Typography.Text type="secondary" style={{ display: 'block', marginTop: 8, fontSize: 12 }}>
|
||||||
|
配置键:{MOCK_KEYS.join(' / ')}
|
||||||
|
</Typography.Text>
|
||||||
|
</Card>
|
||||||
|
|
||||||
|
<Tabs
|
||||||
|
items={[
|
||||||
|
{
|
||||||
|
key: 'phones',
|
||||||
|
label: '手机号名单',
|
||||||
|
children: (
|
||||||
|
<>
|
||||||
|
<Space style={{ marginBottom: 16, width: '100%', justifyContent: 'space-between' }} wrap>
|
||||||
|
<Form
|
||||||
|
form={phoneForm}
|
||||||
|
layout="inline"
|
||||||
|
onFinish={(v) => {
|
||||||
|
setPhoneFilters({ phone: v.phone || undefined });
|
||||||
|
setPhonePage(1);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Form.Item name="phone" label="手机号">
|
||||||
|
<Input allowClear placeholder="模糊搜索" />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item>
|
||||||
|
<Button type="primary" htmlType="submit">
|
||||||
|
查询
|
||||||
|
</Button>
|
||||||
|
</Form.Item>
|
||||||
|
</Form>
|
||||||
|
<Space>
|
||||||
|
<Button
|
||||||
|
onClick={() => {
|
||||||
|
Modal.confirm({
|
||||||
|
title: '从可见性白名单导入',
|
||||||
|
content: '将商品/门店旧可见性手机号合并入全局名单(幂等),并同步测试标记。',
|
||||||
|
okText: '开始导入',
|
||||||
|
cancelText: '取消',
|
||||||
|
onOk: () => onMigrate(),
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
loading={migrating}
|
||||||
|
>
|
||||||
|
从可见性白名单导入
|
||||||
|
</Button>
|
||||||
|
<Button type="primary" onClick={() => setAddOpen(true)}>
|
||||||
|
添加手机号
|
||||||
|
</Button>
|
||||||
|
</Space>
|
||||||
|
</Space>
|
||||||
|
<Table
|
||||||
|
rowKey="id"
|
||||||
|
loading={phonesLoading}
|
||||||
|
columns={phoneColumns}
|
||||||
|
dataSource={phones?.items ?? []}
|
||||||
|
pagination={{
|
||||||
|
current: phonePage,
|
||||||
|
pageSize: phonePageSize,
|
||||||
|
total: phones?.total ?? 0,
|
||||||
|
showSizeChanger: true,
|
||||||
|
onChange: (p, ps) => {
|
||||||
|
setPhonePage(p);
|
||||||
|
setPhonePageSize(ps);
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'accounts',
|
||||||
|
label: '测试账号记录',
|
||||||
|
children: (
|
||||||
|
<>
|
||||||
|
<Space style={{ marginBottom: 16 }} wrap>
|
||||||
|
<Select
|
||||||
|
style={{ width: 140 }}
|
||||||
|
value={accountType}
|
||||||
|
options={ACCOUNT_TYPE_OPTIONS}
|
||||||
|
onChange={(v: AccountType) => {
|
||||||
|
setAccountType(v);
|
||||||
|
setAccountPage(1);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<Input
|
||||||
|
allowClear
|
||||||
|
placeholder="按手机号筛选"
|
||||||
|
style={{ width: 160 }}
|
||||||
|
value={accountPhone}
|
||||||
|
onChange={(e) => setAccountPhone(e.target.value)}
|
||||||
|
onPressEnter={() => {
|
||||||
|
setAccountPage(1);
|
||||||
|
void loadAccounts();
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<Button
|
||||||
|
type="primary"
|
||||||
|
onClick={() => {
|
||||||
|
if (accountPage !== 1) setAccountPage(1);
|
||||||
|
else void loadAccounts();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
查询
|
||||||
|
</Button>
|
||||||
|
</Space>
|
||||||
|
<Table
|
||||||
|
rowKey="id"
|
||||||
|
loading={accountsLoading}
|
||||||
|
columns={accountColumns()}
|
||||||
|
dataSource={accounts?.items ?? []}
|
||||||
|
scroll={{ x: 900 }}
|
||||||
|
pagination={{
|
||||||
|
current: accountPage,
|
||||||
|
pageSize: accountPageSize,
|
||||||
|
total: accounts?.total ?? 0,
|
||||||
|
showSizeChanger: true,
|
||||||
|
onChange: (p, ps) => {
|
||||||
|
setAccountPage(p);
|
||||||
|
setAccountPageSize(ps);
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Modal
|
||||||
|
title="添加白名单手机号"
|
||||||
|
open={addOpen}
|
||||||
|
onCancel={() => setAddOpen(false)}
|
||||||
|
onOk={() => void onAddPhone()}
|
||||||
|
destroyOnClose
|
||||||
|
>
|
||||||
|
<Form form={addForm} layout="vertical">
|
||||||
|
<Form.Item
|
||||||
|
name="phone"
|
||||||
|
label="手机号"
|
||||||
|
rules={[
|
||||||
|
{ required: true, message: '请输入手机号' },
|
||||||
|
{ pattern: /^1\d{10}$/, message: '请输入 11 位手机号' },
|
||||||
|
]}
|
||||||
|
>
|
||||||
|
<Input placeholder="1xxxxxxxxxx" maxLength={11} />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="note" label="备注">
|
||||||
|
<Input.TextArea rows={2} maxLength={256} showCount />
|
||||||
|
</Form.Item>
|
||||||
|
</Form>
|
||||||
|
</Modal>
|
||||||
|
|
||||||
|
<Modal
|
||||||
|
title={`编辑备注 · ${editRow?.phone ?? ''}`}
|
||||||
|
open={editOpen}
|
||||||
|
onCancel={() => {
|
||||||
|
setEditOpen(false);
|
||||||
|
setEditRow(null);
|
||||||
|
}}
|
||||||
|
onOk={() => void onEditPhone()}
|
||||||
|
destroyOnClose
|
||||||
|
>
|
||||||
|
<Form form={editForm} layout="vertical">
|
||||||
|
<Form.Item name="note" label="备注">
|
||||||
|
<Input.TextArea rows={2} maxLength={256} showCount />
|
||||||
|
</Form.Item>
|
||||||
|
</Form>
|
||||||
|
</Modal>
|
||||||
|
|
||||||
|
<Drawer
|
||||||
|
title={linked ? `关联账号 · ${linked.phone.phone}` : '关联账号'}
|
||||||
|
open={linkedOpen}
|
||||||
|
onClose={() => setLinkedOpen(false)}
|
||||||
|
width={560}
|
||||||
|
destroyOnClose
|
||||||
|
>
|
||||||
|
{linkedLoading ? (
|
||||||
|
<Typography.Text type="secondary">加载中…</Typography.Text>
|
||||||
|
) : linked ? (
|
||||||
|
<Space direction="vertical" size={16} style={{ width: '100%' }}>
|
||||||
|
<Descriptions size="small" column={1} bordered>
|
||||||
|
<Descriptions.Item label="手机号">{linked.phone.phone}</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="备注">{linked.phone.note || '—'}</Descriptions.Item>
|
||||||
|
</Descriptions>
|
||||||
|
<div>
|
||||||
|
<Typography.Title level={5}>C 端用户({linked.users.length})</Typography.Title>
|
||||||
|
<Table
|
||||||
|
size="small"
|
||||||
|
rowKey="id"
|
||||||
|
pagination={false}
|
||||||
|
dataSource={linked.users}
|
||||||
|
columns={[
|
||||||
|
{ title: '编号', dataIndex: 'userNo' },
|
||||||
|
{ title: '昵称', dataIndex: 'nickname', render: (v) => v || '—' },
|
||||||
|
{
|
||||||
|
title: '测试',
|
||||||
|
dataIndex: 'isTest',
|
||||||
|
width: 70,
|
||||||
|
render: (v) => (v ? <Tag color="orange">测试</Tag> : '—'),
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<Typography.Title level={5}>门店账号({linked.storeAccounts.length})</Typography.Title>
|
||||||
|
<Table
|
||||||
|
size="small"
|
||||||
|
rowKey="id"
|
||||||
|
pagination={false}
|
||||||
|
dataSource={linked.storeAccounts}
|
||||||
|
columns={[
|
||||||
|
{ title: '姓名', dataIndex: 'name' },
|
||||||
|
{ title: '状态', dataIndex: 'status', width: 90 },
|
||||||
|
{
|
||||||
|
title: '测试',
|
||||||
|
dataIndex: 'isTest',
|
||||||
|
width: 70,
|
||||||
|
render: (v) => (v ? <Tag color="orange">测试</Tag> : '—'),
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<Typography.Title level={5}>合伙人({linked.partners.length})</Typography.Title>
|
||||||
|
<Table
|
||||||
|
size="small"
|
||||||
|
rowKey="id"
|
||||||
|
pagination={false}
|
||||||
|
dataSource={linked.partners}
|
||||||
|
columns={[
|
||||||
|
{ title: '姓名', dataIndex: 'name' },
|
||||||
|
{ title: '公司', dataIndex: 'companyName', render: (v) => v || '—' },
|
||||||
|
{
|
||||||
|
title: '测试',
|
||||||
|
dataIndex: 'isTest',
|
||||||
|
width: 70,
|
||||||
|
render: (v) => (v ? <Tag color="orange">测试</Tag> : '—'),
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<Typography.Title level={5}>门店({linked.stores.length})</Typography.Title>
|
||||||
|
<Table
|
||||||
|
size="small"
|
||||||
|
rowKey="id"
|
||||||
|
pagination={false}
|
||||||
|
dataSource={linked.stores}
|
||||||
|
columns={[
|
||||||
|
{ title: '名称', dataIndex: 'name' },
|
||||||
|
{ title: '状态', dataIndex: 'status', width: 90 },
|
||||||
|
{
|
||||||
|
title: '测试',
|
||||||
|
dataIndex: 'isTest',
|
||||||
|
width: 70,
|
||||||
|
render: (v) => (v ? <Tag color="orange">测试</Tag> : '—'),
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</Space>
|
||||||
|
) : null}
|
||||||
|
</Drawer>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,7 +1,27 @@
|
|||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import { Button, Descriptions, Drawer, Form, Image, Input, Select, Table, Typography, message } from 'antd';
|
import {
|
||||||
|
Button,
|
||||||
|
Descriptions,
|
||||||
|
Drawer,
|
||||||
|
Form,
|
||||||
|
Image,
|
||||||
|
Input,
|
||||||
|
Modal,
|
||||||
|
Select,
|
||||||
|
Space,
|
||||||
|
Table,
|
||||||
|
Tag,
|
||||||
|
Typography,
|
||||||
|
message,
|
||||||
|
} from 'antd';
|
||||||
import type { ColumnsType } from 'antd/es/table';
|
import type { ColumnsType } from 'antd/es/table';
|
||||||
import { TICKET_TYPE_LABELS, type TicketTypeDto } from '@dukang/shared-types';
|
import {
|
||||||
|
TICKET_STATUS_LABELS,
|
||||||
|
TICKET_TYPE_LABELS,
|
||||||
|
ticketStatusLabel,
|
||||||
|
type TicketStatusDto,
|
||||||
|
type TicketTypeDto,
|
||||||
|
} from '@dukang/shared-types';
|
||||||
import { request } from '../lib/api';
|
import { request } from '../lib/api';
|
||||||
import { fmtTime } from '../lib/constants';
|
import { fmtTime } from '../lib/constants';
|
||||||
import { useAdminList } from '../lib/useAdminList';
|
import { useAdminList } from '../lib/useAdminList';
|
||||||
@@ -18,6 +38,21 @@ type Row = {
|
|||||||
createdAt: string;
|
createdAt: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const STATUS_COLOR: Partial<Record<TicketStatusDto, string>> = {
|
||||||
|
PENDING: 'orange',
|
||||||
|
OPEN: 'blue',
|
||||||
|
COLLABORATING: 'cyan',
|
||||||
|
RESOLVED: 'green',
|
||||||
|
REJECTED: 'red',
|
||||||
|
COMPLETED: 'green',
|
||||||
|
CLOSED: 'default',
|
||||||
|
};
|
||||||
|
|
||||||
|
const STATUS_OPTIONS = (Object.keys(TICKET_STATUS_LABELS) as TicketStatusDto[]).map((value) => ({
|
||||||
|
value,
|
||||||
|
label: TICKET_STATUS_LABELS[value],
|
||||||
|
}));
|
||||||
|
|
||||||
export default function TicketsPage() {
|
export default function TicketsPage() {
|
||||||
const [filters, setFilters] = useState<Record<string, string>>({});
|
const [filters, setFilters] = useState<Record<string, string>>({});
|
||||||
const { data, loading, page, pageSize, setPage, setPageSize, reload } = useAdminList<Row>(
|
const { data, loading, page, pageSize, setPage, setPageSize, reload } = useAdminList<Row>(
|
||||||
@@ -32,6 +67,13 @@ export default function TicketsPage() {
|
|||||||
);
|
);
|
||||||
const [detail, setDetail] = useState<Row | null>(null);
|
const [detail, setDetail] = useState<Row | null>(null);
|
||||||
const [drawerOpen, setDrawerOpen] = useState(false);
|
const [drawerOpen, setDrawerOpen] = useState(false);
|
||||||
|
const [createOpen, setCreateOpen] = useState(false);
|
||||||
|
const [creating, setCreating] = useState(false);
|
||||||
|
const [createForm] = Form.useForm<{
|
||||||
|
ticketType: TicketTypeDto;
|
||||||
|
orderNo: string;
|
||||||
|
remark?: string;
|
||||||
|
}>();
|
||||||
|
|
||||||
async function approve(id: string) {
|
async function approve(id: string) {
|
||||||
await request(`/admin/tickets/${id}/approve`, { method: 'POST', body: JSON.stringify({}) });
|
await request(`/admin/tickets/${id}/approve`, { method: 'POST', body: JSON.stringify({}) });
|
||||||
@@ -50,6 +92,29 @@ export default function TicketsPage() {
|
|||||||
setDrawerOpen(false);
|
setDrawerOpen(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function submitCreate() {
|
||||||
|
const values = await createForm.validateFields();
|
||||||
|
setCreating(true);
|
||||||
|
try {
|
||||||
|
await request('/admin/tickets', {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify({
|
||||||
|
ticketType: values.ticketType,
|
||||||
|
orderNo: values.orderNo.trim(),
|
||||||
|
remark: values.remark?.trim() || undefined,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
message.success('工单已创建');
|
||||||
|
setCreateOpen(false);
|
||||||
|
createForm.resetFields();
|
||||||
|
reload();
|
||||||
|
} catch (e) {
|
||||||
|
message.error(e instanceof Error ? e.message : '创建失败');
|
||||||
|
} finally {
|
||||||
|
setCreating(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const columns: ColumnsType<Row> = [
|
const columns: ColumnsType<Row> = [
|
||||||
{ title: '工单号', dataIndex: 'ticketNo', width: 180 },
|
{ title: '工单号', dataIndex: 'ticketNo', width: 180 },
|
||||||
{
|
{
|
||||||
@@ -58,7 +123,14 @@ export default function TicketsPage() {
|
|||||||
width: 110,
|
width: 110,
|
||||||
render: (t: TicketTypeDto) => TICKET_TYPE_LABELS[t] ?? t,
|
render: (t: TicketTypeDto) => TICKET_TYPE_LABELS[t] ?? t,
|
||||||
},
|
},
|
||||||
{ title: '状态', dataIndex: 'status', width: 90 },
|
{
|
||||||
|
title: '状态',
|
||||||
|
dataIndex: 'status',
|
||||||
|
width: 100,
|
||||||
|
render: (s: string) => (
|
||||||
|
<Tag color={STATUS_COLOR[s as TicketStatusDto] ?? 'default'}>{ticketStatusLabel(s)}</Tag>
|
||||||
|
),
|
||||||
|
},
|
||||||
{ title: '关联', width: 140, render: (_, r) => `${r.refType}#${r.refId}` },
|
{ title: '关联', width: 140, render: (_, r) => `${r.refType}#${r.refId}` },
|
||||||
{ title: '备注', dataIndex: 'remark', ellipsis: true },
|
{ title: '备注', dataIndex: 'remark', ellipsis: true },
|
||||||
{ title: '时间', dataIndex: 'createdAt', width: 160, render: fmtTime },
|
{ title: '时间', dataIndex: 'createdAt', width: 160, render: fmtTime },
|
||||||
@@ -84,7 +156,21 @@ export default function TicketsPage() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<Typography.Title level={4}>工单中心</Typography.Title>
|
<div
|
||||||
|
style={{
|
||||||
|
display: 'flex',
|
||||||
|
justifyContent: 'space-between',
|
||||||
|
alignItems: 'center',
|
||||||
|
marginBottom: 16,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Typography.Title level={4} style={{ margin: 0 }}>
|
||||||
|
工单中心
|
||||||
|
</Typography.Title>
|
||||||
|
<Button type="primary" onClick={() => setCreateOpen(true)}>
|
||||||
|
创建工单
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
<Form
|
<Form
|
||||||
layout="inline"
|
layout="inline"
|
||||||
style={{ marginBottom: 16 }}
|
style={{ marginBottom: 16 }}
|
||||||
@@ -102,12 +188,13 @@ export default function TicketsPage() {
|
|||||||
{ value: 'RESHIPMENT', label: '破损补发' },
|
{ value: 'RESHIPMENT', label: '破损补发' },
|
||||||
{ value: 'DAMAGE_RETURN', label: '破损退货' },
|
{ value: 'DAMAGE_RETURN', label: '破损退货' },
|
||||||
{ value: 'RETURN_REFUND', label: '退货退款' },
|
{ value: 'RETURN_REFUND', label: '退货退款' },
|
||||||
|
{ value: 'PACKAGE_DISPUTE', label: '套餐异议' },
|
||||||
{ value: 'ALERT', label: '异常' },
|
{ value: 'ALERT', label: '异常' },
|
||||||
]}
|
]}
|
||||||
/>
|
/>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item name="status" label="状态">
|
<Form.Item name="status" label="状态">
|
||||||
<Input allowClear placeholder="PENDING" />
|
<Select allowClear style={{ width: 140 }} placeholder="全部" options={STATUS_OPTIONS} />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Button type="primary" htmlType="submit">
|
<Button type="primary" htmlType="submit">
|
||||||
筛选
|
筛选
|
||||||
@@ -137,14 +224,14 @@ export default function TicketsPage() {
|
|||||||
onClose={() => setDrawerOpen(false)}
|
onClose={() => setDrawerOpen(false)}
|
||||||
extra={
|
extra={
|
||||||
detail && (detail.status === 'PENDING' || detail.status === 'OPEN') ? (
|
detail && (detail.status === 'PENDING' || detail.status === 'OPEN') ? (
|
||||||
<>
|
<Space>
|
||||||
<Button type="primary" onClick={() => approve(String(detail.id))} style={{ marginRight: 8 }}>
|
<Button type="primary" onClick={() => approve(String(detail.id))}>
|
||||||
通过
|
通过
|
||||||
</Button>
|
</Button>
|
||||||
<Button danger onClick={() => reject(String(detail.id))}>
|
<Button danger onClick={() => reject(String(detail.id))}>
|
||||||
驳回
|
驳回
|
||||||
</Button>
|
</Button>
|
||||||
</>
|
</Space>
|
||||||
) : null
|
) : null
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
@@ -154,7 +241,11 @@ export default function TicketsPage() {
|
|||||||
<Descriptions.Item label="类型">
|
<Descriptions.Item label="类型">
|
||||||
{TICKET_TYPE_LABELS[detail.ticketType] ?? detail.ticketType}
|
{TICKET_TYPE_LABELS[detail.ticketType] ?? detail.ticketType}
|
||||||
</Descriptions.Item>
|
</Descriptions.Item>
|
||||||
<Descriptions.Item label="状态">{String(detail.status)}</Descriptions.Item>
|
<Descriptions.Item label="状态">
|
||||||
|
<Tag color={STATUS_COLOR[detail.status as TicketStatusDto] ?? 'default'}>
|
||||||
|
{ticketStatusLabel(detail.status)}
|
||||||
|
</Tag>
|
||||||
|
</Descriptions.Item>
|
||||||
<Descriptions.Item label="关联">
|
<Descriptions.Item label="关联">
|
||||||
{String(detail.refType)} #{String(detail.refId)}
|
{String(detail.refType)} #{String(detail.refId)}
|
||||||
</Descriptions.Item>
|
</Descriptions.Item>
|
||||||
@@ -173,6 +264,44 @@ export default function TicketsPage() {
|
|||||||
</Descriptions>
|
</Descriptions>
|
||||||
)}
|
)}
|
||||||
</Drawer>
|
</Drawer>
|
||||||
|
|
||||||
|
<Modal
|
||||||
|
title="创建工单"
|
||||||
|
open={createOpen}
|
||||||
|
onCancel={() => setCreateOpen(false)}
|
||||||
|
onOk={() => void submitCreate()}
|
||||||
|
confirmLoading={creating}
|
||||||
|
destroyOnClose
|
||||||
|
okText="提交"
|
||||||
|
>
|
||||||
|
<Form form={createForm} layout="vertical" initialValues={{ ticketType: 'REFUND' }}>
|
||||||
|
<Form.Item
|
||||||
|
name="ticketType"
|
||||||
|
label="工单类型"
|
||||||
|
rules={[{ required: true, message: '请选择类型' }]}
|
||||||
|
>
|
||||||
|
<Select
|
||||||
|
options={[
|
||||||
|
{ value: 'REFUND', label: '仅退款' },
|
||||||
|
{ value: 'RESHIPMENT', label: '破损补发' },
|
||||||
|
{ value: 'DAMAGE_RETURN', label: '破损退货' },
|
||||||
|
{ value: 'RETURN_REFUND', label: '退货退款' },
|
||||||
|
{ value: 'ALERT', label: '异常' },
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item
|
||||||
|
name="orderNo"
|
||||||
|
label="订单号"
|
||||||
|
rules={[{ required: true, message: '请填写订单号' }]}
|
||||||
|
>
|
||||||
|
<Input placeholder="关联订单号" allowClear />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="remark" label="备注">
|
||||||
|
<Input.TextArea rows={3} placeholder="可选" maxLength={512} showCount />
|
||||||
|
</Form.Item>
|
||||||
|
</Form>
|
||||||
|
</Modal>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,9 +17,9 @@ import {
|
|||||||
message,
|
message,
|
||||||
} from 'antd';
|
} from 'antd';
|
||||||
import type { ColumnsType } from 'antd/es/table';
|
import type { ColumnsType } from 'antd/es/table';
|
||||||
import { USER_SOURCE_TYPE_LABELS, type UserSourceType } from '@dukang/shared-types';
|
import { USER_SOURCE_TYPE_LABELS, resolveUserLogCategory, type UserSourceType } from '@dukang/shared-types';
|
||||||
import { request, type AdminUserRow, type Paginated } from '../lib/api';
|
import { request, type AdminUserRow, type HqProfile, type Paginated } from '../lib/api';
|
||||||
import { ORDER_STATUS_LABELS, fmtTime } from '../lib/constants';
|
import { ORDER_STATUS_LABELS, fmtTime, maskPhone } from '../lib/constants';
|
||||||
|
|
||||||
type UserOrderRow = {
|
type UserOrderRow = {
|
||||||
id: string;
|
id: string;
|
||||||
@@ -30,6 +30,21 @@ type UserOrderRow = {
|
|||||||
createdAt: string;
|
createdAt: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** 好客权益金额展示:0 与空值统一显示占位,避免整列都是 ¥0.00 干扰 */
|
||||||
|
function fmtBenefit(v: number | null | undefined) {
|
||||||
|
const n = Number(v ?? 0);
|
||||||
|
if (!Number.isFinite(n) || n <= 0) return '—';
|
||||||
|
return `¥${n.toFixed(2)}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
type UserBehaviorLog = {
|
||||||
|
id: string;
|
||||||
|
eventName: string;
|
||||||
|
clientApp?: string | null;
|
||||||
|
createdAt: string;
|
||||||
|
extraJson?: Record<string, unknown> | null;
|
||||||
|
};
|
||||||
|
|
||||||
type UserDetail = AdminUserRow & {
|
type UserDetail = AdminUserRow & {
|
||||||
wxUnionId?: string | null;
|
wxUnionId?: string | null;
|
||||||
cityPref?: Record<string, unknown> | null;
|
cityPref?: Record<string, unknown> | null;
|
||||||
@@ -66,11 +81,13 @@ export default function UsersPage() {
|
|||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
const [form] = Form.useForm();
|
const [form] = Form.useForm();
|
||||||
|
const [profile, setProfile] = useState<HqProfile | null>(null);
|
||||||
const [data, setData] = useState<Paginated<AdminUserRow> | null>(null);
|
const [data, setData] = useState<Paginated<AdminUserRow> | null>(null);
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const [page, setPage] = useState(1);
|
const [page, setPage] = useState(1);
|
||||||
const [pageSize, setPageSize] = useState(20);
|
const [pageSize, setPageSize] = useState(20);
|
||||||
const [detail, setDetail] = useState<UserDetail | null>(null);
|
const [detail, setDetail] = useState<UserDetail | null>(null);
|
||||||
|
const [behaviorLogs, setBehaviorLogs] = useState<UserBehaviorLog[]>([]);
|
||||||
const [drawerOpen, setDrawerOpen] = useState(false);
|
const [drawerOpen, setDrawerOpen] = useState(false);
|
||||||
const [deleteOpen, setDeleteOpen] = useState(false);
|
const [deleteOpen, setDeleteOpen] = useState(false);
|
||||||
const [deleteConfirm, setDeleteConfirm] = useState('');
|
const [deleteConfirm, setDeleteConfirm] = useState('');
|
||||||
@@ -82,6 +99,11 @@ export default function UsersPage() {
|
|||||||
const [batchPreviewLoading, setBatchPreviewLoading] = useState(false);
|
const [batchPreviewLoading, setBatchPreviewLoading] = useState(false);
|
||||||
const [batchDeleting, setBatchDeleting] = useState(false);
|
const [batchDeleting, setBatchDeleting] = useState(false);
|
||||||
const [batchRiskAck, setBatchRiskAck] = useState(false);
|
const [batchRiskAck, setBatchRiskAck] = useState(false);
|
||||||
|
const canDeleteUsers = (profile?.permissionKeys ?? []).includes('users_delete');
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
request<HqProfile>('/admin/auth/me').then(setProfile).catch(() => {});
|
||||||
|
}, []);
|
||||||
|
|
||||||
const load = useCallback(async () => {
|
const load = useCallback(async () => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
@@ -97,6 +119,7 @@ export default function UsersPage() {
|
|||||||
if (values.status !== undefined && values.status !== '') {
|
if (values.status !== undefined && values.status !== '') {
|
||||||
qs.set('status', String(values.status));
|
qs.set('status', String(values.status));
|
||||||
}
|
}
|
||||||
|
if (values.excludeTest) qs.set('excludeTest', 'true');
|
||||||
const res = await request<Paginated<AdminUserRow>>(`/admin/users?${qs}`);
|
const res = await request<Paginated<AdminUserRow>>(`/admin/users?${qs}`);
|
||||||
setData(res);
|
setData(res);
|
||||||
} finally {
|
} finally {
|
||||||
@@ -117,8 +140,14 @@ export default function UsersPage() {
|
|||||||
}, [location.state, location.pathname, navigate]);
|
}, [location.state, location.pathname, navigate]);
|
||||||
|
|
||||||
async function openDetail(id: string) {
|
async function openDetail(id: string) {
|
||||||
const res = await request<UserDetail>(`/admin/users/${id}`);
|
const [res, logs] = await Promise.all([
|
||||||
|
request<UserDetail>(`/admin/users/${id}`),
|
||||||
|
request<{ items: UserBehaviorLog[] }>(`/admin/logs/users?userId=${id}&pageSize=50`).catch(
|
||||||
|
() => ({ items: [] as UserBehaviorLog[] }),
|
||||||
|
),
|
||||||
|
]);
|
||||||
setDetail(res);
|
setDetail(res);
|
||||||
|
setBehaviorLogs(logs.items ?? []);
|
||||||
setDrawerOpen(true);
|
setDrawerOpen(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -216,13 +245,23 @@ export default function UsersPage() {
|
|||||||
];
|
];
|
||||||
|
|
||||||
const columns: ColumnsType<AdminUserRow> = [
|
const columns: ColumnsType<AdminUserRow> = [
|
||||||
{ title: '用户编号', dataIndex: 'userNo', width: 120 },
|
{
|
||||||
|
title: '用户编号',
|
||||||
|
dataIndex: 'userNo',
|
||||||
|
width: 140,
|
||||||
|
render: (v, row) => (
|
||||||
|
<Space size={4}>
|
||||||
|
<span>{v}</span>
|
||||||
|
{row.isTest ? <Tag color="orange">测试</Tag> : null}
|
||||||
|
</Space>
|
||||||
|
),
|
||||||
|
},
|
||||||
{ title: '昵称', dataIndex: 'nickname', width: 100 },
|
{ title: '昵称', dataIndex: 'nickname', width: 100 },
|
||||||
{
|
{
|
||||||
title: '手机',
|
title: '手机',
|
||||||
dataIndex: 'phone',
|
dataIndex: 'phone',
|
||||||
width: 120,
|
width: 120,
|
||||||
render: (v) => v || '—',
|
render: (v) => maskPhone(v),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: '验手机',
|
title: '验手机',
|
||||||
@@ -283,6 +322,39 @@ export default function UsersPage() {
|
|||||||
render: (v) => (v ? <Tag color="blue">已合并</Tag> : '—'),
|
render: (v) => (v ? <Tag color="blue">已合并</Tag> : '—'),
|
||||||
},
|
},
|
||||||
{ title: '订单数', dataIndex: 'orderCount', width: 80 },
|
{ title: '订单数', dataIndex: 'orderCount', width: 80 },
|
||||||
|
{
|
||||||
|
title: '剩余权益',
|
||||||
|
dataIndex: 'benefitBalance',
|
||||||
|
width: 110,
|
||||||
|
align: 'right',
|
||||||
|
sorter: (a, b) => Number(a.benefitBalance ?? 0) - Number(b.benefitBalance ?? 0),
|
||||||
|
render: (v: number | undefined) =>
|
||||||
|
Number(v ?? 0) > 0 ? (
|
||||||
|
<Typography.Text strong style={{ color: '#cf1322' }}>
|
||||||
|
{fmtBenefit(v)}
|
||||||
|
</Typography.Text>
|
||||||
|
) : (
|
||||||
|
<Typography.Text type="secondary">—</Typography.Text>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '已用权益',
|
||||||
|
dataIndex: 'benefitUsedAmount',
|
||||||
|
width: 110,
|
||||||
|
align: 'right',
|
||||||
|
sorter: (a, b) => Number(a.benefitUsedAmount ?? 0) - Number(b.benefitUsedAmount ?? 0),
|
||||||
|
render: (v: number | undefined) => (
|
||||||
|
<Typography.Text type="secondary">{fmtBenefit(v)}</Typography.Text>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '累计权益',
|
||||||
|
dataIndex: 'benefitTotalAmount',
|
||||||
|
width: 110,
|
||||||
|
align: 'right',
|
||||||
|
sorter: (a, b) => Number(a.benefitTotalAmount ?? 0) - Number(b.benefitTotalAmount ?? 0),
|
||||||
|
render: (v: number | undefined) => fmtBenefit(v),
|
||||||
|
},
|
||||||
{
|
{
|
||||||
title: '注册时间',
|
title: '注册时间',
|
||||||
dataIndex: 'createdAt',
|
dataIndex: 'createdAt',
|
||||||
@@ -309,13 +381,15 @@ export default function UsersPage() {
|
|||||||
<div>
|
<div>
|
||||||
<Space style={{ marginBottom: 16, width: '100%', justifyContent: 'space-between' }}>
|
<Space style={{ marginBottom: 16, width: '100%', justifyContent: 'space-between' }}>
|
||||||
<Typography.Title level={4} style={{ margin: 0 }}>用户监控</Typography.Title>
|
<Typography.Title level={4} style={{ margin: 0 }}>用户监控</Typography.Title>
|
||||||
<Button
|
{canDeleteUsers ? (
|
||||||
danger
|
<Button
|
||||||
disabled={!selectedRowKeys.length}
|
danger
|
||||||
onClick={() => void openBatchDeleteModal()}
|
disabled={!selectedRowKeys.length}
|
||||||
>
|
onClick={() => void openBatchDeleteModal()}
|
||||||
批量删除{selectedRowKeys.length ? ` (${selectedRowKeys.length})` : ''}
|
>
|
||||||
</Button>
|
批量删除{selectedRowKeys.length ? ` (${selectedRowKeys.length})` : ''}
|
||||||
|
</Button>
|
||||||
|
) : null}
|
||||||
</Space>
|
</Space>
|
||||||
<Form form={form} layout="inline" style={{ marginBottom: 16 }} onFinish={() => { setPage(1); void load(); }}>
|
<Form form={form} layout="inline" style={{ marginBottom: 16 }} onFinish={() => { setPage(1); void load(); }}>
|
||||||
<Form.Item name="phone" label="手机号">
|
<Form.Item name="phone" label="手机号">
|
||||||
@@ -339,6 +413,9 @@ export default function UsersPage() {
|
|||||||
{ value: 0, label: '停用' },
|
{ value: 0, label: '停用' },
|
||||||
]} />
|
]} />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
|
<Form.Item name="excludeTest" valuePropName="checked">
|
||||||
|
<Checkbox>过滤测试账号</Checkbox>
|
||||||
|
</Form.Item>
|
||||||
<Form.Item>
|
<Form.Item>
|
||||||
<Space>
|
<Space>
|
||||||
<Button type="primary" htmlType="submit">查询</Button>
|
<Button type="primary" htmlType="submit">查询</Button>
|
||||||
@@ -352,12 +429,12 @@ export default function UsersPage() {
|
|||||||
loading={loading}
|
loading={loading}
|
||||||
columns={columns}
|
columns={columns}
|
||||||
dataSource={data?.items ?? []}
|
dataSource={data?.items ?? []}
|
||||||
scroll={{ x: 1500 }}
|
scroll={{ x: 1830 }}
|
||||||
rowSelection={{
|
rowSelection={canDeleteUsers ? {
|
||||||
selectedRowKeys,
|
selectedRowKeys,
|
||||||
preserveSelectedRowKeys: true,
|
preserveSelectedRowKeys: true,
|
||||||
onChange: (keys) => setSelectedRowKeys(keys as string[]),
|
onChange: (keys) => setSelectedRowKeys(keys as string[]),
|
||||||
}}
|
} : undefined}
|
||||||
pagination={{
|
pagination={{
|
||||||
current: page,
|
current: page,
|
||||||
pageSize,
|
pageSize,
|
||||||
@@ -375,9 +452,9 @@ export default function UsersPage() {
|
|||||||
width={640}
|
width={640}
|
||||||
open={drawerOpen}
|
open={drawerOpen}
|
||||||
onClose={() => setDrawerOpen(false)}
|
onClose={() => setDrawerOpen(false)}
|
||||||
extra={detail && (
|
extra={detail && canDeleteUsers ? (
|
||||||
<Button danger onClick={openDeleteModal}>删除用户</Button>
|
<Button danger onClick={openDeleteModal}>删除用户</Button>
|
||||||
)}
|
) : undefined}
|
||||||
>
|
>
|
||||||
{detail && (
|
{detail && (
|
||||||
<>
|
<>
|
||||||
@@ -385,7 +462,7 @@ export default function UsersPage() {
|
|||||||
<Descriptions.Item label="ID">{detail.id}</Descriptions.Item>
|
<Descriptions.Item label="ID">{detail.id}</Descriptions.Item>
|
||||||
<Descriptions.Item label="用户编号">{detail.userNo}</Descriptions.Item>
|
<Descriptions.Item label="用户编号">{detail.userNo}</Descriptions.Item>
|
||||||
<Descriptions.Item label="昵称">{detail.nickname || '—'}</Descriptions.Item>
|
<Descriptions.Item label="昵称">{detail.nickname || '—'}</Descriptions.Item>
|
||||||
<Descriptions.Item label="手机号">{detail.phone || '—'}</Descriptions.Item>
|
<Descriptions.Item label="手机号">{maskPhone(detail.phone)}</Descriptions.Item>
|
||||||
<Descriptions.Item label="验手机时间">
|
<Descriptions.Item label="验手机时间">
|
||||||
{detail.phoneVerifiedAt ? new Date(detail.phoneVerifiedAt).toLocaleString('zh-CN') : '未验证'}
|
{detail.phoneVerifiedAt ? new Date(detail.phoneVerifiedAt).toLocaleString('zh-CN') : '未验证'}
|
||||||
</Descriptions.Item>
|
</Descriptions.Item>
|
||||||
@@ -419,16 +496,50 @@ export default function UsersPage() {
|
|||||||
<Descriptions.Item label="deviceKey">{detail.deviceKey || '—'}</Descriptions.Item>
|
<Descriptions.Item label="deviceKey">{detail.deviceKey || '—'}</Descriptions.Item>
|
||||||
<Descriptions.Item label="合并至">
|
<Descriptions.Item label="合并至">
|
||||||
{detail.mergedInto
|
{detail.mergedInto
|
||||||
? `${detail.mergedInto.userNo} (${detail.mergedInto.phone || '无手机'})`
|
? `${detail.mergedInto.userNo} (${detail.mergedInto.phone ? maskPhone(detail.mergedInto.phone) : '无手机'})`
|
||||||
: '—'}
|
: '—'}
|
||||||
</Descriptions.Item>
|
</Descriptions.Item>
|
||||||
<Descriptions.Item label="被合并访客数">{detail.mergedFromCount ?? 0}</Descriptions.Item>
|
<Descriptions.Item label="被合并访客数">{detail.mergedFromCount ?? 0}</Descriptions.Item>
|
||||||
<Descriptions.Item label="订单/地址">{detail.orderCount} / {detail.addressCount}</Descriptions.Item>
|
<Descriptions.Item label="订单/地址">{detail.orderCount} / {detail.addressCount}</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="好客权益">
|
||||||
|
<Space size={16} wrap>
|
||||||
|
<span>
|
||||||
|
剩余{' '}
|
||||||
|
<Typography.Text strong style={{ color: '#cf1322' }}>
|
||||||
|
{fmtBenefit(detail.benefitBalance)}
|
||||||
|
</Typography.Text>
|
||||||
|
</span>
|
||||||
|
<span>已用 {fmtBenefit(detail.benefitUsedAmount)}</span>
|
||||||
|
<span>累计 {fmtBenefit(detail.benefitTotalAmount)}</span>
|
||||||
|
</Space>
|
||||||
|
</Descriptions.Item>
|
||||||
<Descriptions.Item label="注册时间">
|
<Descriptions.Item label="注册时间">
|
||||||
{new Date(detail.createdAt).toLocaleString('zh-CN')}
|
{new Date(detail.createdAt).toLocaleString('zh-CN')}
|
||||||
</Descriptions.Item>
|
</Descriptions.Item>
|
||||||
</Descriptions>
|
</Descriptions>
|
||||||
|
|
||||||
|
<Typography.Title level={5} style={{ marginTop: 16 }}>
|
||||||
|
行为时间线(最近 {behaviorLogs.length} 条)
|
||||||
|
</Typography.Title>
|
||||||
|
<Table
|
||||||
|
size="small"
|
||||||
|
rowKey="id"
|
||||||
|
pagination={false}
|
||||||
|
scroll={{ y: 200 }}
|
||||||
|
dataSource={behaviorLogs}
|
||||||
|
locale={{ emptyText: '暂无行为日志' }}
|
||||||
|
columns={[
|
||||||
|
{ title: '时间', dataIndex: 'createdAt', width: 160, render: (v) => fmtTime(v) },
|
||||||
|
{
|
||||||
|
title: '分类',
|
||||||
|
width: 100,
|
||||||
|
render: (_, r) => resolveUserLogCategory(r.eventName) ?? '—',
|
||||||
|
},
|
||||||
|
{ title: '事件', dataIndex: 'eventName' },
|
||||||
|
{ title: '端', dataIndex: 'clientApp', width: 90 },
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
|
||||||
<Typography.Title level={5} style={{ marginTop: 16 }}>
|
<Typography.Title level={5} style={{ marginTop: 16 }}>
|
||||||
全部订单({detail.orders?.length ?? 0})
|
全部订单({detail.orders?.length ?? 0})
|
||||||
</Typography.Title>
|
</Typography.Title>
|
||||||
@@ -593,7 +704,7 @@ export default function UsersPage() {
|
|||||||
columns={[
|
columns={[
|
||||||
{ title: '用户编号', dataIndex: 'userNo', width: 120 },
|
{ title: '用户编号', dataIndex: 'userNo', width: 120 },
|
||||||
{ title: '昵称', dataIndex: 'nickname', width: 100, render: (v) => v || '—' },
|
{ title: '昵称', dataIndex: 'nickname', width: 100, render: (v) => v || '—' },
|
||||||
{ title: '手机', dataIndex: 'phone', width: 120, render: (v) => v || '—' },
|
{ title: '手机', dataIndex: 'phone', width: 120, render: (v) => maskPhone(v) },
|
||||||
{
|
{
|
||||||
title: '风险',
|
title: '风险',
|
||||||
width: 200,
|
width: 200,
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import {
|
|||||||
import type { ColumnsType } from 'antd/es/table';
|
import type { ColumnsType } from 'antd/es/table';
|
||||||
import { request } from '../lib/api';
|
import { request } from '../lib/api';
|
||||||
import { AdminCellLine } from '../components/AdminCellLine';
|
import { AdminCellLine } from '../components/AdminCellLine';
|
||||||
import { fmtTime } from '../lib/constants';
|
import { fmtTime, maskPhone } from '../lib/constants';
|
||||||
import { useAdminList } from '../lib/useAdminList';
|
import { useAdminList } from '../lib/useAdminList';
|
||||||
|
|
||||||
type ActorType = 'USER' | 'STORE' | 'PARTNER' | 'HQ';
|
type ActorType = 'USER' | 'STORE' | 'PARTNER' | 'HQ';
|
||||||
@@ -119,7 +119,7 @@ export default function WechatBindingsPage() {
|
|||||||
title: '手机号',
|
title: '手机号',
|
||||||
dataIndex: 'primaryPhone',
|
dataIndex: 'primaryPhone',
|
||||||
width: 140,
|
width: 140,
|
||||||
render: (v) => v || '—',
|
render: (v) => maskPhone(v),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: '身份摘要',
|
title: '身份摘要',
|
||||||
@@ -128,7 +128,7 @@ export default function WechatBindingsPage() {
|
|||||||
<AdminCellLine
|
<AdminCellLine
|
||||||
primary={r.identities.map((i) => ACTOR_TYPE_LABELS[i.actorType]).join(' / ')}
|
primary={r.identities.map((i) => ACTOR_TYPE_LABELS[i.actorType]).join(' / ')}
|
||||||
secondary={r.identities
|
secondary={r.identities
|
||||||
.map((i) => i.refLabel || i.name || i.phone)
|
.map((i) => i.refLabel || i.name || (i.phone ? maskPhone(i.phone) : ''))
|
||||||
.filter(Boolean)
|
.filter(Boolean)
|
||||||
.join(' · ')}
|
.join(' · ')}
|
||||||
/>
|
/>
|
||||||
@@ -164,7 +164,7 @@ export default function WechatBindingsPage() {
|
|||||||
render: (_, r) => (
|
render: (_, r) => (
|
||||||
<AdminCellLine
|
<AdminCellLine
|
||||||
primary={r.name || '—'}
|
primary={r.name || '—'}
|
||||||
secondary={[r.phone, `#${r.actorId}`].filter(Boolean).join(' ')}
|
secondary={[r.phone ? maskPhone(r.phone) : null, `#${r.actorId}`].filter(Boolean).join(' ')}
|
||||||
/>
|
/>
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -0,0 +1,129 @@
|
|||||||
|
import { useState } from 'react';
|
||||||
|
import { Button, Descriptions, Drawer, Form, Input, Select, Space, Table, Tag, Typography } from 'antd';
|
||||||
|
import type { ColumnsType } from 'antd/es/table';
|
||||||
|
import { useAdminList } from '../lib/useAdminList';
|
||||||
|
import { request } from '../lib/api';
|
||||||
|
import { fmtTime } from '../lib/constants';
|
||||||
|
import type { WecomBotLogDto } from '@dukang/shared-types';
|
||||||
|
|
||||||
|
export default function WecomBotLogsPage() {
|
||||||
|
const [form] = Form.useForm();
|
||||||
|
const [filters, setFilters] = useState<Record<string, string>>({});
|
||||||
|
const [detail, setDetail] = useState<WecomBotLogDto | null>(null);
|
||||||
|
|
||||||
|
const { data, loading, page, pageSize, setPage, setPageSize } = useAdminList<WecomBotLogDto>(
|
||||||
|
'/admin/logs/wecom-bots',
|
||||||
|
() => {
|
||||||
|
const qs = new URLSearchParams();
|
||||||
|
if (filters.botId) qs.set('botId', filters.botId);
|
||||||
|
if (filters.wecomUserId) qs.set('wecomUserId', filters.wecomUserId);
|
||||||
|
if (filters.action) qs.set('action', filters.action);
|
||||||
|
if (filters.success) qs.set('success', filters.success);
|
||||||
|
return qs;
|
||||||
|
},
|
||||||
|
[filters],
|
||||||
|
);
|
||||||
|
|
||||||
|
const columns: ColumnsType<WecomBotLogDto> = [
|
||||||
|
{ title: '时间', dataIndex: 'createdAt', width: 160, render: fmtTime },
|
||||||
|
{ title: '机器人', dataIndex: 'botName', width: 120, ellipsis: true, render: (v, r) => v || r.botKey || '—' },
|
||||||
|
{ title: '企微用户', dataIndex: 'wecomUserId', width: 120, ellipsis: true },
|
||||||
|
{ title: '动作', dataIndex: 'action', width: 160, ellipsis: true },
|
||||||
|
{ title: '权限', dataIndex: 'permission', width: 140, ellipsis: true, render: (v) => v || '—' },
|
||||||
|
{
|
||||||
|
title: '结果',
|
||||||
|
dataIndex: 'success',
|
||||||
|
width: 80,
|
||||||
|
render: (v: boolean) => <Tag color={v ? 'green' : 'red'}>{v ? '成功' : '失败'}</Tag>,
|
||||||
|
},
|
||||||
|
{ title: '耗时(ms)', dataIndex: 'latencyMs', width: 90, render: (v) => v ?? '—' },
|
||||||
|
{ title: '输入摘要', dataIndex: 'inputSummary', ellipsis: true },
|
||||||
|
{
|
||||||
|
title: '操作',
|
||||||
|
width: 80,
|
||||||
|
render: (_, row) => (
|
||||||
|
<Button type="link" size="small" onClick={() => setDetail(row)}>
|
||||||
|
详情
|
||||||
|
</Button>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<Typography.Title level={4}>企微机器人日志</Typography.Title>
|
||||||
|
<Typography.Paragraph type="secondary">
|
||||||
|
记录机器人在企微内的查询与审批操作,含权限点、耗时与成败。
|
||||||
|
</Typography.Paragraph>
|
||||||
|
|
||||||
|
<Form
|
||||||
|
form={form}
|
||||||
|
layout="inline"
|
||||||
|
style={{ marginBottom: 16 }}
|
||||||
|
onFinish={(v) => {
|
||||||
|
setFilters(v);
|
||||||
|
setPage(1);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Form.Item name="botId" label="机器人 ID">
|
||||||
|
<Input allowClear placeholder="wecom_bot.id" style={{ width: 140 }} />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="wecomUserId" label="企微 userid">
|
||||||
|
<Input allowClear placeholder="userid" style={{ width: 140 }} />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="action" label="动作">
|
||||||
|
<Input allowClear placeholder="order.read" style={{ width: 140 }} />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="success" label="结果">
|
||||||
|
<Select
|
||||||
|
allowClear
|
||||||
|
style={{ width: 100 }}
|
||||||
|
options={[
|
||||||
|
{ value: 'true', label: '成功' },
|
||||||
|
{ value: 'false', label: '失败' },
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item>
|
||||||
|
<Button type="primary" htmlType="submit">
|
||||||
|
查询
|
||||||
|
</Button>
|
||||||
|
</Form.Item>
|
||||||
|
</Form>
|
||||||
|
|
||||||
|
<Table
|
||||||
|
rowKey="id"
|
||||||
|
loading={loading}
|
||||||
|
columns={columns}
|
||||||
|
dataSource={data?.items ?? []}
|
||||||
|
scroll={{ x: 1100 }}
|
||||||
|
pagination={{
|
||||||
|
current: page,
|
||||||
|
pageSize,
|
||||||
|
total: data?.total ?? 0,
|
||||||
|
showSizeChanger: true,
|
||||||
|
onChange: (p, ps) => {
|
||||||
|
setPage(p);
|
||||||
|
setPageSize(ps);
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Drawer title="日志详情" width={480} open={!!detail} onClose={() => setDetail(null)}>
|
||||||
|
{detail && (
|
||||||
|
<Descriptions column={1} size="small" bordered>
|
||||||
|
<Descriptions.Item label="时间">{fmtTime(detail.createdAt)}</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="机器人">{detail.botName || detail.botKey || '—'}</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="企微用户">{detail.wecomUserId}</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="动作">{detail.action}</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="权限">{detail.permission || '—'}</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="输入摘要">{detail.inputSummary || '—'}</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="结果">{detail.success ? '成功' : '失败'}</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="错误">{detail.errorMessage || '—'}</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="耗时">{detail.latencyMs != null ? `${detail.latencyMs} ms` : '—'}</Descriptions.Item>
|
||||||
|
</Descriptions>
|
||||||
|
)}
|
||||||
|
</Drawer>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,621 @@
|
|||||||
|
import { useEffect, useState } from 'react';
|
||||||
|
import {
|
||||||
|
Avatar,
|
||||||
|
Button,
|
||||||
|
Checkbox,
|
||||||
|
Descriptions,
|
||||||
|
Drawer,
|
||||||
|
Form,
|
||||||
|
Input,
|
||||||
|
InputNumber,
|
||||||
|
Modal,
|
||||||
|
Popconfirm,
|
||||||
|
Select,
|
||||||
|
Space,
|
||||||
|
Switch,
|
||||||
|
Table,
|
||||||
|
Tag,
|
||||||
|
Typography,
|
||||||
|
message,
|
||||||
|
} from 'antd';
|
||||||
|
import type { ColumnsType } from 'antd/es/table';
|
||||||
|
import {
|
||||||
|
WECOM_BOT_PERMISSION_GROUPS,
|
||||||
|
WECOM_BOT_PERMISSION_LABELS,
|
||||||
|
WECOM_BOT_ROLE_DEFAULT_PERMISSIONS,
|
||||||
|
WECOM_BOT_ROLE_LABELS,
|
||||||
|
WECOM_BOT_ROLES,
|
||||||
|
type LlmApiConfigOptionDto,
|
||||||
|
type KnowledgeBaseOptionDto,
|
||||||
|
type WecomAibotRuntimeDto,
|
||||||
|
type WecomBotDto,
|
||||||
|
type WecomBotPermission,
|
||||||
|
type WecomBotRole,
|
||||||
|
} from '@dukang/shared-types';
|
||||||
|
import { request } from '../lib/api';
|
||||||
|
import { fmtTime } from '../lib/constants';
|
||||||
|
import { useAdminList } from '../lib/useAdminList';
|
||||||
|
import OssUpload from '../components/OssUpload';
|
||||||
|
|
||||||
|
type FormValues = {
|
||||||
|
name: string;
|
||||||
|
role: WecomBotRole;
|
||||||
|
botId: string;
|
||||||
|
secret?: string;
|
||||||
|
avatarUrl?: string;
|
||||||
|
welcome?: string;
|
||||||
|
permissions: WecomBotPermission[];
|
||||||
|
reviewSuperAdminWecomUserIds?: string;
|
||||||
|
aiEnabled: boolean;
|
||||||
|
llmConfigId?: string | null;
|
||||||
|
knowledgeBaseId?: string | null;
|
||||||
|
enabled: boolean;
|
||||||
|
sortOrder: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
function parseUserIdLines(text?: string): string[] {
|
||||||
|
if (!text?.trim()) return [];
|
||||||
|
return [...new Set(text.split(/[,,\s\n]+/).map((s) => s.trim()).filter(Boolean))];
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatUserIdLines(ids?: string[]): string {
|
||||||
|
return (ids ?? []).join('\n');
|
||||||
|
}
|
||||||
|
|
||||||
|
function mapDtoToForm(row: WecomBotDto): FormValues {
|
||||||
|
return {
|
||||||
|
name: row.name,
|
||||||
|
role: row.role,
|
||||||
|
botId: row.botId,
|
||||||
|
secret: '',
|
||||||
|
avatarUrl: row.avatarUrl || '',
|
||||||
|
welcome: row.welcome || '',
|
||||||
|
permissions: [...row.permissions],
|
||||||
|
reviewSuperAdminWecomUserIds: formatUserIdLines(row.reviewSuperAdminWecomUserIds),
|
||||||
|
aiEnabled: row.aiEnabled,
|
||||||
|
llmConfigId: row.llmConfigId,
|
||||||
|
knowledgeBaseId: row.knowledgeBaseId,
|
||||||
|
enabled: row.enabled,
|
||||||
|
sortOrder: row.sortOrder,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function samePermissionSet(a: WecomBotPermission[], b: WecomBotPermission[]): boolean {
|
||||||
|
if (a.length !== b.length) return false;
|
||||||
|
const setB = new Set(b);
|
||||||
|
return a.every((p) => setB.has(p));
|
||||||
|
}
|
||||||
|
|
||||||
|
const CREATE_DEFAULTS: FormValues = {
|
||||||
|
name: '',
|
||||||
|
role: 'CUSTOMER_SERVICE',
|
||||||
|
botId: '',
|
||||||
|
secret: '',
|
||||||
|
avatarUrl: '',
|
||||||
|
welcome: '',
|
||||||
|
permissions: [...WECOM_BOT_ROLE_DEFAULT_PERMISSIONS.CUSTOMER_SERVICE],
|
||||||
|
reviewSuperAdminWecomUserIds: '',
|
||||||
|
aiEnabled: false,
|
||||||
|
llmConfigId: null,
|
||||||
|
knowledgeBaseId: null,
|
||||||
|
enabled: true,
|
||||||
|
sortOrder: 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function WecomBotsPage() {
|
||||||
|
const [filterForm] = Form.useForm();
|
||||||
|
const [form] = Form.useForm<FormValues>();
|
||||||
|
const [filters, setFilters] = useState<Record<string, string>>({});
|
||||||
|
const [modalOpen, setModalOpen] = useState(false);
|
||||||
|
const [editing, setEditing] = useState<WecomBotDto | null>(null);
|
||||||
|
const [formInitial, setFormInitial] = useState<FormValues | null>(null);
|
||||||
|
const [formReady, setFormReady] = useState(false);
|
||||||
|
const [saving, setSaving] = useState(false);
|
||||||
|
const [detail, setDetail] = useState<WecomBotDto | null>(null);
|
||||||
|
const [runtime, setRuntime] = useState<WecomAibotRuntimeDto>();
|
||||||
|
const [llmOptions, setLlmOptions] = useState<LlmApiConfigOptionDto[]>([]);
|
||||||
|
const [kbOptions, setKbOptions] = useState<KnowledgeBaseOptionDto[]>([]);
|
||||||
|
const roleWatch = Form.useWatch('role', form);
|
||||||
|
const permissionsWatch = Form.useWatch('permissions', form) as WecomBotPermission[] | undefined;
|
||||||
|
|
||||||
|
const { data, loading, page, pageSize, setPage, setPageSize, reload } = useAdminList<WecomBotDto>(
|
||||||
|
'/admin/wecom-bots',
|
||||||
|
() => {
|
||||||
|
const qs = new URLSearchParams();
|
||||||
|
if (filters.name) qs.set('name', filters.name);
|
||||||
|
if (filters.role) qs.set('role', filters.role);
|
||||||
|
if (filters.enabled) qs.set('enabled', filters.enabled);
|
||||||
|
return qs;
|
||||||
|
},
|
||||||
|
[filters],
|
||||||
|
);
|
||||||
|
|
||||||
|
const loadRuntime = () =>
|
||||||
|
request<WecomAibotRuntimeDto>('/admin/wecom-bots/runtime')
|
||||||
|
.then(setRuntime)
|
||||||
|
.catch(() => {});
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
void loadRuntime();
|
||||||
|
}, [data]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
void request<{
|
||||||
|
llmConfigs: LlmApiConfigOptionDto[];
|
||||||
|
knowledgeBases: KnowledgeBaseOptionDto[];
|
||||||
|
}>('/admin/wecom-bots/ai-options')
|
||||||
|
.then((res) => {
|
||||||
|
setLlmOptions(res.llmConfigs);
|
||||||
|
setKbOptions(res.knowledgeBases);
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
setLlmOptions([]);
|
||||||
|
setKbOptions([]);
|
||||||
|
});
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!modalOpen || !formReady || !formInitial) return;
|
||||||
|
form.resetFields();
|
||||||
|
form.setFieldsValue(formInitial);
|
||||||
|
}, [modalOpen, formReady, formInitial, form]);
|
||||||
|
|
||||||
|
function closeModal() {
|
||||||
|
setModalOpen(false);
|
||||||
|
setFormReady(false);
|
||||||
|
setFormInitial(null);
|
||||||
|
setEditing(null);
|
||||||
|
form.resetFields();
|
||||||
|
}
|
||||||
|
|
||||||
|
function openCreate() {
|
||||||
|
setEditing(null);
|
||||||
|
setFormInitial({ ...CREATE_DEFAULTS });
|
||||||
|
setFormReady(true);
|
||||||
|
setModalOpen(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function openEdit(row: WecomBotDto) {
|
||||||
|
setEditing(row);
|
||||||
|
setFormInitial(null);
|
||||||
|
setFormReady(false);
|
||||||
|
setModalOpen(true);
|
||||||
|
try {
|
||||||
|
const detail = await request<WecomBotDto>(`/admin/wecom-bots/${row.id}`);
|
||||||
|
setEditing(detail);
|
||||||
|
setFormInitial(mapDtoToForm(detail));
|
||||||
|
} catch (e) {
|
||||||
|
message.error(e instanceof Error ? e.message : '加载机器人详情失败');
|
||||||
|
setFormInitial(mapDtoToForm(row));
|
||||||
|
} finally {
|
||||||
|
setFormReady(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function submit() {
|
||||||
|
const values = await form.validateFields();
|
||||||
|
const permissions = (form.getFieldValue('permissions') ?? values.permissions) as WecomBotPermission[];
|
||||||
|
if (!permissions?.length) {
|
||||||
|
message.error('请至少选择一项权限');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setSaving(true);
|
||||||
|
try {
|
||||||
|
const payload = {
|
||||||
|
name: values.name.trim(),
|
||||||
|
role: values.role,
|
||||||
|
botId: values.botId.trim(),
|
||||||
|
avatarUrl: values.avatarUrl?.trim() || null,
|
||||||
|
welcome: values.welcome?.trim() || null,
|
||||||
|
permissions,
|
||||||
|
reviewSuperAdminWecomUserIds: parseUserIdLines(values.reviewSuperAdminWecomUserIds),
|
||||||
|
aiEnabled: values.aiEnabled,
|
||||||
|
llmConfigId: values.llmConfigId || null,
|
||||||
|
knowledgeBaseId: values.knowledgeBaseId || null,
|
||||||
|
enabled: values.enabled,
|
||||||
|
sortOrder: values.sortOrder,
|
||||||
|
};
|
||||||
|
if (editing) {
|
||||||
|
const saved = await request<WecomBotDto>(`/admin/wecom-bots/${editing.id}`, {
|
||||||
|
method: 'PUT',
|
||||||
|
body: JSON.stringify({
|
||||||
|
...payload,
|
||||||
|
secret: values.secret?.trim() || undefined,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
if (!samePermissionSet(permissions, saved.permissions)) {
|
||||||
|
message.warning('权限与保存结果不一致,已用服务端数据刷新表单');
|
||||||
|
setFormInitial(mapDtoToForm(saved));
|
||||||
|
setEditing(saved);
|
||||||
|
reload();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
message.success('已更新');
|
||||||
|
} else {
|
||||||
|
if (!values.secret?.trim()) {
|
||||||
|
message.error('请填写 Secret');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await request('/admin/wecom-bots', {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify({
|
||||||
|
...payload,
|
||||||
|
secret: values.secret.trim(),
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
message.success('已创建');
|
||||||
|
}
|
||||||
|
closeModal();
|
||||||
|
reload();
|
||||||
|
} catch (e) {
|
||||||
|
message.error(e instanceof Error ? e.message : '保存失败');
|
||||||
|
} finally {
|
||||||
|
setSaving(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function remove(id: string) {
|
||||||
|
try {
|
||||||
|
await request(`/admin/wecom-bots/${id}`, { method: 'DELETE' });
|
||||||
|
message.success('已删除');
|
||||||
|
reload();
|
||||||
|
} catch (e) {
|
||||||
|
message.error(e instanceof Error ? e.message : '删除失败');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function reloadConnections() {
|
||||||
|
try {
|
||||||
|
const st = await request<WecomAibotRuntimeDto>('/admin/wecom-bots/reload', {
|
||||||
|
method: 'POST',
|
||||||
|
body: '{}',
|
||||||
|
});
|
||||||
|
message.success('已重载长连接');
|
||||||
|
setRuntime(st);
|
||||||
|
reload();
|
||||||
|
} catch (e) {
|
||||||
|
message.error(e instanceof Error ? e.message : '重载失败');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const runtimeMap = new Map((runtime?.bots ?? []).map((b) => [b.id, b]));
|
||||||
|
|
||||||
|
const columns: ColumnsType<WecomBotDto> = [
|
||||||
|
{
|
||||||
|
title: '头像',
|
||||||
|
dataIndex: 'avatarUrl',
|
||||||
|
width: 64,
|
||||||
|
render: (url: string | null, row) => (
|
||||||
|
<Avatar src={url || undefined} shape="square" size={40}>
|
||||||
|
{row.name.slice(0, 1)}
|
||||||
|
</Avatar>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{ title: '名称', dataIndex: 'name', width: 140, ellipsis: true },
|
||||||
|
{
|
||||||
|
title: '角色',
|
||||||
|
dataIndex: 'role',
|
||||||
|
width: 120,
|
||||||
|
render: (r: WecomBotRole) => WECOM_BOT_ROLE_LABELS[r] || r,
|
||||||
|
},
|
||||||
|
{ title: 'BotID', dataIndex: 'botId', width: 160, ellipsis: true },
|
||||||
|
{
|
||||||
|
title: '权限',
|
||||||
|
dataIndex: 'permissions',
|
||||||
|
ellipsis: true,
|
||||||
|
render: (perms: WecomBotPermission[]) =>
|
||||||
|
perms.map((p) => (
|
||||||
|
<Tag key={p} style={{ marginBottom: 2 }}>
|
||||||
|
{WECOM_BOT_PERMISSION_LABELS[p] || p}
|
||||||
|
</Tag>
|
||||||
|
)),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'AI',
|
||||||
|
width: 100,
|
||||||
|
render: (_, row) =>
|
||||||
|
row.aiEnabled ? (
|
||||||
|
<Tag color="blue">{row.llmConfigName || '已开'}</Tag>
|
||||||
|
) : (
|
||||||
|
<Tag>关</Tag>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '启用',
|
||||||
|
dataIndex: 'enabled',
|
||||||
|
width: 70,
|
||||||
|
render: (v: boolean) => <Tag color={v ? 'green' : 'default'}>{v ? '是' : '否'}</Tag>,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '连接',
|
||||||
|
width: 80,
|
||||||
|
render: (_, row) => {
|
||||||
|
const rt = runtimeMap.get(row.id);
|
||||||
|
if (!runtime?.masterEnabled) return <Tag>总开关关</Tag>;
|
||||||
|
if (!row.enabled) return <Tag>未启用</Tag>;
|
||||||
|
return (
|
||||||
|
<Tag color={rt?.connected ? 'green' : 'orange'}>{rt?.connected ? '已连接' : '未连接'}</Tag>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{ title: '更新', dataIndex: 'updatedAt', width: 160, render: fmtTime },
|
||||||
|
{
|
||||||
|
title: '操作',
|
||||||
|
width: 180,
|
||||||
|
fixed: 'right',
|
||||||
|
render: (_, row) => (
|
||||||
|
<Space>
|
||||||
|
<Button type="link" size="small" onClick={() => void openEdit(row)}>
|
||||||
|
编辑
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
type="link"
|
||||||
|
size="small"
|
||||||
|
onClick={async () => {
|
||||||
|
setDetail(await request<WecomBotDto>(`/admin/wecom-bots/${row.id}`));
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
详情
|
||||||
|
</Button>
|
||||||
|
<Popconfirm title="确认删除该机器人?" onConfirm={() => remove(row.id)}>
|
||||||
|
<Button type="link" size="small" danger>
|
||||||
|
删除
|
||||||
|
</Button>
|
||||||
|
</Popconfirm>
|
||||||
|
</Space>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<Space style={{ width: '100%', justifyContent: 'space-between', marginBottom: 16 }} wrap>
|
||||||
|
<div>
|
||||||
|
<Typography.Title level={4} style={{ margin: 0 }}>
|
||||||
|
企微机器人
|
||||||
|
</Typography.Title>
|
||||||
|
<Typography.Text type="secondary">
|
||||||
|
并列创建多个智能机器人,配置 BotID / Secret / 权限 / 角色 / 头像。总开关在「系统设置 → 功能开关」。
|
||||||
|
{runtime ? ` 当前总开关:${runtime.masterEnabled ? '开' : '关'}` : ''}
|
||||||
|
</Typography.Text>
|
||||||
|
</div>
|
||||||
|
<Space>
|
||||||
|
<Button onClick={() => void reloadConnections()}>重载连接</Button>
|
||||||
|
<Button type="primary" onClick={openCreate}>
|
||||||
|
创建机器人
|
||||||
|
</Button>
|
||||||
|
</Space>
|
||||||
|
</Space>
|
||||||
|
|
||||||
|
<Form
|
||||||
|
form={filterForm}
|
||||||
|
layout="inline"
|
||||||
|
style={{ marginBottom: 16 }}
|
||||||
|
onFinish={(v) => {
|
||||||
|
setFilters(v);
|
||||||
|
setPage(1);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Form.Item name="name" label="名称">
|
||||||
|
<Input allowClear placeholder="名称" />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="role" label="角色">
|
||||||
|
<Select
|
||||||
|
allowClear
|
||||||
|
style={{ width: 160 }}
|
||||||
|
options={WECOM_BOT_ROLES.map((r) => ({ value: r, label: WECOM_BOT_ROLE_LABELS[r] }))}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="enabled" label="启用">
|
||||||
|
<Select
|
||||||
|
allowClear
|
||||||
|
style={{ width: 100 }}
|
||||||
|
options={[
|
||||||
|
{ value: 'true', label: '是' },
|
||||||
|
{ value: 'false', label: '否' },
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item>
|
||||||
|
<Button type="primary" htmlType="submit">
|
||||||
|
查询
|
||||||
|
</Button>
|
||||||
|
</Form.Item>
|
||||||
|
</Form>
|
||||||
|
|
||||||
|
<Table
|
||||||
|
rowKey="id"
|
||||||
|
loading={loading}
|
||||||
|
columns={columns}
|
||||||
|
dataSource={data?.items ?? []}
|
||||||
|
scroll={{ x: 1200 }}
|
||||||
|
pagination={{
|
||||||
|
current: page,
|
||||||
|
pageSize,
|
||||||
|
total: data?.total ?? 0,
|
||||||
|
showSizeChanger: true,
|
||||||
|
onChange: (p, ps) => {
|
||||||
|
setPage(p);
|
||||||
|
setPageSize(ps);
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Modal
|
||||||
|
title={editing ? '编辑企微机器人' : '创建企微机器人'}
|
||||||
|
open={modalOpen}
|
||||||
|
onCancel={closeModal}
|
||||||
|
onOk={() => void submit()}
|
||||||
|
confirmLoading={saving}
|
||||||
|
width={640}
|
||||||
|
destroyOnClose
|
||||||
|
>
|
||||||
|
{formReady && formInitial ? (
|
||||||
|
<Form
|
||||||
|
key={editing ? `edit-${editing.id}` : 'create'}
|
||||||
|
form={form}
|
||||||
|
layout="vertical"
|
||||||
|
preserve={false}
|
||||||
|
initialValues={formInitial}
|
||||||
|
>
|
||||||
|
<Form.Item name="name" label="名称" rules={[{ required: true, message: '请填写名称' }]}>
|
||||||
|
<Input placeholder="如:客服机器人" maxLength={64} />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="role" label="角色" rules={[{ required: true }]}>
|
||||||
|
<Select
|
||||||
|
options={WECOM_BOT_ROLES.map((r) => ({ value: r, label: WECOM_BOT_ROLE_LABELS[r] }))}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item>
|
||||||
|
<Button
|
||||||
|
size="small"
|
||||||
|
onClick={() => {
|
||||||
|
const role = form.getFieldValue('role') as WecomBotRole | undefined;
|
||||||
|
if (!role) return;
|
||||||
|
form.setFieldValue('permissions', [...WECOM_BOT_ROLE_DEFAULT_PERMISSIONS[role]]);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
应用当前角色默认权限
|
||||||
|
</Button>
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="avatarUrl" label="头像">
|
||||||
|
<OssUpload bizType="WECOM_BOT_AVATAR" />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="botId" label="BotID" rules={[{ required: true, message: '请填写 BotID' }]}>
|
||||||
|
<Input placeholder="企业微信后台长连接 BotID" />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item
|
||||||
|
name="secret"
|
||||||
|
label="Secret"
|
||||||
|
rules={editing ? [] : [{ required: true, message: '请填写 Secret' }]}
|
||||||
|
extra={editing ? '留空表示不修改' : undefined}
|
||||||
|
>
|
||||||
|
<Input.Password placeholder={editing ? '留空不修改' : '长连接专用 Secret'} />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item
|
||||||
|
name="permissions"
|
||||||
|
label="权限(按模块)"
|
||||||
|
rules={[
|
||||||
|
{
|
||||||
|
validator: (_, v: WecomBotPermission[] | undefined) =>
|
||||||
|
v?.length ? Promise.resolve() : Promise.reject(new Error('请至少选择一项权限')),
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
extra={
|
||||||
|
<>
|
||||||
|
{roleWatch
|
||||||
|
? `角色默认:${WECOM_BOT_ROLE_DEFAULT_PERMISSIONS[roleWatch as WecomBotRole]?.map((p) => WECOM_BOT_PERMISSION_LABELS[p]).join('、') || '无'}`
|
||||||
|
: null}
|
||||||
|
{permissionsWatch?.length ? (
|
||||||
|
<Typography.Text type="secondary"> · 已选 {permissionsWatch.length} 项</Typography.Text>
|
||||||
|
) : null}
|
||||||
|
</>
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<Checkbox.Group style={{ width: '100%' }}>
|
||||||
|
{WECOM_BOT_PERMISSION_GROUPS.map((group) => (
|
||||||
|
<div key={group.key} style={{ marginBottom: 12 }}>
|
||||||
|
<Typography.Text strong>{group.label}</Typography.Text>
|
||||||
|
<div style={{ marginTop: 4 }}>
|
||||||
|
{group.permissions.map((p) => (
|
||||||
|
<Checkbox key={p} value={p} style={{ marginInlineStart: 0, marginRight: 12 }}>
|
||||||
|
{WECOM_BOT_PERMISSION_LABELS[p]}
|
||||||
|
</Checkbox>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</Checkbox.Group>
|
||||||
|
</Form.Item>
|
||||||
|
{(roleWatch === 'TECH_SUPPORT' || permissionsWatch?.includes('support_ticket.review')) && (
|
||||||
|
<Form.Item
|
||||||
|
name="reviewSuperAdminWecomUserIds"
|
||||||
|
label="审批白名单(企微 userid)"
|
||||||
|
extra="填写成员企微 userid(如 woDacESQAAD…),不是姓名/昵称;每行或逗号分隔。发「状态」或在服务端日志 inbound user= 可核对"
|
||||||
|
>
|
||||||
|
<Input.TextArea rows={3} placeholder="zhangsan lisi" />
|
||||||
|
</Form.Item>
|
||||||
|
)}
|
||||||
|
<Form.Item name="welcome" label="欢迎语">
|
||||||
|
<Input.TextArea rows={3} placeholder="进入会话时的欢迎语,可空" />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item
|
||||||
|
name="aiEnabled"
|
||||||
|
label="启用 AI 问答"
|
||||||
|
valuePropName="checked"
|
||||||
|
extra="开启后,未匹配指令的自然语言将调用绑定的语言模型(可挂知识库)"
|
||||||
|
>
|
||||||
|
<Switch />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="llmConfigId" label="语言模型">
|
||||||
|
<Select
|
||||||
|
allowClear
|
||||||
|
placeholder="选择已生效的配置"
|
||||||
|
options={llmOptions.map((o) => ({
|
||||||
|
value: o.id,
|
||||||
|
label: `${o.name}(${o.modelName})`,
|
||||||
|
}))}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="knowledgeBaseId" label="知识库">
|
||||||
|
<Select
|
||||||
|
allowClear
|
||||||
|
placeholder="可选,供 AI 检索"
|
||||||
|
options={kbOptions.map((o) => ({
|
||||||
|
value: o.id,
|
||||||
|
label: `${o.name}(${o.documentCount} 篇)`,
|
||||||
|
}))}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
<Space size="large">
|
||||||
|
<Form.Item name="enabled" label="启用" valuePropName="checked">
|
||||||
|
<Switch />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="sortOrder" label="排序">
|
||||||
|
<InputNumber style={{ width: 120 }} />
|
||||||
|
</Form.Item>
|
||||||
|
</Space>
|
||||||
|
</Form>
|
||||||
|
) : (
|
||||||
|
<Typography.Text type="secondary">加载中…</Typography.Text>
|
||||||
|
)}
|
||||||
|
</Modal>
|
||||||
|
|
||||||
|
<Drawer title="机器人详情" width={480} open={!!detail} onClose={() => setDetail(null)}>
|
||||||
|
{detail && (
|
||||||
|
<Descriptions column={1} size="small" bordered>
|
||||||
|
<Descriptions.Item label="头像">
|
||||||
|
<Avatar src={detail.avatarUrl || undefined} size={64} shape="square">
|
||||||
|
{detail.name.slice(0, 1)}
|
||||||
|
</Avatar>
|
||||||
|
</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="名称">{detail.name}</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="角色">
|
||||||
|
{WECOM_BOT_ROLE_LABELS[detail.role] || detail.role}
|
||||||
|
</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="BotID">{detail.botId}</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="Secret">
|
||||||
|
{detail.secretConfigured ? '已配置' : '未配置'}
|
||||||
|
</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="权限">
|
||||||
|
{detail.permissions.map((p) => WECOM_BOT_PERMISSION_LABELS[p] || p).join('、')}
|
||||||
|
</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="审批白名单">
|
||||||
|
{detail.reviewSuperAdminWecomUserIds?.length
|
||||||
|
? detail.reviewSuperAdminWecomUserIds.join('、')
|
||||||
|
: '—'}
|
||||||
|
</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="欢迎语">{detail.welcome || '—'}</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="AI 问答">{detail.aiEnabled ? '开' : '关'}</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="语言模型">{detail.llmConfigName || '—'}</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="知识库">{detail.knowledgeBaseName || '—'}</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="启用">{detail.enabled ? '是' : '否'}</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="排序">{detail.sortOrder}</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="创建">{fmtTime(detail.createdAt)}</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="更新">{fmtTime(detail.updatedAt)}</Descriptions.Item>
|
||||||
|
</Descriptions>
|
||||||
|
)}
|
||||||
|
</Drawer>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,611 @@
|
|||||||
|
import { useCallback, useEffect, useState } from 'react';
|
||||||
|
import {
|
||||||
|
Avatar,
|
||||||
|
Button,
|
||||||
|
Checkbox,
|
||||||
|
Descriptions,
|
||||||
|
Form,
|
||||||
|
Input,
|
||||||
|
InputNumber,
|
||||||
|
Modal,
|
||||||
|
Popconfirm,
|
||||||
|
Select,
|
||||||
|
Space,
|
||||||
|
Switch,
|
||||||
|
Table,
|
||||||
|
Tabs,
|
||||||
|
Tag,
|
||||||
|
Typography,
|
||||||
|
message,
|
||||||
|
} from 'antd';
|
||||||
|
import type { ColumnsType } from 'antd/es/table';
|
||||||
|
import {
|
||||||
|
WECOM_PUSH_CONDITION_GROUPS,
|
||||||
|
WECOM_PUSH_CONDITION_LABELS,
|
||||||
|
WECOM_TEMPLATE_EVENT_KEYS,
|
||||||
|
WECOM_TEMPLATE_EVENT_LABELS,
|
||||||
|
WECOM_TEMPLATE_PLACEHOLDERS,
|
||||||
|
type WecomMessagePushDto,
|
||||||
|
type WecomPushCondition,
|
||||||
|
type WecomPushTemplateDto,
|
||||||
|
type WecomTemplateEventKey,
|
||||||
|
} from '@dukang/shared-types';
|
||||||
|
import { request } from '../lib/api';
|
||||||
|
import { fmtTime } from '../lib/constants';
|
||||||
|
import { useAdminList } from '../lib/useAdminList';
|
||||||
|
import OssUpload from '../components/OssUpload';
|
||||||
|
|
||||||
|
type FormValues = {
|
||||||
|
name: string;
|
||||||
|
avatarUrl?: string;
|
||||||
|
webhookUrl: string;
|
||||||
|
enabled: boolean;
|
||||||
|
mentionWecomUserId?: string;
|
||||||
|
pushConditions: WecomPushCondition[];
|
||||||
|
sortOrder: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
function WecomPushConditionPicker({
|
||||||
|
value,
|
||||||
|
onChange,
|
||||||
|
}: {
|
||||||
|
value?: WecomPushCondition[];
|
||||||
|
onChange?: (next: WecomPushCondition[]) => void;
|
||||||
|
}) {
|
||||||
|
const selected = new Set(value ?? []);
|
||||||
|
|
||||||
|
function toggle(cond: WecomPushCondition, checked: boolean) {
|
||||||
|
const next = new Set(selected);
|
||||||
|
if (checked) next.add(cond);
|
||||||
|
else next.delete(cond);
|
||||||
|
onChange?.([...next]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div style={{ width: '100%' }}>
|
||||||
|
{WECOM_PUSH_CONDITION_GROUPS.map((group) => (
|
||||||
|
<div key={group.key} style={{ marginBottom: 12 }}>
|
||||||
|
<Typography.Text strong>{group.label}</Typography.Text>
|
||||||
|
<div style={{ marginTop: 8 }}>
|
||||||
|
{group.conditions.map((c) => (
|
||||||
|
<div key={c}>
|
||||||
|
<Checkbox
|
||||||
|
checked={selected.has(c)}
|
||||||
|
onChange={(e) => toggle(c, e.target.checked)}
|
||||||
|
>
|
||||||
|
{WECOM_PUSH_CONDITION_LABELS[c]}
|
||||||
|
</Checkbox>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function PushRoutesTab() {
|
||||||
|
const [filterForm] = Form.useForm();
|
||||||
|
const [form] = Form.useForm<FormValues>();
|
||||||
|
const [filters, setFilters] = useState<Record<string, string>>({});
|
||||||
|
const [modalOpen, setModalOpen] = useState(false);
|
||||||
|
const [editing, setEditing] = useState<WecomMessagePushDto | null>(null);
|
||||||
|
const [saving, setSaving] = useState(false);
|
||||||
|
const [detail, setDetail] = useState<WecomMessagePushDto | null>(null);
|
||||||
|
const [testingId, setTestingId] = useState<string | null>(null);
|
||||||
|
|
||||||
|
const { data, loading, page, pageSize, setPage, setPageSize, reload } =
|
||||||
|
useAdminList<WecomMessagePushDto>(
|
||||||
|
'/admin/wecom-message-pushes',
|
||||||
|
() => {
|
||||||
|
const qs = new URLSearchParams();
|
||||||
|
if (filters.name) qs.set('name', filters.name);
|
||||||
|
if (filters.enabled) qs.set('enabled', filters.enabled);
|
||||||
|
return qs;
|
||||||
|
},
|
||||||
|
[filters],
|
||||||
|
);
|
||||||
|
|
||||||
|
const conditionsWatch = Form.useWatch('pushConditions', form) as WecomPushCondition[] | undefined;
|
||||||
|
|
||||||
|
function openCreate() {
|
||||||
|
setEditing(null);
|
||||||
|
form.resetFields();
|
||||||
|
form.setFieldsValue({
|
||||||
|
enabled: true,
|
||||||
|
pushConditions: ['alert.ops'],
|
||||||
|
sortOrder: 0,
|
||||||
|
});
|
||||||
|
setModalOpen(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
function openEdit(row: WecomMessagePushDto) {
|
||||||
|
setEditing(row);
|
||||||
|
form.setFieldsValue({
|
||||||
|
name: row.name,
|
||||||
|
avatarUrl: row.avatarUrl ?? undefined,
|
||||||
|
webhookUrl: row.webhookUrl,
|
||||||
|
enabled: row.enabled,
|
||||||
|
mentionWecomUserId: row.mentionWecomUserId ?? undefined,
|
||||||
|
pushConditions: row.pushConditions,
|
||||||
|
sortOrder: row.sortOrder,
|
||||||
|
});
|
||||||
|
setModalOpen(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function save() {
|
||||||
|
const values = await form.validateFields();
|
||||||
|
setSaving(true);
|
||||||
|
try {
|
||||||
|
const body = {
|
||||||
|
name: values.name,
|
||||||
|
avatarUrl: values.avatarUrl || null,
|
||||||
|
webhookUrl: values.webhookUrl,
|
||||||
|
enabled: values.enabled,
|
||||||
|
mentionWecomUserId: values.mentionWecomUserId?.trim() || null,
|
||||||
|
pushConditions: values.pushConditions,
|
||||||
|
sortOrder: values.sortOrder ?? 0,
|
||||||
|
};
|
||||||
|
if (editing) {
|
||||||
|
await request(`/admin/wecom-message-pushes/${editing.id}`, {
|
||||||
|
method: 'PUT',
|
||||||
|
body: JSON.stringify(body),
|
||||||
|
});
|
||||||
|
message.success('已更新');
|
||||||
|
} else {
|
||||||
|
await request('/admin/wecom-message-pushes', {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify(body),
|
||||||
|
});
|
||||||
|
message.success('已创建');
|
||||||
|
}
|
||||||
|
setModalOpen(false);
|
||||||
|
reload();
|
||||||
|
} catch (e) {
|
||||||
|
message.error(e instanceof Error ? e.message : '保存失败');
|
||||||
|
} finally {
|
||||||
|
setSaving(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function remove(id: string) {
|
||||||
|
try {
|
||||||
|
await request(`/admin/wecom-message-pushes/${id}`, { method: 'DELETE' });
|
||||||
|
message.success('已删除');
|
||||||
|
reload();
|
||||||
|
} catch (e) {
|
||||||
|
message.error(e instanceof Error ? e.message : '删除失败');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function testPush(id: string) {
|
||||||
|
setTestingId(id);
|
||||||
|
try {
|
||||||
|
const res = await request<{ ok: boolean; message: string }>(
|
||||||
|
`/admin/wecom-message-pushes/${id}/test`,
|
||||||
|
{ method: 'POST', body: '{}' },
|
||||||
|
);
|
||||||
|
message.success(res.message || '已发送测试消息');
|
||||||
|
} catch (e) {
|
||||||
|
message.error(e instanceof Error ? e.message : '测试失败');
|
||||||
|
} finally {
|
||||||
|
setTestingId(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const columns: ColumnsType<WecomMessagePushDto> = [
|
||||||
|
{
|
||||||
|
title: '名称',
|
||||||
|
dataIndex: 'name',
|
||||||
|
render: (name: string, row) => (
|
||||||
|
<Space>
|
||||||
|
<Avatar src={row.avatarUrl ?? undefined}>{name.slice(0, 1)}</Avatar>
|
||||||
|
<span>{name}</span>
|
||||||
|
</Space>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'Webhook',
|
||||||
|
dataIndex: 'webhookUrlMasked',
|
||||||
|
ellipsis: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '推送条件',
|
||||||
|
dataIndex: 'pushConditions',
|
||||||
|
render: (conds: WecomPushCondition[]) =>
|
||||||
|
conds.map((c) => (
|
||||||
|
<Tag key={c} style={{ marginBottom: 4 }}>
|
||||||
|
{WECOM_PUSH_CONDITION_LABELS[c]}
|
||||||
|
</Tag>
|
||||||
|
)),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '启用',
|
||||||
|
dataIndex: 'enabled',
|
||||||
|
width: 72,
|
||||||
|
render: (v: boolean) => (v ? <Tag color="green">是</Tag> : <Tag>否</Tag>),
|
||||||
|
},
|
||||||
|
{ title: '排序', dataIndex: 'sortOrder', width: 64 },
|
||||||
|
{
|
||||||
|
title: '操作',
|
||||||
|
key: 'actions',
|
||||||
|
width: 220,
|
||||||
|
render: (_, row) => (
|
||||||
|
<Space wrap>
|
||||||
|
<Button type="link" size="small" onClick={() => openEdit(row)}>
|
||||||
|
编辑
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
type="link"
|
||||||
|
size="small"
|
||||||
|
loading={testingId === row.id}
|
||||||
|
onClick={() => void testPush(row.id)}
|
||||||
|
>
|
||||||
|
测试
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
type="link"
|
||||||
|
size="small"
|
||||||
|
onClick={() => {
|
||||||
|
void request<WecomMessagePushDto>(`/admin/wecom-message-pushes/${row.id}`).then(setDetail);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
详情
|
||||||
|
</Button>
|
||||||
|
<Popconfirm title="确认删除?" onConfirm={() => void remove(row.id)}>
|
||||||
|
<Button type="link" size="small" danger>
|
||||||
|
删除
|
||||||
|
</Button>
|
||||||
|
</Popconfirm>
|
||||||
|
</Space>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Typography.Paragraph type="secondary">
|
||||||
|
配置群机器人 Webhook:按推送条件订阅业务通知 / 告警。运行时不再读取 .env 中的 Webhook URL。
|
||||||
|
</Typography.Paragraph>
|
||||||
|
|
||||||
|
<Form
|
||||||
|
form={filterForm}
|
||||||
|
layout="inline"
|
||||||
|
style={{ marginBottom: 16 }}
|
||||||
|
onFinish={(v) => setFilters(v as Record<string, string>)}
|
||||||
|
>
|
||||||
|
<Form.Item name="name" label="名称">
|
||||||
|
<Input allowClear placeholder="搜索" />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="enabled" label="启用">
|
||||||
|
<Select
|
||||||
|
allowClear
|
||||||
|
placeholder="全部"
|
||||||
|
style={{ width: 100 }}
|
||||||
|
options={[
|
||||||
|
{ value: 'true', label: '启用' },
|
||||||
|
{ value: 'false', label: '停用' },
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item>
|
||||||
|
<Space>
|
||||||
|
<Button type="primary" htmlType="submit">
|
||||||
|
查询
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
onClick={() => {
|
||||||
|
filterForm.resetFields();
|
||||||
|
setFilters({});
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
重置
|
||||||
|
</Button>
|
||||||
|
<Button type="primary" onClick={openCreate}>
|
||||||
|
新建推送
|
||||||
|
</Button>
|
||||||
|
</Space>
|
||||||
|
</Form.Item>
|
||||||
|
</Form>
|
||||||
|
|
||||||
|
<Table<WecomMessagePushDto>
|
||||||
|
rowKey="id"
|
||||||
|
loading={loading}
|
||||||
|
columns={columns}
|
||||||
|
dataSource={data?.items ?? []}
|
||||||
|
pagination={{
|
||||||
|
current: page,
|
||||||
|
pageSize,
|
||||||
|
total: data?.total ?? 0,
|
||||||
|
showSizeChanger: true,
|
||||||
|
onChange: (p, ps) => {
|
||||||
|
setPage(p);
|
||||||
|
setPageSize(ps);
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Modal
|
||||||
|
title={editing ? '编辑消息推送' : '新建消息推送'}
|
||||||
|
open={modalOpen}
|
||||||
|
onCancel={() => setModalOpen(false)}
|
||||||
|
onOk={() => void save()}
|
||||||
|
confirmLoading={saving}
|
||||||
|
width={640}
|
||||||
|
destroyOnClose
|
||||||
|
>
|
||||||
|
<Form form={form} layout="vertical">
|
||||||
|
<Form.Item name="name" label="名称" rules={[{ required: true, message: '请填写名称' }]}>
|
||||||
|
<Input placeholder="如:业务待办通知群" />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="avatarUrl" label="头像(HQ 列表展示)">
|
||||||
|
<OssUpload bizType="WECOM_BOT_AVATAR" />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item
|
||||||
|
name="webhookUrl"
|
||||||
|
label="Webhook URL"
|
||||||
|
rules={[{ required: true, message: '请填写 Webhook URL' }]}
|
||||||
|
>
|
||||||
|
<Input.Password placeholder="企微群机器人 Webhook" />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="enabled" label="启用" valuePropName="checked">
|
||||||
|
<Switch />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item
|
||||||
|
name="mentionWecomUserId"
|
||||||
|
label="企微 userid(可选)"
|
||||||
|
extra="markdown 推送用 <@userid> @ 群成员;任务派发等场景生效"
|
||||||
|
>
|
||||||
|
<Input placeholder="如 woDacESQAAD..." allowClear />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item
|
||||||
|
name="pushConditions"
|
||||||
|
label="推送条件"
|
||||||
|
rules={[
|
||||||
|
{
|
||||||
|
validator: (_, v: WecomPushCondition[] | undefined) =>
|
||||||
|
v?.length ? Promise.resolve() : Promise.reject(new Error('请至少勾选一项推送条件')),
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
>
|
||||||
|
<WecomPushConditionPicker />
|
||||||
|
</Form.Item>
|
||||||
|
{conditionsWatch?.length ? (
|
||||||
|
<Typography.Text type="secondary" style={{ display: 'block', marginBottom: 16 }}>
|
||||||
|
已选 {conditionsWatch.length} 项:
|
||||||
|
{conditionsWatch.map((c) => WECOM_PUSH_CONDITION_LABELS[c]).join('、')}
|
||||||
|
</Typography.Text>
|
||||||
|
) : null}
|
||||||
|
<Form.Item name="sortOrder" label="排序">
|
||||||
|
<InputNumber min={0} style={{ width: '100%' }} />
|
||||||
|
</Form.Item>
|
||||||
|
</Form>
|
||||||
|
</Modal>
|
||||||
|
|
||||||
|
<Modal
|
||||||
|
title="消息推送详情"
|
||||||
|
open={!!detail}
|
||||||
|
onCancel={() => setDetail(null)}
|
||||||
|
footer={null}
|
||||||
|
width={560}
|
||||||
|
>
|
||||||
|
{detail ? (
|
||||||
|
<Descriptions column={1} bordered size="small">
|
||||||
|
<Descriptions.Item label="名称">{detail.name}</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="Webhook">{detail.webhookUrlMasked}</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="启用">{detail.enabled ? '是' : '否'}</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="userid">{detail.mentionWecomUserId || '—'}</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="推送条件">
|
||||||
|
{detail.pushConditions.map((c) => WECOM_PUSH_CONDITION_LABELS[c]).join('、')}
|
||||||
|
</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="排序">{detail.sortOrder}</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="创建时间">{fmtTime(detail.createdAt)}</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="更新时间">{fmtTime(detail.updatedAt)}</Descriptions.Item>
|
||||||
|
</Descriptions>
|
||||||
|
) : null}
|
||||||
|
</Modal>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function TemplatesTab() {
|
||||||
|
const [templates, setTemplates] = useState<WecomPushTemplateDto[]>([]);
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
const [eventKey, setEventKey] = useState<WecomTemplateEventKey>('order.paid');
|
||||||
|
const [form] = Form.useForm<{ title: string; body: string; handleLabel: string }>();
|
||||||
|
const [saving, setSaving] = useState(false);
|
||||||
|
const [testing, setTesting] = useState(false);
|
||||||
|
const [preview, setPreview] = useState('');
|
||||||
|
|
||||||
|
const load = useCallback(async () => {
|
||||||
|
setLoading(true);
|
||||||
|
try {
|
||||||
|
const list = await request<WecomPushTemplateDto[]>('/admin/wecom-push-templates');
|
||||||
|
setTemplates(list);
|
||||||
|
setEventKey((prev) => {
|
||||||
|
const current = list.find((t) => t.eventKey === prev) ?? list[0];
|
||||||
|
if (current) {
|
||||||
|
form.setFieldsValue({
|
||||||
|
title: current.title,
|
||||||
|
body: current.body,
|
||||||
|
handleLabel: current.handleLabel,
|
||||||
|
});
|
||||||
|
return current.eventKey;
|
||||||
|
}
|
||||||
|
return prev;
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
message.error(e instanceof Error ? e.message : '加载模板失败');
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
}, [form]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
void load();
|
||||||
|
}, [load]);
|
||||||
|
|
||||||
|
function selectEvent(key: WecomTemplateEventKey) {
|
||||||
|
setEventKey(key);
|
||||||
|
const row = templates.find((t) => t.eventKey === key);
|
||||||
|
if (row) {
|
||||||
|
form.setFieldsValue({
|
||||||
|
title: row.title,
|
||||||
|
body: row.body,
|
||||||
|
handleLabel: row.handleLabel,
|
||||||
|
});
|
||||||
|
setPreview('');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function save() {
|
||||||
|
const values = await form.validateFields();
|
||||||
|
setSaving(true);
|
||||||
|
try {
|
||||||
|
const updated = await request<WecomPushTemplateDto>(
|
||||||
|
`/admin/wecom-push-templates/${eventKey}`,
|
||||||
|
{
|
||||||
|
method: 'PUT',
|
||||||
|
body: JSON.stringify(values),
|
||||||
|
},
|
||||||
|
);
|
||||||
|
message.success('模板已保存');
|
||||||
|
setTemplates((prev) => prev.map((t) => (t.eventKey === eventKey ? updated : t)));
|
||||||
|
} catch (e) {
|
||||||
|
message.error(e instanceof Error ? e.message : '保存失败');
|
||||||
|
} finally {
|
||||||
|
setSaving(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function reset() {
|
||||||
|
setSaving(true);
|
||||||
|
try {
|
||||||
|
const updated = await request<WecomPushTemplateDto>(
|
||||||
|
`/admin/wecom-push-templates/${eventKey}/reset`,
|
||||||
|
{ method: 'POST', body: '{}' },
|
||||||
|
);
|
||||||
|
message.success('已恢复默认文案');
|
||||||
|
form.setFieldsValue({
|
||||||
|
title: updated.title,
|
||||||
|
body: updated.body,
|
||||||
|
handleLabel: updated.handleLabel,
|
||||||
|
});
|
||||||
|
setTemplates((prev) => prev.map((t) => (t.eventKey === eventKey ? updated : t)));
|
||||||
|
setPreview('');
|
||||||
|
} catch (e) {
|
||||||
|
message.error(e instanceof Error ? e.message : '恢复失败');
|
||||||
|
} finally {
|
||||||
|
setSaving(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function testSend() {
|
||||||
|
setTesting(true);
|
||||||
|
try {
|
||||||
|
const res = await request<{ ok: boolean; message: string; preview: string }>(
|
||||||
|
`/admin/wecom-push-templates/${eventKey}/test`,
|
||||||
|
{ method: 'POST', body: '{}' },
|
||||||
|
);
|
||||||
|
setPreview(res.preview || '');
|
||||||
|
message.success(res.message || '已发送');
|
||||||
|
} catch (e) {
|
||||||
|
message.error(e instanceof Error ? e.message : '测试失败');
|
||||||
|
} finally {
|
||||||
|
setTesting(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const placeholders = WECOM_TEMPLATE_PLACEHOLDERS[eventKey] ?? [];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Typography.Paragraph type="secondary">
|
||||||
|
每种业务事件全站一份文案,使用 {'{{orderNo}}'} 等形式占位。快链由系统注入 {'{{handleUrl}}'}
|
||||||
|
;须在「推送路由」中勾选对应条件并配置 Webhook 才会发出。
|
||||||
|
</Typography.Paragraph>
|
||||||
|
|
||||||
|
<Space align="start" style={{ width: '100%' }} size={24} wrap>
|
||||||
|
<div style={{ minWidth: 200 }}>
|
||||||
|
<Typography.Text strong>事件</Typography.Text>
|
||||||
|
<div style={{ marginTop: 8 }}>
|
||||||
|
{WECOM_TEMPLATE_EVENT_KEYS.map((k) => (
|
||||||
|
<div key={k} style={{ marginBottom: 4 }}>
|
||||||
|
<Button
|
||||||
|
type={k === eventKey ? 'primary' : 'text'}
|
||||||
|
size="small"
|
||||||
|
onClick={() => selectEvent(k)}
|
||||||
|
block
|
||||||
|
style={{ textAlign: 'left' }}
|
||||||
|
>
|
||||||
|
{WECOM_TEMPLATE_EVENT_LABELS[k]}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div style={{ flex: 1, minWidth: 360 }}>
|
||||||
|
<Form form={form} layout="vertical" disabled={loading}>
|
||||||
|
<Form.Item name="title" label="标题(管理用)" rules={[{ required: true }]}>
|
||||||
|
<Input />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item
|
||||||
|
name="body"
|
||||||
|
label="正文(企微 markdown)"
|
||||||
|
rules={[{ required: true }]}
|
||||||
|
extra={`可用占位符:${placeholders.map((p) => `{{${p}}}`).join(' ')}`}
|
||||||
|
>
|
||||||
|
<Input.TextArea rows={12} style={{ fontFamily: 'monospace' }} />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="handleLabel" label="快链按钮文案" rules={[{ required: true }]}>
|
||||||
|
<Input placeholder="去处理" />
|
||||||
|
</Form.Item>
|
||||||
|
<Space wrap>
|
||||||
|
<Button type="primary" loading={saving} onClick={() => void save()}>
|
||||||
|
保存
|
||||||
|
</Button>
|
||||||
|
<Popconfirm title="恢复代码默认文案?将覆盖当前编辑" onConfirm={() => void reset()}>
|
||||||
|
<Button loading={saving}>恢复默认</Button>
|
||||||
|
</Popconfirm>
|
||||||
|
<Button loading={testing} onClick={() => void testSend()}>
|
||||||
|
用示例数据测试推送
|
||||||
|
</Button>
|
||||||
|
</Space>
|
||||||
|
</Form>
|
||||||
|
|
||||||
|
{preview ? (
|
||||||
|
<div style={{ marginTop: 16 }}>
|
||||||
|
<Typography.Text strong>预览</Typography.Text>
|
||||||
|
<pre
|
||||||
|
style={{
|
||||||
|
marginTop: 8,
|
||||||
|
padding: 12,
|
||||||
|
background: '#f5f5f5',
|
||||||
|
whiteSpace: 'pre-wrap',
|
||||||
|
borderRadius: 8,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{preview}
|
||||||
|
</pre>
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
</Space>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function WecomMessagePushesPage() {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<Typography.Title level={4}>企微机器人 · 消息推送</Typography.Title>
|
||||||
|
<Tabs
|
||||||
|
items={[
|
||||||
|
{ key: 'routes', label: '推送路由', children: <PushRoutesTab /> },
|
||||||
|
{ key: 'templates', label: '通知模板', children: <TemplatesTab /> },
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,9 +1,13 @@
|
|||||||
import { useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import {
|
import {
|
||||||
Button,
|
Button,
|
||||||
Card,
|
Card,
|
||||||
DatePicker,
|
DatePicker,
|
||||||
|
Descriptions,
|
||||||
|
Drawer,
|
||||||
Form,
|
Form,
|
||||||
|
Input,
|
||||||
|
Modal,
|
||||||
Select,
|
Select,
|
||||||
Space,
|
Space,
|
||||||
Statistic,
|
Statistic,
|
||||||
@@ -14,82 +18,213 @@ import {
|
|||||||
} from 'antd';
|
} from 'antd';
|
||||||
import type { ColumnsType } from 'antd/es/table';
|
import type { ColumnsType } from 'antd/es/table';
|
||||||
import type { Dayjs } from 'dayjs';
|
import type { Dayjs } from 'dayjs';
|
||||||
import { WINERY_SETTLEMENT_RATE } from '@dukang/shared-types';
|
import {
|
||||||
|
WINERY_SETTLEMENT_RATE,
|
||||||
|
type SystemConfigFormResponse,
|
||||||
|
} from '@dukang/shared-types';
|
||||||
import { fmtTime } from '../lib/constants';
|
import { fmtTime } from '../lib/constants';
|
||||||
import { downloadExcelCsv } from '../lib/exportExcel';
|
import { downloadExcelCsv } from '../lib/exportExcel';
|
||||||
import { request } from '../lib/api';
|
import { request, type HqProfile } from '../lib/api';
|
||||||
import { useAdminList } from '../lib/useAdminList';
|
import { useAdminList } from '../lib/useAdminList';
|
||||||
|
|
||||||
type Row = {
|
type Row = {
|
||||||
orderId: string;
|
id: string;
|
||||||
orderNo: string;
|
billNo: string;
|
||||||
deliveryType: string;
|
billDate: string;
|
||||||
cityName?: string;
|
orderCount: number;
|
||||||
receiverCity?: string;
|
orderAmount: number;
|
||||||
payAmount: number;
|
|
||||||
wineryRate: number;
|
wineryRate: number;
|
||||||
wineryAmount: number;
|
wineryAmount: number;
|
||||||
paidAt: string;
|
status: string;
|
||||||
productName?: string;
|
paidAt?: string | null;
|
||||||
quantity?: number;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
type BillItem = {
|
||||||
|
id: string;
|
||||||
|
orderNo: string;
|
||||||
|
deliveryType: string;
|
||||||
|
payAmount: number;
|
||||||
|
wineryAmount: number;
|
||||||
|
paidAt: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
const STATUS_LABELS: Record<string, string> = {
|
||||||
|
UNPAID: '未打款',
|
||||||
|
PAID: '已打款',
|
||||||
|
NO_PAYMENT_NEEDED: '无需打款',
|
||||||
|
};
|
||||||
|
|
||||||
|
const STATUS_COLORS: Record<string, string> = {
|
||||||
|
UNPAID: 'red',
|
||||||
|
PAID: 'green',
|
||||||
|
NO_PAYMENT_NEEDED: 'default',
|
||||||
|
};
|
||||||
|
|
||||||
|
function isZeroPayable(amount: number | string | null | undefined) {
|
||||||
|
return Number(amount ?? 0) === 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 应付为 0 时展示「无需打款」(灰),否则按 DB 打款状态 */
|
||||||
|
function displayWineryStatus(status: string, wineryAmount: number | string) {
|
||||||
|
if (isZeroPayable(wineryAmount)) {
|
||||||
|
return { key: 'NO_PAYMENT_NEEDED', label: STATUS_LABELS.NO_PAYMENT_NEEDED, color: STATUS_COLORS.NO_PAYMENT_NEEDED };
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
key: status,
|
||||||
|
label: STATUS_LABELS[status] || status,
|
||||||
|
color: STATUS_COLORS[status] || 'default',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function canConfirmWineryPay(row: { status: string; wineryAmount: number | string }) {
|
||||||
|
return row.status === 'UNPAID' && !isZeroPayable(row.wineryAmount);
|
||||||
|
}
|
||||||
|
|
||||||
const DELIVERY_LABELS: Record<string, string> = {
|
const DELIVERY_LABELS: Record<string, string> = {
|
||||||
LOCAL: '同城',
|
LOCAL: '同城',
|
||||||
CROSS_CITY: '跨城',
|
CROSS_CITY: '跨城',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const WINERY_BANK_KEYS = [
|
||||||
|
'WINERY_BANK_ACCOUNT_NAME',
|
||||||
|
'WINERY_BANK_NAME',
|
||||||
|
'WINERY_BANK_BRANCH',
|
||||||
|
'WINERY_BANK_ACCOUNT_NO',
|
||||||
|
] as const;
|
||||||
|
|
||||||
export default function WineryBillsPage() {
|
export default function WineryBillsPage() {
|
||||||
const [form] = Form.useForm();
|
const [form] = Form.useForm();
|
||||||
|
const [bankForm] = Form.useForm<Record<string, string>>();
|
||||||
const [filters, setFilters] = useState<Record<string, string>>({});
|
const [filters, setFilters] = useState<Record<string, string>>({});
|
||||||
const { data, loading, page, pageSize, setPage, setPageSize } = useAdminList<Row>(
|
const { data, loading, page, pageSize, setPage, setPageSize, reload } = useAdminList<Row>(
|
||||||
'/admin/winery-bills',
|
'/admin/winery-bills',
|
||||||
() => {
|
() => {
|
||||||
const qs = new URLSearchParams();
|
const qs = new URLSearchParams();
|
||||||
|
if (filters.status) qs.set('status', filters.status);
|
||||||
if (filters.year) qs.set('year', filters.year);
|
if (filters.year) qs.set('year', filters.year);
|
||||||
if (filters.month) qs.set('month', filters.month);
|
if (filters.month) qs.set('month', filters.month);
|
||||||
if (filters.deliveryType) qs.set('deliveryType', filters.deliveryType);
|
if (filters.dateFrom) qs.set('dateFrom', filters.dateFrom);
|
||||||
|
if (filters.dateTo) qs.set('dateTo', filters.dateTo);
|
||||||
return qs;
|
return qs;
|
||||||
},
|
},
|
||||||
[filters],
|
[filters],
|
||||||
);
|
);
|
||||||
const [exporting, setExporting] = useState(false);
|
const [exporting, setExporting] = useState(false);
|
||||||
|
const [selectedKeys, setSelectedKeys] = useState<React.Key[]>([]);
|
||||||
|
const [detail, setDetail] = useState<(Row & { items?: BillItem[] }) | null>(null);
|
||||||
|
const [drawerOpen, setDrawerOpen] = useState(false);
|
||||||
|
const [profile, setProfile] = useState<HqProfile | null>(null);
|
||||||
|
const [bankOpen, setBankOpen] = useState(false);
|
||||||
|
const [bankLoading, setBankLoading] = useState(false);
|
||||||
|
const [bankSaving, setBankSaving] = useState(false);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
request<HqProfile>('/admin/auth/me').then(setProfile).catch(() => {});
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const canEditWineryBank =
|
||||||
|
profile?.adminRole === 'SUPER_ADMIN' ||
|
||||||
|
(profile?.permissionKeys ?? []).includes('system_settings_winery_bank');
|
||||||
|
|
||||||
|
function confirmPay(ids: string[], amountHint?: number) {
|
||||||
|
Modal.confirm({
|
||||||
|
title: '确认打款?',
|
||||||
|
content: `将确认 ${ids.length} 笔酒厂对账单${amountHint != null ? `,合计约 ¥${amountHint.toFixed(2)}` : ''}。此操作不可撤销。`,
|
||||||
|
okText: '确认打款',
|
||||||
|
cancelText: '取消',
|
||||||
|
onOk: async () => {
|
||||||
|
if (ids.length === 1) {
|
||||||
|
await request(`/admin/winery-bills/${ids[0]}/confirm`, { method: 'POST' });
|
||||||
|
} else {
|
||||||
|
await request('/admin/winery-bills/batch-confirm', {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify({ ids }),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
message.success('已确认打款');
|
||||||
|
setSelectedKeys([]);
|
||||||
|
reload();
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async function openDetail(id: string) {
|
||||||
|
const d = await request<Row & { items?: BillItem[] }>(`/admin/winery-bills/${id}`);
|
||||||
|
setDetail(d);
|
||||||
|
setDrawerOpen(true);
|
||||||
|
}
|
||||||
|
|
||||||
async function exportExcel() {
|
async function exportExcel() {
|
||||||
setExporting(true);
|
setExporting(true);
|
||||||
try {
|
try {
|
||||||
const qs = new URLSearchParams();
|
const qs = new URLSearchParams();
|
||||||
|
if (filters.status) qs.set('status', filters.status);
|
||||||
if (filters.year) qs.set('year', filters.year);
|
if (filters.year) qs.set('year', filters.year);
|
||||||
if (filters.month) qs.set('month', filters.month);
|
if (filters.month) qs.set('month', filters.month);
|
||||||
if (filters.deliveryType) qs.set('deliveryType', filters.deliveryType);
|
if (filters.dateFrom) qs.set('dateFrom', filters.dateFrom);
|
||||||
|
if (filters.dateTo) qs.set('dateTo', filters.dateTo);
|
||||||
const result = await request<{ csv: string; count: number }>(`/admin/winery-bills/export?${qs}`);
|
const result = await request<{ csv: string; count: number }>(`/admin/winery-bills/export?${qs}`);
|
||||||
const suffix = filters.year && filters.month ? `${filters.year}-${filters.month}` : 'all';
|
const suffix = filters.year && filters.month ? `${filters.year}-${filters.month}` : 'all';
|
||||||
downloadExcelCsv(result.csv, `酒厂账单_${suffix}.csv`);
|
downloadExcelCsv(result.csv, `酒厂对账单_${suffix}.csv`);
|
||||||
message.success(`已导出 ${result.count} 条`);
|
message.success(`已导出 ${result.count} 条`);
|
||||||
} finally {
|
} finally {
|
||||||
setExporting(false);
|
setExporting(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function openBankModal() {
|
||||||
|
setBankOpen(true);
|
||||||
|
setBankLoading(true);
|
||||||
|
try {
|
||||||
|
const cfg = await request<SystemConfigFormResponse>('/admin/system-config');
|
||||||
|
const values: Record<string, string> = {};
|
||||||
|
for (const key of WINERY_BANK_KEYS) {
|
||||||
|
values[key] = cfg.values[key] ?? '';
|
||||||
|
}
|
||||||
|
bankForm.setFieldsValue(values);
|
||||||
|
} catch (e) {
|
||||||
|
message.error(e instanceof Error ? e.message : '加载失败');
|
||||||
|
setBankOpen(false);
|
||||||
|
} finally {
|
||||||
|
setBankLoading(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function saveBank() {
|
||||||
|
const values = await bankForm.validateFields();
|
||||||
|
setBankSaving(true);
|
||||||
|
try {
|
||||||
|
await request('/admin/system-config', {
|
||||||
|
method: 'PUT',
|
||||||
|
body: JSON.stringify({ values }),
|
||||||
|
});
|
||||||
|
message.success('酒厂银行账户已保存');
|
||||||
|
setBankOpen(false);
|
||||||
|
} catch (e) {
|
||||||
|
message.error(e instanceof Error ? e.message : '保存失败');
|
||||||
|
} finally {
|
||||||
|
setBankSaving(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const summary = data?.summary;
|
const summary = data?.summary;
|
||||||
const ratePct = Math.round(WINERY_SETTLEMENT_RATE * 100);
|
const ratePct = Math.round(WINERY_SETTLEMENT_RATE * 100);
|
||||||
|
const selectedRows = (data?.items ?? []).filter((r) => selectedKeys.includes(r.id));
|
||||||
|
const selectedAmount = selectedRows.reduce((s, r) => s + Number(r.wineryAmount), 0);
|
||||||
|
|
||||||
const columns: ColumnsType<Row> = [
|
const columns: ColumnsType<Row> = [
|
||||||
{ title: '订单号', dataIndex: 'orderNo', width: 180, ellipsis: true },
|
{ title: '账单号', dataIndex: 'billNo', width: 170, ellipsis: true },
|
||||||
{
|
{
|
||||||
title: '配送类型',
|
title: '账单日',
|
||||||
dataIndex: 'deliveryType',
|
dataIndex: 'billDate',
|
||||||
width: 90,
|
|
||||||
render: (v) => <Tag>{DELIVERY_LABELS[v] || v}</Tag>,
|
|
||||||
},
|
|
||||||
{ title: '开城城市', dataIndex: 'cityName', width: 100, render: (v) => v || '—' },
|
|
||||||
{ title: '收货城市', dataIndex: 'receiverCity', width: 100, render: (v) => v || '—' },
|
|
||||||
{ title: '商品', dataIndex: 'productName', width: 140, ellipsis: true },
|
|
||||||
{ title: '数量', dataIndex: 'quantity', width: 70 },
|
|
||||||
{
|
|
||||||
title: '酒单实付',
|
|
||||||
dataIndex: 'payAmount',
|
|
||||||
width: 110,
|
width: 110,
|
||||||
|
render: (v) => String(v || '').slice(0, 10),
|
||||||
|
},
|
||||||
|
{ title: '订单数', dataIndex: 'orderCount', width: 80 },
|
||||||
|
{
|
||||||
|
title: '酒单实付合计',
|
||||||
|
dataIndex: 'orderAmount',
|
||||||
|
width: 120,
|
||||||
render: (v) => `¥${Number(v).toFixed(2)}`,
|
render: (v) => `¥${Number(v).toFixed(2)}`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -99,36 +234,72 @@ export default function WineryBillsPage() {
|
|||||||
render: (v) => `${Math.round(Number(v) * 100)}%`,
|
render: (v) => `${Math.round(Number(v) * 100)}%`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: '酒厂应付',
|
title: '应付',
|
||||||
dataIndex: 'wineryAmount',
|
dataIndex: 'wineryAmount',
|
||||||
width: 110,
|
width: 110,
|
||||||
render: (v) => `¥${Number(v).toFixed(2)}`,
|
render: (v) => `¥${Number(v).toFixed(2)}`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: '支付时间',
|
title: '状态',
|
||||||
dataIndex: 'paidAt',
|
dataIndex: 'status',
|
||||||
width: 170,
|
width: 100,
|
||||||
render: (v) => (v ? fmtTime(v) : '—'),
|
render: (s, row) => {
|
||||||
|
const d = displayWineryStatus(s, row.wineryAmount);
|
||||||
|
return <Tag color={d.color}>{d.label}</Tag>;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '操作',
|
||||||
|
width: 160,
|
||||||
|
fixed: 'right',
|
||||||
|
render: (_, row) => (
|
||||||
|
<Space size={0}>
|
||||||
|
<Button type="link" size="small" onClick={() => void openDetail(row.id)}>
|
||||||
|
明细
|
||||||
|
</Button>
|
||||||
|
{canConfirmWineryPay(row) && (
|
||||||
|
<Button type="link" size="small" onClick={() => confirmPay([row.id], Number(row.wineryAmount))}>
|
||||||
|
确认打款
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
</Space>
|
||||||
|
),
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<Space direction="vertical" size={0} style={{ marginBottom: 16 }}>
|
<div
|
||||||
<Typography.Title level={4} style={{ margin: 0 }}>
|
style={{
|
||||||
酒厂账单
|
display: 'flex',
|
||||||
</Typography.Title>
|
justifyContent: 'space-between',
|
||||||
<Typography.Text type="secondary">
|
alignItems: 'flex-start',
|
||||||
T+30 结算:按自然月列出同城/跨城已付酒单,应付 = 酒单实付 × {ratePct}%(暂定)
|
marginBottom: 16,
|
||||||
</Typography.Text>
|
gap: 16,
|
||||||
</Space>
|
}}
|
||||||
|
>
|
||||||
|
<Space direction="vertical" size={0}>
|
||||||
|
<Typography.Title level={4} style={{ margin: 0 }}>
|
||||||
|
酒厂对账单
|
||||||
|
</Typography.Title>
|
||||||
|
<Typography.Text type="secondary">
|
||||||
|
T+3:每日 8:00 汇总 3 天前(自然日)已完成的同城/跨城订单(实付 × {ratePct}%);未打款红色、已打款绿色、应付为 0
|
||||||
|
无需打款(灰),可展开订单明细
|
||||||
|
</Typography.Text>
|
||||||
|
</Space>
|
||||||
|
{canEditWineryBank ? (
|
||||||
|
<Button type="default" onClick={() => void openBankModal()}>
|
||||||
|
酒厂银行账户信息配置
|
||||||
|
</Button>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
|
||||||
{summary && (
|
{summary && (
|
||||||
<Card size="small" style={{ marginBottom: 16 }}>
|
<Card size="small" style={{ marginBottom: 16 }}>
|
||||||
<Space size="large" wrap>
|
<Space size="large" wrap>
|
||||||
<Statistic title="酒单数" value={summary.count} />
|
<Statistic title="账单数" value={summary.count} />
|
||||||
<Statistic title="酒单实付合计" value={summary.orderAmount ?? 0} prefix="¥" precision={2} />
|
<Statistic title="酒单实付合计" value={summary.orderAmount ?? 0} prefix="¥" precision={2} />
|
||||||
<Statistic title="酒厂应付合计" value={summary.wineryAmount ?? summary.totalAmount} prefix="¥" precision={2} />
|
<Statistic title="应付合计" value={summary.wineryAmount ?? 0} prefix="¥" precision={2} />
|
||||||
</Space>
|
</Space>
|
||||||
</Card>
|
</Card>
|
||||||
)}
|
)}
|
||||||
@@ -137,27 +308,29 @@ export default function WineryBillsPage() {
|
|||||||
form={form}
|
form={form}
|
||||||
layout="inline"
|
layout="inline"
|
||||||
style={{ marginBottom: 16 }}
|
style={{ marginBottom: 16 }}
|
||||||
onFinish={(v: { month?: Dayjs; deliveryType?: string }) => {
|
onFinish={(v: { status?: string; month?: Dayjs; range?: [Dayjs, Dayjs] }) => {
|
||||||
setFilters({
|
setFilters({
|
||||||
|
status: v.status || '',
|
||||||
year: v.month ? String(v.month.year()) : '',
|
year: v.month ? String(v.month.year()) : '',
|
||||||
month: v.month ? String(v.month.month() + 1) : '',
|
month: v.month ? String(v.month.month() + 1) : '',
|
||||||
deliveryType: v.deliveryType || '',
|
dateFrom: v.range?.[0] ? v.range[0].format('YYYY-MM-DD') : '',
|
||||||
|
dateTo: v.range?.[1] ? v.range[1].format('YYYY-MM-DD') : '',
|
||||||
});
|
});
|
||||||
setPage(1);
|
setPage(1);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
<Form.Item name="status" label="状态">
|
||||||
|
<Select
|
||||||
|
allowClear
|
||||||
|
style={{ width: 130 }}
|
||||||
|
options={Object.entries(STATUS_LABELS).map(([value, label]) => ({ value, label }))}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
<Form.Item name="month" label="账期月">
|
<Form.Item name="month" label="账期月">
|
||||||
<DatePicker picker="month" />
|
<DatePicker picker="month" />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item name="deliveryType" label="配送类型">
|
<Form.Item name="range" label="账单日">
|
||||||
<Select
|
<DatePicker.RangePicker />
|
||||||
allowClear
|
|
||||||
style={{ width: 120 }}
|
|
||||||
options={[
|
|
||||||
{ value: 'LOCAL', label: '同城' },
|
|
||||||
{ value: 'CROSS_CITY', label: '跨城' },
|
|
||||||
]}
|
|
||||||
/>
|
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item>
|
<Form.Item>
|
||||||
<Button type="primary" htmlType="submit">
|
<Button type="primary" htmlType="submit">
|
||||||
@@ -180,15 +353,29 @@ export default function WineryBillsPage() {
|
|||||||
导出 Excel
|
导出 Excel
|
||||||
</Button>
|
</Button>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
|
<Form.Item>
|
||||||
|
<Button
|
||||||
|
type="primary"
|
||||||
|
disabled={!selectedKeys.length}
|
||||||
|
onClick={() => confirmPay(selectedKeys.map(String), selectedAmount)}
|
||||||
|
>
|
||||||
|
批量确认打款 ({selectedKeys.length})
|
||||||
|
</Button>
|
||||||
|
</Form.Item>
|
||||||
</Form>
|
</Form>
|
||||||
|
|
||||||
<Table
|
<Table
|
||||||
rowKey="orderId"
|
rowKey="id"
|
||||||
className="admin-table-nowrap"
|
className="admin-table-nowrap"
|
||||||
loading={loading}
|
loading={loading}
|
||||||
columns={columns}
|
columns={columns}
|
||||||
dataSource={data?.items ?? []}
|
dataSource={data?.items ?? []}
|
||||||
scroll={{ x: 1200 }}
|
rowSelection={{
|
||||||
|
selectedRowKeys: selectedKeys,
|
||||||
|
onChange: setSelectedKeys,
|
||||||
|
getCheckboxProps: (r) => ({ disabled: !canConfirmWineryPay(r) }),
|
||||||
|
}}
|
||||||
|
scroll={{ x: 1100 }}
|
||||||
pagination={{
|
pagination={{
|
||||||
current: page,
|
current: page,
|
||||||
pageSize,
|
pageSize,
|
||||||
@@ -200,6 +387,95 @@ export default function WineryBillsPage() {
|
|||||||
},
|
},
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<Drawer title="酒厂对账单明细" open={drawerOpen} onClose={() => setDrawerOpen(false)} width={640}>
|
||||||
|
{detail && (
|
||||||
|
<>
|
||||||
|
<Descriptions column={1} size="small" bordered>
|
||||||
|
<Descriptions.Item label="账单号">{detail.billNo}</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="账单日">{String(detail.billDate).slice(0, 10)}</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="应付">¥{Number(detail.wineryAmount).toFixed(2)}</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="状态">
|
||||||
|
{displayWineryStatus(detail.status, detail.wineryAmount).label}
|
||||||
|
</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="打款时间">{detail.paidAt ? fmtTime(detail.paidAt) : '—'}</Descriptions.Item>
|
||||||
|
</Descriptions>
|
||||||
|
<Typography.Title level={5} style={{ marginTop: 16 }}>
|
||||||
|
订单明细
|
||||||
|
</Typography.Title>
|
||||||
|
<Table
|
||||||
|
size="small"
|
||||||
|
rowKey="id"
|
||||||
|
pagination={false}
|
||||||
|
dataSource={detail.items ?? []}
|
||||||
|
columns={[
|
||||||
|
{ title: '订单号', dataIndex: 'orderNo', ellipsis: true },
|
||||||
|
{
|
||||||
|
title: '配送',
|
||||||
|
dataIndex: 'deliveryType',
|
||||||
|
width: 70,
|
||||||
|
render: (v) => DELIVERY_LABELS[v] || v,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '实付',
|
||||||
|
dataIndex: 'payAmount',
|
||||||
|
width: 90,
|
||||||
|
render: (v) => `¥${Number(v).toFixed(2)}`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '应付',
|
||||||
|
dataIndex: 'wineryAmount',
|
||||||
|
width: 90,
|
||||||
|
render: (v) => `¥${Number(v).toFixed(2)}`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '支付时间',
|
||||||
|
dataIndex: 'paidAt',
|
||||||
|
width: 150,
|
||||||
|
render: (v) => (v ? fmtTime(v) : '—'),
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</Drawer>
|
||||||
|
|
||||||
|
<Modal
|
||||||
|
title="酒厂银行账户信息配置"
|
||||||
|
open={bankOpen}
|
||||||
|
onCancel={() => setBankOpen(false)}
|
||||||
|
onOk={() => void saveBank()}
|
||||||
|
confirmLoading={bankSaving}
|
||||||
|
destroyOnClose
|
||||||
|
okText="保存"
|
||||||
|
>
|
||||||
|
<Form form={bankForm} layout="vertical" disabled={bankLoading}>
|
||||||
|
<Form.Item
|
||||||
|
name="WINERY_BANK_ACCOUNT_NAME"
|
||||||
|
label="户名"
|
||||||
|
rules={[{ required: true, message: '请填写户名' }]}
|
||||||
|
>
|
||||||
|
<Input placeholder="收款账户户名" />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item
|
||||||
|
name="WINERY_BANK_NAME"
|
||||||
|
label="开户银行"
|
||||||
|
rules={[{ required: true, message: '请填写开户银行' }]}
|
||||||
|
>
|
||||||
|
<Input placeholder="如:中国工商银行" />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="WINERY_BANK_BRANCH" label="开户支行">
|
||||||
|
<Input placeholder="可选" />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item
|
||||||
|
name="WINERY_BANK_ACCOUNT_NO"
|
||||||
|
label="银行账号"
|
||||||
|
rules={[{ required: true, message: '请填写银行账号' }]}
|
||||||
|
>
|
||||||
|
<Input placeholder="银行卡号" />
|
||||||
|
</Form.Item>
|
||||||
|
</Form>
|
||||||
|
</Modal>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { useState } from 'react';
|
import { useState, type CSSProperties } from 'react';
|
||||||
import { useOutletContext } from 'react-router-dom';
|
import { useOutletContext } from 'react-router-dom';
|
||||||
import {
|
import {
|
||||||
Button,
|
Button,
|
||||||
@@ -24,6 +24,16 @@ import {
|
|||||||
import { request } from '../../lib/api';
|
import { request } from '../../lib/api';
|
||||||
import { fmtTime } from '../../lib/constants';
|
import { fmtTime } from '../../lib/constants';
|
||||||
import type { PromoCodeDetailContext } from './PromoCodeDetailLayout';
|
import type { PromoCodeDetailContext } from './PromoCodeDetailLayout';
|
||||||
|
import PromoCodeMetricsPanel from './PromoCodeMetricsPanel';
|
||||||
|
|
||||||
|
const descLabelStyle: CSSProperties = {
|
||||||
|
whiteSpace: 'nowrap',
|
||||||
|
width: 108,
|
||||||
|
};
|
||||||
|
|
||||||
|
const descContentStyle: CSSProperties = {
|
||||||
|
wordBreak: 'break-all',
|
||||||
|
};
|
||||||
|
|
||||||
async function downloadQrcode(url: string, filename: string) {
|
async function downloadQrcode(url: string, filename: string) {
|
||||||
try {
|
try {
|
||||||
@@ -72,46 +82,25 @@ export default function PromoCodeDetailPage() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Row gutter={[16, 16]}>
|
<Row gutter={[16, 16]} align="top">
|
||||||
<Col xs={24} lg={8}>
|
<Col flex="1 1 480px" style={{ minWidth: 0 }}>
|
||||||
<Card title="推广二维码" size="small">
|
|
||||||
{detail.qrcodeUrl ? (
|
|
||||||
<div style={{ textAlign: 'center' }}>
|
|
||||||
<img
|
|
||||||
src={detail.qrcodeUrl}
|
|
||||||
alt="推广二维码"
|
|
||||||
style={{ width: 200, height: 200, marginBottom: 12 }}
|
|
||||||
/>
|
|
||||||
<Space direction="vertical" style={{ width: '100%' }}>
|
|
||||||
<Button
|
|
||||||
block
|
|
||||||
onClick={() => void downloadQrcode(detail.qrcodeUrl!, `${detail.code}-qrcode.png`)}
|
|
||||||
>
|
|
||||||
下载二维码
|
|
||||||
</Button>
|
|
||||||
</Space>
|
|
||||||
</div>
|
|
||||||
) : (
|
|
||||||
<Typography.Text type="secondary">暂无二维码</Typography.Text>
|
|
||||||
)}
|
|
||||||
</Card>
|
|
||||||
</Col>
|
|
||||||
|
|
||||||
<Col xs={24} lg={16}>
|
|
||||||
<Card
|
<Card
|
||||||
title="基础信息"
|
title="基础信息"
|
||||||
size="small"
|
size="small"
|
||||||
|
styles={{ body: { paddingTop: 12 } }}
|
||||||
extra={(
|
extra={(
|
||||||
<Space>
|
<Space>
|
||||||
<Button size="small" onClick={() => {
|
<Button
|
||||||
editForm.setFieldsValue({
|
size="small"
|
||||||
name: detail.name,
|
onClick={() => {
|
||||||
scene: detail.scene,
|
editForm.setFieldsValue({
|
||||||
remark: detail.remark,
|
name: detail.name,
|
||||||
ownerUserId: detail.ownerUser?.id,
|
scene: detail.scene,
|
||||||
});
|
remark: detail.remark,
|
||||||
setEditOpen(true);
|
ownerUserId: detail.ownerUser?.id,
|
||||||
}}
|
});
|
||||||
|
setEditOpen(true);
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
编辑
|
编辑
|
||||||
</Button>
|
</Button>
|
||||||
@@ -135,7 +124,18 @@ export default function PromoCodeDetailPage() {
|
|||||||
</Space>
|
</Space>
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
<Descriptions column={{ xs: 1, sm: 2 }} bordered size="small">
|
<Descriptions
|
||||||
|
column={2}
|
||||||
|
bordered
|
||||||
|
size="small"
|
||||||
|
layout="horizontal"
|
||||||
|
labelStyle={descLabelStyle}
|
||||||
|
contentStyle={descContentStyle}
|
||||||
|
styles={{
|
||||||
|
label: descLabelStyle,
|
||||||
|
content: descContentStyle,
|
||||||
|
}}
|
||||||
|
>
|
||||||
<Descriptions.Item label="名称">{detail.name}</Descriptions.Item>
|
<Descriptions.Item label="名称">{detail.name}</Descriptions.Item>
|
||||||
<Descriptions.Item label="码值">{detail.code}</Descriptions.Item>
|
<Descriptions.Item label="码值">{detail.code}</Descriptions.Item>
|
||||||
<Descriptions.Item label="场景">
|
<Descriptions.Item label="场景">
|
||||||
@@ -144,34 +144,89 @@ export default function PromoCodeDetailPage() {
|
|||||||
<Descriptions.Item label="状态">
|
<Descriptions.Item label="状态">
|
||||||
{PROMO_CODE_STATUS_LABELS[detail.status] || detail.status}
|
{PROMO_CODE_STATUS_LABELS[detail.status] || detail.status}
|
||||||
</Descriptions.Item>
|
</Descriptions.Item>
|
||||||
<Descriptions.Item label="二维码 ID" span={2}>
|
<Descriptions.Item label="活动 ID">
|
||||||
<Typography.Text copyable={{ text: detail.qrcodeId }}>{detail.qrcodeId}</Typography.Text>
|
<Typography.Text copyable={{ text: String(detail.id) }} style={{ whiteSpace: 'nowrap' }}>
|
||||||
|
{detail.id}
|
||||||
|
</Typography.Text>
|
||||||
</Descriptions.Item>
|
</Descriptions.Item>
|
||||||
<Descriptions.Item label="落地链接" span={2}>
|
<Descriptions.Item label="二维码 ID">
|
||||||
<Typography.Text copyable={{ text: detail.landingUrl }}>{detail.landingUrl}</Typography.Text>
|
<Typography.Text copyable={{ text: detail.qrcodeId }} style={{ whiteSpace: 'nowrap' }}>
|
||||||
|
{detail.qrcodeId}
|
||||||
|
</Typography.Text>
|
||||||
</Descriptions.Item>
|
</Descriptions.Item>
|
||||||
<Descriptions.Item label="OSS 地址" span={2}>
|
<Descriptions.Item label="小程序码 OSS" span={2}>
|
||||||
{detail.qrcodeUrl ? (
|
{detail.qrcodeUrl ? (
|
||||||
<Typography.Text copyable={{ text: detail.qrcodeUrl }} ellipsis>
|
<Typography.Text copyable={{ text: detail.qrcodeUrl }} ellipsis style={{ maxWidth: '100%' }}>
|
||||||
{detail.qrcodeUrl}
|
{detail.qrcodeUrl}
|
||||||
</Typography.Text>
|
</Typography.Text>
|
||||||
) : '—'}
|
) : '—'}
|
||||||
</Descriptions.Item>
|
</Descriptions.Item>
|
||||||
<Descriptions.Item label="渠道负责人">
|
<Descriptions.Item label="渠道负责人">
|
||||||
{detail.ownerUser?.userNo || detail.ownerUser?.phone || '—'}
|
<span style={{ whiteSpace: 'nowrap' }}>
|
||||||
|
{detail.ownerUser?.userNo || detail.ownerUser?.phone || '—'}
|
||||||
|
</span>
|
||||||
</Descriptions.Item>
|
</Descriptions.Item>
|
||||||
<Descriptions.Item label="备注">{detail.remark || '—'}</Descriptions.Item>
|
<Descriptions.Item label="备注">{detail.remark || '—'}</Descriptions.Item>
|
||||||
<Descriptions.Item label="创建时间">{fmtTime(detail.createdAt)}</Descriptions.Item>
|
<Descriptions.Item label="创建时间">
|
||||||
<Descriptions.Item label="更新时间">{fmtTime(detail.updatedAt)}</Descriptions.Item>
|
<span style={{ whiteSpace: 'nowrap' }}>{fmtTime(detail.createdAt)}</span>
|
||||||
|
</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="更新时间">
|
||||||
|
<span style={{ whiteSpace: 'nowrap' }}>{fmtTime(detail.updatedAt)}</span>
|
||||||
|
</Descriptions.Item>
|
||||||
</Descriptions>
|
</Descriptions>
|
||||||
</Card>
|
</Card>
|
||||||
</Col>
|
</Col>
|
||||||
|
|
||||||
|
<Col flex="0 0 220px">
|
||||||
|
<Card title="小程序码" size="small" styles={{ body: { textAlign: 'center', padding: 12 } }}>
|
||||||
|
{detail.qrcodeUrl ? (
|
||||||
|
<>
|
||||||
|
<img
|
||||||
|
src={detail.qrcodeUrl}
|
||||||
|
alt="推广小程序码"
|
||||||
|
style={{ width: 168, height: 168, display: 'block', margin: '0 auto 8px' }}
|
||||||
|
/>
|
||||||
|
<Typography.Paragraph
|
||||||
|
type="secondary"
|
||||||
|
style={{ marginBottom: 8, fontSize: 12, whiteSpace: 'nowrap' }}
|
||||||
|
>
|
||||||
|
scene={detail.id}
|
||||||
|
</Typography.Paragraph>
|
||||||
|
<Button
|
||||||
|
block
|
||||||
|
size="small"
|
||||||
|
onClick={() => void downloadQrcode(detail.qrcodeUrl!, `${detail.code}-wxacode.png`)}
|
||||||
|
>
|
||||||
|
下载小程序码
|
||||||
|
</Button>
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<Typography.Text type="secondary">暂无小程序码</Typography.Text>
|
||||||
|
)}
|
||||||
|
</Card>
|
||||||
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
|
|
||||||
<Row gutter={16} style={{ marginTop: 16 }}>
|
<Row gutter={16} style={{ marginTop: 16 }}>
|
||||||
<Col xs={12} sm={6}>
|
<Col xs={12} sm={6}>
|
||||||
<Card size="small">
|
<Card size="small">
|
||||||
<Statistic title="扫码次数" value={stats?.scanCount ?? detail.scanCount} />
|
<Statistic title="扫码进入次数" value={stats?.scanCount ?? detail.scanCount} />
|
||||||
|
</Card>
|
||||||
|
</Col>
|
||||||
|
<Col xs={12} sm={6}>
|
||||||
|
<Card size="small">
|
||||||
|
<Statistic
|
||||||
|
title="归因用户数"
|
||||||
|
value={stats?.attributionCount ?? 0}
|
||||||
|
/>
|
||||||
|
</Card>
|
||||||
|
</Col>
|
||||||
|
<Col xs={12} sm={6}>
|
||||||
|
<Card size="small">
|
||||||
|
<Statistic
|
||||||
|
title="扫码注册用户数"
|
||||||
|
value={stats?.registerCount ?? stats?.sourceMarkedCount ?? 0}
|
||||||
|
/>
|
||||||
</Card>
|
</Card>
|
||||||
</Col>
|
</Col>
|
||||||
<Col xs={12} sm={6}>
|
<Col xs={12} sm={6}>
|
||||||
@@ -187,13 +242,10 @@ export default function PromoCodeDetailPage() {
|
|||||||
/>
|
/>
|
||||||
</Card>
|
</Card>
|
||||||
</Col>
|
</Col>
|
||||||
<Col xs={12} sm={6}>
|
|
||||||
<Card size="small">
|
|
||||||
<Statistic title="来源标记用户" value={stats?.sourceMarkedCount ?? '—'} />
|
|
||||||
</Card>
|
|
||||||
</Col>
|
|
||||||
</Row>
|
</Row>
|
||||||
|
|
||||||
|
<PromoCodeMetricsPanel promoId={detail.id} />
|
||||||
|
|
||||||
<Modal
|
<Modal
|
||||||
title="编辑推广码"
|
title="编辑推广码"
|
||||||
open={editOpen}
|
open={editOpen}
|
||||||
|
|||||||
@@ -0,0 +1,258 @@
|
|||||||
|
import { useCallback, useEffect, useMemo, useState } from 'react';
|
||||||
|
import {
|
||||||
|
Card,
|
||||||
|
DatePicker,
|
||||||
|
Radio,
|
||||||
|
Select,
|
||||||
|
Space,
|
||||||
|
Table,
|
||||||
|
Typography,
|
||||||
|
message,
|
||||||
|
} from 'antd';
|
||||||
|
import type { ColumnsType } from 'antd/es/table';
|
||||||
|
import dayjs, { type Dayjs } from 'dayjs';
|
||||||
|
import ReactECharts from 'echarts-for-react';
|
||||||
|
import type { EChartsOption } from 'echarts';
|
||||||
|
import {
|
||||||
|
PROMO_METRIC_EVENT_LABELS,
|
||||||
|
type PromoMetricEventItem,
|
||||||
|
type PromoMetricEventType,
|
||||||
|
type PromoMetricTimelineDto,
|
||||||
|
} from '@dukang/shared-types';
|
||||||
|
import { request, type Paginated } from '../../lib/api';
|
||||||
|
import { fmtTime } from '../../lib/constants';
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
promoId: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
const SERIES = [
|
||||||
|
{ key: 'scan', name: '扫码进入', color: '#1677ff' },
|
||||||
|
{ key: 'attribution', name: '归因用户', color: '#52c41a' },
|
||||||
|
{ key: 'register', name: '扫码注册', color: '#faad14' },
|
||||||
|
{ key: 'order', name: '订单', color: '#eb2f96' },
|
||||||
|
] as const;
|
||||||
|
|
||||||
|
function buildTimelineQs(promoId: string, range: [Dayjs, Dayjs], granularity: 'day' | 'hour') {
|
||||||
|
const qs = new URLSearchParams();
|
||||||
|
qs.set('dateFrom', range[0].format('YYYY-MM-DD'));
|
||||||
|
qs.set('dateTo', range[1].format('YYYY-MM-DD'));
|
||||||
|
qs.set('granularity', granularity);
|
||||||
|
return `/admin/promo-codes/${promoId}/metrics/timeline?${qs.toString()}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function buildEventsQs(
|
||||||
|
promoId: string,
|
||||||
|
page: number,
|
||||||
|
pageSize: number,
|
||||||
|
range: [Dayjs, Dayjs],
|
||||||
|
eventType?: PromoMetricEventType,
|
||||||
|
) {
|
||||||
|
const qs = new URLSearchParams();
|
||||||
|
qs.set('page', String(page));
|
||||||
|
qs.set('pageSize', String(pageSize));
|
||||||
|
qs.set('dateFrom', range[0].format('YYYY-MM-DD'));
|
||||||
|
qs.set('dateTo', range[1].format('YYYY-MM-DD'));
|
||||||
|
if (eventType) qs.set('eventType', eventType);
|
||||||
|
return `/admin/promo-codes/${promoId}/metrics/events?${qs.toString()}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatRefId(row: PromoMetricEventItem): string {
|
||||||
|
if (row.orderId) return `订单 ${row.orderId}`;
|
||||||
|
if (row.userId) return `用户 ${row.userId}`;
|
||||||
|
if (row.sessionId) return `会话 ${row.sessionId}`;
|
||||||
|
return '—';
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatLocation(row: PromoMetricEventItem): string {
|
||||||
|
const parts = [row.ipProvince, row.ipCity].filter(Boolean);
|
||||||
|
if (parts.length) return parts.join(' ');
|
||||||
|
return '—';
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function PromoCodeMetricsPanel({ promoId }: Props) {
|
||||||
|
const [range, setRange] = useState<[Dayjs, Dayjs]>([dayjs().subtract(6, 'day'), dayjs()]);
|
||||||
|
const [granularity, setGranularity] = useState<'day' | 'hour'>('day');
|
||||||
|
const [timeline, setTimeline] = useState<PromoMetricTimelineDto | null>(null);
|
||||||
|
const [timelineLoading, setTimelineLoading] = useState(false);
|
||||||
|
const [eventType, setEventType] = useState<PromoMetricEventType | undefined>();
|
||||||
|
const [eventsPage, setEventsPage] = useState(1);
|
||||||
|
const [events, setEvents] = useState<Paginated<PromoMetricEventItem> | null>(null);
|
||||||
|
const [eventsLoading, setEventsLoading] = useState(false);
|
||||||
|
|
||||||
|
const loadTimeline = useCallback(() => {
|
||||||
|
setTimelineLoading(true);
|
||||||
|
return request<PromoMetricTimelineDto>(buildTimelineQs(promoId, range, granularity))
|
||||||
|
.then(setTimeline)
|
||||||
|
.catch((e) => {
|
||||||
|
message.error(e instanceof Error ? e.message : '加载趋势失败');
|
||||||
|
setTimeline(null);
|
||||||
|
})
|
||||||
|
.finally(() => setTimelineLoading(false));
|
||||||
|
}, [promoId, range, granularity]);
|
||||||
|
|
||||||
|
const loadEvents = useCallback(() => {
|
||||||
|
setEventsLoading(true);
|
||||||
|
return request<Paginated<PromoMetricEventItem>>(
|
||||||
|
buildEventsQs(promoId, eventsPage, 20, range, eventType),
|
||||||
|
)
|
||||||
|
.then(setEvents)
|
||||||
|
.catch((e) => {
|
||||||
|
message.error(e instanceof Error ? e.message : '加载事件失败');
|
||||||
|
setEvents(null);
|
||||||
|
})
|
||||||
|
.finally(() => setEventsLoading(false));
|
||||||
|
}, [promoId, eventsPage, range, eventType]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
void loadTimeline();
|
||||||
|
}, [loadTimeline]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
void loadEvents();
|
||||||
|
}, [loadEvents]);
|
||||||
|
|
||||||
|
const chartOption = useMemo<EChartsOption>(() => {
|
||||||
|
const buckets = timeline?.buckets ?? [];
|
||||||
|
const xData = buckets.map((b) => b.key);
|
||||||
|
|
||||||
|
return {
|
||||||
|
tooltip: { trigger: 'axis' },
|
||||||
|
legend: { data: SERIES.map((s) => s.name), bottom: 0 },
|
||||||
|
grid: { left: 48, right: 24, top: 24, bottom: 48 },
|
||||||
|
xAxis: {
|
||||||
|
type: 'category',
|
||||||
|
data: xData,
|
||||||
|
axisLabel: {
|
||||||
|
rotate: granularity === 'hour' ? 45 : 0,
|
||||||
|
formatter: (v: string) => (granularity === 'hour' ? v.slice(5, 16) : v.slice(5)),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
yAxis: { type: 'value', minInterval: 1 },
|
||||||
|
series: SERIES.map((s) => ({
|
||||||
|
name: s.name,
|
||||||
|
type: 'line',
|
||||||
|
smooth: true,
|
||||||
|
data: buckets.map((b) => b[s.key]),
|
||||||
|
itemStyle: { color: s.color },
|
||||||
|
markPoint: {
|
||||||
|
symbol: 'pin',
|
||||||
|
symbolSize: 42,
|
||||||
|
data: (() => {
|
||||||
|
const peak = timeline?.peak[s.key];
|
||||||
|
if (!peak || peak.count <= 0) return [];
|
||||||
|
return [{ name: '高峰', coord: [peak.key, peak.count], value: peak.count }];
|
||||||
|
})(),
|
||||||
|
},
|
||||||
|
})),
|
||||||
|
};
|
||||||
|
}, [timeline, granularity]);
|
||||||
|
|
||||||
|
const columns: ColumnsType<PromoMetricEventItem> = [
|
||||||
|
{
|
||||||
|
title: '时间',
|
||||||
|
dataIndex: 'createdAt',
|
||||||
|
width: 168,
|
||||||
|
render: (v: string) => fmtTime(v),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '类型',
|
||||||
|
dataIndex: 'eventType',
|
||||||
|
width: 108,
|
||||||
|
render: (v: PromoMetricEventType) => PROMO_METRIC_EVENT_LABELS[v],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'ID',
|
||||||
|
key: 'ref',
|
||||||
|
render: (_, row) => formatRefId(row),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'IP',
|
||||||
|
dataIndex: 'clientIp',
|
||||||
|
width: 128,
|
||||||
|
render: (v: string | null) => v ?? '—',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '地点',
|
||||||
|
key: 'location',
|
||||||
|
width: 120,
|
||||||
|
render: (_, row) => formatLocation(row),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Card
|
||||||
|
title="数据趋势"
|
||||||
|
style={{ marginTop: 16 }}
|
||||||
|
extra={
|
||||||
|
<Typography.Text type="secondary" style={{ fontSize: 12 }}>
|
||||||
|
仅统计功能上线后的新事件
|
||||||
|
</Typography.Text>
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<Space wrap style={{ marginBottom: 16 }}>
|
||||||
|
<DatePicker.RangePicker
|
||||||
|
value={range}
|
||||||
|
onChange={(v) => {
|
||||||
|
if (v?.[0] && v[1]) {
|
||||||
|
setRange([v[0], v[1]]);
|
||||||
|
setEventsPage(1);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
allowClear={false}
|
||||||
|
/>
|
||||||
|
<Radio.Group
|
||||||
|
value={granularity}
|
||||||
|
onChange={(e) => setGranularity(e.target.value as 'day' | 'hour')}
|
||||||
|
optionType="button"
|
||||||
|
buttonStyle="solid"
|
||||||
|
options={[
|
||||||
|
{ label: '按日', value: 'day' },
|
||||||
|
{ label: '按时', value: 'hour' },
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
</Space>
|
||||||
|
|
||||||
|
<ReactECharts
|
||||||
|
option={chartOption}
|
||||||
|
style={{ height: 360 }}
|
||||||
|
showLoading={timelineLoading}
|
||||||
|
notMerge
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Typography.Title level={5} style={{ marginTop: 24, marginBottom: 12 }}>
|
||||||
|
事件日志
|
||||||
|
</Typography.Title>
|
||||||
|
<Space wrap style={{ marginBottom: 12 }}>
|
||||||
|
<Select
|
||||||
|
allowClear
|
||||||
|
placeholder="全部类型"
|
||||||
|
style={{ width: 160 }}
|
||||||
|
value={eventType}
|
||||||
|
onChange={(v) => {
|
||||||
|
setEventType(v);
|
||||||
|
setEventsPage(1);
|
||||||
|
}}
|
||||||
|
options={Object.entries(PROMO_METRIC_EVENT_LABELS).map(([value, label]) => ({
|
||||||
|
value,
|
||||||
|
label,
|
||||||
|
}))}
|
||||||
|
/>
|
||||||
|
</Space>
|
||||||
|
<Table
|
||||||
|
rowKey="id"
|
||||||
|
size="small"
|
||||||
|
columns={columns}
|
||||||
|
dataSource={events?.items ?? []}
|
||||||
|
loading={eventsLoading}
|
||||||
|
pagination={{
|
||||||
|
current: eventsPage,
|
||||||
|
pageSize: events?.pageSize ?? 20,
|
||||||
|
total: events?.total ?? 0,
|
||||||
|
showSizeChanger: false,
|
||||||
|
onChange: (p) => setEventsPage(p),
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</Card>
|
||||||
|
);
|
||||||
|
}
|
||||||
Vendored
+6
@@ -0,0 +1,6 @@
|
|||||||
|
/// <reference types="vite/client" />
|
||||||
|
|
||||||
|
declare module '*.mp3' {
|
||||||
|
const src: string;
|
||||||
|
export default src;
|
||||||
|
}
|
||||||
@@ -11,7 +11,10 @@
|
|||||||
"isolatedModules": true,
|
"isolatedModules": true,
|
||||||
"noEmit": true,
|
"noEmit": true,
|
||||||
"jsx": "react-jsx",
|
"jsx": "react-jsx",
|
||||||
"strict": true
|
"strict": true,
|
||||||
|
"paths": {
|
||||||
|
"@dukang/domain": ["../../packages/domain/src/index.ts"]
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"include": ["src"]
|
"include": ["src"]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,19 @@
|
|||||||
import { defineConfig } from 'vite';
|
import { defineConfig } from 'vite';
|
||||||
import react from '@vitejs/plugin-react';
|
import react from '@vitejs/plugin-react';
|
||||||
|
import path from 'path';
|
||||||
|
|
||||||
|
const apiTarget = process.env.VITE_API_TARGET ?? 'http://localhost:3010';
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
plugins: [react()],
|
plugins: [react()],
|
||||||
|
resolve: {
|
||||||
|
alias: {
|
||||||
|
'@dukang/domain': path.resolve(__dirname, '../../packages/domain/src/index.ts'),
|
||||||
|
},
|
||||||
|
},
|
||||||
server: {
|
server: {
|
||||||
|
host: true,
|
||||||
port: 5175,
|
port: 5175,
|
||||||
proxy: { '/api': 'http://localhost:3000' },
|
proxy: { '/api': apiTarget },
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -9,15 +9,19 @@
|
|||||||
"lint": "echo ok"
|
"lint": "echo ok"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@dukang/shared-ui": "workspace:*",
|
"@dukang/client-logging": "workspace:*",
|
||||||
|
"@dukang/domain": "workspace:*",
|
||||||
"@dukang/shared-types": "workspace:*",
|
"@dukang/shared-types": "workspace:*",
|
||||||
|
"@dukang/shared-ui": "workspace:*",
|
||||||
"@dukang/weixin-sdk": "workspace:*",
|
"@dukang/weixin-sdk": "workspace:*",
|
||||||
"element-china-area-data": "^6.1.0",
|
"element-china-area-data": "^6.1.0",
|
||||||
|
"qrcode": "^1.5.4",
|
||||||
"react": "^18.3.1",
|
"react": "^18.3.1",
|
||||||
"react-dom": "^18.3.1",
|
"react-dom": "^18.3.1",
|
||||||
"react-router-dom": "^6.26.0"
|
"react-router-dom": "^6.26.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@types/qrcode": "^1.5.6",
|
||||||
"@types/react": "^18.3.3",
|
"@types/react": "^18.3.3",
|
||||||
"@types/react-dom": "^18.3.0",
|
"@types/react-dom": "^18.3.0",
|
||||||
"@vitejs/plugin-react": "^4.3.1",
|
"@vitejs/plugin-react": "^4.3.1",
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
ayPJ4CQqbUcec3jX
|
||||||
@@ -6,6 +6,7 @@ import SubAccountLayout from './layouts/SubAccountLayout';
|
|||||||
import HomePage from './pages/HomePage';
|
import HomePage from './pages/HomePage';
|
||||||
import StoreListPage from './pages/StoreListPage';
|
import StoreListPage from './pages/StoreListPage';
|
||||||
import StoreDetailPage from './pages/StoreDetailPage';
|
import StoreDetailPage from './pages/StoreDetailPage';
|
||||||
|
import StorePackagesPage from './pages/StorePackagesPage';
|
||||||
import StoreCreatePage from './pages/StoreCreatePage';
|
import StoreCreatePage from './pages/StoreCreatePage';
|
||||||
import OrderListPage from './pages/OrderListPage';
|
import OrderListPage from './pages/OrderListPage';
|
||||||
import OrderDetailPage from './pages/OrderDetailPage';
|
import OrderDetailPage from './pages/OrderDetailPage';
|
||||||
@@ -15,6 +16,9 @@ import BillsPage from './pages/BillsPage';
|
|||||||
import SettlementPage from './pages/SettlementPage';
|
import SettlementPage from './pages/SettlementPage';
|
||||||
import WeeklyReportPage from './pages/WeeklyReportPage';
|
import WeeklyReportPage from './pages/WeeklyReportPage';
|
||||||
import ProxyOrderPage from './pages/ProxyOrderPage';
|
import ProxyOrderPage from './pages/ProxyOrderPage';
|
||||||
|
import ProxyOrderProductsPage from './pages/ProxyOrderProductsPage';
|
||||||
|
import ProxyOrderListPage from './pages/ProxyOrderListPage';
|
||||||
|
import ProxyOrderDetailPage from './pages/ProxyOrderDetailPage';
|
||||||
import StaffListPage from './pages/StaffListPage';
|
import StaffListPage from './pages/StaffListPage';
|
||||||
import StaffCreatePage from './pages/StaffCreatePage';
|
import StaffCreatePage from './pages/StaffCreatePage';
|
||||||
import LeaderboardPage from './pages/LeaderboardPage';
|
import LeaderboardPage from './pages/LeaderboardPage';
|
||||||
@@ -28,11 +32,15 @@ function PrimaryRoutes() {
|
|||||||
<Route path="/center" element={<CenterPage />} />
|
<Route path="/center" element={<CenterPage />} />
|
||||||
</Route>
|
</Route>
|
||||||
<Route path="/stores/new" element={<StoreCreatePage />} />
|
<Route path="/stores/new" element={<StoreCreatePage />} />
|
||||||
|
<Route path="/stores/:id/packages" element={<StorePackagesPage />} />
|
||||||
<Route path="/center/bills" element={<BillsPage />} />
|
<Route path="/center/bills" element={<BillsPage />} />
|
||||||
<Route path="/center/settlement" element={<SettlementPage />} />
|
<Route path="/center/settlement" element={<SettlementPage />} />
|
||||||
<Route path="/center/staff" element={<StaffListPage />} />
|
<Route path="/center/staff" element={<StaffListPage />} />
|
||||||
<Route path="/center/staff/new" element={<StaffCreatePage />} />
|
<Route path="/center/staff/new" element={<StaffCreatePage />} />
|
||||||
|
<Route path="/center/proxy-orders" element={<ProxyOrderListPage />} />
|
||||||
|
<Route path="/center/proxy-orders/:id" element={<ProxyOrderDetailPage />} />
|
||||||
<Route path="/proxy-order" element={<ProxyOrderPage />} />
|
<Route path="/proxy-order" element={<ProxyOrderPage />} />
|
||||||
|
<Route path="/proxy-order/products" element={<ProxyOrderProductsPage />} />
|
||||||
<Route path="/reports/weekly" element={<WeeklyReportPage />} />
|
<Route path="/reports/weekly" element={<WeeklyReportPage />} />
|
||||||
<Route path="/leaderboard" element={<LeaderboardPage />} />
|
<Route path="/leaderboard" element={<LeaderboardPage />} />
|
||||||
<Route path="/stores/:id" element={<StoreDetailPage />} />
|
<Route path="/stores/:id" element={<StoreDetailPage />} />
|
||||||
@@ -62,6 +70,7 @@ function SubAccountRoutes() {
|
|||||||
{!isWarehouse && (
|
{!isWarehouse && (
|
||||||
<>
|
<>
|
||||||
<Route path="/stores/new" element={<StoreCreatePage />} />
|
<Route path="/stores/new" element={<StoreCreatePage />} />
|
||||||
|
<Route path="/stores/:id/packages" element={<StorePackagesPage />} />
|
||||||
<Route path="/stores/:id" element={<StoreDetailPage />} />
|
<Route path="/stores/:id" element={<StoreDetailPage />} />
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { Navigate, useLocation } from 'react-router-dom';
|
import { Navigate, useLocation } from 'react-router-dom';
|
||||||
import { getPartnerProfile } from '../lib/api';
|
import { getPartnerProfile, hasPartnerWxSession } from '../lib/api';
|
||||||
import { usePartnerSession } from '../contexts/PartnerSessionContext';
|
import { usePartnerSession } from '../contexts/PartnerSessionContext';
|
||||||
import { partnerHomePath } from '../lib/partnerAccess';
|
import { partnerHomePath } from '../lib/partnerAccess';
|
||||||
|
|
||||||
@@ -18,6 +18,10 @@ export default function AuthGate({ children }: { children: React.ReactNode }) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!authenticated && !PUBLIC_PATHS.has(location.pathname)) {
|
if (!authenticated && !PUBLIC_PATHS.has(location.pathname)) {
|
||||||
|
const profile = getPartnerProfile();
|
||||||
|
if (profile && hasPartnerWxSession() && profile.hasWechat) {
|
||||||
|
return <Navigate to="/login?quick=1" replace state={{ from: location }} />;
|
||||||
|
}
|
||||||
return <Navigate to="/login" replace state={{ from: location }} />;
|
return <Navigate to="/login" replace state={{ from: location }} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,273 @@
|
|||||||
|
import { useEffect, useRef, useState } from 'react';
|
||||||
|
import { uploadFileToOss, type OssMediaType } from '../lib/upload';
|
||||||
|
import { enqueueUpload } from '../lib/upload-lock';
|
||||||
|
import { formatChooseImageFailMessage } from '@dukang/weixin-sdk';
|
||||||
|
import { isWechatEnv, weixinSdk } from '../lib/weixin';
|
||||||
|
import { toastError, toastSuccess } from '../lib/toast';
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
value?: string[];
|
||||||
|
onChange?: (urls: string[]) => void;
|
||||||
|
bizType: string;
|
||||||
|
mediaType?: OssMediaType;
|
||||||
|
maxCount?: number;
|
||||||
|
disabled?: boolean;
|
||||||
|
label?: string;
|
||||||
|
/** 系统文件选择器的 accept,默认仅图片 */
|
||||||
|
accept?: string;
|
||||||
|
/** 计量单位文案,如「张」「个」 */
|
||||||
|
unit?: string;
|
||||||
|
/**
|
||||||
|
* stack:缩略图 + 下方独立上传按钮(合同等)
|
||||||
|
* grid:九宫格,末尾「+」格上传,无独立大按钮(环境图)
|
||||||
|
*/
|
||||||
|
variant?: 'stack' | 'grid';
|
||||||
|
};
|
||||||
|
|
||||||
|
function isCancelError(msg: string): boolean {
|
||||||
|
return /cancel|取消/i.test(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
function isPdf(url: string): boolean {
|
||||||
|
return /\.pdf(\?|$)/i.test(url);
|
||||||
|
}
|
||||||
|
|
||||||
|
function normalizeUrls(value?: string[]) {
|
||||||
|
return (value ?? []).map((u) => String(u || '').trim()).filter(Boolean);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 合伙人端多图批量上传(微信相册可多选) */
|
||||||
|
export default function MultiOssUploadField({
|
||||||
|
value,
|
||||||
|
onChange,
|
||||||
|
bizType,
|
||||||
|
mediaType = 'IMAGE',
|
||||||
|
maxCount = 20,
|
||||||
|
disabled,
|
||||||
|
label,
|
||||||
|
accept = 'image/*',
|
||||||
|
unit = '张',
|
||||||
|
variant = 'stack',
|
||||||
|
}: Props) {
|
||||||
|
const inputRef = useRef<HTMLInputElement>(null);
|
||||||
|
const pickingRef = useRef(false);
|
||||||
|
const [uploading, setUploading] = useState(false);
|
||||||
|
const [error, setError] = useState('');
|
||||||
|
|
||||||
|
const urls = normalizeUrls(value);
|
||||||
|
const urlsRef = useRef(urls);
|
||||||
|
const onChangeRef = useRef(onChange);
|
||||||
|
const remaining = Math.max(0, maxCount - urls.length);
|
||||||
|
const inWechat = isWechatEnv();
|
||||||
|
const isGrid = variant === 'grid';
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
urlsRef.current = urls;
|
||||||
|
}, [urls]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
onChangeRef.current = onChange;
|
||||||
|
}, [onChange]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!inWechat) return;
|
||||||
|
void weixinSdk.init().catch(() => {});
|
||||||
|
}, [inWechat]);
|
||||||
|
|
||||||
|
function showUploadError(text: string) {
|
||||||
|
setError(text);
|
||||||
|
toastError(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function uploadFiles(files: File[]) {
|
||||||
|
const current = urlsRef.current;
|
||||||
|
const room = Math.max(0, maxCount - current.length);
|
||||||
|
const picked = files.slice(0, room);
|
||||||
|
if (!picked.length) {
|
||||||
|
showUploadError(`最多 ${maxCount} ${unit}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setUploading(true);
|
||||||
|
setError('');
|
||||||
|
const appended: string[] = [];
|
||||||
|
try {
|
||||||
|
for (const file of picked) {
|
||||||
|
if (!file.size) continue;
|
||||||
|
const result = await enqueueUpload(() => uploadFileToOss(file, { bizType, mediaType }));
|
||||||
|
appended.push(result.url);
|
||||||
|
}
|
||||||
|
if (appended.length) {
|
||||||
|
const next = [...urlsRef.current, ...appended];
|
||||||
|
urlsRef.current = next;
|
||||||
|
onChangeRef.current?.(next);
|
||||||
|
toastSuccess(`已上传 ${appended.length} ${unit}`);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
showUploadError(e instanceof Error ? e.message : '上传失败');
|
||||||
|
} finally {
|
||||||
|
setUploading(false);
|
||||||
|
if (inputRef.current) inputRef.current.value = '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function pickWechat() {
|
||||||
|
if (pickingRef.current || uploading || disabled || remaining <= 0) return;
|
||||||
|
pickingRef.current = true;
|
||||||
|
setError('');
|
||||||
|
try {
|
||||||
|
await weixinSdk.init();
|
||||||
|
const files = await weixinSdk.chooseImages({
|
||||||
|
count: Math.min(remaining, 9),
|
||||||
|
sourceType: ['album', 'camera'],
|
||||||
|
});
|
||||||
|
if (!files?.length) return;
|
||||||
|
await uploadFiles(files);
|
||||||
|
} catch (e) {
|
||||||
|
const msg = e instanceof Error ? e.message : '无法打开相册';
|
||||||
|
if (isCancelError(msg)) return;
|
||||||
|
const formatted = formatChooseImageFailMessage(msg) || msg;
|
||||||
|
showUploadError(formatted);
|
||||||
|
inputRef.current?.click();
|
||||||
|
} finally {
|
||||||
|
pickingRef.current = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function openPicker() {
|
||||||
|
if (inWechat) void pickWechat();
|
||||||
|
else inputRef.current?.click();
|
||||||
|
}
|
||||||
|
|
||||||
|
function removeAt(index: number) {
|
||||||
|
if (disabled) return;
|
||||||
|
onChange?.(urls.filter((_, i) => i !== index));
|
||||||
|
}
|
||||||
|
|
||||||
|
const thumb = (url: string, index: number) => (
|
||||||
|
<div key={`${url}-${index}`} className={isGrid ? 'partner-upload-grid-thumb' : undefined} style={isGrid ? undefined : { position: 'relative', width: 88, height: 88 }}>
|
||||||
|
{isPdf(url) ? (
|
||||||
|
<a
|
||||||
|
href={url}
|
||||||
|
target="_blank"
|
||||||
|
rel="noreferrer"
|
||||||
|
style={{
|
||||||
|
display: 'flex',
|
||||||
|
width: isGrid ? '100%' : 88,
|
||||||
|
height: isGrid ? '100%' : 88,
|
||||||
|
flexDirection: 'column',
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
gap: 2,
|
||||||
|
borderRadius: 8,
|
||||||
|
border: '1px solid rgba(0,0,0,0.08)',
|
||||||
|
background: '#f7f7f7',
|
||||||
|
fontSize: 12,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<span className="material-symbols-outlined text-primary" style={{ fontSize: 26 }}>
|
||||||
|
description
|
||||||
|
</span>
|
||||||
|
<span className="text-muted">PDF</span>
|
||||||
|
</a>
|
||||||
|
) : (
|
||||||
|
<img
|
||||||
|
src={url}
|
||||||
|
alt=""
|
||||||
|
style={{
|
||||||
|
width: isGrid ? '100%' : 88,
|
||||||
|
height: isGrid ? '100%' : 88,
|
||||||
|
objectFit: 'cover',
|
||||||
|
borderRadius: isGrid ? 12 : 8,
|
||||||
|
display: 'block',
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
{!disabled ? (
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="partner-packages-remove"
|
||||||
|
style={{
|
||||||
|
position: 'absolute',
|
||||||
|
top: 2,
|
||||||
|
right: 2,
|
||||||
|
margin: 0,
|
||||||
|
padding: '2px 6px',
|
||||||
|
fontSize: 12,
|
||||||
|
background: 'rgba(0,0,0,0.55)',
|
||||||
|
color: '#fff',
|
||||||
|
borderRadius: 4,
|
||||||
|
}}
|
||||||
|
onClick={() => removeAt(index)}
|
||||||
|
>
|
||||||
|
删
|
||||||
|
</button>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="partner-oss-upload">
|
||||||
|
<input
|
||||||
|
ref={inputRef}
|
||||||
|
type="file"
|
||||||
|
accept={accept}
|
||||||
|
multiple
|
||||||
|
className="partner-oss-upload-input"
|
||||||
|
disabled={disabled || uploading || remaining <= 0}
|
||||||
|
onChange={(e) => {
|
||||||
|
const list = Array.from(e.target.files ?? []);
|
||||||
|
if (list.length) void uploadFiles(list);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{isGrid ? (
|
||||||
|
<div className="partner-upload-grid">
|
||||||
|
{urls.map((url, index) => thumb(url, index))}
|
||||||
|
{remaining > 0 && !disabled ? (
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="partner-upload-dashed partner-upload-dashed--compact"
|
||||||
|
disabled={uploading}
|
||||||
|
onClick={openPicker}
|
||||||
|
aria-label={uploading ? '上传中' : `添加${unit}(${urls.length}/${maxCount})`}
|
||||||
|
>
|
||||||
|
<span className="material-symbols-outlined text-primary" style={{ fontSize: 28 }}>
|
||||||
|
{uploading ? 'hourglass_top' : 'add'}
|
||||||
|
</span>
|
||||||
|
</button>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
{urls.length > 0 ? (
|
||||||
|
<div style={{ display: 'flex', flexWrap: 'wrap', gap: 8, marginBottom: 8 }}>
|
||||||
|
{urls.map((url, index) => thumb(url, index))}
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="partner-upload-dashed partner-upload-dashed--compact"
|
||||||
|
disabled={disabled || uploading || remaining <= 0}
|
||||||
|
onClick={openPicker}
|
||||||
|
>
|
||||||
|
<span className="material-symbols-outlined text-primary" style={{ fontSize: 28 }}>
|
||||||
|
{uploading ? 'hourglass_top' : 'add_a_photo'}
|
||||||
|
</span>
|
||||||
|
<span className="text-primary" style={{ fontWeight: 500 }}>
|
||||||
|
{uploading
|
||||||
|
? '上传中…'
|
||||||
|
: remaining <= 0
|
||||||
|
? `已达上限 ${maxCount}${unit}`
|
||||||
|
: label ?? `批量上传(${urls.length}/${maxCount})`}
|
||||||
|
</span>
|
||||||
|
</button>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
{error ? (
|
||||||
|
<p className="partner-form-error" role="alert">
|
||||||
|
{error}
|
||||||
|
</p>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
import { useRef, useState } from 'react';
|
import { useEffect, useRef, useState } from 'react';
|
||||||
import { uploadFileToOss, type OssMediaType } from '../lib/upload';
|
import { uploadFileToOss, type OssMediaType } from '../lib/upload';
|
||||||
import { enqueueUpload } from '../lib/upload-lock';
|
import { enqueueUpload } from '../lib/upload-lock';
|
||||||
|
import { formatChooseImageFailMessage } from '@dukang/weixin-sdk';
|
||||||
|
import { isWechatEnv, weixinSdk } from '../lib/weixin';
|
||||||
import { toastError } from '../lib/toast';
|
import { toastError } from '../lib/toast';
|
||||||
|
|
||||||
type OssUploadFieldProps = {
|
type OssUploadFieldProps = {
|
||||||
@@ -12,9 +14,28 @@ type OssUploadFieldProps = {
|
|||||||
wide?: boolean;
|
wide?: boolean;
|
||||||
compact?: boolean;
|
compact?: boolean;
|
||||||
label?: string;
|
label?: string;
|
||||||
|
/** 兼容现有调用:选图不再依赖 openId 绑定 */
|
||||||
|
wechatReady?: boolean;
|
||||||
|
onWechatReadyChange?: (ready: boolean) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
const DEFAULT_MAX_MB = 10;
|
function isCancelError(msg: string): boolean {
|
||||||
|
return /cancel|取消/i.test(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatWechatUploadError(e: unknown): string {
|
||||||
|
const msg = e instanceof Error ? e.message : '无法打开相册';
|
||||||
|
const formatted = formatChooseImageFailMessage(msg);
|
||||||
|
if (formatted) return formatted;
|
||||||
|
if (/invalid signature/i.test(msg)) {
|
||||||
|
return '微信 JSSDK 签名校验失败:请确认公众号已配置 JS 接口安全域名,并刷新页面后重试';
|
||||||
|
}
|
||||||
|
return msg;
|
||||||
|
}
|
||||||
|
|
||||||
|
function acceptsImages(accept: string) {
|
||||||
|
return accept.includes('image');
|
||||||
|
}
|
||||||
|
|
||||||
export default function OssUploadField({
|
export default function OssUploadField({
|
||||||
value,
|
value,
|
||||||
@@ -27,8 +48,10 @@ export default function OssUploadField({
|
|||||||
label,
|
label,
|
||||||
}: OssUploadFieldProps) {
|
}: OssUploadFieldProps) {
|
||||||
const inputRef = useRef<HTMLInputElement>(null);
|
const inputRef = useRef<HTMLInputElement>(null);
|
||||||
|
const pickingRef = useRef(false);
|
||||||
const [uploading, setUploading] = useState(false);
|
const [uploading, setUploading] = useState(false);
|
||||||
const [error, setError] = useState('');
|
const [error, setError] = useState('');
|
||||||
|
const [showAlbumFallback, setShowAlbumFallback] = useState(false);
|
||||||
|
|
||||||
function showUploadError(text: string) {
|
function showUploadError(text: string) {
|
||||||
setError(text);
|
setError(text);
|
||||||
@@ -37,16 +60,23 @@ export default function OssUploadField({
|
|||||||
|
|
||||||
const resolvedAccept =
|
const resolvedAccept =
|
||||||
accept ?? (mediaType === 'VIDEO' ? 'video/*' : mediaType === 'FILE' ? 'image/*,.pdf' : 'image/*');
|
accept ?? (mediaType === 'VIDEO' ? 'video/*' : mediaType === 'FILE' ? 'image/*,.pdf' : 'image/*');
|
||||||
|
const inWechat = isWechatEnv();
|
||||||
|
const useWechatPicker =
|
||||||
|
inWechat && (mediaType === 'IMAGE' || (mediaType === 'FILE' && acceptsImages(resolvedAccept)));
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!useWechatPicker) return;
|
||||||
|
// 仅预热,勿在每次点击时 reset,否则取消后再点常无法调起
|
||||||
|
void weixinSdk.init().catch(() => {
|
||||||
|
/* 点击上传时会再次初始化 */
|
||||||
|
});
|
||||||
|
}, [useWechatPicker]);
|
||||||
|
|
||||||
async function persistUpload(file: File) {
|
async function persistUpload(file: File) {
|
||||||
if (!file.size) {
|
if (!file.size) {
|
||||||
showUploadError('图片读取失败,请重新选择');
|
showUploadError('图片读取失败,请重新选择');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (file.size > DEFAULT_MAX_MB * 1024 * 1024) {
|
|
||||||
showUploadError(`文件不能超过 ${DEFAULT_MAX_MB}MB`);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const result = await uploadFileToOss(file, { bizType, mediaType });
|
const result = await uploadFileToOss(file, { bizType, mediaType });
|
||||||
onChange?.(result.url);
|
onChange?.(result.url);
|
||||||
}
|
}
|
||||||
@@ -64,21 +94,66 @@ export default function OssUploadField({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function pickFile() {
|
async function pickWechatImage() {
|
||||||
if (uploading) return;
|
if (pickingRef.current || uploading) return;
|
||||||
|
pickingRef.current = true;
|
||||||
setError('');
|
setError('');
|
||||||
|
try {
|
||||||
|
// 不要每次 reset:会打断 JSSDK,取消后再点经常无法调起相机/相册
|
||||||
|
await weixinSdk.init();
|
||||||
|
const files = await weixinSdk.chooseImages({
|
||||||
|
count: 1,
|
||||||
|
sourceType: ['album', 'camera'],
|
||||||
|
});
|
||||||
|
// 取消或未选图:直接结束,允许再次点击
|
||||||
|
if (!files?.length) return;
|
||||||
|
|
||||||
|
setUploading(true);
|
||||||
|
try {
|
||||||
|
// 仅串行化实际上传,选图本身不占上传锁,避免取消后锁态异常
|
||||||
|
await enqueueUpload(() => persistUpload(files[0]!));
|
||||||
|
} finally {
|
||||||
|
setUploading(false);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
const msg = e instanceof Error ? e.message : '无法打开相册';
|
||||||
|
if (isCancelError(msg)) return;
|
||||||
|
throw e;
|
||||||
|
} finally {
|
||||||
|
pickingRef.current = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function pickFile() {
|
||||||
|
if (uploading || pickingRef.current) return;
|
||||||
|
setError('');
|
||||||
|
|
||||||
|
if (useWechatPicker) {
|
||||||
|
try {
|
||||||
|
await pickWechatImage();
|
||||||
|
} catch (e) {
|
||||||
|
const msg = e instanceof Error ? e.message : '无法打开相册';
|
||||||
|
if (isCancelError(msg)) return;
|
||||||
|
const formatted = formatWechatUploadError(e);
|
||||||
|
setError(`${formatted},可改从系统相册选择`);
|
||||||
|
setShowAlbumFallback(true);
|
||||||
|
inputRef.current?.click();
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
inputRef.current?.click();
|
inputRef.current?.click();
|
||||||
}
|
}
|
||||||
|
|
||||||
const isImage = mediaType === 'IMAGE' && value;
|
const isImage = mediaType === 'IMAGE' && value;
|
||||||
const isFile = mediaType === 'FILE' && value;
|
const isFile = mediaType === 'FILE' && value;
|
||||||
const busy = uploading;
|
const busy = uploading;
|
||||||
const pickerLabel = label ?? (mediaType === 'IMAGE' ? '从系统相册选择' : '点击上传');
|
const pickerLabel = label ?? (useWechatPicker ? '拍照 / 从相册选择' : '点击上传');
|
||||||
|
|
||||||
const triggerProps = {
|
const triggerProps = {
|
||||||
type: 'button' as const,
|
type: 'button' as const,
|
||||||
disabled: busy,
|
disabled: busy,
|
||||||
onClick: pickFile,
|
onClick: () => void pickFile(),
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -92,6 +167,7 @@ export default function OssUploadField({
|
|||||||
onChange={(e) => {
|
onChange={(e) => {
|
||||||
const file = e.target.files?.[0];
|
const file = e.target.files?.[0];
|
||||||
if (file) {
|
if (file) {
|
||||||
|
setShowAlbumFallback(false);
|
||||||
void uploadSelectedFile(file);
|
void uploadSelectedFile(file);
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
@@ -120,13 +196,24 @@ export default function OssUploadField({
|
|||||||
className={`partner-upload-dashed${wide ? ' partner-upload-dashed--wide' : ''}${compact ? ' partner-upload-dashed--compact' : ''}`}
|
className={`partner-upload-dashed${wide ? ' partner-upload-dashed--wide' : ''}${compact ? ' partner-upload-dashed--compact' : ''}`}
|
||||||
>
|
>
|
||||||
<span className="material-symbols-outlined text-primary" style={{ fontSize: compact ? 28 : 36 }}>
|
<span className="material-symbols-outlined text-primary" style={{ fontSize: compact ? 28 : 36 }}>
|
||||||
{busy ? 'hourglass_top' : 'photo_library'}
|
{busy ? 'hourglass_top' : 'add_a_photo'}
|
||||||
</span>
|
</span>
|
||||||
<span className="text-primary" style={{ fontWeight: 500 }}>
|
<span className="text-primary" style={{ fontWeight: 500 }}>
|
||||||
{uploading ? '上传中…' : pickerLabel}
|
{uploading ? '上传中…' : pickerLabel}
|
||||||
</span>
|
</span>
|
||||||
</button>
|
</button>
|
||||||
)}
|
)}
|
||||||
|
{showAlbumFallback && useWechatPicker && (
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="partner-btn-outline"
|
||||||
|
style={{ marginTop: 8, width: '100%' }}
|
||||||
|
disabled={busy}
|
||||||
|
onClick={() => inputRef.current?.click()}
|
||||||
|
>
|
||||||
|
从系统相册选择
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
{error && <p className="partner-form-error" role="alert">{error}</p>}
|
{error && <p className="partner-form-error" role="alert">{error}</p>}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -0,0 +1,177 @@
|
|||||||
|
import { useState } from 'react';
|
||||||
|
import type { PackageFormItem } from '../lib/storePackages';
|
||||||
|
import { STORE_PACKAGE_IMAGE_MAX_COUNT, STORE_PACKAGE_MAX_COUNT } from '@dukang/shared-types';
|
||||||
|
import { emptyPackage } from '../lib/storePackages';
|
||||||
|
import MultiOssUploadField from './MultiOssUploadField';
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
items: PackageFormItem[];
|
||||||
|
onChange: (items: PackageFormItem[]) => void;
|
||||||
|
disabled?: boolean;
|
||||||
|
/** 嵌入拓店流程时不重复外层卡片边距 */
|
||||||
|
embedded?: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function StorePackagesForm({ items, onChange, disabled, embedded }: Props) {
|
||||||
|
const [collapsed, setCollapsed] = useState<Record<number, boolean>>({});
|
||||||
|
|
||||||
|
function updateAt(index: number, patch: Partial<PackageFormItem>) {
|
||||||
|
const next = items.map((item, i) => (i === index ? { ...item, ...patch } : item));
|
||||||
|
onChange(next);
|
||||||
|
}
|
||||||
|
|
||||||
|
function addItem() {
|
||||||
|
if (items.length >= STORE_PACKAGE_MAX_COUNT) return;
|
||||||
|
onChange([...items, emptyPackage(items.length)]);
|
||||||
|
}
|
||||||
|
|
||||||
|
function removeAt(index: number) {
|
||||||
|
onChange(items.filter((_, i) => i !== index).map((item, i) => ({ ...item, sortOrder: i })));
|
||||||
|
setCollapsed((prev) => {
|
||||||
|
const next: Record<number, boolean> = {};
|
||||||
|
Object.entries(prev).forEach(([k, v]) => {
|
||||||
|
const i = Number(k);
|
||||||
|
if (i < index) next[i] = v;
|
||||||
|
else if (i > index) next[i - 1] = v;
|
||||||
|
});
|
||||||
|
return next;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function toggleCollapse(index: number) {
|
||||||
|
setCollapsed((prev) => ({ ...prev, [index]: !prev[index] }));
|
||||||
|
}
|
||||||
|
|
||||||
|
const list = items.length ? items : [emptyPackage(0)];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className={`partner-packages-form${embedded ? ' partner-packages-form--embedded' : ''}`}>
|
||||||
|
{list.map((item, index) => {
|
||||||
|
const isCollapsed = !!collapsed[index];
|
||||||
|
const displayName = item.name.trim() || `套餐 ${index + 1}`;
|
||||||
|
return (
|
||||||
|
<section
|
||||||
|
key={index}
|
||||||
|
className={`partner-form-card partner-packages-item${isCollapsed ? ' partner-packages-item--collapsed' : ''}`}
|
||||||
|
style={embedded ? { marginLeft: 0, marginRight: 0 } : undefined}
|
||||||
|
>
|
||||||
|
<div className="partner-packages-item-head">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="partner-packages-toggle"
|
||||||
|
onClick={() => toggleCollapse(index)}
|
||||||
|
aria-expanded={!isCollapsed}
|
||||||
|
aria-label={isCollapsed ? '展开套餐' : '收起套餐'}
|
||||||
|
>
|
||||||
|
<span className="material-symbols-outlined">
|
||||||
|
{isCollapsed ? 'expand_more' : 'expand_less'}
|
||||||
|
</span>
|
||||||
|
<span className="headline-md">{displayName}</span>
|
||||||
|
</button>
|
||||||
|
{!disabled && list.length > 1 ? (
|
||||||
|
<button type="button" className="partner-packages-remove" onClick={() => removeAt(index)}>
|
||||||
|
删除
|
||||||
|
</button>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{!isCollapsed ? (
|
||||||
|
<>
|
||||||
|
<div className="partner-field">
|
||||||
|
<label>套餐名称 <span className="text-primary">*</span></label>
|
||||||
|
<div className="partner-field-input">
|
||||||
|
<span className="material-symbols-outlined">restaurant</span>
|
||||||
|
<input
|
||||||
|
placeholder="如:套餐A"
|
||||||
|
value={item.name}
|
||||||
|
disabled={disabled}
|
||||||
|
onChange={(e) => updateAt(index, { name: e.target.value })}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="partner-field">
|
||||||
|
<label>价格(元) <span className="text-primary">*</span></label>
|
||||||
|
<div className="partner-field-input">
|
||||||
|
<span className="material-symbols-outlined">payments</span>
|
||||||
|
<input
|
||||||
|
type="number"
|
||||||
|
min={0}
|
||||||
|
step={0.01}
|
||||||
|
placeholder="198"
|
||||||
|
value={item.price}
|
||||||
|
disabled={disabled}
|
||||||
|
onChange={(e) => updateAt(index, { price: e.target.value })}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="partner-field">
|
||||||
|
<label>菜品 <span className="text-primary">*</span></label>
|
||||||
|
<textarea
|
||||||
|
rows={3}
|
||||||
|
placeholder="红烧肉、红烧鱼、油焖茄子"
|
||||||
|
value={item.dishes}
|
||||||
|
disabled={disabled}
|
||||||
|
onChange={(e) => updateAt(index, { dishes: e.target.value })}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="partner-field">
|
||||||
|
<label>使用时间</label>
|
||||||
|
<textarea
|
||||||
|
rows={2}
|
||||||
|
placeholder="节假日除外"
|
||||||
|
value={item.usableTime || ''}
|
||||||
|
disabled={disabled}
|
||||||
|
onChange={(e) => updateAt(index, { usableTime: e.target.value })}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="partner-field">
|
||||||
|
<label>套餐图片(最多 {STORE_PACKAGE_IMAGE_MAX_COUNT} 张,支持批量)</label>
|
||||||
|
<MultiOssUploadField
|
||||||
|
bizType="STORE_PACKAGE"
|
||||||
|
maxCount={STORE_PACKAGE_IMAGE_MAX_COUNT}
|
||||||
|
disabled={disabled}
|
||||||
|
value={
|
||||||
|
Array.isArray(item.imageUrls) && item.imageUrls.length > 0
|
||||||
|
? item.imageUrls.map((u) => String(u ?? '')).filter((u) => u.trim())
|
||||||
|
: item.imageUrl
|
||||||
|
? [String(item.imageUrl)]
|
||||||
|
: []
|
||||||
|
}
|
||||||
|
onChange={(imageUrls) =>
|
||||||
|
updateAt(index, {
|
||||||
|
imageUrls,
|
||||||
|
imageUrl: imageUrls[0] ?? '',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="partner-field">
|
||||||
|
<label>其他说明</label>
|
||||||
|
<textarea
|
||||||
|
rows={2}
|
||||||
|
placeholder="不可叠加"
|
||||||
|
value={item.otherNotes || ''}
|
||||||
|
disabled={disabled}
|
||||||
|
onChange={(e) => updateAt(index, { otherNotes: e.target.value })}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
) : null}
|
||||||
|
</section>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
|
||||||
|
{!disabled && list.length < STORE_PACKAGE_MAX_COUNT ? (
|
||||||
|
<button type="button" className="partner-packages-add" onClick={addItem}>
|
||||||
|
<span className="material-symbols-outlined">add_circle</span>
|
||||||
|
添加套餐
|
||||||
|
</button>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,234 @@
|
|||||||
|
import { useEffect, useMemo, useState } from 'react';
|
||||||
|
import type { ClientRuntimeConfig } from '@dukang/shared-types';
|
||||||
|
import { request } from '../lib/api';
|
||||||
|
import {
|
||||||
|
buildTencentLocPickerUrl,
|
||||||
|
parseTencentLocPickerMessage,
|
||||||
|
type TencentPickedLocation,
|
||||||
|
} from '../lib/tencentLocPicker';
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
open: boolean;
|
||||||
|
onClose: () => void;
|
||||||
|
onPick: (loc: TencentPickedLocation) => void;
|
||||||
|
latitude?: number | null;
|
||||||
|
longitude?: number | null;
|
||||||
|
/** 保留兼容,iframe 选点不使用 */
|
||||||
|
region?: string | null;
|
||||||
|
};
|
||||||
|
|
||||||
|
let cachedKey: string | null | undefined;
|
||||||
|
|
||||||
|
async function loadTencentLbsKey(): Promise<string> {
|
||||||
|
if (cachedKey) return cachedKey;
|
||||||
|
const cfg = await request<ClientRuntimeConfig>('PARTNER_H5', '/common/client-config', {
|
||||||
|
silent: true,
|
||||||
|
});
|
||||||
|
const key = (cfg.tencentLbsKey || '').trim();
|
||||||
|
if (!key) {
|
||||||
|
throw new Error('未配置腾讯位置服务 Key,请联系管理员在系统设置中配置');
|
||||||
|
}
|
||||||
|
cachedKey = key;
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function TencentLocPickerOverlay({
|
||||||
|
open,
|
||||||
|
onClose,
|
||||||
|
onPick,
|
||||||
|
latitude,
|
||||||
|
longitude,
|
||||||
|
}: Props) {
|
||||||
|
const [key, setKey] = useState<string | null>(cachedKey ?? null);
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
const [error, setError] = useState('');
|
||||||
|
/** 选点结果仅存内存,界面不展示经纬度 */
|
||||||
|
const [pending, setPending] = useState<TencentPickedLocation | null>(null);
|
||||||
|
const [iframeReady, setIframeReady] = useState(false);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!open) {
|
||||||
|
setPending(null);
|
||||||
|
setIframeReady(false);
|
||||||
|
setError('');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let cancelled = false;
|
||||||
|
if (key) return;
|
||||||
|
setLoading(true);
|
||||||
|
void loadTencentLbsKey()
|
||||||
|
.then((k) => {
|
||||||
|
if (!cancelled) setKey(k);
|
||||||
|
})
|
||||||
|
.catch((e) => {
|
||||||
|
if (!cancelled) setError(e instanceof Error ? e.message : '加载地图配置失败');
|
||||||
|
})
|
||||||
|
.finally(() => {
|
||||||
|
if (!cancelled) setLoading(false);
|
||||||
|
});
|
||||||
|
return () => {
|
||||||
|
cancelled = true;
|
||||||
|
};
|
||||||
|
}, [open, key]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!open) return;
|
||||||
|
function onMessage(event: MessageEvent) {
|
||||||
|
const picked = parseTencentLocPickerMessage(event.data);
|
||||||
|
if (!picked) return;
|
||||||
|
setPending(picked);
|
||||||
|
}
|
||||||
|
window.addEventListener('message', onMessage);
|
||||||
|
return () => window.removeEventListener('message', onMessage);
|
||||||
|
}, [open]);
|
||||||
|
|
||||||
|
const src = useMemo(() => {
|
||||||
|
if (!key) return '';
|
||||||
|
const lat = latitude != null ? Number(latitude) : undefined;
|
||||||
|
const lng = longitude != null ? Number(longitude) : undefined;
|
||||||
|
return buildTencentLocPickerUrl(key, {
|
||||||
|
latitude: lat != null && Number.isFinite(lat) ? lat : undefined,
|
||||||
|
longitude: lng != null && Number.isFinite(lng) ? lng : undefined,
|
||||||
|
});
|
||||||
|
}, [key, latitude, longitude]);
|
||||||
|
|
||||||
|
if (!open) return null;
|
||||||
|
|
||||||
|
function confirmPick() {
|
||||||
|
if (!pending) return;
|
||||||
|
onPick(pending);
|
||||||
|
onClose();
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
className="partner-locpicker-overlay"
|
||||||
|
style={{
|
||||||
|
position: 'fixed',
|
||||||
|
inset: 0,
|
||||||
|
zIndex: 1000,
|
||||||
|
background: '#fff',
|
||||||
|
display: 'flex',
|
||||||
|
flexDirection: 'column',
|
||||||
|
height: '100dvh',
|
||||||
|
maxHeight: '-webkit-fill-available',
|
||||||
|
paddingTop: 'env(safe-area-inset-top)',
|
||||||
|
paddingBottom: 'env(safe-area-inset-bottom)',
|
||||||
|
boxSizing: 'border-box',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: 'flex',
|
||||||
|
flexDirection: 'column',
|
||||||
|
padding: '12px 12px 10px',
|
||||||
|
borderBottom: '1px solid rgba(0,0,0,0.06)',
|
||||||
|
flexShrink: 0,
|
||||||
|
gap: 10,
|
||||||
|
background: '#fff',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<h2
|
||||||
|
style={{
|
||||||
|
margin: 0,
|
||||||
|
textAlign: 'center',
|
||||||
|
fontWeight: 700,
|
||||||
|
fontSize: 17,
|
||||||
|
lineHeight: 1.3,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
地图选点
|
||||||
|
</h2>
|
||||||
|
<div style={{ display: 'flex', alignItems: 'center', gap: 10 }}>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="partner-btn-primary"
|
||||||
|
style={{
|
||||||
|
flex: 1,
|
||||||
|
padding: '12px 16px',
|
||||||
|
fontSize: 15,
|
||||||
|
fontWeight: 600,
|
||||||
|
opacity: pending ? 1 : 0.45,
|
||||||
|
width: 'auto',
|
||||||
|
}}
|
||||||
|
disabled={!pending}
|
||||||
|
onClick={confirmPick}
|
||||||
|
>
|
||||||
|
确认
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="partner-btn-outline"
|
||||||
|
style={{ padding: '12px 16px', minWidth: 72, flexShrink: 0 }}
|
||||||
|
onClick={onClose}
|
||||||
|
>
|
||||||
|
关闭
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p
|
||||||
|
className="label-md text-muted"
|
||||||
|
style={{
|
||||||
|
margin: 0,
|
||||||
|
padding: '8px 14px',
|
||||||
|
borderBottom: '1px solid rgba(0,0,0,0.04)',
|
||||||
|
flexShrink: 0,
|
||||||
|
fontSize: 12,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{pending ? '已选定位置,请点右上角「确认」' : '在地图上点选或搜索地点,选中后点右上角「确认」'}
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<div style={{ flex: 1, minHeight: 0, position: 'relative', background: '#f5f5f5' }}>
|
||||||
|
{loading ? (
|
||||||
|
<p className="label-md text-muted" style={{ padding: 24, textAlign: 'center' }}>
|
||||||
|
正在加载地图…
|
||||||
|
</p>
|
||||||
|
) : error ? (
|
||||||
|
<div style={{ padding: 24 }}>
|
||||||
|
<p className="label-md" style={{ color: 'var(--color-heritage-red, #a61d24)' }}>
|
||||||
|
{error}
|
||||||
|
</p>
|
||||||
|
<p className="label-md text-muted" style={{ marginTop: 12 }}>
|
||||||
|
请确认系统设置中已配置腾讯位置服务 Key,并白名单 apis.map.qq.com。
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
) : src ? (
|
||||||
|
<>
|
||||||
|
{!iframeReady ? (
|
||||||
|
<p
|
||||||
|
className="label-md text-muted"
|
||||||
|
style={{
|
||||||
|
position: 'absolute',
|
||||||
|
inset: 0,
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
margin: 0,
|
||||||
|
zIndex: 1,
|
||||||
|
pointerEvents: 'none',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
地图加载中…
|
||||||
|
</p>
|
||||||
|
) : null}
|
||||||
|
<iframe
|
||||||
|
title="地图选点"
|
||||||
|
src={src}
|
||||||
|
allow="geolocation *"
|
||||||
|
onLoad={() => setIframeReady(true)}
|
||||||
|
style={{
|
||||||
|
width: '100%',
|
||||||
|
height: '100%',
|
||||||
|
border: 0,
|
||||||
|
display: 'block',
|
||||||
|
background: '#fff',
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user