diff --git a/packages/core/client/src/collection-manager/interfaces/chinaRegion.ts b/packages/core/client/src/collection-manager/interfaces/chinaRegion.ts index bcdecc69b7..149c267f23 100644 --- a/packages/core/client/src/collection-manager/interfaces/chinaRegion.ts +++ b/packages/core/client/src/collection-manager/interfaces/chinaRegion.ts @@ -8,8 +8,8 @@ */ import { uid } from '@formily/shared'; -import { defaultProps, operators } from './properties'; import { CollectionFieldInterface } from '../../data-source/collection-field-interface/CollectionFieldInterface'; +import { defaultProps, operators } from './properties'; export class ChinaRegionFieldInterface extends CollectionFieldInterface { name = 'chinaRegion'; @@ -86,6 +86,16 @@ export class ChinaRegionFieldInterface extends CollectionFieldInterface { filterable = { children: [ + { + name: 'code', + title: '{{t("Province/city/area code")}}', + operators: operators.regionCode, + schema: { + title: '{{t("Province/city/area code")}}', + type: 'string', + 'x-component': 'Input', + }, + }, { name: 'name', title: '{{t("Province/city/area name")}}', diff --git a/packages/core/client/src/collection-manager/interfaces/properties/operators.ts b/packages/core/client/src/collection-manager/interfaces/properties/operators.ts index ed58efc79d..f83e1c556c 100644 --- a/packages/core/client/src/collection-manager/interfaces/properties/operators.ts +++ b/packages/core/client/src/collection-manager/interfaces/properties/operators.ts @@ -16,6 +16,8 @@ export const string = [ { label: '{{t("is not empty")}}', value: '$notEmpty', noValue: true }, ]; +export const regionCode = [{ label: '{{t("is")}}', value: '$regionCodeEq' }]; + export const array = [ { label: '{{t("is")}}', diff --git a/packages/plugins/@nocobase/plugin-field-china-region/src/server/index.ts b/packages/plugins/@nocobase/plugin-field-china-region/src/server/index.ts index 652a51db02..af10a76d48 100644 --- a/packages/plugins/@nocobase/plugin-field-china-region/src/server/index.ts +++ b/packages/plugins/@nocobase/plugin-field-china-region/src/server/index.ts @@ -8,7 +8,7 @@ */ import { Plugin } from '@nocobase/server'; -import { resolve } from 'path'; +import _ from 'lodash'; import { ChinaRegionInterface } from './interfaces/china-region-interface'; function getChinaDivisionData(key: string) { @@ -26,10 +26,19 @@ export class PluginFieldChinaRegionServer extends Plugin { } async load() { - await this.importCollections(resolve(__dirname, 'collections')); - this.app.acl.allow('chinaRegions', 'list', 'loggedIn'); + this.db.registerOperators({ + $regionCodeEq: (value, ctx) => { + const eq = this.db.operators.get('$eq'); + if (Array.isArray(value)) { + const obj = _.castArray(value).pop(); + return eq(obj?.code, ctx); + } + return eq(value, ctx); + }, + }); + this.app.resourcer.use(async (ctx, next) => { const { resourceName, actionName } = ctx.action.params;