| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440 |
- import common from '../../utils/util';
- import main from '../../utils/main';
- const app = getApp();
- var iTimeout = 0, intervalSound = 0, intervalRefresh = 0;
- var arrImage = [];
- Page({
- data: {
- IsExistCard: false,
- },
- onLoad: function (options) {
- wx.hideShareMenu();
- var that = this;
- var id = 0;
- if (options.id)
- id = options.id;
- that.setData({
- Containnerheight: main.getWindowHeight(),
- ShowType: options.type,
- MiaoguoCardID: id,
- });
- //console.log("MiaoguoCardID:" + id);
- this.audioCtx = [];
- if (options.type == "share") {
- wx.setNavigationBarTitle({
- title: "查看共享"
- });
- }
- },
- onShow: function () {
- var that = this;
- if (that.data.ShowType)
- if (that.data.ShowType == "share") {
- var url = "GetMiaoguoCardInfo?UserID=" + app.globalData.introducer + "&MiaoguoCardID=" + that.data.MiaoguoCardID;
- main.getData(url, function (data) {
- if (data) {
- app.globalData.CardList = [data];
- that.init();
- }
- });
- }
- else
- that.init();
- },
- onUnload: function () {
- clearTimeout(iTimeout);
- clearInterval(intervalSound);
- },
- init: function () {
- var that = this;
- var list = app.globalData.CardList;
- var card = {};
- var prevId = 0;
- var nextId = 0;
- for (var i = 0; i < list.length; i++) {
- if (this.data.MiaoguoCardID == list[i].MiaoguoCardID) {
- if (i > 0)
- prevId = list[i - 1].MiaoguoCardID;
- else
- prevId = 0;
- if (i < list.length - 1)
- nextId = list[i + 1].MiaoguoCardID;
- else
- nextId = 0;
- card = main.changeStringToView(list[i].Content);
- card.MiaoguoCardID = list[i].MiaoguoCardID;
- card.LimitTime = list[i].LimitTime;
- card.FontSize = list[i].FontSize;
- break;
- }
- }
- if (!card.FontSize)
- card.FontSize = 46;
- arrImage = card.Images;
- //console.log("arrImage:" + arrImage);
- var limitTimeStr = common.formatDateCHS(card.LimitTime);
- var isTodayPractice = true;
- var task = app.globalData.TaskToday;
- if (task && (task.ListNew.length > 0 || task.ListHistory.length>0 || task.ListReview.length>0)) {
- for (var i = 0; i < task.ListNew.length; i++) {
- if (task.ListNew[i].MiaoguoCardID == that.data.MiaoguoCardID) {
- isTodayPractice = false;
- break;
- }
- }
- for (var i = 0; i < task.ListHistory.length; i++) {
- if (task.ListHistory[i].MiaoguoCardID == that.data.MiaoguoCardID) {
- isTodayPractice = false;
- break;
- }
- }
- for (var i = 0; i < task.ListReview.length; i++) {
- if (task.ListReview[i].MiaoguoCardID == that.data.MiaoguoCardID) {
- isTodayPractice = false;
- break;
- }
- }
- }
- this.setData({
- ID: card.MiaoguoCardID,
- Field: card.Field,
- Tags: card.Tags,
- PrevID: prevId,
- NextID: nextId,
- FontSize: card.FontSize,
- LimitTimeStr: limitTimeStr,
- IsTodayPractice: isTodayPractice,
- });
- },
- practiceToday: function () {
- var that = this;
- wx.showModal({
- title: '要今天练吗?',
- content: '这张题卡今天必须练习',
- success(res) {
- if (res.confirm) {
- var obj = {
- ID: that.data.ID,
- BtnNumber: -1,
- LearningType: 2,
- }
- that.saveCard(obj, function () {
- var time = common.formatTime(new Date());
- that.setData({
- LimitTimeStr: common.formatDateCHS(time),
- IsTodayPractice: false,
- });
- var list = app.globalData.CardList;
- for (var i = 0; i < list.length; i++) {
- if (that.data.ID == list[i].MiaoguoCardID) {
- list[i].LimitTime = time;
- list[i].LimitTimeStr = "今天";
- break;
- }
- }
- app.globalData.CardList = list;
- wx.showToast({
- title: '改为今天练',
- icon: 'none',
- });
- });
- }
- else if (res.cancel) {
- }
- }
- })
- },
- shelveTask: function () {
- //搁置题卡,今天不练
- var that = this;
- wx.showModal({
- title: '今天不练吗?',
- content: '这张题卡今天不练习',
- success(res) {
- if (res.confirm) {
- var url = "UpdateMiaoguoCardToday?";
- url += "ID=" + that.data.MiaoguoCardID;
- url += "&UserID=" + app.globalData.userInfo.UserID;
- url += "&IntervalTime=1d";
- url += "&BtnNumber=1";
- url += "&LearningType=3";
- url += "&Duration=0";
- url += "&IsUndo=0";
- main.getData(url, function (data) {
- var time = common.formatTime(common.addDate("d", 1, new Date()));
- that.setData({
- LimitTimeStr: common.formatDateCHS(time),
- IsTodayPractice: true,
- });
- var list = app.globalData.CardList;
- for (var i = 0; i < list.length; i++) {
- if (that.data.ID == list[i].MiaoguoCardID) {
- list[i].LimitTime = time;
- list[i].LimitTimeStr = "明天";
- break;
- }
- }
- app.globalData.CardList = list;
- wx.showToast({
- title: '改为明天练',
- icon: 'none',
- });
- });
- }
- else if (res.cancel) {
- }
- }
- })
- },
- saveCard: function (obj, callback) {
- var url = "UpdateMiaoguoCardToday?";
- url += "ID=" + obj.ID;
- url += "&UserID=" + app.globalData.userInfo.UserID;
- url += "&BtnNumber=" + obj.BtnNumber;
- url += "&LearningType=" + obj.LearningType;
- main.getData(url, function (data) {
- callback();
- });
- },
- copyCard: function () {
- wx.showLoading({
- title: '处理中',
- });
- var that = this;
- var url = "CollectMiaoguoCard?";
- url += "MiaoguoCardID=" + that.data.MiaoguoCardID;
- url += "&UserIDSource=" + app.globalData.introducer;
- url += "&UserIDTarget=" + app.globalData.userInfo.UserID;
- main.getData(url, function (data) {
- wx.hideLoading();
- var title = "题卡已存在!";
- var image = "universalpic_wrong_white_120x120";
- if (data == 1) {
- title = "已保存";
- image = "universalpic_saved_white_120x120";
- }
- wx.showToast({
- title: title,
- mask: true,
- image: "../images/" + image + ".png",
- duration: 2000,
- success: function () {
- that.setData({
- IsExistCard: true,
- });
- }
- });
- });
- },
- playSound: function (e) {
- var that = this;
- var str = e.currentTarget.dataset.content;
- var url;
- if (str.indexOf("英 [") >= 0 || str.indexOf("美 [") >= 0) {
- str = str.replace("英 [", "[");
- str = str.replace("美 [", "[");
- url = e.currentTarget.dataset.soundmark;
- }
- else if (e.currentTarget.dataset.soundmark && e.currentTarget.dataset.soundmark != "undefined") {
- var soundmark = e.currentTarget.dataset.soundmark;
- if (soundmark && soundmark.indexOf("http") < 0) {
- url = app.globalData.audioUrlBaidu;
- url = url.replace("[token]", app.globalData.BaiduToken);
- url = url.replace("[word]", soundmark);
- }
- else {
- url = soundmark;
- }
- }
- else {
- url = app.globalData.audioUrlBaidu;
- url = url.replace("[token]", app.globalData.BaiduToken);
- url = url.replace("[word]", str);
- }
- var arr = url.split(",");
- for (var i = 0; i < arr.length; i++) {
- this.audioCtx.push(wx.createAudioContext('myAudio' + i));
- }
- var index = 0;
- intervalSound = setInterval(function () {
- that.audioCtx[index].setSrc(arr[index]);
- that.audioCtx[index].play();
- index++;
- if (index >= arr.length) {
- clearInterval(intervalSound);
- }
- }, 1000);
- var fieldid = e.currentTarget.dataset.fieldid;
- var content = that.data.Field[fieldid];
- var selectIndex = 0;
- for (var i = 0; i < content.length; i++) {
- if (content[i].Type == 'sound') {
- if (content[i].Content == e.currentTarget.dataset.content) {
- content[i].SoundImageName = "gif";
- selectIndex = i;
- break;
- }
- }
- }
- that.setData({
- Field: that.data.Field,
- });
- iTimeout = setTimeout(function () {
- content[selectIndex].SoundImageName = "png";
- that.data.Field[fieldid] = content;
- that.setData({
- Field: that.data.Field,
- });
- }, 2000);
- },
- onMore: function () {
- var that = this;
- wx.showActionSheet({
- itemList: ["详细信息", "编辑题卡", "删除题卡"],
- success(res) {
- //console.log(res.tapIndex);
- if (res.tapIndex == 0) {
- wx.navigateTo({
- url: './cardInfo?id=' + that.data.MiaoguoCardID,
- });
- }
- else if (res.tapIndex == 1) {
- wx.navigateTo({
- url: './add?type=edit2&id=' + that.data.MiaoguoCardID,
- });
- }
- else if (res.tapIndex == 2) {
- that.deleteCard();
- }
- },
- })
- },
- deleteCard: function () {
- var that = this;
- wx.showModal({
- title: '提醒',
- content: '这张题卡要删除吗?',
- success(res) {
- if (res.confirm) {
- var url = 'DeleteMiaoguoCard?UserID=' + app.globalData.userInfo.UserID;
- url += "&ID=" + that.data.MiaoguoCardID;
- main.getData(url, function (data) {
- var list = app.globalData.CardList;
- for (var i = 0; i < list.length; i++) {
- if (that.data.MiaoguoCardID == list[i].MiaoguoCardID) {
- list.splice(i, 1);
- break;
- }
- }
- app.globalData.CardList = list;
- var taskToday = app.globalData.TaskToday;
- taskToday.CardNumber--;
- app.globalData.TaskToday = taskToday;
- wx.navigateBack({
- delta: 1,
- });
- });
- }
- }
- });
- },
- onPreview: function (e) {
- clearTimeout(iTimeout);
- var id = e.currentTarget.dataset.id;
- wx.redirectTo({
- url: './preview?type=show&id=' + id,
- });
- },
- close: function () {
- wx.navigateBack({
- delta: 1,
- });
- },
- editField: function (e) {
- if (this.data.ShowType == "show") {
- var that = this;
- var fieldid = e.currentTarget.dataset.id;
- wx.navigateTo({
- url: './add?type=edit3&id=' + that.data.MiaoguoCardID + '&fieldid=' + fieldid,
- });
- }
- },
- showImage: function (e) {
- var name = e.currentTarget.dataset.name;
- wx.previewImage({
- current: name,
- urls: arrImage,
- });
- },
- onBindError: function (e) {
- var that = this;
- var serverUrl = e.currentTarget.dataset.serverurl;
- var oldTempUrl = e.currentTarget.dataset.name;
- //console.log("serverUrl1:" + serverUrl);
- wx.downloadFile({
- url: serverUrl, // 仅为示例,并非真实的资源
- success(res) {
- // 只要服务器有响应数据,就会把响应内容写入文件并进入 success 回调,业务需要自行判断是否下载到了想要的内容
- if (res.statusCode === 200) {
- //console.log("serverUrl2:" + serverUrl);
- //console.log(res.tempFilePath);
- main.saveTempImage(serverUrl, res.tempFilePath);
- for (var i = 0; i < arrImage.length; i++) {
- if (arrImage[i] == oldTempUrl) {
- arrImage[i] = res.tempFilePath;
- }
- }
- }
- }
- });
- clearTimeout(intervalRefresh);
- intervalRefresh = setTimeout(function () {
- that.init();
- }, 1000);
- },
- returnDefault: function () {
- wx.reLaunch({
- url: './default?IsStart=1',
- });
- },
- onShareAppMessage: function () {
- var that = this;
- this.setData({
- ShowType: 'sharepreview'
- });
- setTimeout(function () {
- that.setData({
- ShowType: 'show'
- });
- }, 1000);
- return {
- title: '分享题卡',
- path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID + '&Share=1&MiaoguoCardID=' + this.data.MiaoguoCardID,
- imageUrl: app.globalData.ShareImage,
- }
- },
- })
|