四零语境后端代码仓库
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.

36 lines
982 B

6 months ago
  1. <template>
  2. <div>
  3. <BasicForm @register="registerForm" @submit="handleSubmit"/>
  4. </div>
  5. </template>
  6. <script lang="ts" setup>
  7. import { BasicForm, useForm } from '/@/components/Form/index';
  8. import { formSchema } from '../AppletCoursePage.data';
  9. import { saveOrUpdate } from '../AppletCoursePage.api';
  10. import { useMessage } from '/@/hooks/web/useMessage';
  11. const { createMessage } = useMessage();
  12. const emit = defineEmits(['success']);
  13. const [registerForm, { validate, resetFields }] = useForm({
  14. labelWidth: 120,
  15. schemas: formSchema,
  16. showActionButtonGroup: true,
  17. actionColOptions: {
  18. span: 24,
  19. },
  20. baseColProps: { span: 12 },
  21. });
  22. async function handleSubmit() {
  23. try {
  24. const values = await validate();
  25. await saveOrUpdate(values, false);
  26. createMessage.success('保存成功');
  27. await resetFields();
  28. emit('success');
  29. } catch (error) {
  30. createMessage.error('保存失败');
  31. }
  32. }
  33. </script>