chengjie 4 月之前
父节点
当前提交
6c4368240b
共有 4 个文件被更改,包括 48 次插入12 次删除
  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
     let hl="nonelight";
146
     let hl="nonelight";
147
     if (that.data.IsShowKeyword)
147
     if (that.data.IsShowKeyword)
148
       hl="highlight";
148
       hl="highlight";
149
+    
150
+    // 简化的解决方案:按长度排序并使用临时标记
149
     for(let i=0;i<content.ArticleEnglish.length;i++){
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
         let regex = new RegExp(`\\b${word}\\b[.,!?;:]?`, 'gi');
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
           let punctuation = match.match(/[.,!?;:]$/);
163
           let punctuation = match.match(/[.,!?;:]$/);
155
           let punc = punctuation ? punctuation[0] : '';
164
           let punc = punctuation ? punctuation[0] : '';
156
           let wordPart = match.replace(/[.,!?;:]$/, '');
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
     content.ArticleEnglishArr=[];
181
     content.ArticleEnglishArr=[];
162
-    //debugger;
163
     for(let i=0;i<content.ArticleEnglish.length;i++){
182
     for(let i=0;i<content.ArticleEnglish.length;i++){
164
       let obj=common.splitByMultipleDelimiters(content.ArticleEnglish[i],["<span class='"+hl+"'>","</span>"]);
183
       let obj=common.splitByMultipleDelimiters(content.ArticleEnglish[i],["<span class='"+hl+"'>","</span>"]);
165
       obj=common.removeDuplicateAndTrimStrings(obj);
184
       obj=common.removeDuplicateAndTrimStrings(obj);

+ 3 - 2
pages/main/article.wxml

@@ -18,8 +18,9 @@
18
     </text>
18
     </text>
19
     <!-- 有翻译文章 -->
19
     <!-- 有翻译文章 -->
20
     <view class="textArticle FlexColumn" wx:if="{{IsShowTranslate}}">
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
         <view class="textArticleTranslate">{{Content.ArticleChinese[index]}}</view>
24
         <view class="textArticleTranslate">{{Content.ArticleChinese[index]}}</view>
24
         <view class="panelLine" wx:if="{{index<Content.ArticleEnglish.length-1}}"></view>
25
         <view class="panelLine" wx:if="{{index<Content.ArticleEnglish.length-1}}"></view>
25
       </view>
26
       </view>

+ 20 - 4
pages/main/myarticles.js

@@ -12,14 +12,14 @@ Page({
12
     that.setData({
12
     that.setData({
13
       Containnerheight: main.getWindowHeight(),
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
     wx.showLoading({
18
     wx.showLoading({
19
       title: '请稍候',
19
       title: '请稍候',
20
     });
20
     });
21
     let that=this;
21
     let that=this;
22
-    main.getData('GetYJBDCArticleList?UserID=' + app.globalData.userInfo.UserID, function (data) {
22
+    main.getData('GetYJBDCArticleList?UserID=' + userID, function (data) {
23
       wx.hideLoading();
23
       wx.hideLoading();
24
       if (data) {
24
       if (data) {
25
         for(let i=0;i<data.length;i++){
25
         for(let i=0;i<data.length;i++){
@@ -63,10 +63,26 @@ Page({
63
          wx.showToast({
63
          wx.showToast({
64
            title: '删除完成',
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
   onShareAppMessage: function () {
86
   onShareAppMessage: function () {
71
     return {
87
     return {
72
       title: app.globalData.ShareTitle,
88
       title: app.globalData.ShareTitle,

+ 1 - 1
pages/main/myarticles.wxml

@@ -1,5 +1,5 @@
1
 <view class="container FlexColumn" style='min-height:{{Containnerheight}}rpx;'>
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
   <view class="panelNull FlexColumn" wx:if="{{List.length==0}}">
3
   <view class="panelNull FlexColumn" wx:if="{{List.length==0}}">
4
     <view>无内容</view>
4
     <view>无内容</view>
5
     <view class="textNull1">请先前往首页制作短文</view>
5
     <view class="textNull1">请先前往首页制作短文</view>