feat(admin): Phase 4 行业配置管理页面 + 账号行业授权
Some checks failed
CI / Lint & TypeCheck (push) Has been cancelled
CI / Unit Tests (push) Has been cancelled
CI / Build Frontend (push) Has been cancelled
CI / Rust Check (push) Has been cancelled
CI / Security Scan (push) Has been cancelled
CI / E2E Tests (push) Has been cancelled
Some checks failed
CI / Lint & TypeCheck (push) Has been cancelled
CI / Unit Tests (push) Has been cancelled
CI / Build Frontend (push) Has been cancelled
CI / Rust Check (push) Has been cancelled
CI / Security Scan (push) Has been cancelled
CI / E2E Tests (push) Has been cancelled
- 新增 Industries.tsx: 行业列表(ProTable) + 编辑弹窗(关键词/prompt/痛点种子) + 新建弹窗 - 新增 services/industries.ts: 行业 API 服务层(list/create/update/fullConfig/accountIndustries) - 增强 Accounts.tsx: 编辑弹窗添加行业授权多选, 自动获取/同步用户行业 - 注册 /industries 路由 + 侧边栏导航(ShopOutlined)
This commit is contained in:
@@ -21,6 +21,7 @@ import {
|
||||
SafetyOutlined,
|
||||
FieldTimeOutlined,
|
||||
SyncOutlined,
|
||||
ShopOutlined,
|
||||
} from '@ant-design/icons'
|
||||
import { Avatar, Dropdown, Tooltip, Drawer } from 'antd'
|
||||
import { useAuthStore } from '@/stores/authStore'
|
||||
@@ -50,6 +51,7 @@ const navItems: NavItem[] = [
|
||||
{ path: '/relay', name: '中转任务', icon: <SwapOutlined />, permission: 'relay:use', group: '运维' },
|
||||
{ path: '/scheduled-tasks', name: '定时任务', icon: <FieldTimeOutlined />, permission: 'scheduler:read', group: '运维' },
|
||||
{ path: '/knowledge', name: '知识库', icon: <BookOutlined />, permission: 'knowledge:read', group: '资源管理' },
|
||||
{ path: '/industries', name: '行业配置', icon: <ShopOutlined />, permission: 'config:read', group: '资源管理' },
|
||||
{ path: '/billing', name: '计费管理', icon: <CrownOutlined />, permission: 'billing:read', group: '核心' },
|
||||
{ path: '/logs', name: '操作日志', icon: <FileTextOutlined />, permission: 'admin:full', group: '运维' },
|
||||
{ path: '/config-sync', name: '同步日志', icon: <SyncOutlined />, permission: 'config:read', group: '运维' },
|
||||
|
||||
@@ -2,12 +2,13 @@
|
||||
// 账号管理
|
||||
// ============================================================
|
||||
|
||||
import { useState } from 'react'
|
||||
import { useState, useEffect } from 'react'
|
||||
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'
|
||||
import { Button, message, Tag, Modal, Form, Input, Select, Popconfirm, Space } from 'antd'
|
||||
import { Button, message, Tag, Modal, Form, Input, Select, Popconfirm, Space, Divider } from 'antd'
|
||||
import type { ProColumns } from '@ant-design/pro-components'
|
||||
import { ProTable } from '@ant-design/pro-components'
|
||||
import { accountService } from '@/services/accounts'
|
||||
import { industryService } from '@/services/industries'
|
||||
import { PageHeader } from '@/components/PageHeader'
|
||||
import type { AccountPublic } from '@/types'
|
||||
|
||||
@@ -41,12 +42,35 @@ export default function Accounts() {
|
||||
const [modalOpen, setModalOpen] = useState(false)
|
||||
const [editingId, setEditingId] = useState<string | null>(null)
|
||||
const [searchParams, setSearchParams] = useState<Record<string, string>>({})
|
||||
const [editingIndustries, setEditingIndustries] = useState<string[]>([])
|
||||
|
||||
const { data, isLoading } = useQuery({
|
||||
queryKey: ['accounts', searchParams],
|
||||
queryFn: ({ signal }) => accountService.list(searchParams, signal),
|
||||
})
|
||||
|
||||
// 获取行业列表(用于下拉选择)
|
||||
const { data: industriesData } = useQuery({
|
||||
queryKey: ['industries-all'],
|
||||
queryFn: ({ signal }) => industryService.list({ page: 1, page_size: 100, status: 'active' }, signal),
|
||||
})
|
||||
|
||||
// 获取当前编辑用户的行业授权
|
||||
const { data: accountIndustries } = useQuery({
|
||||
queryKey: ['account-industries', editingId],
|
||||
queryFn: ({ signal }) => industryService.getAccountIndustries(editingId!, signal),
|
||||
enabled: !!editingId,
|
||||
})
|
||||
|
||||
// 当账户行业数据加载完,同步到表单
|
||||
useEffect(() => {
|
||||
if (accountIndustries) {
|
||||
const ids = accountIndustries.map((item) => item.industry_id)
|
||||
setEditingIndustries(ids)
|
||||
form.setFieldValue('industry_ids', ids)
|
||||
}
|
||||
}, [accountIndustries, form])
|
||||
|
||||
const updateMutation = useMutation({
|
||||
mutationFn: ({ id, data }: { id: string; data: Partial<AccountPublic> }) =>
|
||||
accountService.update(id, data),
|
||||
@@ -68,6 +92,18 @@ export default function Accounts() {
|
||||
onError: (err: Error) => message.error(err.message || '状态更新失败'),
|
||||
})
|
||||
|
||||
// 设置用户行业授权
|
||||
const setIndustriesMutation = useMutation({
|
||||
mutationFn: ({ accountId, industries }: { accountId: string; industries: string[] }) =>
|
||||
industryService.setAccountIndustries(accountId, {
|
||||
industries: industries.map((id, idx) => ({
|
||||
industry_id: id,
|
||||
is_primary: idx === 0,
|
||||
})),
|
||||
}),
|
||||
onError: (err: Error) => message.error(err.message || '行业授权更新失败'),
|
||||
})
|
||||
|
||||
const columns: ProColumns<AccountPublic>[] = [
|
||||
{ title: '用户名', dataIndex: 'username', width: 120, tooltip: '搜索用户名、邮箱或显示名' },
|
||||
{ title: '显示名', dataIndex: 'display_name', width: 120, hideInSearch: true },
|
||||
@@ -150,13 +186,39 @@ export default function Accounts() {
|
||||
const handleSave = async () => {
|
||||
const values = await form.validateFields()
|
||||
if (editingId) {
|
||||
updateMutation.mutate({ id: editingId, data: values })
|
||||
// 更新基础信息
|
||||
const { industry_ids, ...accountData } = values
|
||||
updateMutation.mutate({ id: editingId, data: accountData })
|
||||
|
||||
// 更新行业授权(如果变更了)
|
||||
const newIndustryIds: string[] = industry_ids || []
|
||||
const oldIndustryIds = accountIndustries?.map((i) => i.industry_id) || []
|
||||
const changed = newIndustryIds.length !== oldIndustryIds.length
|
||||
|| newIndustryIds.some((id) => !oldIndustryIds.includes(id))
|
||||
|
||||
if (changed) {
|
||||
await setIndustriesMutation.mutateAsync({ accountId: editingId, industries: newIndustryIds })
|
||||
message.success('行业授权已更新')
|
||||
queryClient.invalidateQueries({ queryKey: ['account-industries'] })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const handleClose = () => {
|
||||
setModalOpen(false)
|
||||
setEditingId(null)
|
||||
setEditingIndustries([])
|
||||
form.resetFields()
|
||||
}
|
||||
|
||||
const industryOptions = (industriesData?.items || []).map((item) => ({
|
||||
value: item.id,
|
||||
label: `${item.icon} ${item.name}`,
|
||||
}))
|
||||
|
||||
return (
|
||||
<div>
|
||||
<PageHeader title="账号管理" description="管理系统用户账号、角色与权限" />
|
||||
<PageHeader title="账号管理" description="管理系统用户账号、角色、权限与行业授权" />
|
||||
|
||||
<ProTable<AccountPublic>
|
||||
columns={columns}
|
||||
@@ -169,7 +231,6 @@ export default function Accounts() {
|
||||
const filtered: Record<string, string> = {}
|
||||
for (const [k, v] of Object.entries(values)) {
|
||||
if (v !== undefined && v !== null && v !== '') {
|
||||
// Map 'username' search field to backend 'search' param
|
||||
if (k === 'username') {
|
||||
filtered.search = String(v)
|
||||
} else {
|
||||
@@ -192,8 +253,9 @@ export default function Accounts() {
|
||||
title={<span className="text-base font-semibold">编辑账号</span>}
|
||||
open={modalOpen}
|
||||
onOk={handleSave}
|
||||
onCancel={() => { setModalOpen(false); setEditingId(null); form.resetFields() }}
|
||||
onCancel={handleClose}
|
||||
confirmLoading={updateMutation.isPending}
|
||||
width={560}
|
||||
>
|
||||
<Form form={form} layout="vertical" className="mt-4">
|
||||
<Form.Item name="display_name" label="显示名">
|
||||
@@ -215,6 +277,21 @@ export default function Accounts() {
|
||||
{ value: 'relay', label: 'SaaS 中转 (Token 池)' },
|
||||
]} />
|
||||
</Form.Item>
|
||||
|
||||
<Divider>行业授权</Divider>
|
||||
|
||||
<Form.Item
|
||||
name="industry_ids"
|
||||
label="授权行业"
|
||||
extra="第一个行业将设为主行业。行业决定管家可触达的知识域和技能优先级。"
|
||||
>
|
||||
<Select
|
||||
mode="multiple"
|
||||
placeholder="选择授权的行业"
|
||||
options={industryOptions}
|
||||
loading={!industriesData}
|
||||
/>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</Modal>
|
||||
</div>
|
||||
|
||||
350
admin-v2/src/pages/Industries.tsx
Normal file
350
admin-v2/src/pages/Industries.tsx
Normal file
@@ -0,0 +1,350 @@
|
||||
// ============================================================
|
||||
// 行业配置管理
|
||||
// ============================================================
|
||||
|
||||
import { useState, useEffect } from 'react'
|
||||
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'
|
||||
import {
|
||||
Button, message, Tag, Modal, Form, Input, Select, Space, Popconfirm,
|
||||
Tabs, Typography, Spin, Empty,
|
||||
} from 'antd'
|
||||
import {
|
||||
PlusOutlined, EditOutlined, CheckCircleOutlined, StopOutlined,
|
||||
ShopOutlined, SettingOutlined,
|
||||
} from '@ant-design/icons'
|
||||
import type { ProColumns } from '@ant-design/pro-components'
|
||||
import { ProTable } from '@ant-design/pro-components'
|
||||
import { industryService } from '@/services/industries'
|
||||
import type { IndustryListItem, IndustryFullConfig, UpdateIndustryRequest } from '@/services/industries'
|
||||
import { PageHeader } from '@/components/PageHeader'
|
||||
|
||||
const { TextArea } = Input
|
||||
const { Text } = Typography
|
||||
|
||||
const statusLabels: Record<string, string> = { active: '启用', disabled: '禁用' }
|
||||
const statusColors: Record<string, string> = { active: 'green', disabled: 'default' }
|
||||
const sourceLabels: Record<string, string> = { builtin: '内置', custom: '自定义' }
|
||||
|
||||
// === 行业列表 ===
|
||||
|
||||
function IndustryListPanel() {
|
||||
const queryClient = useQueryClient()
|
||||
const [page, setPage] = useState(1)
|
||||
const [pageSize, setPageSize] = useState(20)
|
||||
const [filters, setFilters] = useState<{ status?: string }>({})
|
||||
const [editId, setEditId] = useState<string | null>(null)
|
||||
const [createOpen, setCreateOpen] = useState(false)
|
||||
|
||||
const { data, isLoading } = useQuery({
|
||||
queryKey: ['industries', page, pageSize, filters],
|
||||
queryFn: ({ signal }) => industryService.list({ page, page_size: pageSize, ...filters }, signal),
|
||||
})
|
||||
|
||||
const updateStatusMutation = useMutation({
|
||||
mutationFn: ({ id, status }: { id: string; status: string }) =>
|
||||
industryService.update(id, { status }),
|
||||
onSuccess: () => {
|
||||
message.success('状态已更新')
|
||||
queryClient.invalidateQueries({ queryKey: ['industries'] })
|
||||
},
|
||||
onError: (err: Error) => message.error(err.message || '更新失败'),
|
||||
})
|
||||
|
||||
const columns: ProColumns<IndustryListItem>[] = [
|
||||
{
|
||||
title: '图标',
|
||||
dataIndex: 'icon',
|
||||
width: 50,
|
||||
search: false,
|
||||
render: (_, r) => <span className="text-xl">{r.icon}</span>,
|
||||
},
|
||||
{
|
||||
title: '行业名称',
|
||||
dataIndex: 'name',
|
||||
width: 150,
|
||||
},
|
||||
{
|
||||
title: '描述',
|
||||
dataIndex: 'description',
|
||||
width: 250,
|
||||
search: false,
|
||||
ellipsis: true,
|
||||
},
|
||||
{
|
||||
title: '来源',
|
||||
dataIndex: 'source',
|
||||
width: 80,
|
||||
valueType: 'select',
|
||||
valueEnum: {
|
||||
builtin: { text: '内置' },
|
||||
custom: { text: '自定义' },
|
||||
},
|
||||
render: (_, r) => <Tag color={r.source === 'builtin' ? 'blue' : 'purple'}>{sourceLabels[r.source] || r.source}</Tag>,
|
||||
},
|
||||
{
|
||||
title: '关键词数',
|
||||
dataIndex: 'keywords_count',
|
||||
width: 90,
|
||||
search: false,
|
||||
render: (_, r) => <Tag>{r.keywords_count}</Tag>,
|
||||
},
|
||||
{
|
||||
title: '状态',
|
||||
dataIndex: 'status',
|
||||
width: 80,
|
||||
valueType: 'select',
|
||||
valueEnum: {
|
||||
active: { text: '启用', status: 'Success' },
|
||||
disabled: { text: '禁用', status: 'Default' },
|
||||
},
|
||||
render: (_, r) => <Tag color={statusColors[r.status]}>{statusLabels[r.status] || r.status}</Tag>,
|
||||
},
|
||||
{
|
||||
title: '更新时间',
|
||||
dataIndex: 'updated_at',
|
||||
width: 160,
|
||||
valueType: 'dateTime',
|
||||
search: false,
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
width: 180,
|
||||
search: false,
|
||||
render: (_, r) => (
|
||||
<Space>
|
||||
<Button
|
||||
type="link"
|
||||
size="small"
|
||||
icon={<EditOutlined />}
|
||||
onClick={() => setEditId(r.id)}
|
||||
>
|
||||
编辑
|
||||
</Button>
|
||||
{r.status === 'active' ? (
|
||||
<Popconfirm title="确定禁用此行业?" onConfirm={() => updateStatusMutation.mutate({ id: r.id, status: 'disabled' })}>
|
||||
<Button type="link" size="small" danger icon={<StopOutlined />}>禁用</Button>
|
||||
</Popconfirm>
|
||||
) : (
|
||||
<Popconfirm title="确定启用此行业?" onConfirm={() => updateStatusMutation.mutate({ id: r.id, status: 'active' })}>
|
||||
<Button type="link" size="small" icon={<CheckCircleOutlined />}>启用</Button>
|
||||
</Popconfirm>
|
||||
)}
|
||||
</Space>
|
||||
),
|
||||
},
|
||||
]
|
||||
|
||||
return (
|
||||
<div>
|
||||
<ProTable<IndustryListItem>
|
||||
columns={columns}
|
||||
dataSource={data?.items || []}
|
||||
loading={isLoading}
|
||||
rowKey="id"
|
||||
search={{
|
||||
onReset: () => { setFilters({}); setPage(1) },
|
||||
onSearch: (values) => { setFilters(values); setPage(1) },
|
||||
}}
|
||||
toolBarRender={() => [
|
||||
<Button key="create" type="primary" icon={<PlusOutlined />} onClick={() => setCreateOpen(true)}>
|
||||
新建行业
|
||||
</Button>,
|
||||
]}
|
||||
pagination={{
|
||||
current: page,
|
||||
pageSize,
|
||||
total: data?.total || 0,
|
||||
showSizeChanger: true,
|
||||
onChange: (p, ps) => { setPage(p); setPageSize(ps) },
|
||||
}}
|
||||
options={{ density: false, fullScreen: false, reload: () => queryClient.invalidateQueries({ queryKey: ['industries'] }) }}
|
||||
/>
|
||||
|
||||
<IndustryEditModal
|
||||
open={!!editId}
|
||||
industryId={editId}
|
||||
onClose={() => setEditId(null)}
|
||||
/>
|
||||
|
||||
<IndustryCreateModal
|
||||
open={createOpen}
|
||||
onClose={() => setCreateOpen(false)}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// === 行业编辑弹窗 ===
|
||||
|
||||
function IndustryEditModal({ open, industryId, onClose }: {
|
||||
open: boolean
|
||||
industryId: string | null
|
||||
onClose: () => void
|
||||
}) {
|
||||
const queryClient = useQueryClient()
|
||||
const [form] = Form.useForm()
|
||||
|
||||
const { data, isLoading } = useQuery({
|
||||
queryKey: ['industry-full-config', industryId],
|
||||
queryFn: ({ signal }) => industryService.getFullConfig(industryId!, signal),
|
||||
enabled: !!industryId,
|
||||
})
|
||||
|
||||
useEffect(() => {
|
||||
if (data && open) {
|
||||
form.setFieldsValue({
|
||||
name: data.name,
|
||||
icon: data.icon,
|
||||
description: data.description,
|
||||
keywords: data.keywords,
|
||||
system_prompt: data.system_prompt,
|
||||
cold_start_template: data.cold_start_template,
|
||||
pain_seed_categories: data.pain_seed_categories,
|
||||
})
|
||||
}
|
||||
}, [data, open, form])
|
||||
|
||||
const updateMutation = useMutation({
|
||||
mutationFn: (body: UpdateIndustryRequest) =>
|
||||
industryService.update(industryId!, body),
|
||||
onSuccess: () => {
|
||||
message.success('行业配置已更新')
|
||||
queryClient.invalidateQueries({ queryKey: ['industries'] })
|
||||
queryClient.invalidateQueries({ queryKey: ['industry-full-config'] })
|
||||
onClose()
|
||||
},
|
||||
onError: (err: Error) => message.error(err.message || '更新失败'),
|
||||
})
|
||||
|
||||
return (
|
||||
<Modal
|
||||
title={<span className="text-base font-semibold">编辑行业配置 — {data?.name || ''}</span>}
|
||||
open={open}
|
||||
onCancel={() => { onClose(); form.resetFields() }}
|
||||
onOk={() => form.submit()}
|
||||
confirmLoading={updateMutation.isPending}
|
||||
width={720}
|
||||
destroyOnClose
|
||||
>
|
||||
{isLoading ? (
|
||||
<div className="flex justify-center py-8"><Spin /></div>
|
||||
) : data ? (
|
||||
<Form
|
||||
form={form}
|
||||
layout="vertical"
|
||||
className="mt-4"
|
||||
onFinish={(values) => updateMutation.mutate(values)}
|
||||
>
|
||||
<Form.Item name="name" label="行业名称" rules={[{ required: true, message: '请输入行业名称' }]}>
|
||||
<Input />
|
||||
</Form.Item>
|
||||
<Form.Item name="icon" label="图标">
|
||||
<Input placeholder="行业图标 emoji,如 🏥" className="w-32" />
|
||||
</Form.Item>
|
||||
<Form.Item name="description" label="描述">
|
||||
<TextArea rows={2} placeholder="行业简要描述" />
|
||||
</Form.Item>
|
||||
<Form.Item name="keywords" label="关键词列表" extra="用于语义路由匹配,回车添加">
|
||||
<Select mode="tags" placeholder="输入关键词后回车添加" />
|
||||
</Form.Item>
|
||||
<Form.Item name="system_prompt" label="系统提示词" extra="匹配到此行业时注入的 system prompt">
|
||||
<TextArea rows={6} placeholder="行业专属系统提示词模板" />
|
||||
</Form.Item>
|
||||
<Form.Item name="cold_start_template" label="冷启动模板" extra="首次匹配时的引导消息模板">
|
||||
<TextArea rows={3} placeholder="冷启动引导消息" />
|
||||
</Form.Item>
|
||||
<Form.Item name="pain_seed_categories" label="痛点种子分类" extra="预置的痛点分类维度">
|
||||
<Select mode="tags" placeholder="输入痛点分类后回车添加" />
|
||||
</Form.Item>
|
||||
<div className="mb-2">
|
||||
<Text type="secondary">
|
||||
来源: <Tag color={data.source === 'builtin' ? 'blue' : 'purple'}>{sourceLabels[data.source]}</Tag>
|
||||
{' '}状态: <Tag color={statusColors[data.status]}>{statusLabels[data.status]}</Tag>
|
||||
</Text>
|
||||
</div>
|
||||
</Form>
|
||||
) : (
|
||||
<Empty description="未找到行业配置" />
|
||||
)}
|
||||
</Modal>
|
||||
)
|
||||
}
|
||||
|
||||
// === 新建行业弹窗 ===
|
||||
|
||||
function IndustryCreateModal({ open, onClose }: {
|
||||
open: boolean
|
||||
onClose: () => void
|
||||
}) {
|
||||
const queryClient = useQueryClient()
|
||||
const [form] = Form.useForm()
|
||||
|
||||
const createMutation = useMutation({
|
||||
mutationFn: (data: Parameters<typeof industryService.create>[0]) =>
|
||||
industryService.create(data),
|
||||
onSuccess: () => {
|
||||
message.success('行业已创建')
|
||||
queryClient.invalidateQueries({ queryKey: ['industries'] })
|
||||
onClose()
|
||||
form.resetFields()
|
||||
},
|
||||
onError: (err: Error) => message.error(err.message || '创建失败'),
|
||||
})
|
||||
|
||||
return (
|
||||
<Modal
|
||||
title="新建行业"
|
||||
open={open}
|
||||
onCancel={() => { onClose(); form.resetFields() }}
|
||||
onOk={() => form.submit()}
|
||||
confirmLoading={createMutation.isPending}
|
||||
width={640}
|
||||
destroyOnClose
|
||||
>
|
||||
<Form
|
||||
form={form}
|
||||
layout="vertical"
|
||||
className="mt-4"
|
||||
initialValues={{ icon: '🏢' }}
|
||||
onFinish={(values) => createMutation.mutate(values)}
|
||||
>
|
||||
<Form.Item name="name" label="行业名称" rules={[{ required: true, message: '请输入行业名称' }]}>
|
||||
<Input placeholder="如:医疗健康、教育培训" />
|
||||
</Form.Item>
|
||||
<Form.Item name="icon" label="图标">
|
||||
<Input placeholder="行业图标 emoji" className="w-32" />
|
||||
</Form.Item>
|
||||
<Form.Item name="description" label="描述" rules={[{ required: true, message: '请输入行业描述' }]}>
|
||||
<TextArea rows={2} placeholder="行业简要描述" />
|
||||
</Form.Item>
|
||||
<Form.Item name="keywords" label="关键词列表" extra="用于语义路由匹配,回车添加">
|
||||
<Select mode="tags" placeholder="输入关键词后回车添加" />
|
||||
</Form.Item>
|
||||
<Form.Item name="system_prompt" label="系统提示词">
|
||||
<TextArea rows={4} placeholder="行业专属系统提示词" />
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</Modal>
|
||||
)
|
||||
}
|
||||
|
||||
// === 主页面 ===
|
||||
|
||||
export default function Industries() {
|
||||
return (
|
||||
<div>
|
||||
<PageHeader title="行业配置" description="管理行业关键词、系统提示词、痛点种子,驱动管家语义路由" />
|
||||
<Tabs
|
||||
defaultActiveKey="list"
|
||||
items={[
|
||||
{
|
||||
key: 'list',
|
||||
label: '行业列表',
|
||||
icon: <ShopOutlined />,
|
||||
children: <IndustryListPanel />,
|
||||
},
|
||||
]}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -36,6 +36,7 @@ export const router = createBrowserRouter([
|
||||
{ path: 'prompts', lazy: () => import('@/pages/Prompts').then((m) => ({ Component: m.default })) },
|
||||
{ path: 'logs', lazy: () => import('@/pages/Logs').then((m) => ({ Component: m.default })) },
|
||||
{ path: 'config-sync', lazy: () => import('@/pages/ConfigSync').then((m) => ({ Component: m.default })) },
|
||||
{ path: 'industries', lazy: () => import('@/pages/Industries').then((m) => ({ Component: m.default })) },
|
||||
],
|
||||
},
|
||||
])
|
||||
|
||||
104
admin-v2/src/services/industries.ts
Normal file
104
admin-v2/src/services/industries.ts
Normal file
@@ -0,0 +1,104 @@
|
||||
// ============================================================
|
||||
// 行业配置 API 服务层
|
||||
// ============================================================
|
||||
|
||||
import request, { withSignal } from './request'
|
||||
import type { PaginatedResponse } from '@/types'
|
||||
import type { IndustryInfo, AccountIndustryItem } from '@/types'
|
||||
|
||||
/** 行业列表项(列表接口返回) */
|
||||
export interface IndustryListItem {
|
||||
id: string
|
||||
name: string
|
||||
icon: string
|
||||
description: string
|
||||
status: string
|
||||
source: string
|
||||
keywords_count: number
|
||||
created_at: string
|
||||
updated_at: string
|
||||
}
|
||||
|
||||
/** 行业完整配置(含关键词、prompt 等) */
|
||||
export interface IndustryFullConfig {
|
||||
id: string
|
||||
name: string
|
||||
icon: string
|
||||
description: string
|
||||
status: string
|
||||
source: string
|
||||
keywords: string[]
|
||||
system_prompt: string
|
||||
cold_start_template: string
|
||||
pain_seed_categories: string[]
|
||||
skill_priorities: Array<{ skill_id: string; priority: number }>
|
||||
created_at: string
|
||||
updated_at: string
|
||||
}
|
||||
|
||||
/** 创建行业请求 */
|
||||
export interface CreateIndustryRequest {
|
||||
name: string
|
||||
icon: string
|
||||
description: string
|
||||
keywords?: string[]
|
||||
system_prompt?: string
|
||||
cold_start_template?: string
|
||||
pain_seed_categories?: string[]
|
||||
}
|
||||
|
||||
/** 更新行业请求 */
|
||||
export interface UpdateIndustryRequest {
|
||||
name?: string
|
||||
icon?: string
|
||||
description?: string
|
||||
status?: string
|
||||
keywords?: string[]
|
||||
system_prompt?: string
|
||||
cold_start_template?: string
|
||||
pain_seed_categories?: string[]
|
||||
skill_priorities?: Array<{ skill_id: string; priority: number }>
|
||||
}
|
||||
|
||||
/** 设置用户行业请求 */
|
||||
export interface SetAccountIndustriesRequest {
|
||||
industries: Array<{
|
||||
industry_id: string
|
||||
is_primary: boolean
|
||||
}>
|
||||
}
|
||||
|
||||
export const industryService = {
|
||||
/** 行业列表 */
|
||||
list: (params?: { page?: number; page_size?: number; status?: string }, signal?: AbortSignal) =>
|
||||
request.get<PaginatedResponse<IndustryListItem>>('/industries', withSignal({ params }, signal))
|
||||
.then((r) => r.data),
|
||||
|
||||
/** 行业详情 */
|
||||
get: (id: string, signal?: AbortSignal) =>
|
||||
request.get<IndustryInfo>(`/industries/${id}`, withSignal({}, signal))
|
||||
.then((r) => r.data),
|
||||
|
||||
/** 行业完整配置 */
|
||||
getFullConfig: (id: string, signal?: AbortSignal) =>
|
||||
request.get<IndustryFullConfig>(`/industries/${id}/full-config`, withSignal({}, signal))
|
||||
.then((r) => r.data),
|
||||
|
||||
/** 创建行业 */
|
||||
create: (data: CreateIndustryRequest) =>
|
||||
request.post<IndustryInfo>('/industries', data).then((r) => r.data),
|
||||
|
||||
/** 更新行业 */
|
||||
update: (id: string, data: UpdateIndustryRequest) =>
|
||||
request.patch<IndustryInfo>(`/industries/${id}`, data).then((r) => r.data),
|
||||
|
||||
/** 获取用户授权行业 */
|
||||
getAccountIndustries: (accountId: string, signal?: AbortSignal) =>
|
||||
request.get<AccountIndustryItem[]>(`/accounts/${accountId}/industries`, withSignal({}, signal))
|
||||
.then((r) => r.data),
|
||||
|
||||
/** 设置用户授权行业 */
|
||||
setAccountIndustries: (accountId: string, data: SetAccountIndustriesRequest) =>
|
||||
request.put<AccountIndustryItem[]>(`/accounts/${accountId}/industries`, data)
|
||||
.then((r) => r.data),
|
||||
}
|
||||
@@ -44,6 +44,30 @@ export interface PaginatedResponse<T> {
|
||||
page_size: number
|
||||
}
|
||||
|
||||
/** 行业配置 */
|
||||
export interface IndustryInfo {
|
||||
id: string
|
||||
name: string
|
||||
icon: string
|
||||
description: string
|
||||
status: string
|
||||
source: string
|
||||
keywords?: string[]
|
||||
system_prompt?: string
|
||||
cold_start_template?: string
|
||||
pain_seed_categories?: string[]
|
||||
created_at: string
|
||||
updated_at: string
|
||||
}
|
||||
|
||||
/** 用户-行业关联 */
|
||||
export interface AccountIndustryItem {
|
||||
industry_id: string
|
||||
is_primary: boolean
|
||||
industry_name: string
|
||||
industry_icon: string
|
||||
}
|
||||
|
||||
/** 服务商 (Provider) */
|
||||
export interface Provider {
|
||||
id: string
|
||||
|
||||
Reference in New Issue
Block a user