chengjie 7 年之前
父节点
当前提交
1ecbe3a308
共有 10 个文件被更改,包括 174 次插入115 次删除
  1. 88 52
      pages/main/detail.js
  2. 30 12
      pages/main/detail.wxml
  3. 2 0
      pages/main/detail.wxss
  4. 1 1
      pages/main/index.wxml
  5. 2 2
      pages/main/list.wxml
  6. 12 0
      pages/main/list.wxss
  7. 23 38
      pages/main/search.js
  8. 1 1
      pages/main/search.wxml
  9. 1 1
      project.config.json
  10. 14 8
      utils/util.js

+ 88 - 52
pages/main/detail.js

@@ -80,6 +80,8 @@ Page({
80 80
                     that.init();
81 81
                   else if (that.data.WordType == "review")
82 82
                     that.initReview();
83
+                  else if (that.data.WordType == "search")
84
+                    that.initSearch();
83 85
                 });
84 86
               });
85 87
             });
@@ -115,7 +117,6 @@ Page({
115 117
   init: function () {
116 118
     var arr = JSON.parse(wx.getStorageSync("HanziAll"));
117 119
     var arrReview = wx.getStorageSync("ReviewList");
118
-    var title = "";
119 120
     var result;
120 121
     for (var i = 0; i < arr.length; i++) {
121 122
       if (arr[i].ID == this.data.BookID) {
@@ -129,9 +130,6 @@ Page({
129 130
               item.Words[k].WordUrl = app.globalData.imageUrl + "/images/hanzi" + item.Words[k].Name + ".jpg";
130 131
 
131 132
               item.Words[k].IsReview = false;
132
-
133
-              title = arr[i].Name.replace("识字能力", "");
134
-              title += " " + item.Name;
135 133
               for (var l = 0; l < arrReview.length; l++) {
136 134
                 if (arrReview[l].Word == item.Words[k].Name) {
137 135
                   item.Words[k].IsReview = true;
@@ -163,35 +161,18 @@ Page({
163 161
     });
164 162
 
165 163
     this.restart(this.data.CurrentIndex);
166
-
167 164
     wx.setNavigationBarTitle({
168
-      title: title
165
+      title: "练习"
169 166
     });
170 167
   },
171 168
   initReview: function () {
172
-    var arr = JSON.parse(wx.getStorageSync("HanziAll"));
173 169
     var arrReview = wx.getStorageSync("ReviewList");
174
-    var title = "";
175
-    var result = [];
176 170
     for (var l = 0; l < arrReview.length; l++) {
177
-      for (var i = 0; i < arr.length; i++) {
178
-        for (var j = 0; j < arr[i].Units.length; j++) {
179
-          var item = arr[i].Units[j];
180
-          for (var k = 0; k < item.Words.length; k++) {
181
-            if (arrReview[l].Word == item.Words[k].Name && arrReview[l].WordID == item.Words[k].ID) {
182
-              if (item.Words[k].Pinyin.indexOf(",") > 0)
183
-                item.Words[k].Pinyin = item.Words[k].Pinyin.substr(0, item.Words[k].Pinyin.indexOf(","));
184
-
185
-              item.Words[k].WordUrl = app.globalData.imageUrl + "/images/hanzi" + item.Words[k].Name + ".jpg";
186
-              item.Words[k].IsReview = false;
187
-              item.Words[k].IsReview = true;
188
-              result.push(item.Words[k]);
189
-              break;
190
-            }
191
-          }
192
-        }
193
-      }
171
+      var item = arrReview[l];
172
+      item.WordUrl = app.globalData.imageUrl + "/images/hanzi" + item.Name + ".jpg";
173
+      item.IsReview = true;
194 174
     }
175
+    var result = arrReview;
195 176
 
196 177
     if (this.data.selectedRandom) {
197 178
       result = common.randomArray(result);
@@ -211,8 +192,51 @@ Page({
211 192
     this.restart(this.data.CurrentIndex);
212 193
 
213 194
     wx.setNavigationBarTitle({
214
-      title: "复习"
195
+      title: "练习"
196
+    });
197
+  },
198
+  initSearch: function () {
199
+    var arr = JSON.parse(wx.getStorageSync("HanziAll"));
200
+    var result = wx.getStorageSync("CurrentSearchWord");
201
+    result.WordUrl += "?" + new Date().getTime();
202
+    var arrReview = wx.getStorageSync("ReviewList");
203
+    var title = "汉字";
204
+    for (var i = 0; i < arr.length; i++) {
205
+      for (var j = 0; j < arr[i].Units.length; j++) {
206
+        var item = arr[i].Units[j];
207
+        for (var k = 0; k < item.Words.length; k++) {
208
+
209
+          if (result.ID == item.Words[k].ID) {
210
+            title = arr[i].Name.replace("识字能力", "");
211
+            title += " " + item.Name;
212
+          }
213
+          result.IsReview = false;
214
+
215
+          for (var l = 0; l < arrReview.length; l++) {
216
+            if (arrReview[l].Word == result.Name) {
217
+              result.IsReview = true;
218
+              break;
219
+            }
220
+          }
221
+        }
222
+      }
223
+    }
224
+
225
+    var resultArr = [];
226
+    resultArr.push(result);
227
+    var obj = {
228
+      IsEnd: true,
229
+    }
230
+    resultArr.push(obj);
231
+    this.setData({
232
+      List: resultArr,
233
+    });
234
+
235
+    wx.setNavigationBarTitle({
236
+      title: title
215 237
     });
238
+
239
+    this.restart(this.data.CurrentIndex);
216 240
   },
217 241
   playAudio: function (e) {
218 242
     //console.log("playAudio");
@@ -242,8 +266,7 @@ Page({
242 266
 
243 267
           var Name = this.data.List[this.data.CurrentIndex].Name;
244 268
           var CombineWords = this.data.List[this.data.CurrentIndex].CombineWords;
245
-
246
-
269
+          CombineWords = CombineWords.replace(Name, Name + "(" + pinyinItem + ")");
247 270
           if ((e && e.currentTarget.dataset.pinyin) || !this.data.IsAudioLengthChecked) {
248 271
             url = url.replace("[word]", Name + "(" + pinyinItem + ")");
249 272
             url = url.replace("spd=3", "spd=1");
@@ -251,7 +274,6 @@ Page({
251 274
           else {
252 275
             url = url.replace("[word]", Name + "(" + pinyinItem + ")," + CombineWords + "的" + Name + "(" + pinyinItem + ")");
253 276
           }
254
-
255 277
         }
256 278
       }
257 279
       this.audioCtx.setSrc(url);
@@ -316,17 +338,6 @@ Page({
316 338
     if (index == 0)
317 339
       isShowPrev = false;
318 340
 
319
-
320
-    if (that.data.wordType == "review") {
321
-      for (var i = 0; i < that.data.List.length - 1; i++) {
322
-        if (!that.data.List[i].IsReview)
323
-          that.data.List.splice(i, 1);
324
-      }
325
-      that.setData({
326
-        List: that.data.List,
327
-      });
328
-    }
329
-
330 341
     this.setCurrentWord(index, isShowPrev, true);
331 342
 
332 343
     this.playAudio();
@@ -359,7 +370,9 @@ Page({
359 370
     });
360 371
   },
361 372
   getImageDownload: function () {
373
+    this.data.List[this.data.CurrentIndex].WordUrl += common.random(0, 9);
362 374
     this.setData({
375
+      List: this.data.List,
363 376
       IsImageError: false,
364 377
     });
365 378
   },
@@ -372,18 +385,41 @@ Page({
372 385
       });
373 386
 
374 387
       if (this.data.IsShowWordDetail) {
375
-        var id = e.currentTarget.dataset.id;
376
-        server.getData('GetHanziDetail?ID=' + id, function (data) {
377
-          if (data) {
378
-            //var data = common.Decrypt(data);
379
-            //data=JSON.parse(data);
380
-            data.Antonym = data.Antonym.join(" ");
381
-            data.Synonym = data.Synonym.join(" ");
382
-            that.setData({
383
-              Detail: data,
384
-            });
388
+        if (this.data.WordType == "search") {
389
+          var result = wx.getStorageSync("CurrentSearchWord");
390
+          result = JSON.parse(result.Details);
391
+          for (var i = 0; i < result.PinYin.length; i++) {
392
+            var item = result.PinYin[i].explain;
393
+            item = common.ReplaceAllString(item, "<p>", "");
394
+            item = common.ReplaceAllString(item, "<span>", "");
395
+            item = common.ReplaceAllString(item, "</span>", "");
396
+            item = common.ReplaceAllString(item, "\r", "");
397
+            item = common.ReplaceAllString(item, "\n", "");
398
+
399
+            var arr = item.split("</p>");
400
+            arr.pop();
401
+            result.PinYin[i].explain = arr;
385 402
           }
386
-        });
403
+          result.Antonym = result.Antonym.join(" ");
404
+          result.Synonym = result.Synonym.join(" ");
405
+          that.setData({
406
+            Detail: result,
407
+          });
408
+        }
409
+        else {
410
+          var id = e.currentTarget.dataset.id;
411
+          server.getData('GetHanziDetail?ID=' + id, function (data) {
412
+            if (data) {
413
+              //var data = common.Decrypt(data);
414
+              //data=JSON.parse(data);
415
+              data.Antonym = data.Antonym.join(" ");
416
+              data.Synonym = data.Synonym.join(" ");
417
+              that.setData({
418
+                Detail: data,
419
+              });
420
+            }
421
+          });
422
+        }
387 423
       }
388 424
     }
389 425
   },

+ 30 - 12
pages/main/detail.wxml

@@ -17,12 +17,12 @@
17 17
       </view>
18 18
 
19 19
       <view class="finished FlexColumn" catchtap='updateFinish' wx:if="{{WordType!='review' && IsFinished}}">
20
-        <view class="finished1 FlexColumn" >
20
+        <view class="finished1 FlexColumn">
21 21
           <image src='../../images/05010.png' class="btnImage04006" />
22 22
         </view>
23 23
       </view>
24 24
       <view class="finished2 finished FlexColumn" catchtap='updateFinish' wx:if="{{WordType!='review' && !IsFinished}}">
25
-        <view class="finished3 finished1 FlexColumn" >
25
+        <view class="finished3 finished1 FlexColumn">
26 26
           <image src='../../images/05011.png' class="btnImage04006" />
27 27
         </view>
28 28
       </view>
@@ -32,11 +32,18 @@
32 32
 
33 33
   </view>
34 34
   <view class="detail" wx:if="{{IsShowWordDetail}}">
35
-    <image src='{{Detail.BiShunUrl}}' class="bishun" />
36
-    <view class="line"></view>
37
-    <view class="title2 title FlexRow">
38
-      <view class="title1">汉语拼音</view>
39
-    </view>
35
+    <block wx:if="{{Detail.BiShunUrl}}">
36
+      <image src='{{Detail.BiShunUrl}}' class="bishun" />
37
+      <view class="line"></view>
38
+      <view class="title2 title FlexRow">
39
+        <view class="title1">汉语拼音</view>
40
+      </view>
41
+    </block>
42
+    <block wx:if="{{!Detail.BiShunUrl}}">
43
+      <view class="title FlexRow">
44
+        <view class="title1">汉语拼音</view>
45
+      </view>
46
+    </block>
40 47
     <view class="content FlexRow">
41 48
       <view class="pinyin FlexRow" wx:for="{{Detail.PinYin}}" wx:key="index" catchtap='playAudio' data-click="true" data-pinyin="{{item.pinyin}}">
42 49
         <view>{{item.pinyin}}</view>
@@ -100,24 +107,35 @@
100 107
 
101 108
   <view class="bottom FlexColumn">
102 109
     <view class="bottom1 FlexRow">
103
-      <view class="btn FlexColumn" bindtap='prevHandler'>
104
-        <image src='../../images/05001.png' class="btnImage05001" wx:if="{{IsShowPrev && !IsAutoPage }}" />
110
+      <view class="btn FlexColumn" bindtap='prevHandler' wx:if="{{IsShowPrev && !IsAutoPage }}">
111
+        <image src='../../images/05001.png' class="btnImage05001" />
112
+      </view>
113
+      <view class="btn FlexColumn" bindtap='prevHandler' wx:if="{{!(IsShowPrev && !IsAutoPage) }}">
105 114
       </view>
115
+      
106 116
       <view class="btn FlexColumn" bindtap='reviewHandler'>
107 117
         <image wx:if="{{!List[CurrentIndex].IsReview && IsShowNext && !IsAutoPage}}" src='../../images/05002.png' class="btnImage05002" />
108 118
         <image wx:if="{{List[CurrentIndex].IsReview && IsShowNext && !IsAutoPage}}" src='../../images/05003.png' class="btnImage05002" />
109 119
         <image wx:if="{{!IsShowNext}}" src='../../images/05009.png' class="btnImage022" />
110 120
       </view>
111
-      <view class="btn FlexColumn" bindtap='openSetting'>
121
+
122
+      <view class="btn FlexColumn" bindtap='openSetting' wx:if="{{WordType!='search'}}">
112 123
         <image src='../../images/05004.png' class="btnImage05004" />
113 124
       </view>
125
+      <view class="btn FlexColumn" wx:if="{{WordType=='search'}}">
126
+      </view>
127
+
114 128
       <view class="btn FlexColumn" bindtap='showWordDetailHandler' data-id='{{List[CurrentIndex].ID}}'>
115 129
         <image src='../../images/05005.png' wx:if="{{!IsShowWordDetail && IsShowNext && !IsAutoPage}}" class="btnImage05005" />
116 130
         <image src='../../images/05006.png' wx:if="{{IsShowWordDetail && IsShowNext && !IsAutoPage}}" class="btnImage05006" />
117 131
       </view>
118
-      <view class="btn FlexColumn" bindtap='nextHandler' data-status="click">
119
-        <image src='../../images/05007.png' class="btnImage05001" wx:if="{{IsShowNext && !IsAutoPage}}" />
132
+
133
+      <view class="btn FlexColumn" bindtap='nextHandler' data-status="click" wx:if="{{IsShowNext && !IsAutoPage && WordType!='search'}}">
134
+        <image src='../../images/05007.png' class="btnImage05001" />
135
+      </view>
136
+      <view class="btn FlexColumn" bindtap='nextHandler' data-status="click" wx:if="{{!(IsShowNext && !IsAutoPage && WordType!='search')}}">
120 137
       </view>
138
+      
121 139
     </view>
122 140
   </view>
123 141
 </view>

+ 2 - 0
pages/main/detail.wxss

@@ -90,6 +90,8 @@
90 90
   left:0;
91 91
   z-index: 10;
92 92
   overflow-x: hidden;
93
+  background-color: #F0F0F0;
94
+  
93 95
 }
94 96
 .detail .bishun{
95 97
   width:758rpx;

+ 1 - 1
pages/main/index.wxml

@@ -60,7 +60,7 @@
60 60
     <view class="index8 FlexColumn">
61 61
       <image src='../../images/02013.png' class="img" />
62 62
       <view class="index8_1" bindtap='gotoSearch'>
63
-        搜一搜,输入一个字
63
+        输入一个字
64 64
       </view>
65 65
     </view>
66 66
 

+ 2 - 2
pages/main/list.wxml

@@ -1,6 +1,6 @@
1 1
 <view class="container FlexColumn" style='min-height:{{Height}}rpx;'>
2
-  <view class="line"></view>
3
-  <view class="line1 line"></view>
2
+  <view class="top line"></view>
3
+  <view class="top2 top line1 line"></view>
4 4
   <image src='{{topImage}}' class="topImage" />
5 5
 
6 6
   <view class="line"></view>

+ 12 - 0
pages/main/list.wxss

@@ -15,7 +15,19 @@
15 15
   background-color: #c4a271;
16 16
 }
17 17
 
18
+
19
+.top {
20
+  position: fixed;
21
+  top:0;
22
+  z-index: 10;
23
+}
24
+
25
+.top2 {
26
+  top:10rpx;
27
+}
28
+
18 29
 .topImage {
30
+  margin-top: 20rpx;
19 31
   width: 100%;
20 32
   height: 430rpx;
21 33
 }

+ 23 - 38
pages/main/search.js

@@ -13,13 +13,13 @@ Page({
13 13
       IsSearchResult: false,
14 14
     });
15 15
   },
16
-  getExampleArray:function(){
17
-    var result=[];
16
+  getExampleArray: function () {
17
+    var result = [];
18 18
     var arr = JSON.parse(wx.getStorageSync("HanziAll"));
19 19
     for (var i = 0; i < arr.length; i++) {
20
-      var rnd1 = common.random(0, arr[i].Units.length-1);
20
+      var rnd1 = common.random(0, arr[i].Units.length - 1);
21 21
       var rnd2 = common.random(0, arr[i].Units[rnd1].Words.length - 1);
22
-      
22
+
23 23
       var isfinished = false;
24 24
       var arrReview = wx.getStorageSync("ReviewList");
25 25
       for (var l = 0; l < arrReview.length; l++) {
@@ -31,47 +31,32 @@ Page({
31 31
       arr[i].Units[rnd1].Words[rnd2].BookID = arr[i].ID;
32 32
       arr[i].Units[rnd1].Words[rnd2].UnitID = arr[i].Units[rnd1].ID;
33 33
       arr[i].Units[rnd1].Words[rnd2].WordID = rnd2;
34
-      arr[i].Units[rnd1].Words[rnd2].IsFinished=isfinished;
34
+      arr[i].Units[rnd1].Words[rnd2].IsFinished = isfinished;
35 35
       result.push(arr[i].Units[rnd1].Words[rnd2]);
36 36
     }
37 37
     return result;
38 38
   },
39 39
   researchWord: function (e) {
40
-    var result=false;
40
+    var that = this;
41
+    var result = false;
41 42
     var word = e.detail.value;
42
-    if (word) {
43
-      console.log(word);
44
-      var arr = JSON.parse(wx.getStorageSync("HanziAll"));
45
-      for (var i = 0; i < arr.length; i++) {
46
-        for (var j = 0; j < arr[i].Units.length; j++) {
47
-          var item = arr[i].Units[j];
48
-          for (var n = 0; n < item.Words.length; n++) {
49
-            if (word == item.Words[n].Name) {
50
-              var bookid = arr[i].ID;
51
-              var unitid = item.ID;
52
-              var wordid = n;
53
-
54
-              var isfinished = false;
55
-              var arrReview = wx.getStorageSync("ReviewList");
56
-              for (var l = 0; l < arrReview.length; l++) {
57
-                if (arrReview[l].Word == word) {
58
-                  isfinished=true;
59
-                  break;
60
-                }
61
-              }
62
-              wx.navigateTo({
63
-                url: "./detail?bookid=" + bookid + "&unitid=" + unitid + "&wordid=" + wordid + "&isfinished=" + isfinished,
64
-              });
65
-              result=true;
66
-              break;
67
-            }
68
-          }
43
+    if (common.IsChinese(word)) {
44
+      server.getData('SearchHanzi?Word=' + word, function (data) {
45
+        if (data) {
46
+          wx.setStorageSync("CurrentSearchWord", data);
47
+          wx.navigateTo({
48
+            url: "./detail?Type=search",
49
+          });
69 50
         }
70
-      }
51
+        else{
52
+          that.setData({
53
+            IsSearchResult: true,
54
+          });
55
+        }
56
+      });
71 57
     }
72
-
73
-    if (!result){
74
-      this.setData({
58
+    else {
59
+      that.setData({
75 60
         IsSearchResult: true,
76 61
       });
77 62
     }
@@ -88,7 +73,7 @@ Page({
88 73
       wx.setStorageSync('IsAutoPage', false);
89 74
     }
90 75
     wx.navigateTo({
91
-      url: "./detail?bookid=" + bookid + "&unitid=" + unitid + "&wordid=" + wordid + "&isfinished=" + isfinished,
76
+      url: "./detail?Type=search&bookid=" + bookid + "&unitid=" + unitid + "&wordid=" + wordid + "&isfinished=" + isfinished,
92 77
     });
93 78
   },
94 79
 })

+ 1 - 1
pages/main/search.wxml

@@ -5,7 +5,7 @@
5 5
   <block wx:if="{{IsSearchResult}}">
6 6
     <image class="image04009" src="../../images/04009.png" />
7 7
     <view class="search2">暂未收录</view>
8
-    <text class="search3">换个常用字试试吧\n更多字逐步更新中</text>
8
+    <text class="search3">不支持英文和其它字符</text>
9 9
     <view class="line"></view>
10 10
     <view class="search4">推荐几个常用字</view>
11 11
     <view class="search5 FlexRow">

+ 1 - 1
project.config.json

@@ -1,7 +1,7 @@
1 1
 {
2 2
 	"description": "项目配置文件。",
3 3
 	"setting": {
4
-		"urlCheck": false,
4
+		"urlCheck": true,
5 5
 		"es6": true,
6 6
 		"postcss": true,
7 7
 		"minified": true,

+ 14 - 8
utils/util.js

@@ -346,9 +346,9 @@ function getWordArray(word, key) {
346 346
     }
347 347
     else {
348 348
       var number1 = word.indexOf(key);
349
-      var number2 = number1+key.length;
349
+      var number2 = number1 + key.length;
350 350
       result.push({ css: "", name: word.substr(0, number1) });
351
-      result.push({ css: "highlight", name: key});
351
+      result.push({ css: "highlight", name: key });
352 352
       result.push({ css: "", name: word.substr(number2) });
353 353
     }
354 354
 
@@ -360,18 +360,18 @@ function getWordArray(word, key) {
360 360
 //console.log(sortArrayByStringLength(arrTemp));
361 361
 
362 362
 //排序数组根据字符串长度
363
-function sortArrayByStringLength(arr){
364
-  var result=[],temp=[];
365
-  for(var i=0;i<30;i++){
363
+function sortArrayByStringLength(arr) {
364
+  var result = [], temp = [];
365
+  for (var i = 0; i < 30; i++) {
366 366
     temp.push([]);
367 367
   }
368 368
   for (var i = 0; i < arr.length; i++) {
369
-    var item=arr[i];
369
+    var item = arr[i];
370 370
     temp[item.length].push(item);
371 371
   }
372 372
   for (var i = 0; i < temp.length; i++) {
373 373
     temp[i].sort();
374
-    for (var j = 0; j < temp[i].length;j++){
374
+    for (var j = 0; j < temp[i].length; j++) {
375 375
       result.push(temp[i][j]);
376 376
     }
377 377
   }
@@ -388,6 +388,11 @@ function ReplaceAllString(str, replaceStrFrom, replaceStrTo) {//替换
388 388
     return str;
389 389
 }
390 390
 
391
+function isChinese(temp) {
392
+  var reg = /^[\u4e00-\u9fa5]|[\uFE30-\uFFA0]+$/;   /*定义验证表达式*/
393
+    return reg.test(temp);     /*进行验证*/
394
+}
395
+
391 396
 module.exports = {
392 397
   formatTime: formatTime,
393 398
   formatDateCHS: formatDateCHS,
@@ -409,5 +414,6 @@ module.exports = {
409 414
   getTimeFormat: getTimeFormat,
410 415
   getWordArray: getWordArray,
411 416
   sortArrayByStringLength: sortArrayByStringLength,
412
-  ReplaceAllString: ReplaceAllString
417
+  ReplaceAllString: ReplaceAllString,
418
+  IsChinese: isChinese
413 419
 }