token增加了isRoot方法
This commit is contained in:
parent
b84c85b426
commit
f36830faaf
|
|
@ -73,11 +73,11 @@ export default OakPage(
|
|||
},
|
||||
],
|
||||
isList: true,
|
||||
formData: async function ({ data: users, params }) {
|
||||
formData: async function ({ data: users, params, features }) {
|
||||
const { entity } = params!;
|
||||
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');
|
||||
|
||||
return {
|
||||
|
|
@ -101,6 +101,7 @@ export default OakPage(
|
|||
searchValue: (
|
||||
filter?.$or as [{ name: { $includes: string } }]
|
||||
)[0].name.$includes,
|
||||
isRoot,
|
||||
};
|
||||
},
|
||||
properties: {
|
||||
|
|
@ -137,14 +138,10 @@ export default OakPage(
|
|||
async searchConfirm() {
|
||||
this.refresh();
|
||||
},
|
||||
goUpsert() {
|
||||
goUpsertUser() {
|
||||
const { entity, entityId } = this.props;
|
||||
this.navigateTo({
|
||||
url: '../userEntityGrant/grant/index',
|
||||
entity,
|
||||
entityId,
|
||||
relations: ['manager'],
|
||||
type: 'grant',
|
||||
url: '../user/manage/upsert/index',
|
||||
});
|
||||
},
|
||||
handleCardClick(event: any) {
|
||||
|
|
|
|||
|
|
@ -16,11 +16,13 @@
|
|||
</view>
|
||||
</l-card>
|
||||
</block>
|
||||
<fab bind:click="goUpsert">
|
||||
<block wx:if="{{isRoot}}">
|
||||
<fab bind:click="goUpsertUser">
|
||||
<l-icon name="add" type="material" color="#fff" size="48" />
|
||||
</fab>
|
||||
</block>
|
||||
<block wx:else>
|
||||
<l-status-show show="{{true}}" type="data" button-text="添加人员" bind:lintap="goUpsert"></l-status-show>
|
||||
</block>
|
||||
<block wx:elif="{{isRoot}}">
|
||||
<l-status-show show="{{true}}" type="data" button-text="添加人员" bind:lintap="goUpsertUser"></l-status-show>
|
||||
</block>
|
||||
</view>
|
||||
|
|
@ -8,6 +8,7 @@ import { CommonAspectDict } from 'oak-common-aspect';
|
|||
import { AspectDict } from '../aspects/AspectDict';
|
||||
import { GeneralRuntimeContext } from '..';
|
||||
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>> {
|
||||
private token?: string;
|
||||
|
|
@ -122,4 +123,32 @@ export class Token<ED extends EntityDict, Cxt extends GeneralRuntimeContext<ED>,
|
|||
});
|
||||
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;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue