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.5 KiB
56 lines
1.5 KiB
1 year ago
|
<script lang="ts" setup>
|
||
|
import { ref } from 'vue'
|
||
|
import { formSchema } from './data'
|
||
|
import { useMessage } from '@/hooks/web/useMessage'
|
||
|
import { BasicForm, useForm } from '@/components/Form'
|
||
|
import { BasicModal, useModalInner } from '@/components/Modal'
|
||
|
import { createMenu, updateMenu } from '@/api/system/menu'
|
||
|
import type { MenuItem } from '@/api/system/menu/types'
|
||
|
|
||
|
defineOptions({ name: 'SystemMenuFormModal' })
|
||
|
|
||
|
const emit = defineEmits(['success', 'register'])
|
||
|
|
||
|
const [registerForm, { setFieldsValue, validate }] = useForm({
|
||
|
labelWidth: 140,
|
||
|
baseColProps: { span: 24 },
|
||
|
schemas: formSchema,
|
||
|
showActionButtonGroup: false,
|
||
|
})
|
||
|
|
||
|
const isUpdate = ref(true)
|
||
|
const [registerModal, { setModalProps, closeModal }] = useModalInner((data: MenuItem) => {
|
||
|
isUpdate.value = true
|
||
|
setFieldsValue({
|
||
|
...data,
|
||
|
parentId: data.parentId === '0' ? undefined : data.parentId,
|
||
|
})
|
||
|
})
|
||
|
|
||
|
async function handleSubmit() {
|
||
|
try {
|
||
|
const values = await validate<MenuItem>()
|
||
|
setModalProps({ confirmLoading: true })
|
||
|
await (isUpdate.value ? updateMenu(values) : createMenu(values))
|
||
|
emit('success')
|
||
|
closeModal()
|
||
|
useMessage().createMessage.success('保存成功')
|
||
|
}
|
||
|
finally {
|
||
|
setModalProps({ confirmLoading: false })
|
||
|
}
|
||
|
}
|
||
|
</script>
|
||
|
|
||
|
<template>
|
||
|
<BasicModal
|
||
|
v-bind="$attrs"
|
||
|
:title="isUpdate ? '编辑' : '新建'"
|
||
|
@register="registerModal"
|
||
|
@ok="handleSubmit"
|
||
|
@cancel="isUpdate = false"
|
||
|
>
|
||
|
<BasicForm @register="registerForm" @submit="handleSubmit" />
|
||
|
</BasicModal>
|
||
|
</template>
|