feat(user): 补充开发者审核通过时添加店员记录功能

- 引入 addShopStoreUser 接口用于新增门店店员记录
- 新增 clerkStoreId 和 clerkTenantId 状态,保存当前审核店员的门店和租户信息
- 在审核通过后调用 addShopStoreUser,添加申请人为当前门店店员
- 保证只有当 clerkStoreId 存在时才执行新增操作
- 调整平台管理页 UI,使其与门店中心保持一致风格
- 门店中心及平台管理入口权限调整,仅超级管理员可访问
- 用户菜单中平台管理和门店中心入口现基于 isSuperAdmin 字段控制
- 优化登录及权限校验流程,避免权限不足时页面闪烁显示
- 更新工作记录文档,补充审核通过流程中新添加的店员记录步骤
This commit is contained in:
2026-07-23 18:25:35 +08:00
parent babcf36439
commit 9fba545d34
7 changed files with 318 additions and 114 deletions

View File

@@ -1,104 +1,241 @@
import React, { useState, useEffect, useCallback } from 'react'
import { View, Text, ScrollView } from '@tarojs/components'
import { View, Text, Image } from '@tarojs/components'
import Taro from '@tarojs/taro'
import NavBar from '@/components/NavBar'
import StatCard from '@/components/common/StatCard'
import EntryGrid from '@/components/common/EntryGrid'
import Loading from '@/components/common/Loading'
import { useUser } from '@/hooks/useUser'
import { pageAllApps, pagePublishReviews } from '@/api/app/appProduct'
import { getAllTickets } from '@/api/app/ticket'
import { pageUsers } from '@/api/system/user'
import { getPageTotal } from '@/utils/devcenter'
import { getPageTotal, getPageList } from '@/utils/devcenter'
import Badge from '@/components/common/Badge'
definePageConfig({ navigationBarTitleText: '平台管理' })
definePageConfig({
navigationBarTitleText: '平台管理',
})
const AdminCenterPage: React.FC = () => {
const { user, isLoggedIn } = useUser()
const isAdmin = !!(user as any)?.isAdmin
const [loading, setLoading] = useState(true)
const [stats, setStats] = useState({ apps: 0, pending: 0, tickets: 0, users: 0 })
// 功能卡片定义(与门店中心同款结构:图标 + 标题 + 描述 + 角标 + 跳转)
const FEATURE_CARDS = [
{
key: 'app-review',
icon: '📝',
title: '应用审核',
desc: '审核开发者提交的应用上架',
url: '/pages/admin/app-review/index',
color: '#3b82f6',
bgColor: '#dbeafe',
showBadge: true,
},
{
key: 'git-review',
icon: '🐙',
title: 'Git 审核',
desc: '审核 Git 仓库接入申请',
url: '/pages/admin/git-review/index',
color: '#8b5cf6',
bgColor: '#ede9fe',
showBadge: false,
},
{
key: 'domain-review',
icon: '🌐',
title: '域名审核',
desc: '审核自定义域名绑定',
url: '/pages/admin/domain-review/index',
color: '#0891b2',
bgColor: '#cffafe',
showBadge: false,
},
{
key: 'tickets',
icon: '🎫',
title: '工单处理',
desc: '处理用户提交的工单',
url: '/pages/admin/tickets/index',
color: '#f59e0b',
bgColor: '#fef3c7',
showBadge: true,
},
]
export default function AdminCenterPage() {
const { user, isLoggedIn, loading: userLoading } = useUser()
const isSuperAdmin = (user as any)?.isSuperAdmin === 1
const [dataLoading, setDataLoading] = useState(true)
const [pendingApps, setPendingApps] = useState(0)
const [pendingTickets, setPendingTickets] = useState(0)
const [overview, setOverview] = useState({ apps: 0, users: 0, tickets: 0 })
useEffect(() => {
if (isLoggedIn && isSuperAdmin) {
load()
} else {
setDataLoading(false)
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [isLoggedIn, isSuperAdmin])
/** 加载角标数量与平台概况 */
const load = useCallback(async () => {
setLoading(true)
setDataLoading(true)
try {
const [appsR, pendR, tickR, usersR] = await Promise.allSettled([
const [appsR, pendR, allR, usersR] = await Promise.allSettled([
pageAllApps({ page: 1, limit: 1 }),
pagePublishReviews({ page: 1, limit: 1 }),
getAllTickets({ page: 1, limit: 1 }),
getAllTickets({ page: 1, limit: 100 }),
pageUsers({ page: 1, limit: 1 } as any),
])
const apps = appsR.status === 'fulfilled' ? getPageTotal(appsR.value) : 0
const pending = pendR.status === 'fulfilled' ? getPageTotal(pendR.value) : 0
const tickets = tickR.status === 'fulfilled' ? getPageTotal(tickR.value) : 0
const users = usersR.status === 'fulfilled' ? getPageTotal(usersR.value) : 0
setStats({ apps, pending, tickets, users })
} catch (e) {
// 待审核应用pagePublishReviews 已按 pending_review 过滤)
const pendingAppsCount = pendR.status === 'fulfilled' ? getPageTotal(pendR.value) : 0
setPendingApps(pendingAppsCount)
// 工单:总数 + 待处理(未解决/未关闭)
const ticketData = allR.status === 'fulfilled' ? allR.value : null
const ticketList = ticketData ? getPageList(ticketData) : []
const pendingTicketsCount = ticketList.filter(
(t: any) => t.status !== 'resolved' && t.status !== 'closed'
).length
setPendingTickets(pendingTicketsCount)
const appsTotal = appsR.status === 'fulfilled' ? getPageTotal(appsR.value) : 0
const ticketsTotal = ticketData ? getPageTotal(ticketData) : 0
const usersTotal = usersR.status === 'fulfilled' ? getPageTotal(usersR.value) : 0
setOverview({ apps: appsTotal, users: usersTotal, tickets: ticketsTotal })
} catch {
// ignore
} finally {
setLoading(false)
setDataLoading(false)
}
}, [])
useEffect(() => {
if (isLoggedIn) load()
}, [isLoggedIn, load])
/** 获取卡片角标数字 */
const getBadgeCount = (key: string) => {
if (key === 'app-review') return pendingApps
if (key === 'tickets') return pendingTickets
return 0
}
if (userLoading || dataLoading) {
return (
<View className='min-h-full bg-gray-50 flex items-center justify-center'>
<Text className='text-gray-400'>...</Text>
</View>
)
}
if (!isLoggedIn) {
return (
<View className='min-h-screen bg-gray-100'>
<NavBar title='平台管理' />
<View className='flex flex-col items-center justify-center py-24'>
<Text className='text-gray-400 text-sm'></Text>
</View>
<View className='min-h-full bg-gray-50 flex flex-col items-center justify-center py-24'>
<Text className='text-5xl mb-3'>🔐</Text>
<Text className='text-base text-gray-700 mb-2'></Text>
<Text className='text-xs text-gray-400 text-center'></Text>
</View>
)
}
if (!isAdmin) {
if (!isSuperAdmin) {
return (
<View className='min-h-screen bg-gray-100'>
<NavBar title='平台管理' />
<View className='flex flex-col items-center justify-center py-20 px-10'>
<Text className='text-5xl mb-3'>🛡</Text>
<Text className='text-base text-gray-700 mb-2'>访</Text>
<Text className='text-xs text-gray-400 text-center'></Text>
</View>
<View className='min-h-full bg-gray-50 flex flex-col items-center justify-center py-20 px-10'>
<Text className='text-5xl mb-3'>🛡</Text>
<Text className='text-base text-gray-700 mb-2'>访</Text>
<Text className='text-xs text-gray-400 text-center'></Text>
</View>
)
}
const entries = [
{ icon: '📝', label: '应用审核', url: '/pages/admin/app-review/index' },
{ icon: '🐙', label: 'Git 审核', url: '/pages/admin/git-review/index' },
{ icon: '🌐', label: '域名审核', url: '/pages/admin/domain-review/index' },
{ icon: '🎫', label: '工单处理', url: '/pages/admin/tickets/index' },
]
const adminName = (user as any)?.nickname || (user as any)?.username || '平台管理员'
const adminPhone = (user as any)?.phone
return (
<View className='min-h-screen bg-gray-100'>
<NavBar title='平台管理' />
<ScrollView scrollY>
{loading ? (
<Loading />
) : (
<View className='p-4'>
<View className='grid grid-cols-2 gap-3 mb-3'>
<StatCard label='应用总数' value={stats.apps} color='#3b82f6' />
<StatCard label='待审核应用' value={stats.pending} color='#f59e0b' sub={stats.pending > 0 ? '需处理' : undefined} subColor='#f59e0b' />
</View>
<View className='grid grid-cols-2 gap-3 mb-3'>
<StatCard label='工单总数' value={stats.tickets} color='#10b981' />
<StatCard label='用户总数' value={stats.users} color='#8b5cf6' />
</View>
<Text className='text-base font-medium mb-2 block'></Text>
<EntryGrid items={entries} columns={4} />
<View className='h-6' />
<View className='min-h-full bg-gray-50'>
{/* 顶部信息区:管理员头像 + 平台名称(与门店中心同款渐变头部) */}
<View
className='pt-8 pb-12 px-5 rounded-b-3xl relative overflow-hidden'
style={{ background: 'linear-gradient(135deg, #15803d 0%, #22c55e 60%, #4ade80 100%)' }}
>
<View className='absolute -top-10 -right-10 w-40 h-40 rounded-full opacity-10'
style={{ background: 'radial-gradient(circle, #ffffff, transparent)' }} />
<View className='absolute -bottom-6 -left-6 w-24 h-24 rounded-full opacity-15'
style={{ background: 'radial-gradient(circle, #ffffff, transparent)' }} />
<View className='relative z-10 flex items-center gap-4'>
{/* 管理员头像 */}
<View className='w-16 h-16 rounded-full bg-white/20 border-2 border-white/40 overflow-hidden flex-shrink-0'>
{((user as any)?.avatar) ? (
<Image
className='w-full h-full'
src={(user as any).avatar}
mode='aspectFill'
/>
) : (
<View className='w-full h-full flex items-center justify-center'>
<Text className='text-2xl'>👤</Text>
</View>
)}
</View>
)}
</ScrollView>
{/* 平台信息 */}
<View className='flex-1 min-w-0'>
<Text className='text-white text-lg font-bold block truncate'>
</Text>
<Text className='text-white text-opacity-80 text-sm mt-1 block truncate'>
{adminName}{adminPhone ? ` · ${adminPhone}` : ''}
</Text>
</View>
</View>
</View>
{/* 功能卡片区(与门店中心同款) */}
<View className='mx-3 -mt-6 relative z-20'>
<View className='flex flex-col gap-3'>
{FEATURE_CARDS.map(card => (
<View
key={card.key}
className='bg-white rounded-xl p-4 flex items-center gap-4 active:opacity-80 relative'
onClick={() => Taro.navigateTo({ url: card.url })}
>
{/* 图标 */}
<View
className='w-12 h-12 rounded-xl flex items-center justify-center flex-shrink-0'
style={{ background: card.bgColor }}
>
<Text className='text-2xl'>{card.icon}</Text>
</View>
{/* 文字 */}
<View className='flex-1 min-w-0'>
<Text className='text-gray-800 text-base font-medium block'>{card.title}</Text>
<Text className='text-gray-400 text-xs mt-0.5 block'>{card.desc}</Text>
</View>
{/* 待处理角标 */}
{card.showBadge && (
<Badge count={getBadgeCount(card.key)} className='absolute -top-1 -right-1' size={20} fontSize={11} fontWeight='bold' />
)}
{/* 箭头 */}
<Text className='text-gray-300 text-lg flex-shrink-0'></Text>
</View>
))}
</View>
</View>
{/* 底部:平台概况(保留原页面统计信息,沿用同款卡片样式) */}
<View className='mx-3 mt-6 mb-6'>
<View className='bg-white rounded-xl p-4 flex items-center gap-3'>
<View className='w-10 h-10 rounded-full bg-green-50 flex items-center justify-center flex-shrink-0'>
<Text className='text-xl'>📊</Text>
</View>
<View className='flex-1 min-w-0'>
<Text className='text-gray-800 text-sm font-medium block'></Text>
<Text className='text-gray-400 text-xs mt-0.5 block'>
{overview.apps} · {overview.users} · {overview.tickets}
</Text>
</View>
</View>
</View>
</View>
)
}
export default AdminCenterPage

View File

@@ -255,8 +255,8 @@ const IndexPage: React.FC = () => {
</View>
<ScrollView scrollY style={{ height: scrollHeight }}>
{/* 角色工作台入口:仅开发者 / 平台管理员可见 */}
{(isLoggedIn && ((user as any)?.isDeveloper || (user as any)?.isAdmin)) && (
{/* 角色工作台入口:仅开发者 / 平台管理员 / 超级管理员可见 */}
{(isLoggedIn && ((user as any)?.isDeveloper || (user as any)?.isAdmin || (user as any)?.isSuperAdmin === 1)) && (
<View className='mx-3 mt-2 grid grid-cols-2 gap-2'>
{(user as any)?.isDeveloper && (
<View
@@ -268,7 +268,7 @@ const IndexPage: React.FC = () => {
<Text className='text-sm font-medium text-blue-700'></Text>
</View>
)}
{(user as any)?.isAdmin && (
{(user as any)?.isSuperAdmin === 1 && (
<View
className='flex items-center justify-center py-3 rounded-lg border border-purple-100'
style={{ background: 'linear-gradient(135deg, #f5f3ff 0%, #ede9fe 100%)' }}

View File

@@ -5,6 +5,7 @@ import { getMyClerk } from '@/api/shop/shopStoreUser'
import { listShopDealerApply } from '@/api/shop/shopDealerApply'
import { pageShopOrder } from '@/api/shop/shopOrder'
import Badge from '@/components/common/Badge'
import { useUser } from '@/hooks/useUser'
definePageConfig({
navigationBarTitleText: '门店中心',
@@ -61,30 +62,28 @@ const SUBSCRIBE_TMPL_IDS = [
]
export default function StoreCenterPage() {
const { user, isLoggedIn, loading: userLoading } = useUser()
const isSuperAdmin = (user as any)?.isSuperAdmin === 1
const [storeInfo, setStoreInfo] = useState<any>(null)
const [pendingVipCount, setPendingVipCount] = useState(0)
const [pendingOrderCount, setPendingOrderCount] = useState(0)
const [loading, setLoading] = useState(true)
useEffect(() => {
// 验证店员身份
getMyClerk()
.then(data => {
if (!data) {
Taro.showToast({ title: '仅门店店员可访问', icon: 'none' })
setTimeout(() => Taro.navigateBack(), 1500)
return
}
setStoreInfo(data)
// 加载待审核数量
loadBadgeCounts()
})
.catch(() => {
Taro.showToast({ title: '仅门店店员可访问', icon: 'none' })
// 仅超级管理员可访问
if (!isLoggedIn || !isSuperAdmin) {
if (isLoggedIn && !isSuperAdmin) {
Taro.showToast({ title: '仅超级管理员可访问', icon: 'none' })
setTimeout(() => Taro.navigateBack(), 1500)
})
.finally(() => setLoading(false))
}, [])
}
return
}
// 超管若同时具备店员身份,加载门店信息用于头部展示(非必须)
getMyClerk()
.then(data => setStoreInfo(data || null))
.catch(() => setStoreInfo(null))
// 加载待审核数量
loadBadgeCounts()
}, [isLoggedIn, isSuperAdmin])
/** 加载各类待处理角标数量 */
const loadBadgeCounts = async () => {
@@ -140,7 +139,7 @@ export default function StoreCenterPage() {
})
}, [])
if (loading) {
if (userLoading) {
return (
<View className='min-h-full bg-gray-50 flex items-center justify-center'>
<Text className='text-gray-400'>...</Text>
@@ -148,12 +147,43 @@ export default function StoreCenterPage() {
)
}
if (!storeInfo) return null
if (!isLoggedIn) {
return (
<View className='min-h-full bg-gray-50 flex flex-col items-center justify-center py-24'>
<Text className='text-5xl mb-3'>🔐</Text>
<Text className='text-base text-gray-700 mb-2'></Text>
<Text className='text-xs text-gray-400 text-center'></Text>
</View>
)
}
if (!isSuperAdmin) {
return (
<View className='min-h-full bg-gray-50 flex flex-col items-center justify-center py-20 px-10'>
<Text className='text-5xl mb-3'>🛡</Text>
<Text className='text-base text-gray-700 mb-2'>访</Text>
<Text className='text-xs text-gray-400 text-center'></Text>
</View>
)
}
// 头部展示信息:超管同时是店员则展示门店,否则展示管理员身份兜底
const header = storeInfo
? {
avatar: storeInfo.avatar,
title: storeInfo.storeName || '门店中心',
subtitle: `${storeInfo.name || ''}${storeInfo.phone ? ` · ${storeInfo.phone}` : ''}`,
}
: {
avatar: (user as any)?.avatar,
title: '门店中心',
subtitle: `${((user as any)?.nickname || (user as any)?.username || '')}${((user as any)?.phone) ? ` · ${(user as any).phone}` : ''}`,
}
return (
<View className='min-h-full bg-gray-50'>
{/* 顶部信息区:店员头像 + 门店名称 */}
{/* 顶部信息区:头像 + 名称 */}
<View
className='pt-8 pb-12 px-5 rounded-b-3xl relative overflow-hidden'
style={{ background: 'linear-gradient(135deg, #15803d 0%, #22c55e 60%, #4ade80 100%)' }}
@@ -163,12 +193,12 @@ export default function StoreCenterPage() {
<View className='absolute -bottom-6 -left-6 w-24 h-24 rounded-full opacity-15'
style={{ background: 'radial-gradient(circle, #ffffff, transparent)' }} />
<View className='relative z-10 flex items-center gap-4'>
{/* 店员头像 */}
{/* 头像 */}
<View className='w-16 h-16 rounded-full bg-white/20 border-2 border-white/40 overflow-hidden flex-shrink-0'>
{storeInfo.avatar ? (
{header.avatar ? (
<Image
className='w-full h-full'
src={storeInfo.avatar}
src={header.avatar}
mode='aspectFill'
/>
) : (
@@ -178,13 +208,13 @@ export default function StoreCenterPage() {
)}
</View>
{/* 门店信息 */}
{/* 信息 */}
<View className='flex-1 min-w-0'>
<Text className='text-white text-lg font-bold block truncate'>
{storeInfo.storeName || '门店中心'}
{header.title}
</Text>
<Text className='text-white text-opacity-80 text-sm mt-1 block truncate'>
{storeInfo.name} {storeInfo.phone ? `· ${storeInfo.phone}` : ''}
{header.subtitle}
</Text>
</View>
</View>

View File

@@ -105,10 +105,10 @@ const UserPage: React.FC = () => {
{ icon: '🔰', label: '申请成为开发者', url: '/pages/user/vip-upgrade/index', highlight: true, requireAuth: true },
// 开发者中心:仅 isDeveloper 用户显示
...((user as any)?.isDeveloper ? [{ icon: '🛠️', label: '开发者中心', url: '/pages/developer/index/index', requireAuth: true }] : []),
// 平台管理:仅 isAdmin 用户显示
...((user as any)?.isAdmin ? [{ icon: '🛡️', label: '平台管理', url: '/pages/admin/index/index', requireAuth: true }] : []),
// 门店中心:仅门店店员/店长显示(通过 /shop/shop-store-user/my 判断)
...(storeInfo ? [{ icon: '🏪', label: '门店中心', url: '/pages/store/center/index', requireAuth: true }] : []),
// 平台管理:仅 isSuperAdmin=1 用户显示
...((user as any)?.isSuperAdmin === 1 ? [{ icon: '🛡️', label: '平台管理', url: '/pages/admin/index/index', requireAuth: true }] : []),
// 门店中心:仅 isSuperAdmin=1 用户显示
...((user as any)?.isSuperAdmin === 1 ? [{ icon: '🏪', label: '门店中心', url: '/pages/store/center/index', requireAuth: true }] : []),
{ icon: '💰', label: '我的钱包', url: '/pages/user/wallet', requireAuth: true },
{ icon: '📍', label: '收货地址', url: '/pages/user/address-list', requireAuth: true },
// { icon: '⭐', label: '积分明细', url: '/pages/user/points-record' },