token增加了isRoot方法

This commit is contained in:
Xu Chang 2022-07-01 11:42:22 +08:00
parent b84c85b426
commit f36830faaf
3 changed files with 41 additions and 13 deletions

View File

@ -73,11 +73,11 @@ export default OakPage(
}, },
], ],
isList: true, isList: true,
formData: async function ({ data: users, params }) { formData: async function ({ data: users, params, features }) {
const { entity } = params!; const { entity } = params!;
const entityStr = entity.charAt(0).toUpperCase() + entity.substring(1); const entityStr = entity.charAt(0).toUpperCase() + entity.substring(1);
const filters = await this.getFilters(); const isRoot = await features.token.isRoot();
const filter = await this.getFilterByName('name'); const filter = await this.getFilterByName('name');
return { return {
@ -101,6 +101,7 @@ export default OakPage(
searchValue: ( searchValue: (
filter?.$or as [{ name: { $includes: string } }] filter?.$or as [{ name: { $includes: string } }]
)[0].name.$includes, )[0].name.$includes,
isRoot,
}; };
}, },
properties: { properties: {
@ -137,14 +138,10 @@ export default OakPage(
async searchConfirm() { async searchConfirm() {
this.refresh(); this.refresh();
}, },
goUpsert() { goUpsertUser() {
const { entity, entityId } = this.props; const { entity, entityId } = this.props;
this.navigateTo({ this.navigateTo({
url: '../userEntityGrant/grant/index', url: '../user/manage/upsert/index',
entity,
entityId,
relations: ['manager'],
type: 'grant',
}); });
}, },
handleCardClick(event: any) { handleCardClick(event: any) {

View File

@ -16,11 +16,13 @@
</view> </view>
</l-card> </l-card>
</block> </block>
<fab bind:click="goUpsert"> <block wx:if="{{isRoot}}">
<l-icon name="add" type="material" color="#fff" size="48" /> <fab bind:click="goUpsertUser">
</fab> <l-icon name="add" type="material" color="#fff" size="48" />
</fab>
</block>
</block> </block>
<block wx:else> <block wx:elif="{{isRoot}}">
<l-status-show show="{{true}}" type="data" button-text="添加人员" bind:lintap="goUpsert"></l-status-show> <l-status-show show="{{true}}" type="data" button-text="添加人员" bind:lintap="goUpsertUser"></l-status-show>
</block> </block>
</view> </view>

View File

@ -8,6 +8,7 @@ import { CommonAspectDict } from 'oak-common-aspect';
import { AspectDict } from '../aspects/AspectDict'; import { AspectDict } from '../aspects/AspectDict';
import { GeneralRuntimeContext } from '..'; import { GeneralRuntimeContext } from '..';
import { AspectWrapper } from 'oak-domain/lib/types'; import { AspectWrapper } from 'oak-domain/lib/types';
import { ROOT_ROLE_ID } from '../constants';
export class Token<ED extends EntityDict, Cxt extends GeneralRuntimeContext<ED>, AD extends AspectDict<ED, Cxt>> extends Feature<ED, Cxt, AD & CommonAspectDict<ED, Cxt>> { export class Token<ED extends EntityDict, Cxt extends GeneralRuntimeContext<ED>, AD extends AspectDict<ED, Cxt>> extends Feature<ED, Cxt, AD & CommonAspectDict<ED, Cxt>> {
private token?: string; private token?: string;
@ -122,4 +123,32 @@ export class Token<ED extends EntityDict, Cxt extends GeneralRuntimeContext<ED>,
}); });
return result[0]?.userId; return result[0]?.userId;
} }
async isRoot(): Promise<boolean> {
const token = await this.getToken();
if (!token) {
return false;
}
const [tokenValue] = await this.cache.get('token', {
data: {
id: 1,
userId: 1,
player: {
id: 1,
userRole$user: {
$entity: 'userRole',
data: {
id: 1,
userId: 1,
roleId: 1,
},
},
},
},
filter: {
id: token,
}
});
return tokenValue?.player?.userRole$user && tokenValue?.player?.userRole$user[0]?.roleId === ROOT_ROLE_ID || false;
}
} }