import common from '../../utils/util'; import main from '../../utils/main'; const app = getApp(); Page({ data: { Words:[], IsShowAlert:false, IsShowSetPanel:false, IsShowPanelHelp:false, }, onLoad: function (options) { var that = this; let grade=wx.getStorageSync('Grade'); if (!grade) grade=[{Name:"小学",CSS:"Selected"},{Name:"初中",CSS:""},{Name:"高中",CSS:""},{Name:"大学",CSS:""}]; let ArticleStyle=wx.getStorageSync('ArticleStyle'); if (!ArticleStyle) ArticleStyle=[{Name:"任意",CSS:"Selected"},{Name:"童话",CSS:""},{Name:"科幻",CSS:""},{Name:"奇幻",CSS:""},{Name:"旅行",CSS:""},{Name:"动物",CSS:""},{Name:"家庭亲子",CSS:""},{Name:"校园生活",CSS:""},{Name:"科普",CSS:""},{Name:"节日文化",CSS:""},{Name:"成长",CSS:""},{Name:"人生励志",CSS:""},{Name:"环保",CSS:""}]; const hiddenhelp=wx.getStorageSync('HiddenWordInputHelp'); that.setData({ Containnerheight: main.getWindowHeight(), Grade:grade, ArticleStyle:ArticleStyle, IsShowPanelHelp:!hiddenhelp, KeyboardBtnName:"next", }); }, onShow:function(e){ var that = this; app.globalData.SelectedWords=common.removeDuplicateAndTrimStrings(app.globalData.SelectedWords); that.data.Words=[]; for(let i=0;i<10;i++){ let obj={}; obj.ID=i+1; if (app.globalData.SelectedWords[i]){ obj.Word=app.globalData.SelectedWords[i]; obj.CSS="txtWordFinished"; } else{ obj.Word=""; obj.CSS=""; } obj.IsError=false; that.data.Words.push(obj); } console.log(app.globalData.SelectedWords); that.setData({ Words:that.data.Words, }); that.isShowAlert(); }, bindKeyInput: function (e) { let that=this; let id=e.currentTarget.dataset.id; let word=e.detail.value; for(let i=0;i<10;i++){ if (i+1==id){ that.data.Words[i].Word=word; that.data.Words[i].CSS="txtWordFinished"; if (word && !that.isValidInput(word)){ that.data.Words[i].IsError=true; } else{ that.data.Words[i].IsError=false; if (!word) that.data.Words[i].CSS=""; } break; } } that.setData({ Words:that.data.Words, }); that.isShowAlert(); }, isShowAlert:function(){ const that=this; let b=false; for(let i=0;i<10;i++){ if (that.data.Words[i].IsError){ b=true; break; } } that.setData({ IsShowAlert:b, AlertContent:"不支持特殊符号、数字、句子、非英语单词内容" }); }, setArticleParam:function(e){ const that=this; let count=0; for(let i=0;i<10;i++){ if (that.data.Words[i].CSS=="txtWordFinished"){ count++ } } if (count<5){ that.setData({ IsShowAlert:true, AlertContent:"请输入至少5个英语单词" }); } else{ that.setData({ IsShowAlert:false, IsShowSetPanel:true, }); } }, setMenu:function(){ this.setData({ IsShowSetPanel:!this.data.IsShowSetPanel, }); }, keyboardOK:function(e){ const that=this; let id=e.currentTarget.dataset.id; id++; that.setFocus({currentTarget:{dataset:{id:id}}}); }, setFocus:function(e){ const that=this; let id=e.currentTarget.dataset.id; for(let i=0;i