feat(category): 接单平台支持二级分类目录与接单大厅联动展示及限额优化
This commit is contained in:
@@ -1,6 +1,18 @@
|
||||
import { useQuery, useQueryClient } from '@tanstack/react-query'
|
||||
import { App, Button, Card, Descriptions, Form, InputNumber, Space, Table, Tag } from 'antd'
|
||||
import { useEffect, useState } from 'react'
|
||||
import {
|
||||
App,
|
||||
Avatar,
|
||||
Button,
|
||||
Card,
|
||||
Descriptions,
|
||||
Form,
|
||||
InputNumber,
|
||||
Space,
|
||||
Switch,
|
||||
Table,
|
||||
Tag,
|
||||
} from 'antd'
|
||||
import { useEffect, useMemo, useState } from 'react'
|
||||
|
||||
import {
|
||||
fetchAdminWorkCategories,
|
||||
@@ -11,6 +23,7 @@ import type { WorkCategory } from '@/types/worker-platform'
|
||||
|
||||
type HallConfigFormValues = {
|
||||
maxVisibleOrders: number
|
||||
showSubcategories: boolean
|
||||
categoryMaxVisibleOrders: Record<string, number>
|
||||
}
|
||||
|
||||
@@ -29,20 +42,44 @@ export default function HallConfigPanel() {
|
||||
if (config) {
|
||||
form.setFieldsValue({
|
||||
maxVisibleOrders: config.maxVisibleOrders,
|
||||
showSubcategories: config.showSubcategories ?? true,
|
||||
categoryMaxVisibleOrders: config.categoryMaxVisibleOrders || {},
|
||||
})
|
||||
}
|
||||
}, [config, form])
|
||||
|
||||
const categoriesQuery = useQuery({
|
||||
queryKey: ['admin-worker-platform-categories'],
|
||||
queryFn: fetchAdminWorkCategories,
|
||||
})
|
||||
|
||||
const treeData = useMemo(() => {
|
||||
const rawCategories = categoriesQuery.data?.data.items || []
|
||||
const rootCategories = rawCategories.filter((item) => !item.parentId)
|
||||
const childrenMap = new Map<number, WorkCategory[]>()
|
||||
for (const item of rawCategories) {
|
||||
if (item.parentId) {
|
||||
const list = childrenMap.get(item.parentId) || []
|
||||
list.push(item)
|
||||
childrenMap.set(item.parentId, list)
|
||||
}
|
||||
}
|
||||
|
||||
return rootCategories.map((root) => {
|
||||
const children = childrenMap.get(root.categoryId) || []
|
||||
return {
|
||||
...root,
|
||||
children: children.length > 0 ? children : undefined,
|
||||
}
|
||||
})
|
||||
}, [categoriesQuery.data?.data.items])
|
||||
|
||||
async function saveConfig(values: HallConfigFormValues) {
|
||||
setSaving(true)
|
||||
try {
|
||||
await saveAdminWorkerHallConfig({
|
||||
maxVisibleOrders: Number(values.maxVisibleOrders),
|
||||
showSubcategories: Boolean(values.showSubcategories),
|
||||
categoryMaxVisibleOrders: values.categoryMaxVisibleOrders || {},
|
||||
})
|
||||
await Promise.all([
|
||||
@@ -59,29 +96,43 @@ export default function HallConfigPanel() {
|
||||
|
||||
return (
|
||||
<Card title="大厅配置" bordered={false} loading={configQuery.isLoading}>
|
||||
<Space direction="vertical" size="middle" style={{ width: '100%', maxWidth: 560 }}>
|
||||
<Space direction="vertical" size="middle" style={{ width: '100%', maxWidth: 640 }}>
|
||||
<Descriptions size="small" column={3}>
|
||||
<Descriptions.Item label="展示中">{config?.visibleOrderCount || 0}</Descriptions.Item>
|
||||
<Descriptions.Item label="等待入厅">{config?.queuedOrderCount || 0}</Descriptions.Item>
|
||||
<Descriptions.Item label="当前上限">{config?.maxVisibleOrders || '-'}</Descriptions.Item>
|
||||
</Descriptions>
|
||||
<Form form={form} layout="vertical" onFinish={saveConfig}>
|
||||
<Form.Item
|
||||
name="maxVisibleOrders"
|
||||
label="大厅订单总数"
|
||||
rules={[{ required: true, message: '请输入大厅订单总数' }]}
|
||||
>
|
||||
<InputNumber min={1} max={500} precision={0} style={{ width: 160 }} />
|
||||
</Form.Item>
|
||||
<Space size="large" align="start" wrap style={{ marginBottom: 8 }}>
|
||||
<Form.Item
|
||||
name="maxVisibleOrders"
|
||||
label="大厅订单总数"
|
||||
rules={[{ required: true, message: '请输入大厅订单总数' }]}
|
||||
style={{ marginBottom: 12 }}
|
||||
>
|
||||
<InputNumber min={1} max={500} precision={0} style={{ width: 160 }} />
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
name="showSubcategories"
|
||||
label="大厅二级目录展示"
|
||||
valuePropName="checked"
|
||||
tooltip="开启后,接单大厅一级分类下方联动展示其二级分类选项;关闭后大厅只展示一级分类。"
|
||||
style={{ marginBottom: 12 }}
|
||||
>
|
||||
<Switch checkedChildren="开启展示" unCheckedChildren="关闭展示" />
|
||||
</Form.Item>
|
||||
</Space>
|
||||
|
||||
<Form.Item>
|
||||
<Button type="primary" htmlType="submit" loading={saving}>
|
||||
保存
|
||||
保存配置
|
||||
</Button>
|
||||
</Form.Item>
|
||||
|
||||
<div>
|
||||
<Tag color="blue">分类上限</Tag>
|
||||
<span style={{ marginLeft: 8, color: '#666' }}>
|
||||
未填写的分类沿用大厅总上限;填写后仅限制该分类最多展示数量。
|
||||
<Tag color="blue">分类最多展示上限</Tag>
|
||||
<span style={{ marginLeft: 8, color: '#666', fontSize: 13 }}>
|
||||
一级分类限额将限制该游戏及旗下所有子分类的总单量;二级分类可单独设置细化限额。
|
||||
</span>
|
||||
</div>
|
||||
<Table<WorkCategory>
|
||||
@@ -89,11 +140,39 @@ export default function HallConfigPanel() {
|
||||
size="small"
|
||||
pagination={false}
|
||||
loading={categoriesQuery.isLoading}
|
||||
dataSource={categoriesQuery.data?.data.items || []}
|
||||
dataSource={treeData}
|
||||
defaultExpandAllRows
|
||||
columns={[
|
||||
{ title: '分类', dataIndex: 'name' },
|
||||
{
|
||||
title: '分类名称',
|
||||
dataIndex: 'name',
|
||||
render: (_, category) => (
|
||||
<Space size="small">
|
||||
{category.iconUrl ? (
|
||||
<Avatar src={category.iconUrl} size={20} shape="square" />
|
||||
) : null}
|
||||
<span>{category.name}</span>
|
||||
{category.parentId ? (
|
||||
<Tag
|
||||
color="blue"
|
||||
style={{ fontSize: 11, lineHeight: '18px', padding: '0 4px' }}
|
||||
>
|
||||
二级
|
||||
</Tag>
|
||||
) : (
|
||||
<Tag
|
||||
color="orange"
|
||||
style={{ fontSize: 11, lineHeight: '18px', padding: '0 4px' }}
|
||||
>
|
||||
一级
|
||||
</Tag>
|
||||
)}
|
||||
</Space>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: '状态',
|
||||
width: 90,
|
||||
render: (_, category) => (
|
||||
<Tag color={category.status === 'active' ? 'green' : 'default'}>
|
||||
{category.status === 'active' ? '启用' : '停用'}
|
||||
@@ -102,12 +181,19 @@ export default function HallConfigPanel() {
|
||||
},
|
||||
{
|
||||
title: '最多展示',
|
||||
width: 180,
|
||||
render: (_, category) => (
|
||||
<Form.Item
|
||||
name={['categoryMaxVisibleOrders', String(category.categoryId)]}
|
||||
style={{ margin: 0 }}
|
||||
>
|
||||
<InputNumber min={1} max={500} precision={0} placeholder="跟随总上限" />
|
||||
<InputNumber
|
||||
min={1}
|
||||
max={500}
|
||||
precision={0}
|
||||
placeholder={category.parentId ? '跟随父级' : '跟随总上限'}
|
||||
style={{ width: '100%' }}
|
||||
/>
|
||||
</Form.Item>
|
||||
),
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user