roymondchen 1c67b5e77b feat(editor): 注册编辑器字段内置 typeMatch 校验规则并补充文档
- 新增 typeMatchRules.ts,为编辑器自定义字段注册内置 typeMatch 校验规则
- 抽取 event.ts 事件工具函数
- form typeMatch 适配 TDesign 校验器签名,错误消息补充实际值
- rules.md 新增「Editor 字段内置规则」章节,16 个字段文档补充校验说明
2026-07-14 17:15:28 +08:00

63 lines
1.5 KiB
Vue

<template>
<TMagicSelect
:model-value="model[name]"
clearable
filterable
:size="size"
:disabled="disabled"
@change="fieldChangeHandler"
>
<component
v-for="option in options"
class="tmagic-design-option"
:key="option.value"
:is="optionComponent?.component || 'el-option'"
v-bind="
optionComponent?.props({
label: option.text,
value: option.value,
}) || {
label: option.text,
value: option.value,
}
"
>
</component>
</TMagicSelect>
</template>
<script setup lang="ts">
import { computed } from 'vue';
import { getDesignConfig, TMagicSelect } from '@tmagic/design';
import type { CondOpSelectConfig, FieldProps } from '@tmagic/form';
import { useServices } from '@editor/hooks/use-services';
import { getCondOpOptionsByFieldType, getFieldType } from '@editor/utils';
defineOptions({
name: 'MFieldsCondOpSelect',
});
const emit = defineEmits<{
change: [value: string];
}>();
const { dataSourceService } = useServices();
const props = defineProps<FieldProps<CondOpSelectConfig>>();
const optionComponent = getDesignConfig('components')?.option;
const options = computed(() => {
const [id, ...fieldNames] = [...(props.config.parentFields || []), ...props.model.field];
const ds = dataSourceService.getDataSourceById(id);
const type = getFieldType(ds, fieldNames);
return getCondOpOptionsByFieldType(type);
});
const fieldChangeHandler = (v: string) => {
emit('change', v);
};
</script>