fix: add filter operator "is not current logged-in user"

This commit is contained in:
chenos 2023-01-09 10:59:26 +08:00
parent a614bc7de8
commit fd71d57bdf
3 changed files with 14 additions and 0 deletions

View File

@ -86,6 +86,14 @@ export const id = [
return field.collectionName === 'users';
},
},
{
label: '{{t("is not current logged-in user")}}',
value: '$isNotCurrentUser',
noValue: true,
visible(field) {
return field.collectionName === 'users';
},
},
{ label: '{{t("exists")}}', value: '$exists', noValue: true },
{ label: '{{t("not exists")}}', value: '$notExists', noValue: true },
];

View File

@ -447,6 +447,7 @@ export default {
'exists': '存在',
'not exists': '不存在',
'is current logged-in user': '为当前登录用户',
'is not current logged-in user': '不为当前登录用户',
'=': '=',
'≠': '≠',
'>': '>',

View File

@ -43,6 +43,11 @@ export default class UsersPlugin extends Plugin<UserPluginConfig> {
[Op.eq]: ctx?.app?.ctx?.state?.currentUser?.id || -1,
};
},
$isNotCurrentUser(_, ctx) {
return {
[Op.ne]: ctx?.app?.ctx?.state?.currentUser?.id || -1,
};
},
$isVar(val, ctx) {
const obj = parse({ val: `{{${val}}}` })(JSON.parse(JSON.stringify(ctx?.app?.ctx?.state)));
return {