chengjie 4 maanden geleden
bovenliggende
commit
2c05f3ea76

+ 2 - 2
app.js

@@ -1,8 +1,8 @@
1 1
 // app.js
2 2
 App({
3 3
   globalData: {
4
-    Version: "1.0.3",
5
-    //IsProduction: true,
4
+    Version: "1.0.4",
5
+    IsProduction: true,
6 6
     ShareTitle: "阅读理解+答题",
7 7
     SharePath: "pages/index/index",
8 8
     ShareImage: '../images/pic_07.png',

+ 29 - 0
app.wxss

@@ -27,3 +27,32 @@
27 27
   background-color: #004433;
28 28
 } 
29 29
 
30
+
31
+.panelRemindParent{
32
+  background-color: rgba(26,67,51,0.10);
33
+  z-index: 20;
34
+  position: fixed;
35
+  bottom:0;
36
+}
37
+
38
+/* 弹窗上滑动画 */
39
+@keyframes slideUp {
40
+  from { transform: translateY(100%); }
41
+  to { transform: translateY(0); }
42
+}
43
+
44
+/* 弹窗下滑动画 */
45
+@keyframes slideDown {
46
+  from { transform: translateY(0); }
47
+  to { transform: translateY(100%); }
48
+}
49
+
50
+/* 上滑动画类 */
51
+.remind-slide-up {
52
+  animation: slideUp 0.3s ease-out forwards;
53
+}
54
+
55
+/* 下滑动画类 */
56
+.remind-slide-down {
57
+  animation: slideDown 0.3s ease-out forwards;
58
+}

+ 77 - 71
pages/main/article.js

@@ -1,5 +1,7 @@
1 1
 import common from '../../utils/util';
2 2
 import main from '../../utils/main';
3
+import animation from '../../utils/animation';
4
+
3 5
 const Theme=[{
4 6
     "Name":"DarkColor",
5 7
     "backgroundColor": "#004433",
@@ -137,64 +139,86 @@ Page({
137 139
   updateData:function(content){
138 140
     let that=this;
139 141
     //console.log(content);
142
+    
140 143
     if (typeof content === 'string') {
141 144
       content = JSON.parse(content);
142 145
     }
143 146
     if (typeof content === 'string') {
144 147
       content = JSON.parse(content);
145 148
     }
146
-    let hl="nonelight";
147
-    if (that.data.IsShowKeyword)
148
-      hl="highlight";
149
+    let hl = that.data.IsShowKeyword ? "highlight" : "nonelight";
149 150
     
150
-    // 简化的解决方案:按长度排序并使用临时标记
151
-    for(let i=0;i<content.ArticleEnglish.length;i++){
152
-      // 1. 先对单词按长度从长到短排序,确保先处理"Come on"再处理"Come"
153
-      let sortedWords = [...content.FormsOfWords].sort((a, b) => b.length - a.length);
151
+    // 初始化ArticleEnglishArr数组
152
+    content.ArticleEnglishArr = [];
153
+    
154
+    for(let i=0; i<content.ArticleEnglish.length; i++){
155
+      // 确保每个句子末尾有空格,避免和下一句紧挨着
156
+      const sentence = content.ArticleEnglish[i] + " ";
157
+      // 按长度从长到短排序单词,确保先匹配较长的词组
158
+      const sortedWords = [...content.FormsOfWords].sort((a, b) => b.length - a.length);
154 159
       
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];
160
-        let regex = new RegExp(`\\b${word}\\b[.,!?;:]?`, 'gi');
160
+      // 创建一个句子的分段数组
161
+      let segments = [{
162
+        Sentence: sentence,
163
+        CSS: ""
164
+      }];
165
+      
166
+      // 对每个单词进行处理
167
+      for(let j=0; j<sortedWords.length; j++){
168
+        const word = sortedWords[j];
169
+        // 创建一个新的分段数组,用于存储处理后的结果
170
+        let newSegments = [];
161 171
         
162
-        text = text.replace(regex, match => {
163
-          let punctuation = match.match(/[.,!?;:]$/);
164
-          let punc = punctuation ? punctuation[0] : '';
165
-          let wordPart = match.replace(/[.,!?;:]$/, '');
172
+        // 处理每个现有分段
173
+        for(let k=0; k<segments.length; k++){
174
+          const segment = segments[k];
166 175
           
167
-          // 使用唯一的占位符
168
-          let placeholder = `__PLACEHOLDER_${placeholders.length}__`;
169
-          placeholders.push(`<span class='${hl}'>${wordPart}</span>${punc}`);
170
-          return placeholder;
171
-        });
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;
180
-    }
181
-    content.ArticleEnglishArr=[];
182
-    for(let i=0;i<content.ArticleEnglish.length;i++){
183
-      let obj=common.splitByMultipleDelimiters(content.ArticleEnglish[i],["<span class='"+hl+"'>","</span>"]);
184
-      obj=common.removeDuplicateAndTrimStrings(obj);
185
-      //debugger;
186
-      let arr=[];
187
-      for(let j=0;j<obj.length;j++){
188
-        let objChild={};
189
-        objChild.Content=obj[j]+" ";
190
-        objChild.CSS="";
191
-        if (j%2==1){
192
-          objChild.CSS=hl;
193
-          objChild.Content=" "+objChild.Content;
176
+          // 如果当前分段已经被标记为高亮,则不再处理
177
+          if(segment.CSS !== ""){
178
+            newSegments.push(segment);
179
+            continue;
180
+          }
181
+          
182
+          const text = segment.Sentence;
183
+          // 使用正则表达式查找单词边界
184
+          const regex = new RegExp(`\\b${word}\\b`, 'gi');
185
+          let lastIndex = 0;
186
+          let match;
187
+          
188
+          // 查找所有匹配项
189
+          while((match = regex.exec(text)) !== null){
190
+            // 添加匹配前的文本
191
+            if(match.index > lastIndex){
192
+              newSegments.push({
193
+                Sentence: text.substring(lastIndex, match.index),
194
+                CSS: ""
195
+              });
196
+            }
197
+            
198
+            // 添加匹配的单词(高亮)
199
+            newSegments.push({
200
+              Sentence: match[0],
201
+              CSS: hl
202
+            });
203
+            
204
+            lastIndex = match.index + match[0].length;
205
+          }
206
+          
207
+          // 添加最后一个匹配后的文本
208
+          if(lastIndex < text.length){
209
+            newSegments.push({
210
+              Sentence: text.substring(lastIndex),
211
+              CSS: ""
212
+            });
213
+          }
194 214
         }
195
-        arr.push(objChild);
215
+        
216
+        // 更新分段数组
217
+        segments = newSegments;
196 218
       }
197
-      content.ArticleEnglishArr.push(arr);
219
+      
220
+      // 将分段数组添加到ArticleEnglishArr
221
+      content.ArticleEnglishArr.push(segments);
198 222
     }
199 223
 
200 224
     for(let i=0;i<content.Question.length;i++){
@@ -415,9 +439,6 @@ Page({
415 439
       //console.log("选中的句子索引:", selectedIndex);
416 440
       //console.log("选中的句子:", that.data.Content.ArticleEnglish[selectedIndex]);
417 441
       engSentence=that.data.Content.ArticleEnglish[selectedIndex];
418
-      engSentence=common.ReplaceAllString(engSentence,"<span class='highlight'>","");
419
-      engSentence=common.ReplaceAllString(engSentence,"<span class='nonelight'>","");
420
-      engSentence=common.ReplaceAllString(engSentence,"</span>","");
421 442
       chnSentence=that.data.Content.ArticleChinese[selectedIndex];
422 443
     }
423 444
     else if (strType=="question"){
@@ -431,31 +452,16 @@ Page({
431 452
     this.setData({
432 453
       EnglishSentence:engSentence,
433 454
       ChineseSentence:chnSentence,
434
-      remindAnimation: "remind-slide-up", // 添加上滑动画
435
-      IsShowRemind:true,
455
+    });
456
+    // 使用动画工具函数显示弹窗,并指定显示动画
457
+    animation.toggleRemindWithAnimation(this, {
458
+      showAnimation: 'remind-slide-up'
436 459
     });
437 460
   },
438 461
   showRemind:function(e){
439
-    let that = this;
440
-    if (that.data.IsShowRemind) {
441
-      // 如果当前是显示状态,先播放下滑动画,然后再隐藏
442
-      that.setData({
443
-        remindAnimation: "remind-slide-down" // 添加下滑动画
444
-      });
445
-      
446
-      // 等待动画完成后再隐藏弹窗
447
-      setTimeout(function() {
448
-        that.setData({
449
-          IsShowRemind: false
450
-        });
451
-      }, 300); // 动画持续时间为0.3秒
452
-    } else {
453
-      // 如果当前是隐藏状态,直接显示并播放上滑动画
454
-      that.setData({
455
-        IsShowRemind: true,
456
-        remindAnimation: "remind-slide-up"
457
-      });
458
-    }
462
+    animation.toggleRemindWithAnimation(this, {
463
+      showAnimation: 'remind-slide-down'
464
+    });
459 465
   },
460 466
   onShareAppMessage: function () {
461 467
     return {

+ 4 - 4
pages/main/article.wxml

@@ -13,14 +13,14 @@
13 13
     <!-- 完整文章 -->
14 14
     <text class="textArticle" wx:if="{{!IsShowTranslate}}" >
15 15
       <text bindlongpress="onLongPress" data-strtype="article" data-index="{{index}}" wx:for="{{Content.ArticleEnglishArr}}" wx:key="index" >
16
-        <text  class="{{itemChild.CSS}}" wx:for="{{item}}" wx:key="index2" wx:for-item="itemChild" wx:for-index="indexChild">{{itemChild.Content}}</text>
16
+        <text class="{{itemChild.CSS}}" wx:for="{{item}}" wx:key="index2" wx:for-item="itemChild" wx:for-index="indexChild">{{itemChild.Sentence}}</text>
17 17
       </text>
18 18
     </text>
19 19
     <!-- 有翻译文章 -->
20 20
     <view class="textArticle FlexColumn" wx:if="{{IsShowTranslate}}">
21 21
       <view wx:for="{{Content.ArticleEnglishArr}}" wx:key="index" class="textArticle">
22 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
+        <text  class="{{itemChild.CSS}}" wx:for="{{item}}" wx:key="index2" wx:for-item="itemChild" wx:for-index="indexChild">{{itemChild.Sentence}}</text>
24 24
         <view class="textArticleTranslate">{{Content.ArticleChinese[index]}}</view>
25 25
         <view class="panelLine" wx:if="{{index<Content.ArticleEnglish.length-1}}"></view>
26 26
       </view>
@@ -111,8 +111,8 @@
111 111
 </view>
112 112
 
113 113
 <!-- 翻译 -->
114
-<view wx:if="{{IsShowRemind}}" class="panelRemindParent container FlexColumn" style='min-height:{{Containnerheight}}rpx;'>
115
-  <view class="panelRemind FlexColumn {{remindAnimation}}">
114
+<view wx:if="{{IsShowRemind}}" class="panelRemindParent {{remindAnimation}} container FlexColumn" style='min-height:{{Containnerheight}}rpx;'>
115
+  <view class="panelRemind FlexColumn">
116 116
     <image src="../images/sysIcon_b17.png" class="sysIcon_b10"></image>
117 117
       
118 118
     <view class="panelRemind1 FlexRow">

+ 0 - 37
pages/main/article.wxss

@@ -561,43 +561,6 @@
561 561
 }
562 562
 
563 563
 /* 翻译 */
564
-.panelRemindParent{
565
-  background-color: rgba(26,67,51,0.10);
566
-  z-index: 20;
567
-  position: fixed;
568
-  top:0;
569
-}
570
-
571
-/* 翻译弹窗动画 */
572
-@keyframes slideUp {
573
-  from {
574
-    transform: translateY(100%);
575
-    opacity: 0;
576
-  }
577
-  to {
578
-    transform: translateY(0);
579
-    opacity: 1;
580
-  }
581
-}
582
-
583
-@keyframes slideDown {
584
-  from {
585
-    transform: translateY(0);
586
-    opacity: 1;
587
-  }
588
-  to {
589
-    transform: translateY(100%);
590
-    opacity: 0;
591
-  }
592
-}
593
-
594
-.remind-slide-up {
595
-  animation: slideUp 0.3s ease-out forwards;
596
-}
597
-
598
-.remind-slide-down {
599
-  animation: slideDown 0.3s ease-out forwards;
600
-}
601 564
 
602 565
 .panelRemind{
603 566
   width: 690rpx;

+ 9 - 7
pages/main/index.js

@@ -1,11 +1,13 @@
1 1
 import common from '../../utils/util';
2 2
 import main from '../../utils/main';
3
+import animation from '../../utils/animation';
3 4
 
4 5
 const app = getApp();
5 6
 
6 7
 Page({
7 8
   data: {
8 9
     IsShowRemind:false,
10
+    remindAnimation: "",
9 11
   },
10 12
   onLoad: function (options) {
11 13
     let that = this;
@@ -23,15 +25,18 @@ Page({
23 25
     var url=e.currentTarget.dataset.url;
24 26
     if (url=="wordsinput"){
25 27
       if (that.data.TodayCount>that.data.MaxCount){
26
-        this.setData({
27
-          IsShowRemind:true,
28
-        });
28
+        animation.toggleRemindWithAnimation(that);
29 29
         return ;
30 30
       }
31 31
     }
32
+    
32 33
     wx.navigateTo({
33 34
       url: url,
34 35
     });
36
+    that.setData({
37
+      IsShowRemind:false,
38
+    })
39
+    
35 40
   },
36 41
   getData:function(){
37 42
     let that=this;
@@ -40,15 +45,12 @@ Page({
40 45
         that.setData({
41 46
           TodayCount:data.TodayCount,
42 47
           MaxCount:data.MaxCount,
43
-          IsShowRemind:false,
44 48
         });
45 49
       }
46 50
     });
47 51
   },
48 52
   showRemind:function(){
49
-    this.setData({
50
-      IsShowRemind:!this.data.IsShowRemind,
51
-    });
53
+    animation.toggleRemindWithAnimation(this);
52 54
   },
53 55
   onShareAppMessage: function () {
54 56
     return {

+ 1 - 1
pages/main/index.wxml

@@ -31,7 +31,7 @@
31 31
   </view>
32 32
 </view>
33 33
 
34
-<view wx:if="{{IsShowRemind}}" class="panelMenu container FlexColumn" style='min-height:{{Containnerheight}}rpx;'>
34
+<view wx:if="{{IsShowRemind}}" class="panelRemindParent {{remindAnimation}} container FlexColumn" style='min-height:{{Containnerheight}}rpx;'>
35 35
   <view class="panelRemind FlexColumn">
36 36
     <image src="../images/sysIcon_b10.png" class="sysIcon_b10"></image>
37 37
       

+ 3 - 4
pages/main/myarticles.js

@@ -1,5 +1,6 @@
1 1
 import common from '../../utils/util';
2 2
 import main from '../../utils/main';
3
+import animation from '../../utils/animation';
3 4
 
4 5
 const app = getApp();
5 6
 
@@ -47,17 +48,15 @@ Page({
47 48
     })
48 49
   },
49 50
   deleteArticle:function(e){
51
+    animation.toggleRemindWithAnimation(this);
50 52
     this.setData({
51
-      IsShowRemind:true,
52 53
       ID:e.currentTarget.dataset.id
53 54
     });
54 55
   },
55 56
   showRemind:function(e){
56 57
     let that=this;
57 58
     const confirm=e.currentTarget.dataset.confirm;
58
-    this.setData({
59
-      IsShowRemind:!this.data.IsShowRemind,
60
-    });
59
+    animation.toggleRemindWithAnimation(this);
61 60
     if (confirm=="1") {
62 61
       main.getData('DeleteYJBDCArticleList?UserID=' + app.globalData.userInfo.UserID+"&ID="+that.data.ID, function (data) {
63 62
          wx.showToast({

+ 1 - 1
pages/main/myarticles.wxml

@@ -34,7 +34,7 @@
34 34
 </view>
35 35
 
36 36
 
37
-<view wx:if="{{IsShowRemind}}" class="panelMenu container FlexColumn" style='min-height:{{Containnerheight}}rpx;'>
37
+<view wx:if="{{IsShowRemind}}" class="panelRemindParent {{remindAnimation}} container FlexColumn" style='min-height:{{Containnerheight}}rpx;'>
38 38
   <view class="panelRemind FlexColumn">
39 39
     <image src="../images/sysIcon_b13.png" class="sysIcon_b10"></image>
40 40
       

+ 1 - 1
pages/main/ocr.js

@@ -110,7 +110,7 @@ Page({
110 110
       // 3. 调用云函数(添加超时处理)
111 111
       let postData={ ImageBase64: `data:image/jpeg;base64,${fileRes.data}` };
112 112
       
113
-      let url = common.Encrypt("OCRImageData");
113
+      let url = common.Encrypt("OCRImageData?UserID="+app.globalData.userInfo.UserID);
114 114
       url=app.globalData.serverUrl+url;
115 115
       //console.log("url:"+url);
116 116
       const cloudRes = await new Promise((resolve, reject) => {

+ 2 - 3
pages/main/wordsinput.js

@@ -1,5 +1,6 @@
1 1
 import common from '../../utils/util';
2 2
 import main from '../../utils/main';
3
+import animation from '../../utils/animation';
3 4
 
4 5
 const app = getApp();
5 6
 let isFocus=true;
@@ -304,9 +305,7 @@ Page({
304 305
     }
305 306
   },
306 307
   showRemind:function(e){
307
-    this.setData({
308
-      IsShowRemind:!this.data.IsShowRemind,
309
-    });
308
+    animation.toggleRemindWithAnimation(this);
310 309
   },
311 310
   // 阻止示例面板的触摸事件传递到底层
312 311
   catchTouchMove: function(e) {

+ 1 - 1
pages/main/wordsinput.wxml

@@ -97,7 +97,7 @@
97 97
   </view>
98 98
 </view>
99 99
 
100
-<view wx:if="{{IsShowRemind}}" class="panelMenu container FlexColumn" style='min-height:{{Containnerheight}}rpx;'>
100
+<view wx:if="{{IsShowRemind}}" class="panelRemindParent {{remindAnimation}} container FlexColumn" style='min-height:{{Containnerheight}}rpx;'>
101 101
   <view class="panelRemind FlexColumn">
102 102
     <image src="../images/sysIcon_b10.png" class="sysIcon_b10"></image>
103 103
       

+ 33 - 0
utils/animation.js

@@ -0,0 +1,33 @@
1
+function toggleRemindWithAnimation(page, {
2
+  remindKey = 'IsShowRemind',
3
+  animationKey = 'remindAnimation',
4
+  duration = 300,
5
+  showAnimation = 'remind-slide-up',
6
+  hideAnimation = 'remind-slide-down'
7
+} = {}) {
8
+  // 获取当前显示状态
9
+  const isCurrentlyShown = page.data[remindKey];
10
+  if (isCurrentlyShown) {
11
+    // 如果当前是显示状态,先播放隐藏动画,然后再隐藏
12
+    const animationData = {};
13
+    animationData[animationKey] = hideAnimation;
14
+    page.setData(animationData);
15
+    
16
+    // 等待动画完成后再隐藏弹窗
17
+    setTimeout(function() {
18
+      const hideData = {};
19
+      hideData[remindKey] = false;
20
+      page.setData(hideData);
21
+    }, duration);
22
+  } else {
23
+    // 如果当前是隐藏状态,直接显示并播放显示动画
24
+    const showData = {};
25
+    showData[remindKey] = true;
26
+    showData[animationKey] = showAnimation;
27
+    page.setData(showData);
28
+  }
29
+}
30
+
31
+module.exports = {
32
+  toggleRemindWithAnimation:toggleRemindWithAnimation,
33
+}