| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- import common from '../../utils/util';
- import server from '../../utils/main';
- import pinyin from '../../utils/pinyin';
- const app = getApp();
- var currentIndex=0;
- var isRight=false;
- Page({
- data: {
- List:[
- {
- Name:"程",
- Pinyin:"cheng2",
- AnswerList: [
- {
- pinyin: "cen2",
- }, {
- pinyin: "chen2",
- }, {
- pinyin: "ceng2",
- }, {
- pinyin: "cheng2",
- },
- ]
- },
- {
- Name: "杰",
- Pinyin: "jie2",
- AnswerList: [
- {
- pinyin: "ji2",
- }, {
- pinyin: "jie2",
- }, {
- pinyin: "xie2",
- }, {
- pinyin: "qie2",
- },
- ]
- }
- ]
-
- },
- onLoad: function (options) {
- this.setData({
- Height: common.getSystemHeight(),
- });
- this.getList();
- this.audioCtx = wx.createAudioContext('myAudio');
- },
- getList: function () {
- isRight=false;
- var pinyinList = pinyin.getPinyinArray();
- var item = this.data.List[currentIndex];
- var list = item.AnswerList;
- for (var i = 0; i < list.length; i++) {
- for (var j = 0; j < pinyinList.length; j++) {
- if (list[i].pinyin == pinyinList[j][0]) {
- list[i].Pinyin = pinyinList[j][1];
- list[i].Name = pinyinList[j][2][0];
- break;
- }
- }
- if (item.Pinyin==list[i].pinyin)
- list[i].IsResult=true;
- else
- list[i].IsResult=false;
- }
- this.setData({
- CurrentItem: item,
- });
- },
- selectedHanzi: function (e) {
- var id = e.currentTarget.dataset.id;
- var list = this.data.CurrentItem.AnswerList;
- for (var i = 0; i < list.length; i++) {
- list[i].IsSelected = false;
- }
- list[id].IsSelected = true;
- if (list[id].IsResult)
- isRight=true;
- this.data.CurrentItem.AnswerList=list;
- this.playAudio(list[id].Pinyin, list[id].Name);
- this.setData({
- CurrentItem: this.data.CurrentItem,
- });
- },
- playAudio: function (pinyin,name) {
- var url = app.globalData.audioUrlBaidu;
- url = url.replace("[token]", app.globalData.BaiduToken);
- url = url.replace("[word]", name+"("+pinyin+")");
- url = encodeURI(url);
- this.audioCtx.setSrc(url);
- this.audioCtx.play();
- },
- gotoOK:function(){
- var that=this;
- var title="错误";
- var icon="none";
- if (isRight){
- title="正确";
- icon ="success";
- }
- wx.showToast({
- title: title,
- icon: icon,
- duration:1000,
- complete:function(){
- currentIndex++;
- if (currentIndex >= that.data.List.length)
- currentIndex = 0;
- that.getList();
- }
- })
-
- },
- onShareAppMessage: function () {
- return {
- title: app.globalData.ShareTitle,
- path: 'pages/index/index?UserID=' + app.globalData.userInfo.UserID,
- imageUrl: '../../images/07001.png',
- }
- },
- });
|