fix: ux
This commit is contained in:
parent
ded0383ac4
commit
e59816aba4
@ -37,13 +37,13 @@ export const AppPermissionList: PermissionListType<AppPermissionKeyEnum> = {
|
||||
name: '门户快捷应用权限',
|
||||
description: '',
|
||||
value: GateQuickAppPermission,
|
||||
checkBoxType: 'multiple' // TODO: 加个隐藏选项
|
||||
checkBoxType: 'hiden'
|
||||
},
|
||||
[AppPermissionKeyEnum.featuredGate]: {
|
||||
name: '门户推荐应用权限',
|
||||
description: '',
|
||||
value: GateFeaturedAppPermission,
|
||||
checkBoxType: 'multiple' // TODO: 加个隐藏选项
|
||||
checkBoxType: 'hiden'
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -11,6 +11,7 @@ export class AppPermission extends Permission {
|
||||
} else if (!props?.per) {
|
||||
props.per = AppDefaultPermissionVal;
|
||||
}
|
||||
props.permissionList = AppPermissionList;
|
||||
super(props);
|
||||
this.setUpdatePermissionCallback(() => {
|
||||
this.hasReadPer = this.checkPer(AppPermissionList.read.value);
|
||||
|
||||
@ -1,5 +1,10 @@
|
||||
import { type PermissionListType, type PermissionValueType } from './type';
|
||||
import { PermissionList, NullPermission, OwnerPermissionVal } from './constant';
|
||||
import {
|
||||
PermissionList,
|
||||
NullPermission,
|
||||
OwnerPermissionVal,
|
||||
ManagePermissionVal
|
||||
} from './constant';
|
||||
|
||||
export type PerConstructPros = {
|
||||
per?: PermissionValueType;
|
||||
@ -63,6 +68,12 @@ export class Permission {
|
||||
if (perm === OwnerPermissionVal) {
|
||||
return this.value === OwnerPermissionVal;
|
||||
}
|
||||
|
||||
// 管理员
|
||||
if ((this.value & ManagePermissionVal) === ManagePermissionVal) {
|
||||
return (this._permissionList.manage.value & perm) === perm;
|
||||
}
|
||||
|
||||
return (this.value & perm) === perm;
|
||||
}
|
||||
|
||||
|
||||
2
packages/global/support/permission/type.d.ts
vendored
2
packages/global/support/permission/type.d.ts
vendored
@ -18,7 +18,7 @@ export type PermissionListType<T = {}> = Record<
|
||||
name: string;
|
||||
description: string;
|
||||
value: PermissionValueType;
|
||||
checkBoxType: 'single' | 'multiple';
|
||||
checkBoxType: 'single' | 'multiple' | 'hiden';
|
||||
}
|
||||
>;
|
||||
|
||||
|
||||
@ -137,7 +137,7 @@ export const authApp = async ({
|
||||
appId: ParentIdType;
|
||||
per: PermissionValueType;
|
||||
}): Promise<
|
||||
AuthResponseType & {
|
||||
AuthResponseType<AppPermission> & {
|
||||
app: AppDetailType;
|
||||
}
|
||||
> => {
|
||||
|
||||
@ -83,7 +83,7 @@ function PermissionSelect({
|
||||
const selectedSingleValue = useMemo(() => {
|
||||
if (!permissionList) return undefined;
|
||||
|
||||
const per = new Permission({ per: value });
|
||||
const per = new Permission({ per: value, permissionList });
|
||||
|
||||
if (per.hasManagePer) return permissionList['manage'].value;
|
||||
if (per.hasWritePer) return permissionList['write'].value;
|
||||
@ -91,18 +91,18 @@ function PermissionSelect({
|
||||
return permissionList['read'].value;
|
||||
}, [permissionList, value]);
|
||||
const selectedMultipleValues = useMemo(() => {
|
||||
const per = new Permission({ per: value });
|
||||
const per = new Permission({ per: value, permissionList });
|
||||
|
||||
return permissionSelectList.multipleCheckBoxList
|
||||
.filter((item) => {
|
||||
return per.checkPer(item.value);
|
||||
})
|
||||
.map((item) => item.value);
|
||||
}, [permissionSelectList.multipleCheckBoxList, value]);
|
||||
}, [permissionList, permissionSelectList.multipleCheckBoxList, value]);
|
||||
|
||||
const onSelectPer = (perValue: PermissionValueType) => {
|
||||
if (perValue === value) return;
|
||||
const per = new Permission({ per: perValue });
|
||||
const per = new Permission({ per: perValue, permissionList });
|
||||
per.addPer(...selectedMultipleValues);
|
||||
onChange(per.value);
|
||||
};
|
||||
@ -157,7 +157,7 @@ function PermissionSelect({
|
||||
{/* The list of single select permissions */}
|
||||
{permissionSelectList.singleCheckBoxList.map((item) => {
|
||||
const change = () => {
|
||||
const per = new Permission({ per: value });
|
||||
const per = new Permission({ per: value, permissionList });
|
||||
per.removePer(selectedSingleValue);
|
||||
per.addPer(item.value);
|
||||
onSelectPer(per.value);
|
||||
@ -191,12 +191,13 @@ function PermissionSelect({
|
||||
<MyDivider my={2} />
|
||||
{permissionSelectList.multipleCheckBoxList.map((item) => {
|
||||
const isChecked = selectedMultipleValues.includes(item.value);
|
||||
const isDisabled = new Permission({ per: selectedSingleValue }).checkPer(
|
||||
item.value
|
||||
);
|
||||
const isDisabled = new Permission({
|
||||
per: selectedSingleValue,
|
||||
permissionList
|
||||
}).checkPer(item.value);
|
||||
const change = () => {
|
||||
if (isDisabled) return;
|
||||
const per = new Permission({ per: value });
|
||||
const per = new Permission({ per: value, permissionList });
|
||||
if (isChecked) {
|
||||
per.removePer(item.value);
|
||||
} else {
|
||||
@ -221,14 +222,18 @@ function PermissionSelect({
|
||||
: {
|
||||
cursor: 'pointer'
|
||||
})}
|
||||
onClick={change}
|
||||
>
|
||||
<Checkbox
|
||||
size="lg"
|
||||
isChecked={isChecked}
|
||||
onChange={change}
|
||||
// onChange={(e) => {
|
||||
// e.stopPropagation();
|
||||
// e.preventDefault();
|
||||
// }}
|
||||
isDisabled={isDisabled}
|
||||
/>
|
||||
<Box ml={4} onClick={change}>
|
||||
<Box ml={4}>
|
||||
<Box>{t(item.name as any)}</Box>
|
||||
<Box color={'myGray.500'} fontSize={'mini'}>
|
||||
{t(item.description as any)}
|
||||
|
||||
@ -38,7 +38,7 @@ async function handler(
|
||||
]);
|
||||
|
||||
// auth chat permission
|
||||
if (chat && !app.permission.hasManagePer && String(tmbId) !== String(chat?.tmbId)) {
|
||||
if (chat && !app.permission.hasLogPer && String(tmbId) !== String(chat?.tmbId)) {
|
||||
return Promise.reject(ChatErrEnum.unAuthChat);
|
||||
}
|
||||
|
||||
|
||||
@ -170,7 +170,7 @@ export async function authChatCrud({
|
||||
};
|
||||
|
||||
if (String(teamId) !== String(chat.teamId)) return Promise.reject(ChatErrEnum.unAuthChat);
|
||||
if (permission.hasManagePer)
|
||||
if (permission.hasLogPer)
|
||||
return {
|
||||
teamId,
|
||||
tmbId,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user