import common from '../../utils/util'; import main from '../../utils/main'; import animation from '../../utils/animation'; import commonBehavior from '../behaviors/commonBehavior'; const Theme=[{ "Name":"DarkColor", "backgroundColor": "#004433", "color":"#C1E1C1", "frontColor": '#ffffff', },{ "Name":"LightColor", "backgroundColor": "#D0ECD3", "color":"#151815", "frontColor": '#000000', } ]; const app = getApp(); Page({ behaviors: [commonBehavior], data: { Words:"", IsShowFirstOpen:true, IsBuilding:false, IsBuildError:false, IsShowLightColor:false, IsShowKeyword:true,//显示关键词 IsShowQuestion:false, IsShowTranslate:false, IsShowSetting:false, IsShowWordTranslate:false, IsBuildQueue:false, TranslateHeight:100,//翻译单词框的高度 CurrentQuestionIndex:0, swiperHeight: "526rpx", lastTapTime: 0, // 记录上一次点击的时间,用于检测双击 CountDown:30,//倒计时秒数 }, onLoad: function (options) { let that = this; let words=app.globalData.SelectedWords.join(","); let wordsStr=app.globalData.SelectedWords.join(" "); const IsShowFirstOpen2=wx.getStorageSync('IsShowFirstOpen2'); const IsShowGuideContainer=wx.getStorageSync('IsShowGuideContainer'); if (!IsShowGuideContainer && !IsShowFirstOpen2){ that.setData({ IsShowFirstOpen2:1, }); } else if (IsShowGuideContainer){ that.setData({ IsShowGuideContainer:true, IsShowFirstOpen2:false, }); main.showGuideContainer(that,"#btnQAndA",-61,-195,"pic_ha07",240,0); } let IsShowKeyword=wx.getStorageSync('IsShowKeyword'); if (IsShowKeyword===""){ IsShowKeyword=true; wx.setStorageSync('IsShowKeyword', true); } let IsShowLightColor=wx.getStorageSync('IsShowLightColor'); if (!IsShowLightColor){ IsShowLightColor=false; } that.setData({ Containnerheight: main.getWindowHeight(), Words:words, WordsStr:wordsStr, Level:options.Level, ArticleStyle:options.ArticleStyle, AIVersion:options.AIVersion, OpenType:options.Type,//打开的类型,可能是新用户引导 IsShowLightColor:IsShowLightColor, IsShowKeyword:IsShowKeyword, IsBuildError:false, IsBuilding:false, IsCollect:false, }); if (options.ID) that.getArticleByID(options.ID); else that.init(options); that.setTheme(); // //测试 // that.setData({ // IsBuilding:true, // }); // that.getChoicenessArticle(); main.checkGenerating(); this.audioCtx = wx.createAudioContext('myAudio'); }, onShow:function(){ main.getPageInfo(); }, getArticleByID:function(id){ let that=this; main.getData('GetYJBDCArticleList?UserID=' + app.globalData.userInfo.UserID+'&ID='+id, function (data) { if (data) { data=data[0]; that.setData({ Words:data.Words, Level:data.Level, ArticleStyle:data.ArticleStyle, CreateTime:data.CreateTime, ID:id, }); let content=data.JSONString; that.updateData(content); that.updateReadCount(that.data.ID); } }); }, init:function(options){ let that=this; let interval=0; that.data.CountDown=options.BuildSecond; that.setData({ CountDown:that.data.CountDown, }); interval = setInterval(function(){ that.setData({ CountDown:--that.data.CountDown, }); if (that.data.CountDown<=0) clearInterval(interval); },1200); that.setData({ IsBuilding:true, IsNew:true, }); app.globalData.Generating=true; let words=app.globalData.SelectedWords.join(","); main.postData('QueuedGenerateArticle?UserID='+app.globalData.userInfo.UserID, { Words:words, Level:that.data.Level, ArticleStyle:that.data.ArticleStyle, AIVersion:that.data.AIVersion }, function (data) { app.globalData.Generating=false; app.globalData.GeneratingStart=false; if (data){ console.log("请求生成数据:"+JSON.stringify(data)); if (data=="-1"){ that.setData({ IsBuilding:false, IsBuildError:true, IsBuildQueue:false, }); } else if (data=="-2"){ that.setData({ IsBuilding:false, IsBuildError:false, IsBuildQueue:true, }); } else{ console.log("生成1"); if (that.data.IsNew){ console.log("生成2"); that.updateData(data.Content); that.updateReadCount(that.data.ID); } that.setData({ IsBuilding:false, ID:data.ID, CreateTime:common.formatDateCHS(common.formatTime(new Date()),true), }); } clearInterval(interval); } }); that.getChoicenessArticle(); }, updateReadCount:function(id){ if (id!="MAX") main.getData('UpdateYJBDCArticleReadCount?UserID=' + app.globalData.userInfo.UserID+'&ID='+id, function (data) {}); }, //得到精选文章 getChoicenessArticle:function(){ let that=this; main.getData('GetYJBDCArticleList?IsFine=1', function (data) { if (data) { that.setData({ ChoicenessList:data, }); } }); }, updateData:function(content){ let that=this; //console.log(content); // 添加检查,确保 content 不是 undefined if (!content) { console.error('Content is undefined in updateData'); return; } if (typeof content === 'string') { content = JSON.parse(content); } if (typeof content === 'string') { content = JSON.parse(content); } let hl = that.data.IsShowKeyword ? "highlight" : "nonelight"; // 初始化ArticleEnglishArr数组 content.ArticleEnglishArr = []; for(let i=0; i