Add condition part

This commit is contained in:
2025-01-22 23:37:31 +08:00
parent 4062d85ea0
commit 58ad3571cd
13 changed files with 186 additions and 92 deletions

View File

@@ -1,14 +1,8 @@
import TableCombobox from '@/components/basic/condition/TableCombobox.vue';
import TableInput from '@/components/basic/condition/TableInput.vue';
import type { FieldsInfo } from '@/types/model';
import type { FieldType } from './kintone-rest-api-client';
const component = {
'': undefined,
input: TableInput,
select: TableCombobox,
};
export type ComponentType = keyof typeof component;
export type ConditionValue = '' | 'eq' | 'ne';
// Condition
export type ConditionValue = '' | 'eq' | 'ne' | 'test';
type ConditionItem = {
value: ConditionValue;
@@ -21,10 +15,9 @@ export const conditionList: ConditionItem[] = [
{ value: '', label: '--------', type: '', func: (a: string, b: string) => true },
{ value: 'eq', label: '=(等しい)', type: 'input', func: (a: string, b: string) => a === b },
{ value: 'ne', label: '≠ (等しくない)', type: 'input', func: (a: string, b: string) => a !== b },
{ value: 'test', label: 'test combobox', type: 'select', func: (a: string, b: string) => a < b },
];
// type ConditionItem = (typeof conditionList)[number];
export const conditionMap: Record<ConditionValue, ConditionItem> = conditionList.reduce(
(map, item) => {
map[item.value] = item;
@@ -33,6 +26,29 @@ export const conditionMap: Record<ConditionValue, ConditionItem> = conditionList
{} as Record<ConditionValue, ConditionItem>,
);
// Field Type -> Condition
type FieldConditions = Partial<Record<FieldType, ConditionValue[]>>;
const fieldConditions: FieldConditions = {
SINGLE_LINE_TEXT: ['eq', 'ne'],
NUMBER: ['ne', 'test'],
} as const;
export const getAvailableCondition = (fieldCode: string, { fields }: FieldsInfo) => {
if (!fieldCode||!fields) return;
const conditions = fieldConditions[fields[fieldCode]?.type] || [];
return conditions.map((condition) => conditionMap[condition]);
};
// Condition -> Component
const component = {
'': undefined,
input: 'kuc-text',
select: 'kuc-combobox',
};
export type ComponentType = keyof typeof component;
export const getComponent = (value: ConditionValue) => {
if (!value) return;
return component[conditionMap[value].type];
};