wangzhonglu 1 рік тому
джерело
коміт
f15c7e414e
2 змінених файлів з 56 додано та 67 видалено
  1. 39
    31
      src/views/news/index.vue
  2. 17
    36
      src/views/news/newsEditor.vue

+ 39
- 31
src/views/news/index.vue Переглянути файл

@@ -494,22 +494,26 @@ export default {
494 494
       };
495 495
     },
496 496
     toSaveAdd() {
497
-      n_save({
498
-        newstitle: this.addForm.newstitle,
499
-        newscontent: this.addForm.newscontent,
500
-        newssummary: this.addForm.newssummary,
501
-        newspic: this.addForm.newspic,
502
-        ltype: this.addForm.ltype,
503
-        newsorder: this.addForm.newsorder,
504
-        newsup: this.addForm.newsup,
505
-        createid: this.userInfo.userid
506
-      }).then((res) => {
507
-        this.addForm.show = false;
508
-        if (res.code === 0) {
509
-          this.$Message.success(res.msg);
510
-          this.searchList();
511
-        } else {
512
-          this.$Message.error(res.msg);
497
+      this.$refs.addForm.validate((valid) => {
498
+        if (valid) {
499
+          n_save({
500
+            newstitle: this.addForm.newstitle,
501
+            newscontent: this.addForm.newscontent,
502
+            newssummary: this.addForm.newssummary,
503
+            newspic: this.addForm.newspic,
504
+            ltype: this.addForm.ltype,
505
+            newsorder: this.addForm.newsorder,
506
+            newsup: this.addForm.newsup,
507
+            createid: this.userInfo.userid
508
+          }).then((res) => {
509
+            this.addForm.show = false;
510
+            if (res.code === 0) {
511
+              this.$Message.success(res.msg);
512
+              this.searchList();
513
+            } else {
514
+              this.$Message.error(res.msg);
515
+            }
516
+          });
513 517
         }
514 518
       });
515 519
     },
@@ -526,21 +530,25 @@ export default {
526 530
       };
527 531
     },
528 532
     toSaveModify() {
529
-      n_update({
530
-        newstitle: this.modifyForm.newstitle,
531
-        newscontent: this.modifyForm.newscontent,
532
-        newssummary: this.modifyForm.newssummary,
533
-        newspic: this.modifyForm.newspic,
534
-        newsorder: this.modifyForm.newsorder,
535
-        newsup: this.modifyForm.newsup,
536
-        newsid: this.modifyForm.newsid
537
-      }).then((res) => {
538
-        this.modifyForm.show = false;
539
-        if (res.code === 0) {
540
-          this.$Message.success(res.msg);
541
-          this.searchList();
542
-        } else {
543
-          this.$Message.error(res.msg);
533
+      this.$refs.modifyForm.validate((valid) => {
534
+        if (valid) {
535
+          n_update({
536
+            newstitle: this.modifyForm.newstitle,
537
+            newscontent: this.modifyForm.newscontent,
538
+            newssummary: this.modifyForm.newssummary,
539
+            newspic: this.modifyForm.newspic,
540
+            newsorder: this.modifyForm.newsorder,
541
+            newsup: this.modifyForm.newsup,
542
+            newsid: this.modifyForm.newsid
543
+          }).then((res) => {
544
+            this.modifyForm.show = false;
545
+            if (res.code === 0) {
546
+              this.$Message.success(res.msg);
547
+              this.searchList();
548
+            } else {
549
+              this.$Message.error(res.msg);
550
+            }
551
+          });
544 552
         }
545 553
       });
546 554
     },

+ 17
- 36
src/views/news/newsEditor.vue Переглянути файл

@@ -120,33 +120,27 @@ export default {
120 120
           }
121 121
         });
122 122
         that.myCkeditor.on("afterPaste", function () {
123
-          let imgPromiseArr = [];
123
+          let newImgsPromiseArr = [];
124 124
           for (const imgSrc in that.imgsObj) {
125
-            if (!that.imgsObj[imgSrc]) {
126
-              imgPromiseArr.push(that.checkImgExists(imgSrc));
125
+            if (!that.imgsObj[imgSrc] && imgSrc) {
126
+              newImgsPromiseArr.push(that.changeImageUrl(imgSrc));
127 127
             }
128 128
           }
129
-          Promise.all(imgPromiseArr)
130
-            .then((imgURLPromiseArr) => {
131
-              let newImgsPromiseArr = [];
132
-              for (const _url of imgURLPromiseArr) {
133
-                newImgsPromiseArr.push(that.changeImageUrl(_url));
129
+          Promise.all(newImgsPromiseArr).then((newImgs) => {
130
+            let oldhtml = "";
131
+            if (that.myCkeditor && that.myCkeditor.document.getBody().$) {
132
+              oldhtml = that.myCkeditor.document.getBody().getHtml();
133
+            }
134
+            for (const imgArr of newImgs) {
135
+              if (imgArr && imgArr[0] && imgArr[1]) {
136
+                oldhtml = oldhtml.replaceAll(
137
+                  imgArr[0],
138
+                  that.$api.showImageUrl + imgArr[1]
139
+                );
134 140
               }
135
-              Promise.all(newImgsPromiseArr).then((newImgs) => {
136
-                let oldhtml = "";
137
-                if (that.myCkeditor && that.myCkeditor.document.getBody().$) {
138
-                  oldhtml = that.myCkeditor.document.getBody().getHtml();
139
-                }
140
-                for (const imgArr of newImgs) {
141
-                  oldhtml = oldhtml.replaceAll(
142
-                    imgArr[0],
143
-                    that.$api.showImageUrl + imgArr[1]
144
-                  );
145
-                }
146
-                that.setContent(oldhtml);
147
-              });
148
-            })
149
-            .catch(() => {});
141
+            }
142
+            that.setContent(oldhtml);
143
+          });
150 144
         });
151 145
         that.myCkeditor.on("fileUploadRequest", async function (evt) {
152 146
           let fileLoader = evt.data.fileLoader,
@@ -196,19 +190,6 @@ export default {
196 190
         });
197 191
       });
198 192
     },
199
-    // 验证图片连接是否有效
200
-    checkImgExists(imgUrl) {
201
-      return new Promise(function (resolve, reject) {
202
-        let ImgObj = new Image();
203
-        ImgObj.src = imgUrl;
204
-        ImgObj.onload = function () {
205
-          resolve(imgUrl);
206
-        };
207
-        ImgObj.onerror = function () {
208
-          reject(imgUrl);
209
-        };
210
-      });
211
-    },
212 193
     changeImageUrl(imgSrc) {
213 194
       return new Promise((resolve, reject) => {
214 195
         let that = this;

Завантаження…
Відмінити
Зберегти