| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265 |
- import common from '../../utils/util';
- import main from '../../utils/main';
- const app = getApp();
- var innerAudioContext1;
- Page({
- data: {
- },
- 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,
- });
- innerAudioContext1 = wx.createInnerAudioContext();
- },
- onShow: function () {
- var that = this;
- if (that.data.ShowType == "share") {
- var url = "GetMiaoguoCardInfo?UserID=" + app.globalData.introducer + "&MiaoguoCardID=" + that.data.MiaoguoCardID;
- main.getData(url, function (data) {
- if (data) {
- wx.setStorageSync("CardList", [data]);
- that.init();
- }
- });
- }
- else
- that.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;
- }
- }
- if (!card.FontSize)
- card.FontSize = 46;
- 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();
- });
- },
- 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 = "题卡已存在!";
- if (data == 1) {
- title = "收藏成功!";
- }
- wx.showToast({
- title: title,
- mask: true,
- duration: 3000,
- success: function () {
- that.setData({
- ShowType: 'preview'
- });
- }
- });
- });
- },
- 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 if (e.currentTarget.dataset.soundmark && e.currentTarget.dataset.soundmark == "undefined") {
- url = e.currentTarget.dataset.soundmark;
- }
- else {
- var url = app.globalData.audioUrlBaidu;
- url = url.replace("[token]", app.globalData.BaiduToken);
- url = url.replace("[word]", str);
- }
- innerAudioContext1.src = url;
- innerAudioContext1.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);
- var taskToday = wx.getStorageSync("TaskToday");
- taskToday.CardNumber--;
- wx.setStorageSync("TaskToday", taskToday);
- 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,
- });
- },
- 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,
- });
- }
- },
- onShareAppMessage: function () {
- var that = this;
- this.setData({
- ShowType: 'preview'
- });
- 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,
- }
- },
- })
|