完善接单平台通知配置
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import {
|
||||
AuditOutlined,
|
||||
BellOutlined,
|
||||
BugOutlined,
|
||||
DashboardOutlined,
|
||||
FileSearchOutlined,
|
||||
@@ -10,18 +11,36 @@ import {
|
||||
SafetyCertificateOutlined,
|
||||
SettingOutlined,
|
||||
ShopOutlined,
|
||||
SoundOutlined,
|
||||
TeamOutlined,
|
||||
TrophyOutlined,
|
||||
UnorderedListOutlined,
|
||||
UserOutlined,
|
||||
} from '@ant-design/icons'
|
||||
import { App, Button, Dropdown, Layout, Menu, Space, Typography } from 'antd'
|
||||
import {
|
||||
App,
|
||||
Badge,
|
||||
Button,
|
||||
Dropdown,
|
||||
Layout,
|
||||
List,
|
||||
Menu,
|
||||
Popover,
|
||||
Space,
|
||||
Tooltip,
|
||||
Typography,
|
||||
} from 'antd'
|
||||
import type { MenuProps } from 'antd'
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import { useMemo, useState } from 'react'
|
||||
import { useQuery, useQueryClient } from '@tanstack/react-query'
|
||||
import { useEffect, useMemo, useRef, useState } from 'react'
|
||||
import { Outlet, useLocation, useNavigate } from 'react-router'
|
||||
|
||||
import { fetchDevMockStatus, logoutAdmin } from '@/services/admin'
|
||||
import {
|
||||
fetchAdminNotifications,
|
||||
fetchDevMockStatus,
|
||||
logoutAdmin,
|
||||
type AdminNotification,
|
||||
} from '@/services/admin'
|
||||
import {
|
||||
clearAdminSession,
|
||||
getAdminRole,
|
||||
@@ -31,17 +50,25 @@ import {
|
||||
import { formatAdminDateTime } from '@/utils/admin-time'
|
||||
|
||||
const SIDEBAR_COLLAPSED_KEY = 'react-admin-sidebar-collapsed'
|
||||
const NOTIFICATION_SOUND_KEY = 'admin-notification-sound-enabled'
|
||||
const NOTIFICATION_SOUND_COOLDOWN_MS = 30_000
|
||||
|
||||
export default function AdminLayout() {
|
||||
const navigate = useNavigate()
|
||||
const location = useLocation()
|
||||
const { message } = App.useApp()
|
||||
const queryClient = useQueryClient()
|
||||
const [collapsed, setCollapsed] = useState(
|
||||
() => window.localStorage.getItem(SIDEBAR_COLLAPSED_KEY) === '1',
|
||||
)
|
||||
const role = getAdminRole()
|
||||
const username = getAdminUsername() || 'admin'
|
||||
const expiresAt = getAdminTokenExpiresAt()
|
||||
const [soundEnabled, setSoundEnabled] = useState(
|
||||
() => window.localStorage.getItem(NOTIFICATION_SOUND_KEY) === '1',
|
||||
)
|
||||
const seenNotificationVersions = useRef<Map<number, string> | null>(null)
|
||||
const lastSoundAt = useRef(0)
|
||||
|
||||
const devMockStatusQuery = useQuery({
|
||||
queryKey: ['admin-dev-mock-status'],
|
||||
@@ -50,6 +77,43 @@ export default function AdminLayout() {
|
||||
retry: false,
|
||||
})
|
||||
const devMockEnabled = Boolean(devMockStatusQuery.data?.data?.enabled)
|
||||
const notificationsQuery = useQuery({
|
||||
queryKey: ['admin-notifications'],
|
||||
queryFn: fetchAdminNotifications,
|
||||
refetchInterval: 10_000,
|
||||
refetchIntervalInBackground: false,
|
||||
refetchOnWindowFocus: true,
|
||||
retry: false,
|
||||
})
|
||||
const notifications = notificationsQuery.data?.data.items || []
|
||||
const pendingNotificationCount = Number(notificationsQuery.data?.data.pendingCount || 0)
|
||||
|
||||
useEffect(() => {
|
||||
const currentVersions = new Map(
|
||||
notifications.map((notification) => [notification.notificationId, notification.updatedAt]),
|
||||
)
|
||||
if (seenNotificationVersions.current === null) {
|
||||
seenNotificationVersions.current = currentVersions
|
||||
return
|
||||
}
|
||||
const changedNotifications = notifications.filter(
|
||||
(notification) =>
|
||||
seenNotificationVersions.current?.get(notification.notificationId) !==
|
||||
notification.updatedAt,
|
||||
)
|
||||
seenNotificationVersions.current = currentVersions
|
||||
if (changedNotifications.length === 0) return
|
||||
|
||||
void Promise.all([
|
||||
queryClient.invalidateQueries({ queryKey: ['admin-worker-platform-finance-requests'] }),
|
||||
queryClient.invalidateQueries({ queryKey: ['admin-worker-platform-orders'] }),
|
||||
queryClient.invalidateQueries({ queryKey: ['admin-worker-platform-summary'] }),
|
||||
])
|
||||
if (soundEnabled && Date.now() - lastSoundAt.current >= NOTIFICATION_SOUND_COOLDOWN_MS) {
|
||||
lastSoundAt.current = Date.now()
|
||||
announceNotification(selectNotificationToAnnounce(changedNotifications))
|
||||
}
|
||||
}, [notifications, queryClient, soundEnabled])
|
||||
|
||||
const menuItems = useMemo<MenuProps['items']>(() => {
|
||||
const operationItems: MenuProps['items'] = [
|
||||
@@ -121,6 +185,64 @@ export default function AdminLayout() {
|
||||
window.localStorage.setItem(SIDEBAR_COLLAPSED_KEY, next ? '1' : '0')
|
||||
}
|
||||
|
||||
function toggleNotificationSound() {
|
||||
const next = !soundEnabled
|
||||
setSoundEnabled(next)
|
||||
window.localStorage.setItem(NOTIFICATION_SOUND_KEY, next ? '1' : '0')
|
||||
if (next) {
|
||||
playNotificationSound('default')
|
||||
message.success('通知声音已开启')
|
||||
} else {
|
||||
message.info('通知声音已关闭')
|
||||
}
|
||||
}
|
||||
|
||||
function openNotification(notification: AdminNotification) {
|
||||
const actionPath = buildNotificationActionPath(notification)
|
||||
if (actionPath) {
|
||||
void navigate(actionPath)
|
||||
}
|
||||
}
|
||||
|
||||
const notificationContent = (
|
||||
<div className="admin-notification-popover">
|
||||
{notifications.length === 0 ? (
|
||||
<Typography.Text type="secondary">暂无待处理事项</Typography.Text>
|
||||
) : (
|
||||
<List
|
||||
size="small"
|
||||
dataSource={notifications.slice(0, 8)}
|
||||
renderItem={(notification) => (
|
||||
<List.Item
|
||||
className="admin-notification-item"
|
||||
onClick={() => openNotification(notification)}
|
||||
>
|
||||
<div>
|
||||
<Space size={6} wrap>
|
||||
<Typography.Text strong>{notification.title}</Typography.Text>
|
||||
{notification.priority === 'high' || notification.priority === 'urgent' ? (
|
||||
<span className="admin-notification-priority">紧急</span>
|
||||
) : null}
|
||||
{notification.reminderCount > 0 ? (
|
||||
<Typography.Text type="secondary">
|
||||
已催 {notification.reminderCount} 次
|
||||
</Typography.Text>
|
||||
) : null}
|
||||
</Space>
|
||||
<Typography.Paragraph type="secondary" ellipsis={{ rows: 2 }}>
|
||||
{notification.body}
|
||||
</Typography.Paragraph>
|
||||
<Typography.Text type="secondary" className="admin-notification-time">
|
||||
{formatAdminDateTime(notification.updatedAt)}
|
||||
</Typography.Text>
|
||||
</div>
|
||||
</List.Item>
|
||||
)}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
|
||||
const selectedKey = resolveSelectedKey(location.pathname)
|
||||
|
||||
return (
|
||||
@@ -182,6 +304,24 @@ export default function AdminLayout() {
|
||||
<Layout className="admin-main-shell">
|
||||
<Layout.Header className="admin-topbar">
|
||||
<Space className="admin-user" size={12}>
|
||||
<Tooltip title={soundEnabled ? '关闭通知声音' : '开启通知声音'}>
|
||||
<Button
|
||||
type="text"
|
||||
aria-label={soundEnabled ? '关闭通知声音' : '开启通知声音'}
|
||||
icon={<SoundOutlined className={soundEnabled ? '' : 'admin-sound-muted'} />}
|
||||
onClick={toggleNotificationSound}
|
||||
/>
|
||||
</Tooltip>
|
||||
<Popover
|
||||
content={notificationContent}
|
||||
title="待处理事项"
|
||||
trigger="click"
|
||||
placement="bottomRight"
|
||||
>
|
||||
<Badge count={pendingNotificationCount} size="small" overflowCount={99}>
|
||||
<Button type="text" aria-label="待处理事项" icon={<BellOutlined />} />
|
||||
</Badge>
|
||||
</Popover>
|
||||
<Dropdown
|
||||
menu={{
|
||||
items: [{ key: 'logout', label: '退出登录' }],
|
||||
@@ -203,6 +343,99 @@ export default function AdminLayout() {
|
||||
)
|
||||
}
|
||||
|
||||
type NotificationAlertKind =
|
||||
| 'withdraw'
|
||||
| 'recharge'
|
||||
| 'acceptance'
|
||||
| 'material'
|
||||
| 'reminder'
|
||||
| 'default'
|
||||
|
||||
function selectNotificationToAnnounce(notifications: AdminNotification[]) {
|
||||
return [...notifications].sort((left, right) => {
|
||||
const priorityDiff = notificationAlertRank(right) - notificationAlertRank(left)
|
||||
if (priorityDiff !== 0) return priorityDiff
|
||||
return right.notificationId - left.notificationId
|
||||
})[0]
|
||||
}
|
||||
|
||||
function notificationAlertRank(notification: AdminNotification) {
|
||||
if (notification.notificationType === 'worker_acceptance_reminded') return 3
|
||||
if (notification.notificationType === 'worker_withdraw_requested') return 2
|
||||
return 1
|
||||
}
|
||||
|
||||
function announceNotification(notification?: AdminNotification) {
|
||||
if (!notification?.soundEnabled) return
|
||||
const { text, kind } = resolveNotificationAnnouncement(notification)
|
||||
playNotificationSound(kind)
|
||||
if (!('speechSynthesis' in window) || typeof SpeechSynthesisUtterance === 'undefined') return
|
||||
|
||||
try {
|
||||
window.speechSynthesis.cancel()
|
||||
const utterance = new SpeechSynthesisUtterance(text)
|
||||
utterance.lang = 'zh-CN'
|
||||
utterance.rate = 1.05
|
||||
utterance.volume = 0.9
|
||||
window.speechSynthesis.speak(utterance)
|
||||
} catch {
|
||||
// 语音播报不可用时,前面的区分音调仍会提示新待办。
|
||||
}
|
||||
}
|
||||
|
||||
function resolveNotificationAnnouncement(notification?: AdminNotification): {
|
||||
text: string
|
||||
kind: NotificationAlertKind
|
||||
} {
|
||||
if (notification?.notificationType === 'worker_acceptance_reminded') {
|
||||
return { text: '你有新的催验收工单', kind: 'reminder' }
|
||||
}
|
||||
if (notification?.notificationType === 'worker_withdraw_requested') {
|
||||
return { text: '你有新的提现申请', kind: 'withdraw' }
|
||||
}
|
||||
if (notification?.notificationType === 'worker_recharge_requested') {
|
||||
return { text: '你有新的充值申请', kind: 'recharge' }
|
||||
}
|
||||
if (notification?.notificationType === 'worker_acceptance_submitted') {
|
||||
return { text: '你有新的待验收工单', kind: 'acceptance' }
|
||||
}
|
||||
if (notification?.notificationType === 'work_order_material_required') {
|
||||
return { text: '你有工单待补资料', kind: 'material' }
|
||||
}
|
||||
return { text: '你有新的待处理事项', kind: 'default' }
|
||||
}
|
||||
|
||||
function playNotificationSound(kind: NotificationAlertKind) {
|
||||
try {
|
||||
const audio = new AudioContext()
|
||||
const oscillator = audio.createOscillator()
|
||||
const gain = audio.createGain()
|
||||
oscillator.type = 'sine'
|
||||
const notes: Record<NotificationAlertKind, number[]> = {
|
||||
withdraw: [740, 988],
|
||||
recharge: [587, 740],
|
||||
acceptance: [660, 784],
|
||||
material: [523, 659],
|
||||
reminder: [880, 1047, 1319],
|
||||
default: [880],
|
||||
}
|
||||
const duration = 0.12
|
||||
const sequence = notes[kind]
|
||||
sequence.forEach((frequency, index) => {
|
||||
oscillator.frequency.setValueAtTime(frequency, audio.currentTime + index * duration)
|
||||
})
|
||||
gain.gain.setValueAtTime(0.08, audio.currentTime)
|
||||
gain.gain.exponentialRampToValueAtTime(0.001, audio.currentTime + sequence.length * duration)
|
||||
oscillator.connect(gain)
|
||||
gain.connect(audio.destination)
|
||||
oscillator.start()
|
||||
oscillator.stop(audio.currentTime + sequence.length * duration)
|
||||
oscillator.addEventListener('ended', () => void audio.close())
|
||||
} catch {
|
||||
// 部分浏览器禁止音频或不支持 Web Audio,不影响待办轮询。
|
||||
}
|
||||
}
|
||||
|
||||
function resolveSelectedKey(pathname: string) {
|
||||
if (pathname.startsWith('/admin/orders')) return '/admin/orders'
|
||||
if (pathname.startsWith('/admin/tasks')) return '/admin/tasks'
|
||||
@@ -212,6 +445,24 @@ function resolveSelectedKey(pathname: string) {
|
||||
return pathname
|
||||
}
|
||||
|
||||
function buildNotificationActionPath(notification: AdminNotification) {
|
||||
if (!notification.entityId) {
|
||||
return notification.actionPath
|
||||
}
|
||||
const [pathname, query = ''] = notification.actionPath.split('?')
|
||||
const searchParams = new URLSearchParams(query)
|
||||
if (notification.entityType === 'work_order') {
|
||||
searchParams.set('tab', 'orders')
|
||||
searchParams.set('workOrderId', String(notification.entityId))
|
||||
} else if (notification.entityType === 'worker_finance_request') {
|
||||
searchParams.set('tab', 'finance')
|
||||
searchParams.set('financeRequestId', String(notification.entityId))
|
||||
} else {
|
||||
return notification.actionPath
|
||||
}
|
||||
return `${pathname}?${searchParams.toString()}`
|
||||
}
|
||||
|
||||
function roleLabel(role: string) {
|
||||
if (role === 'admin') return '管理员'
|
||||
if (role === 'operator') return '普通运营'
|
||||
|
||||
@@ -1,18 +1,31 @@
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import { Card, Space, Tabs } from 'antd'
|
||||
import { useState } from 'react'
|
||||
import { useEffect, useState } from 'react'
|
||||
import { useSearchParams } from 'react-router'
|
||||
|
||||
import PageHeader from '@/components/admin/PageHeader'
|
||||
import { fetchAdminWorkerPlatformSummary } from '@/services/admin'
|
||||
import { getAdminRole } from '@/utils/admin-auth'
|
||||
import CategoriesPanel from './panels/CategoriesPanel'
|
||||
import FinancePanel from './panels/FinancePanel'
|
||||
import LevelsPanel from './panels/LevelsPanel'
|
||||
import NotificationsPanel from './panels/NotificationsPanel'
|
||||
import ProductRulesPanel from './panels/ProductRulesPanel'
|
||||
import WorkersPanel from './panels/WorkersPanel'
|
||||
import WorkOrdersPanel from './panels/WorkOrdersPanel'
|
||||
|
||||
export default function AdminWorkerPlatformPage() {
|
||||
const [activeTab, setActiveTab] = useState(loadActiveTabPreference)
|
||||
const [searchParams] = useSearchParams()
|
||||
const [activeTab, setActiveTab] = useState(() => loadActiveTab(searchParams.get('tab')))
|
||||
const isAdmin = getAdminRole() === 'admin'
|
||||
const visibleActiveTab = !isAdmin && activeTab === 'notifications' ? 'orders' : activeTab
|
||||
|
||||
useEffect(() => {
|
||||
const tab = searchParams.get('tab')
|
||||
if (isWorkerPlatformTab(tab)) {
|
||||
setActiveTab(tab)
|
||||
}
|
||||
}, [searchParams])
|
||||
|
||||
function changeTab(nextTab: string) {
|
||||
setActiveTab(nextTab)
|
||||
@@ -25,7 +38,7 @@ export default function AdminWorkerPlatformPage() {
|
||||
<SummaryCards />
|
||||
<Tabs
|
||||
destroyOnHidden={false}
|
||||
activeKey={activeTab}
|
||||
activeKey={visibleActiveTab}
|
||||
onChange={changeTab}
|
||||
items={[
|
||||
{ key: 'orders', label: '接单工单', children: <WorkOrdersPanel /> },
|
||||
@@ -34,6 +47,9 @@ export default function AdminWorkerPlatformPage() {
|
||||
{ key: 'workers', label: '打手', children: <WorkersPanel /> },
|
||||
{ key: 'finance', label: '资金', children: <FinancePanel /> },
|
||||
{ key: 'levels', label: '等级权限', children: <LevelsPanel /> },
|
||||
...(isAdmin
|
||||
? [{ key: 'notifications', label: '通知配置', children: <NotificationsPanel /> }]
|
||||
: []),
|
||||
]}
|
||||
/>
|
||||
</section>
|
||||
@@ -49,11 +65,28 @@ function loadActiveTabPreference(): string {
|
||||
saved === 'categories' ||
|
||||
saved === 'workers' ||
|
||||
saved === 'finance' ||
|
||||
saved === 'levels'
|
||||
saved === 'levels' ||
|
||||
saved === 'notifications'
|
||||
? saved
|
||||
: 'orders'
|
||||
}
|
||||
|
||||
function loadActiveTab(tab: string | null): string {
|
||||
return isWorkerPlatformTab(tab) ? tab : loadActiveTabPreference()
|
||||
}
|
||||
|
||||
function isWorkerPlatformTab(tab: string | null): tab is string {
|
||||
return [
|
||||
'orders',
|
||||
'rules',
|
||||
'categories',
|
||||
'workers',
|
||||
'finance',
|
||||
'levels',
|
||||
'notifications',
|
||||
].includes(String(tab || ''))
|
||||
}
|
||||
|
||||
function SummaryCards() {
|
||||
const summaryQuery = useQuery({
|
||||
queryKey: ['admin-worker-platform-summary'],
|
||||
|
||||
@@ -2,6 +2,7 @@ import { ReloadOutlined } from '@ant-design/icons'
|
||||
import { useQuery, useQueryClient } from '@tanstack/react-query'
|
||||
import {
|
||||
App,
|
||||
Alert,
|
||||
Button,
|
||||
Card,
|
||||
Descriptions,
|
||||
@@ -18,6 +19,7 @@ import {
|
||||
} from 'antd'
|
||||
import type { TableColumnsType } from 'antd'
|
||||
import { useEffect, useState } from 'react'
|
||||
import { useSearchParams } from 'react-router'
|
||||
|
||||
import ImageUpload from '@/components/files/ImageUpload'
|
||||
import ImagePreviewList from '@/components/files/ImagePreviewList'
|
||||
@@ -59,9 +61,11 @@ type FinanceReviewAction = 'approved' | 'rejected' | 'cancelled'
|
||||
export default function FinancePanel() {
|
||||
const { message } = App.useApp()
|
||||
const queryClient = useQueryClient()
|
||||
const [searchParams, setSearchParams] = useSearchParams()
|
||||
const [configForm] = Form.useForm<FinanceConfigFormValues>()
|
||||
const [reviewForm] = Form.useForm<{ reviewedNote?: string }>()
|
||||
const [requestStatus, setRequestStatus] = useState('')
|
||||
const [targetRequestId, setTargetRequestId] = useState<number | undefined>()
|
||||
const [requestType, setRequestType] = useState('')
|
||||
const [keywordInput, setKeywordInput] = useState('')
|
||||
const [keyword, setKeyword] = useState('')
|
||||
@@ -79,11 +83,29 @@ export default function FinancePanel() {
|
||||
queryKey: ['admin-worker-platform-finance-config'],
|
||||
queryFn: () => fetchAdminWorkerFinanceConfig(),
|
||||
})
|
||||
useEffect(() => {
|
||||
const requestId = Number(searchParams.get('financeRequestId') || 0)
|
||||
if (!Number.isInteger(requestId) || requestId <= 0) return
|
||||
setTargetRequestId(requestId)
|
||||
setRequestStatus('')
|
||||
setRequestType('')
|
||||
setKeyword('')
|
||||
setKeywordInput('')
|
||||
setPage(1)
|
||||
setSearchParams(
|
||||
(current) => {
|
||||
current.delete('financeRequestId')
|
||||
return current
|
||||
},
|
||||
{ replace: true },
|
||||
)
|
||||
}, [searchParams, setSearchParams])
|
||||
const financeRequestsQuery = useQuery({
|
||||
queryKey: [
|
||||
'admin-worker-platform-finance-requests',
|
||||
requestStatus,
|
||||
requestType,
|
||||
targetRequestId,
|
||||
keyword,
|
||||
page,
|
||||
pageSize,
|
||||
@@ -92,6 +114,7 @@ export default function FinancePanel() {
|
||||
fetchAdminWorkerFinanceRequests({
|
||||
status: requestStatus,
|
||||
requestType,
|
||||
requestId: targetRequestId,
|
||||
keyword,
|
||||
page,
|
||||
pageSize,
|
||||
@@ -274,6 +297,18 @@ export default function FinancePanel() {
|
||||
|
||||
return (
|
||||
<section className="platform-panel-stack">
|
||||
{targetRequestId ? (
|
||||
<Alert
|
||||
type="info"
|
||||
showIcon
|
||||
message={`已定位资金申请 #${targetRequestId}`}
|
||||
action={
|
||||
<Button size="small" onClick={() => setTargetRequestId(undefined)}>
|
||||
取消定位
|
||||
</Button>
|
||||
}
|
||||
/>
|
||||
) : null}
|
||||
<Card
|
||||
title="资金配置"
|
||||
bordered={false}
|
||||
|
||||
@@ -0,0 +1,162 @@
|
||||
import { useQuery, useQueryClient } from '@tanstack/react-query'
|
||||
import { App, Alert, Button, Card, Space, Switch, Table, Typography } from 'antd'
|
||||
import type { TableColumnsType } from 'antd'
|
||||
import { useEffect, useState } from 'react'
|
||||
|
||||
import {
|
||||
fetchAdminWorkerPlatformNotificationConfig,
|
||||
saveAdminWorkerPlatformNotificationConfig,
|
||||
} from '@/services/admin'
|
||||
import type {
|
||||
WorkerPlatformNotificationConfig,
|
||||
WorkerPlatformNotificationEventKey,
|
||||
} from '@/types/worker-platform'
|
||||
|
||||
type NotificationEventRow = {
|
||||
key: WorkerPlatformNotificationEventKey
|
||||
name: string
|
||||
description: string
|
||||
}
|
||||
|
||||
const notificationEventRows: NotificationEventRow[] = [
|
||||
{ key: 'withdraw_requested', name: '提现申请', description: '打手提交新的提现申请' },
|
||||
{ key: 'recharge_requested', name: '充值申请', description: '打手提交新的充值申请' },
|
||||
{ key: 'acceptance_submitted', name: '提交验收', description: '打手提交订单验收资料' },
|
||||
{ key: 'acceptance_reminded', name: '催验收', description: '打手在验收后催促处理' },
|
||||
{ key: 'material_required', name: '待补资料工单', description: '新工单等待后台补充资料' },
|
||||
]
|
||||
|
||||
export default function NotificationsPanel() {
|
||||
const { message } = App.useApp()
|
||||
const queryClient = useQueryClient()
|
||||
const [draft, setDraft] = useState<WorkerPlatformNotificationConfig | null>(null)
|
||||
const [saving, setSaving] = useState(false)
|
||||
const configQuery = useQuery({
|
||||
queryKey: ['admin-worker-platform-notification-config'],
|
||||
queryFn: fetchAdminWorkerPlatformNotificationConfig,
|
||||
})
|
||||
|
||||
useEffect(() => {
|
||||
const config = configQuery.data?.data
|
||||
if (config) {
|
||||
setDraft(config)
|
||||
}
|
||||
}, [configQuery.data])
|
||||
|
||||
function updateEvent(
|
||||
eventKey: WorkerPlatformNotificationEventKey,
|
||||
field: 'todoEnabled' | 'soundEnabled' | 'externalPushEnabled',
|
||||
value: boolean,
|
||||
) {
|
||||
setDraft((current) => {
|
||||
if (!current) return current
|
||||
const event = current.events[eventKey]
|
||||
const nextEvent = { ...event, [field]: value }
|
||||
if (field === 'todoEnabled' && !value) {
|
||||
nextEvent.soundEnabled = false
|
||||
}
|
||||
return {
|
||||
...current,
|
||||
events: { ...current.events, [eventKey]: nextEvent },
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
async function saveConfig() {
|
||||
if (!draft) return
|
||||
setSaving(true)
|
||||
try {
|
||||
await saveAdminWorkerPlatformNotificationConfig(draft)
|
||||
await queryClient.invalidateQueries({
|
||||
queryKey: ['admin-worker-platform-notification-config'],
|
||||
})
|
||||
message.success('通知配置已保存')
|
||||
} catch (error) {
|
||||
message.error(error instanceof Error ? error.message : '保存通知配置失败')
|
||||
} finally {
|
||||
setSaving(false)
|
||||
}
|
||||
}
|
||||
|
||||
const columns: TableColumnsType<NotificationEventRow> = [
|
||||
{
|
||||
title: '通知事件',
|
||||
dataIndex: 'name',
|
||||
minWidth: 220,
|
||||
render: (_, row) => (
|
||||
<div className="cell-stack">
|
||||
<Typography.Text strong>{row.name}</Typography.Text>
|
||||
<Typography.Text type="secondary">{row.description}</Typography.Text>
|
||||
</div>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: '后台待办',
|
||||
width: 130,
|
||||
align: 'center',
|
||||
render: (_, row) => (
|
||||
<Switch
|
||||
checked={draft?.events[row.key].todoEnabled || false}
|
||||
disabled={!draft || saving}
|
||||
onChange={(checked) => updateEvent(row.key, 'todoEnabled', checked)}
|
||||
/>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: '声音播报',
|
||||
width: 130,
|
||||
align: 'center',
|
||||
render: (_, row) => (
|
||||
<Switch
|
||||
checked={draft?.events[row.key].soundEnabled || false}
|
||||
disabled={!draft?.events[row.key].todoEnabled || saving}
|
||||
onChange={(checked) => updateEvent(row.key, 'soundEnabled', checked)}
|
||||
/>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: 'Bark/WPush',
|
||||
width: 140,
|
||||
align: 'center',
|
||||
render: (_, row) => (
|
||||
<Switch
|
||||
checked={draft?.events[row.key].externalPushEnabled || false}
|
||||
disabled={!draft || saving}
|
||||
onChange={(checked) => updateEvent(row.key, 'externalPushEnabled', checked)}
|
||||
/>
|
||||
),
|
||||
},
|
||||
]
|
||||
|
||||
return (
|
||||
<Card size="small" bordered={false}>
|
||||
<Space direction="vertical" size={16} style={{ width: '100%' }}>
|
||||
<Alert
|
||||
type="info"
|
||||
showIcon
|
||||
message="配置仅影响保存后产生的通知"
|
||||
description="关闭后台待办后,声音播报会同步关闭;已创建的待办不会被隐藏或删除。"
|
||||
/>
|
||||
<Table
|
||||
rowKey="key"
|
||||
columns={columns}
|
||||
dataSource={notificationEventRows}
|
||||
pagination={false}
|
||||
loading={configQuery.isLoading}
|
||||
scroll={{ x: 660 }}
|
||||
/>
|
||||
<Space>
|
||||
<Button
|
||||
type="primary"
|
||||
loading={saving}
|
||||
disabled={!draft}
|
||||
onClick={() => void saveConfig()}
|
||||
>
|
||||
保存配置
|
||||
</Button>
|
||||
<Typography.Text type="secondary">浏览器总声音开关仍可在后台右上角控制。</Typography.Text>
|
||||
</Space>
|
||||
</Space>
|
||||
</Card>
|
||||
)
|
||||
}
|
||||
@@ -37,7 +37,7 @@ import {
|
||||
} from 'antd'
|
||||
import type { TableColumnsType } from 'antd'
|
||||
import { useEffect, useRef, useState } from 'react'
|
||||
import { useNavigate } from 'react-router'
|
||||
import { useNavigate, useSearchParams } from 'react-router'
|
||||
|
||||
import JsonPreview from '@/components/admin/JsonPreview'
|
||||
import WorkOrderEventTimeline from '@/components/WorkOrderEventTimeline'
|
||||
@@ -116,9 +116,11 @@ type CancelOrderFormValues = {
|
||||
export default function WorkOrdersPanel() {
|
||||
const { message, modal } = App.useApp()
|
||||
const navigate = useNavigate()
|
||||
const [searchParams, setSearchParams] = useSearchParams()
|
||||
const queryClient = useQueryClient()
|
||||
const canEditRequirementFields = hasAdminRole('operator')
|
||||
const [statuses, setStatuses] = useState<string[]>([])
|
||||
const [targetWorkOrderId, setTargetWorkOrderId] = useState<number | undefined>()
|
||||
const [keyword, setKeyword] = useState('')
|
||||
const [keywordInput, setKeywordInput] = useState('')
|
||||
const [workerId, setWorkerId] = useState<number | undefined>()
|
||||
@@ -165,12 +167,31 @@ export default function WorkOrdersPanel() {
|
||||
)
|
||||
const vipEvidencePending = statuses.includes(VIP_EVIDENCE_PENDING_STATUS)
|
||||
|
||||
useEffect(() => {
|
||||
const workOrderId = Number(searchParams.get('workOrderId') || 0)
|
||||
if (!Number.isInteger(workOrderId) || workOrderId <= 0) return
|
||||
setTargetWorkOrderId(workOrderId)
|
||||
setStatuses([])
|
||||
setKeyword('')
|
||||
setKeywordInput('')
|
||||
setWorkerId(undefined)
|
||||
setPage(1)
|
||||
setSearchParams(
|
||||
(current) => {
|
||||
current.delete('workOrderId')
|
||||
return current
|
||||
},
|
||||
{ replace: true },
|
||||
)
|
||||
}, [searchParams, setSearchParams])
|
||||
|
||||
const ordersQuery = useQuery({
|
||||
queryKey: [
|
||||
'admin-worker-platform-orders',
|
||||
statuses.join(','),
|
||||
keyword,
|
||||
workerId,
|
||||
targetWorkOrderId,
|
||||
page,
|
||||
pageSize,
|
||||
],
|
||||
@@ -179,6 +200,7 @@ export default function WorkOrdersPanel() {
|
||||
status:
|
||||
selectedWorkOrderStatuses.length > 0 ? selectedWorkOrderStatuses.join(',') : undefined,
|
||||
vipEvidencePending: vipEvidencePending || undefined,
|
||||
workOrderId: targetWorkOrderId,
|
||||
keyword,
|
||||
workerId,
|
||||
page,
|
||||
@@ -207,7 +229,7 @@ export default function WorkOrdersPanel() {
|
||||
|
||||
useEffect(() => {
|
||||
setSelectedAcceptanceOrderIds([])
|
||||
}, [statuses, keyword, workerId, page, pageSize])
|
||||
}, [statuses, keyword, workerId, targetWorkOrderId, page, pageSize])
|
||||
|
||||
function openAssignModal(row: WorkOrder) {
|
||||
setAssignOrder(row)
|
||||
@@ -482,6 +504,7 @@ export default function WorkOrdersPanel() {
|
||||
}
|
||||
|
||||
function clearOrderFilters() {
|
||||
setTargetWorkOrderId(undefined)
|
||||
setKeywordInput('')
|
||||
setKeyword('')
|
||||
setStatuses([])
|
||||
@@ -865,6 +888,18 @@ export default function WorkOrdersPanel() {
|
||||
|
||||
return (
|
||||
<section className="platform-panel-stack">
|
||||
{targetWorkOrderId ? (
|
||||
<Alert
|
||||
type="info"
|
||||
showIcon
|
||||
message={`已定位工单 #${targetWorkOrderId}`}
|
||||
action={
|
||||
<Button size="small" onClick={() => setTargetWorkOrderId(undefined)}>
|
||||
取消定位
|
||||
</Button>
|
||||
}
|
||||
/>
|
||||
) : null}
|
||||
<Card title="订单搜索与筛选" bordered={false}>
|
||||
<div className="worker-orders-toolbar">
|
||||
<Space wrap className="filter-form worker-orders-search-controls">
|
||||
|
||||
@@ -37,6 +37,7 @@ import {
|
||||
fetchWorkerMyOrderOverview,
|
||||
fetchWorkerMyOrders,
|
||||
fetchWorkerProfile,
|
||||
remindWorkerAcceptance,
|
||||
saveWorkerAcceptanceDraft,
|
||||
saveWorkerOrderNote,
|
||||
supplementWorkerAcceptedOrderEvidence,
|
||||
@@ -300,6 +301,16 @@ export default function WorkerOrdersPage() {
|
||||
}
|
||||
}
|
||||
|
||||
async function submitAcceptanceReminder(order: WorkOrder) {
|
||||
try {
|
||||
await remindWorkerAcceptance(order.workOrderId)
|
||||
message.success('已催促管理员验收')
|
||||
await refreshAll()
|
||||
} catch (error) {
|
||||
message.error(error instanceof Error ? error.message : '催验收失败')
|
||||
}
|
||||
}
|
||||
|
||||
async function submitAcceptance(values: AcceptanceFormValues) {
|
||||
if (!editingOrder) return
|
||||
const isAcceptedEvidenceSupplement = canSupplementAcceptedEvidence(editingOrder)
|
||||
@@ -597,6 +608,9 @@ export default function WorkerOrdersPage() {
|
||||
{hasSubmittedAcceptance(row) ? '补充图片' : '验收'}
|
||||
</Button>
|
||||
) : null}
|
||||
{canRemindAcceptance(row) ? (
|
||||
<Button onClick={() => submitAcceptanceReminder(row)}>催验收</Button>
|
||||
) : null}
|
||||
</Space>
|
||||
</div>
|
||||
),
|
||||
@@ -893,6 +907,11 @@ export default function WorkerOrdersPage() {
|
||||
{hasSubmittedAcceptance(order) ? '补充图片' : '提交验收'}
|
||||
</Button>
|
||||
) : null}
|
||||
{canRemindAcceptance(order) ? (
|
||||
<Button size="small" onClick={() => submitAcceptanceReminder(order)}>
|
||||
催验收
|
||||
</Button>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
</article>
|
||||
@@ -1292,6 +1311,10 @@ function canSubmitAcceptance(order: WorkOrder) {
|
||||
return ['in_progress', 'problem'].includes(order.status)
|
||||
}
|
||||
|
||||
function canRemindAcceptance(order: WorkOrder) {
|
||||
return !order.myShare && order.status === 'pending_acceptance'
|
||||
}
|
||||
|
||||
function canAutoAcceptOrder(order: WorkOrder, workerCanAutoAcceptWithoutEvidence: boolean) {
|
||||
return (
|
||||
workerCanAutoAcceptWithoutEvidence &&
|
||||
|
||||
@@ -7,4 +7,5 @@ export * from './kuaishou-industry'
|
||||
export * from './orders'
|
||||
export * from './tasks'
|
||||
export * from './dev-mock'
|
||||
export * from './notifications'
|
||||
export * from './worker-platform'
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
import { apiGet } from '@/lib/http'
|
||||
|
||||
export type AdminNotification = {
|
||||
notificationId: number
|
||||
notificationType: string
|
||||
priority: 'normal' | 'high' | 'urgent' | string
|
||||
entityType: string
|
||||
entityId: number
|
||||
title: string
|
||||
body: string
|
||||
actionPath: string
|
||||
reminderCount: number
|
||||
soundEnabled: boolean
|
||||
lastRemindedAt: string | null
|
||||
createdAt: string
|
||||
updatedAt: string
|
||||
}
|
||||
|
||||
export function fetchAdminNotifications() {
|
||||
return apiGet<{ pendingCount: number; items: AdminNotification[] }>('/api/v1/admin/notifications')
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import type {
|
||||
WorkProductRule,
|
||||
WorkerFinanceConfig,
|
||||
WorkerFinanceRequest,
|
||||
WorkerPlatformNotificationConfig,
|
||||
WorkerLevel,
|
||||
WorkerListResponse,
|
||||
WorkerUser,
|
||||
@@ -203,6 +204,21 @@ export function saveAdminWorkerFinanceConfig(payload: {
|
||||
return apiPost<WorkerFinanceConfig>('/api/v1/admin/worker-platform/finance-config', payload)
|
||||
}
|
||||
|
||||
export function fetchAdminWorkerPlatformNotificationConfig() {
|
||||
return apiGet<WorkerPlatformNotificationConfig>(
|
||||
'/api/v1/admin/worker-platform/notification-config',
|
||||
)
|
||||
}
|
||||
|
||||
export function saveAdminWorkerPlatformNotificationConfig(
|
||||
payload: WorkerPlatformNotificationConfig,
|
||||
) {
|
||||
return apiPost<WorkerPlatformNotificationConfig>(
|
||||
'/api/v1/admin/worker-platform/notification-config',
|
||||
payload,
|
||||
)
|
||||
}
|
||||
|
||||
export function fetchAdminWorkerFinanceRequests(params?: Record<string, unknown>) {
|
||||
return apiGet<WorkerListResponse<WorkerFinanceRequest>>(
|
||||
'/api/v1/admin/worker-platform/finance-requests',
|
||||
|
||||
@@ -154,6 +154,12 @@ export function submitWorkerAcceptance(
|
||||
)
|
||||
}
|
||||
|
||||
export function remindWorkerAcceptance(workOrderId: number) {
|
||||
return apiPost<{ reminderCount: number; nextRemindAt: string }>(
|
||||
`/api/v1/worker/orders/${workOrderId}/remind-acceptance`,
|
||||
)
|
||||
}
|
||||
|
||||
export function saveWorkerAcceptanceDraft(
|
||||
workOrderId: number,
|
||||
payload: { note?: string; imageUrls?: string[]; files?: UploadedFile[] },
|
||||
|
||||
@@ -449,6 +449,36 @@
|
||||
margin-left: auto;
|
||||
}
|
||||
|
||||
.admin-sound-muted {
|
||||
opacity: 0.45;
|
||||
}
|
||||
|
||||
.admin-notification-popover {
|
||||
width: min(380px, calc(100vw - 32px));
|
||||
}
|
||||
|
||||
.admin-notification-item {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.admin-notification-item .ant-list-item-meta,
|
||||
.admin-notification-item > div {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.admin-notification-item .ant-typography {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.admin-notification-priority {
|
||||
color: #cf1322;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.admin-notification-time {
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.admin-user-copy {
|
||||
display: grid;
|
||||
justify-items: end;
|
||||
|
||||
@@ -106,6 +106,24 @@ export type WorkerFinanceConfig = {
|
||||
}
|
||||
}
|
||||
|
||||
export type WorkerPlatformNotificationEventKey =
|
||||
| 'withdraw_requested'
|
||||
| 'recharge_requested'
|
||||
| 'acceptance_submitted'
|
||||
| 'acceptance_reminded'
|
||||
| 'material_required'
|
||||
|
||||
export type WorkerPlatformNotificationConfig = {
|
||||
events: Record<
|
||||
WorkerPlatformNotificationEventKey,
|
||||
{
|
||||
todoEnabled: boolean
|
||||
soundEnabled: boolean
|
||||
externalPushEnabled: boolean
|
||||
}
|
||||
>
|
||||
}
|
||||
|
||||
export type WorkerWithdrawalAccount = {
|
||||
accountChannel: string
|
||||
accountName: string
|
||||
|
||||
Reference in New Issue
Block a user