create.vue 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 router = 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())
  41. data.endTime = Date.parse(new Date(data.endTime).toString())
  42. // 添加的提交
  43. await LeaveApi.createLeaveApi(data)
  44. message.success(t('common.createSuccess'))
  45. // 关闭窗口
  46. router.push({
  47. path: '/bpm/oa/leave'
  48. })
  49. } finally {
  50. actionLoading.value = false
  51. }
  52. })
  53. }
  54. </script>