diff --git a/src/components/form/form-modal.tsx b/src/components/form/form-modal.tsx index bd7eef1..1791dfc 100644 --- a/src/components/form/form-modal.tsx +++ b/src/components/form/form-modal.tsx @@ -1,6 +1,6 @@ import { Button, ButtonInstance, FormInstance, Message, Modal } from "@arco-design/web-vue"; import { assign, cloneDeep, omit } from "lodash-es"; -import { PropType, defineComponent } from "vue"; +import { PropType, VNode, defineComponent } from "vue"; import { Form } from "./form"; import { IFormItem } from "./form-item"; @@ -13,19 +13,26 @@ export const FormModal = defineComponent({ props: { /** * 弹窗标题 - * @default '新建' + * @default '添加' */ title: { type: [String, Function] as PropType< string | ((args: { model: Record; items: IFormItem[] }) => string) >, - default: "新建", + default: "添加", }, /** * 触发元素 */ trigger: { - type: [Boolean, Object] as PropType, + type: [Boolean, Object] as PropType< + | boolean + | ((props: { model: any; items: any[] }) => VNode) + | { + text?: string; + buttonProps?: ButtonInstance["$props"]; + } + >, default: true, }, /** @@ -119,20 +126,23 @@ export const FormModal = defineComponent({ return null; } let content; - if (typeof props.trigger === "boolean") { + if (typeof props.trigger === "boolean" || typeof props.trigger === "string") { content = ( ); } + if (typeof props.trigger === "function") { + content = props.trigger({ model: props.model, items: props.items }); + } if (typeof props.trigger === "object") { content = ( ); } diff --git a/src/components/form/form-node.tsx b/src/components/form/form-node.tsx index 6e7630b..32eef02 100644 --- a/src/components/form/form-node.tsx +++ b/src/components/form/form-node.tsx @@ -19,10 +19,10 @@ const initOptions = ({ item, model }: any) => { item.nodeProps.options = item.options; } if (typeof item.options === "function") { + const loadData = item.options; item.nodeProps.options = reactive([]); - const fetchData = item.options; item._updateOptions = async () => { - let data = await fetchData({ item, model }); + let data = await loadData({ item, model }); if (Array.isArray(data?.data?.data)) { data = data.data.data.map((i: any) => ({ label: i.name, value: i.id })); } @@ -35,10 +35,6 @@ const initOptions = ({ item, model }: any) => { } }; -const defineNodeMap = (map: T) => { - return map; -}; - /** * 表单项组件映射 */ @@ -101,12 +97,12 @@ export const nodeMap = { */ cascader: { component: Cascader, + init: initOptions, nodeProps: { placeholder: "请选择", allowClear: true, expandTrigger: "hover", } as InstanceType["$props"], - init: initOptions, }, /** * 时间选择框 @@ -169,8 +165,6 @@ export const nodeMap = { */ submit: { component: (props: any, { emit }: any) => { - const state = inject("tableInstance"); - console.log("st", state); return ( <> + ); + }, submit: ({ model }) => { console.log(model); },