ExampleEdit.vue 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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, useRoute } from 'vue-router'
  7. import { saveTableApi, getTableDetApi } from '@/api/table'
  8. import { TableData } from '@/api/table/types'
  9. import { useEmitt } from '@/hooks/event/useEmitt'
  10. const { emitter } = useEmitt()
  11. const { push, go } = useRouter()
  12. const { query } = useRoute()
  13. const { t } = useI18n()
  14. const currentRow = ref<Nullable<TableData>>(null)
  15. const getTableDet = async () => {
  16. const res = await getTableDetApi(query.id as string)
  17. if (res) {
  18. currentRow.value = res.data
  19. }
  20. }
  21. getTableDet()
  22. const writeRef = ref<ComponentRef<typeof Write>>()
  23. const loading = ref(false)
  24. const save = async () => {
  25. const write = unref(writeRef)
  26. const formData = await write?.submit()
  27. if (formData) {
  28. loading.value = true
  29. const res = await saveTableApi(formData)
  30. .catch(() => {})
  31. .finally(() => {
  32. loading.value = false
  33. })
  34. if (res) {
  35. emitter.emit('getList', 'editor')
  36. push('/example/example-page')
  37. }
  38. }
  39. }
  40. </script>
  41. <template>
  42. <ContentDetailWrap :title="t('exampleDemo.edit')" @back="push('/example/example-page')">
  43. <Write ref="writeRef" :current-row="currentRow" />
  44. <template #header>
  45. <BaseButton @click="go(-1)">
  46. {{ t('common.back') }}
  47. </BaseButton>
  48. <BaseButton type="primary" :loading="loading" @click="save">
  49. {{ t('exampleDemo.save') }}
  50. </BaseButton>
  51. </template>
  52. </ContentDetailWrap>
  53. </template>
  54. @/hooks/event/useEmitt