mirror of
https://github.com/Tencent/tmagic-editor.git
synced 2025-09-26 10:59:58 +08:00
48 lines
1.1 KiB
Vue
48 lines
1.1 KiB
Vue
<template>
|
|
<m-form-container
|
|
:config="{
|
|
...config,
|
|
...cascaderConfig,
|
|
}"
|
|
:model="model"
|
|
@change="onChangeHandler"
|
|
></m-form-container>
|
|
</template>
|
|
|
|
<script setup lang="ts">
|
|
import { computed, inject } from 'vue';
|
|
|
|
import type { FieldProps } from '@tmagic/form';
|
|
|
|
import type { DataSourceFieldSelectConfig, Services } from '@editor/type';
|
|
|
|
const services = inject<Services>('services');
|
|
const emit = defineEmits(['change']);
|
|
|
|
const props = withDefaults(defineProps<FieldProps<DataSourceFieldSelectConfig>>(), {
|
|
disabled: false,
|
|
});
|
|
|
|
const dataSources = computed(() => services?.dataSourceService.get('dataSources'));
|
|
|
|
const cascaderConfig = {
|
|
type: 'cascader',
|
|
name: props.name,
|
|
options: () =>
|
|
dataSources.value
|
|
?.filter((ds) => ds.fields?.length)
|
|
?.map((ds) => ({
|
|
label: ds.title || ds.id,
|
|
value: ds.id,
|
|
children: ds.fields?.map((field) => ({
|
|
label: field.title,
|
|
value: field.name,
|
|
})),
|
|
})) || [],
|
|
};
|
|
|
|
const onChangeHandler = (value: any) => {
|
|
emit('change', value);
|
|
};
|
|
</script>
|