create.vue 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <template>
  2. <ContentWrap>
  3. <!-- 对话框(添加 / 修改) -->
  4. <Form :schema="allSchemas.formSchema" :rules="rules" ref="formRef" />
  5. <!-- 按钮:保存 -->
  6. <XButton
  7. type="primary"
  8. :title="t('action.save')"
  9. :loading="actionLoading"
  10. @click="submitForm"
  11. />
  12. </ContentWrap>
  13. </template>
  14. <script setup lang="ts">
  15. import { FormExpose } from '@/components/Form'
  16. // import XEUtils from 'xe-utils'
  17. // 业务相关的 import
  18. import * as LeaveApi from '@/api/bpm/leave'
  19. import { rules, allSchemas } from './leave.data'
  20. const { t } = useI18n() // 国际化
  21. const message = useMessage() // 消息弹窗
  22. const { push } = useRouter() // 路由
  23. // 表单参数
  24. const actionLoading = ref(false) // 按钮 Loading
  25. const formRef = ref<FormExpose>() // 表单 Ref
  26. // 提交按钮
  27. const submitForm = async () => {
  28. const elForm = unref(formRef)?.getElFormRef()
  29. if (!elForm) return
  30. elForm.validate(async (valid) => {
  31. if (!valid) {
  32. return
  33. }
  34. try {
  35. // 设置提交中
  36. actionLoading.value = true
  37. const data = unref(formRef)?.formModel as LeaveApi.LeaveVO
  38. // data.startTime = XEUtils.toDateString(data.startTime, 'yyyy-MM-dd HH:mm:ss')
  39. // data.endTime = XEUtils.toDateString(data.endTime, 'yyyy-MM-dd HH:mm:ss')
  40. data.startTime = Date.parse(new Date(data.startTime).toString()).toString()
  41. data.endTime = Date.parse(new Date(data.endTime).toString()).toString()
  42. // 添加的提交
  43. await LeaveApi.createLeaveApi(data)
  44. message.success(t('common.createSuccess'))
  45. // 关闭窗口
  46. push('/bpm/oa/leave')
  47. } finally {
  48. actionLoading.value = false
  49. }
  50. })
  51. }
  52. </script>