chengjie vor 4 Monaten
Ursprung
Commit
6c4368240b
4 geänderte Dateien mit 48 neuen und 12 gelöschten Zeilen
  1. 24 5
      pages/main/article.js
  2. 3 2
      pages/main/article.wxml
  3. 20 4
      pages/main/myarticles.js
  4. 1 1
      pages/main/myarticles.wxml

+ 24 - 5
pages/main/article.js

@@ -146,20 +146,39 @@ Page({
146 146
     let hl="nonelight";
147 147
     if (that.data.IsShowKeyword)
148 148
       hl="highlight";
149
+    
150
+    // 简化的解决方案:按长度排序并使用临时标记
149 151
     for(let i=0;i<content.ArticleEnglish.length;i++){
150
-      for(let j=0;j<content.FormsOfWords.length;j++){
151
-        let word = content.FormsOfWords[j];
152
+      // 1. 先对单词按长度从长到短排序,确保先处理"Come on"再处理"Come"
153
+      let sortedWords = [...content.FormsOfWords].sort((a, b) => b.length - a.length);
154
+      
155
+      // 2. 使用临时标记替换匹配的单词,避免HTML解析问题
156
+      let text = content.ArticleEnglish[i];
157
+      let placeholders = [];
158
+      for(let j=0;j<sortedWords.length;j++){
159
+        let word = sortedWords[j];
152 160
         let regex = new RegExp(`\\b${word}\\b[.,!?;:]?`, 'gi');
153
-        content.ArticleEnglish[i] = content.ArticleEnglish[i].replace(regex, match => {
161
+        
162
+        text = text.replace(regex, match => {
154 163
           let punctuation = match.match(/[.,!?;:]$/);
155 164
           let punc = punctuation ? punctuation[0] : '';
156 165
           let wordPart = match.replace(/[.,!?;:]$/, '');
157
-          return `<span class='`+hl+`'>${wordPart}</span>${punc}`;
166
+          
167
+          // 使用唯一的占位符
168
+          let placeholder = `__PLACEHOLDER_${placeholders.length}__`;
169
+          placeholders.push(`<span class='${hl}'>${wordPart}</span>${punc}`);
170
+          return placeholder;
158 171
         });
159 172
       }
173
+      
174
+      // 3. 将临时标记替换为实际的HTML标签
175
+      for(let j=0; j<placeholders.length; j++){
176
+        text = text.replace(`__PLACEHOLDER_${j}__`, placeholders[j]);
177
+      }
178
+      
179
+      content.ArticleEnglish[i] = text;
160 180
     }
161 181
     content.ArticleEnglishArr=[];
162
-    //debugger;
163 182
     for(let i=0;i<content.ArticleEnglish.length;i++){
164 183
       let obj=common.splitByMultipleDelimiters(content.ArticleEnglish[i],["<span class='"+hl+"'>","</span>"]);
165 184
       obj=common.removeDuplicateAndTrimStrings(obj);

+ 3 - 2
pages/main/article.wxml

@@ -18,8 +18,9 @@
18 18
     </text>
19 19
     <!-- 有翻译文章 -->
20 20
     <view class="textArticle FlexColumn" wx:if="{{IsShowTranslate}}">
21
-      <view wx:for="{{Content.ArticleEnglish}}" wx:key="index" class="textArticle">
22
-        <rich-text class="textArticle" nodes="{{item}}"></rich-text>
21
+      <view wx:for="{{Content.ArticleEnglishArr}}" wx:key="index" class="textArticle">
22
+        <!-- <rich-text class="textArticle" nodes="{{item}}"></rich-text> -->
23
+        <text  class="{{itemChild.CSS}}" wx:for="{{item}}" wx:key="index2" wx:for-item="itemChild" wx:for-index="indexChild">{{itemChild.Content}}</text>
23 24
         <view class="textArticleTranslate">{{Content.ArticleChinese[index]}}</view>
24 25
         <view class="panelLine" wx:if="{{index<Content.ArticleEnglish.length-1}}"></view>
25 26
       </view>

+ 20 - 4
pages/main/myarticles.js

@@ -12,14 +12,14 @@ Page({
12 12
     that.setData({
13 13
       Containnerheight: main.getWindowHeight(),
14 14
     });
15
-    that.getData();
15
+    that.getData(app.globalData.userInfo.UserID);
16 16
   },
17
-  getData:function(){
17
+  getData:function(userID){
18 18
     wx.showLoading({
19 19
       title: '请稍候',
20 20
     });
21 21
     let that=this;
22
-    main.getData('GetYJBDCArticleList?UserID=' + app.globalData.userInfo.UserID, function (data) {
22
+    main.getData('GetYJBDCArticleList?UserID=' + userID, function (data) {
23 23
       wx.hideLoading();
24 24
       if (data) {
25 25
         for(let i=0;i<data.length;i++){
@@ -63,10 +63,26 @@ Page({
63 63
          wx.showToast({
64 64
            title: '删除完成',
65 65
          });
66
-         that.getData();
66
+         that.getData(app.globalData.userInfo.UserID);
67 67
       });
68 68
     }
69 69
   },
70
+  setGotoID:function(e){
71
+    let that=this;
72
+    if (app.globalData.userInfo.UserID<4){
73
+      wx.showModal({
74
+        title: '输入用户ID,获得生成的文章',
75
+        content: '',
76
+        editable:true,
77
+        complete: (res) => {
78
+          if (res.confirm) {
79
+            if (res.content)
80
+              that.getData(res.content);
81
+          }
82
+        }
83
+      })
84
+    }
85
+  },
70 86
   onShareAppMessage: function () {
71 87
     return {
72 88
       title: app.globalData.ShareTitle,

+ 1 - 1
pages/main/myarticles.wxml

@@ -1,5 +1,5 @@
1 1
 <view class="container FlexColumn" style='min-height:{{Containnerheight}}rpx;'>
2
-  <view style="height: 50rpx;"></view>
2
+  <view style="height: 50rpx;width: 100%;" bind:tap="setGotoID"></view>
3 3
   <view class="panelNull FlexColumn" wx:if="{{List.length==0}}">
4 4
     <view>无内容</view>
5 5
     <view class="textNull1">请先前往首页制作短文</view>