You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
56 lines
1.6 KiB
56 lines
1.6 KiB
<template> |
|
<BasicModal v-bind="$attrs" |
|
@register="registerModal" |
|
showFooter |
|
:title="getTitle" |
|
width="500px" |
|
@ok="handleSubmit" |
|
> |
|
<BasicForm @register="registerForm"/> |
|
</BasicModal> |
|
</template> |
|
<script lang="ts" setup> |
|
import { ref, computed, unref } from 'vue'; |
|
import { BasicForm, useForm } from '/@/components/Form/index'; |
|
import { formSchema } from './dict.data'; |
|
import { TreeItem } from '/@/components/Tree'; |
|
//import { set } from '/@/api/platform/system/controller/dict'; |
|
import {BasicModal, useModalInner} from "/@/components/Modal"; |
|
|
|
const emit = defineEmits(['success', 'register']); |
|
const isUpdate = ref(true); |
|
const treeData = ref<TreeItem[]>([]); |
|
|
|
const [registerForm, { resetFields, setFieldsValue, validate }] = useForm({ |
|
labelWidth: 100, |
|
schemas: formSchema, |
|
showActionButtonGroup: false, |
|
}); |
|
|
|
const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => { |
|
await resetFields(); |
|
setModalProps({ confirmLoading: false }); |
|
|
|
isUpdate.value = !!data?.isUpdate; |
|
|
|
if (unref(isUpdate)) { |
|
await setFieldsValue({ |
|
...data.record, |
|
}); |
|
} |
|
}); |
|
|
|
const getTitle = computed(() => (!unref(isUpdate) ? '新增字典' : '编辑字典')); |
|
|
|
async function handleSubmit() { |
|
try { |
|
const values = await validate(); |
|
setModalProps({ confirmLoading: true }); |
|
await set(values); |
|
closeModal(); |
|
emit('success'); |
|
} finally { |
|
setModalProps({ confirmLoading: false }); |
|
} |
|
} |
|
</script>
|
|
|