zhuoyuan.wang
2024-06-19 15ebe96f28cadec6a726c5324593a40bbf56205f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<template>
  <app-page-form v-bind="pageFormProps" v-loading="appStore.getLoading('getEntity')">
    <base-info v-bind="baseInfoProps"/>
    <editor-form v-bind="editorFormProps"/>
  </app-page-form>
</template>
 
<script setup>
 
import BaseInfo from './BaseInfo';
import EditorForm from './EditorForm';
import {closeTab} from '@/utils/iframe.js';
import {useAppStore, useEntityStore} from "@/store/modules";
import {convertFilter} from "@/utils/filter.js";
import * as baseApi from "@/api/index.js";
 
const entityStore = useEntityStore();
const appStore = useAppStore();
 
const router = useRouter();
 
const baseInfoRef = ref();
 
const baseInfoProps = {
  ref: baseInfoRef,
}
 
const params = router.currentRoute.value.query;
 
const onReset = async () => {
  if (params.id) {
    const {data} = await entityStore.getEntity({
      dataName: "affiche",
      filter: convertFilter({
        andEqParams: {
          id: params.id
        }
      })
    });
 
    const content = await baseApi.file.getFileText(data.affiche.file_id);
    baseInfoRef.value.onSetData(data.affiche);
    editorFormRef.value.onSetData({content});
    return;
  }
  baseInfoRef.value.onSetData({});
  editorFormRef.value.onSetData({});
 
}
 
onMounted(async () => {
  await onReset();
});
 
const editorFormRef = ref();
 
const editorFormProps = {
  ref: editorFormRef,
}
 
 
const pageFormProps = {
  subClose() {
    closeTab();
  },
  async subSubmit() {
    const baseInfo = await baseInfoRef.value.onGetData();
    const content = await editorFormRef.value.onGetData();
    await entityStore.dataEntity({
      dataName: 'affiche',
      data: {
        affiche: {
          ...baseInfo,
          content
        }
      }
    });
    closeTab();
  },
  async subReset() {
    await onReset();
  },
}
 
</script>