Browse Source

新闻资讯样式优化

gzb
wangzhonglu 1 year ago
parent
commit
a78628f26b
2 changed files with 17 additions and 5 deletions
  1. 4
    1
      src/views/news/index.vue
  2. 13
    4
      src/views/news/newsEditor.vue

+ 4
- 1
src/views/news/index.vue View File

245
           detailInfo.newssummary
245
           detailInfo.newssummary
246
         }}</FormItem>
246
         }}</FormItem>
247
         <FormItem label="内容" prop="newscontent">
247
         <FormItem label="内容" prop="newscontent">
248
-          <div v-html="detailInfo.newscontent"></div>
248
+          <div class="news_content" v-html="detailInfo.newscontent"></div>
249
         </FormItem>
249
         </FormItem>
250
       </Form>
250
       </Form>
251
       <div slot="footer" style="text-align: center">
251
       <div slot="footer" style="text-align: center">
593
   padding: 16px 0;
593
   padding: 16px 0;
594
   text-align: right;
594
   text-align: right;
595
 }
595
 }
596
+.news_content /deep/ img {
597
+  max-width: 100%;
598
+}
596
 </style>
599
 </style>

+ 13
- 4
src/views/news/newsEditor.vue View File

111
                   imgSrc.indexOf("http://") > -1 ||
111
                   imgSrc.indexOf("http://") > -1 ||
112
                   imgSrc.indexOf("https://") > -1
112
                   imgSrc.indexOf("https://") > -1
113
                 ) {
113
                 ) {
114
-                  if (imgSrc.indexOf(that.$api.showImageUrl) == -1) {
114
+                  if (imgSrc.indexOf(that.$api.showImageUrl) === -1) {
115
                     that.imgsObj[imgSrc] = "";
115
                     that.imgsObj[imgSrc] = "";
116
                   }
116
                   }
117
                 }
117
                 }
186
       return new Promise(function (resolve, reject) {
186
       return new Promise(function (resolve, reject) {
187
         let ImgObj = new Image();
187
         let ImgObj = new Image();
188
         ImgObj.src = imgUrl;
188
         ImgObj.src = imgUrl;
189
-        ImgObj.setAttribute("crossOrigin", "Anonymous");
190
         ImgObj.onload = function () {
189
         ImgObj.onload = function () {
191
           resolve(imgUrl);
190
           resolve(imgUrl);
192
         };
191
         };
198
     changeImageUrl(imgSrc) {
197
     changeImageUrl(imgSrc) {
199
       let that = this;
198
       let that = this;
200
       let formData = new FormData();
199
       let formData = new FormData();
201
-      formData.append("newpath", "news");
202
-      formData.append("filepath", imgSrc);
200
+      formData.append("newpath", imgSrc);
201
+      formData.append("filepath", "news");
203
       that
202
       that
204
         .axios({
203
         .axios({
205
           method: "POST",
204
           method: "POST",
213
         .then((res) => {
212
         .then((res) => {
214
           if (!res.data.code) {
213
           if (!res.data.code) {
215
             that.imgsObj[imgSrc] = res.data.obj;
214
             that.imgsObj[imgSrc] = res.data.obj;
215
+            if (that.myCkeditor && that.myCkeditor.document.getBody().$) {
216
+              let oldhtml = that.myCkeditor.document.getBody().getHtml();
217
+              if (oldhtml) {
218
+                let newhtml = oldhtml.replaceAll(
219
+                  imgSrc,
220
+                  that.$api.showImageUrl + res.data.obj
221
+                );
222
+                that.setContent(newhtml);
223
+              }
224
+            }
216
           } else {
225
           } else {
217
             that.$Message.error(res.data.msg);
226
             that.$Message.error(res.data.msg);
218
           }
227
           }

Loading…
Cancel
Save