tangshi300/pages/kewen-exercise/kewen-exercise.js

111 lines
3.2 KiB
JavaScript

var t = require("../../@babel/runtime/helpers/defineProperty"), e = require("../../lib/aes.js"), a = getApp();
Page({
data: t({
kewen: {},
xitiList: [],
currentIndex: 0,
xiti: {},
completed: !1,
textbookUnitWordList: [],
currentWord: {},
wordFill: [],
wordSelect: [],
enSelection: [],
selectionValue: "",
zhSelection: [],
currentMissingWordIndex: 0,
missingWord: "",
step: 1,
stepList: [ {
text: "中文翻译"
}, {
text: "英文翻译"
}, {
text: "单词填空"
}, {
text: "单词示例"
} ],
pageIndex: 0,
resultIndex: !1,
reslut: !1,
percentage: 0,
pivotText: "",
score: 100,
id: 0,
type: ""
}, "step", 1),
onLoad: function(t) {
var e = wx.createInnerAudioContext();
this.audio = e, this.setData({
id: t.id,
type: t.type
}), this.getBook();
},
onReady: function() {},
onShow: function() {},
onUnload: function() {},
getBook: function() {
var t = this, i = a.globalData.API_URL + "/h5/api/textbook/poetry/question";
"test" == t.data.type && (i = a.globalData.API_URL + "/h5/api/textbook/poetry/question/grade");
var o = {
id: t.data.id
};
wx.request({
url: i,
data: o,
success: function(i) {
var o = e.decrypt(i.data, a.globalData.key), r = JSON.parse(o);
t.setData({
xitiList: r,
currentIndex: 0,
xiti: r[0]
});
}
});
},
checkWord: function(t) {
var e = this, a = t.currentTarget.dataset.item, i = (e.data.xiti, {});
i["xiti.selectAnswer"] = a.id, e.setData(i), a.answer ? (this.audio.src = "/img/tap_ok.mp3",
this.audio.play(), setTimeout(function() {
var t = e.data.currentIndex + 1;
t === e.data.xitiList.length ? e.setData({
completed: !0
}) : e.setData({
currentIndex: t,
xiti: e.data.xitiList[t]
});
}, 1e3)) : (this.audio.src = "/img/tap_wrong.mp3", this.audio.play());
},
gotoPage: function(t) {
var e = this.data.textbookUnitWordList;
this.setData({
currentWord: e[t]
});
},
returnHome: function() {
wx.navigateBack({
delta: 1
});
},
round: function(t, e) {
return Math.round((t * Math.pow(10, e)).toFixed(1)) / Math.pow(10, e);
},
floor: function(t, e) {
return parseInt(t * Math.pow(10, e)) / Math.pow(10, e);
},
shuffle: function(t) {
for (var e = t.length, a = 0; a < e; a++) {
var i = e - 1, o = Math.random() * (i + 1) >> 0, r = t[i];
t[i] = t[o], t[o] = r;
}
return t;
},
randomCoding: function() {
for (var t = [], e = 0; e < 5; e++) {
var a = Math.ceil(25 * Math.random());
t.push(String.fromCharCode(97 + a));
}
return t;
}
});