Răsfoiți Sursa

特殊字符

panhui 4 ani în urmă
părinte
comite
01c8053071
3 a modificat fișierele cu 28 adăugiri și 9 ștergeri
  1. 20 0
      src/mixins/nodeHtml.js
  2. 3 7
      src/pagesNews/Detail.vue
  3. 5 2
      src/pagesProduct/Detail.vue

+ 20 - 0
src/mixins/nodeHtml.js

@@ -0,0 +1,20 @@
+export default {
+    data() {
+        return {
+            specialVal: [[/±/g, '±'], [/á/g, 'á']]
+        };
+    },
+    methods: {
+        initText(text) {
+            return text.replace(/code/g, '_Code');
+        },
+        changeText(info) {
+            let allText = JSON.stringify(info);
+            allText = allText.replace(/_Code/g, 'code');
+            [...this.specialVal].forEach(item => {
+                allText = allText.replace(item[0], item[1]);
+            });
+            return JSON.parse(allText);
+        }
+    }
+};

+ 3 - 7
src/pagesNews/Detail.vue

@@ -80,6 +80,7 @@ import Banner from '../components/Banner.vue';
 import CustomBar from '../components/bar/CustomBar.vue';
 import FixedButton from '../components/FixedButton';
 import octoparse from 'octoparse';
+import nodeHtml from '../mixins/nodeHtml';
 export default {
     data() {
         return {
@@ -91,6 +92,7 @@ export default {
             imgList: []
         };
     },
+    mixins: [nodeHtml],
     computed: {
         banners() {
             return this.info.img
@@ -121,7 +123,7 @@ export default {
             this.info = res;
             this.imgList = [];
             let _this = this;
-            res.content = res.content.replace(/code/g, '_Code');
+            res.content = this.initText(res.content);
             let options = {
                 visitors: {
                     img(node) {
@@ -161,11 +163,6 @@ export default {
         }
     },
     methods: {
-        changeText(info) {
-            let allText = JSON.stringify(info);
-            allText = allText.replace(/_Code/g, 'code');
-            return JSON.parse(allText);
-        },
         getActivity() {
             this.$http
                 .post(
@@ -246,7 +243,6 @@ export default {
             }
         }
     },
-
     onPageScroll() {},
     onShareAppMessage(from, target) {
         return {

+ 5 - 2
src/pagesProduct/Detail.vue

@@ -222,6 +222,7 @@ import { mapState } from 'vuex';
 import { saveBrowse } from '../utils/commont';
 import Dialog from '../native/vant/dialog/dialog';
 import octoparse from 'octoparse';
+import nodeHtml from '../mixins/nodeHtml';
 export default {
     components: { CustomBar, Banner, Parameter },
     data() {
@@ -239,7 +240,7 @@ export default {
             imgList: []
         };
     },
-    mixins: [collection],
+    mixins: [collection, nodeHtml],
     computed: {
         ...mapState(['intentionList', 'barHeight']),
         origin() {
@@ -351,7 +352,9 @@ export default {
                             }
                         }
                     };
-                    this.detail = octoparse.htmlParse(res.detailImg, options);
+                    res.detailImg = this.initText(res.detailImg);
+                    let detail = octoparse.htmlParse(res.detailImg, options);
+                    this.detail = this.changeText(detail);
                     if (res.video) {
                         wx.setNavigationBarColor({
                             frontColor: '#ffffff',