feat: 套餐折叠、小程序 staging API、首页去筛选、企微日志权限
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import { Alert, Button, Form, Input, InputNumber, Space, Typography, message } from 'antd';
|
import { Alert, Button, Form, Input, InputNumber, Space, Typography, message } from 'antd';
|
||||||
|
import { DownOutlined, UpOutlined } from '@ant-design/icons';
|
||||||
import type { StorePackageItemDto } from '@dukang/shared-types';
|
import type { StorePackageItemDto } from '@dukang/shared-types';
|
||||||
import { STORE_PACKAGE_MAX_COUNT } from '@dukang/shared-types';
|
import { STORE_PACKAGE_MAX_COUNT } from '@dukang/shared-types';
|
||||||
import { request } from '../lib/api';
|
import { request } from '../lib/api';
|
||||||
@@ -12,6 +13,7 @@ function emptyRow(index = 0): PackageRow {
|
|||||||
|
|
||||||
export default function AdminStorePackagesSection({ storeId }: { storeId: string }) {
|
export default function AdminStorePackagesSection({ storeId }: { storeId: string }) {
|
||||||
const [items, setItems] = useState<PackageRow[]>([emptyRow()]);
|
const [items, setItems] = useState<PackageRow[]>([emptyRow()]);
|
||||||
|
const [collapsed, setCollapsed] = useState<Record<number, boolean>>({});
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
const [saving, setSaving] = useState(false);
|
const [saving, setSaving] = useState(false);
|
||||||
|
|
||||||
@@ -40,6 +42,19 @@ export default function AdminStorePackagesSection({ storeId }: { storeId: string
|
|||||||
|
|
||||||
function removeAt(index: number) {
|
function removeAt(index: number) {
|
||||||
setItems((prev) => prev.filter((_, i) => i !== index).map((item, i) => ({ ...item, sortOrder: i })));
|
setItems((prev) => prev.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] }));
|
||||||
}
|
}
|
||||||
|
|
||||||
async function save() {
|
async function save() {
|
||||||
@@ -100,7 +115,10 @@ export default function AdminStorePackagesSection({ storeId }: { storeId: string
|
|||||||
message={`总部直存立即生效,无需审核。同一门店最多 ${STORE_PACKAGE_MAX_COUNT} 条套餐。`}
|
message={`总部直存立即生效,无需审核。同一门店最多 ${STORE_PACKAGE_MAX_COUNT} 条套餐。`}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{items.map((item, index) => (
|
{items.map((item, index) => {
|
||||||
|
const isCollapsed = !!collapsed[index];
|
||||||
|
const displayName = item.name.trim() || `套餐 ${index + 1}`;
|
||||||
|
return (
|
||||||
<div
|
<div
|
||||||
key={index}
|
key={index}
|
||||||
style={{
|
style={{
|
||||||
@@ -111,10 +129,17 @@ export default function AdminStorePackagesSection({ storeId }: { storeId: string
|
|||||||
background: '#fafafa',
|
background: '#fafafa',
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Space style={{ width: '100%', justifyContent: 'space-between', marginBottom: 12 }}>
|
<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 }}>
|
<Typography.Title level={5} style={{ margin: 0 }}>
|
||||||
套餐 {index + 1}
|
{displayName}
|
||||||
</Typography.Title>
|
</Typography.Title>
|
||||||
|
</Button>
|
||||||
{items.length > 1 ? (
|
{items.length > 1 ? (
|
||||||
<Button type="link" danger onClick={() => removeAt(index)}>
|
<Button type="link" danger onClick={() => removeAt(index)}>
|
||||||
删除
|
删除
|
||||||
@@ -122,6 +147,8 @@ export default function AdminStorePackagesSection({ storeId }: { storeId: string
|
|||||||
) : null}
|
) : null}
|
||||||
</Space>
|
</Space>
|
||||||
|
|
||||||
|
{!isCollapsed ? (
|
||||||
|
<>
|
||||||
<Form.Item label="套餐名称" required style={{ marginBottom: 12 }}>
|
<Form.Item label="套餐名称" required style={{ marginBottom: 12 }}>
|
||||||
<Input
|
<Input
|
||||||
placeholder="如:套餐A"
|
placeholder="如:套餐A"
|
||||||
@@ -166,8 +193,11 @@ export default function AdminStorePackagesSection({ storeId }: { storeId: string
|
|||||||
onChange={(e) => updateAt(index, { otherNotes: e.target.value })}
|
onChange={(e) => updateAt(index, { otherNotes: e.target.value })}
|
||||||
/>
|
/>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
|
</>
|
||||||
|
) : null}
|
||||||
</div>
|
</div>
|
||||||
))}
|
);
|
||||||
|
})}
|
||||||
|
|
||||||
{items.length < STORE_PACKAGE_MAX_COUNT ? (
|
{items.length < STORE_PACKAGE_MAX_COUNT ? (
|
||||||
<Button onClick={addRow} style={{ marginBottom: 16 }}>
|
<Button onClick={addRow} style={{ marginBottom: 16 }}>
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { useState } from 'react';
|
||||||
import type { PackageFormItem } from '../lib/storePackages';
|
import type { PackageFormItem } from '../lib/storePackages';
|
||||||
import { STORE_PACKAGE_MAX_COUNT } from '@dukang/shared-types';
|
import { STORE_PACKAGE_MAX_COUNT } from '@dukang/shared-types';
|
||||||
import { emptyPackage } from '../lib/storePackages';
|
import { emptyPackage } from '../lib/storePackages';
|
||||||
@@ -11,6 +12,8 @@ type Props = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export default function StorePackagesForm({ items, onChange, disabled, embedded }: Props) {
|
export default function StorePackagesForm({ items, onChange, disabled, embedded }: Props) {
|
||||||
|
const [collapsed, setCollapsed] = useState<Record<number, boolean>>({});
|
||||||
|
|
||||||
function updateAt(index: number, patch: Partial<PackageFormItem>) {
|
function updateAt(index: number, patch: Partial<PackageFormItem>) {
|
||||||
const next = items.map((item, i) => (i === index ? { ...item, ...patch } : item));
|
const next = items.map((item, i) => (i === index ? { ...item, ...patch } : item));
|
||||||
onChange(next);
|
onChange(next);
|
||||||
@@ -23,23 +26,47 @@ export default function StorePackagesForm({ items, onChange, disabled, embedded
|
|||||||
|
|
||||||
function removeAt(index: number) {
|
function removeAt(index: number) {
|
||||||
onChange(items.filter((_, i) => i !== index).map((item, i) => ({ ...item, sortOrder: i })));
|
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)];
|
const list = items.length ? items : [emptyPackage(0)];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={`partner-packages-form${embedded ? ' partner-packages-form--embedded' : ''}`}>
|
<div className={`partner-packages-form${embedded ? ' partner-packages-form--embedded' : ''}`}>
|
||||||
{list.map((item, index) => (
|
{list.map((item, index) => {
|
||||||
|
const isCollapsed = !!collapsed[index];
|
||||||
|
const displayName = item.name.trim() || `套餐 ${index + 1}`;
|
||||||
|
return (
|
||||||
<section
|
<section
|
||||||
key={index}
|
key={index}
|
||||||
className="partner-form-card partner-packages-item"
|
className={`partner-form-card partner-packages-item${isCollapsed ? ' partner-packages-item--collapsed' : ''}`}
|
||||||
style={embedded ? { marginLeft: 0, marginRight: 0 } : undefined}
|
style={embedded ? { marginLeft: 0, marginRight: 0 } : undefined}
|
||||||
>
|
>
|
||||||
<div className="partner-packages-item-head">
|
<div className="partner-packages-item-head">
|
||||||
<div className="partner-section-title" style={{ marginBottom: 0 }}>
|
<button
|
||||||
<div className="partner-section-bar" />
|
type="button"
|
||||||
<h2 className="headline-md">套餐 {index + 1}</h2>
|
className="partner-packages-toggle"
|
||||||
</div>
|
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 ? (
|
{!disabled && list.length > 1 ? (
|
||||||
<button type="button" className="partner-packages-remove" onClick={() => removeAt(index)}>
|
<button type="button" className="partner-packages-remove" onClick={() => removeAt(index)}>
|
||||||
删除
|
删除
|
||||||
@@ -47,6 +74,8 @@ export default function StorePackagesForm({ items, onChange, disabled, embedded
|
|||||||
) : null}
|
) : null}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{!isCollapsed ? (
|
||||||
|
<>
|
||||||
<div className="partner-field">
|
<div className="partner-field">
|
||||||
<label>套餐名称 <span className="text-primary">*</span></label>
|
<label>套餐名称 <span className="text-primary">*</span></label>
|
||||||
<div className="partner-field-input">
|
<div className="partner-field-input">
|
||||||
@@ -112,8 +141,11 @@ export default function StorePackagesForm({ items, onChange, disabled, embedded
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</>
|
||||||
|
) : null}
|
||||||
</section>
|
</section>
|
||||||
))}
|
);
|
||||||
|
})}
|
||||||
|
|
||||||
{!disabled && list.length < STORE_PACKAGE_MAX_COUNT ? (
|
{!disabled && list.length < STORE_PACKAGE_MAX_COUNT ? (
|
||||||
<button type="button" className="partner-packages-add" onClick={addItem}>
|
<button type="button" className="partner-packages-add" onClick={addItem}>
|
||||||
|
|||||||
@@ -3678,6 +3678,34 @@ header:has(> .app-page-title:only-child),
|
|||||||
margin-bottom: var(--space-md);
|
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 {
|
.partner-packages-remove {
|
||||||
border: none;
|
border: none;
|
||||||
background: transparent;
|
background: transparent;
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { useState } from 'react';
|
||||||
import { STORE_PACKAGE_MAX_COUNT } from '@dukang/shared-types';
|
import { STORE_PACKAGE_MAX_COUNT } from '@dukang/shared-types';
|
||||||
import { emptyPackage, type PackageFormItem } from '../lib/storePackages';
|
import { emptyPackage, type PackageFormItem } from '../lib/storePackages';
|
||||||
|
|
||||||
@@ -8,6 +9,8 @@ type Props = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export default function ShopPackagesForm({ items, onChange, disabled }: Props) {
|
export default function ShopPackagesForm({ items, onChange, disabled }: Props) {
|
||||||
|
const [collapsed, setCollapsed] = useState<Record<number, boolean>>({});
|
||||||
|
|
||||||
function updateAt(index: number, patch: Partial<PackageFormItem>) {
|
function updateAt(index: number, patch: Partial<PackageFormItem>) {
|
||||||
onChange(items.map((item, i) => (i === index ? { ...item, ...patch } : item)));
|
onChange(items.map((item, i) => (i === index ? { ...item, ...patch } : item)));
|
||||||
}
|
}
|
||||||
@@ -19,16 +22,43 @@ export default function ShopPackagesForm({ items, onChange, disabled }: Props) {
|
|||||||
|
|
||||||
function removeAt(index: number) {
|
function removeAt(index: number) {
|
||||||
onChange(items.filter((_, i) => i !== index).map((item, i) => ({ ...item, sortOrder: i })));
|
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)];
|
const list = items.length ? items : [emptyPackage(0)];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="shop-packages-form">
|
<div className="shop-packages-form">
|
||||||
{list.map((item, index) => (
|
{list.map((item, index) => {
|
||||||
<section key={index} className="shop-packages-card">
|
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">
|
<div className="shop-packages-card-head">
|
||||||
<h3 className="shop-packages-card-title">套餐 {index + 1}</h3>
|
<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 ? (
|
{!disabled && list.length > 1 ? (
|
||||||
<button type="button" className="shop-packages-remove" onClick={() => removeAt(index)}>
|
<button type="button" className="shop-packages-remove" onClick={() => removeAt(index)}>
|
||||||
删除
|
删除
|
||||||
@@ -36,6 +66,8 @@ export default function ShopPackagesForm({ items, onChange, disabled }: Props) {
|
|||||||
) : null}
|
) : null}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{!isCollapsed ? (
|
||||||
|
<>
|
||||||
<label className="shop-packages-field">
|
<label className="shop-packages-field">
|
||||||
<span className="shop-packages-label">套餐名称 *</span>
|
<span className="shop-packages-label">套餐名称 *</span>
|
||||||
<input
|
<input
|
||||||
@@ -94,8 +126,11 @@ export default function ShopPackagesForm({ items, onChange, disabled }: Props) {
|
|||||||
onChange={(e) => updateAt(index, { otherNotes: e.target.value })}
|
onChange={(e) => updateAt(index, { otherNotes: e.target.value })}
|
||||||
/>
|
/>
|
||||||
</label>
|
</label>
|
||||||
|
</>
|
||||||
|
) : null}
|
||||||
</section>
|
</section>
|
||||||
))}
|
);
|
||||||
|
})}
|
||||||
|
|
||||||
{!disabled && list.length < STORE_PACKAGE_MAX_COUNT ? (
|
{!disabled && list.length < STORE_PACKAGE_MAX_COUNT ? (
|
||||||
<button type="button" className="shop-packages-add" onClick={addItem}>
|
<button type="button" className="shop-packages-add" onClick={addItem}>
|
||||||
|
|||||||
@@ -1976,6 +1976,30 @@
|
|||||||
margin-bottom: 12px;
|
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 {
|
.shop-packages-card-title {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
font-size: 16px;
|
font-size: 16px;
|
||||||
|
|||||||
@@ -9,9 +9,10 @@ const isDevMode =
|
|||||||
process.argv.includes('development');
|
process.argv.includes('development');
|
||||||
|
|
||||||
/** 小程序/H5 请求的后端 origin(不含 /api);本地默认本机,生产构建默认远程 */
|
/** 小程序/H5 请求的后端 origin(不含 /api);本地默认本机,生产构建默认远程 */
|
||||||
|
// TODO(prod-release): 发生产前改回 https://api.dukanghaoke.com
|
||||||
const API_ORIGIN =
|
const API_ORIGIN =
|
||||||
process.env.VITE_API_TARGET ??
|
process.env.VITE_API_TARGET ??
|
||||||
(isDevMode ? 'http://localhost:3000' : 'https://api.dukanghaoke.com');
|
(isDevMode ? 'http://localhost:3000' : 'https://api-test.dukanghaoke.com');
|
||||||
|
|
||||||
const requireFromApp = createRequire(path.resolve(__dirname, '../package.json'));
|
const requireFromApp = createRequire(path.resolve(__dirname, '../package.json'));
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ import { capturePromoSceneAndTouchScan } from '../../lib/promo';
|
|||||||
import { getProductMainImage } from '../../lib/product-images';
|
import { getProductMainImage } from '../../lib/product-images';
|
||||||
import {
|
import {
|
||||||
canBuyOnline,
|
canBuyOnline,
|
||||||
canCrossCity,
|
|
||||||
canPickupOnSite,
|
canPickupOnSite,
|
||||||
normalizeFulfillmentFlags,
|
normalizeFulfillmentFlags,
|
||||||
} from '../../lib/product-fulfillment';
|
} from '../../lib/product-fulfillment';
|
||||||
@@ -49,22 +48,6 @@ type Product = {
|
|||||||
allowCrossCityDelivery?: boolean;
|
allowCrossCityDelivery?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
type FulfillmentFilter = 'ALL' | 'ONLINE' | 'CROSS_CITY' | 'ON_SITE';
|
|
||||||
|
|
||||||
const FULFILLMENT_FILTERS: Array<{ key: FulfillmentFilter; label: string }> = [
|
|
||||||
{ key: 'ALL', label: '全部' },
|
|
||||||
{ key: 'ONLINE', label: '线上' },
|
|
||||||
{ key: 'CROSS_CITY', label: '跨城' },
|
|
||||||
{ key: 'ON_SITE', label: '现场' },
|
|
||||||
];
|
|
||||||
|
|
||||||
function matchFulfillmentFilter(p: Product, filter: FulfillmentFilter): boolean {
|
|
||||||
if (filter === 'ALL') return true;
|
|
||||||
if (filter === 'ONLINE') return canBuyOnline(p);
|
|
||||||
if (filter === 'CROSS_CITY') return canCrossCity(p);
|
|
||||||
return canPickupOnSite(p);
|
|
||||||
}
|
|
||||||
|
|
||||||
type MiniHomeConfig = {
|
type MiniHomeConfig = {
|
||||||
banners: string[];
|
banners: string[];
|
||||||
footerUrl: string | null;
|
footerUrl: string | null;
|
||||||
@@ -87,7 +70,6 @@ function aromaSectionId(key: AromaKey) {
|
|||||||
|
|
||||||
export default function HomePage() {
|
export default function HomePage() {
|
||||||
const [activeAroma, setActiveAroma] = useState<AromaKey>('QINGXIANG');
|
const [activeAroma, setActiveAroma] = useState<AromaKey>('QINGXIANG');
|
||||||
const [fulfillmentFilter, setFulfillmentFilter] = useState<FulfillmentFilter>('ALL');
|
|
||||||
const [products, setProducts] = useState<Product[]>([]);
|
const [products, setProducts] = useState<Product[]>([]);
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
const [displayCity, setDisplayCity] = useState('郑州市');
|
const [displayCity, setDisplayCity] = useState('郑州市');
|
||||||
@@ -205,23 +187,18 @@ export default function HomePage() {
|
|||||||
Taro.navigateTo({ url: returnPath });
|
Taro.navigateTo({ url: returnPath });
|
||||||
}
|
}
|
||||||
|
|
||||||
const filteredProducts = useMemo(
|
|
||||||
() => products.filter((p) => matchFulfillmentFilter(p, fulfillmentFilter)),
|
|
||||||
[products, fulfillmentFilter],
|
|
||||||
);
|
|
||||||
|
|
||||||
const productsByAroma = useMemo(() => {
|
const productsByAroma = useMemo(() => {
|
||||||
const map: Record<AromaKey, Product[]> = {
|
const map: Record<AromaKey, Product[]> = {
|
||||||
QINGXIANG: [],
|
QINGXIANG: [],
|
||||||
JIANGXIANG: [],
|
JIANGXIANG: [],
|
||||||
NONGXIANG: [],
|
NONGXIANG: [],
|
||||||
};
|
};
|
||||||
for (const p of filteredProducts) {
|
for (const p of products) {
|
||||||
const key = p.aromaType as AromaKey;
|
const key = p.aromaType as AromaKey;
|
||||||
if (key in map) map[key].push(p);
|
if (key in map) map[key].push(p);
|
||||||
}
|
}
|
||||||
return map;
|
return map;
|
||||||
}, [filteredProducts]);
|
}, [products]);
|
||||||
|
|
||||||
const banners = miniHome.banners;
|
const banners = miniHome.banners;
|
||||||
const footerUrl = miniHome.footerUrl;
|
const footerUrl = miniHome.footerUrl;
|
||||||
@@ -377,28 +354,13 @@ export default function HomePage() {
|
|||||||
<Text className="home-aroma-city">{displayCity}</Text>
|
<Text className="home-aroma-city">{displayCity}</Text>
|
||||||
</View>
|
</View>
|
||||||
|
|
||||||
<View className="home-fulfillment-filters">
|
|
||||||
{FULFILLMENT_FILTERS.map((f) => (
|
|
||||||
<Text
|
|
||||||
key={f.key}
|
|
||||||
className={`home-fulfillment-chip${fulfillmentFilter === f.key ? ' home-fulfillment-chip--active' : ''}`}
|
|
||||||
onClick={() => setFulfillmentFilter(f.key)}
|
|
||||||
>
|
|
||||||
{f.label}
|
|
||||||
</Text>
|
|
||||||
))}
|
|
||||||
</View>
|
|
||||||
|
|
||||||
<View className="home-product-list">
|
<View className="home-product-list">
|
||||||
{loading ? <View className="home-empty">加载中…</View> : null}
|
{loading ? <View className="home-empty">加载中…</View> : null}
|
||||||
{!loading && products.length === 0 ? (
|
{!loading && products.length === 0 ? (
|
||||||
<View className="home-empty">当前城市暂无在售商品</View>
|
<View className="home-empty">当前城市暂无在售商品</View>
|
||||||
) : null}
|
) : null}
|
||||||
{!loading && products.length > 0 && filteredProducts.length === 0 ? (
|
|
||||||
<View className="home-empty">暂无符合履约方式的商品</View>
|
|
||||||
) : null}
|
|
||||||
{!loading &&
|
{!loading &&
|
||||||
filteredProducts.length > 0 &&
|
products.length > 0 &&
|
||||||
AROMA_TABS.map((t) => {
|
AROMA_TABS.map((t) => {
|
||||||
const list = productsByAroma[t.key];
|
const list = productsByAroma[t.key];
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ export const WECOM_BOT_PERMISSIONS = [
|
|||||||
'support_ticket.create',
|
'support_ticket.create',
|
||||||
'support_ticket.progress',
|
'support_ticket.progress',
|
||||||
'handbook.query',
|
'handbook.query',
|
||||||
|
'server_log.view',
|
||||||
|
'api.query',
|
||||||
] as const;
|
] as const;
|
||||||
|
|
||||||
export type WecomBotPermission = (typeof WECOM_BOT_PERMISSIONS)[number];
|
export type WecomBotPermission = (typeof WECOM_BOT_PERMISSIONS)[number];
|
||||||
@@ -17,6 +19,8 @@ export const WECOM_BOT_PERMISSION_LABELS: Record<WecomBotPermission, string> = {
|
|||||||
'support_ticket.create': '创建技术支持工单',
|
'support_ticket.create': '创建技术支持工单',
|
||||||
'support_ticket.progress': '查看开发进度',
|
'support_ticket.progress': '查看开发进度',
|
||||||
'handbook.query': '查询使用手册',
|
'handbook.query': '查询使用手册',
|
||||||
|
'server_log.view': '查看服务器日志',
|
||||||
|
'api.query': '查询业务 API(只读)',
|
||||||
};
|
};
|
||||||
|
|
||||||
/** 预置机器人角色(创建时可选;权限可按角色带出默认值后自定义) */
|
/** 预置机器人角色(创建时可选;权限可按角色带出默认值后自定义) */
|
||||||
@@ -38,7 +42,7 @@ export const WECOM_BOT_ROLE_LABELS: Record<WecomBotRole, string> = {
|
|||||||
|
|
||||||
export const WECOM_BOT_ROLE_DEFAULT_PERMISSIONS: Record<WecomBotRole, WecomBotPermission[]> = {
|
export const WECOM_BOT_ROLE_DEFAULT_PERMISSIONS: Record<WecomBotRole, WecomBotPermission[]> = {
|
||||||
CUSTOMER_SERVICE: ['ticket.create', 'user.view_sms', 'delivery.view'],
|
CUSTOMER_SERVICE: ['ticket.create', 'user.view_sms', 'delivery.view'],
|
||||||
TECH_SUPPORT: ['support_ticket.create', 'support_ticket.progress'],
|
TECH_SUPPORT: ['support_ticket.create', 'support_ticket.progress', 'server_log.view', 'api.query'],
|
||||||
TEAM_ASSISTANT: ['handbook.query'],
|
TEAM_ASSISTANT: ['handbook.query'],
|
||||||
CUSTOM: [],
|
CUSTOM: [],
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -95,6 +95,21 @@ export class WecomBotActionsService {
|
|||||||
'',
|
'',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
if (wecomBotHasPermission(bot, 'server_log.view')) {
|
||||||
|
lines.push(
|
||||||
|
'**服务器日志**',
|
||||||
|
'`日志` 最近客户端报错 · `日志 <关键词>` 搜索',
|
||||||
|
'`三方日志 [provider]` 最近第三方调用日志',
|
||||||
|
'',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (wecomBotHasPermission(bot, 'api.query')) {
|
||||||
|
lines.push(
|
||||||
|
'**业务查询(只读)**',
|
||||||
|
'`查订单 <订单号>` · `用户号 <用户号>`',
|
||||||
|
'',
|
||||||
|
);
|
||||||
|
}
|
||||||
if (bot.aiEnabled && bot.llmConfigId) {
|
if (bot.aiEnabled && bot.llmConfigId) {
|
||||||
lines.push(
|
lines.push(
|
||||||
'**智能问答**',
|
'**智能问答**',
|
||||||
@@ -160,6 +175,30 @@ export class WecomBotActionsService {
|
|||||||
return this.queryHandbook(q);
|
return this.queryHandbook(q);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 服务器日志
|
||||||
|
if (/^(日志|错误日志|服务端日志)/i.test(content)) {
|
||||||
|
this.requirePerm(bot, 'server_log.view');
|
||||||
|
const q = content.replace(/^(日志|错误日志|服务端日志)\s*/i, '').trim();
|
||||||
|
return this.queryServerLogs(q);
|
||||||
|
}
|
||||||
|
if (/^(三方日志|第三方日志)/i.test(content)) {
|
||||||
|
this.requirePerm(bot, 'server_log.view');
|
||||||
|
const q = content.replace(/^(三方日志|第三方日志)\s*/i, '').trim();
|
||||||
|
return this.queryThirdPartyLogs(q);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 业务 API 只读查询
|
||||||
|
if (/^(查订单|订单查询)\s+/i.test(content)) {
|
||||||
|
this.requirePerm(bot, 'api.query');
|
||||||
|
const orderNo = content.replace(/^(查订单|订单查询)\s+/i, '').trim();
|
||||||
|
return this.queryOrder(orderNo);
|
||||||
|
}
|
||||||
|
if (/^(用户号|查用户号)\s+/i.test(content)) {
|
||||||
|
this.requirePerm(bot, 'api.query');
|
||||||
|
const userNo = content.replace(/^(用户号|查用户号)\s+/i, '').trim();
|
||||||
|
return this.queryUserByNo(userNo);
|
||||||
|
}
|
||||||
|
|
||||||
// 自然语言手册(仅团队助手有 handbook 权限时;开启 AI 时改由模型+知识库回答)
|
// 自然语言手册(仅团队助手有 handbook 权限时;开启 AI 时改由模型+知识库回答)
|
||||||
if (
|
if (
|
||||||
!opts?.skipNaturalFallback &&
|
!opts?.skipNaturalFallback &&
|
||||||
@@ -448,6 +487,121 @@ export class WecomBotActionsService {
|
|||||||
return formatHandbook(hits);
|
return formatHandbook(hits);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async queryServerLogs(keyword: string) {
|
||||||
|
const rows = await this.prisma.logUserAnalytics.findMany({
|
||||||
|
where: keyword
|
||||||
|
? {
|
||||||
|
eventName: 'client_error',
|
||||||
|
OR: [
|
||||||
|
{ pagePath: { contains: keyword } },
|
||||||
|
{ extraJson: { string_contains: keyword } },
|
||||||
|
],
|
||||||
|
}
|
||||||
|
: { eventName: 'client_error' },
|
||||||
|
orderBy: { createdAt: 'desc' },
|
||||||
|
take: 8,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!rows.length) {
|
||||||
|
return keyword ? `未找到与「${keyword}」相关的客户端报错日志` : '暂无近期客户端报错日志';
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
`**最近客户端报错**${keyword ? `(关键词:${keyword})` : ''}`,
|
||||||
|
...rows.map((row, i) => formatClientErrorLog(row, i + 1)),
|
||||||
|
].join('\n\n');
|
||||||
|
}
|
||||||
|
|
||||||
|
private async queryThirdPartyLogs(provider?: string) {
|
||||||
|
const where = provider ? { provider: provider.toUpperCase() as never } : {};
|
||||||
|
const rows = await this.prisma.logThirdParty.findMany({
|
||||||
|
where,
|
||||||
|
orderBy: { createdAt: 'desc' },
|
||||||
|
take: 8,
|
||||||
|
});
|
||||||
|
if (!rows.length) {
|
||||||
|
return provider ? `未找到 provider=${provider} 的第三方日志` : '暂无近期第三方调用日志';
|
||||||
|
}
|
||||||
|
return [
|
||||||
|
`**最近第三方日志**${provider ? `(${provider})` : ''}`,
|
||||||
|
...rows.map((row, i) => {
|
||||||
|
const err = row.errorMessage ? `\n- 错误:${row.errorMessage.slice(0, 120)}` : '';
|
||||||
|
return [
|
||||||
|
`**${i + 1}. ${row.provider}/${row.scene}**`,
|
||||||
|
`- 状态:${row.status}`,
|
||||||
|
`- 关联:${row.refType || '—'} ${row.refId?.toString() || ''}`,
|
||||||
|
`- 外部单号:${row.externalNo || '—'}${err}`,
|
||||||
|
`- 时间:${row.createdAt.toISOString().slice(0, 19).replace('T', ' ')}`,
|
||||||
|
].join('\n');
|
||||||
|
}),
|
||||||
|
].join('\n\n');
|
||||||
|
}
|
||||||
|
|
||||||
|
private async queryOrder(orderNo: string) {
|
||||||
|
if (!orderNo) return '请提供订单号,例如:`查订单 DK123456`';
|
||||||
|
const order = await this.prisma.order.findFirst({
|
||||||
|
where: { orderNo: { contains: orderNo } },
|
||||||
|
include: {
|
||||||
|
user: { select: { userNo: true, phone: true, nickname: true } },
|
||||||
|
delivery: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
if (!order) return `未找到订单:${orderNo}`;
|
||||||
|
|
||||||
|
const deliveryLines = order.delivery
|
||||||
|
? [`- ${order.delivery.provider} ${order.delivery.trackingNo || '—'}`]
|
||||||
|
: ['- 暂无配送单'];
|
||||||
|
|
||||||
|
return [
|
||||||
|
'**订单摘要**',
|
||||||
|
`- 订单号:${order.orderNo}`,
|
||||||
|
`- 状态:${order.status}`,
|
||||||
|
`- 商品:${order.productName}`,
|
||||||
|
`- 数量:${order.quantity}`,
|
||||||
|
`- 实付:¥${Number(order.payAmount).toFixed(2)}`,
|
||||||
|
`- 履约:${order.deliveryType}`,
|
||||||
|
`- 用户:${order.user?.nickname || '—'} / ${order.user?.userNo || '—'} / ${maskPhone(order.user?.phone || '')}`,
|
||||||
|
`- 下单:${order.createdAt.toISOString().slice(0, 19).replace('T', ' ')}`,
|
||||||
|
'**配送**',
|
||||||
|
...deliveryLines,
|
||||||
|
].join('\n');
|
||||||
|
}
|
||||||
|
|
||||||
|
private async queryUserByNo(userNo: string) {
|
||||||
|
if (!userNo) return '请提供用户号,例如:`用户号 U123456`';
|
||||||
|
const user = await this.prisma.user.findFirst({
|
||||||
|
where: { userNo: { contains: userNo } },
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
userNo: true,
|
||||||
|
phone: true,
|
||||||
|
nickname: true,
|
||||||
|
status: true,
|
||||||
|
phoneVerifiedAt: true,
|
||||||
|
createdAt: true,
|
||||||
|
_count: { select: { orders: true } },
|
||||||
|
},
|
||||||
|
});
|
||||||
|
if (!user) return `未找到用户号:${userNo}`;
|
||||||
|
|
||||||
|
const coupons = await this.prisma.benefitCoupon.aggregate({
|
||||||
|
where: { userId: user.id, status: 'ACTIVE' },
|
||||||
|
_sum: { balance: true },
|
||||||
|
});
|
||||||
|
|
||||||
|
return [
|
||||||
|
'**用户摘要**',
|
||||||
|
`- 用户号:${user.userNo}`,
|
||||||
|
`- 昵称:${user.nickname || '—'}`,
|
||||||
|
`- 手机:${maskPhone(user.phone || '')}`,
|
||||||
|
`- 手机已验:${user.phoneVerifiedAt ? '是' : '否'}`,
|
||||||
|
`- 状态:${user.status}`,
|
||||||
|
`- 订单数:${user._count.orders}`,
|
||||||
|
`- 权益余额:¥${Number(coupons._sum.balance ?? 0).toFixed(2)}`,
|
||||||
|
`- 注册:${user.createdAt.toISOString().slice(0, 19).replace('T', ' ')}`,
|
||||||
|
].join('\n');
|
||||||
|
}
|
||||||
|
|
||||||
private async resolveCreator(wecomUserId: string) {
|
private async resolveCreator(wecomUserId: string) {
|
||||||
const admin = await this.prisma.hqAccount.findFirst({
|
const admin = await this.prisma.hqAccount.findFirst({
|
||||||
where: { status: 'ACTIVE' },
|
where: { status: 'ACTIVE' },
|
||||||
@@ -470,3 +624,30 @@ function maskPhone(phone: string): string {
|
|||||||
function formatHandbook(entries: ReturnType<typeof searchHandbook>): string {
|
function formatHandbook(entries: ReturnType<typeof searchHandbook>): string {
|
||||||
return entries.map((e) => `**${e.title}**\n${e.body}`).join('\n\n---\n\n');
|
return entries.map((e) => `**${e.title}**\n${e.body}`).join('\n\n---\n\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ClientErrorLogRow = {
|
||||||
|
id: bigint;
|
||||||
|
clientApp: string | null;
|
||||||
|
pagePath: string | null;
|
||||||
|
extraJson: unknown;
|
||||||
|
createdAt: Date;
|
||||||
|
};
|
||||||
|
|
||||||
|
function formatClientErrorLog(row: ClientErrorLogRow, index: number): string {
|
||||||
|
const extra =
|
||||||
|
row.extraJson && typeof row.extraJson === 'object'
|
||||||
|
? (row.extraJson as Record<string, unknown>)
|
||||||
|
: {};
|
||||||
|
const level = typeof extra.level === 'string' ? extra.level : '—';
|
||||||
|
const category = typeof extra.category === 'string' ? extra.category : '—';
|
||||||
|
const message = typeof extra.message === 'string' ? extra.message.slice(0, 160) : '—';
|
||||||
|
return [
|
||||||
|
`**${index}. [${level}/${category}]**`,
|
||||||
|
`- 端:${row.clientApp || '—'}`,
|
||||||
|
row.pagePath ? `- 页面:${row.pagePath}` : null,
|
||||||
|
`- 消息:${message}`,
|
||||||
|
`- 时间:${row.createdAt.toISOString().slice(0, 19).replace('T', ' ')}`,
|
||||||
|
]
|
||||||
|
.filter(Boolean)
|
||||||
|
.join('\n');
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user