chengjie 7 years ago
parent
commit
f5c73e238d
4 changed files with 64 additions and 81 deletions
  1. 2 2
      pages/main/index.wxml
  2. 56 76
      pages/main/test.js
  3. 2 2
      pages/main/test.wxml
  4. 4 1
      pages/main/test.wxss

+ 2 - 2
pages/main/index.wxml

@@ -122,9 +122,9 @@
122
           <view class="ReviewCount">{{ReviewCount}}</view>
122
           <view class="ReviewCount">{{ReviewCount}}</view>
123
         </view>
123
         </view>
124
       </view>
124
       </view>
125
-      <!-- <view class="btn8 btn6 btn" wx:if="{{FinishedCount>0}}" bindtap="gotoTest">
125
+      <view class="btn8 btn6 btn" wx:if="{{FinishedCount>0}}" bindtap="gotoTest">
126
         <view class="btn7 btn1">测试</view>
126
         <view class="btn7 btn1">测试</view>
127
-      </view> -->
127
+      </view>
128
 
128
 
129
       <button class="Circle FlexColumn" open-type="share">
129
       <button class="Circle FlexColumn" open-type="share">
130
         <image src='../../images/02015.png' class="Share" />
130
         <image src='../../images/02015.png' class="Share" />

+ 56 - 76
pages/main/test.js

@@ -3,44 +3,11 @@ import server from '../../utils/main';
3
 import pinyin from '../../utils/pinyin';
3
 import pinyin from '../../utils/pinyin';
4
 
4
 
5
 const app = getApp();
5
 const app = getApp();
6
-var currentIndex=0;
7
-var isRight=false;
6
+var currentIndex = 0;
7
+var isRight = false;
8
 
8
 
