fix: china region code eq

This commit is contained in:
chenos 2024-08-05 16:04:50 +08:00
parent dd9f5d5e52
commit 6434b5d8dc
3 changed files with 25 additions and 4 deletions

View File

@ -8,8 +8,8 @@
*/ */
import { uid } from '@formily/shared'; import { uid } from '@formily/shared';
import { defaultProps, operators } from './properties';
import { CollectionFieldInterface } from '../../data-source/collection-field-interface/CollectionFieldInterface'; import { CollectionFieldInterface } from '../../data-source/collection-field-interface/CollectionFieldInterface';
import { defaultProps, operators } from './properties';
export class ChinaRegionFieldInterface extends CollectionFieldInterface { export class ChinaRegionFieldInterface extends CollectionFieldInterface {
name = 'chinaRegion'; name = 'chinaRegion';
@ -86,6 +86,16 @@ export class ChinaRegionFieldInterface extends CollectionFieldInterface {
filterable = { filterable = {
children: [ 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', name: 'name',
title: '{{t("Province/city/area name")}}', title: '{{t("Province/city/area name")}}',

View File

@ -16,6 +16,8 @@ export const string = [
{ label: '{{t("is not empty")}}', value: '$notEmpty', noValue: true }, { label: '{{t("is not empty")}}', value: '$notEmpty', noValue: true },
]; ];
export const regionCode = [{ label: '{{t("is")}}', value: '$regionCodeEq' }];
export const array = [ export const array = [
{ {
label: '{{t("is")}}', label: '{{t("is")}}',

View File

@ -8,7 +8,7 @@
*/ */
import { Plugin } from '@nocobase/server'; import { Plugin } from '@nocobase/server';
import { resolve } from 'path'; import _ from 'lodash';
import { ChinaRegionInterface } from './interfaces/china-region-interface'; import { ChinaRegionInterface } from './interfaces/china-region-interface';
function getChinaDivisionData(key: string) { function getChinaDivisionData(key: string) {
@ -26,10 +26,19 @@ export class PluginFieldChinaRegionServer extends Plugin {
} }
async load() { async load() {
await this.importCollections(resolve(__dirname, 'collections'));
this.app.acl.allow('chinaRegions', 'list', 'loggedIn'); 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) => { this.app.resourcer.use(async (ctx, next) => {
const { resourceName, actionName } = ctx.action.params; const { resourceName, actionName } = ctx.action.params;