AccountModal.vue 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <template>
  2. <BasicModal v-bind="$attrs" @register="registerModal" :title="getTitle" @ok="handleSubmit">
  3. <BasicForm @register="registerForm" />
  4. </BasicModal>
  5. </template>
  6. <script lang="ts">
  7. import { defineComponent, ref, computed, unref } from 'vue';
  8. import { BasicModal, useModalInner } from '/@/components/Modal';
  9. import { BasicForm, useForm } from '/@/components/Form/index';
  10. import { accountFormSchema } from './account.data';
  11. export default defineComponent({
  12. name: 'AccountModal',
  13. components: { BasicModal, BasicForm },
  14. setup() {
  15. const isUpdate = ref(true);
  16. const [registerForm, { setFieldsValue, validate }] = useForm({
  17. labelWidth: 100,
  18. schemas: accountFormSchema,
  19. showActionButtonGroup: false,
  20. actionColOptions: {
  21. span: 23,
  22. },
  23. });
  24. const [registerModal, { setModalProps }] = useModalInner((data) => {
  25. setModalProps({ confirmLoading: false });
  26. isUpdate.value = !!data?.isUpdate;
  27. if (unref(isUpdate)) {
  28. setFieldsValue({
  29. ...data.record,
  30. });
  31. }
  32. });
  33. const getTitle = computed(() => (!unref(isUpdate) ? '新增账号' : '编辑账号'));
  34. async function handleSubmit() {
  35. try {
  36. const values = await validate();
  37. setModalProps({ confirmLoading: true });
  38. // TODO custom api
  39. console.log(values);
  40. } finally {
  41. setModalProps({ confirmLoading: false });
  42. }
  43. }
  44. return { registerModal, registerForm, getTitle, handleSubmit };
  45. },
  46. });
  47. </script>