ExampleAdd.vue 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <script setup lang="ts">
  2. import Write from './components/Write.vue'
  3. import { ContentDetailWrap } from '@/components/ContentDetailWrap'
  4. import { ref, unref } from 'vue'
  5. import { useI18n } from '@/hooks/web/useI18n'
  6. import { useRouter } from 'vue-router'
  7. import { saveTableApi } from '@/api/table'
  8. import { useEventBus } from '@/hooks/event/useEventBus'
  9. const { emit } = useEventBus()
  10. const { push, go } = useRouter()
  11. const { t } = useI18n()
  12. const writeRef = ref<ComponentRef<typeof Write>>()
  13. const loading = ref(false)
  14. const save = async () => {
  15. const write = unref(writeRef)
  16. const formData = await write?.submit()
  17. if (formData) {
  18. loading.value = true
  19. const res = await saveTableApi(formData)
  20. .catch(() => {})
  21. .finally(() => {
  22. loading.value = false
  23. })
  24. if (res) {
  25. emit('getList', 'add')
  26. push('/example/example-page')
  27. }
  28. }
  29. }
  30. </script>
  31. <template>
  32. <ContentDetailWrap :title="t('exampleDemo.add')" @back="push('/example/example-page')">
  33. <Write ref="writeRef" />
  34. <template #header>
  35. <BaseButton @click="go(-1)">
  36. {{ t('common.back') }}
  37. </BaseButton>
  38. <BaseButton type="primary" :loading="loading" @click="save">
  39. {{ t('exampleDemo.save') }}
  40. </BaseButton>
  41. </template>
  42. </ContentDetailWrap>
  43. </template>
  44. @/hooks/event/useEventBus