Bläddra i källkod

新闻资讯样式优化

gzb
wangzhonglu 1 år sedan
förälder
incheckning
a78628f26b
2 ändrade filer med 17 tillägg och 5 borttagningar
  1. 4
    1
      src/views/news/index.vue
  2. 13
    4
      src/views/news/newsEditor.vue

+ 4
- 1
src/views/news/index.vue Visa fil

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

+ 13
- 4
src/views/news/newsEditor.vue Visa fil

@@ -111,7 +111,7 @@ export default {
111 111
                   imgSrc.indexOf("http://") > -1 ||
112 112
                   imgSrc.indexOf("https://") > -1
113 113
                 ) {
114
-                  if (imgSrc.indexOf(that.$api.showImageUrl) == -1) {
114
+                  if (imgSrc.indexOf(that.$api.showImageUrl) === -1) {
115 115
                     that.imgsObj[imgSrc] = "";
116 116
                   }
117 117
                 }
@@ -186,7 +186,6 @@ export default {
186 186
       return new Promise(function (resolve, reject) {
187 187
         let ImgObj = new Image();
188 188
         ImgObj.src = imgUrl;
189
-        ImgObj.setAttribute("crossOrigin", "Anonymous");
190 189
         ImgObj.onload = function () {
191 190
           resolve(imgUrl);
192 191
         };
@@ -198,8 +197,8 @@ export default {
198 197
     changeImageUrl(imgSrc) {
199 198
       let that = this;
200 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 202
       that
204 203
         .axios({
205 204
           method: "POST",
@@ -213,6 +212,16 @@ export default {
213 212
         .then((res) => {
214 213
           if (!res.data.code) {
215 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 225
           } else {
217 226
             that.$Message.error(res.data.msg);
218 227
           }

Laddar…
Avbryt
Spara