| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678 |
- import common from '../../utils/util';
- import main from '../../utils/main';
- const app = getApp();
- var intervalSound = 0, intervalRefresh = 0;
- var arrImage = [];
- var isCopying = false;
- var isPlaying = false;
- var isCollecting = false;
- var playList = [];
- var innerAudioContext1;
- var timeoutPlayAudio;
- var tempPlayUrl = "";
- var tempPlayUrlLocal = "";
- Page({
- data: {
- IsExistCard: false,
- Containnerheight:1440,
- },
- onReady: function () {
- var that=this;
- innerAudioContext1 = wx.createInnerAudioContext();
- innerAudioContext1.onPlay(() => {
- console.log('开始播放')
- });
- innerAudioContext1.onError((res) => {
- console.log("innerAudioContext1.errMsg:" + res.errMsg);
- console.log("innerAudioContext1.errCode:" + res.errCode);
- that.audioCtx.setSrc(tempPlayUrl);
- that.audioCtx.play();
- });
- },
- onLoad: function (options) {
- var that = this;
- isCopying = false;
- var id = 0;
- if (options.id)
- id = options.id;
- that.setData({
- Containnerheight: main.getWindowHeight(),
- ShowType: options.type,
- MiaoguoCardID: id,
- Color: main.getDetailColor(app.globalData.ColorIndex),
- });
- console.log("MiaoguoCardID:" + id);
- this.audioCtx = wx.createAudioContext('myAudio');
- if (options.type == "show") {
- wx.setNavigationBarTitle({
- title: "查看题卡"
- });
- if (wx.setBackgroundColor) {
- wx.setBackgroundColor({
- backgroundColor: that.data.Color.BackColor,
- backgroundColorTop: "#ffffff",
- backgroundColorBottom: that.data.Color.BackColor,
- })
- }
- }
- else {
- if (options.type == "share") {
- wx.setNavigationBarTitle({
- title: "来自分享"
- });
- }
- else if (options.type == "play") {
- wx.setNavigationBarTitle({
- title: "幻灯片"
- });
- if (that.data.ShowType == "play") {
- playList = [];
- for (var i = 0; i < app.globalData.CardList.length; i++) {
- playList.push(app.globalData.CardList[i].MiaoguoCardID);
- }
- playList = common.randomArray(playList);
- that.data.MiaoguoCardID = playList[0];
- that.setData({
- MiaoguoCardID: that.data.MiaoguoCardID,
- CurrentIndex: 0,
- PlayListCount: playList.length,
- });
- }
- }
- if (wx.setBackgroundColor) {
- wx.setBackgroundColor({
- backgroundColor: that.data.Color.BackColor,
- backgroundColorTop: that.data.Color.BackColor,
- backgroundColorBottom: that.data.Color.BackColor,
- })
- }
- if (wx.setNavigationBarColor) {
- wx.setNavigationBarColor({
- frontColor: "#ffffff",
- backgroundColor: that.data.Color.BackColor,
- })
- }
- }
- if (app.globalData.BaiduToken==="")
- main.getBaiduToken();
- },
- 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 {
- var time = 2000;
- wx.showToast({
- title: '分享人已删除',
- mask: true,
- duration: time,
- complete: function () {
- setTimeout(function () {
- wx.reLaunch({
- url: './default?IsStart=1',
- });
- }, time);
- }
- });
- }
- });
- }
- else
- that.init();
- },
- onUnload: function () {
- isPlaying = false;
- if (innerAudioContext1) {
- innerAudioContext1.stop();
- }
- },
- onPullDownRefresh: function () {
- var that = this;
- if (that.data.ShowType == "play") {
- that.onHideAnswer();
- }
- wx.stopPullDownRefresh();
- },
- init: function () {
- var that = this;
- var list = app.globalData.CardList;
- var card = {};
- var prevId = 0, 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;
- card.IsCollect = list[i].IsCollect;
- card.CardType = list[i].CardType;
- 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 && (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;
- }
- }
- }
- var TagWidth = 0;
- if (card.Tags && card.Tags.length > 0) {
- TagWidth = 92 + (card.Tags.length - 1) * 122;
- for (var j = 0; j < card.Tags.length; j++) {
- if (card.Tags[j].length > 2) {
- TagWidth += 46 * (card.Tags[j].length - 2);
- }
- }
- }
- var IsShowAnswer = [1, 1];
- if (that.data.ShowType == "show"){
- if (that.data.IsShowAnswer)
- IsShowAnswer = that.data.IsShowAnswer;
- }
- else if (that.data.ShowType == "play") {
- IsShowAnswer = [0, 0];
- if (this.data.CurrentIndex <= 0) {
- prevId = 0;
- }
- else
- prevId = 1;
- if (this.data.CurrentIndex >= playList.length - 1) {
- nextId = 0;
- }
- else
- nextId = 1;
- }
- this.setData({
- ID: card.MiaoguoCardID,
- CardType:card.CardType,
- Field: card.Field,
- Tags: card.Tags,
- TagWidth: TagWidth,
- PrevID: prevId,
- NextID: nextId,
- FontSize: card.FontSize,
- LimitTimeStr: limitTimeStr,
- IsTodayPractice: isTodayPractice,
- IsCollect: card.IsCollect,
- IsShowAnswer: IsShowAnswer,
- });
- wx.pageScrollTo({
- scrollTop: 0,
- });
- isPlaying = false;
- },
- // practiceToday: function () {
- // var that = this;
- // wx.showModal({
- // title: '要今天练吗?',
- // content: '这张题卡今天必须练习',
- // success(res) {
- // if (res.confirm) {
- // var arr = [];
- // var obj = {};
- // obj.Card = {};
- // obj.Card.MiaoguoCardID = that.data.ID;
- // obj.BtnNumber = -1;
- // obj.LearningType = 2;
- // arr.push(obj);
- // wx.setStorageSync("ListTaskFinished", arr);
- // main.UpdateMiaoguoCardTodayAll(false, 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 arr = [];
- // var obj = {};
- // obj.Card = {};
- // obj.Card.MiaoguoCardID = that.data.MiaoguoCardID;
- // obj.IntervalTime = "1d";
- // obj.BtnNumber = 1;
- // obj.Duration = 0;
- // obj.LearningType = 3;
- // arr.push(obj);
- // wx.setStorageSync("ListTaskFinished", arr);
- // main.UpdateMiaoguoCardTodayAll(false, function () {
- // 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) {
- // }
- // }
- // })
- // },
- showMenu:function(){
- wx.navigateTo({
- url: './previewMenu?ID='+this.data.MiaoguoCardID+'&CardType=' + this.data.CardType,
- });
- },
- copyCard: function () {
- if (!isCopying) {
- isCopying = true;
- setTimeout(function () {
- isCopying = false;
- }, 15000);
- wx.showLoading({
- title: '处理中',
- });
- setTimeout(function () {
- wx.hideLoading();
- }, 5000);
- 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) {
- clearTimeout(timeoutPlayAudio);
- var that = this;
- var str = e.currentTarget.dataset.content;
- var url;
- if (str == "recorder") {
- url = e.currentTarget.dataset.soundmark;
- }
- else 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);
- }
- if (url.indexOf("http") > 0)
- url = url.substr(url.indexOf("http"));
- if (url.indexOf("'") > 0)
- url = common.ReplaceAllString(url,"'","");
- url = url.replace("http://", "https://");
- url = encodeURI(url);
- if (!isPlaying || tempPlayUrl=="" || url!=tempPlayUrl) {
- isPlaying = true;
- timeoutPlayAudio = setTimeout(function () {
- isPlaying = false;
- }, 60000);
- wx.showLoading({
- title: '音频下载中',
- mask: true,
- });
- var timeout=setTimeout(function () {
- wx.hideLoading();
- }, 30000);
- console.log(url);
- wx.downloadFile({
- url: url,
- success(res) {
- clearTimeout(timeout);
- wx.hideLoading();
- if (res.statusCode === 200) {
- tempPlayUrlLocal = res.tempFilePath;
- that.audioCtx.setSrc(res.tempFilePath);
- that.audioCtx.play();
- tempPlayUrl = url;
- }
- //console.log("res.statusCode:" + res.statusCode);
- },
- fail(err) {
- wx.hideLoading();
- console.log("downling err:"+err);
- clearTimeout(timeout);
- }
- });
- }
- else {
- this.audioCtx.pause();
- if (innerAudioContext1)
- innerAudioContext1.stop();
- isPlaying = false;
- }
- },
- audioBindEnded:function(){
- isPlaying = false;
- },
- audioBindError: function (err) {
- //console.log(err);
- innerAudioContext1.src = tempPlayUrlLocal;
- innerAudioContext1.play();
- },
- getDetailInfo: function () {
- wx.navigateTo({
- url: './cardInfo?id=' + this.data.MiaoguoCardID,
- });
- },
- 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,
- });
- });
- }
- }
- });
- },
- previewNext: function (e) {
- var that = this;
- var id = e.currentTarget.dataset.id;
- that.setData({
- MiaoguoCardID: id,
- });
- that.init();
- },
- close: function () {
- wx.navigateBack({
- delta: 1,
- });
- },
- editField: function (e) {
- if (this.data.ShowType == "show") {
- var that = this;
- wx.navigateTo({
- url: './add?type=edit&id=' + that.data.MiaoguoCardID,
- });
- }
- },
- gotoCollect: function () {
- var that = this;
- if (!isCollecting) {
- isCollecting = true;
- setTimeout(function () {
- isCollecting = false;
- }, 3000);
- if (!that.data.IsCollect) {
- that.data.IsCollect = 1;
- }
- else {
- that.data.IsCollect = 0;
- }
- that.setData({
- IsCollect: that.data.IsCollect
- });
- main.setCollect(that.data.MiaoguoCardID, that.data.IsCollect, function () {
- var list = app.globalData.CardList;
- for (var i = 0; i < list.length; i++) {
- if (that.data.MiaoguoCardID == list[i].MiaoguoCardID) {
- list[i].IsCollect = that.data.IsCollect;
- break;
- }
- }
- });
- }
- },
- onHideAnswer: function () {
- this.setData({
- IsShowAnswer: [0, 0]
- });
- },
- onShowAnswer: function () {
- this.setData({
- IsShowAnswer: [1, 1]
- });
- },
- onPlayAgain: function () {
- playList.push(this.data.MiaoguoCardID);
- this.setData({
- PlayListCount: playList.length,
- NextID: 1,
- });
- wx.showToast({
- title: '稍后回放',
- mask: true,
- duration: 500,
- });
- },
- playNext: function (e) {
- var that = this;
- var div = e.currentTarget.dataset.div;
- if (div == 1) {
- this.data.CurrentIndex++;
- if (this.data.CurrentIndex >= playList.length) {
- this.data.CurrentIndex = playList.length - 1;
- }
- }
- else {
- this.data.CurrentIndex--;
- if (this.data.CurrentIndex < 0)
- this.data.CurrentIndex = 0;
- }
- that.setData({
- CurrentIndex: this.data.CurrentIndex,
- MiaoguoCardID: playList[this.data.CurrentIndex],
- PlayListCount: playList.length,
- });
- that.init();
- },
- showImage: function (e) {
- var name = e.currentTarget.dataset.name;
- if (name && name.length > 5) {
- 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'
- });
- var url = 'ShareMiaoguoCard?UserID=' + app.globalData.userInfo.UserID;
- url += "&MiaoguoCardID=" + that.data.MiaoguoCardID;
- main.getData(url, function (data) { });
- setTimeout(function () {
- that.setData({
- ShowType: 'show'
- });
- }, 1000);
- return {
- title: '我的分享',
- path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID + '&type=share&ColorIndex=' + app.globalData.ColorIndex + '&MiaoguoCardID=' + this.data.MiaoguoCardID,
- }
- },
- })
|