decorate.vue 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <template>
  2. <DiyEditor
  3. v-if="formData && !formLoading"
  4. v-model="formData.property"
  5. :title="formData.name"
  6. :libs="PAGE_LIBS"
  7. @save="submitForm"
  8. />
  9. </template>
  10. <script setup lang="ts">
  11. import * as DiyPageApi from '@/api/mall/promotion/diy/page'
  12. import { useTagsViewStore } from '@/store/modules/tagsView'
  13. import { PAGE_LIBS } from '@/components/DiyEditor/util'
  14. /** 装修页面表单 */
  15. defineOptions({ name: 'DiyPageDecorate' })
  16. const message = useMessage() // 消息弹窗
  17. const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
  18. const formData = ref<DiyPageApi.DiyPageVO>()
  19. const formRef = ref() // 表单 Ref
  20. // 获取详情
  21. const getPageDetail = async (id: any) => {
  22. formLoading.value = true
  23. try {
  24. formData.value = await DiyPageApi.getDiyPageProperty(id)
  25. } finally {
  26. formLoading.value = false
  27. }
  28. }
  29. // 提交表单
  30. const submitForm = async () => {
  31. // 校验表单
  32. if (!formRef) return
  33. // 提交请求
  34. formLoading.value = true
  35. try {
  36. await DiyPageApi.updateDiyPageProperty(unref(formData)!)
  37. message.success('保存成功')
  38. } finally {
  39. formLoading.value = false
  40. }
  41. }
  42. // 重置表单
  43. const resetForm = () => {
  44. formData.value = {
  45. id: undefined,
  46. templateId: undefined,
  47. name: '',
  48. remark: '',
  49. previewImageUrls: [],
  50. property: ''
  51. } as DiyPageApi.DiyPageVO
  52. formRef.value?.resetFields()
  53. }
  54. /** 初始化 **/
  55. const { currentRoute } = useRouter() // 路由
  56. const { delView } = useTagsViewStore() // 视图操作
  57. const route = useRoute()
  58. onMounted(() => {
  59. resetForm()
  60. if (!route.params.id) {
  61. message.warning('参数错误,页面编号不能为空!')
  62. delView(unref(currentRoute))
  63. return
  64. }
  65. getPageDetail(route.params.id)
  66. })
  67. </script>