| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190 |
- import common from '../../utils/util';
- import main from '../../utils/main';
- const app = getApp();
- Page({
- data: {
- },
- onLoad: function (options) {
- var that = this;
- var id = 0;
- if (options.id)
- id = options.id;
- that.setData({
- Containnerheight: main.getWindowHeight(),
- ShowType: options.type,
- MiaoguoCardID: id,
- });
- this.audioCtx = wx.createAudioContext('myAudio');
- },
- onShow: function () {
- this.init();
- },
- init: function () {
- var list = wx.getStorageSync("CardList");
- var card = {};
- var prevId=0;
- var nextId=0;
- for (var i = 0; i < list.length; i++) {
- if (this.data.MiaoguoCardID == list[i].MiaoguoCardID) {
- wx.setStorageSync("TempCardInfo", list[i]);
- 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;
- }
- }
- this.setData({
- ID: card.MiaoguoCardID,
- Field: card.Field,
- Tags: card.Tags,
- PrevID:prevId,
- NextID:nextId,
- FontSize:card.FontSize,
- LimitTimeStr: common.formatDateCHS(card.LimitTime),
- });
- },
- 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),
- });
- var list = wx.getStorageSync("CardList");
- for (var i = 0; i < list.length; i++) {
- if (that.data.ID == list[i].MiaoguoCardID) {
- list[i].LimitTime = time;
- list[i].LimitTimeStr = "今天";
- break;
- }
- }
- wx.setStorageSync("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();
- });
- },
- playSound: function (e) {
- 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 {
- var url = app.globalData.audioUrlBaidu;
- url = url.replace("[token]", app.globalData.BaiduToken);
- url = url.replace("[word]", str);
- }
- this.audioCtx.setSrc(url);
- this.audioCtx.play();
- },
- 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 = wx.getStorageSync("CardList");
- for (var i = 0; i < list.length; i++) {
- if (that.data.MiaoguoCardID == list[i].MiaoguoCardID) {
- list.splice(i, 1);
- break;
- }
- }
- wx.setStorageSync("CardList", list);
- wx.navigateBack({
- delta: 1,
- });
- });
- }
- }
- });
- },
- onPreview: function (e) {
- var id = e.currentTarget.dataset.id;
- wx.redirectTo({
- url: './preview?type=show&id=' + id,
- })
- },
- close: function () {
- wx.navigateBack({
- delta: 1,
- });
- },
- onShareAppMessage: function () {
- return {
- title: app.globalData.ShareTitle,
- path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
- imageUrl: app.globalData.ShareImage,
- }
- },
- })
|