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: { }, onLoad: function (options) { this.setData({ Height: common.getSystemHeight(), }); this.getList(); this.audioCtx = wx.createAudioContext('myAudio'); }, getList: function () { var that = this; server.getData('GetHanziTestList', function (data) { if (data) { var list = data; var item = list[currentIndex]; var pinyinList = pinyin.getPinyinArray(); for (var i = 0; i < list.length; i++) { for (var k = 0; k < list[i].PinyinTest.length; k++) { for (var j = 0; j < pinyinList.length; j++) { if (list[i].PinyinTest[k].options == pinyinList[j][1]) { list[i].PinyinTest[k].name = pinyinList[j][2][0]; break; } } } } that.setData({ List: data, CurrentItem: item, }); } }); }, selectedHanzi: function (e) { var id = e.currentTarget.dataset.id; var list = this.data.CurrentItem.PinyinTest; for (var i = 0; i < list.length; i++) { list[i].IsSelected = false; } list[id].IsSelected = true; if (list[id].IsAnswer) isRight = true; this.data.CurrentItem.PinyinTest = list; this.playAudio(list[id].options, list[id].name); this.setData({ CurrentItem: this.data.CurrentItem, }); }, playAudio: function (pinyin, name) { if (name != undefined){ if (pinyin==undefined) pinyin=""; 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 () { isRight=false; currentIndex++; if (currentIndex >= that.data.List.length) currentIndex = 0; that.setData({ CurrentItem: that.data.List[currentIndex], }); } }) }, onShareAppMessage: function () { return { title: app.globalData.ShareTitle, path: 'pages/index/index?UserID=' + app.globalData.userInfo.UserID, imageUrl: '../../images/07001.png', } }, });