decorate.vue 1.8 KB

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