9
 Page({
9
 Page({
10
   data: {
10
   data: {
11
-    List:[
12
-      {
13
-        Name:"程",
14
-        Pinyin:"cheng2",
15
-        AnswerList: [
16
-          {
17
-            pinyin: "cen2",
18
-          }, {
19
-            pinyin: "chen2",
20
-          }, {
21
-            pinyin: "ceng2",
22
-          }, {
23
-            pinyin: "cheng2",
24
-          },
25
-        ]
26
-      },
27
-      {
28
-        Name: "杰",
29
-        Pinyin: "jie2",
30
-        AnswerList: [
31
-          {
32
-            pinyin: "ji2",
33
-          }, {
34
-            pinyin: "jie2",
35
-          }, {
36
-            pinyin: "xie2",
37
-          }, {
38
-            pinyin: "qie2",
39
-          },
40
-        ]
41
-      }
42
-    ]
43
-    
44
   },
11
   },
45
   onLoad: function (options) {
12
   onLoad: function (options) {
46
     this.setData({
13
     this.setData({
@@ -51,74 +18,87 @@ Page({
51
 
18
 
52
   },
19
   },
53
   getList: function () {
20
   getList: function () {
54
-    isRight=false;
55
-    var pinyinList = pinyin.getPinyinArray();
56
-    var item = this.data.List[currentIndex];
57
-    var list = item.AnswerList;
58
-    for (var i = 0; i < list.length; i++) {
59
-      for (var j = 0; j < pinyinList.length; j++) {
60
-        if (list[i].pinyin == pinyinList[j][0]) {
61
-          list[i].Pinyin = pinyinList[j][1];
62
-          list[i].Name = pinyinList[j][2][0];
63
-          break;
21
+    var that = this;
22
+    server.getData('GetHanziTestList', function (data) {
23
+      if (data) {
24
+        var list = data;
25
+        var item = list[currentIndex];
26
+        var pinyinList = pinyin.getPinyinArray();
27
+
28
+        for (var i = 0; i < list.length; i++) {
29
+          for (var k = 0; k < list[i].PinyinTest.length; k++) {
30
+            for (var j = 0; j < pinyinList.length; j++) {
31
+              if (list[i].PinyinTest[k].options == pinyinList[j][1]) {
32
+                list[i].PinyinTest[k].name = pinyinList[j][2][0];
33
+                
34
+                break;
35
+              }
36
+            }
37
+          }
64
         }
38
         }
39
+
40
+        that.setData({
41
+          List: data,
42
+          CurrentItem: item,
43
+        });
65
       }
44
       }
66
-      if (item.Pinyin==list[i].pinyin)
67
-        list[i].IsResult=true;
68
-      else
69
-        list[i].IsResult=false;
70
-    }
71
-    this.setData({
72
-      CurrentItem: item,
73
     });
45
     });
74
   },
46
   },
75
   selectedHanzi: function (e) {
47
   selectedHanzi: function (e) {
76
     var id = e.currentTarget.dataset.id;
48
     var id = e.currentTarget.dataset.id;
77
-    var list = this.data.CurrentItem.AnswerList;
49
+    var list = this.data.CurrentItem.PinyinTest;
78
     for (var i = 0; i < list.length; i++) {
50
     for (var i = 0; i < list.length; i++) {
79
       list[i].IsSelected = false;
51
       list[i].IsSelected = false;
80
     }
52
     }
81
     list[id].IsSelected = true;
53
     list[id].IsSelected = true;
82
-    if (list[id].IsResult)
83
-      isRight=true;
84
-    this.data.CurrentItem.AnswerList=list;
85
-    this.playAudio(list[id].Pinyin, list[id].Name);
54
+    if (list[id].IsAnswer)
55
+      isRight = true;
56
+    this.data.CurrentItem.PinyinTest = list;
57
+    this.playAudio(list[id].options, list[id].name);
86
 
58
 
87
     this.setData({
59
     this.setData({
88
       CurrentItem: this.data.CurrentItem,
60
       CurrentItem: this.data.CurrentItem,
89
     });
61
     });
90
   },
62
   },
91
-  playAudio: function (pinyin,name) {
92
-
93
-    var url = app.globalData.audioUrlBaidu;
94
-    url = url.replace("[token]", app.globalData.BaiduToken);
95
-    url = url.replace("[word]", name+"("+pinyin+")");
63
+  playAudio: function (pinyin, name) {
64
+    if (name != undefined){
65
+      if (pinyin==undefined)
66
+        pinyin="";
67
+      
68
+      var url = app.globalData.audioUrlBaidu;
69
+      url = url.replace("[token]", app.globalData.BaiduToken);
70
+      url = url.replace("[word]", name + "(" + pinyin + ")");
96
 
71
 
97
-    url = encodeURI(url);
98
-    this.audioCtx.setSrc(url);
99
-    this.audioCtx.play();
72
+      url = encodeURI(url);
73
+      this.audioCtx.setSrc(url);
74
+      this.audioCtx.play();
75
+    }
100
   },
76
   },
101
-  gotoOK:function(){
102
-    var that=this;
77
+  gotoOK: function () {
78
+    var that = this;
103
 
79
 
104
-    var title="错误";
105
-    var icon="none";
106
-    if (isRight){
107
-      title="正确";
108
-      icon ="success";
80
+    var title = "错误";
81
+    var icon = "none";
82
+    if (isRight) {
83
+      title = "正确";
84
+      icon = "success";
109
     }
85
     }
86
+
110
     wx.showToast({
87
     wx.showToast({
111
       title: title,
88
       title: title,
112
       icon: icon,
89
       icon: icon,
113
-      duration:1000,
114
-      complete:function(){
90
+      duration: 1000,
91
+      complete: function () {
92
+        isRight=false;
115
         currentIndex++;
93
         currentIndex++;
116
         if (currentIndex >= that.data.List.length)
94
         if (currentIndex >= that.data.List.length)
117
           currentIndex = 0;
95
           currentIndex = 0;
118
-        that.getList();
96
+        that.setData({
97
+          CurrentItem: that.data.List[currentIndex],
98
+        });
119
       }
99
       }
120
     })
100
     })
121
-    
101
+
122
   },
102
   },
123
   onShareAppMessage: function () {
103
   onShareAppMessage: function () {
124
     return {
104
     return {

+ 2 - 2
pages/main/test.wxml

@@ -4,12 +4,12 @@
4
   <view class="panelTop FlexRow">
4
   <view class="panelTop FlexRow">
5
     <view class="title">选择正确的汉字发音</view>
5
     <view class="title">选择正确的汉字发音</view>
6
   </view>
6
   </view>
7
-  <view class="panel FlexRow" wx:for="{{CurrentItem.AnswerList}}" wx:key="index" bindtap='selectedHanzi' data-id="{{index}}">
7
+  <view class="panel FlexRow" wx:for="{{CurrentItem.PinyinTest}}" wx:key="index" bindtap='selectedHanzi' data-id="{{index}}">
8
     <view wx:if="{{!item.IsSelected}}" class="universalpic_select_on_black"></view>
8
     <view wx:if="{{!item.IsSelected}}" class="universalpic_select_on_black"></view>
9
     <image src='../../images/SelectYes.png' wx:if="{{item.IsSelected}}" class="universalpic_select_on_black" />
9
     <image src='../../images/SelectYes.png' wx:if="{{item.IsSelected}}" class="universalpic_select_on_black" />
10
     <view class="Number">{{index+1}}.</view>
10
     <view class="Number">{{index+1}}.</view>
11
     
11
     
12
-    <view class="Name">{{item.Pinyin}}</view>
12
+    <view class="Name">{{item.options}}</view>
13
   </view>
13
   </view>
14
   <view class="bottom" bindtap='gotoOK' data-id="0">确认</view>
14
   <view class="bottom" bindtap='gotoOK' data-id="0">确认</view>
15
 
15
 

+ 4 - 1
pages/main/test.wxss

@@ -36,7 +36,10 @@
36
 }
36
 }
37
 .Name{
37
 .Name{
38
   margin-left: 30rpx;
38
   margin-left: 30rpx;
39
-  font-size:28rpx;
39
+  font-size:36rpx;
40
+  font-family: "GB Pinyinok-C";
41
+  font-weight: 300;
42
+  font-style: normal;
40
 }
43
 }
41
 
44
 
42
 .universalpic_select_on_black{
45
 .universalpic_select_on_black{