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', } }, });