Parcourir la source

模板编辑初步完成

zhangjie il y a 2 ans
Parent
commit
6cf901928a

+ 13 - 0
src/modules/paper-export/components/PaperTemplateDesign.vue

@@ -60,6 +60,13 @@
           >
         </div>
         <div class="control-right">
+          <el-button
+            type="success"
+            :loading="isSubmit"
+            :disabled="!pages.length"
+            @click="toPreview"
+            >预览</el-button
+          >
           <el-button type="primary" :loading="isSubmit" @click="toSubmit"
             >提交</el-button
           >
@@ -266,6 +273,12 @@ export default {
         }, 100);
       });
     },
+    toPreview() {
+      if (this.isSubmit) return;
+      this.$emit("on-preview", {
+        pages: this.pages,
+      });
+    },
     toSubmit() {
       if (this.isSubmit) return;
       this.$emit("on-submit", {

+ 26 - 69
src/modules/paper-export/views/PaperTemplateEdit.vue

@@ -5,15 +5,9 @@
       ref="PaperTemplateDesign"
       :content="tempContent"
       @on-preview="toPreview"
-      @on-save="toSave"
       @on-submit="toSubmit"
       @on-exit="toExit"
     ></paper-template-design>
-
-    <!-- paper-template-view-frame -->
-    <div v-if="tempPreviewUrl" class="design-preview-frame">
-      <iframe :src="tempPreviewUrl" frameborder="0"></iframe>
-    </div>
   </div>
 </template>
 
@@ -29,31 +23,26 @@ export default {
     return {
       tid: this.$route.params.tid,
       tempContent: {},
-      tempPreviewUrl: "",
       dataReady: false,
     };
   },
   computed: {
     isEdit() {
-      return !!this.cardId;
+      return !!this.tid;
     },
   },
-  beforeDestroy() {
-    delete window.submitCardTemp;
-  },
   mounted() {
     this.initData();
-    // todo:不需要预览了获取html了
-    this.registWindowSubmit();
   },
   methods: {
-    initData() {
+    async initData() {
       this.dataReady = false;
       if (this.isEdit) {
-        this.getPaperTemplate();
+        await this.getPaperTemplate();
       } else {
         this.initTempContent();
       }
+      this.dataReady = true;
     },
     async getPaperTemplate() {
       const detDataRes = await paperTemplateDetailApi(this.tid);
@@ -71,8 +60,11 @@ export default {
       };
     },
     // 操作
-    async toPreview(datas) {
-      await this.toSave(datas);
+    async toPreview(paperTempData) {
+      const result = await this.toSave(paperTempData).catch(() => {});
+      if (!result) {
+        this.$message.error("保存失败");
+      }
 
       const { href } = this.$router.resolve({
         name: "PaperTemplatePreview",
@@ -84,63 +76,28 @@ export default {
       window.open(href);
     },
     // save
-    async toSave(infos) {
-      let datas = { ...infos };
-      datas.id = this.tid;
-      datas.formal = false;
+    async toSave(paperTempData) {
+      this.$refs.PaperTemplateDesign.loading();
+
+      let datas = {
+        id: this.tid,
+        content: JSON.stringify(paperTempData),
+        formal: true,
+      };
       let result = await savePaperTemplateApi(datas).catch(() => {});
       this.$refs.PaperTemplateDesign.unloading();
-      if (!result) return;
+      if (!result) return Promise.reject("保存失败");
       this.tid = result.data;
-      this.$message.success("保存成功!");
+      return Promise.resolve("保存成功!");
     },
     async toSubmit(paperTempData) {
-      const res = await this.$confirm("确定要提交当前模板吗?", "提示", {
-        type: "warning",
-      }).catch(() => {});
-      if (res !== "confirm") return;
-
-      window.paperTempData = paperTempData;
-      this.$refs.PaperTemplateDesign.loading();
-      const { href } = this.$router.resolve({
-        name: "PaperTemplatePreview",
-        params: {
-          tid: 1,
-          viewType: "frame",
-        },
-        query: {
-          t: Date.now(),
-        },
-      });
-      this.tempPreviewUrl = href;
-    },
-    registWindowSubmit() {
-      window.submitCardTemp = async (tempContent) => {
-        if (!tempContent) {
-          this.$refs.PaperTemplateDesign.unloading();
-          window.paperTempData = null;
-          this.tempPreviewUrl = "";
-          this.$message.error("提交失败,请重新尝试!");
-          return;
-        }
-
-        let datas = {
-          content: tempContent,
-        };
-        datas.id = this.tid;
-        datas.formal = true;
-        let result = await savePaperTemplateApi(datas).catch(() => {});
-        this.tempPreviewUrl = "";
-        window.paperTempData = null;
-        this.$refs.PaperTemplateDesign.unloading();
-        if (result) {
-          this.tid = result.data;
-          this.$message.success("提交成功!");
-          this.goback();
-        } else {
-          this.$message.error("提交失败,请重新尝试!");
-        }
-      };
+      const result = await this.toSave(paperTempData).catch(() => {});
+      if (result) {
+        this.$message.success("提交成功!");
+        this.goback();
+      } else {
+        this.$message.error("提交失败,请重新尝试!");
+      }
     },
     toExit() {
       this.$confirm(