Compare commits
64 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 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 |
@@ -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 直存;套餐变更审核通过/驳回 |
|
||||||
|
|||||||
@@ -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`。
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ant-design/icons": "^5.5.1",
|
"@ant-design/icons": "^5.5.1",
|
||||||
"@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": "^6.1.0",
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ 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 StorePackageAuditsPage from './pages/StorePackageAuditsPage';
|
||||||
import StoresPage from './pages/StoresPage';
|
import StoresPage from './pages/StoresPage';
|
||||||
import StoreRatingsPage from './pages/StoreRatingsPage';
|
import StoreRatingsPage from './pages/StoreRatingsPage';
|
||||||
import StoreAccountsPage from './pages/StoreAccountsPage';
|
import StoreAccountsPage from './pages/StoreAccountsPage';
|
||||||
@@ -37,6 +38,7 @@ import TicketsPage from './pages/TicketsPage';
|
|||||||
import SupportTicketsPage from './pages/SupportTicketsPage';
|
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';
|
||||||
@@ -45,8 +47,13 @@ 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 WecomBotsPage from './pages/WecomBotsPage';
|
import WecomBotsPage from './pages/WecomBotsPage';
|
||||||
|
import WecomMessagePushesPage from './pages/WecomMessagePushesPage';
|
||||||
|
import WecomBotLogsPage from './pages/WecomBotLogsPage';
|
||||||
import LlmConfigsPage from './pages/LlmConfigsPage';
|
import LlmConfigsPage from './pages/LlmConfigsPage';
|
||||||
import KnowledgeBasesPage from './pages/KnowledgeBasesPage';
|
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 />;
|
||||||
@@ -73,12 +80,19 @@ 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={<WecomBotsPage />} />
|
<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="/llm-configs" element={<LlmConfigsPage />} />
|
||||||
<Route path="/knowledge-bases" element={<KnowledgeBasesPage />} />
|
<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-ratings" element={<StoreRatingsPage />} />
|
||||||
<Route path="/store-categories" element={<StoreCategoriesPage />} />
|
<Route path="/store-categories" element={<StoreCategoriesPage />} />
|
||||||
<Route path="/store-accounts" element={<StoreAccountsPage />} />
|
<Route path="/store-accounts" element={<StoreAccountsPage />} />
|
||||||
@@ -118,6 +132,7 @@ export default function App() {
|
|||||||
<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 />} />
|
||||||
|
|||||||
@@ -0,0 +1,253 @@
|
|||||||
|
import { useEffect, useState } from 'react';
|
||||||
|
import { Alert, Button, Form, Input, InputNumber, Modal, Space, Typography, message } from 'antd';
|
||||||
|
import { DownOutlined, UpOutlined } from '@ant-design/icons';
|
||||||
|
import type { StorePackageItemDto } from '@dukang/shared-types';
|
||||||
|
import { STORE_PACKAGE_MAX_COUNT } from '@dukang/shared-types';
|
||||||
|
import { request } from '../lib/api';
|
||||||
|
import OssUpload from './OssUpload';
|
||||||
|
type PackageRow = StorePackageItemDto;
|
||||||
|
|
||||||
|
function emptyRow(index = 0): PackageRow {
|
||||||
|
return { name: '', price: '0', dishes: '', usableTime: '', otherNotes: '', imageUrl: '', sortOrder: index };
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function AdminStorePackagesSection({ storeId }: { storeId: string }) {
|
||||||
|
const [items, setItems] = useState<PackageRow[]>([emptyRow()]);
|
||||||
|
const [collapsed, setCollapsed] = useState<Record<number, boolean>>({});
|
||||||
|
const [loading, setLoading] = useState(true);
|
||||||
|
const [saving, setSaving] = useState(false);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setLoading(true);
|
||||||
|
request<{ live: PackageRow[] }>(`/admin/stores/${storeId}/packages`)
|
||||||
|
.then((data) => {
|
||||||
|
setItems(
|
||||||
|
data.live?.length
|
||||||
|
? data.live.map((p, i) => ({ ...p, price: String(p.price), sortOrder: i }))
|
||||||
|
: [emptyRow()],
|
||||||
|
);
|
||||||
|
})
|
||||||
|
.catch((e) => message.error(e instanceof Error ? e.message : '加载套餐失败'))
|
||||||
|
.finally(() => setLoading(false));
|
||||||
|
}, [storeId]);
|
||||||
|
|
||||||
|
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() {
|
||||||
|
const filled = items
|
||||||
|
.map((item, index) => ({
|
||||||
|
name: item.name.trim(),
|
||||||
|
price: item.price.trim(),
|
||||||
|
dishes: item.dishes.trim(),
|
||||||
|
usableTime: item.usableTime?.trim() || null,
|
||||||
|
otherNotes: item.otherNotes?.trim() || null,
|
||||||
|
imageUrl: item.imageUrl?.trim() || null,
|
||||||
|
sortOrder: index,
|
||||||
|
}))
|
||||||
|
.filter((item) => item.name || item.dishes || item.price);
|
||||||
|
|
||||||
|
for (let i = 0; i < filled.length; i++) {
|
||||||
|
const item = filled[i];
|
||||||
|
if (!item.name) {
|
||||||
|
message.warning(`第 ${i + 1} 条套餐名称不能为空`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!item.dishes) {
|
||||||
|
message.warning(`第 ${i + 1} 条套餐菜品不能为空`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const price = Number(item.price);
|
||||||
|
if (!Number.isFinite(price) || price < 0) {
|
||||||
|
message.warning(`第 ${i + 1} 条套餐价格须为非负数字`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
setSaving(true);
|
||||||
|
try {
|
||||||
|
await request(`/admin/stores/${storeId}/packages`, {
|
||||||
|
method: 'PUT',
|
||||||
|
body: JSON.stringify({
|
||||||
|
packages: filled.map((p) => ({ ...p, price: Number(p.price).toFixed(2) })),
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
message.success('套餐已保存并生效');
|
||||||
|
} catch (e) {
|
||||||
|
message.error(e instanceof Error ? e.message : '保存失败');
|
||||||
|
} finally {
|
||||||
|
setSaving(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="该门店暂无套餐,可添加或保存为空。" />
|
||||||
|
<Button onClick={addRow} style={{ marginBottom: 16 }}>
|
||||||
|
添加套餐
|
||||||
|
</Button>
|
||||||
|
<Button type="primary" loading={saving} onClick={() => void save()}>
|
||||||
|
保存套餐
|
||||||
|
</Button>
|
||||||
|
</Form>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ( <Form layout="vertical" requiredMark={false}>
|
||||||
|
<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
|
||||||
|
placeholder="节假日除外"
|
||||||
|
value={item.usableTime || ''}
|
||||||
|
onChange={(e) => updateAt(index, { usableTime: e.target.value })}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
|
||||||
|
<Form.Item label="套餐图片" style={{ marginBottom: 12 }}>
|
||||||
|
<OssUpload
|
||||||
|
bizType="STORE_PACKAGE"
|
||||||
|
mediaType="IMAGE"
|
||||||
|
value={item.imageUrl || undefined}
|
||||||
|
onChange={(url) => updateAt(index, { imageUrl: url })}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
|
||||||
|
<Form.Item label="其他说明" style={{ marginBottom: 0 }}> <Input
|
||||||
|
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 }}>
|
||||||
|
修改后点击下方按钮保存,C 端将立即展示生效套餐。
|
||||||
|
</Typography.Paragraph>
|
||||||
|
|
||||||
|
<Button type="primary" loading={saving} onClick={() => void save()}>
|
||||||
|
保存套餐
|
||||||
|
</Button>
|
||||||
|
</Form>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -15,8 +15,6 @@ type OssUploadProps = {
|
|||||||
placeholder?: string;
|
placeholder?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
const DEFAULT_MAX_MB = 10;
|
|
||||||
|
|
||||||
export default function OssUpload({
|
export default function OssUpload({
|
||||||
value,
|
value,
|
||||||
onChange,
|
onChange,
|
||||||
@@ -24,7 +22,6 @@ 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);
|
||||||
@@ -34,12 +31,6 @@ export default function OssUpload({
|
|||||||
|
|
||||||
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 });
|
||||||
|
|||||||
@@ -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>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -18,6 +18,7 @@ import {
|
|||||||
LockOutlined,
|
LockOutlined,
|
||||||
SettingOutlined,
|
SettingOutlined,
|
||||||
AccountBookOutlined,
|
AccountBookOutlined,
|
||||||
|
ProjectOutlined,
|
||||||
} from '@ant-design/icons';
|
} from '@ant-design/icons';
|
||||||
import { hasAnySystemSettingsPermission } from '@dukang/shared-types';
|
import { hasAnySystemSettingsPermission } from '@dukang/shared-types';
|
||||||
import { clearAuth, request, type HqProfile } from '../lib/api';
|
import { clearAuth, request, type HqProfile } from '../lib/api';
|
||||||
@@ -42,7 +43,15 @@ 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-bots', icon: <TeamOutlined />, label: '企微机器人' },
|
{
|
||||||
|
key: 'wecom-group',
|
||||||
|
icon: <TeamOutlined />,
|
||||||
|
label: '企微机器人',
|
||||||
|
children: [
|
||||||
|
{ key: '/wecom/bots', label: '智能机器人' },
|
||||||
|
{ key: '/wecom/pushes', label: '消息推送' },
|
||||||
|
],
|
||||||
|
},
|
||||||
{ key: '/llm-configs', icon: <RobotOutlined />, label: '语言模型' },
|
{ key: '/llm-configs', icon: <RobotOutlined />, label: '语言模型' },
|
||||||
{ key: '/knowledge-bases', icon: <FileTextOutlined />, label: '知识库' },
|
{ key: '/knowledge-bases', icon: <FileTextOutlined />, label: '知识库' },
|
||||||
{
|
{
|
||||||
@@ -51,6 +60,7 @@ const MENU_ITEMS: MenuProps['items'] = [
|
|||||||
label: '门店',
|
label: '门店',
|
||||||
children: [
|
children: [
|
||||||
{ key: '/stores', label: '门店列表' },
|
{ key: '/stores', label: '门店列表' },
|
||||||
|
{ key: '/store-package-audits', label: '套餐审核' },
|
||||||
{ key: '/store-ratings', label: '门店评价' },
|
{ key: '/store-ratings', label: '门店评价' },
|
||||||
{ key: '/store-categories', label: '门店分类' },
|
{ key: '/store-categories', label: '门店分类' },
|
||||||
{ key: '/store-accounts', label: '门店账户' },
|
{ key: '/store-accounts', label: '门店账户' },
|
||||||
@@ -109,6 +119,16 @@ const MENU_ITEMS: MenuProps['items'] = [
|
|||||||
{ key: '/tickets/support', 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 资源库' },
|
||||||
{
|
{
|
||||||
@@ -121,6 +141,8 @@ 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: '权限分配' },
|
||||||
@@ -132,6 +154,9 @@ function menuAllowed(key: string, permissionKeys: string[]): boolean {
|
|||||||
if (key === 'tickets-group') {
|
if (key === 'tickets-group') {
|
||||||
return permissionKeys.includes('tickets') || permissionKeys.includes('tech_support');
|
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'> = {
|
const map: Record<string, string | 'system_settings_any'> = {
|
||||||
'/': 'dashboard',
|
'/': 'dashboard',
|
||||||
'/users': 'users',
|
'/users': 'users',
|
||||||
@@ -141,11 +166,14 @@ function menuAllowed(key: string, permissionKeys: string[]): boolean {
|
|||||||
'/product-detail-templates': 'products',
|
'/product-detail-templates': 'products',
|
||||||
'/orders': 'orders',
|
'/orders': 'orders',
|
||||||
'/promo-codes': 'promo_codes',
|
'/promo-codes': 'promo_codes',
|
||||||
'/wecom-bots': 'wecom_bots',
|
'/wecom/bots': 'wecom_bots',
|
||||||
|
'/wecom/pushes': 'wecom_bots',
|
||||||
|
'wecom-group': 'wecom_bots',
|
||||||
'/llm-configs': 'llm_configs',
|
'/llm-configs': 'llm_configs',
|
||||||
'/knowledge-bases': 'knowledge_bases',
|
'/knowledge-bases': 'knowledge_bases',
|
||||||
'stores-group': 'stores',
|
'stores-group': 'stores',
|
||||||
'/stores': 'stores',
|
'/stores': 'stores',
|
||||||
|
'/store-package-audits': 'stores',
|
||||||
'/store-ratings': 'stores',
|
'/store-ratings': 'stores',
|
||||||
'/store-categories': 'stores',
|
'/store-categories': 'stores',
|
||||||
'/store-accounts': 'stores',
|
'/store-accounts': 'stores',
|
||||||
@@ -172,14 +200,20 @@ function menuAllowed(key: string, permissionKeys: string[]): boolean {
|
|||||||
'/deliveries/xiaofeixia': 'deliveries',
|
'/deliveries/xiaofeixia': 'deliveries',
|
||||||
'/tickets': 'tickets',
|
'/tickets': 'tickets',
|
||||||
'/tickets/support': 'tech_support',
|
'/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',
|
'/invoices': 'invoices',
|
||||||
'/resources': 'resources',
|
'/resources': 'resources',
|
||||||
'logs-group': 'logs',
|
'logs-group': 'logs',
|
||||||
'/logs/users': 'logs',
|
'/logs/users': 'logs',
|
||||||
|
'/logs/wecom-bots': 'logs',
|
||||||
'/logs/stores': 'logs',
|
'/logs/stores': 'logs',
|
||||||
'/logs/partners': 'logs',
|
'/logs/partners': 'logs',
|
||||||
'/logs/hq': 'logs',
|
'/logs/hq': 'logs',
|
||||||
'/logs/third-party': 'logs',
|
'/logs/third-party': 'logs',
|
||||||
|
'/logs/domain-events': 'logs',
|
||||||
'/hq-permissions': 'hq_permissions',
|
'/hq-permissions': 'hq_permissions',
|
||||||
'/system-settings': 'system_settings_any',
|
'/system-settings': 'system_settings_any',
|
||||||
'/hq-accounts': 'hq_accounts',
|
'/hq-accounts': 'hq_accounts',
|
||||||
|
|||||||
@@ -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 = {
|
||||||
@@ -242,7 +243,8 @@ export default function BenefitCouponsPage() {
|
|||||||
|
|
||||||
<Drawer
|
<Drawer
|
||||||
title="权益券详情"
|
title="权益券详情"
|
||||||
width={720}
|
width={980}
|
||||||
|
styles={{ body: { paddingBottom: 24 } }}
|
||||||
open={drawerOpen}
|
open={drawerOpen}
|
||||||
onClose={() => setDrawerOpen(false)}
|
onClose={() => setDrawerOpen(false)}
|
||||||
extra={
|
extra={
|
||||||
@@ -310,14 +312,15 @@ export default function BenefitCouponsPage() {
|
|||||||
size="small"
|
size="small"
|
||||||
rowKey="id"
|
rowKey="id"
|
||||||
pagination={false}
|
pagination={false}
|
||||||
|
tableLayout="fixed"
|
||||||
locale={{ emptyText: '暂无关联核销单' }}
|
locale={{ emptyText: '暂无关联核销单' }}
|
||||||
dataSource={detail.redeemRecords ?? []}
|
dataSource={detail.redeemRecords ?? []}
|
||||||
columns={[
|
columns={[
|
||||||
{ title: '核销号', dataIndex: 'redeemNo', width: 160, ellipsis: true },
|
{ title: '核销号', dataIndex: 'redeemNo', ellipsis: true },
|
||||||
{
|
{
|
||||||
title: '角色',
|
title: '角色',
|
||||||
dataIndex: 'role',
|
dataIndex: 'role',
|
||||||
width: 70,
|
width: 72,
|
||||||
render: (v: string | undefined) =>
|
render: (v: string | undefined) =>
|
||||||
v === 'SECONDARY' ? <Tag color="orange">次券</Tag> : <Tag color="blue">主券</Tag>,
|
v === 'SECONDARY' ? <Tag color="orange">次券</Tag> : <Tag color="blue">主券</Tag>,
|
||||||
},
|
},
|
||||||
@@ -331,31 +334,31 @@ export default function BenefitCouponsPage() {
|
|||||||
{
|
{
|
||||||
title: '本券分摊',
|
title: '本券分摊',
|
||||||
dataIndex: 'couponAmount',
|
dataIndex: 'couponAmount',
|
||||||
width: 95,
|
width: 96,
|
||||||
render: (v: number | undefined, row: CouponRedeemRecord) =>
|
render: (v: number | undefined, row: CouponRedeemRecord) =>
|
||||||
`¥${Number(v ?? row.amount).toFixed(2)}`,
|
`¥${Number(v ?? row.amount).toFixed(2)}`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: '核销总额',
|
title: '核销总额',
|
||||||
dataIndex: 'amount',
|
dataIndex: 'amount',
|
||||||
width: 90,
|
width: 96,
|
||||||
render: (v: number) => `¥${Number(v).toFixed(2)}`,
|
render: (v: number) => `¥${Number(v).toFixed(2)}`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: '结算额',
|
title: '结算额',
|
||||||
dataIndex: 'settleAmount',
|
dataIndex: 'settleAmount',
|
||||||
width: 90,
|
width: 96,
|
||||||
render: (v: number) => `¥${Number(v).toFixed(2)}`,
|
render: (v: number) => `¥${Number(v).toFixed(2)}`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: '时间',
|
title: '时间',
|
||||||
dataIndex: 'createdAt',
|
dataIndex: 'createdAt',
|
||||||
width: 150,
|
width: 148,
|
||||||
render: (v: string) => fmtTime(v),
|
render: (v: string) => fmtTime(v),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: '操作',
|
title: '操作',
|
||||||
width: 70,
|
width: 64,
|
||||||
render: (_: unknown, row: CouponRedeemRecord) => (
|
render: (_: unknown, row: CouponRedeemRecord) => (
|
||||||
<Button type="link" size="small" onClick={() => void openRedeemDetail(row.id)}>
|
<Button type="link" size="small" onClick={() => void openRedeemDetail(row.id)}>
|
||||||
详情
|
详情
|
||||||
@@ -374,7 +377,7 @@ export default function BenefitCouponsPage() {
|
|||||||
|
|
||||||
<Drawer
|
<Drawer
|
||||||
title="核销单详情"
|
title="核销单详情"
|
||||||
width={520}
|
width={640}
|
||||||
open={redeemDrawerOpen}
|
open={redeemDrawerOpen}
|
||||||
onClose={() => {
|
onClose={() => {
|
||||||
setRedeemDrawerOpen(false);
|
setRedeemDrawerOpen(false);
|
||||||
@@ -385,79 +388,7 @@ export default function BenefitCouponsPage() {
|
|||||||
{redeemDetailLoading ? (
|
{redeemDetailLoading ? (
|
||||||
<Typography.Text type="secondary">加载中…</Typography.Text>
|
<Typography.Text type="secondary">加载中…</Typography.Text>
|
||||||
) : redeemDetail ? (
|
) : redeemDetail ? (
|
||||||
<Descriptions column={1} bordered size="small">
|
<RedeemRecordDetailDescriptions detail={redeemDetail} />
|
||||||
<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}
|
) : null}
|
||||||
</Drawer>
|
</Drawer>
|
||||||
</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>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -18,6 +18,7 @@ import type { ColumnsType } from 'antd/es/table';
|
|||||||
import { UploadOutlined } from '@ant-design/icons';
|
import { UploadOutlined } from '@ant-design/icons';
|
||||||
import type {
|
import type {
|
||||||
KnowledgeBaseDto,
|
KnowledgeBaseDto,
|
||||||
|
KnowledgeDocumentDetailDto,
|
||||||
KnowledgeDocumentDto,
|
KnowledgeDocumentDto,
|
||||||
} from '@dukang/shared-types';
|
} from '@dukang/shared-types';
|
||||||
import { request } from '../lib/api';
|
import { request } from '../lib/api';
|
||||||
@@ -49,6 +50,10 @@ export default function KnowledgeBasesPage() {
|
|||||||
const [docsLoading, setDocsLoading] = useState(false);
|
const [docsLoading, setDocsLoading] = useState(false);
|
||||||
const [docModalOpen, setDocModalOpen] = useState(false);
|
const [docModalOpen, setDocModalOpen] = useState(false);
|
||||||
const [docSaving, setDocSaving] = 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 } =
|
const { data, loading, page, pageSize, setPage, setPageSize, reload } =
|
||||||
useAdminList<KnowledgeBaseDto>(
|
useAdminList<KnowledgeBaseDto>(
|
||||||
@@ -195,28 +200,52 @@ export default function KnowledgeBasesPage() {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: '操作',
|
title: '操作',
|
||||||
width: 80,
|
width: 140,
|
||||||
render: (_, row) =>
|
render: (_, row) =>
|
||||||
drawerKb?.canEditFull ? (
|
drawerKb?.canEditFull ? (
|
||||||
<Popconfirm
|
<Space>
|
||||||
title="删除文档?"
|
<Button
|
||||||
onConfirm={async () => {
|
type="link"
|
||||||
try {
|
size="small"
|
||||||
await request(`/admin/knowledge-bases/${drawerKb.id}/documents/${row.id}`, {
|
onClick={async () => {
|
||||||
method: 'DELETE',
|
if (!drawerKb) return;
|
||||||
});
|
try {
|
||||||
message.success('已删除');
|
const detail = await request<KnowledgeDocumentDetailDto>(
|
||||||
void loadDocs(drawerKb);
|
`/admin/knowledge-bases/${drawerKb.id}/documents/${row.id}`,
|
||||||
reload();
|
);
|
||||||
} catch (e) {
|
setEditingDoc(row);
|
||||||
message.error(e instanceof Error ? e.message : String(e));
|
editDocForm.setFieldsValue({
|
||||||
}
|
title: detail.title,
|
||||||
}}
|
contentText: detail.contentText || '',
|
||||||
>
|
});
|
||||||
<Button type="link" size="small" danger>
|
setEditDocModalOpen(true);
|
||||||
删除
|
} catch (e) {
|
||||||
|
message.error(e instanceof Error ? e.message : String(e));
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
编辑
|
||||||
</Button>
|
</Button>
|
||||||
</Popconfirm>
|
<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,
|
) : null,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
@@ -398,6 +427,50 @@ export default function KnowledgeBasesPage() {
|
|||||||
</Form.Item>
|
</Form.Item>
|
||||||
</Form>
|
</Form>
|
||||||
</Modal>
|
</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>
|
</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` : '获取验证码'}
|
||||||
|
|||||||
@@ -168,10 +168,10 @@ 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" />
|
<DetailImageUrlList label="详情图" bizType="DETAIL" />
|
||||||
<Divider />
|
<Divider />
|
||||||
<Form.Item name="storyTitle" label="故事标题">
|
<Form.Item name="storyTitle" label="故事标题">
|
||||||
|
|||||||
@@ -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,7 +1,8 @@
|
|||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import { Button, Descriptions, Drawer, Form, Input, Select, Table, Tag, Typography } from 'antd';
|
import { Button, 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 { 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';
|
||||||
@@ -13,11 +14,16 @@ type Row = {
|
|||||||
settleAmount: number;
|
settleAmount: number;
|
||||||
channel?: RedeemChannel;
|
channel?: RedeemChannel;
|
||||||
createdAt: string;
|
createdAt: string;
|
||||||
user?: { userNo: string; phone: string | null };
|
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 [form] = Form.useForm();
|
const [form] = Form.useForm();
|
||||||
const [filters, setFilters] = useState<Record<string, string>>({});
|
const [filters, setFilters] = useState<Record<string, string>>({});
|
||||||
@@ -34,6 +40,17 @@ export default function RedeemRecordsPage() {
|
|||||||
);
|
);
|
||||||
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);
|
||||||
|
|
||||||
|
async function openDetail(id: string) {
|
||||||
|
setDetailLoading(true);
|
||||||
|
setDrawerOpen(true);
|
||||||
|
try {
|
||||||
|
setDetail(await request(`/admin/redeem-records/${id}`));
|
||||||
|
} finally {
|
||||||
|
setDetailLoading(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const columns: ColumnsType<Row> = [
|
const columns: ColumnsType<Row> = [
|
||||||
{ title: '核销号', dataIndex: 'redeemNo', width: 180 },
|
{ title: '核销号', dataIndex: 'redeemNo', width: 180 },
|
||||||
@@ -50,7 +67,19 @@ export default function RedeemRecordsPage() {
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{ title: '用户', dataIndex: ['user', 'userNo'], width: 110 },
|
{ 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}` },
|
||||||
@@ -60,14 +89,7 @@ export default function RedeemRecordsPage() {
|
|||||||
title: '操作',
|
title: '操作',
|
||||||
width: 80,
|
width: 80,
|
||||||
render: (_, row) => (
|
render: (_, row) => (
|
||||||
<Button
|
<Button type="link" size="small" onClick={() => void openDetail(row.id)}>
|
||||||
type="link"
|
|
||||||
size="small"
|
|
||||||
onClick={async () => {
|
|
||||||
setDetail(await request(`/admin/redeem-records/${row.id}`));
|
|
||||||
setDrawerOpen(true);
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
详情
|
详情
|
||||||
</Button>
|
</Button>
|
||||||
),
|
),
|
||||||
@@ -113,7 +135,7 @@ export default function RedeemRecordsPage() {
|
|||||||
loading={loading}
|
loading={loading}
|
||||||
columns={columns}
|
columns={columns}
|
||||||
dataSource={data?.items ?? []}
|
dataSource={data?.items ?? []}
|
||||||
scroll={{ x: 1100 }}
|
scroll={{ x: 1300 }}
|
||||||
pagination={{
|
pagination={{
|
||||||
current: page,
|
current: page,
|
||||||
pageSize,
|
pageSize,
|
||||||
@@ -125,22 +147,21 @@ export default function RedeemRecordsPage() {
|
|||||||
},
|
},
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<Drawer title="核销详情" width={520} open={drawerOpen} onClose={() => setDrawerOpen(false)}>
|
<Drawer
|
||||||
{detail && (
|
title="核销详情"
|
||||||
<Descriptions column={1} bordered size="small">
|
width={640}
|
||||||
<Descriptions.Item label="核销号">{String(detail.redeemNo)}</Descriptions.Item>
|
open={drawerOpen}
|
||||||
<Descriptions.Item label="方式">
|
onClose={() => {
|
||||||
{
|
setDrawerOpen(false);
|
||||||
REDEEM_CHANNEL_LABELS[
|
setDetail(null);
|
||||||
(detail.channel === 'PHONE' ? 'PHONE' : 'SCAN') as RedeemChannel
|
}}
|
||||||
]
|
destroyOnClose
|
||||||
}
|
>
|
||||||
</Descriptions.Item>
|
{detailLoading ? (
|
||||||
<Descriptions.Item label="核销额">¥{String(detail.amount)}</Descriptions.Item>
|
<Typography.Text type="secondary">加载中…</Typography.Text>
|
||||||
<Descriptions.Item label="结算额">¥{String(detail.settleAmount)}</Descriptions.Item>
|
) : detail ? (
|
||||||
<Descriptions.Item label="时间">{fmtTime(String(detail.createdAt))}</Descriptions.Item>
|
<RedeemRecordDetailDescriptions detail={detail} />
|
||||||
</Descriptions>
|
) : null}
|
||||||
)}
|
|
||||||
</Drawer>
|
</Drawer>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -0,0 +1,331 @@
|
|||||||
|
import { useEffect, useState } from 'react';
|
||||||
|
import {
|
||||||
|
Button,
|
||||||
|
Drawer,
|
||||||
|
Input,
|
||||||
|
Modal,
|
||||||
|
Space,
|
||||||
|
Table,
|
||||||
|
Tag,
|
||||||
|
Typography,
|
||||||
|
message,
|
||||||
|
} from 'antd';
|
||||||
|
import type { ColumnsType } from 'antd/es/table';
|
||||||
|
import type {
|
||||||
|
StorePackageAuditDetailDto,
|
||||||
|
StorePackageChangeRequestDto,
|
||||||
|
StorePackageItemDto,
|
||||||
|
StorePackageViewDto,
|
||||||
|
} from '@dukang/shared-types';
|
||||||
|
import { STORE_PACKAGE_CHANGE_STATUS_LABELS } from '@dukang/shared-types';
|
||||||
|
import { request, type Paginated } from '../lib/api';
|
||||||
|
import { fmtTime } from '../lib/constants';
|
||||||
|
|
||||||
|
function packageKey(pkg: StorePackageItemDto | StorePackageViewDto, index: number) {
|
||||||
|
const name = String(pkg.name ?? '').trim();
|
||||||
|
return name ? `name:${name}` : `idx:${index}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}> = [];
|
||||||
|
|
||||||
|
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 ?? '');
|
||||||
|
rows.push({ key, change: changed ? 'changed' : 'unchanged', live: l, proposed: p });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return rows;
|
||||||
|
}
|
||||||
|
|
||||||
|
const CHANGE_LABELS = {
|
||||||
|
added: { text: '新增', color: 'green' },
|
||||||
|
removed: { text: '删除', color: 'red' },
|
||||||
|
changed: { text: '变更', color: 'orange' },
|
||||||
|
unchanged: { text: '未变', color: 'default' },
|
||||||
|
} as const;
|
||||||
|
|
||||||
|
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 [rejectOpen, setRejectOpen] = useState(false);
|
||||||
|
const [rejectReason, setRejectReason] = useState('');
|
||||||
|
const [activeId, setActiveId] = useState<string | null>(null);
|
||||||
|
const [detailOpen, setDetailOpen] = useState(false);
|
||||||
|
const [detailLoading, setDetailLoading] = useState(false);
|
||||||
|
const [detail, setDetail] = useState<StorePackageAuditDetailDto | 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 = await request<Paginated<StorePackageChangeRequestDto>>(
|
||||||
|
`/admin/store-package-audits?${qs}`,
|
||||||
|
);
|
||||||
|
setItems(data.items);
|
||||||
|
setTotal(data.total);
|
||||||
|
setPage(data.page);
|
||||||
|
} catch (e) {
|
||||||
|
message.error(e instanceof Error ? e.message : '加载失败');
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
void reload(1, status);
|
||||||
|
}, [status]);
|
||||||
|
|
||||||
|
async function openDetail(id: string) {
|
||||||
|
setDetailOpen(true);
|
||||||
|
setDetailLoading(true);
|
||||||
|
setDetail(null);
|
||||||
|
try {
|
||||||
|
const data = await request<StorePackageAuditDetailDto>(`/admin/store-package-audits/${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-package-audits/${id}/audit`, {
|
||||||
|
method: 'PUT',
|
||||||
|
body: JSON.stringify(
|
||||||
|
action === 'REJECT' ? { action, rejectReason: reason } : { action },
|
||||||
|
),
|
||||||
|
});
|
||||||
|
message.success(action === 'APPROVE' ? '已通过' : '已驳回');
|
||||||
|
setDetailOpen(false);
|
||||||
|
void reload(page, status);
|
||||||
|
} catch (e) {
|
||||||
|
message.error(e instanceof Error ? e.message : '操作失败');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const diffRows = detail ? diffPackages(detail.livePackages ?? [], detail.packages ?? []) : [];
|
||||||
|
|
||||||
|
const diffColumns: ColumnsType<(typeof diffRows)[number]> = [
|
||||||
|
{
|
||||||
|
title: '变更',
|
||||||
|
dataIndex: 'change',
|
||||||
|
width: 72,
|
||||||
|
render: (v: keyof typeof CHANGE_LABELS) => {
|
||||||
|
const meta = CHANGE_LABELS[v];
|
||||||
|
return <Tag color={meta.color}>{meta.text}</Tag>;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '当前线上',
|
||||||
|
render: (_, row) =>
|
||||||
|
row.live ? (
|
||||||
|
<div>
|
||||||
|
<div><strong>{row.live.name}</strong> · ¥{row.live.price}</div>
|
||||||
|
<Typography.Text type="secondary">{row.live.dishes}</Typography.Text>
|
||||||
|
{row.live.usableTime ? (
|
||||||
|
<div><Typography.Text type="secondary">可用:{row.live.usableTime}</Typography.Text></div>
|
||||||
|
) : null}
|
||||||
|
{row.live.otherNotes ? (
|
||||||
|
<div><Typography.Text type="secondary">备注:{row.live.otherNotes}</Typography.Text></div>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
'—'
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '申请变更',
|
||||||
|
render: (_, row) =>
|
||||||
|
row.proposed ? (
|
||||||
|
<div>
|
||||||
|
<div><strong>{row.proposed.name}</strong> · ¥{row.proposed.price}</div>
|
||||||
|
<Typography.Text type="secondary">{row.proposed.dishes}</Typography.Text>
|
||||||
|
{row.proposed.usableTime ? (
|
||||||
|
<div><Typography.Text type="secondary">可用:{row.proposed.usableTime}</Typography.Text></div>
|
||||||
|
) : null}
|
||||||
|
{row.proposed.otherNotes ? (
|
||||||
|
<div><Typography.Text type="secondary">备注:{row.proposed.otherNotes}</Typography.Text></div>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
'—'
|
||||||
|
),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const columns: ColumnsType<StorePackageChangeRequestDto> = [
|
||||||
|
{ title: '门店', dataIndex: 'storeName', render: (_, row) => row.storeName || row.storeId },
|
||||||
|
{
|
||||||
|
title: '状态',
|
||||||
|
dataIndex: 'status',
|
||||||
|
render: (v: StorePackageChangeRequestDto['status']) => (
|
||||||
|
<Tag>{STORE_PACKAGE_CHANGE_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={() => 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>
|
||||||
|
<Typography.Title level={4}>套餐变更审核</Typography.Title>
|
||||||
|
<Space style={{ marginBottom: 16 }}>
|
||||||
|
{(['PENDING', 'APPROVED', 'REJECTED', ''] as const).map((s) => (
|
||||||
|
<Button key={s || 'all'} type={status === s ? 'primary' : 'default'} onClick={() => setStatus(s)}>
|
||||||
|
{s ? STORE_PACKAGE_CHANGE_STATUS_LABELS[s as keyof typeof STORE_PACKAGE_CHANGE_STATUS_LABELS] : '全部'}
|
||||||
|
</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={720}
|
||||||
|
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 }}>
|
||||||
|
<Tag>{STORE_PACKAGE_CHANGE_STATUS_LABELS[detail.status]}</Tag>
|
||||||
|
<Typography.Text type="secondary">
|
||||||
|
提交方:{detail.submitterType === 'PARTNER' ? '合伙人' : '门店'} · {fmtTime(detail.createdAt)}
|
||||||
|
</Typography.Text>
|
||||||
|
</Space>
|
||||||
|
{detail.rejectReason ? (
|
||||||
|
<Typography.Paragraph type="danger">驳回原因:{detail.rejectReason}</Typography.Paragraph>
|
||||||
|
) : null}
|
||||||
|
<Typography.Paragraph type="secondary">
|
||||||
|
线上 {detail.livePackages?.length ?? 0} 条 → 申请 {detail.packages?.length ?? 0} 条
|
||||||
|
</Typography.Paragraph>
|
||||||
|
<Table
|
||||||
|
size="small"
|
||||||
|
rowKey="key"
|
||||||
|
columns={diffColumns}
|
||||||
|
dataSource={diffRows}
|
||||||
|
pagination={false}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
) : 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>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import { useState } from 'react';
|
|
||||||
import { Button, Form, Input, Table, Typography } from 'antd';
|
import { Button, Form, Input, Table, Typography } from 'antd';
|
||||||
import type { ColumnsType } from 'antd/es/table';
|
import type { ColumnsType } from 'antd/es/table';
|
||||||
import { useSearchParams } from 'react-router-dom';
|
import { useSearchParams } from 'react-router-dom';
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ import { resolveRegionBinding } from '../lib/china-region';
|
|||||||
import ChinaRegionCascader from '../components/ChinaRegionCascader';
|
import ChinaRegionCascader from '../components/ChinaRegionCascader';
|
||||||
import OssUpload from '../components/OssUpload';
|
import OssUpload from '../components/OssUpload';
|
||||||
import TencentLocPickerModal from '../components/TencentLocPickerModal';
|
import TencentLocPickerModal from '../components/TencentLocPickerModal';
|
||||||
|
import AdminStorePackagesSection from '../components/AdminStorePackagesSection';
|
||||||
|
|
||||||
const CREATE_STEPS = [
|
const CREATE_STEPS = [
|
||||||
{ title: '基本信息' },
|
{ title: '基本信息' },
|
||||||
@@ -375,7 +376,7 @@ type StoreRow = {
|
|||||||
visibilityWhitelistEnabled?: boolean;
|
visibilityWhitelistEnabled?: boolean;
|
||||||
visibilityPhones?: string[];
|
visibilityPhones?: string[];
|
||||||
cityRef?: { name: string; code: string };
|
cityRef?: { name: string; code: string };
|
||||||
partner?: { companyName: string };
|
partner?: { id?: string; companyName?: string | null; name?: string | null; phone?: string | null };
|
||||||
account?: {
|
account?: {
|
||||||
phone: string;
|
phone: string;
|
||||||
name: string;
|
name: string;
|
||||||
@@ -393,13 +394,14 @@ type StoreRow = {
|
|||||||
category?: { id: string; name: string; parentId?: string | null } | null;
|
category?: { id: string; name: string; parentId?: string | null } | null;
|
||||||
};
|
};
|
||||||
|
|
||||||
type PartnerOption = { id: string; companyName: string; name?: string };
|
type PartnerOption = { id: string; companyName?: string | null; name?: string | null; phone?: string | null };
|
||||||
|
|
||||||
function partnerOptionLabel(p: PartnerOption): string {
|
function partnerOptionLabel(p: PartnerOption): string {
|
||||||
const company = (p.companyName || '').trim();
|
const company = (p.companyName || '').trim();
|
||||||
const person = (p.name || '').trim();
|
const person = (p.name || '').trim();
|
||||||
|
const phone = (p.phone || '').trim();
|
||||||
if (company && person) return `${company}-${person}`;
|
if (company && person) return `${company}-${person}`;
|
||||||
return company || person || p.id;
|
return company || person || phone || p.id;
|
||||||
}
|
}
|
||||||
type CityOption = {
|
type CityOption = {
|
||||||
id: string;
|
id: string;
|
||||||
@@ -866,7 +868,13 @@ export default function StoresPage() {
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{ title: '开城合伙人', dataIndex: ['partner', 'companyName'], width: 120 },
|
{
|
||||||
|
title: '开城合伙人',
|
||||||
|
dataIndex: 'partner',
|
||||||
|
width: 140,
|
||||||
|
render: (partner: StoreRow['partner']) =>
|
||||||
|
partner ? partnerOptionLabel({ id: partner.id ?? '', ...partner }) : '—',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
title: '可见',
|
title: '可见',
|
||||||
dataIndex: 'visibilityWhitelistEnabled',
|
dataIndex: 'visibilityWhitelistEnabled',
|
||||||
@@ -1214,6 +1222,11 @@ export default function StoresPage() {
|
|||||||
label: '审核材料',
|
label: '审核材料',
|
||||||
children: <StoreAuditMediaSection detail={detail} />,
|
children: <StoreAuditMediaSection detail={detail} />,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
key: 'packages',
|
||||||
|
label: '套餐',
|
||||||
|
children: <AdminStorePackagesSection storeId={String(detail.id)} />,
|
||||||
|
},
|
||||||
]}
|
]}
|
||||||
/>
|
/>
|
||||||
</Form>
|
</Form>
|
||||||
@@ -1398,14 +1411,20 @@ export default function StoresPage() {
|
|||||||
<OssUpload bizType="STORE_TITLE" mediaType="IMAGE" />
|
<OssUpload bizType="STORE_TITLE" mediaType="IMAGE" />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Typography.Text strong>环境照片</Typography.Text>
|
<Typography.Text strong>环境照片</Typography.Text>
|
||||||
|
<Typography.Paragraph type="secondary" style={{ marginTop: 4 }}>
|
||||||
|
至少 3 张,可继续添加
|
||||||
|
</Typography.Paragraph>
|
||||||
<Form.List name="envPhotoUrls">
|
<Form.List name="envPhotoUrls">
|
||||||
{(fields) => (
|
{(fields, { add }) => (
|
||||||
<div style={{ marginTop: 8 }}>
|
<div style={{ marginTop: 8 }}>
|
||||||
{fields.map((field, index) => (
|
{fields.map((field, index) => (
|
||||||
<Form.Item key={field.key} name={field.name} label={`环境图 ${index + 1}`}>
|
<Form.Item key={field.key} name={field.name} label={`环境图 ${index + 1}`}>
|
||||||
<OssUpload bizType="STORE_ENV" mediaType="IMAGE" />
|
<OssUpload bizType="STORE_ENV" mediaType="IMAGE" />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
))}
|
))}
|
||||||
|
<Button type="dashed" onClick={() => add('')} block>
|
||||||
|
添加环境照片
|
||||||
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</Form.List>
|
</Form.List>
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -61,34 +61,6 @@ function MockSmsCodePanel({ codes, loading }: { codes: MockSmsCodeItem[]; loadin
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function WecomAlertTestButton() {
|
|
||||||
const [testing, setTesting] = useState(false);
|
|
||||||
async function onTest() {
|
|
||||||
setTesting(true);
|
|
||||||
try {
|
|
||||||
const res = await request<{ ok: boolean; message: string }>(
|
|
||||||
'/admin/system-config/wecom-alert/test',
|
|
||||||
{ method: 'POST', body: '{}' },
|
|
||||||
);
|
|
||||||
message.success(res.message || '已发送测试告警');
|
|
||||||
} catch (e) {
|
|
||||||
message.error(e instanceof Error ? e.message : '发送失败');
|
|
||||||
} finally {
|
|
||||||
setTesting(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return (
|
|
||||||
<div style={{ marginTop: -8, marginBottom: 16 }}>
|
|
||||||
<Button size="small" loading={testing} onClick={() => void onTest()}>
|
|
||||||
发送测试告警
|
|
||||||
</Button>
|
|
||||||
<Typography.Text type="secondary" style={{ marginLeft: 8, fontSize: 12 }}>
|
|
||||||
需已配置 WECOM_ALERT_WEBHOOK_URL 并开启上方开关
|
|
||||||
</Typography.Text>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function renderField(
|
function renderField(
|
||||||
field: SystemConfigFieldMeta,
|
field: SystemConfigFieldMeta,
|
||||||
configuredSecrets: string[],
|
configuredSecrets: string[],
|
||||||
@@ -291,8 +263,6 @@ export default function SystemSettingsPage() {
|
|||||||
meta.configuredSecrets,
|
meta.configuredSecrets,
|
||||||
f.key === 'MOCK_SMS' && mockSmsEnabled ? (
|
f.key === 'MOCK_SMS' && mockSmsEnabled ? (
|
||||||
<MockSmsCodePanel codes={meta.mockSmsCodes ?? []} loading={loading} />
|
<MockSmsCodePanel codes={meta.mockSmsCodes ?? []} loading={loading} />
|
||||||
) : f.key === 'WECOM_ALERT_ENABLED' ? (
|
|
||||||
<WecomAlertTestButton />
|
|
||||||
) : undefined,
|
) : undefined,
|
||||||
),
|
),
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -10,11 +10,18 @@ import {
|
|||||||
Select,
|
Select,
|
||||||
Space,
|
Space,
|
||||||
Table,
|
Table,
|
||||||
|
Tag,
|
||||||
Typography,
|
Typography,
|
||||||
message,
|
message,
|
||||||
} from 'antd';
|
} 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';
|
||||||
@@ -31,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>(
|
||||||
@@ -101,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 },
|
||||||
@@ -159,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">
|
||||||
筛选
|
筛选
|
||||||
@@ -211,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>
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ 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 HqProfile, type Paginated } from '../lib/api';
|
import { request, type AdminUserRow, type HqProfile, type Paginated } from '../lib/api';
|
||||||
import { ORDER_STATUS_LABELS, fmtTime, maskPhone } from '../lib/constants';
|
import { ORDER_STATUS_LABELS, fmtTime, maskPhone } from '../lib/constants';
|
||||||
|
|
||||||
@@ -30,6 +30,14 @@ type UserOrderRow = {
|
|||||||
createdAt: string;
|
createdAt: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
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;
|
||||||
@@ -72,6 +80,7 @@ export default function UsersPage() {
|
|||||||
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('');
|
||||||
@@ -123,8 +132,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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -437,6 +452,28 @@ export default function UsersPage() {
|
|||||||
</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>
|
||||||
|
|||||||
@@ -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>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -20,13 +20,14 @@ import {
|
|||||||
} from 'antd';
|
} from 'antd';
|
||||||
import type { ColumnsType } from 'antd/es/table';
|
import type { ColumnsType } from 'antd/es/table';
|
||||||
import {
|
import {
|
||||||
WECOM_BOT_PERMISSIONS,
|
WECOM_BOT_PERMISSION_GROUPS,
|
||||||
WECOM_BOT_PERMISSION_LABELS,
|
WECOM_BOT_PERMISSION_LABELS,
|
||||||
WECOM_BOT_ROLE_DEFAULT_PERMISSIONS,
|
WECOM_BOT_ROLE_DEFAULT_PERMISSIONS,
|
||||||
WECOM_BOT_ROLE_LABELS,
|
WECOM_BOT_ROLE_LABELS,
|
||||||
WECOM_BOT_ROLES,
|
WECOM_BOT_ROLES,
|
||||||
type LlmApiConfigOptionDto,
|
type LlmApiConfigOptionDto,
|
||||||
type KnowledgeBaseOptionDto,
|
type KnowledgeBaseOptionDto,
|
||||||
|
type WecomAibotRuntimeDto,
|
||||||
type WecomBotDto,
|
type WecomBotDto,
|
||||||
type WecomBotPermission,
|
type WecomBotPermission,
|
||||||
type WecomBotRole,
|
type WecomBotRole,
|
||||||
@@ -36,17 +37,6 @@ import { fmtTime } from '../lib/constants';
|
|||||||
import { useAdminList } from '../lib/useAdminList';
|
import { useAdminList } from '../lib/useAdminList';
|
||||||
import OssUpload from '../components/OssUpload';
|
import OssUpload from '../components/OssUpload';
|
||||||
|
|
||||||
type ListRes = {
|
|
||||||
items: WecomBotDto[];
|
|
||||||
total: number;
|
|
||||||
page: number;
|
|
||||||
pageSize: number;
|
|
||||||
runtime?: {
|
|
||||||
masterEnabled: boolean;
|
|
||||||
bots: Array<{ id: string; connected: boolean; lastError: string | null }>;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
type FormValues = {
|
type FormValues = {
|
||||||
name: string;
|
name: string;
|
||||||
role: WecomBotRole;
|
role: WecomBotRole;
|
||||||
@@ -55,6 +45,7 @@ type FormValues = {
|
|||||||
avatarUrl?: string;
|
avatarUrl?: string;
|
||||||
welcome?: string;
|
welcome?: string;
|
||||||
permissions: WecomBotPermission[];
|
permissions: WecomBotPermission[];
|
||||||
|
reviewSuperAdminWecomUserIds?: string;
|
||||||
aiEnabled: boolean;
|
aiEnabled: boolean;
|
||||||
llmConfigId?: string | null;
|
llmConfigId?: string | null;
|
||||||
knowledgeBaseId?: string | null;
|
knowledgeBaseId?: string | null;
|
||||||
@@ -62,18 +53,70 @@ type FormValues = {
|
|||||||
sortOrder: number;
|
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() {
|
export default function WecomBotsPage() {
|
||||||
const [filterForm] = Form.useForm();
|
const [filterForm] = Form.useForm();
|
||||||
const [form] = Form.useForm<FormValues>();
|
const [form] = Form.useForm<FormValues>();
|
||||||
const [filters, setFilters] = useState<Record<string, string>>({});
|
const [filters, setFilters] = useState<Record<string, string>>({});
|
||||||
const [modalOpen, setModalOpen] = useState(false);
|
const [modalOpen, setModalOpen] = useState(false);
|
||||||
const [editing, setEditing] = useState<WecomBotDto | null>(null);
|
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 [saving, setSaving] = useState(false);
|
||||||
const [detail, setDetail] = useState<WecomBotDto | null>(null);
|
const [detail, setDetail] = useState<WecomBotDto | null>(null);
|
||||||
const [runtime, setRuntime] = useState<ListRes['runtime']>();
|
const [runtime, setRuntime] = useState<WecomAibotRuntimeDto>();
|
||||||
const [llmOptions, setLlmOptions] = useState<LlmApiConfigOptionDto[]>([]);
|
const [llmOptions, setLlmOptions] = useState<LlmApiConfigOptionDto[]>([]);
|
||||||
const [kbOptions, setKbOptions] = useState<KnowledgeBaseOptionDto[]>([]);
|
const [kbOptions, setKbOptions] = useState<KnowledgeBaseOptionDto[]>([]);
|
||||||
const roleWatch = Form.useWatch('role', form);
|
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>(
|
const { data, loading, page, pageSize, setPage, setPageSize, reload } = useAdminList<WecomBotDto>(
|
||||||
'/admin/wecom-bots',
|
'/admin/wecom-bots',
|
||||||
@@ -87,11 +130,13 @@ export default function WecomBotsPage() {
|
|||||||
[filters],
|
[filters],
|
||||||
);
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
const loadRuntime = () =>
|
||||||
// useAdminList returns items; runtime comes from same API — fetch once for banner
|
request<WecomAibotRuntimeDto>('/admin/wecom-bots/runtime')
|
||||||
void request<ListRes>('/admin/wecom-bots?page=1&pageSize=1')
|
.then(setRuntime)
|
||||||
.then((res) => setRuntime(res.runtime))
|
|
||||||
.catch(() => {});
|
.catch(() => {});
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
void loadRuntime();
|
||||||
}, [data]);
|
}, [data]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -109,46 +154,51 @@ export default function WecomBotsPage() {
|
|||||||
});
|
});
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
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() {
|
function openCreate() {
|
||||||
setEditing(null);
|
setEditing(null);
|
||||||
form.setFieldsValue({
|
setFormInitial({ ...CREATE_DEFAULTS });
|
||||||
name: '',
|
setFormReady(true);
|
||||||
role: 'CUSTOMER_SERVICE',
|
|
||||||
botId: '',
|
|
||||||
secret: '',
|
|
||||||
avatarUrl: '',
|
|
||||||
welcome: '',
|
|
||||||
permissions: [...WECOM_BOT_ROLE_DEFAULT_PERMISSIONS.CUSTOMER_SERVICE],
|
|
||||||
aiEnabled: false,
|
|
||||||
llmConfigId: null,
|
|
||||||
knowledgeBaseId: null,
|
|
||||||
enabled: true,
|
|
||||||
sortOrder: 0,
|
|
||||||
});
|
|
||||||
setModalOpen(true);
|
setModalOpen(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
function openEdit(row: WecomBotDto) {
|
async function openEdit(row: WecomBotDto) {
|
||||||
setEditing(row);
|
setEditing(row);
|
||||||
form.setFieldsValue({
|
setFormInitial(null);
|
||||||
name: row.name,
|
setFormReady(false);
|
||||||
role: row.role,
|
|
||||||
botId: row.botId,
|
|
||||||
secret: '',
|
|
||||||
avatarUrl: row.avatarUrl || '',
|
|
||||||
welcome: row.welcome || '',
|
|
||||||
permissions: row.permissions,
|
|
||||||
aiEnabled: row.aiEnabled,
|
|
||||||
llmConfigId: row.llmConfigId,
|
|
||||||
knowledgeBaseId: row.knowledgeBaseId,
|
|
||||||
enabled: row.enabled,
|
|
||||||
sortOrder: row.sortOrder,
|
|
||||||
});
|
|
||||||
setModalOpen(true);
|
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() {
|
async function submit() {
|
||||||
const values = await form.validateFields();
|
const values = await form.validateFields();
|
||||||
|
const permissions = (form.getFieldValue('permissions') ?? values.permissions) as WecomBotPermission[];
|
||||||
|
if (!permissions?.length) {
|
||||||
|
message.error('请至少选择一项权限');
|
||||||
|
return;
|
||||||
|
}
|
||||||
setSaving(true);
|
setSaving(true);
|
||||||
try {
|
try {
|
||||||
const payload = {
|
const payload = {
|
||||||
@@ -157,7 +207,8 @@ export default function WecomBotsPage() {
|
|||||||
botId: values.botId.trim(),
|
botId: values.botId.trim(),
|
||||||
avatarUrl: values.avatarUrl?.trim() || null,
|
avatarUrl: values.avatarUrl?.trim() || null,
|
||||||
welcome: values.welcome?.trim() || null,
|
welcome: values.welcome?.trim() || null,
|
||||||
permissions: values.permissions,
|
permissions,
|
||||||
|
reviewSuperAdminWecomUserIds: parseUserIdLines(values.reviewSuperAdminWecomUserIds),
|
||||||
aiEnabled: values.aiEnabled,
|
aiEnabled: values.aiEnabled,
|
||||||
llmConfigId: values.llmConfigId || null,
|
llmConfigId: values.llmConfigId || null,
|
||||||
knowledgeBaseId: values.knowledgeBaseId || null,
|
knowledgeBaseId: values.knowledgeBaseId || null,
|
||||||
@@ -165,13 +216,20 @@ export default function WecomBotsPage() {
|
|||||||
sortOrder: values.sortOrder,
|
sortOrder: values.sortOrder,
|
||||||
};
|
};
|
||||||
if (editing) {
|
if (editing) {
|
||||||
await request(`/admin/wecom-bots/${editing.id}`, {
|
const saved = await request<WecomBotDto>(`/admin/wecom-bots/${editing.id}`, {
|
||||||
method: 'PUT',
|
method: 'PUT',
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
...payload,
|
...payload,
|
||||||
secret: values.secret?.trim() || undefined,
|
secret: values.secret?.trim() || undefined,
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
if (!samePermissionSet(permissions, saved.permissions)) {
|
||||||
|
message.warning('权限与保存结果不一致,已用服务端数据刷新表单');
|
||||||
|
setFormInitial(mapDtoToForm(saved));
|
||||||
|
setEditing(saved);
|
||||||
|
reload();
|
||||||
|
return;
|
||||||
|
}
|
||||||
message.success('已更新');
|
message.success('已更新');
|
||||||
} else {
|
} else {
|
||||||
if (!values.secret?.trim()) {
|
if (!values.secret?.trim()) {
|
||||||
@@ -187,7 +245,7 @@ export default function WecomBotsPage() {
|
|||||||
});
|
});
|
||||||
message.success('已创建');
|
message.success('已创建');
|
||||||
}
|
}
|
||||||
setModalOpen(false);
|
closeModal();
|
||||||
reload();
|
reload();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
message.error(e instanceof Error ? e.message : '保存失败');
|
message.error(e instanceof Error ? e.message : '保存失败');
|
||||||
@@ -208,10 +266,10 @@ export default function WecomBotsPage() {
|
|||||||
|
|
||||||
async function reloadConnections() {
|
async function reloadConnections() {
|
||||||
try {
|
try {
|
||||||
const st = await request<{
|
const st = await request<WecomAibotRuntimeDto>('/admin/wecom-bots/reload', {
|
||||||
masterEnabled: boolean;
|
method: 'POST',
|
||||||
bots: Array<{ id: string; connected: boolean; lastError: string | null }>;
|
body: '{}',
|
||||||
}>('/admin/wecom-bots/reload', { method: 'POST', body: '{}' });
|
});
|
||||||
message.success('已重载长连接');
|
message.success('已重载长连接');
|
||||||
setRuntime(st);
|
setRuntime(st);
|
||||||
reload();
|
reload();
|
||||||
@@ -287,7 +345,7 @@ export default function WecomBotsPage() {
|
|||||||
fixed: 'right',
|
fixed: 'right',
|
||||||
render: (_, row) => (
|
render: (_, row) => (
|
||||||
<Space>
|
<Space>
|
||||||
<Button type="link" size="small" onClick={() => openEdit(row)}>
|
<Button type="link" size="small" onClick={() => void openEdit(row)}>
|
||||||
编辑
|
编辑
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
@@ -386,23 +444,39 @@ export default function WecomBotsPage() {
|
|||||||
<Modal
|
<Modal
|
||||||
title={editing ? '编辑企微机器人' : '创建企微机器人'}
|
title={editing ? '编辑企微机器人' : '创建企微机器人'}
|
||||||
open={modalOpen}
|
open={modalOpen}
|
||||||
onCancel={() => setModalOpen(false)}
|
onCancel={closeModal}
|
||||||
onOk={() => void submit()}
|
onOk={() => void submit()}
|
||||||
confirmLoading={saving}
|
confirmLoading={saving}
|
||||||
width={640}
|
width={640}
|
||||||
destroyOnClose
|
destroyOnClose
|
||||||
>
|
>
|
||||||
<Form form={form} layout="vertical">
|
{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: '请填写名称' }]}>
|
<Form.Item name="name" label="名称" rules={[{ required: true, message: '请填写名称' }]}>
|
||||||
<Input placeholder="如:客服机器人" maxLength={64} />
|
<Input placeholder="如:客服机器人" maxLength={64} />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item name="role" label="角色" rules={[{ required: true }]}>
|
<Form.Item name="role" label="角色" rules={[{ required: true }]}>
|
||||||
<Select
|
<Select
|
||||||
options={WECOM_BOT_ROLES.map((r) => ({ value: r, label: WECOM_BOT_ROLE_LABELS[r] }))}
|
options={WECOM_BOT_ROLES.map((r) => ({ value: r, label: WECOM_BOT_ROLE_LABELS[r] }))}
|
||||||
onChange={(role: WecomBotRole) => {
|
/>
|
||||||
|
</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]]);
|
form.setFieldValue('permissions', [...WECOM_BOT_ROLE_DEFAULT_PERMISSIONS[role]]);
|
||||||
}}
|
}}
|
||||||
/>
|
>
|
||||||
|
应用当前角色默认权限
|
||||||
|
</Button>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item name="avatarUrl" label="头像">
|
<Form.Item name="avatarUrl" label="头像">
|
||||||
<OssUpload bizType="WECOM_BOT_AVATAR" />
|
<OssUpload bizType="WECOM_BOT_AVATAR" />
|
||||||
@@ -420,21 +494,48 @@ export default function WecomBotsPage() {
|
|||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item
|
<Form.Item
|
||||||
name="permissions"
|
name="permissions"
|
||||||
label="权限"
|
label="权限(按模块)"
|
||||||
rules={[{ required: true, message: '请至少选择一项权限' }]}
|
rules={[
|
||||||
|
{
|
||||||
|
validator: (_, v: WecomBotPermission[] | undefined) =>
|
||||||
|
v?.length ? Promise.resolve() : Promise.reject(new Error('请至少选择一项权限')),
|
||||||
|
},
|
||||||
|
]}
|
||||||
extra={
|
extra={
|
||||||
roleWatch
|
<>
|
||||||
? `角色默认:${WECOM_BOT_ROLE_DEFAULT_PERMISSIONS[roleWatch as WecomBotRole]?.map((p) => WECOM_BOT_PERMISSION_LABELS[p]).join('、') || '无'}`
|
{roleWatch
|
||||||
: undefined
|
? `角色默认:${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
|
<Checkbox.Group style={{ width: '100%' }}>
|
||||||
options={WECOM_BOT_PERMISSIONS.map((p) => ({
|
{WECOM_BOT_PERMISSION_GROUPS.map((group) => (
|
||||||
value: p,
|
<div key={group.key} style={{ marginBottom: 12 }}>
|
||||||
label: WECOM_BOT_PERMISSION_LABELS[p],
|
<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>
|
</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="欢迎语">
|
<Form.Item name="welcome" label="欢迎语">
|
||||||
<Input.TextArea rows={3} placeholder="进入会话时的欢迎语,可空" />
|
<Input.TextArea rows={3} placeholder="进入会话时的欢迎语,可空" />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
@@ -475,6 +576,9 @@ export default function WecomBotsPage() {
|
|||||||
</Form.Item>
|
</Form.Item>
|
||||||
</Space>
|
</Space>
|
||||||
</Form>
|
</Form>
|
||||||
|
) : (
|
||||||
|
<Typography.Text type="secondary">加载中…</Typography.Text>
|
||||||
|
)}
|
||||||
</Modal>
|
</Modal>
|
||||||
|
|
||||||
<Drawer title="机器人详情" width={480} open={!!detail} onClose={() => setDetail(null)}>
|
<Drawer title="机器人详情" width={480} open={!!detail} onClose={() => setDetail(null)}>
|
||||||
@@ -496,6 +600,11 @@ export default function WecomBotsPage() {
|
|||||||
<Descriptions.Item label="权限">
|
<Descriptions.Item label="权限">
|
||||||
{detail.permissions.map((p) => WECOM_BOT_PERMISSION_LABELS[p] || p).join('、')}
|
{detail.permissions.map((p) => WECOM_BOT_PERMISSION_LABELS[p] || p).join('、')}
|
||||||
</Descriptions.Item>
|
</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="审批白名单">
|
||||||
|
{detail.reviewSuperAdminWecomUserIds?.length
|
||||||
|
? detail.reviewSuperAdminWecomUserIds.join('、')
|
||||||
|
: '—'}
|
||||||
|
</Descriptions.Item>
|
||||||
<Descriptions.Item label="欢迎语">{detail.welcome || '—'}</Descriptions.Item>
|
<Descriptions.Item label="欢迎语">{detail.welcome || '—'}</Descriptions.Item>
|
||||||
<Descriptions.Item label="AI 问答">{detail.aiEnabled ? '开' : '关'}</Descriptions.Item>
|
<Descriptions.Item label="AI 问答">{detail.aiEnabled ? '开' : '关'}</Descriptions.Item>
|
||||||
<Descriptions.Item label="语言模型">{detail.llmConfigName || '—'}</Descriptions.Item>
|
<Descriptions.Item label="语言模型">{detail.llmConfigName || '—'}</Descriptions.Item>
|
||||||
|
|||||||
@@ -0,0 +1,405 @@
|
|||||||
|
import { useState } from 'react';
|
||||||
|
import {
|
||||||
|
Avatar,
|
||||||
|
Button,
|
||||||
|
Checkbox,
|
||||||
|
Descriptions,
|
||||||
|
Form,
|
||||||
|
Input,
|
||||||
|
InputNumber,
|
||||||
|
Modal,
|
||||||
|
Popconfirm,
|
||||||
|
Select,
|
||||||
|
Space,
|
||||||
|
Switch,
|
||||||
|
Table,
|
||||||
|
Tag,
|
||||||
|
Typography,
|
||||||
|
message,
|
||||||
|
} from 'antd';
|
||||||
|
import type { ColumnsType } from 'antd/es/table';
|
||||||
|
import {
|
||||||
|
WECOM_PUSH_CONDITION_GROUPS,
|
||||||
|
WECOM_PUSH_CONDITION_LABELS,
|
||||||
|
type WecomMessagePushDto,
|
||||||
|
type WecomPushCondition,
|
||||||
|
} 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>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function WecomMessagePushesPage() {
|
||||||
|
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 (
|
||||||
|
<div>
|
||||||
|
<Typography.Title level={4}>企微机器人 · 消息推送</Typography.Title>
|
||||||
|
<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 />
|
||||||
|
</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>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -258,7 +258,7 @@ export default function WineryBillsPage() {
|
|||||||
酒厂对账单
|
酒厂对账单
|
||||||
</Typography.Title>
|
</Typography.Title>
|
||||||
<Typography.Text type="secondary">
|
<Typography.Text type="secondary">
|
||||||
每日 8:00 汇总昨日已付订单(实付 × {ratePct}%);未打款红色、已打款绿色,可展开订单明细
|
T+3:每日 8:00 汇总 3 天前(自然日)已完成的同城/跨城订单(实付 × {ratePct}%);未打款红色、已打款绿色,可展开订单明细
|
||||||
</Typography.Text>
|
</Typography.Text>
|
||||||
</Space>
|
</Space>
|
||||||
{canEditWineryBank ? (
|
{canEditWineryBank ? (
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ 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 = {
|
const descLabelStyle: CSSProperties = {
|
||||||
whiteSpace: 'nowrap',
|
whiteSpace: 'nowrap',
|
||||||
@@ -212,6 +213,14 @@ export default function PromoCodeDetailPage() {
|
|||||||
<Statistic title="扫码进入次数" value={stats?.scanCount ?? detail.scanCount} />
|
<Statistic title="扫码进入次数" value={stats?.scanCount ?? detail.scanCount} />
|
||||||
</Card>
|
</Card>
|
||||||
</Col>
|
</Col>
|
||||||
|
<Col xs={12} sm={6}>
|
||||||
|
<Card size="small">
|
||||||
|
<Statistic
|
||||||
|
title="归因用户数"
|
||||||
|
value={stats?.attributionCount ?? 0}
|
||||||
|
/>
|
||||||
|
</Card>
|
||||||
|
</Col>
|
||||||
<Col xs={12} sm={6}>
|
<Col xs={12} sm={6}>
|
||||||
<Card size="small">
|
<Card size="small">
|
||||||
<Statistic
|
<Statistic
|
||||||
@@ -235,6 +244,8 @@ export default function PromoCodeDetailPage() {
|
|||||||
</Col>
|
</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>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -9,6 +9,7 @@
|
|||||||
"lint": "echo ok"
|
"lint": "echo ok"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@dukang/client-logging": "workspace:*",
|
||||||
"@dukang/shared-types": "workspace:*",
|
"@dukang/shared-types": "workspace:*",
|
||||||
"@dukang/shared-ui": "workspace:*",
|
"@dukang/shared-ui": "workspace:*",
|
||||||
"@dukang/weixin-sdk": "workspace:*",
|
"@dukang/weixin-sdk": "workspace:*",
|
||||||
|
|||||||
@@ -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';
|
||||||
@@ -31,6 +32,7 @@ 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 />} />
|
||||||
@@ -68,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 />} />
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -19,8 +19,6 @@ type OssUploadFieldProps = {
|
|||||||
onWechatReadyChange?: (ready: boolean) => void;
|
onWechatReadyChange?: (ready: boolean) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
const DEFAULT_MAX_MB = 10;
|
|
||||||
|
|
||||||
function isCancelError(msg: string): boolean {
|
function isCancelError(msg: string): boolean {
|
||||||
return /cancel|取消/i.test(msg);
|
return /cancel|取消/i.test(msg);
|
||||||
}
|
}
|
||||||
@@ -79,10 +77,6 @@ export default function OssUploadField({
|
|||||||
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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,169 @@
|
|||||||
|
import { useState } from 'react';
|
||||||
|
import type { PackageFormItem } from '../lib/storePackages';
|
||||||
|
import { STORE_PACKAGE_MAX_COUNT } from '@dukang/shared-types';
|
||||||
|
import { emptyPackage } from '../lib/storePackages';
|
||||||
|
import OssUploadField from './OssUploadField';
|
||||||
|
|
||||||
|
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>
|
||||||
|
<div className="partner-field-input">
|
||||||
|
<span className="material-symbols-outlined">schedule</span>
|
||||||
|
<input
|
||||||
|
placeholder="节假日除外"
|
||||||
|
value={item.usableTime || ''}
|
||||||
|
disabled={disabled}
|
||||||
|
onChange={(e) => updateAt(index, { usableTime: e.target.value })}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="partner-field">
|
||||||
|
<label>套餐图片</label>
|
||||||
|
<OssUploadField
|
||||||
|
bizType="STORE_PACKAGE"
|
||||||
|
value={item.imageUrl || ''}
|
||||||
|
disabled={disabled}
|
||||||
|
onChange={(url) => updateAt(index, { imageUrl: url })}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="partner-field">
|
||||||
|
<label>其他说明</label>
|
||||||
|
<div className="partner-field-input">
|
||||||
|
<span className="material-symbols-outlined">info</span>
|
||||||
|
<input
|
||||||
|
placeholder="不可叠加"
|
||||||
|
value={item.otherNotes || ''}
|
||||||
|
disabled={disabled}
|
||||||
|
onChange={(e) => updateAt(index, { otherNotes: e.target.value })}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</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,16 @@
|
|||||||
|
import { createPartnerTracker } from '@dukang/client-logging';
|
||||||
|
import { apiBase } from './api';
|
||||||
|
|
||||||
|
const tracker = createPartnerTracker({
|
||||||
|
apiBase,
|
||||||
|
clientApp: 'PARTNER_H5',
|
||||||
|
getToken: () => localStorage.getItem('partnerAccessToken'),
|
||||||
|
});
|
||||||
|
|
||||||
|
export function trackPartner(eventName: string, params?: Record<string, unknown>) {
|
||||||
|
tracker.track(eventName, params);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function trackPartnerPageView(eventName: string, params?: Record<string, unknown>) {
|
||||||
|
tracker.trackPageView(eventName, params);
|
||||||
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
import type { PartnerMe, PartnerStaffRole } from '@dukang/shared-types';
|
import type { PartnerMe, PartnerStaffRole } from '@dukang/shared-types';
|
||||||
|
import { reportApiError } from '@dukang/client-logging';
|
||||||
import { isOnAppPath, toAppPath } from '@dukang/weixin-sdk';
|
import { isOnAppPath, toAppPath } from '@dukang/weixin-sdk';
|
||||||
import { showPartnerToast } from './toast';
|
import { showPartnerToast } from './toast';
|
||||||
|
|
||||||
@@ -159,6 +160,12 @@ async function rawRequest<T>(
|
|||||||
if (json.code !== 0) {
|
if (json.code !== 0) {
|
||||||
const err = new Error(json.message || '请求失败') as Error & { status?: number };
|
const err = new Error(json.message || '请求失败') as Error & { status?: number };
|
||||||
err.status = json.code === 401 ? 401 : json.code;
|
err.status = json.code === 401 ? 401 : json.code;
|
||||||
|
if (json.code === 400) {
|
||||||
|
reportApiError(
|
||||||
|
{ apiBase, clientApp: CLIENT_APP, getToken: () => localStorage.getItem(ACCESS_TOKEN) },
|
||||||
|
{ message: json.message || '请求失败', status: 400, url: path, category: 'validation_error' },
|
||||||
|
);
|
||||||
|
}
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
return json.data as T;
|
return json.data as T;
|
||||||
|
|||||||
@@ -29,6 +29,8 @@ export type StoreDraftForm = {
|
|||||||
bankAccountName: string;
|
bankAccountName: string;
|
||||||
bankAccountNo: string;
|
bankAccountNo: string;
|
||||||
bankBranch: string;
|
bankBranch: string;
|
||||||
|
/** 门店套餐(拓店第 4 步,可空) */
|
||||||
|
packages: import('@dukang/shared-types').StorePackageItemDto[];
|
||||||
};
|
};
|
||||||
|
|
||||||
export type StoreDraft = {
|
export type StoreDraft = {
|
||||||
@@ -68,6 +70,7 @@ export const defaultStoreForm = (): StoreDraftForm => ({
|
|||||||
bankAccountName: '',
|
bankAccountName: '',
|
||||||
bankAccountNo: '',
|
bankAccountNo: '',
|
||||||
bankBranch: '',
|
bankBranch: '',
|
||||||
|
packages: [],
|
||||||
});
|
});
|
||||||
|
|
||||||
const TIME_RE = /^([01]\d|2[0-3]):([0-5]\d)$/;
|
const TIME_RE = /^([01]\d|2[0-3]):([0-5]\d)$/;
|
||||||
@@ -79,12 +82,18 @@ function timeToMinutes(hhmm: string): number {
|
|||||||
return h * 60 + m;
|
return h * 60 + m;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const MIN_ENV_PHOTO_COUNT = 3;
|
||||||
|
|
||||||
export function normalizeStringArray(urls: unknown, minLen: number): string[] {
|
export function normalizeStringArray(urls: unknown, minLen: number): string[] {
|
||||||
const arr = Array.isArray(urls) ? urls.map((u) => String(u ?? '')) : [];
|
const arr = Array.isArray(urls) ? urls.map((u) => String(u ?? '')) : [];
|
||||||
while (arr.length < minLen) arr.push('');
|
while (arr.length < minLen) arr.push('');
|
||||||
return arr;
|
return arr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function addEnvPhotoSlot(urls: string[]): string[] {
|
||||||
|
return [...urls, ''];
|
||||||
|
}
|
||||||
|
|
||||||
export function normalizeStoreDraftForm(raw: Partial<StoreDraftForm> | null | undefined): StoreDraftForm {
|
export function normalizeStoreDraftForm(raw: Partial<StoreDraftForm> | null | undefined): StoreDraftForm {
|
||||||
const base = defaultStoreForm();
|
const base = defaultStoreForm();
|
||||||
if (!raw) return base;
|
if (!raw) return base;
|
||||||
@@ -101,7 +110,17 @@ export function normalizeStoreDraftForm(raw: Partial<StoreDraftForm> | null | un
|
|||||||
openTime2: String(raw.openTime2 ?? base.openTime2),
|
openTime2: String(raw.openTime2 ?? base.openTime2),
|
||||||
closeTime2: String(raw.closeTime2 ?? base.closeTime2),
|
closeTime2: String(raw.closeTime2 ?? base.closeTime2),
|
||||||
avgPrice: String(raw.avgPrice ?? base.avgPrice),
|
avgPrice: String(raw.avgPrice ?? base.avgPrice),
|
||||||
envPhotoUrls: normalizeStringArray(raw.envPhotoUrls, 3),
|
envPhotoUrls: normalizeStringArray(raw.envPhotoUrls, MIN_ENV_PHOTO_COUNT),
|
||||||
|
packages: Array.isArray(raw.packages)
|
||||||
|
? raw.packages.map((p, i) => ({
|
||||||
|
name: String((p as { name?: string }).name ?? ''),
|
||||||
|
price: String((p as { price?: string | number }).price ?? ''),
|
||||||
|
dishes: String((p as { dishes?: string }).dishes ?? ''),
|
||||||
|
usableTime: (p as { usableTime?: string }).usableTime ?? '',
|
||||||
|
otherNotes: (p as { otherNotes?: string }).otherNotes ?? '',
|
||||||
|
sortOrder: i,
|
||||||
|
}))
|
||||||
|
: [],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -202,13 +221,14 @@ export function validateStoreStep2(
|
|||||||
): string | null {
|
): string | null {
|
||||||
if (!form.coverUrl.trim()) return '请上传门头照';
|
if (!form.coverUrl.trim()) return '请上传门头照';
|
||||||
const envCount = form.envPhotoUrls.filter((u) => u.trim()).length;
|
const envCount = form.envPhotoUrls.filter((u) => u.trim()).length;
|
||||||
if (envCount < 3) return '请上传至少 3 张环境照片';
|
if (envCount < MIN_ENV_PHOTO_COUNT) return `请上传至少 ${MIN_ENV_PHOTO_COUNT} 张环境照片`;
|
||||||
if (!form.contractUrl.trim()) return '请上传签约合同';
|
if (!form.contractUrl.trim()) return '请上传签约合同';
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function patchEnvPhotoAt(urls: string[], index: number, url: string): string[] {
|
export function patchEnvPhotoAt(urls: string[], index: number, url: string): string[] {
|
||||||
const envPhotoUrls = normalizeStringArray(urls, 3);
|
const envPhotoUrls = [...urls];
|
||||||
|
while (envPhotoUrls.length <= index) envPhotoUrls.push('');
|
||||||
envPhotoUrls[index] = url;
|
envPhotoUrls[index] = url;
|
||||||
return envPhotoUrls;
|
return envPhotoUrls;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,54 @@
|
|||||||
|
import type { StorePackageItemDto } from '@dukang/shared-types';
|
||||||
|
import { STORE_PACKAGE_MAX_COUNT } from '@dukang/shared-types';
|
||||||
|
|
||||||
|
export type PackageFormItem = StorePackageItemDto;
|
||||||
|
|
||||||
|
export function emptyPackage(index = 0): PackageFormItem {
|
||||||
|
return {
|
||||||
|
name: '',
|
||||||
|
price: '',
|
||||||
|
dishes: '',
|
||||||
|
usableTime: '',
|
||||||
|
otherNotes: '',
|
||||||
|
imageUrl: '',
|
||||||
|
sortOrder: index,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function normalizePackageFormItems(raw: PackageFormItem[]): PackageFormItem[] {
|
||||||
|
return raw
|
||||||
|
.map((item, index) => ({
|
||||||
|
name: item.name.trim(),
|
||||||
|
price: item.price.trim(),
|
||||||
|
dishes: item.dishes.trim(),
|
||||||
|
usableTime: item.usableTime?.trim() || '',
|
||||||
|
otherNotes: item.otherNotes?.trim() || '',
|
||||||
|
imageUrl: item.imageUrl?.trim() || '',
|
||||||
|
sortOrder: index,
|
||||||
|
}))
|
||||||
|
.filter(
|
||||||
|
(item) =>
|
||||||
|
item.name || item.price || item.dishes || item.usableTime || item.otherNotes || item.imageUrl,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function validatePackageFormItems(items: PackageFormItem[]): string | null {
|
||||||
|
const filled = normalizePackageFormItems(items);
|
||||||
|
if (filled.length > STORE_PACKAGE_MAX_COUNT) {
|
||||||
|
return `套餐最多 ${STORE_PACKAGE_MAX_COUNT} 条`;
|
||||||
|
}
|
||||||
|
for (let i = 0; i < filled.length; i++) {
|
||||||
|
const item = filled[i];
|
||||||
|
if (!item.name) return `第 ${i + 1} 条套餐名称不能为空`;
|
||||||
|
const price = Number(item.price);
|
||||||
|
if (!Number.isFinite(price) || price < 0) return `第 ${i + 1} 条套餐价格须为非负数字`;
|
||||||
|
if (!item.dishes) return `第 ${i + 1} 条套餐菜品不能为空`;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function formatPackagePrice(price: string | number) {
|
||||||
|
const n = typeof price === 'number' ? price : Number(price);
|
||||||
|
if (!Number.isFinite(n)) return String(price);
|
||||||
|
return n % 1 === 0 ? String(n) : n.toFixed(2);
|
||||||
|
}
|
||||||
@@ -1,4 +1,9 @@
|
|||||||
import { apiBase, request } from './api';
|
import { apiBase, request } from './api';
|
||||||
|
import {
|
||||||
|
compressImageFileIfNeeded,
|
||||||
|
DEFAULT_OSS_MAX_UPLOAD_BYTES,
|
||||||
|
formatOssMaxSizeMb,
|
||||||
|
} from '@dukang/shared-ui/compressImage';
|
||||||
|
|
||||||
const UPLOAD_TIMEOUT_MS = 120_000;
|
const UPLOAD_TIMEOUT_MS = 120_000;
|
||||||
|
|
||||||
@@ -11,13 +16,23 @@ 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;
|
||||||
|
}
|
||||||
|
|
||||||
async function uploadFileToOssInner(
|
async function uploadFileToOssInner(
|
||||||
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);
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
import { useEffect, useRef } from 'react';
|
||||||
|
import { trackPartnerPageView } from './analytics';
|
||||||
|
|
||||||
|
export function usePartnerPageView(eventName: string, params?: Record<string, unknown>) {
|
||||||
|
const fired = useRef(false);
|
||||||
|
useEffect(() => {
|
||||||
|
if (fired.current) return;
|
||||||
|
fired.current = true;
|
||||||
|
trackPartnerPageView(eventName, params);
|
||||||
|
}, [eventName, params]);
|
||||||
|
}
|
||||||
@@ -48,6 +48,19 @@ export async function canPartnerUseWechatLogin(options: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 短信登录/发码前:校验手机号对应合伙人存在且未暂停 */
|
||||||
|
export async function checkPartnerPhoneForLogin(phone: string): Promise<PartnerPhoneCheckResponse> {
|
||||||
|
const normalized = phone.trim();
|
||||||
|
if (!/^1\d{10}$/.test(normalized)) {
|
||||||
|
throw new Error('请输入正确的手机号');
|
||||||
|
}
|
||||||
|
return request<PartnerPhoneCheckResponse>('PARTNER_H5', '/partner/auth/phone/check', {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify({ phone: normalized }),
|
||||||
|
silent: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
export async function fetchClientConfig(): Promise<ClientRuntimeConfig> {
|
export async function fetchClientConfig(): Promise<ClientRuntimeConfig> {
|
||||||
return request<ClientRuntimeConfig>('PARTNER_H5', '/common/client-config');
|
return request<ClientRuntimeConfig>('PARTNER_H5', '/common/client-config');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,11 +5,16 @@ import { getRouterBasename } from '@dukang/weixin-sdk';
|
|||||||
import App from './App';
|
import App from './App';
|
||||||
import { PartnerSessionProvider } from './contexts/PartnerSessionContext';
|
import { PartnerSessionProvider } from './contexts/PartnerSessionContext';
|
||||||
import { PartnerToastProvider } from './contexts/PartnerToastContext';
|
import { PartnerToastProvider } from './contexts/PartnerToastContext';
|
||||||
import { installClientErrorReporting } from './lib/client-error';
|
import { installClientErrorReporting } from '@dukang/client-logging';
|
||||||
|
import { apiBase } from './lib/api';
|
||||||
import './styles.css';
|
import './styles.css';
|
||||||
import './styles/legal.css';
|
import './styles/legal.css';
|
||||||
|
|
||||||
installClientErrorReporting();
|
installClientErrorReporting({
|
||||||
|
apiBase,
|
||||||
|
clientApp: 'PARTNER_H5',
|
||||||
|
getToken: () => localStorage.getItem('partnerAccessToken'),
|
||||||
|
});
|
||||||
|
|
||||||
ReactDOM.createRoot(document.getElementById('root')!).render(
|
ReactDOM.createRoot(document.getElementById('root')!).render(
|
||||||
<React.StrictMode>
|
<React.StrictMode>
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import PullToRefresh from '@dukang/shared-ui/PullToRefresh';
|
|||||||
import type { PartnerBillDto } from '@dukang/shared-types';
|
import type { PartnerBillDto } from '@dukang/shared-types';
|
||||||
import { isLoggedIn, request } from '../lib/api';
|
import { isLoggedIn, request } from '../lib/api';
|
||||||
import { toastError, toastSuccess } from '../lib/toast';
|
import { toastError, toastSuccess } from '../lib/toast';
|
||||||
|
import { usePartnerPageView } from '../lib/usePageView';
|
||||||
|
|
||||||
function fmtMoney(n: number) {
|
function fmtMoney(n: number) {
|
||||||
return n.toLocaleString('zh-CN', { minimumFractionDigits: 2, maximumFractionDigits: 2 });
|
return n.toLocaleString('zh-CN', { minimumFractionDigits: 2, maximumFractionDigits: 2 });
|
||||||
@@ -25,6 +26,7 @@ function canConfirm(status: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default function BillsPage() {
|
export default function BillsPage() {
|
||||||
|
usePartnerPageView('partner_bills_view');
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const [searchParams] = useSearchParams();
|
const [searchParams] = useSearchParams();
|
||||||
const [bills, setBills] = useState<PartnerBillDto[]>([]);
|
const [bills, setBills] = useState<PartnerBillDto[]>([]);
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { useCallback, useEffect, useMemo, useState } from 'react';
|
|||||||
import { Link, useNavigate } from 'react-router-dom';
|
import { Link, useNavigate } from 'react-router-dom';
|
||||||
import type { PartnerLeaderboardEntry } from '@dukang/shared-types';
|
import type { PartnerLeaderboardEntry } from '@dukang/shared-types';
|
||||||
import PullToRefresh from '@dukang/shared-ui/PullToRefresh';
|
import PullToRefresh from '@dukang/shared-ui/PullToRefresh';
|
||||||
|
import { usePartnerPageView } from '../lib/usePageView';
|
||||||
import { isLoggedIn, request } from '../lib/api';
|
import { isLoggedIn, request } from '../lib/api';
|
||||||
import { fetchPartnerLeaderboard } from '../lib/leaderboard';
|
import { fetchPartnerLeaderboard } from '../lib/leaderboard';
|
||||||
import {
|
import {
|
||||||
@@ -137,6 +138,7 @@ function LeaderboardPreview({ entries }: { entries: PartnerLeaderboardEntry[] })
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default function HomePage() {
|
export default function HomePage() {
|
||||||
|
usePartnerPageView('partner_home_view');
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const { account } = usePartnerSession();
|
const { account } = usePartnerSession();
|
||||||
const navKind = getPartnerNavKind(account);
|
const navKind = getPartnerNavKind(account);
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import PullToRefresh from '@dukang/shared-ui/PullToRefresh';
|
|||||||
import { fetchPartnerLeaderboard } from '../lib/leaderboard';
|
import { fetchPartnerLeaderboard } from '../lib/leaderboard';
|
||||||
import { usePartnerSession } from '../contexts/PartnerSessionContext';
|
import { usePartnerSession } from '../contexts/PartnerSessionContext';
|
||||||
import { isPrimaryAccount } from '../lib/partnerAccess';
|
import { isPrimaryAccount } from '../lib/partnerAccess';
|
||||||
|
import { usePartnerPageView } from '../lib/usePageView';
|
||||||
|
|
||||||
const PERIOD_TABS: { key: PartnerLeaderboardPeriod; label: string }[] = [
|
const PERIOD_TABS: { key: PartnerLeaderboardPeriod; label: string }[] = [
|
||||||
{ key: 'month', label: '本月' },
|
{ key: 'month', label: '本月' },
|
||||||
@@ -26,6 +27,7 @@ function periodSubLabel(period: PartnerLeaderboardPeriod): string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default function LeaderboardPage() {
|
export default function LeaderboardPage() {
|
||||||
|
usePartnerPageView('partner_leaderboard_view');
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const { account } = usePartnerSession();
|
const { account } = usePartnerSession();
|
||||||
const showStaffFab = isPrimaryAccount(account);
|
const showStaffFab = isPrimaryAccount(account);
|
||||||
|
|||||||
@@ -12,8 +12,10 @@ import {
|
|||||||
} from '../lib/api';
|
} from '../lib/api';
|
||||||
import { usePartnerSession } from '../contexts/PartnerSessionContext';
|
import { usePartnerSession } from '../contexts/PartnerSessionContext';
|
||||||
import { partnerHomePath } from '../lib/partnerAccess';
|
import { partnerHomePath } from '../lib/partnerAccess';
|
||||||
|
import type { PartnerPhoneCheckResponse } from '@dukang/shared-types';
|
||||||
import {
|
import {
|
||||||
bindPartnerWechatAfterSmsLogin,
|
bindPartnerWechatAfterSmsLogin,
|
||||||
|
checkPartnerPhoneForLogin,
|
||||||
fetchClientConfig,
|
fetchClientConfig,
|
||||||
loginPartnerWithWechat,
|
loginPartnerWithWechat,
|
||||||
} from '../lib/wechat-auth';
|
} from '../lib/wechat-auth';
|
||||||
@@ -69,14 +71,17 @@ function formatPartnerError(e: unknown): string {
|
|||||||
if (text.includes('合伙人账号不存在') || text.includes('未找到合伙人账号')) {
|
if (text.includes('合伙人账号不存在') || text.includes('未找到合伙人账号')) {
|
||||||
return '未找到合伙人账号';
|
return '未找到合伙人账号';
|
||||||
}
|
}
|
||||||
if (text.includes('合伙人账号已停用')) {
|
if (text.includes('合伙人账号已停用') || text.includes('账号已停用')) {
|
||||||
return '合伙人账号已停用';
|
return '合伙人账号已暂停,无法登录';
|
||||||
}
|
}
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
function formatWechatError(e: unknown): string {
|
function formatWechatError(e: unknown): string {
|
||||||
const text = e instanceof Error ? e.message : '微信登录失败';
|
const text = e instanceof Error ? e.message : '微信登录失败';
|
||||||
|
if (text.includes('合伙人账号已停用') || text.includes('账号已停用')) {
|
||||||
|
return '合伙人账号已暂停,无法登录';
|
||||||
|
}
|
||||||
if (text.includes('首次登录') || text.includes('手机验证码')) {
|
if (text.includes('首次登录') || text.includes('手机验证码')) {
|
||||||
return '该微信尚未绑定合伙人账号,请先使用手机验证码登录,登录后将自动关联微信';
|
return '该微信尚未绑定合伙人账号,请先使用手机验证码登录,登录后将自动关联微信';
|
||||||
}
|
}
|
||||||
@@ -138,11 +143,21 @@ export default function LoginPage() {
|
|||||||
|
|
||||||
async function sendCode() {
|
async function sendCode() {
|
||||||
if (!ensureAgreed()) return;
|
if (!ensureAgreed()) return;
|
||||||
|
const trimmedPhone = phone.trim();
|
||||||
|
if (!trimmedPhone) {
|
||||||
|
setMsg('请输入手机号');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!/^1\d{10}$/.test(trimmedPhone)) {
|
||||||
|
setMsg('请输入正确的手机号');
|
||||||
|
return;
|
||||||
|
}
|
||||||
setMsg('');
|
setMsg('');
|
||||||
try {
|
try {
|
||||||
|
await checkPartnerPhoneForLogin(trimmedPhone);
|
||||||
await request('PARTNER_H5', '/partner/auth/sms/send', {
|
await request('PARTNER_H5', '/partner/auth/sms/send', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: JSON.stringify({ phone, scene: 'PARTNER_LOGIN' }),
|
body: JSON.stringify({ phone: trimmedPhone, scene: 'PARTNER_LOGIN' }),
|
||||||
silent: true,
|
silent: true,
|
||||||
});
|
});
|
||||||
setMsg('验证码已发送');
|
setMsg('验证码已发送');
|
||||||
@@ -168,12 +183,27 @@ export default function LoginPage() {
|
|||||||
|
|
||||||
async function login() {
|
async function login() {
|
||||||
if (!ensureAgreed()) return;
|
if (!ensureAgreed()) return;
|
||||||
|
const trimmedPhone = phone.trim();
|
||||||
|
const trimmedCode = code.trim();
|
||||||
|
if (!trimmedPhone) {
|
||||||
|
setMsg('请输入手机号');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!/^1\d{10}$/.test(trimmedPhone)) {
|
||||||
|
setMsg('请输入正确的手机号');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!trimmedCode) {
|
||||||
|
setMsg('请输入验证码');
|
||||||
|
return;
|
||||||
|
}
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
setMsg('');
|
setMsg('');
|
||||||
try {
|
try {
|
||||||
|
await checkPartnerPhoneForLogin(trimmedPhone);
|
||||||
const data = await request<PartnerSessionPayload>('PARTNER_H5', '/partner/auth/login/sms', {
|
const data = await request<PartnerSessionPayload>('PARTNER_H5', '/partner/auth/login/sms', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: JSON.stringify({ phone, code }),
|
body: JSON.stringify({ phone: trimmedPhone, code: trimmedCode }),
|
||||||
silent: true,
|
silent: true,
|
||||||
});
|
});
|
||||||
saveRememberedSession(data);
|
saveRememberedSession(data);
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { useNavigate, useParams } from 'react-router-dom';
|
|||||||
import PageHeader from '@dukang/shared-ui/PageHeader';
|
import PageHeader from '@dukang/shared-ui/PageHeader';
|
||||||
import { request } from '../lib/api';
|
import { request } from '../lib/api';
|
||||||
import { toastError, toastSuccess } from '../lib/toast';
|
import { toastError, toastSuccess } from '../lib/toast';
|
||||||
|
import { usePartnerPageView } from '../lib/usePageView';
|
||||||
|
|
||||||
const TIMELINE = [
|
const TIMELINE = [
|
||||||
{ key: 'confirm', label: '待确认' },
|
{ key: 'confirm', label: '待确认' },
|
||||||
@@ -36,6 +37,7 @@ function canShip(status: string) {
|
|||||||
|
|
||||||
export default function OrderDetailPage() {
|
export default function OrderDetailPage() {
|
||||||
const { id } = useParams();
|
const { id } = useParams();
|
||||||
|
usePartnerPageView('partner_order_detail_view', id ? { orderId: id } : undefined);
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const [order, setOrder] = useState<Record<string, unknown> | null>(null);
|
const [order, setOrder] = useState<Record<string, unknown> | null>(null);
|
||||||
const [shipping, setShipping] = useState(false);
|
const [shipping, setShipping] = useState(false);
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import PullToRefresh from '@dukang/shared-ui/PullToRefresh';
|
|||||||
import { isLoggedIn, request } from '../lib/api';
|
import { isLoggedIn, request } from '../lib/api';
|
||||||
import { usePartnerSession } from '../contexts/PartnerSessionContext';
|
import { usePartnerSession } from '../contexts/PartnerSessionContext';
|
||||||
import { hasWarehouseAccess } from '../lib/partnerAccess';
|
import { hasWarehouseAccess } from '../lib/partnerAccess';
|
||||||
|
import { usePartnerPageView } from '../lib/usePageView';
|
||||||
|
|
||||||
type DateFilter = 'today' | '7d' | '30d';
|
type DateFilter = 'today' | '7d' | '30d';
|
||||||
type StatusFilter = 'ALL' | 'PENDING_SHIP' | 'SHIPPING' | 'COMPLETED' | 'ABNORMAL';
|
type StatusFilter = 'ALL' | 'PENDING_SHIP' | 'SHIPPING' | 'COMPLETED' | 'ABNORMAL';
|
||||||
@@ -44,6 +45,7 @@ type OrdersResponse = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export default function OrderListPage({ tabRoot = false }: OrderListPageProps) {
|
export default function OrderListPage({ tabRoot = false }: OrderListPageProps) {
|
||||||
|
usePartnerPageView('partner_order_list_view');
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const { account } = usePartnerSession();
|
const { account } = usePartnerSession();
|
||||||
const warehouseOk = hasWarehouseAccess(account);
|
const warehouseOk = hasWarehouseAccess(account);
|
||||||
|
|||||||
@@ -59,6 +59,7 @@ export default function ProxyOrderDetailPage() {
|
|||||||
const [payMethod, setPayMethod] = useState<ProxyPayMethod>('NATIVE');
|
const [payMethod, setPayMethod] = useState<ProxyPayMethod>('NATIVE');
|
||||||
const [codeUrl, setCodeUrl] = useState<string | null>(null);
|
const [codeUrl, setCodeUrl] = useState<string | null>(null);
|
||||||
const [qrDataUrl, setQrDataUrl] = useState<string | null>(null);
|
const [qrDataUrl, setQrDataUrl] = useState<string | null>(null);
|
||||||
|
const [cancelling, setCancelling] = useState(false);
|
||||||
const pollRef = useRef<number | null>(null);
|
const pollRef = useRef<number | null>(null);
|
||||||
|
|
||||||
function stopPoll() {
|
function stopPoll() {
|
||||||
@@ -77,7 +78,12 @@ export default function ProxyOrderDetailPage() {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!id) return;
|
if (!id) return;
|
||||||
void request<PartnerProxyOrderListItem>('PARTNER_H5', `/partner/proxy-orders/${id}`)
|
void request<PartnerProxyOrderListItem>('PARTNER_H5', `/partner/proxy-orders/${id}`)
|
||||||
.then(setOrder)
|
.then((data) => {
|
||||||
|
setOrder(data);
|
||||||
|
if (data.proxyPayMethod) {
|
||||||
|
setPayMethod(data.proxyPayMethod);
|
||||||
|
}
|
||||||
|
})
|
||||||
.catch((e) => setError(e instanceof Error ? e.message : '加载失败'));
|
.catch((e) => setError(e instanceof Error ? e.message : '加载失败'));
|
||||||
}, [id]);
|
}, [id]);
|
||||||
|
|
||||||
@@ -129,6 +135,15 @@ export default function ProxyOrderDetailPage() {
|
|||||||
|
|
||||||
async function startPay(method: ProxyPayMethod) {
|
async function startPay(method: ProxyPayMethod) {
|
||||||
if (!id) return;
|
if (!id) return;
|
||||||
|
const locked = order?.proxyPayMethod;
|
||||||
|
if (locked && locked !== method) {
|
||||||
|
setPayMsg(
|
||||||
|
locked === 'JSAPI'
|
||||||
|
? '该订单已发起微信代付,请先取消支付后重新下单'
|
||||||
|
: '该订单已生成收款码,请先取消支付后重新下单',
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
setPaying(true);
|
setPaying(true);
|
||||||
setPayMsg('');
|
setPayMsg('');
|
||||||
setPayMethod(method);
|
setPayMethod(method);
|
||||||
@@ -166,12 +181,14 @@ export default function ProxyOrderDetailPage() {
|
|||||||
|
|
||||||
if (pay.mode === 'native' && pay.codeUrl) {
|
if (pay.mode === 'native' && pay.codeUrl) {
|
||||||
setCodeUrl(pay.codeUrl);
|
setCodeUrl(pay.codeUrl);
|
||||||
|
setOrder((prev) => (prev ? { ...prev, proxyPayMethod: method } : prev));
|
||||||
startPoll(id);
|
startPoll(id);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pay.mode === 'jsapi' && pay.prepay) {
|
if (pay.mode === 'jsapi' && pay.prepay) {
|
||||||
setCodeUrl(null);
|
setCodeUrl(null);
|
||||||
|
setOrder((prev) => (prev ? { ...prev, proxyPayMethod: method } : prev));
|
||||||
await invokeWechatPay(pay.prepay, {
|
await invokeWechatPay(pay.prepay, {
|
||||||
apiBase: '/api/v1',
|
apiBase: '/api/v1',
|
||||||
clientApp: 'PARTNER_H5',
|
clientApp: 'PARTNER_H5',
|
||||||
@@ -191,14 +208,27 @@ export default function ProxyOrderDetailPage() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const autoPayStartedRef = useRef(false);
|
async function cancelPay() {
|
||||||
useEffect(() => {
|
if (!id) return;
|
||||||
if (!id || !unpaid || autoPayStartedRef.current) return;
|
setCancelling(true);
|
||||||
autoPayStartedRef.current = true;
|
setPayMsg('');
|
||||||
void startPay('NATIVE');
|
stopPoll();
|
||||||
// 仅首次进入未支付详情时自动拉收款码
|
try {
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
await request('PARTNER_H5', `/partner/proxy-orders/${id}/cancel-pay`, {
|
||||||
}, [id, unpaid]);
|
method: 'POST',
|
||||||
|
body: '{}',
|
||||||
|
});
|
||||||
|
toastSuccess('已取消支付,可重新下单并选择其他支付方式');
|
||||||
|
navigate('/center/proxy-orders');
|
||||||
|
} catch (e) {
|
||||||
|
setPayMsg(e instanceof Error ? e.message : '取消失败');
|
||||||
|
toastError(e instanceof Error ? e.message : '取消失败');
|
||||||
|
} finally {
|
||||||
|
setCancelling(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const lockedPayMethod = order?.proxyPayMethod ?? null;
|
||||||
|
|
||||||
const img = order?.imageResource?.url || '';
|
const img = order?.imageResource?.url || '';
|
||||||
const isOnSite = String(order?.deliveryType || '').toUpperCase() === 'ON_SITE_PICKUP';
|
const isOnSite = String(order?.deliveryType || '').toUpperCase() === 'ON_SITE_PICKUP';
|
||||||
@@ -285,6 +315,7 @@ export default function ProxyOrderDetailPage() {
|
|||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
className={`partner-proxy-mode-tab${payMethod === 'NATIVE' ? ' is-active' : ''}`}
|
className={`partner-proxy-mode-tab${payMethod === 'NATIVE' ? ' is-active' : ''}`}
|
||||||
|
disabled={!!lockedPayMethod && lockedPayMethod !== 'NATIVE'}
|
||||||
onClick={() => void startPay('NATIVE')}
|
onClick={() => void startPay('NATIVE')}
|
||||||
>
|
>
|
||||||
收款码
|
收款码
|
||||||
@@ -292,11 +323,21 @@ export default function ProxyOrderDetailPage() {
|
|||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
className={`partner-proxy-mode-tab${payMethod === 'JSAPI' ? ' is-active' : ''}`}
|
className={`partner-proxy-mode-tab${payMethod === 'JSAPI' ? ' is-active' : ''}`}
|
||||||
|
disabled={!!lockedPayMethod && lockedPayMethod !== 'JSAPI'}
|
||||||
onClick={() => void startPay('JSAPI')}
|
onClick={() => void startPay('JSAPI')}
|
||||||
>
|
>
|
||||||
微信代付
|
微信代付
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
{lockedPayMethod ? (
|
||||||
|
<p className="label-md text-muted" style={{ marginTop: 8 }}>
|
||||||
|
已选择{lockedPayMethod === 'NATIVE' ? '收款码' : '微信代付'},切换方式请先取消支付
|
||||||
|
</p>
|
||||||
|
) : (
|
||||||
|
<p className="label-md text-muted" style={{ marginTop: 8 }}>
|
||||||
|
请选择支付方式并点击下方按钮发起支付
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
|
||||||
{payMethod === 'NATIVE' ? (
|
{payMethod === 'NATIVE' ? (
|
||||||
<div style={{ textAlign: 'center', marginTop: 16 }}>
|
<div style={{ textAlign: 'center', marginTop: 16 }}>
|
||||||
@@ -338,6 +379,16 @@ export default function ProxyOrderDetailPage() {
|
|||||||
{payMsg}
|
{payMsg}
|
||||||
</p>
|
</p>
|
||||||
) : null}
|
) : null}
|
||||||
|
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="btn btn-block"
|
||||||
|
style={{ marginTop: 16 }}
|
||||||
|
disabled={cancelling || paying}
|
||||||
|
onClick={() => void cancelPay()}
|
||||||
|
>
|
||||||
|
{cancelling ? '取消中…' : '取消支付'}
|
||||||
|
</button>
|
||||||
</section>
|
</section>
|
||||||
) : null}
|
) : null}
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import type {
|
|||||||
ProxyOrderPayResponse,
|
ProxyOrderPayResponse,
|
||||||
ProxyPayMethod,
|
ProxyPayMethod,
|
||||||
} from '@dukang/shared-types';
|
} from '@dukang/shared-types';
|
||||||
|
import { usePartnerPageView } from '../lib/usePageView';
|
||||||
|
|
||||||
function fmtMoney(n: number) {
|
function fmtMoney(n: number) {
|
||||||
return n.toLocaleString('zh-CN', { minimumFractionDigits: 2, maximumFractionDigits: 2 });
|
return n.toLocaleString('zh-CN', { minimumFractionDigits: 2, maximumFractionDigits: 2 });
|
||||||
@@ -46,6 +47,7 @@ function initialDraft(): ProxyOrderDraft {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default function ProxyOrderPage() {
|
export default function ProxyOrderPage() {
|
||||||
|
usePartnerPageView('partner_proxy_order_view');
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const [searchParams] = useSearchParams();
|
const [searchParams] = useSearchParams();
|
||||||
const draft0 = useMemo(() => initialDraft(), []);
|
const draft0 = useMemo(() => initialDraft(), []);
|
||||||
@@ -70,6 +72,8 @@ export default function ProxyOrderPage() {
|
|||||||
const [codeUrl, setCodeUrl] = useState<string | null>(null);
|
const [codeUrl, setCodeUrl] = useState<string | null>(null);
|
||||||
const [qrDataUrl, setQrDataUrl] = useState<string | null>(null);
|
const [qrDataUrl, setQrDataUrl] = useState<string | null>(null);
|
||||||
const [paying, setPaying] = useState(false);
|
const [paying, setPaying] = useState(false);
|
||||||
|
const [cancelling, setCancelling] = useState(false);
|
||||||
|
const [lockedPayMethod, setLockedPayMethod] = useState<ProxyPayMethod | null>(null);
|
||||||
const pollRef = useRef<number | null>(null);
|
const pollRef = useRef<number | null>(null);
|
||||||
|
|
||||||
const region = useMemo(() => parseRegionCodes(regionCodes), [regionCodes]);
|
const region = useMemo(() => parseRegionCodes(regionCodes), [regionCodes]);
|
||||||
@@ -234,8 +238,17 @@ export default function ProxyOrderPage() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function startPay(orderId: string, method: ProxyPayMethod) {
|
async function startPay(orderId: string, method: ProxyPayMethod) {
|
||||||
|
if (lockedPayMethod && lockedPayMethod !== method) {
|
||||||
|
setMsg(
|
||||||
|
lockedPayMethod === 'JSAPI'
|
||||||
|
? '该订单已发起微信代付,请先取消支付后重新下单'
|
||||||
|
: '该订单已生成收款码,请先取消支付后重新下单',
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
setPaying(true);
|
setPaying(true);
|
||||||
setMsg('');
|
setMsg('');
|
||||||
|
setPayMethod(method);
|
||||||
try {
|
try {
|
||||||
if (method === 'JSAPI') {
|
if (method === 'JSAPI') {
|
||||||
if (!isWechatEnv()) {
|
if (!isWechatEnv()) {
|
||||||
@@ -266,11 +279,14 @@ export default function ProxyOrderPage() {
|
|||||||
|
|
||||||
if (pay.mode === 'native' && pay.codeUrl) {
|
if (pay.mode === 'native' && pay.codeUrl) {
|
||||||
setCodeUrl(pay.codeUrl);
|
setCodeUrl(pay.codeUrl);
|
||||||
|
setLockedPayMethod(method);
|
||||||
startPoll(orderId);
|
startPoll(orderId);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pay.mode === 'jsapi' && pay.prepay) {
|
if (pay.mode === 'jsapi' && pay.prepay) {
|
||||||
|
setCodeUrl(null);
|
||||||
|
setLockedPayMethod(method);
|
||||||
await invokeWechatPay(pay.prepay, {
|
await invokeWechatPay(pay.prepay, {
|
||||||
apiBase: '/api/v1',
|
apiBase: '/api/v1',
|
||||||
clientApp: 'PARTNER_H5',
|
clientApp: 'PARTNER_H5',
|
||||||
@@ -289,6 +305,40 @@ export default function ProxyOrderPage() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function cancelPay(orderId: string) {
|
||||||
|
setCancelling(true);
|
||||||
|
setMsg('');
|
||||||
|
stopPoll();
|
||||||
|
try {
|
||||||
|
await request('PARTNER_H5', `/partner/proxy-orders/${orderId}/cancel-pay`, {
|
||||||
|
method: 'POST',
|
||||||
|
body: '{}',
|
||||||
|
});
|
||||||
|
toastSuccess('已取消支付,可重新下单并选择其他支付方式');
|
||||||
|
setStep('form');
|
||||||
|
setCreated(null);
|
||||||
|
setCodeUrl(null);
|
||||||
|
setLockedPayMethod(null);
|
||||||
|
} catch (e) {
|
||||||
|
setMsg(e instanceof Error ? e.message : '取消失败');
|
||||||
|
} finally {
|
||||||
|
setCancelling(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function switchPayMethod(method: ProxyPayMethod) {
|
||||||
|
if (lockedPayMethod && lockedPayMethod !== method) {
|
||||||
|
setMsg(
|
||||||
|
lockedPayMethod === 'JSAPI'
|
||||||
|
? '该订单已发起微信代付,请先取消支付后重新下单'
|
||||||
|
: '该订单已生成收款码,请先取消支付后重新下单',
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setPayMethod(method);
|
||||||
|
setMsg('');
|
||||||
|
}
|
||||||
|
|
||||||
async function submit() {
|
async function submit() {
|
||||||
setMsg('');
|
setMsg('');
|
||||||
const err = validateForm();
|
const err = validateForm();
|
||||||
@@ -322,6 +372,7 @@ export default function ProxyOrderPage() {
|
|||||||
setCreated(order);
|
setCreated(order);
|
||||||
setStep('pay');
|
setStep('pay');
|
||||||
setCodeUrl(null);
|
setCodeUrl(null);
|
||||||
|
setLockedPayMethod(null);
|
||||||
await startPay(order.id, payMethod);
|
await startPay(order.id, payMethod);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
setMsg(e instanceof Error ? e.message : '下单失败');
|
setMsg(e instanceof Error ? e.message : '下单失败');
|
||||||
@@ -359,24 +410,25 @@ export default function ProxyOrderPage() {
|
|||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
className={`partner-proxy-mode-tab${payMethod === 'NATIVE' ? ' is-active' : ''}`}
|
className={`partner-proxy-mode-tab${payMethod === 'NATIVE' ? ' is-active' : ''}`}
|
||||||
onClick={() => {
|
disabled={!!lockedPayMethod && lockedPayMethod !== 'NATIVE'}
|
||||||
setPayMethod('NATIVE');
|
onClick={() => switchPayMethod('NATIVE')}
|
||||||
void startPay(created.id, 'NATIVE');
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
收款码
|
收款码
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
className={`partner-proxy-mode-tab${payMethod === 'JSAPI' ? ' is-active' : ''}`}
|
className={`partner-proxy-mode-tab${payMethod === 'JSAPI' ? ' is-active' : ''}`}
|
||||||
onClick={() => {
|
disabled={!!lockedPayMethod && lockedPayMethod !== 'JSAPI'}
|
||||||
setPayMethod('JSAPI');
|
onClick={() => switchPayMethod('JSAPI')}
|
||||||
void startPay(created.id, 'JSAPI');
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
微信代付
|
微信代付
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
{lockedPayMethod ? (
|
||||||
|
<p className="label-md text-muted" style={{ marginTop: 8 }}>
|
||||||
|
已选择{lockedPayMethod === 'NATIVE' ? '收款码' : '微信代付'},切换方式请先取消支付
|
||||||
|
</p>
|
||||||
|
) : null}
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
{payMethod === 'NATIVE' ? (
|
{payMethod === 'NATIVE' ? (
|
||||||
@@ -419,6 +471,16 @@ export default function ProxyOrderPage() {
|
|||||||
{msg}
|
{msg}
|
||||||
</p>
|
</p>
|
||||||
) : null}
|
) : null}
|
||||||
|
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="btn btn-block"
|
||||||
|
style={{ marginTop: 16 }}
|
||||||
|
disabled={cancelling || paying}
|
||||||
|
onClick={() => void cancelPay(created.id)}
|
||||||
|
>
|
||||||
|
{cancelling ? '取消中…' : '取消支付'}
|
||||||
|
</button>
|
||||||
</>
|
</>
|
||||||
) : loadingOptions ? (
|
) : loadingOptions ? (
|
||||||
<p className="label-md text-muted">加载商品…</p>
|
<p className="label-md text-muted">加载商品…</p>
|
||||||
|
|||||||
@@ -9,8 +9,10 @@ import {
|
|||||||
type PartnerStaffItem,
|
type PartnerStaffItem,
|
||||||
} from '@dukang/shared-types';
|
} from '@dukang/shared-types';
|
||||||
import { deletePartnerStaff, listPartnerStaff, updatePartnerStaff } from '../lib/staff';
|
import { deletePartnerStaff, listPartnerStaff, updatePartnerStaff } from '../lib/staff';
|
||||||
|
import { usePartnerPageView } from '../lib/usePageView';
|
||||||
|
|
||||||
export default function StaffListPage() {
|
export default function StaffListPage() {
|
||||||
|
usePartnerPageView('partner_staff_list_view');
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const [staff, setStaff] = useState<PartnerStaffItem[]>([]);
|
const [staff, setStaff] = useState<PartnerStaffItem[]>([]);
|
||||||
const [q, setQ] = useState('');
|
const [q, setQ] = useState('');
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import { isWechatEnv, weixinSdk } from '../lib/weixin';
|
|||||||
import { usePartnerSession } from '../contexts/PartnerSessionContext';
|
import { usePartnerSession } from '../contexts/PartnerSessionContext';
|
||||||
|
|
||||||
import TencentLocPickerOverlay from '../components/TencentLocPickerOverlay';
|
import TencentLocPickerOverlay from '../components/TencentLocPickerOverlay';
|
||||||
|
import { usePartnerPageView } from '../lib/usePageView';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
|
||||||
@@ -40,12 +41,13 @@ import {
|
|||||||
validateStoreStep3,
|
validateStoreStep3,
|
||||||
|
|
||||||
patchEnvPhotoAt,
|
patchEnvPhotoAt,
|
||||||
|
addEnvPhotoSlot,
|
||||||
|
MIN_ENV_PHOTO_COUNT,
|
||||||
} from '../lib/storeDraft';
|
} from '../lib/storeDraft';
|
||||||
|
import StorePackagesForm from '../components/StorePackagesForm';
|
||||||
|
import { normalizePackageFormItems, validatePackageFormItems } from '../lib/storePackages';
|
||||||
|
|
||||||
|
const STEPS = ['基本信息', '照片上传', '结算资质', '门店套餐'] as const;
|
||||||
|
|
||||||
const STEPS = ['基本信息', '照片上传', '结算资质'] as const;
|
|
||||||
|
|
||||||
type StoreCategoryNode = {
|
type StoreCategoryNode = {
|
||||||
id: string;
|
id: string;
|
||||||
@@ -77,6 +79,8 @@ function isPhoneValidationMessage(message: string) {
|
|||||||
|
|
||||||
export default function StoreCreatePage() {
|
export default function StoreCreatePage() {
|
||||||
|
|
||||||
|
usePartnerPageView('partner_store_create_view');
|
||||||
|
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
const { account } = usePartnerSession();
|
const { account } = usePartnerSession();
|
||||||
@@ -102,6 +106,7 @@ export default function StoreCreatePage() {
|
|||||||
const [categoryTree, setCategoryTree] = useState<StoreCategoryNode[]>([]);
|
const [categoryTree, setCategoryTree] = useState<StoreCategoryNode[]>([]);
|
||||||
|
|
||||||
const [mapPickerOpen, setMapPickerOpen] = useState(false);
|
const [mapPickerOpen, setMapPickerOpen] = useState(false);
|
||||||
|
const [stepErrorModal, setStepErrorModal] = useState<string | null>(null);
|
||||||
|
|
||||||
const draftSaveDisabledRef = useRef(false);
|
const draftSaveDisabledRef = useRef(false);
|
||||||
|
|
||||||
@@ -109,9 +114,14 @@ export default function StoreCreatePage() {
|
|||||||
setSubmitError(message);
|
setSubmitError(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function reportStepError(message: string) {
|
||||||
|
setSubmitError(message);
|
||||||
|
setStepErrorModal(message);
|
||||||
|
}
|
||||||
|
|
||||||
const stepFromUrl = Number(params.get('step') || 0);
|
const stepFromUrl = Number(params.get('step') || 0);
|
||||||
|
|
||||||
const step = stepFromUrl >= 1 && stepFromUrl <= 3 ? stepFromUrl : (saved?.step ?? 1);
|
const step = stepFromUrl >= 1 && stepFromUrl <= 4 ? stepFromUrl : (saved?.step ?? 1);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -301,7 +311,7 @@ export default function StoreCreatePage() {
|
|||||||
const msg = validateStoreStep1(form);
|
const msg = validateStoreStep1(form);
|
||||||
|
|
||||||
if (msg) {
|
if (msg) {
|
||||||
reportFormError(msg);
|
reportStepError(msg);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -312,19 +322,32 @@ export default function StoreCreatePage() {
|
|||||||
const msg = validateStoreStep2(form);
|
const msg = validateStoreStep2(form);
|
||||||
|
|
||||||
if (msg) {
|
if (msg) {
|
||||||
reportFormError(msg);
|
reportStepError(msg);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (step === 3) {
|
||||||
|
const msg = validateStoreStep3(form);
|
||||||
|
if (msg) {
|
||||||
|
if (isPhoneValidationMessage(msg)) {
|
||||||
|
setFieldErrors({ phone: msg });
|
||||||
|
reportStepError(msg);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
reportStepError(msg);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
goStep(step + 1);
|
goStep(step + 1);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
async function submit() {
|
async function submit(skipPackages = false) {
|
||||||
|
|
||||||
const msg = validateStoreStep3(form);
|
const msg = validateStoreStep3(form);
|
||||||
|
|
||||||
@@ -337,6 +360,15 @@ export default function StoreCreatePage() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const packagesToSubmit = skipPackages ? [] : form.packages || [];
|
||||||
|
if (!skipPackages) {
|
||||||
|
const pkgMsg = validatePackageFormItems(packagesToSubmit);
|
||||||
|
if (pkgMsg) {
|
||||||
|
reportFormError(pkgMsg);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const step1Msg = validateStoreStep1(form);
|
const step1Msg = validateStoreStep1(form);
|
||||||
|
|
||||||
if (step1Msg) {
|
if (step1Msg) {
|
||||||
@@ -472,6 +504,15 @@ export default function StoreCreatePage() {
|
|||||||
|
|
||||||
draftSaveDisabledRef.current = true;
|
draftSaveDisabledRef.current = true;
|
||||||
clearAllStoreDrafts(accountId);
|
clearAllStoreDrafts(accountId);
|
||||||
|
const packages = normalizePackageFormItems(packagesToSubmit);
|
||||||
|
if (packages.length) {
|
||||||
|
await request('PARTNER_H5', `/partner/stores/${result.store.id}/packages`, {
|
||||||
|
method: 'PUT',
|
||||||
|
body: JSON.stringify({
|
||||||
|
packages: packages.map((p) => ({ ...p, price: Number(p.price).toFixed(2) })),
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
}
|
||||||
setForm(defaultStoreForm());
|
setForm(defaultStoreForm());
|
||||||
setFieldErrors({});
|
setFieldErrors({});
|
||||||
setSubmitError('');
|
setSubmitError('');
|
||||||
@@ -496,7 +537,7 @@ export default function StoreCreatePage() {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
const progress = step === 1 ? 0 : step === 2 ? 50 : 100;
|
const progress = step === 1 ? 0 : step === 2 ? 33 : step === 3 ? 66 : 100;
|
||||||
|
|
||||||
const nextDisabled = submitting;
|
const nextDisabled = submitting;
|
||||||
|
|
||||||
@@ -919,7 +960,7 @@ export default function StoreCreatePage() {
|
|||||||
|
|
||||||
<h3 className="headline-md">环境照片 <span className="text-primary">*</span></h3>
|
<h3 className="headline-md">环境照片 <span className="text-primary">*</span></h3>
|
||||||
|
|
||||||
<p className="label-md text-muted" style={{ margin: '4px 0 12px' }}>至少 3 张,展示店内整洁环境</p>
|
<p className="label-md text-muted" style={{ margin: '4px 0 12px' }}>至少 {MIN_ENV_PHOTO_COUNT} 张,展示店内整洁环境</p>
|
||||||
|
|
||||||
<div className="partner-upload-grid">
|
<div className="partner-upload-grid">
|
||||||
|
|
||||||
@@ -945,6 +986,17 @@ export default function StoreCreatePage() {
|
|||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="partner-btn-outline"
|
||||||
|
style={{ width: '100%', marginTop: 12 }}
|
||||||
|
onClick={() =>
|
||||||
|
setForm((prev) => ({ ...prev, envPhotoUrls: addEnvPhotoSlot(prev.envPhotoUrls) }))
|
||||||
|
}
|
||||||
|
>
|
||||||
|
添加环境照片
|
||||||
|
</button>
|
||||||
|
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
|
||||||
@@ -1096,6 +1148,26 @@ export default function StoreCreatePage() {
|
|||||||
|
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{step === 4 && (
|
||||||
|
<>
|
||||||
|
<section className="partner-form-card">
|
||||||
|
<div className="partner-section-title">
|
||||||
|
<div className="partner-section-bar" />
|
||||||
|
<h2 className="headline-md">门店套餐</h2>
|
||||||
|
</div>
|
||||||
|
<p className="label-md text-muted" style={{ marginBottom: 16 }}>
|
||||||
|
可选填写;提交后将进入总部审核。也可在最后一页点击「跳过」。
|
||||||
|
</p>
|
||||||
|
<StorePackagesForm
|
||||||
|
items={form.packages?.length ? form.packages : [{ name: '', price: '', dishes: '', usableTime: '', otherNotes: '', sortOrder: 0 }]}
|
||||||
|
onChange={(packages) => setForm((prev) => ({ ...prev, packages }))}
|
||||||
|
disabled={submitting}
|
||||||
|
embedded
|
||||||
|
/>
|
||||||
|
</section>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<footer className="partner-sticky-footer">
|
<footer className="partner-sticky-footer">
|
||||||
@@ -1110,7 +1182,7 @@ export default function StoreCreatePage() {
|
|||||||
|
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{step < 3 ? (
|
{step < 4 ? (
|
||||||
|
|
||||||
<button type="button" className="partner-btn-primary" onClick={() => void handleNext()} disabled={nextDisabled}>
|
<button type="button" className="partner-btn-primary" onClick={() => void handleNext()} disabled={nextDisabled}>
|
||||||
|
|
||||||
@@ -1122,16 +1194,37 @@ export default function StoreCreatePage() {
|
|||||||
|
|
||||||
) : (
|
) : (
|
||||||
|
|
||||||
<button type="button" className="partner-btn-primary" onClick={() => void submit()} disabled={submitting}>
|
<>
|
||||||
|
<button type="button" className="partner-btn-outline" onClick={() => void submit(true)} disabled={submitting}>
|
||||||
|
跳过
|
||||||
|
</button>
|
||||||
|
<button type="button" className="partner-btn-primary" onClick={() => void submit(false)} disabled={submitting}>
|
||||||
|
|
||||||
{submitting ? '提交中…' : '提交'}
|
{submitting ? '提交中…' : '提交'}
|
||||||
|
|
||||||
</button>
|
</button>
|
||||||
|
</>
|
||||||
|
|
||||||
)}
|
)}
|
||||||
|
|
||||||
</footer>
|
</footer>
|
||||||
|
|
||||||
|
{stepErrorModal ? (
|
||||||
|
<div className="partner-ship-modal-backdrop" role="presentation" onClick={() => setStepErrorModal(null)}>
|
||||||
|
<div className="partner-ship-modal" role="dialog" aria-modal="true" onClick={(e) => e.stopPropagation()}>
|
||||||
|
<h3 className="headline-md" style={{ marginBottom: 8 }}>请完善信息</h3>
|
||||||
|
<p className="body-md text-muted" style={{ lineHeight: 1.6, whiteSpace: 'pre-wrap' }}>
|
||||||
|
{stepErrorModal}
|
||||||
|
</p>
|
||||||
|
<div className="partner-ship-actions">
|
||||||
|
<button type="button" className="partner-btn-primary" onClick={() => setStepErrorModal(null)}>
|
||||||
|
我知道了
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
|
|
||||||
<TencentLocPickerOverlay
|
<TencentLocPickerOverlay
|
||||||
open={mapPickerOpen}
|
open={mapPickerOpen}
|
||||||
onClose={() => setMapPickerOpen(false)}
|
onClose={() => setMapPickerOpen(false)}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { request } from '../lib/api';
|
|||||||
import { toastError, toastSuccess } from '../lib/toast';
|
import { toastError, toastSuccess } from '../lib/toast';
|
||||||
import { usePartnerSession } from '../contexts/PartnerSessionContext';
|
import { usePartnerSession } from '../contexts/PartnerSessionContext';
|
||||||
import { canManagePartnerStore } from '../lib/partnerAccess';
|
import { canManagePartnerStore } from '../lib/partnerAccess';
|
||||||
import { normalizeStringArray, patchEnvPhotoAt } from '../lib/storeDraft';
|
import { MIN_ENV_PHOTO_COUNT, normalizeStringArray, patchEnvPhotoAt, addEnvPhotoSlot } from '../lib/storeDraft';
|
||||||
import OssUploadField from '../components/OssUploadField';
|
import OssUploadField from '../components/OssUploadField';
|
||||||
import TencentLocPickerOverlay from '../components/TencentLocPickerOverlay';
|
import TencentLocPickerOverlay from '../components/TencentLocPickerOverlay';
|
||||||
import {
|
import {
|
||||||
@@ -16,9 +16,9 @@ import {
|
|||||||
storeStatusPillClass,
|
storeStatusPillClass,
|
||||||
type StoreStatusValue,
|
type StoreStatusValue,
|
||||||
} from '../lib/storeStatus';
|
} from '../lib/storeStatus';
|
||||||
|
import { usePartnerPageView } from '../lib/usePageView';
|
||||||
|
|
||||||
const STATUS_OPTIONS: StoreStatusValue[] = ['OPEN', 'PAUSED', 'CLOSED'];
|
const STATUS_OPTIONS: StoreStatusValue[] = ['OPEN', 'PAUSED', 'CLOSED'];
|
||||||
const ENV_SLOT_COUNT = 3;
|
|
||||||
|
|
||||||
function uniqueEnvUrls(urls: string[]): string[] {
|
function uniqueEnvUrls(urls: string[]): string[] {
|
||||||
const seen = new Set<string>();
|
const seen = new Set<string>();
|
||||||
@@ -34,6 +34,7 @@ function uniqueEnvUrls(urls: string[]): string[] {
|
|||||||
|
|
||||||
export default function StoreDetailPage() {
|
export default function StoreDetailPage() {
|
||||||
const { id } = useParams();
|
const { id } = useParams();
|
||||||
|
usePartnerPageView('partner_store_detail_view', id ? { storeId: id } : undefined);
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const { account } = usePartnerSession();
|
const { account } = usePartnerSession();
|
||||||
const canMutate = canManagePartnerStore(account);
|
const canMutate = canManagePartnerStore(account);
|
||||||
@@ -81,7 +82,7 @@ export default function StoreDetailPage() {
|
|||||||
.map((m) => String(m.url || '')),
|
.map((m) => String(m.url || '')),
|
||||||
)
|
)
|
||||||
: [];
|
: [];
|
||||||
setEnvPhotoUrls(normalizeStringArray(envFromMedia, ENV_SLOT_COUNT));
|
setEnvPhotoUrls(normalizeStringArray(envFromMedia, MIN_ENV_PHOTO_COUNT));
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -196,8 +197,8 @@ export default function StoreDetailPage() {
|
|||||||
setActionError('请上传门头照');
|
setActionError('请上传门头照');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (nextEnv.length < ENV_SLOT_COUNT) {
|
if (nextEnv.length < MIN_ENV_PHOTO_COUNT) {
|
||||||
setActionError(`请上传至少 ${ENV_SLOT_COUNT} 张环境照片`);
|
setActionError(`请上传至少 ${MIN_ENV_PHOTO_COUNT} 张环境照片`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setMediaSaving(true);
|
setMediaSaving(true);
|
||||||
@@ -277,6 +278,18 @@ export default function StoreDetailPage() {
|
|||||||
)}
|
)}
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
{canMutate && !auditPending && status !== 'CLOSED' && (
|
||||||
|
<section className="partner-form-card" style={{ margin: '0 0 16px' }}>
|
||||||
|
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
|
||||||
|
<h3 className="label-md text-muted" style={{ textTransform: 'uppercase', letterSpacing: '0.1em' }}>门店套餐</h3>
|
||||||
|
<button type="button" className="partner-btn-outline" onClick={() => navigate(`/stores/${id}/packages`)}>
|
||||||
|
编辑套餐
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<p className="label-md text-muted" style={{ marginTop: 8 }}>维护可核销套餐信息,提交后由总部审核。</p>
|
||||||
|
</section>
|
||||||
|
)}
|
||||||
|
|
||||||
{canMutate && (
|
{canMutate && (
|
||||||
<section className="partner-form-card" style={{ margin: '0 0 16px' }}>
|
<section className="partner-form-card" style={{ margin: '0 0 16px' }}>
|
||||||
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 16 }}>
|
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 16 }}>
|
||||||
@@ -388,7 +401,7 @@ export default function StoreDetailPage() {
|
|||||||
<h3 className="headline-md" style={{ borderLeft: '4px solid var(--color-heritage-red)', paddingLeft: 12 }}>店内环境</h3>
|
<h3 className="headline-md" style={{ borderLeft: '4px solid var(--color-heritage-red)', paddingLeft: 12 }}>店内环境</h3>
|
||||||
<span className="label-md text-muted">
|
<span className="label-md text-muted">
|
||||||
{canMutate && !readOnly
|
{canMutate && !readOnly
|
||||||
? `需 ${ENV_SLOT_COUNT} 张 · 已选 ${uniqueEnvUrls(envPhotoUrls).length} 张`
|
? `至少 ${MIN_ENV_PHOTO_COUNT} 张 · 已选 ${uniqueEnvUrls(envPhotoUrls).length} 张`
|
||||||
: envPhotos.length
|
: envPhotos.length
|
||||||
? `已上传 ${envPhotos.length} 张`
|
? `已上传 ${envPhotos.length} 张`
|
||||||
: '暂无照片'}
|
: '暂无照片'}
|
||||||
@@ -408,6 +421,14 @@ export default function StoreDetailPage() {
|
|||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="partner-btn-outline"
|
||||||
|
style={{ width: '100%', marginTop: 12 }}
|
||||||
|
onClick={() => setEnvPhotoUrls((prev) => addEnvPhotoSlot(prev))}
|
||||||
|
>
|
||||||
|
添加环境照片
|
||||||
|
</button>
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
className="partner-btn-outline"
|
className="partner-btn-outline"
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import {
|
|||||||
storeStatusPillClass,
|
storeStatusPillClass,
|
||||||
type StoreStatusValue,
|
type StoreStatusValue,
|
||||||
} from '../lib/storeStatus';
|
} from '../lib/storeStatus';
|
||||||
|
import { usePartnerPageView } from '../lib/usePageView';
|
||||||
|
|
||||||
type StatusFilter = 'ALL' | StoreStatusValue | 'PENDING_AUDIT' | 'REJECTED';
|
type StatusFilter = 'ALL' | StoreStatusValue | 'PENDING_AUDIT' | 'REJECTED';
|
||||||
|
|
||||||
@@ -26,6 +27,7 @@ const FILTERS: { key: StatusFilter; label: string }[] = [
|
|||||||
];
|
];
|
||||||
|
|
||||||
export default function StoreListPage() {
|
export default function StoreListPage() {
|
||||||
|
usePartnerPageView('partner_store_list_view');
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const [searchParams] = useSearchParams();
|
const [searchParams] = useSearchParams();
|
||||||
const { account } = usePartnerSession();
|
const { account } = usePartnerSession();
|
||||||
|
|||||||
@@ -0,0 +1,143 @@
|
|||||||
|
import { useEffect, useState } from 'react';
|
||||||
|
import { useNavigate, useParams } from 'react-router-dom';
|
||||||
|
import type { StorePackagesResponse } from '@dukang/shared-types';
|
||||||
|
import StorePackagesForm from '../components/StorePackagesForm';
|
||||||
|
import { request } from '../lib/api';
|
||||||
|
import { toastError, toastSuccess } from '../lib/toast';
|
||||||
|
import {
|
||||||
|
emptyPackage,
|
||||||
|
normalizePackageFormItems,
|
||||||
|
validatePackageFormItems,
|
||||||
|
type PackageFormItem,
|
||||||
|
} from '../lib/storePackages';
|
||||||
|
|
||||||
|
export default function StorePackagesPage() {
|
||||||
|
const { id } = useParams();
|
||||||
|
const navigate = useNavigate();
|
||||||
|
const [items, setItems] = useState<PackageFormItem[]>([emptyPackage()]);
|
||||||
|
const [pending, setPending] = useState<StorePackagesResponse['pendingRequest']>(null);
|
||||||
|
const [loading, setLoading] = useState(true);
|
||||||
|
const [submitting, setSubmitting] = useState(false);
|
||||||
|
const [error, setError] = useState('');
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!id) return;
|
||||||
|
setLoading(true);
|
||||||
|
request<StorePackagesResponse>('PARTNER_H5', `/partner/stores/${id}/packages`)
|
||||||
|
.then((data) => {
|
||||||
|
const base = data.pendingRequest?.packages?.length
|
||||||
|
? data.pendingRequest.packages
|
||||||
|
: data.live?.length
|
||||||
|
? data.live
|
||||||
|
: [emptyPackage()];
|
||||||
|
setItems(base.map((p, i) => ({ ...p, price: String(p.price), sortOrder: i })));
|
||||||
|
setPending(data.pendingRequest ?? null);
|
||||||
|
})
|
||||||
|
.catch((e) => setError(e instanceof Error ? e.message : '加载失败'))
|
||||||
|
.finally(() => setLoading(false));
|
||||||
|
}, [id]);
|
||||||
|
|
||||||
|
async function submitAudit() {
|
||||||
|
if (!id) return;
|
||||||
|
const msg = validatePackageFormItems(items);
|
||||||
|
if (msg) {
|
||||||
|
toastError(msg);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (pending?.status === 'PENDING') {
|
||||||
|
toastError('已有套餐变更审核中,请等待总部处理');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setSubmitting(true);
|
||||||
|
try {
|
||||||
|
const packages = normalizePackageFormItems(items).map((p) => ({
|
||||||
|
...p,
|
||||||
|
price: Number(p.price).toFixed(2),
|
||||||
|
}));
|
||||||
|
await request('PARTNER_H5', `/partner/stores/${id}/packages`, {
|
||||||
|
method: 'PUT',
|
||||||
|
body: JSON.stringify({ packages }),
|
||||||
|
});
|
||||||
|
toastSuccess('已提交审核');
|
||||||
|
navigate(`/stores/${id}`);
|
||||||
|
} catch (e) {
|
||||||
|
toastError(e instanceof Error ? e.message : '提交失败');
|
||||||
|
} finally {
|
||||||
|
setSubmitting(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (loading) {
|
||||||
|
return (
|
||||||
|
<div className="partner-detail-page partner-home--flush-top">
|
||||||
|
<main style={{ padding: '24px 20px' }}>
|
||||||
|
<p className="label-md text-muted">加载中…</p>
|
||||||
|
</main>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="partner-page-sticky partner-home--flush-top">
|
||||||
|
<header className="partner-packages-page-header">
|
||||||
|
<button type="button" className="partner-packages-back" onClick={() => navigate(`/stores/${id}`)}>
|
||||||
|
<span className="material-symbols-outlined">arrow_back</span>
|
||||||
|
</button>
|
||||||
|
<h1 className="headline-md">门店套餐</h1>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<main className="partner-packages-page-main">
|
||||||
|
{error ? <p className="partner-form-error" role="alert">{error}</p> : null}
|
||||||
|
|
||||||
|
{pending?.status === 'PENDING' ? (
|
||||||
|
<div className="partner-info-banner">
|
||||||
|
<span className="material-symbols-outlined" style={{ color: 'var(--color-heritage-red)' }}>hourglass_top</span>
|
||||||
|
<p className="body-md">套餐变更审核中,C 端仍展示上一版生效套餐。</p>
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
|
|
||||||
|
{pending?.status === 'REJECTED' && pending.rejectReason ? (
|
||||||
|
<div className="partner-info-banner" style={{ background: 'rgba(180,35,24,0.06)', borderColor: 'rgba(180,35,24,0.15)' }}>
|
||||||
|
<span className="material-symbols-outlined" style={{ color: 'var(--color-heritage-red)' }}>error</span>
|
||||||
|
<p className="body-md">上次驳回:{pending.rejectReason}</p>
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
|
|
||||||
|
<section className="partner-form-card">
|
||||||
|
<div className="partner-section-title">
|
||||||
|
<div className="partner-section-bar" />
|
||||||
|
<h2 className="headline-md">套餐信息</h2>
|
||||||
|
</div>
|
||||||
|
<p className="label-md text-muted" style={{ marginBottom: 16 }}>
|
||||||
|
提交后将由总部审核,通过后 C 端展示生效套餐。
|
||||||
|
</p>
|
||||||
|
<StorePackagesForm
|
||||||
|
items={items}
|
||||||
|
onChange={setItems}
|
||||||
|
disabled={pending?.status === 'PENDING' || submitting}
|
||||||
|
embedded
|
||||||
|
/>
|
||||||
|
</section>
|
||||||
|
</main>
|
||||||
|
|
||||||
|
<footer className="partner-sticky-footer">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="partner-btn-outline"
|
||||||
|
onClick={() => navigate(`/stores/${id}`)}
|
||||||
|
disabled={submitting}
|
||||||
|
>
|
||||||
|
返回
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="partner-btn-primary"
|
||||||
|
disabled={submitting || pending?.status === 'PENDING'}
|
||||||
|
onClick={() => void submitAudit()}
|
||||||
|
>
|
||||||
|
{submitting ? '提交中…' : '提交审核'}
|
||||||
|
</button>
|
||||||
|
</footer>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -4,6 +4,7 @@ import type { PartnerWeeklyReportResponse } from '@dukang/shared-types';
|
|||||||
import PageHeader from '@dukang/shared-ui/PageHeader';
|
import PageHeader from '@dukang/shared-ui/PageHeader';
|
||||||
import PullToRefresh from '@dukang/shared-ui/PullToRefresh';
|
import PullToRefresh from '@dukang/shared-ui/PullToRefresh';
|
||||||
import { fetchPartnerWeeklyReport } from '../lib/weeklyReport';
|
import { fetchPartnerWeeklyReport } from '../lib/weeklyReport';
|
||||||
|
import { usePartnerPageView } from '../lib/usePageView';
|
||||||
|
|
||||||
function fmtMoney(n: number) {
|
function fmtMoney(n: number) {
|
||||||
return n.toLocaleString('zh-CN', { minimumFractionDigits: 0, maximumFractionDigits: 0 });
|
return n.toLocaleString('zh-CN', { minimumFractionDigits: 0, maximumFractionDigits: 0 });
|
||||||
@@ -15,6 +16,7 @@ function fmtGrowth(n: number) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default function WeeklyReportPage() {
|
export default function WeeklyReportPage() {
|
||||||
|
usePartnerPageView('partner_weekly_report_view');
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const [selectedStart, setSelectedStart] = useState<string | undefined>();
|
const [selectedStart, setSelectedStart] = useState<string | undefined>();
|
||||||
const [data, setData] = useState<PartnerWeeklyReportResponse | null>(null);
|
const [data, setData] = useState<PartnerWeeklyReportResponse | null>(null);
|
||||||
|
|||||||
@@ -3634,3 +3634,107 @@ header:has(> .app-page-title:only-child),
|
|||||||
border: none !important;
|
border: none !important;
|
||||||
box-shadow: none !important;
|
box-shadow: none !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ─── 门店套餐 ─── */
|
||||||
|
.partner-packages-page-header {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 8px;
|
||||||
|
padding: 12px var(--space-page) 8px;
|
||||||
|
background: var(--color-surface);
|
||||||
|
border-bottom: 1px solid rgba(226, 190, 188, 0.12);
|
||||||
|
}
|
||||||
|
|
||||||
|
.partner-packages-back {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
width: 40px;
|
||||||
|
height: 40px;
|
||||||
|
border: none;
|
||||||
|
background: transparent;
|
||||||
|
color: var(--color-on-surface);
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.partner-packages-page-main {
|
||||||
|
padding-bottom: 88px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.partner-packages-form--embedded .partner-packages-item {
|
||||||
|
margin-bottom: var(--space-md);
|
||||||
|
box-shadow: none;
|
||||||
|
border: 1px solid rgba(226, 190, 188, 0.2);
|
||||||
|
}
|
||||||
|
|
||||||
|
.partner-packages-form--embedded .partner-packages-item:last-of-type {
|
||||||
|
margin-bottom: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.partner-packages-item-head {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
margin-bottom: var(--space-md);
|
||||||
|
}
|
||||||
|
|
||||||
|
.partner-packages-item--collapsed .partner-packages-item-head {
|
||||||
|
margin-bottom: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.partner-packages-toggle {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 4px;
|
||||||
|
border: none;
|
||||||
|
background: transparent;
|
||||||
|
padding: 0;
|
||||||
|
color: inherit;
|
||||||
|
cursor: pointer;
|
||||||
|
text-align: left;
|
||||||
|
flex: 1;
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.partner-packages-toggle .material-symbols-outlined {
|
||||||
|
font-size: 20px;
|
||||||
|
color: var(--color-on-surface-variant, #666);
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.partner-packages-toggle .headline-md {
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.partner-packages-remove {
|
||||||
|
border: none;
|
||||||
|
background: transparent;
|
||||||
|
color: var(--color-heritage-red);
|
||||||
|
font-size: 13px;
|
||||||
|
padding: 4px 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.partner-packages-add {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
gap: 6px;
|
||||||
|
width: calc(100% - var(--space-page) * 2);
|
||||||
|
margin: 0 var(--space-page) var(--space-md);
|
||||||
|
min-height: 48px;
|
||||||
|
border: 1px dashed rgba(166, 29, 36, 0.35);
|
||||||
|
border-radius: var(--radius-md);
|
||||||
|
background: rgba(166, 29, 36, 0.04);
|
||||||
|
color: var(--color-heritage-red);
|
||||||
|
font-size: 14px;
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
.partner-packages-add .material-symbols-outlined {
|
||||||
|
font-size: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.partner-packages-form:not(.partner-packages-form--embedded) .partner-packages-item {
|
||||||
|
margin-left: var(--space-page);
|
||||||
|
margin-right: var(--space-page);
|
||||||
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
"lint": "echo ok"
|
"lint": "echo ok"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@dukang/client-logging": "workspace:*",
|
||||||
"@dukang/shared-ui": "workspace:*",
|
"@dukang/shared-ui": "workspace:*",
|
||||||
"@dukang/shared-types": "workspace:*",
|
"@dukang/shared-types": "workspace:*",
|
||||||
"@dukang/weixin-sdk": "workspace:*",
|
"@dukang/weixin-sdk": "workspace:*",
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import StatusPage from './pages/StatusPage';
|
|||||||
import MinePage from './pages/MinePage';
|
import MinePage from './pages/MinePage';
|
||||||
import StaffPage from './pages/StaffPage';
|
import StaffPage from './pages/StaffPage';
|
||||||
import WithdrawPage from './pages/WithdrawPage';
|
import WithdrawPage from './pages/WithdrawPage';
|
||||||
|
import PackagesPage from './pages/PackagesPage';
|
||||||
|
|
||||||
export default function App() {
|
export default function App() {
|
||||||
return (
|
return (
|
||||||
@@ -24,6 +25,7 @@ export default function App() {
|
|||||||
<Route path="/select-store" element={<SelectStorePage />} />
|
<Route path="/select-store" element={<SelectStorePage />} />
|
||||||
<Route path="/staff" element={<StaffPage />} />
|
<Route path="/staff" element={<StaffPage />} />
|
||||||
<Route path="/withdraw" element={<WithdrawPage />} />
|
<Route path="/withdraw" element={<WithdrawPage />} />
|
||||||
|
<Route path="/packages" element={<PackagesPage />} />
|
||||||
<Route path="/redeem" element={<RedeemConfirmPage />} />
|
<Route path="/redeem" element={<RedeemConfirmPage />} />
|
||||||
<Route path="/redeem/phone" element={<PhoneRedeemPage />} />
|
<Route path="/redeem/phone" element={<PhoneRedeemPage />} />
|
||||||
<Route path="/redeem/success" element={<RedeemSuccessPage />} />
|
<Route path="/redeem/success" element={<RedeemSuccessPage />} />
|
||||||
|
|||||||
@@ -0,0 +1,187 @@
|
|||||||
|
import { useRef, useState } from 'react';
|
||||||
|
import { STORE_PACKAGE_MAX_COUNT } from '@dukang/shared-types';
|
||||||
|
import { emptyPackage, type PackageFormItem } from '../lib/storePackages';
|
||||||
|
import { uploadFileToOss } from '../lib/upload';
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
items: PackageFormItem[];
|
||||||
|
onChange: (items: PackageFormItem[]) => void;
|
||||||
|
disabled?: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function ShopPackagesForm({ items, onChange, disabled }: Props) {
|
||||||
|
const [collapsed, setCollapsed] = useState<Record<number, boolean>>({});
|
||||||
|
const [uploadingIndex, setUploadingIndex] = useState<number | null>(null);
|
||||||
|
const fileRefs = useRef<Record<number, HTMLInputElement | null>>({});
|
||||||
|
|
||||||
|
async function pickPackageImage(index: number, file?: File | null) {
|
||||||
|
if (!file || disabled) return;
|
||||||
|
setUploadingIndex(index);
|
||||||
|
try {
|
||||||
|
const result = await uploadFileToOss(file, 'STORE_PACKAGE');
|
||||||
|
updateAt(index, { imageUrl: result.url });
|
||||||
|
} finally {
|
||||||
|
setUploadingIndex(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateAt(index: number, patch: Partial<PackageFormItem>) {
|
||||||
|
onChange(items.map((item, i) => (i === index ? { ...item, ...patch } : item)));
|
||||||
|
}
|
||||||
|
|
||||||
|
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="shop-packages-form">
|
||||||
|
{list.map((item, index) => {
|
||||||
|
const isCollapsed = !!collapsed[index];
|
||||||
|
const displayName = item.name.trim() || `套餐 ${index + 1}`;
|
||||||
|
return (
|
||||||
|
<section key={index} className={`shop-packages-card${isCollapsed ? ' shop-packages-card--collapsed' : ''}`}>
|
||||||
|
<div className="shop-packages-card-head">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="shop-packages-toggle"
|
||||||
|
onClick={() => toggleCollapse(index)}
|
||||||
|
aria-expanded={!isCollapsed}
|
||||||
|
aria-label={isCollapsed ? '展开套餐' : '收起套餐'}
|
||||||
|
>
|
||||||
|
<span className="material-symbols-outlined">
|
||||||
|
{isCollapsed ? 'expand_more' : 'expand_less'}
|
||||||
|
</span>
|
||||||
|
<span className="shop-packages-card-title">{displayName}</span>
|
||||||
|
</button>
|
||||||
|
{!disabled && list.length > 1 ? (
|
||||||
|
<button type="button" className="shop-packages-remove" onClick={() => removeAt(index)}>
|
||||||
|
删除
|
||||||
|
</button>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{!isCollapsed ? (
|
||||||
|
<>
|
||||||
|
<label className="shop-packages-field">
|
||||||
|
<span className="shop-packages-label">套餐名称 *</span>
|
||||||
|
<input
|
||||||
|
className="shop-packages-input"
|
||||||
|
placeholder="如:套餐A"
|
||||||
|
value={item.name}
|
||||||
|
disabled={disabled}
|
||||||
|
onChange={(e) => updateAt(index, { name: e.target.value })}
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<label className="shop-packages-field">
|
||||||
|
<span className="shop-packages-label">价格(元) *</span>
|
||||||
|
<input
|
||||||
|
className="shop-packages-input"
|
||||||
|
type="number"
|
||||||
|
min={0}
|
||||||
|
step={0.01}
|
||||||
|
placeholder="198"
|
||||||
|
value={item.price}
|
||||||
|
disabled={disabled}
|
||||||
|
onChange={(e) => updateAt(index, { price: e.target.value })}
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<label className="shop-packages-field">
|
||||||
|
<span className="shop-packages-label">菜品 *</span>
|
||||||
|
<textarea
|
||||||
|
className="shop-packages-textarea"
|
||||||
|
rows={3}
|
||||||
|
placeholder="红烧肉、红烧鱼、油焖茄子"
|
||||||
|
value={item.dishes}
|
||||||
|
disabled={disabled}
|
||||||
|
onChange={(e) => updateAt(index, { dishes: e.target.value })}
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<label className="shop-packages-field">
|
||||||
|
<span className="shop-packages-label">使用时间</span>
|
||||||
|
<input
|
||||||
|
className="shop-packages-input"
|
||||||
|
placeholder="节假日除外"
|
||||||
|
value={item.usableTime || ''}
|
||||||
|
disabled={disabled}
|
||||||
|
onChange={(e) => updateAt(index, { usableTime: e.target.value })}
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<label className="shop-packages-field">
|
||||||
|
<span className="shop-packages-label">套餐图片</span>
|
||||||
|
{item.imageUrl ? (
|
||||||
|
<img
|
||||||
|
src={item.imageUrl}
|
||||||
|
alt=""
|
||||||
|
style={{ width: '100%', maxHeight: 160, objectFit: 'cover', borderRadius: 8, marginBottom: 8 }}
|
||||||
|
/>
|
||||||
|
) : null}
|
||||||
|
<input
|
||||||
|
ref={(el) => {
|
||||||
|
fileRefs.current[index] = el;
|
||||||
|
}}
|
||||||
|
type="file"
|
||||||
|
accept="image/*"
|
||||||
|
hidden
|
||||||
|
disabled={disabled}
|
||||||
|
onChange={(e) => void pickPackageImage(index, e.target.files?.[0])}
|
||||||
|
/>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="shop-packages-add"
|
||||||
|
style={{ marginTop: 0 }}
|
||||||
|
disabled={disabled || uploadingIndex === index}
|
||||||
|
onClick={() => fileRefs.current[index]?.click()}
|
||||||
|
>
|
||||||
|
{uploadingIndex === index ? '上传中…' : item.imageUrl ? '更换图片' : '上传图片'}
|
||||||
|
</button>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<label className="shop-packages-field">
|
||||||
|
<span className="shop-packages-label">其他说明</span>
|
||||||
|
<input
|
||||||
|
className="shop-packages-input"
|
||||||
|
placeholder="不可叠加"
|
||||||
|
value={item.otherNotes || ''}
|
||||||
|
disabled={disabled}
|
||||||
|
onChange={(e) => updateAt(index, { otherNotes: e.target.value })}
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
</>
|
||||||
|
) : null}
|
||||||
|
</section>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
|
||||||
|
{!disabled && list.length < STORE_PACKAGE_MAX_COUNT ? (
|
||||||
|
<button type="button" className="shop-packages-add" onClick={addItem}>
|
||||||
|
<span className="material-symbols-outlined">add_circle</span>
|
||||||
|
添加套餐
|
||||||
|
</button>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -19,6 +19,7 @@ import {
|
|||||||
import {
|
import {
|
||||||
fetchClientConfig,
|
fetchClientConfig,
|
||||||
handleShopWechatCallback,
|
handleShopWechatCallback,
|
||||||
|
handleShopWechatCallbackOnce,
|
||||||
handleShopWechatLoginResult,
|
handleShopWechatLoginResult,
|
||||||
isShopWechatUnboundError,
|
isShopWechatUnboundError,
|
||||||
SHOP_WX_NEED_PHONE_LOGIN_MSG,
|
SHOP_WX_NEED_PHONE_LOGIN_MSG,
|
||||||
@@ -79,7 +80,7 @@ export function StoreSessionProvider({ children }: { children: ReactNode }) {
|
|||||||
try {
|
try {
|
||||||
const config = await fetchClientConfig();
|
const config = await fetchClientConfig();
|
||||||
if (isWxAuthorizeEnabled(config)) {
|
if (isWxAuthorizeEnabled(config)) {
|
||||||
const result = await handleShopWechatCallback();
|
const result = await handleShopWechatCallbackOnce();
|
||||||
if (result && !cancelled) {
|
if (result && !cancelled) {
|
||||||
const session = handleShopWechatLoginResult(result);
|
const session = handleShopWechatLoginResult(result);
|
||||||
if (session) applySession(session);
|
if (session) applySession(session);
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
import { createStoreTracker } from '@dukang/client-logging';
|
||||||
|
import { apiBase } from './api';
|
||||||
|
|
||||||
|
const tracker = createStoreTracker({
|
||||||
|
apiBase,
|
||||||
|
clientApp: 'SHOP_H5',
|
||||||
|
getToken: () => localStorage.getItem('shopAccessToken'),
|
||||||
|
getStoreId: () => {
|
||||||
|
try {
|
||||||
|
const raw = localStorage.getItem('shopSession');
|
||||||
|
if (!raw) return null;
|
||||||
|
const parsed = JSON.parse(raw) as { storeId?: string };
|
||||||
|
return parsed.storeId ?? null;
|
||||||
|
} catch {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
export function trackStore(eventName: string, params?: Record<string, unknown>) {
|
||||||
|
tracker.track(eventName, params);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function trackStorePageView(eventName: string, params?: Record<string, unknown>) {
|
||||||
|
tracker.trackPageView(eventName, params);
|
||||||
|
}
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import { reportApiError } from '@dukang/client-logging';
|
||||||
|
|
||||||
export const apiBase = '/api/v1';
|
export const apiBase = '/api/v1';
|
||||||
const CLIENT_APP = 'SHOP_H5';
|
const CLIENT_APP = 'SHOP_H5';
|
||||||
|
|
||||||
@@ -213,6 +215,12 @@ async function rawRequest<T>(
|
|||||||
if (json.code !== 0) {
|
if (json.code !== 0) {
|
||||||
const err = new Error(json.message || '请求失败') as Error & { status?: number };
|
const err = new Error(json.message || '请求失败') as Error & { status?: number };
|
||||||
err.status = res.status >= 500 ? res.status : json.code;
|
err.status = res.status >= 500 ? res.status : json.code;
|
||||||
|
if (json.code === 400) {
|
||||||
|
reportApiError(
|
||||||
|
{ apiBase, clientApp: CLIENT_APP, getToken: () => localStorage.getItem(ACCESS_TOKEN) },
|
||||||
|
{ message: json.message || '请求失败', status: 400, url: path, category: 'validation_error' },
|
||||||
|
);
|
||||||
|
}
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
return json.data as T;
|
return json.data as T;
|
||||||
|
|||||||
@@ -0,0 +1,33 @@
|
|||||||
|
import { isIosDevice } from '@dukang/weixin-sdk';
|
||||||
|
|
||||||
|
/** 扫码前发起 OAuth 时标记,回跳后在首页续扫 */
|
||||||
|
export const SHOP_PENDING_SCAN_KEY = 'shop_pending_scan';
|
||||||
|
|
||||||
|
export function markPendingScanAfterAuth(): void {
|
||||||
|
try {
|
||||||
|
sessionStorage.setItem(SHOP_PENDING_SCAN_KEY, '1');
|
||||||
|
} catch {
|
||||||
|
/* ignore */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function peekPendingScanAfterAuth(): boolean {
|
||||||
|
try {
|
||||||
|
return sessionStorage.getItem(SHOP_PENDING_SCAN_KEY) === '1';
|
||||||
|
} catch {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function clearPendingScanAfterAuth(): void {
|
||||||
|
try {
|
||||||
|
sessionStorage.removeItem(SHOP_PENDING_SCAN_KEY);
|
||||||
|
} catch {
|
||||||
|
/* ignore */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** OAuth 回跳后延迟再调 scanQRCode(iOS JSSDK 离线校验更慢) */
|
||||||
|
export function getPostAuthScanDelayMs(): number {
|
||||||
|
return isIosDevice() ? 1200 : 600;
|
||||||
|
}
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
import type { StorePackageItemDto } from '@dukang/shared-types';
|
||||||
|
import { STORE_PACKAGE_MAX_COUNT } from '@dukang/shared-types';
|
||||||
|
|
||||||
|
export type PackageFormItem = StorePackageItemDto;
|
||||||
|
|
||||||
|
export function emptyPackage(index = 0): PackageFormItem {
|
||||||
|
return {
|
||||||
|
name: '',
|
||||||
|
price: '',
|
||||||
|
dishes: '',
|
||||||
|
usableTime: '',
|
||||||
|
otherNotes: '',
|
||||||
|
imageUrl: '',
|
||||||
|
sortOrder: index,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function normalizePackageFormItems(raw: PackageFormItem[]): PackageFormItem[] {
|
||||||
|
return raw
|
||||||
|
.map((item, index) => ({
|
||||||
|
name: item.name.trim(),
|
||||||
|
price: item.price.trim(),
|
||||||
|
dishes: item.dishes.trim(),
|
||||||
|
usableTime: item.usableTime?.trim() || '',
|
||||||
|
otherNotes: item.otherNotes?.trim() || '',
|
||||||
|
imageUrl: item.imageUrl?.trim() || '',
|
||||||
|
sortOrder: index,
|
||||||
|
}))
|
||||||
|
.filter(
|
||||||
|
(item) =>
|
||||||
|
item.name || item.price || item.dishes || item.usableTime || item.otherNotes || item.imageUrl,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function validatePackageFormItems(items: PackageFormItem[]): string | null {
|
||||||
|
const filled = normalizePackageFormItems(items);
|
||||||
|
if (filled.length > STORE_PACKAGE_MAX_COUNT) {
|
||||||
|
return `套餐最多 ${STORE_PACKAGE_MAX_COUNT} 条`;
|
||||||
|
}
|
||||||
|
for (let i = 0; i < filled.length; i++) {
|
||||||
|
const item = filled[i];
|
||||||
|
if (!item.name) return `第 ${i + 1} 条套餐名称不能为空`;
|
||||||
|
const price = Number(item.price);
|
||||||
|
if (!Number.isFinite(price) || price < 0) return `第 ${i + 1} 条套餐价格须为非负数字`;
|
||||||
|
if (!item.dishes) return `第 ${i + 1} 条套餐菜品不能为空`;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
@@ -1,5 +1,10 @@
|
|||||||
import { apiBase } from './api';
|
import { apiBase } from './api';
|
||||||
import { getStoreProfile } from './api';
|
import { getStoreProfile } from './api';
|
||||||
|
import {
|
||||||
|
compressImageFileIfNeeded,
|
||||||
|
DEFAULT_OSS_MAX_UPLOAD_BYTES,
|
||||||
|
formatOssMaxSizeMb,
|
||||||
|
} from '@dukang/shared-ui/compressImage';
|
||||||
|
|
||||||
const UPLOAD_TIMEOUT_MS = 120_000;
|
const UPLOAD_TIMEOUT_MS = 120_000;
|
||||||
|
|
||||||
@@ -15,9 +20,13 @@ export type RegisteredResource = {
|
|||||||
url: string;
|
url: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
async function uploadFileToOss(file: File, bizType: string): Promise<UploadFileResult> {
|
export async function uploadFileToOss(file: File, bizType: string): Promise<UploadFileResult> {
|
||||||
|
const compressed = await compressImageFileIfNeeded(file);
|
||||||
|
if (compressed.size > DEFAULT_OSS_MAX_UPLOAD_BYTES) {
|
||||||
|
throw new Error(`图片压缩后仍超过 ${formatOssMaxSizeMb()}MB,请换一张较小的图片`);
|
||||||
|
}
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
formData.append('file', file);
|
formData.append('file', compressed);
|
||||||
formData.append('bizType', bizType);
|
formData.append('bizType', bizType);
|
||||||
formData.append('mediaType', 'IMAGE');
|
formData.append('mediaType', 'IMAGE');
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
import { useEffect, useRef } from 'react';
|
||||||
|
import { trackStorePageView } from './analytics';
|
||||||
|
|
||||||
|
export function useStorePageView(eventName: string, params?: Record<string, unknown>) {
|
||||||
|
const fired = useRef(false);
|
||||||
|
useEffect(() => {
|
||||||
|
if (fired.current) return;
|
||||||
|
fired.current = true;
|
||||||
|
trackStorePageView(eventName, params);
|
||||||
|
}, [eventName, params]);
|
||||||
|
}
|
||||||
@@ -138,6 +138,20 @@ export async function handleShopWechatCallback(): Promise<WechatLoginResult | nu
|
|||||||
return weixinSdk.handleOAuthCallback();
|
return weixinSdk.handleOAuthCallback();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let oauthCallbackInflight: Promise<WechatLoginResult | null> | null = null;
|
||||||
|
|
||||||
|
/** 全局单例:避免 Context 与页面 effect 重复消费 OAuth code */
|
||||||
|
export async function handleShopWechatCallbackOnce(): Promise<WechatLoginResult | null> {
|
||||||
|
if (!isWechatEnv()) return null;
|
||||||
|
const params = new URLSearchParams(window.location.search);
|
||||||
|
if (!params.get('code')) return null;
|
||||||
|
if (oauthCallbackInflight) return oauthCallbackInflight;
|
||||||
|
oauthCallbackInflight = handleShopWechatCallback().finally(() => {
|
||||||
|
oauthCallbackInflight = null;
|
||||||
|
});
|
||||||
|
return oauthCallbackInflight;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 微信一键登录(已绑定微信的门店账号免验证码)。
|
* 微信一键登录(已绑定微信的门店账号免验证码)。
|
||||||
* 返回 session = 已登录;void = 已跳转授权页等待回调。
|
* 返回 session = 已登录;void = 已跳转授权页等待回调。
|
||||||
|
|||||||
@@ -3,12 +3,17 @@ import ReactDOM from 'react-dom/client';
|
|||||||
import { BrowserRouter } from 'react-router-dom';
|
import { BrowserRouter } from 'react-router-dom';
|
||||||
import { getRouterBasename } from '@dukang/weixin-sdk';
|
import { getRouterBasename } from '@dukang/weixin-sdk';
|
||||||
import { StoreSessionProvider } from './contexts/StoreSessionContext';
|
import { StoreSessionProvider } from './contexts/StoreSessionContext';
|
||||||
import { installClientErrorReporting } from './lib/client-error';
|
import { installClientErrorReporting } from '@dukang/client-logging';
|
||||||
import App from './App';
|
import App from './App';
|
||||||
|
import { apiBase } from './lib/api';
|
||||||
import './styles.css';
|
import './styles.css';
|
||||||
import './styles/legal.css';
|
import './styles/legal.css';
|
||||||
|
|
||||||
installClientErrorReporting();
|
installClientErrorReporting({
|
||||||
|
apiBase,
|
||||||
|
clientApp: 'SHOP_H5',
|
||||||
|
getToken: () => localStorage.getItem('shopAccessToken'),
|
||||||
|
});
|
||||||
|
|
||||||
ReactDOM.createRoot(document.getElementById('root')!).render(
|
ReactDOM.createRoot(document.getElementById('root')!).render(
|
||||||
<React.StrictMode>
|
<React.StrictMode>
|
||||||
|
|||||||
+293
-281
@@ -1,281 +1,293 @@
|
|||||||
import { useCallback, useEffect, useState } from 'react';
|
import { useCallback, useEffect, useRef, useState } from 'react';
|
||||||
import { Link, useNavigate, useSearchParams } from 'react-router-dom';
|
|
||||||
import PullToRefresh from '@dukang/shared-ui/PullToRefresh';
|
import { Link, useNavigate, useSearchParams } from 'react-router-dom';
|
||||||
import { useStoreSession } from '../contexts/StoreSessionContext';
|
|
||||||
import { request } from '../lib/api';
|
import PullToRefresh from '@dukang/shared-ui/PullToRefresh';
|
||||||
import { parseRedeemTokenFromScan } from '../lib/redeem-scan';
|
|
||||||
import {
|
import { isScanPermissionWarmupError } from '@dukang/weixin-sdk';
|
||||||
authorizeShopWechat,
|
|
||||||
checkNeedsWechatAuth,
|
import { useStoreSession } from '../contexts/StoreSessionContext';
|
||||||
fetchShopAccount,
|
|
||||||
handleShopWechatCallback,
|
import { request } from '../lib/api';
|
||||||
handleShopWechatLoginResult,
|
|
||||||
} from '../lib/wechat-auth';
|
import { parseRedeemTokenFromScan } from '../lib/redeem-scan';
|
||||||
import { isWechatEnv, weixinSdk } from '../lib/weixin';
|
|
||||||
import { stripOAuthParamsFromLocation } from '@dukang/weixin-sdk';
|
import {
|
||||||
import WechatScanAuthModal from '../components/WechatScanAuthModal';
|
|
||||||
|
authorizeShopWechat,
|
||||||
const PENDING_SCAN_KEY = 'shop_pending_scan';
|
|
||||||
|
checkNeedsWechatAuth,
|
||||||
function formatMoney(n: number) {
|
|
||||||
return n.toLocaleString('zh-CN', { minimumFractionDigits: 0, maximumFractionDigits: 2 });
|
fetchShopAccount,
|
||||||
}
|
|
||||||
|
} from '../lib/wechat-auth';
|
||||||
function formatScanError(e: unknown): string {
|
|
||||||
const msg = e instanceof Error ? e.message : '扫码失败,请重试';
|
import { isWechatEnv, weixinSdk } from '../lib/weixin';
|
||||||
if (/invalid signature/i.test(msg)) {
|
|
||||||
return '微信 JSSDK 签名校验失败:请确认公众号已配置 JS 接口安全域名,并刷新页面后重试';
|
import {
|
||||||
}
|
|
||||||
if (/offline verifying|权限验证中|接口未就绪/i.test(msg)) {
|
clearPendingScanAfterAuth,
|
||||||
return '微信权限校验尚未完成,请等待 1~2 秒后再次点击扫码(首次绑定微信时较常见)';
|
|
||||||
}
|
getPostAuthScanDelayMs,
|
||||||
return msg;
|
|
||||||
}
|
markPendingScanAfterAuth,
|
||||||
|
|
||||||
export default function HomePage() {
|
peekPendingScanAfterAuth,
|
||||||
const navigate = useNavigate();
|
|
||||||
const { applySession } = useStoreSession();
|
} from '../lib/shop-scan-auth';
|
||||||
const [searchParams, setSearchParams] = useSearchParams();
|
|
||||||
const [dash, setDash] = useState<Record<string, unknown> | null>(null);
|
import WechatScanAuthModal from '../components/WechatScanAuthModal';
|
||||||
const [scanMsg, setScanMsg] = useState('');
|
|
||||||
const [scanning, setScanning] = useState(false);
|
import { useStorePageView } from '../lib/usePageView';
|
||||||
const [authModalOpen, setAuthModalOpen] = useState(false);
|
|
||||||
const [authLoading, setAuthLoading] = useState(false);
|
import { trackStore } from '../lib/analytics';
|
||||||
const [authError, setAuthError] = useState('');
|
|
||||||
|
|
||||||
const loadDashboard = useCallback(() => {
|
|
||||||
return request<Record<string, unknown>>('SHOP_H5', '/shop/dashboard')
|
function formatMoney(n: number) {
|
||||||
.then((d) => {
|
|
||||||
setDash(d);
|
return n.toLocaleString('zh-CN', { minimumFractionDigits: 0, maximumFractionDigits: 2 });
|
||||||
})
|
|
||||||
.catch(() => {});
|
}
|
||||||
}, []);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
void loadDashboard();
|
function formatScanError(e: unknown, opts?: { afterAuth?: boolean }): string {
|
||||||
}, [loadDashboard]);
|
|
||||||
|
const msg = e instanceof Error ? e.message : '扫码失败,请重试';
|
||||||
useEffect(() => {
|
|
||||||
function onResume() {
|
if (/invalid signature/i.test(msg)) {
|
||||||
setScanning(false);
|
|
||||||
void loadDashboard();
|
return '微信 JSSDK 签名校验失败:请确认公众号已配置 JS 接口安全域名,并刷新页面后重试';
|
||||||
}
|
|
||||||
function onVisibility() {
|
}
|
||||||
if (document.visibilityState === 'visible') onResume();
|
|
||||||
}
|
if (isScanPermissionWarmupError(msg)) {
|
||||||
document.addEventListener('visibilitychange', onVisibility);
|
|
||||||
window.addEventListener('pageshow', onResume);
|
if (opts?.afterAuth) {
|
||||||
window.addEventListener('focus', onResume);
|
|
||||||
return () => {
|
return '微信授权已完成,扫码权限仍在准备中,请再点一次「扫码核销」';
|
||||||
document.removeEventListener('visibilitychange', onVisibility);
|
|
||||||
window.removeEventListener('pageshow', onResume);
|
}
|
||||||
window.removeEventListener('focus', onResume);
|
|
||||||
};
|
return '微信权限校验尚未完成,请等待 1~2 秒后再次点击扫码(首次绑定微信时较常见)';
|
||||||
}, [loadDashboard]);
|
|
||||||
|
}
|
||||||
async function runScan(opts?: { postAuthWarmup?: boolean }) {
|
|
||||||
if (!isWechatEnv()) {
|
return msg;
|
||||||
setScanMsg('请在微信内打开门店端进行扫码核销');
|
|
||||||
return;
|
}
|
||||||
}
|
|
||||||
setScanning(true);
|
|
||||||
setScanMsg('');
|
|
||||||
try {
|
export default function HomePage() {
|
||||||
// 授权回跳后强制重签,避免沿用带 code 的旧签名态
|
|
||||||
if (opts?.postAuthWarmup) {
|
useStorePageView('store_home_view');
|
||||||
weixinSdk.reset();
|
|
||||||
}
|
const navigate = useNavigate();
|
||||||
await weixinSdk.init();
|
|
||||||
const raw = await weixinSdk.scanQrCode(
|
const { ready, authenticated } = useStoreSession();
|
||||||
opts?.postAuthWarmup ? { postAuthWarmup: true } : undefined,
|
|
||||||
);
|
const [searchParams] = useSearchParams();
|
||||||
if (!raw) {
|
|
||||||
void loadDashboard();
|
const [dash, setDash] = useState<Record<string, unknown> | null>(null);
|
||||||
return;
|
|
||||||
}
|
const [scanMsg, setScanMsg] = useState('');
|
||||||
const token = parseRedeemTokenFromScan(raw);
|
|
||||||
if (!token) {
|
const [scanning, setScanning] = useState(false);
|
||||||
setScanMsg('无法识别核销码,请扫描用户出示的核销二维码');
|
|
||||||
return;
|
const [authModalOpen, setAuthModalOpen] = useState(false);
|
||||||
}
|
|
||||||
navigate(`/redeem?token=${encodeURIComponent(token)}`);
|
const [authLoading, setAuthLoading] = useState(false);
|
||||||
} catch (e) {
|
|
||||||
setScanMsg(formatScanError(e));
|
const [authError, setAuthError] = useState('');
|
||||||
} finally {
|
|
||||||
setScanning(false);
|
const pendingScanStartedRef = useRef(false);
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
useEffect(() => {
|
const loadDashboard = useCallback(() => {
|
||||||
if (!isWechatEnv() || !searchParams.get('code')) return;
|
|
||||||
void handleShopWechatCallback()
|
return request<Record<string, unknown>>('SHOP_H5', '/shop/dashboard')
|
||||||
.then((result) => {
|
|
||||||
if (!result) return;
|
.then((d) => {
|
||||||
const session = handleShopWechatLoginResult(result);
|
|
||||||
if (session) {
|
setDash(d);
|
||||||
applySession(session);
|
|
||||||
}
|
})
|
||||||
setAuthModalOpen(false);
|
|
||||||
setAuthError('');
|
.catch(() => {});
|
||||||
// 先清 OAuth 参数再扫,保证 JSSDK 签名 URL 与当前页一致
|
|
||||||
stripOAuthParamsFromLocation();
|
}, []);
|
||||||
setSearchParams({}, { replace: true });
|
|
||||||
const shouldScan = sessionStorage.getItem(PENDING_SCAN_KEY) === '1';
|
|
||||||
sessionStorage.removeItem(PENDING_SCAN_KEY);
|
|
||||||
if (shouldScan) {
|
useEffect(() => {
|
||||||
// OAuth 回跳后微信权限离线校验未完成;稍候再扫,失败可再点一次
|
|
||||||
window.setTimeout(() => void runScan({ postAuthWarmup: true }), 400);
|
void loadDashboard();
|
||||||
}
|
|
||||||
})
|
}, [loadDashboard]);
|
||||||
.catch((e) => {
|
|
||||||
setAuthError(e instanceof Error ? e.message : '微信授权失败');
|
|
||||||
});
|
|
||||||
}, [searchParams, applySession, setSearchParams]);
|
useEffect(() => {
|
||||||
|
|
||||||
async function handleScan() {
|
function onResume() {
|
||||||
setScanMsg('');
|
|
||||||
if (!isWechatEnv()) {
|
setScanning(false);
|
||||||
setScanMsg('请在微信内打开门店端进行扫码核销');
|
|
||||||
return;
|
void loadDashboard();
|
||||||
}
|
|
||||||
try {
|
}
|
||||||
const profile = await fetchShopAccount();
|
|
||||||
if (await checkNeedsWechatAuth(profile)) {
|
function onVisibility() {
|
||||||
setAuthModalOpen(true);
|
|
||||||
return;
|
if (document.visibilityState === 'visible') onResume();
|
||||||
}
|
|
||||||
await runScan();
|
}
|
||||||
} catch (e) {
|
|
||||||
setScanMsg(e instanceof Error ? e.message : '无法发起扫码');
|
document.addEventListener('visibilitychange', onVisibility);
|
||||||
}
|
|
||||||
}
|
window.addEventListener('pageshow', onResume);
|
||||||
|
|
||||||
async function startWechatAuth() {
|
window.addEventListener('focus', onResume);
|
||||||
setAuthLoading(true);
|
|
||||||
setAuthError('');
|
return () => {
|
||||||
try {
|
|
||||||
sessionStorage.setItem(PENDING_SCAN_KEY, '1');
|
document.removeEventListener('visibilitychange', onVisibility);
|
||||||
await authorizeShopWechat();
|
|
||||||
} catch (e) {
|
window.removeEventListener('pageshow', onResume);
|
||||||
sessionStorage.removeItem(PENDING_SCAN_KEY);
|
|
||||||
setAuthError(e instanceof Error ? e.message : '微信授权失败');
|
window.removeEventListener('focus', onResume);
|
||||||
setAuthLoading(false);
|
|
||||||
}
|
};
|
||||||
}
|
|
||||||
|
}, [loadDashboard]);
|
||||||
const store = dash?.store as Record<string, unknown> | undefined;
|
|
||||||
const recent = (dash?.recentRecords as Array<Record<string, unknown>>) || [];
|
|
||||||
const status = String(store?.status || '');
|
|
||||||
const open = status === 'OPEN';
|
const runScan = useCallback(
|
||||||
const hoursParts: string[] = [];
|
|
||||||
if (store?.openTime && store?.closeTime) hoursParts.push(`${store.openTime} - ${store.closeTime}`);
|
async (opts?: { postAuthWarmup?: boolean }) => {
|
||||||
if (store?.openTime2 && store?.closeTime2) hoursParts.push(`${store.openTime2} - ${store.closeTime2}`);
|
|
||||||
const hoursText = hoursParts.length ? hoursParts.join(',') : '10:00 - 22:00';
|
trackStore('store_redeem_scan_start');
|
||||||
const statusText =
|
|
||||||
status === 'CLOSED' ? '永久关闭' : open ? '当前正在营业中' : '当前临时闭店';
|
if (!isWechatEnv()) {
|
||||||
|
|
||||||
return (
|
setScanMsg('请在微信内打开门店端进行扫码核销');
|
||||||
<PullToRefresh onRefresh={loadDashboard} className="shop-home-page">
|
|
||||||
<header className="shop-home-header">
|
return;
|
||||||
<h1 className="app-page-title">门店管理中心</h1>
|
|
||||||
</header>
|
}
|
||||||
|
|
||||||
<div className="shop-home-content">
|
setScanning(true);
|
||||||
<section className="shop-home-hero">
|
|
||||||
<div className="shop-home-hero-store">
|
if (!opts?.postAuthWarmup) {
|
||||||
<span className="material-symbols-outlined shop-fill-icon">store</span>
|
|
||||||
<h2>{String(store?.name || '门店')}</h2>
|
setScanMsg('');
|
||||||
</div>
|
|
||||||
<div className="shop-home-stats">
|
}
|
||||||
<div className="shop-home-stat">
|
|
||||||
<p className="shop-home-stat-label">今日核销笔数</p>
|
try {
|
||||||
<p className="shop-home-stat-value">{Number(dash?.todayCount || 0)}</p>
|
|
||||||
<p className="shop-home-stat-sub">
|
if (opts?.postAuthWarmup) {
|
||||||
扫码 {Number(dash?.todayScanCount || 0)} · 手机号 {Number(dash?.todayPhoneCount || 0)}
|
|
||||||
</p>
|
weixinSdk.reset();
|
||||||
</div>
|
|
||||||
<div className="shop-home-stat">
|
}
|
||||||
<p className="shop-home-stat-label">今日到账金额</p>
|
|
||||||
<p className="shop-home-stat-value">
|
await weixinSdk.init();
|
||||||
<span style={{ fontSize: 18 }}>¥</span>
|
|
||||||
{formatMoney(Number(dash?.todayAmount || 0))}
|
const raw = await weixinSdk.scanQrCode(
|
||||||
</p>
|
|
||||||
</div>
|
opts?.postAuthWarmup ? { postAuthWarmup: true } : undefined,
|
||||||
</div>
|
|
||||||
</section>
|
);
|
||||||
|
|
||||||
<section className="shop-home-scan">
|
if (!raw) {
|
||||||
<button
|
|
||||||
type="button"
|
void loadDashboard();
|
||||||
className="shop-home-scan-btn"
|
|
||||||
disabled={scanning}
|
return;
|
||||||
onClick={() => void handleScan()}
|
|
||||||
>
|
}
|
||||||
<span className="material-symbols-outlined">qr_code_scanner</span>
|
|
||||||
</button>
|
const token = parseRedeemTokenFromScan(raw);
|
||||||
<p className="shop-home-scan-label">{scanning ? '正在打开相机…' : '扫码核销'}</p>
|
|
||||||
{scanMsg && <p className="shop-home-scan-msg" role="alert">{scanMsg}</p>}
|
if (!token) {
|
||||||
<Link to="/redeem/phone" className="shop-home-phone-link">
|
|
||||||
<span className="material-symbols-outlined">smartphone</span>
|
setScanMsg('无法识别核销码,请扫描用户出示的核销二维码');
|
||||||
手机号核销
|
|
||||||
</Link>
|
return;
|
||||||
</section>
|
|
||||||
|
}
|
||||||
<section className="shop-home-status">
|
|
||||||
<div className="shop-home-status-left">
|
navigate(`/redeem?token=${encodeURIComponent(token)}`);
|
||||||
<div className={`shop-home-status-icon${open ? '' : ' closed'}`}>
|
|
||||||
<span className="material-symbols-outlined shop-fill-icon">schedule</span>
|
} catch (e) {
|
||||||
</div>
|
|
||||||
<div>
|
setScanMsg(formatScanError(e, { afterAuth: opts?.postAuthWarmup }));
|
||||||
<p className="shop-home-status-title">营业状态</p>
|
|
||||||
<p className="shop-home-status-sub">{statusText}</p>
|
} finally {
|
||||||
<p className="shop-home-status-sub">营业时间: {hoursText}</p>
|
|
||||||
</div>
|
setScanning(false);
|
||||||
</div>
|
|
||||||
<label className="shop-home-switch" onClick={() => navigate('/status')}>
|
}
|
||||||
<input type="checkbox" checked={open && status !== 'CLOSED'} readOnly tabIndex={-1} />
|
|
||||||
<span className="shop-home-switch-track" />
|
},
|
||||||
</label>
|
|
||||||
</section>
|
[loadDashboard, navigate],
|
||||||
|
|
||||||
<section>
|
);
|
||||||
<div className="shop-home-records-head">
|
|
||||||
<h3 className="shop-home-records-title">核销记录</h3>
|
|
||||||
<Link to="/records" className="shop-home-records-link">
|
|
||||||
查看全部
|
// OAuth 由 StoreSessionContext 单例处理;此处仅在授权完成后续扫
|
||||||
<span className="material-symbols-outlined" style={{ fontSize: 16 }}>chevron_right</span>
|
|
||||||
</Link>
|
useEffect(() => {
|
||||||
</div>
|
|
||||||
<div className="shop-home-record-list">
|
if (!ready || !authenticated || !isWechatEnv()) return;
|
||||||
{recent.length === 0 && (
|
|
||||||
<p className="shop-home-status-sub" style={{ textAlign: 'center', padding: '16px 0' }}>暂无核销记录</p>
|
if (searchParams.get('code')) return;
|
||||||
)}
|
|
||||||
{recent.map((r) => (
|
if (!peekPendingScanAfterAuth() || pendingScanStartedRef.current) return;
|
||||||
<div key={String(r.id)} className="shop-home-record-item">
|
|
||||||
<div>
|
|
||||||
<p className="shop-home-record-time">核销时间</p>
|
|
||||||
<p className="shop-home-record-value">
|
pendingScanStartedRef.current = true;
|
||||||
{new Date(String(r.createdAt)).toLocaleString('zh-CN')}
|
|
||||||
</p>
|
clearPendingScanAfterAuth();
|
||||||
</div>
|
|
||||||
<p className="shop-home-record-amount">¥{formatMoney(Number(r.amount))}</p>
|
setAuthModalOpen(false);
|
||||||
</div>
|
|
||||||
))}
|
setAuthLoading(false);
|
||||||
</div>
|
|
||||||
</section>
|
setAuthError('');
|
||||||
</div>
|
|
||||||
|
setScanMsg('微信授权成功,正在准备扫码…');
|
||||||
<WechatScanAuthModal
|
|
||||||
open={authModalOpen}
|
|
||||||
loading={authLoading}
|
|
||||||
error={authError}
|
const timer = window.setTimeout(() => {
|
||||||
onAuthorize={() => void startWechatAuth()}
|
|
||||||
onCancel={() => {
|
void runScan({ postAuthWarmup: true });
|
||||||
setAuthModalOpen(false);
|
|
||||||
setAuthError('');
|
}, getPostAuthScanDelayMs());
|
||||||
sessionStorage.removeItem(PENDING_SCAN_KEY);
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</PullToRefresh>
|
return () => window.clearTimeout(timer);
|
||||||
);
|
|
||||||
}
|
}, [ready, authenticated, searchParams, runScan]);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
async function handleScan() {
|
||||||
|
|
||||||
|
setScanMsg('');
|
||||||
|
|
||||||
|
if (!isWechatEnv()) {
|
||||||
|
|
||||||
|
setScanMsg('请在微信内打开门店端进行扫码核销');
|
||||||
|
|
||||||
|
return;
|
||||||
@@ -18,7 +18,7 @@ import {
|
|||||||
consumeShopWechatLoginHint,
|
consumeShopWechatLoginHint,
|
||||||
fetchClientConfig,
|
fetchClientConfig,
|
||||||
formatShopWechatError,
|
formatShopWechatError,
|
||||||
handleShopWechatCallback,
|
handleShopWechatCallbackOnce,
|
||||||
handleShopWechatLoginResult,
|
handleShopWechatLoginResult,
|
||||||
loginShopWithWechat,
|
loginShopWithWechat,
|
||||||
} from '../lib/wechat-auth';
|
} from '../lib/wechat-auth';
|
||||||
@@ -88,7 +88,7 @@ export default function LoginPage() {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!isWechatEnv() || !wxAuthorize || !params.get('code')) return;
|
if (!isWechatEnv() || !wxAuthorize || !params.get('code')) return;
|
||||||
void handleShopWechatCallback()
|
void handleShopWechatCallbackOnce()
|
||||||
.then((result) => {
|
.then((result) => {
|
||||||
if (!result) return;
|
if (!result) return;
|
||||||
const session = handleShopWechatLoginResult(result);
|
const session = handleShopWechatLoginResult(result);
|
||||||
@@ -140,12 +140,22 @@ export default function LoginPage() {
|
|||||||
|
|
||||||
async function login() {
|
async function login() {
|
||||||
if (!ensureAgreed()) return;
|
if (!ensureAgreed()) return;
|
||||||
|
const trimmedPhone = phone.trim();
|
||||||
|
const trimmedCode = code.trim();
|
||||||
|
if (!trimmedPhone) {
|
||||||
|
setMsg('phone should not be empty');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!trimmedCode) {
|
||||||
|
setMsg('code should not be empty');
|
||||||
|
return;
|
||||||
|
}
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
setMsg('');
|
setMsg('');
|
||||||
try {
|
try {
|
||||||
const data = await request<ShopSessionPayload>('SHOP_H5', '/shop/auth/login/sms', {
|
const data = await request<ShopSessionPayload>('SHOP_H5', '/shop/auth/login/sms', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: JSON.stringify({ phone, code }),
|
body: JSON.stringify({ phone: trimmedPhone, code: trimmedCode }),
|
||||||
});
|
});
|
||||||
saveRememberedSession(data);
|
saveRememberedSession(data);
|
||||||
applySession(data);
|
applySession(data);
|
||||||
|
|||||||
@@ -9,12 +9,14 @@ import {
|
|||||||
authorizeShopWechat,
|
authorizeShopWechat,
|
||||||
fetchClientConfig,
|
fetchClientConfig,
|
||||||
fetchShopAccount,
|
fetchShopAccount,
|
||||||
handleShopWechatCallback,
|
handleShopWechatCallbackOnce,
|
||||||
handleShopWechatLoginResult,
|
handleShopWechatLoginResult,
|
||||||
} from '../lib/wechat-auth';
|
} from '../lib/wechat-auth';
|
||||||
import { isWechatEnv } from '../lib/weixin';
|
import { isWechatEnv } from '../lib/weixin';
|
||||||
|
import { useStorePageView } from '../lib/usePageView';
|
||||||
|
|
||||||
export default function MinePage() {
|
export default function MinePage() {
|
||||||
|
useStorePageView('store_mine_view');
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const [searchParams, setSearchParams] = useSearchParams();
|
const [searchParams, setSearchParams] = useSearchParams();
|
||||||
const { resetSession, store: sessionStore, applySession } = useStoreSession();
|
const { resetSession, store: sessionStore, applySession } = useStoreSession();
|
||||||
@@ -43,7 +45,7 @@ export default function MinePage() {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!isWechatEnv() || !wxAuthorize || !searchParams.get('code')) return;
|
if (!isWechatEnv() || !wxAuthorize || !searchParams.get('code')) return;
|
||||||
void handleShopWechatCallback()
|
void handleShopWechatCallbackOnce()
|
||||||
.then((result) => {
|
.then((result) => {
|
||||||
if (!result) return;
|
if (!result) return;
|
||||||
const session = handleShopWechatLoginResult(result);
|
const session = handleShopWechatLoginResult(result);
|
||||||
@@ -145,6 +147,12 @@ export default function MinePage() {
|
|||||||
<span className="material-symbols-outlined" style={{ fontSize: 20 }}>account_balance_wallet</span>
|
<span className="material-symbols-outlined" style={{ fontSize: 20 }}>account_balance_wallet</span>
|
||||||
结算提现
|
结算提现
|
||||||
</button>
|
</button>
|
||||||
|
{profile?.isPrimary ? (
|
||||||
|
<button type="button" className="shop-mine-action" onClick={() => navigate('/packages')}>
|
||||||
|
<span className="material-symbols-outlined" style={{ fontSize: 20 }}>restaurant_menu</span>
|
||||||
|
门店套餐
|
||||||
|
</button>
|
||||||
|
) : null}
|
||||||
{profile?.isPrimary ? (
|
{profile?.isPrimary ? (
|
||||||
<button type="button" className="shop-mine-action" onClick={() => navigate('/staff')}>
|
<button type="button" className="shop-mine-action" onClick={() => navigate('/staff')}>
|
||||||
<span className="material-symbols-outlined" style={{ fontSize: 20 }}>group</span>
|
<span className="material-symbols-outlined" style={{ fontSize: 20 }}>group</span>
|
||||||
|
|||||||
@@ -0,0 +1,143 @@
|
|||||||
|
import { useEffect, useState } from 'react';
|
||||||
|
import { useNavigate } from 'react-router-dom';
|
||||||
|
import type { StorePackagesResponse } from '@dukang/shared-types';
|
||||||
|
import PullToRefresh from '@dukang/shared-ui/PullToRefresh';
|
||||||
|
import ShopPackagesForm from '../components/ShopPackagesForm';
|
||||||
|
import { request } from '../lib/api';
|
||||||
|
import { useStorePageView } from '../lib/usePageView';
|
||||||
|
import {
|
||||||
|
emptyPackage,
|
||||||
|
normalizePackageFormItems,
|
||||||
|
validatePackageFormItems,
|
||||||
|
type PackageFormItem,
|
||||||
|
} from '../lib/storePackages';
|
||||||
|
|
||||||
|
export default function PackagesPage() {
|
||||||
|
useStorePageView('store_packages_view');
|
||||||
|
const navigate = useNavigate();
|
||||||
|
const [items, setItems] = useState<PackageFormItem[]>([emptyPackage()]);
|
||||||
|
const [pending, setPending] = useState<StorePackagesResponse['pendingRequest']>(null);
|
||||||
|
const [loading, setLoading] = useState(true);
|
||||||
|
const [submitting, setSubmitting] = useState(false);
|
||||||
|
const [msg, setMsg] = useState('');
|
||||||
|
|
||||||
|
async function load() {
|
||||||
|
setLoading(true);
|
||||||
|
try {
|
||||||
|
const data = await request<StorePackagesResponse>('SHOP_H5', '/shop/store/packages');
|
||||||
|
const base = data.pendingRequest?.packages?.length
|
||||||
|
? data.pendingRequest.packages
|
||||||
|
: data.live?.length
|
||||||
|
? data.live
|
||||||
|
: [emptyPackage()];
|
||||||
|
setItems(base.map((p, i) => ({ ...p, price: String(p.price), sortOrder: i })));
|
||||||
|
setPending(data.pendingRequest ?? null);
|
||||||
|
setMsg('');
|
||||||
|
} catch (e) {
|
||||||
|
setMsg(e instanceof Error ? e.message : '加载失败');
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
void load();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
async function submitAudit() {
|
||||||
|
const validationMsg = validatePackageFormItems(items);
|
||||||
|
if (validationMsg) {
|
||||||
|
setMsg(validationMsg);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (pending?.status === 'PENDING') {
|
||||||
|
setMsg('已有套餐变更审核中,请等待总部处理');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setSubmitting(true);
|
||||||
|
setMsg('');
|
||||||
|
try {
|
||||||
|
const packages = normalizePackageFormItems(items).map((p) => ({
|
||||||
|
...p,
|
||||||
|
price: Number(p.price).toFixed(2),
|
||||||
|
}));
|
||||||
|
await request('SHOP_H5', '/shop/store/packages', {
|
||||||
|
method: 'PUT',
|
||||||
|
body: JSON.stringify({ packages }),
|
||||||
|
});
|
||||||
|
setMsg('已提交审核,请等待总部处理');
|
||||||
|
await load();
|
||||||
|
} catch (e) {
|
||||||
|
setMsg(e instanceof Error ? e.message : '提交失败');
|
||||||
|
} finally {
|
||||||
|
setSubmitting(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const disabled = pending?.status === 'PENDING' || submitting;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<PullToRefresh onRefresh={load} className="shop-records-page shop-packages-page">
|
||||||
|
<header className="shop-records-header" style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="shop-withdraw-back"
|
||||||
|
onClick={() => navigate('/mine')}
|
||||||
|
aria-label="返回"
|
||||||
|
>
|
||||||
|
<span className="material-symbols-outlined" style={{ fontSize: 22 }}>
|
||||||
|
arrow_back
|
||||||
|
</span>
|
||||||
|
</button>
|
||||||
|
<h1 className="app-page-title" style={{ margin: 0 }}>
|
||||||
|
门店套餐
|
||||||
|
</h1>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<div className="shop-records-main">
|
||||||
|
{loading ? <p className="shop-records-empty">加载中…</p> : null}
|
||||||
|
|
||||||
|
{!loading && pending?.status === 'PENDING' ? (
|
||||||
|
<section className="shop-packages-notice">
|
||||||
|
<span className="material-symbols-outlined shop-fill-icon" style={{ fontSize: 18 }}>
|
||||||
|
hourglass_top
|
||||||
|
</span>
|
||||||
|
<p>套餐变更审核中,用户端仍展示上一版生效套餐。</p>
|
||||||
|
</section>
|
||||||
|
) : null}
|
||||||
|
|
||||||
|
{!loading && pending?.status === 'REJECTED' && pending.rejectReason ? (
|
||||||
|
<section className="shop-packages-notice shop-packages-notice--warn">
|
||||||
|
<span className="material-symbols-outlined shop-fill-icon" style={{ fontSize: 18 }}>
|
||||||
|
error
|
||||||
|
</span>
|
||||||
|
<p>上次驳回:{pending.rejectReason}</p>
|
||||||
|
</section>
|
||||||
|
) : null}
|
||||||
|
|
||||||
|
{!loading ? (
|
||||||
|
<>
|
||||||
|
<p className="shop-packages-intro">
|
||||||
|
维护门店可核销套餐信息,提交后由总部审核通过后在用户端展示。
|
||||||
|
</p>
|
||||||
|
<ShopPackagesForm items={items} onChange={setItems} disabled={disabled} />
|
||||||
|
</>
|
||||||
|
) : null}
|
||||||
|
|
||||||
|
{msg ? <p className="shop-withdraw-msg">{msg}</p> : null}
|
||||||
|
|
||||||
|
{!loading ? (
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="shop-withdraw-btn"
|
||||||
|
style={{ marginTop: 16 }}
|
||||||
|
disabled={disabled}
|
||||||
|
onClick={() => void submitAudit()}
|
||||||
|
>
|
||||||
|
{submitting ? '提交中…' : '提交审核'}
|
||||||
|
</button>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
</PullToRefresh>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -2,12 +2,14 @@ import { useEffect, useState } from 'react';
|
|||||||
import { useNavigate } from 'react-router-dom';
|
import { useNavigate } from 'react-router-dom';
|
||||||
import type { RedeemPhoneDirectPrepareResult } from '@dukang/shared-types';
|
import type { RedeemPhoneDirectPrepareResult } from '@dukang/shared-types';
|
||||||
import { request } from '../lib/api';
|
import { request } from '../lib/api';
|
||||||
|
import { useStorePageView } from '../lib/usePageView';
|
||||||
|
|
||||||
function formatAmount(n: number) {
|
function formatAmount(n: number) {
|
||||||
return n.toLocaleString('zh-CN', { minimumFractionDigits: 2, maximumFractionDigits: 2 });
|
return n.toLocaleString('zh-CN', { minimumFractionDigits: 2, maximumFractionDigits: 2 });
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function PhoneRedeemPage() {
|
export default function PhoneRedeemPage() {
|
||||||
|
useStorePageView('store_phone_redeem_view');
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const [phone, setPhone] = useState('');
|
const [phone, setPhone] = useState('');
|
||||||
const [amount, setAmount] = useState('');
|
const [amount, setAmount] = useState('');
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { useCallback, useEffect, useMemo, useState } from 'react';
|
|||||||
import PullToRefresh from '@dukang/shared-ui/PullToRefresh';
|
import PullToRefresh from '@dukang/shared-ui/PullToRefresh';
|
||||||
import { REDEEM_CHANNEL_LABELS, type RedeemChannel, type RedeemStatsDto } from '@dukang/shared-types';
|
import { REDEEM_CHANNEL_LABELS, type RedeemChannel, type RedeemStatsDto } from '@dukang/shared-types';
|
||||||
import { request } from '../lib/api';
|
import { request } from '../lib/api';
|
||||||
|
import { useStorePageView } from '../lib/usePageView';
|
||||||
|
|
||||||
type RangeKey = 'today' | '7d' | '30d';
|
type RangeKey = 'today' | '7d' | '30d';
|
||||||
type StatusFilter = 'all' | 'pending' | 'paid';
|
type StatusFilter = 'all' | 'pending' | 'paid';
|
||||||
@@ -30,6 +31,7 @@ function channelLabel(channel: unknown): string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default function RecordsPage() {
|
export default function RecordsPage() {
|
||||||
|
useStorePageView('store_records_view');
|
||||||
const [records, setRecords] = useState<Array<Record<string, unknown>>>([]);
|
const [records, setRecords] = useState<Array<Record<string, unknown>>>([]);
|
||||||
const [range, setRange] = useState<RangeKey>('today');
|
const [range, setRange] = useState<RangeKey>('today');
|
||||||
const [statusFilter, setStatusFilter] = useState<StatusFilter>('all');
|
const [statusFilter, setStatusFilter] = useState<StatusFilter>('all');
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { useNavigate, useSearchParams } from 'react-router-dom';
|
|||||||
import WeakNetFallbackPanel from '../components/WeakNetFallbackPanel';
|
import WeakNetFallbackPanel from '../components/WeakNetFallbackPanel';
|
||||||
import { request } from '../lib/api';
|
import { request } from '../lib/api';
|
||||||
import { reportRedeemFailure } from '../lib/redeem-failure';
|
import { reportRedeemFailure } from '../lib/redeem-failure';
|
||||||
|
import { useStorePageView } from '../lib/usePageView';
|
||||||
|
|
||||||
function formatAmount(n: number) {
|
function formatAmount(n: number) {
|
||||||
return n.toLocaleString('zh-CN', { minimumFractionDigits: 2, maximumFractionDigits: 2 });
|
return n.toLocaleString('zh-CN', { minimumFractionDigits: 2, maximumFractionDigits: 2 });
|
||||||
@@ -17,6 +18,7 @@ type Preview = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export default function RedeemConfirmPage() {
|
export default function RedeemConfirmPage() {
|
||||||
|
useStorePageView('store_redeem_confirm_view');
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const [searchParams] = useSearchParams();
|
const [searchParams] = useSearchParams();
|
||||||
const [token, setToken] = useState('');
|
const [token, setToken] = useState('');
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { STORE_STAFF_ROLE_LABELS, type StoreStaffRole } from '@dukang/shared-typ
|
|||||||
import PullToRefresh from '@dukang/shared-ui/PullToRefresh';
|
import PullToRefresh from '@dukang/shared-ui/PullToRefresh';
|
||||||
import { useStoreSession } from '../contexts/StoreSessionContext';
|
import { useStoreSession } from '../contexts/StoreSessionContext';
|
||||||
import { getStoreProfile, request } from '../lib/api';
|
import { getStoreProfile, request } from '../lib/api';
|
||||||
|
import { useStorePageView } from '../lib/usePageView';
|
||||||
|
|
||||||
type StaffItem = {
|
type StaffItem = {
|
||||||
id: string;
|
id: string;
|
||||||
@@ -23,6 +24,7 @@ function maskPhone(phone: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default function StaffPage() {
|
export default function StaffPage() {
|
||||||
|
useStorePageView('store_staff_view');
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const { store } = useStoreSession();
|
const { store } = useStoreSession();
|
||||||
const profile = store ?? getStoreProfile();
|
const profile = store ?? getStoreProfile();
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import {
|
|||||||
} from '@dukang/shared-types';
|
} from '@dukang/shared-types';
|
||||||
import PullToRefresh from '@dukang/shared-ui/PullToRefresh';
|
import PullToRefresh from '@dukang/shared-ui/PullToRefresh';
|
||||||
import { request } from '../lib/api';
|
import { request } from '../lib/api';
|
||||||
|
import { useStorePageView } from '../lib/usePageView';
|
||||||
|
|
||||||
type StatusFilter = 'all' | StoreWithdrawStatus;
|
type StatusFilter = 'all' | StoreWithdrawStatus;
|
||||||
|
|
||||||
@@ -16,6 +17,7 @@ function formatMoney(n: number) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default function WithdrawPage() {
|
export default function WithdrawPage() {
|
||||||
|
useStorePageView('store_withdraw_view');
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const [summary, setSummary] = useState<StoreWithdrawSummaryDto | null>(null);
|
const [summary, setSummary] = useState<StoreWithdrawSummaryDto | null>(null);
|
||||||
const [items, setItems] = useState<StoreWithdrawRequestDto[]>([]);
|
const [items, setItems] = useState<StoreWithdrawRequestDto[]>([]);
|
||||||
@@ -78,7 +80,6 @@ export default function WithdrawPage() {
|
|||||||
const canApply =
|
const canApply =
|
||||||
!!summary?.isPrimary &&
|
!!summary?.isPrimary &&
|
||||||
summary.availableAmount > 0 &&
|
summary.availableAmount > 0 &&
|
||||||
!summary.hasPendingRequest &&
|
|
||||||
summary.hasBankAccount &&
|
summary.hasBankAccount &&
|
||||||
!submitting;
|
!submitting;
|
||||||
|
|
||||||
@@ -124,7 +125,6 @@ export default function WithdrawPage() {
|
|||||||
info
|
info
|
||||||
</span>
|
</span>
|
||||||
单日上限 ¥{formatMoney(summary?.dailyLimit ?? 5000)}
|
单日上限 ¥{formatMoney(summary?.dailyLimit ?? 5000)}
|
||||||
{summary?.hasPendingRequest ? ' · 已有待审核申请' : ''}
|
|
||||||
{!summary?.hasBankAccount ? ' · 请先完善收款账户' : ''}
|
{!summary?.hasBankAccount ? ' · 请先完善收款账户' : ''}
|
||||||
</p>
|
</p>
|
||||||
</section>
|
</section>
|
||||||
|
|||||||
@@ -1920,6 +1920,165 @@
|
|||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ─── 门店套餐 ─── */
|
||||||
|
.shop-packages-page .shop-records-main {
|
||||||
|
padding-bottom: 24px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.shop-packages-intro {
|
||||||
|
margin: 0 0 12px;
|
||||||
|
font-size: 13px;
|
||||||
|
line-height: 1.5;
|
||||||
|
color: var(--color-subtle-gray);
|
||||||
|
}
|
||||||
|
|
||||||
|
.shop-packages-notice {
|
||||||
|
display: flex;
|
||||||
|
align-items: flex-start;
|
||||||
|
gap: 8px;
|
||||||
|
margin-bottom: 12px;
|
||||||
|
padding: 12px 14px;
|
||||||
|
border-radius: var(--radius-md);
|
||||||
|
background: rgba(46, 125, 50, 0.08);
|
||||||
|
border: 1px solid rgba(46, 125, 50, 0.15);
|
||||||
|
font-size: 13px;
|
||||||
|
line-height: 1.5;
|
||||||
|
color: var(--color-on-surface);
|
||||||
|
}
|
||||||
|
|
||||||
|
.shop-packages-notice--warn {
|
||||||
|
background: rgba(180, 35, 24, 0.06);
|
||||||
|
border-color: rgba(180, 35, 24, 0.12);
|
||||||
|
}
|
||||||
|
|
||||||
|
.shop-packages-notice p {
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.shop-packages-form {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.shop-packages-card {
|
||||||
|
background: var(--color-card);
|
||||||
|
border-radius: var(--radius-md);
|
||||||
|
padding: 16px;
|
||||||
|
box-shadow: var(--shadow-card);
|
||||||
|
border: 1px solid rgba(0, 0, 0, 0.04);
|
||||||
|
}
|
||||||
|
|
||||||
|
.shop-packages-card-head {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
margin-bottom: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.shop-packages-card--collapsed .shop-packages-card-head {
|
||||||
|
margin-bottom: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.shop-packages-toggle {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 4px;
|
||||||
|
border: none;
|
||||||
|
background: transparent;
|
||||||
|
padding: 0;
|
||||||
|
color: inherit;
|
||||||
|
cursor: pointer;
|
||||||
|
text-align: left;
|
||||||
|
flex: 1;
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.shop-packages-toggle .material-symbols-outlined {
|
||||||
|
font-size: 20px;
|
||||||
|
color: var(--color-on-surface-variant, #666);
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.shop-packages-card-title {
|
||||||
|
margin: 0;
|
||||||
|
font-size: 16px;
|
||||||
|
font-weight: 700;
|
||||||
|
color: var(--color-on-surface);
|
||||||
|
}
|
||||||
|
|
||||||
|
.shop-packages-remove {
|
||||||
|
border: none;
|
||||||
|
background: transparent;
|
||||||
|
color: var(--color-heritage-red);
|
||||||
|
font-size: 13px;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.shop-packages-field {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 6px;
|
||||||
|
margin-bottom: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.shop-packages-field:last-child {
|
||||||
|
margin-bottom: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.shop-packages-label {
|
||||||
|
font-size: 12px;
|
||||||
|
color: var(--color-subtle-gray);
|
||||||
|
}
|
||||||
|
|
||||||
|
.shop-packages-input,
|
||||||
|
.shop-packages-textarea {
|
||||||
|
width: 100%;
|
||||||
|
box-sizing: border-box;
|
||||||
|
padding: 12px;
|
||||||
|
border: 1px solid rgba(0, 0, 0, 0.08);
|
||||||
|
border-radius: var(--radius-sm);
|
||||||
|
background: var(--color-surface-container-low, #fafafa);
|
||||||
|
font-size: 14px;
|
||||||
|
color: var(--color-on-surface);
|
||||||
|
}
|
||||||
|
|
||||||
|
.shop-packages-textarea {
|
||||||
|
resize: vertical;
|
||||||
|
min-height: 72px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.shop-packages-input:focus,
|
||||||
|
.shop-packages-textarea:focus {
|
||||||
|
outline: none;
|
||||||
|
border-color: var(--color-heritage-red);
|
||||||
|
box-shadow: 0 0 0 1px rgba(166, 29, 36, 0.12);
|
||||||
|
}
|
||||||
|
|
||||||
|
.shop-packages-input:disabled,
|
||||||
|
.shop-packages-textarea:disabled {
|
||||||
|
opacity: 0.6;
|
||||||
|
}
|
||||||
|
|
||||||
|
.shop-packages-add {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
gap: 6px;
|
||||||
|
width: 100%;
|
||||||
|
min-height: 48px;
|
||||||
|
border: 1px dashed rgba(166, 29, 36, 0.35);
|
||||||
|
border-radius: var(--radius-md);
|
||||||
|
background: rgba(166, 29, 36, 0.04);
|
||||||
|
color: var(--color-heritage-red);
|
||||||
|
font-size: 14px;
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
.shop-packages-add .material-symbols-outlined {
|
||||||
|
font-size: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
.shop-record-amounts {
|
.shop-record-amounts {
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: 1fr 1fr;
|
grid-template-columns: 1fr 1fr;
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
"lint": "echo ok"
|
"lint": "echo ok"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@dukang/client-logging": "workspace:*",
|
||||||
"@dukang/shared-types": "workspace:*",
|
"@dukang/shared-types": "workspace:*",
|
||||||
"@dukang/shared-ui": "workspace:*",
|
"@dukang/shared-ui": "workspace:*",
|
||||||
"@dukang/weixin-sdk": "workspace:*",
|
"@dukang/weixin-sdk": "workspace:*",
|
||||||
|
|||||||
@@ -1,16 +1,21 @@
|
|||||||
|
import { createUserTracker, getSessionId } from '@dukang/client-logging';
|
||||||
import { apiBase } from './api';
|
import { apiBase } from './api';
|
||||||
|
|
||||||
export function track(eventName: string, params?: Record<string, unknown>) {
|
const tracker = createUserTracker({
|
||||||
const token = localStorage.getItem('accessToken');
|
apiBase,
|
||||||
if (!token) return;
|
clientApp: 'USER_H5',
|
||||||
|
});
|
||||||
|
|
||||||
void fetch(`${apiBase}/analytics/events`, {
|
export { getSessionId };
|
||||||
method: 'POST',
|
|
||||||
headers: {
|
export function track(eventName: string, params?: Record<string, unknown>) {
|
||||||
'Content-Type': 'application/json',
|
tracker.track(eventName, params);
|
||||||
Authorization: `Bearer ${token}`,
|
}
|
||||||
'X-Client-App': 'USER_H5',
|
|
||||||
},
|
export function trackPageView(eventName: string, params?: Record<string, unknown>) {
|
||||||
body: JSON.stringify({ events: [{ eventName, params }] }),
|
tracker.trackPageView(eventName, params);
|
||||||
}).catch(() => {});
|
}
|
||||||
|
|
||||||
|
export function initUserAnalytics() {
|
||||||
|
tracker.trackSessionStart();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import { reportApiError } from '@dukang/client-logging';
|
||||||
|
|
||||||
export const BRAND = {
|
export const BRAND = {
|
||||||
red: '#A02D30',
|
red: '#A02D30',
|
||||||
yellow: '#FFC107',
|
yellow: '#FFC107',
|
||||||
@@ -83,6 +85,12 @@ async function rawRequest<T>(
|
|||||||
if (json.code !== 0) {
|
if (json.code !== 0) {
|
||||||
const err = new Error(json.message || '请求失败') as Error & { status?: number };
|
const err = new Error(json.message || '请求失败') as Error & { status?: number };
|
||||||
err.status = json.code;
|
err.status = json.code;
|
||||||
|
if (json.code === 400) {
|
||||||
|
reportApiError(
|
||||||
|
{ apiBase, clientApp: CLIENT_APP, getToken: () => localStorage.getItem(ACCESS_TOKEN) },
|
||||||
|
{ message: json.message || '请求失败', status: 400, url: path, category: 'validation_error' },
|
||||||
|
);
|
||||||
|
}
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
return json.data as T;
|
return json.data as T;
|
||||||
|
|||||||
@@ -1,4 +1,9 @@
|
|||||||
import { apiBase } from './api';
|
import { apiBase } 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';
|
||||||
|
|
||||||
@@ -15,8 +20,15 @@ export async function uploadFileToOss(
|
|||||||
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');
|
||||||
|
let prepared = file;
|
||||||
|
if (mediaType === 'IMAGE') {
|
||||||
|
prepared = await compressImageFileIfNeeded(file);
|
||||||
|
if (prepared.size > DEFAULT_OSS_MAX_UPLOAD_BYTES) {
|
||||||
|
throw new Error(`图片压缩后仍超过 ${formatOssMaxSizeMb()}MB,请换一张较小的图片`);
|
||||||
|
}
|
||||||
|
}
|
||||||
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);
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
import { useEffect, useRef } from 'react';
|
||||||
|
import { trackPageView } from './analytics';
|
||||||
|
|
||||||
|
export function usePageView(eventName: string, params?: Record<string, unknown>) {
|
||||||
|
const fired = useRef(false);
|
||||||
|
useEffect(() => {
|
||||||
|
if (fired.current) return;
|
||||||
|
fired.current = true;
|
||||||
|
trackPageView(eventName, params);
|
||||||
|
}, [eventName, params]);
|
||||||
|
}
|
||||||
@@ -2,10 +2,16 @@ import React from 'react';
|
|||||||
import ReactDOM from 'react-dom/client';
|
import ReactDOM from 'react-dom/client';
|
||||||
import { BrowserRouter } from 'react-router-dom';
|
import { BrowserRouter } from 'react-router-dom';
|
||||||
import { getRouterBasename } from '@dukang/weixin-sdk';
|
import { getRouterBasename } from '@dukang/weixin-sdk';
|
||||||
|
import { installClientErrorReporting } from '@dukang/client-logging';
|
||||||
import App from './App';
|
import App from './App';
|
||||||
|
import { initUserAnalytics } from './lib/analytics';
|
||||||
|
import { apiBase } from './lib/api';
|
||||||
import './styles.css';
|
import './styles.css';
|
||||||
import './styles/legal.css';
|
import './styles/legal.css';
|
||||||
|
|
||||||
|
installClientErrorReporting({ apiBase, clientApp: 'USER_H5' });
|
||||||
|
initUserAnalytics();
|
||||||
|
|
||||||
ReactDOM.createRoot(document.getElementById('root')!).render(
|
ReactDOM.createRoot(document.getElementById('root')!).render(
|
||||||
<React.StrictMode>
|
<React.StrictMode>
|
||||||
<BrowserRouter basename={getRouterBasename()}>
|
<BrowserRouter basename={getRouterBasename()}>
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import { request } from '../lib/api';
|
|||||||
import { buildAddressListUrl, readCheckoutContext } from '../lib/navigation';
|
import { buildAddressListUrl, readCheckoutContext } from '../lib/navigation';
|
||||||
import { DEFAULT_REGION, formatRegion } from '../lib/region-data';
|
import { DEFAULT_REGION, formatRegion } from '../lib/region-data';
|
||||||
import { normalizePhoneInput, validateMobilePhone } from '../lib/phone';
|
import { normalizePhoneInput, validateMobilePhone } from '../lib/phone';
|
||||||
|
import { usePageView } from '../lib/usePageView';
|
||||||
|
|
||||||
type AddressForm = {
|
type AddressForm = {
|
||||||
receiverName: string;
|
receiverName: string;
|
||||||
@@ -21,6 +22,7 @@ export default function AddressEditPage() {
|
|||||||
const { id } = useParams();
|
const { id } = useParams();
|
||||||
const [params] = useSearchParams();
|
const [params] = useSearchParams();
|
||||||
const isEdit = Boolean(id);
|
const isEdit = Boolean(id);
|
||||||
|
usePageView('address_edit', { mode: isEdit ? 'edit' : 'create' });
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const [pickerOpen, setPickerOpen] = useState(false);
|
const [pickerOpen, setPickerOpen] = useState(false);
|
||||||
const [saving, setSaving] = useState(false);
|
const [saving, setSaving] = useState(false);
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import SubPageHeader from '../components/SubPageHeader';
|
|||||||
import { request } from '../lib/api';
|
import { request } from '../lib/api';
|
||||||
import { useUserSession } from '../contexts/UserSessionContext';
|
import { useUserSession } from '../contexts/UserSessionContext';
|
||||||
import { buildAddressEditUrl, buildAddressListUrl, buildOrderConfirmUrl, hasCheckoutContext, readCheckoutContext } from '../lib/navigation';
|
import { buildAddressEditUrl, buildAddressListUrl, buildOrderConfirmUrl, hasCheckoutContext, readCheckoutContext } from '../lib/navigation';
|
||||||
|
import { usePageView } from '../lib/usePageView';
|
||||||
|
|
||||||
type Address = {
|
type Address = {
|
||||||
id: string;
|
id: string;
|
||||||
@@ -25,6 +26,7 @@ function formatAddress(a: Address) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default function AddressListPage() {
|
export default function AddressListPage() {
|
||||||
|
usePageView('address_list_view');
|
||||||
const { profile } = useUserSession();
|
const { profile } = useUserSession();
|
||||||
const [list, setList] = useState<Address[]>([]);
|
const [list, setList] = useState<Address[]>([]);
|
||||||
const [pendingAddress, setPendingAddress] = useState<Address | null>(null);
|
const [pendingAddress, setPendingAddress] = useState<Address | null>(null);
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { useNavigate } from 'react-router-dom';
|
|||||||
import { TICKET_TYPE_LABELS, type TicketTypeDto } from '@dukang/shared-types';
|
import { TICKET_TYPE_LABELS, type TicketTypeDto } from '@dukang/shared-types';
|
||||||
import SubPageHeader from '../components/SubPageHeader';
|
import SubPageHeader from '../components/SubPageHeader';
|
||||||
import { request } from '../lib/api';
|
import { request } from '../lib/api';
|
||||||
|
import { usePageView } from '../lib/usePageView';
|
||||||
|
|
||||||
type TicketRow = {
|
type TicketRow = {
|
||||||
id: string;
|
id: string;
|
||||||
@@ -23,6 +24,7 @@ const STATUS_LABEL: Record<string, string> = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export default function AfterSaleListPage() {
|
export default function AfterSaleListPage() {
|
||||||
|
usePageView('after_sale_list_view');
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const [items, setItems] = useState<TicketRow[]>([]);
|
const [items, setItems] = useState<TicketRow[]>([]);
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ import {
|
|||||||
import SubPageHeader from '../components/SubPageHeader';
|
import SubPageHeader from '../components/SubPageHeader';
|
||||||
import { request } from '../lib/api';
|
import { request } from '../lib/api';
|
||||||
import { uploadFileToOss } from '../lib/upload';
|
import { uploadFileToOss } from '../lib/upload';
|
||||||
|
import { usePageView } from '../lib/usePageView';
|
||||||
|
import { track } from '../lib/analytics';
|
||||||
|
|
||||||
type OrderRow = {
|
type OrderRow = {
|
||||||
id: string;
|
id: string;
|
||||||
@@ -21,6 +23,7 @@ type OrderRow = {
|
|||||||
const STEPS = ['类型', '订单', '凭证', '完成'] as const;
|
const STEPS = ['类型', '订单', '凭证', '完成'] as const;
|
||||||
|
|
||||||
export default function AfterSalePage() {
|
export default function AfterSalePage() {
|
||||||
|
usePageView('after_sale_apply');
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const [params] = useSearchParams();
|
const [params] = useSearchParams();
|
||||||
const presetOrderId = params.get('orderId') || '';
|
const presetOrderId = params.get('orderId') || '';
|
||||||
|
|||||||
@@ -2,9 +2,11 @@ import { useEffect, useState } from 'react';
|
|||||||
import { useNavigate, useParams } from 'react-router-dom';
|
import { useNavigate, useParams } from 'react-router-dom';
|
||||||
import PageHeader from '@dukang/shared-ui/PageHeader';
|
import PageHeader from '@dukang/shared-ui/PageHeader';
|
||||||
import { request } from '../lib/api';
|
import { request } from '../lib/api';
|
||||||
|
import { usePageView } from '../lib/usePageView';
|
||||||
|
|
||||||
export default function BenefitDetailPage() {
|
export default function BenefitDetailPage() {
|
||||||
const { id } = useParams();
|
const { id } = useParams();
|
||||||
|
usePageView('benefit_detail_view', { couponId: id });
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const [data, setData] = useState<{ coupon: Record<string, unknown>; ledgers: Array<Record<string, unknown>> } | null>(null);
|
const [data, setData] = useState<{ coupon: Record<string, unknown>; ledgers: Array<Record<string, unknown>> } | null>(null);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { useEffect, useRef, useState } from 'react';
|
|||||||
import { Link, useNavigate } from 'react-router-dom';
|
import { Link, useNavigate } from 'react-router-dom';
|
||||||
import BrandLogo from '@dukang/shared-ui/BrandLogo';
|
import BrandLogo from '@dukang/shared-ui/BrandLogo';
|
||||||
import { request } from '../lib/api';
|
import { request } from '../lib/api';
|
||||||
|
import { usePageView } from '../lib/usePageView';
|
||||||
|
|
||||||
type BenefitSummary = {
|
type BenefitSummary = {
|
||||||
totalBalance: number;
|
totalBalance: number;
|
||||||
@@ -44,6 +45,7 @@ function buildRedeemUrl(coupon?: CouponItem) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default function BenefitPage() {
|
export default function BenefitPage() {
|
||||||
|
usePageView('benefit_page_view');
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const listRef = useRef<HTMLElement>(null);
|
const listRef = useRef<HTMLElement>(null);
|
||||||
const [summary, setSummary] = useState<BenefitSummary | null>(null);
|
const [summary, setSummary] = useState<BenefitSummary | null>(null);
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import { buildOrderAddressSelectUrl } from '../lib/navigation';
|
|||||||
import { STITCH_ORDER_PRODUCT_IMAGE } from '../lib/order-images';
|
import { STITCH_ORDER_PRODUCT_IMAGE } from '../lib/order-images';
|
||||||
import { handleShareButtonClick } from '../lib/wechat-share';
|
import { handleShareButtonClick } from '../lib/wechat-share';
|
||||||
import ContactCustomerSheet from '../components/ContactCustomerSheet';
|
import ContactCustomerSheet from '../components/ContactCustomerSheet';
|
||||||
|
import { usePageView } from '../lib/usePageView';
|
||||||
|
|
||||||
type OrderItem = {
|
type OrderItem = {
|
||||||
productName: string;
|
productName: string;
|
||||||
@@ -131,6 +132,7 @@ function fullReceiverAddress(order: Order) {
|
|||||||
|
|
||||||
export default function OrderDetailPage() {
|
export default function OrderDetailPage() {
|
||||||
const { id } = useParams();
|
const { id } = useParams();
|
||||||
|
usePageView('order_detail_view', { orderId: id });
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const [order, setOrder] = useState<Order | null>(null);
|
const [order, setOrder] = useState<Order | null>(null);
|
||||||
const [showCs, setShowCs] = useState(false);
|
const [showCs, setShowCs] = useState(false);
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import PageHeader from '@dukang/shared-ui/PageHeader';
|
|||||||
import AppImage from '@dukang/shared-ui/AppImage';
|
import AppImage from '@dukang/shared-ui/AppImage';
|
||||||
import OrderStatusTabs from '@dukang/shared-ui/OrderStatusTabs';
|
import OrderStatusTabs from '@dukang/shared-ui/OrderStatusTabs';
|
||||||
import { request } from '../lib/api';
|
import { request } from '../lib/api';
|
||||||
|
import { usePageView } from '../lib/usePageView';
|
||||||
|
|
||||||
const TABS = [
|
const TABS = [
|
||||||
{ key: 'all', label: '全部' },
|
{ key: 'all', label: '全部' },
|
||||||
@@ -36,6 +37,7 @@ function orderStatusLabel(order: Record<string, unknown>) {
|
|||||||
export default function OrderListPage() {
|
export default function OrderListPage() {
|
||||||
const [params, setParams] = useSearchParams();
|
const [params, setParams] = useSearchParams();
|
||||||
const tab = params.get('tab') || 'all';
|
const tab = params.get('tab') || 'all';
|
||||||
|
usePageView('order_list_view', { tab });
|
||||||
const [data, setData] = useState<{ list: Array<Record<string, unknown>> }>({ list: [] });
|
const [data, setData] = useState<{ list: Array<Record<string, unknown>> }>({ list: [] });
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,8 @@ import {
|
|||||||
} from '../lib/pay-wechat';
|
} from '../lib/pay-wechat';
|
||||||
import { applyWechatLoginResult, handleWechatAuthCallback } from '../lib/wechat-auth';
|
import { applyWechatLoginResult, handleWechatAuthCallback } from '../lib/wechat-auth';
|
||||||
import { isWechatEnv } from '../lib/weixin';
|
import { isWechatEnv } from '../lib/weixin';
|
||||||
|
import { usePageView } from '../lib/usePageView';
|
||||||
|
import { track } from '../lib/analytics';
|
||||||
|
|
||||||
function sleep(ms: number) {
|
function sleep(ms: number) {
|
||||||
return new Promise((resolve) => setTimeout(resolve, ms));
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
||||||
@@ -32,6 +34,7 @@ async function waitOrderPaid(orderId: string, maxAttempts = 15) {
|
|||||||
export default function PayPage() {
|
export default function PayPage() {
|
||||||
const [params] = useSearchParams();
|
const [params] = useSearchParams();
|
||||||
const orderId = params.get('orderId') || '';
|
const orderId = params.get('orderId') || '';
|
||||||
|
usePageView('pay_page_view', { orderId });
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const [authLoading, setAuthLoading] = useState(false);
|
const [authLoading, setAuthLoading] = useState(false);
|
||||||
@@ -161,6 +164,11 @@ export default function PayPage() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setMsg(e instanceof Error ? e.message : '支付失败');
|
setMsg(e instanceof Error ? e.message : '支付失败');
|
||||||
|
track('pay_fail', {
|
||||||
|
orderId,
|
||||||
|
failReason: e instanceof Error ? e.message : '支付失败',
|
||||||
|
pagePath: '/pay',
|
||||||
|
});
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -155,7 +155,10 @@ export default function ProductDetailPage() {
|
|||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
className="product-detail-buy-btn"
|
className="product-detail-buy-btn"
|
||||||
onClick={() => navigate(`/order/confirm?productId=${id}&qty=2`)}
|
onClick={() => {
|
||||||
|
track('product_click', { refType: 'PRODUCT', refId: id, productId: id });
|
||||||
|
navigate(`/order/confirm?productId=${id}&qty=2`);
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
立即购买
|
立即购买
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
@@ -2,8 +2,10 @@ import { useEffect, useState } from 'react';
|
|||||||
import { useNavigate } from 'react-router-dom';
|
import { useNavigate } from 'react-router-dom';
|
||||||
import { REDEEM_TOKEN_TTL_SECONDS } from '@dukang/shared-types';
|
import { REDEEM_TOKEN_TTL_SECONDS } from '@dukang/shared-types';
|
||||||
import PageHeader from '@dukang/shared-ui/PageHeader';
|
import PageHeader from '@dukang/shared-ui/PageHeader';
|
||||||
|
import { usePageView } from '../lib/usePageView';
|
||||||
|
|
||||||
export default function RedeemCodePage() {
|
export default function RedeemCodePage() {
|
||||||
|
usePageView('redeem_code_view');
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const token = sessionStorage.getItem('redeemToken') || '';
|
const token = sessionStorage.getItem('redeemToken') || '';
|
||||||
const amount = sessionStorage.getItem('redeemAmount') || '0';
|
const amount = sessionStorage.getItem('redeemAmount') || '0';
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { useCallback, useEffect, useRef, useState } from 'react';
|
|||||||
import { useNavigate, useSearchParams } from 'react-router-dom';
|
import { useNavigate, useSearchParams } from 'react-router-dom';
|
||||||
import { REDEEM_TOKEN_TTL_SECONDS } from '@dukang/shared-types';
|
import { REDEEM_TOKEN_TTL_SECONDS } from '@dukang/shared-types';
|
||||||
import { request } from '../lib/api';
|
import { request } from '../lib/api';
|
||||||
|
import { usePageView } from '../lib/usePageView';
|
||||||
|
|
||||||
const POLL_INTERVAL_MS = 2500;
|
const POLL_INTERVAL_MS = 2500;
|
||||||
|
|
||||||
@@ -37,6 +38,7 @@ function formatTimer(seconds: number) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default function RedeemPage() {
|
export default function RedeemPage() {
|
||||||
|
usePageView('benefit_redeem_start');
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const [searchParams] = useSearchParams();
|
const [searchParams] = useSearchParams();
|
||||||
const couponId = searchParams.get('couponId') ?? undefined;
|
const couponId = searchParams.get('couponId') ?? undefined;
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user