fix: 筛选表单关联字段添加运算符 (#1537)

Reviewed-on: daoyoucloud/tachybase#1537
Co-authored-by: wjh <wwwjh0710@163.com>
Co-committed-by: wjh <wwwjh0710@163.com>
This commit is contained in:
wjh 2024-09-18 18:23:47 +08:00 committed by bai.zixv
parent 7cd0a044c5
commit d6dfdfd54d
7 changed files with 30 additions and 10 deletions

View File

@ -2,7 +2,7 @@ import { ISchema, uid } from '@tachybase/schema';
import { CollectionFieldInterface } from '../../data-source/collection-field-interface/CollectionFieldInterface';
import { getUniqueKeyFromCollection } from './o2m';
import { defaultProps, relationshipType, reverseFieldProperties } from './properties';
import { defaultProps, operators, relationshipType, reverseFieldProperties } from './properties';
export class M2MFieldInterface extends CollectionFieldInterface {
name = 'm2m';
@ -233,6 +233,7 @@ export class M2MFieldInterface extends CollectionFieldInterface {
};
filterable = {
nested: true,
operators: operators.collectionField,
children: [
// {
// name: 'id',

View File

@ -2,7 +2,7 @@ import { ISchema } from '@tachybase/schema';
import { CollectionFieldInterface } from '../../data-source/collection-field-interface/CollectionFieldInterface';
import { getUniqueKeyFromCollection } from './o2m';
import { constraintsProps, relationshipType, reverseFieldProperties } from './properties';
import { constraintsProps, operators, relationshipType, reverseFieldProperties } from './properties';
export class M2OFieldInterface extends CollectionFieldInterface {
name = 'm2o';
@ -168,6 +168,7 @@ export class M2OFieldInterface extends CollectionFieldInterface {
filterable = {
nested: true,
operators: operators.collectionField,
children: [
// {
// name: 'id',

View File

@ -2,7 +2,7 @@ import { ISchema } from '@tachybase/schema';
import { Collection } from '../../data-source';
import { CollectionFieldInterface } from '../../data-source/collection-field-interface/CollectionFieldInterface';
import { constraintsProps, relationshipType, reverseFieldProperties } from './properties';
import { constraintsProps, operators, relationshipType, reverseFieldProperties } from './properties';
export class O2MFieldInterface extends CollectionFieldInterface {
name = 'o2m';
@ -190,6 +190,7 @@ export class O2MFieldInterface extends CollectionFieldInterface {
};
filterable = {
nested: true,
operators: operators.collectionField,
children: [
// {
// name: 'id',

View File

@ -2,7 +2,7 @@ import { ISchema } from '@tachybase/schema';
import { CollectionFieldInterface } from '../../data-source/collection-field-interface/CollectionFieldInterface';
import { getUniqueKeyFromCollection } from './o2m';
import { constraintsProps, relationshipType, reverseFieldProperties } from './properties';
import { constraintsProps, operators, relationshipType, reverseFieldProperties } from './properties';
export class O2OFieldInterface extends CollectionFieldInterface {
name = 'o2o';
@ -171,6 +171,7 @@ export class O2OFieldInterface extends CollectionFieldInterface {
};
filterable = {
nested: true,
operators: operators.collectionField,
children: [
// {
// name: 'id',
@ -351,6 +352,7 @@ export class OHOFieldInterface extends CollectionFieldInterface {
};
filterable = {
nested: true,
operators: operators.collectionField,
children: [
// {
// name: 'id',
@ -531,6 +533,7 @@ export class OBOFieldInterface extends CollectionFieldInterface {
};
filterable = {
nested: true,
operators: operators.collectionField,
children: [
// {
// name: 'id',

View File

@ -174,3 +174,17 @@ export const collection = [
{ label: '{{t("is empty")}}', value: '$empty', noValue: true },
{ label: '{{t("is not empty")}}', value: '$notEmpty', noValue: true },
];
export const collectionField = [
{
label: '{{t("is")}}',
value: '$eq',
selected: true,
},
{
label: '{{t("is not")}}',
value: '$ne',
},
{ label: '{{t("is empty")}}', value: '$empty', noValue: true },
{ label: '{{t("is not empty")}}', value: '$notEmpty', noValue: true },
];

View File

@ -134,9 +134,9 @@ export const transformToFilter = (
const result = {
$and: Object.keys(values)
.map((key) => {
const defKey = key;
let value = _.get(values, key);
const collectionField = getCollectionJoinField(`${collectionName}.${key}`);
if (collectionField?.target) {
value = getValuesByPath(value, collectionField.targetKey || 'id');
key = `${key}.${collectionField.targetKey || 'id'}`;
@ -145,7 +145,6 @@ export const transformToFilter = (
if (!value) {
return null;
}
// 处理布尔类型
if (operators[key] === '$isTruly' || operators[key] === '$isFalsy') {
if (value === 'true') {
@ -162,10 +161,9 @@ export const transformToFilter = (
};
}
}
return {
[key]: {
[operators[key] || '$eq']: value,
[operators[key] || operators[defKey] || '$eq']: value,
},
};
})

View File

@ -484,6 +484,7 @@ export const useEnsureOperatorsValid = () => {
export const EditOperator = () => {
const compile = useCompile();
const fieldSchema = useFieldSchema();
const field = useField<Field>();
const { t } = useTranslation();
const { dn } = useDesignable();
@ -507,7 +508,7 @@ export const EditOperator = () => {
['x-uid']: uid,
['x-filter-operators']: storedOperators,
};
let componentProps = {};
let componentProps = { ...fieldSchema['x-component-props'] };
const isCustom = (fieldSchema.name as string).includes('__custom');
// 根据操作符的配置,设置组件的属性
if (operator?.schema?.['x-component']) {
@ -516,6 +517,7 @@ export const EditOperator = () => {
field.reset();
componentProps = {
component: operator.schema['x-component'],
...fieldSchema['x-component-props'],
...operator.schema?.['x-component-props'],
};
const dnSchema = {
@ -544,6 +546,7 @@ export const EditOperator = () => {
field.reset();
componentProps = {
component: isCustom ? fieldSchema['x-component-props']?.component : null,
...fieldSchema['x-component-props'],
...operator.schema?.['x-component-props'],
};
const dnSchema = {
@ -557,7 +560,6 @@ export const EditOperator = () => {
}
dn.emit('patch', dnSchema);
}
field.componentProps = componentProps;
dn.emit('patch', {
schema,