refactor(chat): 欢迎语仅保留账号群配置

This commit is contained in:
yml2213
2026-10-30 17:50:37 +08:00
parent 77b5c6123a
commit 0a85634a58
18 changed files with 29 additions and 236 deletions
@@ -3,12 +3,7 @@ import { useQuery, useQueryClient } from '@tanstack/react-query'
import { Alert, App, Button, Card, Form, Input, Space, Tag, Typography } from 'antd'
import { ReloadOutlined } from '@ant-design/icons'
import {
fetchChatAutoWelcome,
fetchListingGroupWelcome,
updateChatAutoWelcome,
updateListingGroupWelcome,
} from '@/features/admin/api'
import { fetchListingGroupWelcome, updateListingGroupWelcome } from '@/features/admin/api'
import { AdminPageHeader } from '@/features/admin/components/AdminPageHeader'
import { useAdminSessionStore } from '@/stores/adminSession'
@@ -20,30 +15,20 @@ function errorText(error: unknown) {
export function AdminChatWelcomePage() {
const { message } = App.useApp()
const queryClient = useQueryClient()
const [autoForm] = Form.useForm<{ message: string }>()
const [groupForm] = Form.useForm<{ message: string }>()
const [saving, setSaving] = useState<'auto' | 'group' | null>(null)
const [saving, setSaving] = useState(false)
const permissions = useAdminSessionStore(state => state.admin?.permissions)
const canView = Boolean(permissions?.includes('*') || permissions?.includes('system_config:view'))
const canManage = Boolean(
permissions?.includes('*') || permissions?.includes('system_config:update')
)
const autoQuery = useQuery({
queryKey: ['chat-auto-welcome'],
queryFn: fetchChatAutoWelcome,
enabled: canView,
})
const groupQuery = useQuery({
queryKey: ['chat-listing-group-welcome'],
queryFn: fetchListingGroupWelcome,
enabled: canView,
})
useEffect(() => {
if (autoQuery.data != null) autoForm.setFieldsValue({ message: autoQuery.data })
}, [autoQuery.data, autoForm])
useEffect(() => {
if (groupQuery.data != null) groupForm.setFieldsValue({ message: groupQuery.data })
}, [groupQuery.data, groupForm])
@@ -57,23 +42,17 @@ export function AdminChatWelcomePage() {
)
}
const save = async (kind: 'auto' | 'group') => {
const form = kind === 'auto' ? autoForm : groupForm
const values = await form.validateFields()
setSaving(kind)
const save = async () => {
const values = await groupForm.validateFields()
setSaving(true)
try {
if (kind === 'auto') {
await updateChatAutoWelcome(values.message.trim())
await queryClient.invalidateQueries({ queryKey: ['chat-auto-welcome'] })
} else {
await updateListingGroupWelcome(values.message.trim())
await queryClient.invalidateQueries({ queryKey: ['chat-listing-group-welcome'] })
}
await updateListingGroupWelcome(values.message.trim())
await queryClient.invalidateQueries({ queryKey: ['chat-listing-group-welcome'] })
message.success('欢迎语已保存')
} catch (error) {
message.error(errorText(error))
} finally {
setSaving(null)
setSaving(false)
}
}
@@ -82,49 +61,24 @@ export function AdminChatWelcomePage() {
<AdminPageHeader
eyebrow="JIEYOU OPS · 客服"
title="欢迎语配置"
description="维护订单群与账号群的自动欢迎语,客服建群后自动发送。"
description="维护账号群的自动欢迎语,客服建群后自动发送。"
meta={
<Space size={8} wrap>
<Tag color="geekblue">订单群</Tag>
<Tag color="purple">账号群</Tag>
</Space>
}
extra={
<Button
icon={<ReloadOutlined />}
loading={autoQuery.isFetching || groupQuery.isFetching}
onClick={() => {
void autoQuery.refetch()
void groupQuery.refetch()
}}
loading={groupQuery.isFetching}
onClick={() => void groupQuery.refetch()}
>
刷新
</Button>
}
/>
<Card title="订单群欢迎语" className="admin-table-card">
<Form form={autoForm} layout="vertical" requiredMark={false}>
<Form.Item
name="message"
label="欢迎语"
rules={[{ required: true, message: '请输入欢迎语' }, { max: 500 }]}
extra="订单群建立后自动发送给租客与号主"
>
<Input.TextArea rows={4} maxLength={500} showCount disabled={!canManage} />
</Form.Item>
<Button
type="primary"
loading={saving === 'auto'}
disabled={!canManage}
onClick={() => void save('auto')}
>
保存订单群欢迎语
</Button>
</Form>
</Card>
<Card title="账号群欢迎语" className="admin-table-card" style={{ marginTop: 16 }}>
<Card title="账号群欢迎语" className="admin-table-card">
<Form form={groupForm} layout="vertical" requiredMark={false}>
<Form.Item
name="message"
@@ -136,9 +90,9 @@ export function AdminChatWelcomePage() {
</Form.Item>
<Button
type="primary"
loading={saving === 'group'}
loading={saving}
disabled={!canManage}
onClick={() => void save('group')}
onClick={() => void save()}
>
保存账号群欢迎语
</Button>
@@ -146,7 +100,7 @@ export function AdminChatWelcomePage() {
</Card>
<Typography.Paragraph type="secondary" style={{ marginTop: 12 }}>
欢迎语保存在系统配置中,修改后对新建立的群生效。
欢迎语保存在系统配置中,修改后对新建立的账号群生效。
</Typography.Paragraph>
</div>
)
-15
View File
@@ -2027,21 +2027,6 @@ export async function updateCrashConfig(payload: Partial<AdminCrashConfig>) {
return data.data
}
export async function fetchChatAutoWelcome() {
const { data } = await adminClient.get<ApiResponse<{ message: string }>>(
'/admin/chats/auto-welcome'
)
return data.data.message ?? ''
}
export async function updateChatAutoWelcome(message: string) {
const { data } = await adminClient.put<ApiResponse<{ message: string }>>(
'/admin/chats/auto-welcome',
{ message }
)
return data.data
}
export async function fetchListingGroupWelcome() {
const { data } = await adminClient.get<ApiResponse<{ message: string }>>(
'/admin/chats/listing-group-welcome'
+1 -1
View File
@@ -210,7 +210,7 @@ export function ChatPage() {
<BrandLogo height={48} variant="seal" />
<Typography.Title level={3}>登录后进入会话</Typography.Title>
<Typography.Paragraph type="secondary">
订单群聊与客服会话只对当前账号开放。
账号群聊与客服会话只对当前账号开放。
</Typography.Paragraph>
<Button type="primary" onClick={() => navigate(`/login?redirect=/messages/${id}`)}>
去登录
@@ -31,8 +31,7 @@ import { formatRelativeTime } from '@/shared/utils/format'
function conversationMeta(type: string) {
if (type === 'general_support') return { label: '平台客服', color: 'gold' }
if (type === 'order_group') return { label: '订单群聊', color: 'green' }
if (type === 'listing_group') return { label: '商品咨询', color: 'blue' }
if (type === 'listing_group') return { label: '账号群', color: 'blue' }
return { label: '交易会话', color: 'default' }
}
@@ -154,7 +153,7 @@ export function MessagesPage() {
<BrandLogo height={48} variant="seal" />
<Typography.Title level={3}>登录后查看消息</Typography.Title>
<Typography.Paragraph type="secondary">
订单群聊、客服回复与系统通知只对当前账号开放。
账号群聊、客服回复与系统通知只对当前账号开放。
</Typography.Paragraph>
<Button
type="primary"
@@ -176,7 +175,7 @@ export function MessagesPage() {
消息中心
</Typography.Title>
<Typography.Paragraph type="secondary">
订单群聊会随下单自动建立,交接、结账与申诉都建议在群内留痕。
账号群聊随商品发布建立,交接、结账与申诉都建议在群内留痕。
</Typography.Paragraph>
</div>
<Space wrap>
@@ -140,7 +140,7 @@ export function MobileMessagesPage() {
<div className="mobile-orders__login">
<BrandLogo height={40} variant="seal" />
<h2>先登录,再看消息</h2>
<p>订单群聊与客服会话只对交易双方开放。</p>
<p>账号群聊与客服会话只对交易双方开放。</p>
<Button block color="primary" onClick={() => navigate('/m/login?redirect=/m/messages')}>
去登录
</Button>
@@ -185,7 +185,7 @@ export function MobileMessagesPage() {
) : chatItems.length === 0 ? (
<div className="mobile-messages__empty">
<Empty description="还没有会话" />
<span>下单后会自动创建订单群聊,也可以先联系客服。</span>
<span>商品发布后会自动创建账号群,也可以先联系客服。</span>
</div>
) : (
<div className="mobile-message-list">
@@ -54,7 +54,7 @@ export function MobileOrderDetailPage() {
} catch (error) {
Toast.show({
icon: 'fail',
content: error instanceof Error ? error.message : '订单群聊暂时无法打开',
content: error instanceof Error ? error.message : '账号群暂时无法打开',
})
} finally {
setOpeningChat(false)
@@ -254,7 +254,7 @@ export function MobileOrderDetailPage() {
loading={openingChat}
onClick={() => void openOrderChat()}
>
进入订单群聊
进入账号群
</Button>
<MobileOrderActionPanel
order={order}
@@ -57,7 +57,7 @@ export function OrderDetailPage() {
const conversation = await fetchOrderConversation(order.id)
navigate(`/messages/${conversation.id}`)
} catch (error) {
message.error(error instanceof Error ? error.message : '订单群聊暂时无法打开')
message.error(error instanceof Error ? error.message : '账号群暂时无法打开')
} finally {
setOpeningChat(false)
}
@@ -321,7 +321,7 @@ export function OrderDetailPage() {
className="pc-order-chat-button"
onClick={() => void openOrderChat()}
>
进入订单群聊
进入账号群
</Button>
<OrderActionPanel
order={order}