diff --git a/packages/grid/src/core/types/core.ts b/packages/grid/src/core/types/core.ts index 04e46f0b..ffb66d46 100644 --- a/packages/grid/src/core/types/core.ts +++ b/packages/grid/src/core/types/core.ts @@ -98,6 +98,8 @@ export enum AITableSelectOptionStyle { export type TextFieldValue = string; +export type LinkFieldValue = { url: string; text: string }; + export type SelectFieldValue = Id[]; // 数字 export type NumberFieldValue = number; @@ -112,6 +114,7 @@ export type RateFieldValue = 1 | 2 | 3 | 4 | 5; export type FieldValue = | TextFieldValue + | LinkFieldValue | SelectFieldValue | NumberFieldValue | DateFieldValue diff --git a/packages/state/src/utils/field/model/index.ts b/packages/state/src/utils/field/model/index.ts index 06f32505..deb3ba15 100644 --- a/packages/state/src/utils/field/model/index.ts +++ b/packages/state/src/utils/field/model/index.ts @@ -5,6 +5,7 @@ import { SelectField } from './select'; import { DateField } from './date'; import { NumberField } from './number'; import { RateField } from './rate'; +import { LinkField } from './link'; export const ViewOperationMap: Record = { [AITableFieldType.text]: new TextField(), @@ -15,7 +16,7 @@ export const ViewOperationMap: Record = { [AITableFieldType.updatedAt]: new DateField(), [AITableFieldType.number]: new NumberField(), [AITableFieldType.rate]: new RateField(), - [AITableFieldType.link]: new TextField(), + [AITableFieldType.link]: new LinkField(), [AITableFieldType.member]: new SelectField(), [AITableFieldType.progress]: new NumberField(), [AITableFieldType.createdBy]: new SelectField(), diff --git a/packages/state/src/utils/field/model/link.ts b/packages/state/src/utils/field/model/link.ts new file mode 100644 index 00000000..735049d3 --- /dev/null +++ b/packages/state/src/utils/field/model/link.ts @@ -0,0 +1,42 @@ +import { isEmpty } from '../../common'; +import { AITableFilterCondition, AITableFilterOperation } from '../../../types'; +import { Field } from './field'; +import { AITableField, FieldValue, LinkFieldValue } from '@ai-table/grid'; +import { isObject, isString } from 'ngx-tethys/util'; + +export class LinkField extends Field { + override isMeetFilter(condition: AITableFilterCondition, cellValue: FieldValue) { + const cellTextValue = this.cellValueToString(cellValue); + switch (condition.operation) { + case AITableFilterOperation.empty: + return isEmpty(cellTextValue); + case AITableFilterOperation.exists: + return !isEmpty(cellTextValue); + case AITableFilterOperation.contain: + return !isEmpty(cellTextValue) && this.stringInclude(cellTextValue, condition.value); + default: + return super.isMeetFilter(condition, cellTextValue); + } + } + + override eq(cv1: LinkFieldValue | string | null, cv2: LinkFieldValue | string | null): boolean { + return this.cellValueToString(cv1) === this.cellValueToString(cv2); + } + + override compare(cellValue1: FieldValue, cellValue2: FieldValue, field: AITableField): number { + const cellTextValue1 = this.cellValueToString(cellValue1); + const cellTextValue2 = this.cellValueToString(cellValue2); + + return super.compare(cellTextValue1, cellTextValue2, field); + } + + cellValueToString(cellValue: LinkFieldValue | string | null): string { + if (isString(cellValue)) { + return cellValue; + } + if (isObject(cellValue)) { + return cellValue.text; + } + return ''; + } +}