Browse Source

权限控制

dev
巴林闲侠 2 years ago
parent
commit
1858235eb6
  1. 4
      api/app/lib/controllers/auth/index.js
  2. 101
      weapp/src/pages/home/index.jsx
  3. 78
      weapp/src/pages/user/index.jsx

4
api/app/lib/controllers/auth/index.js

@ -90,6 +90,10 @@ async function wxLogin(ctx, next) {
delete: false, delete: false,
}, },
attributes: { exclude: ['password', 'delete'] }, attributes: { exclude: ['password', 'delete'] },
include: [{
attributes: ["resourceId", "isshow"],
model: models.UserResource
}]
}); });
if (!userRes) { if (!userRes) {
ctx.status = 400; ctx.status = 400;

101
weapp/src/pages/home/index.jsx

@ -43,52 +43,65 @@ const Index = () => {
}) })
} }
function judgeRight (code) {
return userInfo && userInfo.userResources && userInfo.userResources.some(item => item.resourceId === code)
}
return ( return (
<View className='page'> <View className='page'>
{
<View className='card fill'> judgeRight('WXPATROLREPOR') ?
<View className='title'> </View> <View className='card fill'>
<View className='btn' onClick={ <View className='title'> </View>
isSuperAdmin ? <View className='btn' onClick={
() => toPatrolView('patrol') isSuperAdmin ?
: () => toPatrol('patrol') () => toPatrolView('patrol')
}> : () => toPatrol('patrol')
{isSuperAdmin ? '查看' : '填报'} }>
</View> {isSuperAdmin ? '查看' : '填报'}
</View> </View>
</View>
<View className='card fill'> : ''
<View className='title'> </View> }
<View className='btn' onClick={ {
isSuperAdmin ? judgeRight('WXMAINTENANCEREPORT') ?
() => toPatrolView('conserve') <View className='card fill'>
: () => toPatrol('conserve') <View className='title'> </View>
}> <View className='btn' onClick={
{isSuperAdmin ? '查看' : '填报'} isSuperAdmin ?
</View> () => toPatrolView('conserve')
</View> : () => toPatrol('conserve')
}>
<View className='card fill_road'> {isSuperAdmin ? '查看' : '填报'}
<View className='title'> </View> </View>
<View className='btn' onClick={ </View> : ''
isSuperAdmin ? }
() => toPatrolView('road') {
: () => toPatrol('road') judgeRight('WXBUILDINGROAD') ?
}> <View className='card fill_road'>
{isSuperAdmin ? '查看' : '填报'} <View className='title'> </View>
</View> <View className='btn' onClick={
</View> isSuperAdmin ?
() => toPatrolView('road')
<View className='card fill_anomaly'> : () => toPatrol('road')
<View className='title'> </View> }>
<View className='btn' onClick={ {isSuperAdmin ? '查看' : '填报'}
isSuperAdmin ? </View>
() => toPatrolView('anomaly') </View> : ''
: () => toPatrol('anomaly') }
}> {
{isSuperAdmin ? '查看' : '填报'} judgeRight('WXFEEDBACKMANAGE') ?
</View> <View className='card fill_anomaly'>
</View> <View className='title'> </View>
<View className='btn' onClick={
isSuperAdmin ?
() => toPatrolView('anomaly')
: () => toPatrol('anomaly')
}>
{isSuperAdmin ? '查看' : '填报'}
</View>
</View> : ''
}
{/* { {/* {
isSuperAdmin && isSuperAdmin &&

78
weapp/src/pages/user/index.jsx

@ -52,6 +52,10 @@ const Index = ({ ...props }) => {
}) })
} }
function judgeRight (code) {
return userInfo && userInfo.userResources && userInfo.userResources.some(item => item.resourceId === code)
}
return ( return (
<View className='page'> <View className='page'>
<View className='myBox'> <View className='myBox'>
@ -64,38 +68,48 @@ const Index = ({ ...props }) => {
</View> </View>
</View> </View>
<View className='box' onClick={isSuperAdmin ? () => toPatrolReport('patrol') : () => toMyReport('patrol')}> {
<Image className='box-img' src={reportImg} /> judgeRight('WXPATROLREPOR') ?
<View className='box-txt'> <View className='box' onClick={isSuperAdmin ? () => toPatrolReport('patrol') : () => toMyReport('patrol')}>
{isSuperAdmin ? '巡查上报' : '巡查上报'} <Image className='box-img' src={reportImg} />
</View> <View className='box-txt'>
<Image className='img' src={moreImg} /> {isSuperAdmin ? '巡查上报' : '巡查上报'}
</View> </View>
<Image className='img' src={moreImg} />
<View className='box' onClick={isSuperAdmin ? () => toPatrolReport('conserve') : () => toMyReport('conserve')}> </View> : ''
<Image className='box-img' src={reportImg} /> }
<View className='box-txt'> {
{isSuperAdmin ? '养护上报' : '养护上报'} judgeRight('WXMAINTENANCEREPORT') ?
</View> <View className='box' onClick={isSuperAdmin ? () => toPatrolReport('conserve') : () => toMyReport('conserve')}>
<Image className='img' src={moreImg} /> <Image className='box-img' src={reportImg} />
</View> <View className='box-txt'>
{isSuperAdmin ? '养护上报' : '养护上报'}
<View className='box' onClick={isSuperAdmin ? () => toPatrolReport('road') : () => toMyReport('road')}> </View>
<Image className='box-img' src={reportImg} /> <Image className='img' src={moreImg} />
<View className='box-txt'> </View>
{isSuperAdmin ? '在建道路上报' : '在建道路'} : ''
</View> }
<Image className='img' src={moreImg} /> {
</View> judgeRight('WXBUILDINGROAD') ?
<View className='box' onClick={isSuperAdmin ? () => toPatrolReport('road') : () => toMyReport('road')}>
<View className='box' onClick={isSuperAdmin ? () => toPatrolReport('anomaly') : () => toMyReport('anomaly')}> <Image className='box-img' src={reportImg} />
<Image className='box-img' src={reportImg} /> <View className='box-txt'>
<View className='box-txt'> {isSuperAdmin ? '在建道路上报' : '在建道路'}
{isSuperAdmin ? '异常反馈上报' : '异常反馈'} </View>
</View> <Image className='img' src={moreImg} />
<Image className='img' src={moreImg} /> </View> : ''
</View> }
{
judgeRight('WXFEEDBACKMANAGE') ?
<View className='box' onClick={isSuperAdmin ? () => toPatrolReport('anomaly') : () => toMyReport('anomaly')}>
<Image className='box-img' src={reportImg} />
<View className='box-txt'>
{isSuperAdmin ? '异常反馈上报' : '异常反馈'}
</View>
<Image className='img' src={moreImg} />
</View>
: ''
}
<View className='box' onClick={changePassword} style={{ marginTop: '2rpx' }}> <View className='box' onClick={changePassword} style={{ marginTop: '2rpx' }}>
<Image className='box-img' src={pswdImg} /> <Image className='box-img' src={pswdImg} />
<View className='box-txt'>修改密码</View> <View className='box-txt'>修改密码</View>

Loading…
Cancel
Save