功能(接单平台): 为普通运营增加杂项配置权限
This commit is contained in:
@@ -5,9 +5,10 @@ import { useLocation, useSearchParams } from 'react-router'
|
||||
|
||||
import PageHeader from '@/components/admin/PageHeader'
|
||||
import type { WorkOrder } from '@/types/worker-platform'
|
||||
import { fetchAdminWorkerPlatformSummary } from '@/services/admin'
|
||||
import { getAdminRole, hasAdminPermission } from '@/utils/admin-auth'
|
||||
import { fetchAdminSession, fetchAdminWorkerPlatformSummary } from '@/services/admin'
|
||||
import { getAdminRole, hasAdminPermission, resolveAdminPermission } from '@/utils/admin-auth'
|
||||
import {
|
||||
WORKER_PLATFORM_MISC_CONFIG_PERMISSION,
|
||||
WORKER_PLATFORM_TAB_QUERY_KEYS as TAB_QUERY_KEYS,
|
||||
isWorkerPlatformTab,
|
||||
} from '@/utils/admin-worker-platform-tabs'
|
||||
@@ -52,6 +53,17 @@ export default function AdminWorkerPlatformPage() {
|
||||
const isAdmin = role === 'admin'
|
||||
const isSupport = role === 'support'
|
||||
const isFinance = role === 'finance'
|
||||
const adminSessionQuery = useQuery({
|
||||
queryKey: ['admin-session'],
|
||||
queryFn: fetchAdminSession,
|
||||
retry: false,
|
||||
})
|
||||
const canManageMiscConfig =
|
||||
isAdmin ||
|
||||
resolveAdminPermission(
|
||||
adminSessionQuery.data?.data.user?.permissions,
|
||||
WORKER_PLATFORM_MISC_CONFIG_PERMISSION,
|
||||
)
|
||||
const canViewConsignment = hasAdminPermission('consignment.view')
|
||||
const isConsignmentTab =
|
||||
activeTab === 'consignment-inventory' ||
|
||||
@@ -63,9 +75,11 @@ export default function AdminWorkerPlatformPage() {
|
||||
? 'finance'
|
||||
: !isAdmin && activeTab === 'notifications'
|
||||
? 'orders'
|
||||
: !canViewConsignment && isConsignmentTab
|
||||
: !canManageMiscConfig && activeTab === 'announcement'
|
||||
? 'orders'
|
||||
: activeTab
|
||||
: !canViewConsignment && isConsignmentTab
|
||||
? 'orders'
|
||||
: activeTab
|
||||
|
||||
// 切换标签页时自动刷新对应标签页的查询数据,确保切入即为最新状态
|
||||
useEffect(() => {
|
||||
@@ -123,6 +137,9 @@ export default function AdminWorkerPlatformPage() {
|
||||
label: '售后问题单',
|
||||
children: <AfterSalesPanel ref={afterSalesPanelRef} />,
|
||||
}
|
||||
const miscConfigTab = canManageMiscConfig
|
||||
? [{ key: 'announcement', label: '杂项配置', children: <AnnouncementPanel /> }]
|
||||
: []
|
||||
|
||||
// 寄卖相关 tab 按权限渲染:后端所有寄卖接口都挂了 requireAdminPermission,
|
||||
// 没有 consignment.view 的人看到 tab 只会一路 403。
|
||||
@@ -172,6 +189,7 @@ export default function AdminWorkerPlatformPage() {
|
||||
{ key: 'feedbacks', label: '问题反馈', children: <FeedbacksPanel /> },
|
||||
{ key: 'invite-codes', label: '邀请码', children: <InviteCodesPanel /> },
|
||||
afterSalesTab,
|
||||
...miscConfigTab,
|
||||
]
|
||||
: [
|
||||
{ key: 'orders', label: '接单工单', children: <WorkOrdersPanel /> },
|
||||
@@ -183,9 +201,7 @@ export default function AdminWorkerPlatformPage() {
|
||||
},
|
||||
{ key: 'feedbacks', label: '问题反馈', children: <FeedbacksPanel /> },
|
||||
afterSalesTab,
|
||||
...(isAdmin
|
||||
? [{ key: 'announcement', label: '杂项配置', children: <AnnouncementPanel /> }]
|
||||
: []),
|
||||
...miscConfigTab,
|
||||
{ key: 'rules', label: '接单模板', children: <ProductRulesPanel /> },
|
||||
{ key: 'order-service', label: '订单服务', children: <OrderServicePanel /> },
|
||||
{
|
||||
|
||||
@@ -2,12 +2,12 @@ import { apiGet, apiPost } from '@/lib/http'
|
||||
import type { AdminScheduledJobsConfig, AdminScheduledJobsResponse } from '@/types/admin'
|
||||
|
||||
export function fetchAdminScheduledJobsConfig() {
|
||||
return apiGet<AdminScheduledJobsResponse>('/api/v1/admin/platform-config/scheduled-jobs')
|
||||
return apiGet<AdminScheduledJobsResponse>('/api/v1/admin/worker-platform/scheduled-jobs')
|
||||
}
|
||||
|
||||
export function saveAdminScheduledJobsConfig(payload: AdminScheduledJobsConfig) {
|
||||
return apiPost<AdminScheduledJobsResponse>(
|
||||
'/api/v1/admin/platform-config/scheduled-jobs',
|
||||
'/api/v1/admin/worker-platform/scheduled-jobs',
|
||||
payload,
|
||||
)
|
||||
}
|
||||
@@ -16,5 +16,5 @@ export function runAdminScheduledJob(jobId: string) {
|
||||
return apiPost<{
|
||||
result: Record<string, unknown>
|
||||
runtime: AdminScheduledJobsResponse['runtime']
|
||||
}>(`/api/v1/admin/platform-config/scheduled-jobs/${jobId}/run`, {})
|
||||
}>(`/api/v1/admin/worker-platform/scheduled-jobs/${jobId}/run`, {})
|
||||
}
|
||||
|
||||
@@ -11,6 +11,8 @@
|
||||
*/
|
||||
|
||||
/** 所有可作为 tab 的 key(新增 tab 只改这里)。 */
|
||||
export const WORKER_PLATFORM_MISC_CONFIG_PERMISSION = 'worker_platform.misc_config'
|
||||
|
||||
export const WORKER_PLATFORM_TAB_KEYS: readonly string[] = [
|
||||
'orders',
|
||||
'consignment-inventory',
|
||||
@@ -84,3 +86,7 @@ export const WORKER_PLATFORM_NON_TAB_QUERY_KEYS: readonly string[] = ['hall-conf
|
||||
export function isWorkerPlatformTab(tab: string | null): tab is string {
|
||||
return WORKER_PLATFORM_TAB_KEYS.includes(String(tab || ''))
|
||||
}
|
||||
|
||||
export function canManageWorkerPlatformMiscConfig(role: string | null | undefined) {
|
||||
return role === 'admin' || role === 'operator'
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ import assert from 'node:assert/strict'
|
||||
import test from 'node:test'
|
||||
|
||||
import {
|
||||
WORKER_PLATFORM_MISC_CONFIG_PERMISSION,
|
||||
WORKER_PLATFORM_NON_TAB_QUERY_KEYS,
|
||||
WORKER_PLATFORM_TAB_KEYS,
|
||||
WORKER_PLATFORM_TAB_QUERY_KEYS,
|
||||
@@ -58,3 +59,7 @@ test('名单里的每个 key 都能被自身校验通过', () => {
|
||||
assert.equal(isWorkerPlatformTab(key), true, `${key} 应可通过校验`)
|
||||
}
|
||||
})
|
||||
|
||||
test('杂项配置使用独立权限点,并默认由角色权限表授权', () => {
|
||||
assert.equal(WORKER_PLATFORM_MISC_CONFIG_PERMISSION, 'worker_platform.misc_config')
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user