Commit f8e54dda30dd28d8994bc80f15969d3d9b3f4068
1 parent
81b8f417
feat: vben codegen
Showing
1 changed file
with
42 additions
and
37 deletions
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3_vben/views/form.vue.vm
| 1 | <template> | 1 | <template> |
| 2 | - <BasicModal v-bind="$attrs" @register="registerModal" :title="isUpdate ? '编辑' : '新增'" @ok="handleSubmit"> | 2 | + <BasicModal v-bind="$attrs" @register="registerModal" :title="isUpdate ? t('action.edit') : t('action.create')" @ok="handleSubmit"> |
| 3 | <BasicForm @register="registerForm" /> | 3 | <BasicForm @register="registerForm" /> |
| 4 | </BasicModal> | 4 | </BasicModal> |
| 5 | </template> | 5 | </template> |
| 6 | <script lang="ts" setup name="${table.className}Modal"> | 6 | <script lang="ts" setup name="${table.className}Modal"> |
| 7 | - import { ref, unref } from 'vue' | ||
| 8 | - import { BasicModal, useModalInner } from '@/components/Modal' | ||
| 9 | - import { BasicForm, useForm } from '@/components/Form' | ||
| 10 | - import { formSchema } from './${classNameVar}.data' | ||
| 11 | - import { create${simpleClassName}, get${simpleClassName}, update${simpleClassName} } from '@/api/${table.moduleName}/${classNameVar}' | 7 | +import { ref, unref } from 'vue' |
| 8 | +import { useI18n } from '@/hooks/web/useI18n' | ||
| 9 | +import { useMessage } from '@/hooks/web/useMessage' | ||
| 10 | +import { BasicForm, useForm } from '@/components/Form' | ||
| 11 | +import { BasicModal, useModalInner } from '@/components/Modal' | ||
| 12 | +import { formSchema } from './${classNameVar}.data' | ||
| 13 | +import { create${simpleClassName}, get${simpleClassName}, update${simpleClassName} } from '@/api/${table.moduleName}/${classNameVar}' | ||
| 12 | 14 | ||
| 13 | - const emit = defineEmits(['success', 'register']) | ||
| 14 | - const isUpdate = ref(true) | 15 | +const { t } = useI18n() |
| 16 | +const { createMessage } = useMessage() | ||
| 17 | +const emit = defineEmits(['success', 'register']) | ||
| 18 | +const isUpdate = ref(true) | ||
| 15 | 19 | ||
| 16 | - const [registerForm, { setFieldsValue, resetFields, validate }] = useForm({ | ||
| 17 | - labelWidth: 120, | ||
| 18 | - baseColProps: { span: 24 }, | ||
| 19 | - schemas: formSchema, | ||
| 20 | - showActionButtonGroup: false, | ||
| 21 | - actionColOptions: { span: 23 } | ||
| 22 | - }) | 20 | +const [registerForm, { setFieldsValue, resetFields, validate }] = useForm({ |
| 21 | + labelWidth: 120, | ||
| 22 | + baseColProps: { span: 24 }, | ||
| 23 | + schemas: formSchema, | ||
| 24 | + showActionButtonGroup: false, | ||
| 25 | + actionColOptions: { span: 23 } | ||
| 26 | +}) | ||
| 23 | 27 | ||
| 24 | - const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => { | ||
| 25 | - resetFields() | ||
| 26 | - setModalProps({ confirmLoading: false }) | ||
| 27 | - isUpdate.value = !!data?.isUpdate | ||
| 28 | - if (unref(isUpdate)) { | ||
| 29 | - const res = await get${simpleClassName}(data.record.id) | ||
| 30 | - setFieldsValue({ ...res }) | ||
| 31 | - } | ||
| 32 | - }) | 28 | +const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => { |
| 29 | + resetFields() | ||
| 30 | + setModalProps({ confirmLoading: false }) | ||
| 31 | + isUpdate.value = !!data?.isUpdate | ||
| 32 | + if (unref(isUpdate)) { | ||
| 33 | + const res = await get${simpleClassName}(data.record.id) | ||
| 34 | + setFieldsValue({ ...res }) | ||
| 35 | + } | ||
| 36 | +}) | ||
| 33 | 37 | ||
| 34 | - async function handleSubmit() { | ||
| 35 | - try { | ||
| 36 | - const values = await validate() | ||
| 37 | - setModalProps({ confirmLoading: true }) | ||
| 38 | - if (unref(isUpdate)) { | ||
| 39 | - await update${simpleClassName}(values) | ||
| 40 | - } else { | ||
| 41 | - await create${simpleClassName}(values) | ||
| 42 | - } | ||
| 43 | - closeModal() | ||
| 44 | - emit('success') | ||
| 45 | - } finally { | ||
| 46 | - setModalProps({ confirmLoading: false }) | 38 | +async function handleSubmit() { |
| 39 | + try { | ||
| 40 | + const values = await validate() | ||
| 41 | + setModalProps({ confirmLoading: true }) | ||
| 42 | + if (unref(isUpdate)) { | ||
| 43 | + await update${simpleClassName}(values) | ||
| 44 | + } else { | ||
| 45 | + await create${simpleClassName}(values) | ||
| 47 | } | 46 | } |
| 47 | + closeModal() | ||
| 48 | + emit('success') | ||
| 49 | + } finally { | ||
| 50 | + createMessage.success(t('common.saveSuccessText')) | ||
| 51 | + setModalProps({ confirmLoading: false }) | ||
| 48 | } | 52 | } |
| 53 | +} | ||
| 49 | </script> | 54 | </script> |