| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223 |
- import common from '../../utils/util';
- import main from '../../utils/main';
- const app = getApp();
- Page({
- data: {
- Words:[],
- IsShowAlert:false,
- IsShowSetPanel:false,
- IsShowFirstOpen:false,
- IsShowExample: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('HiddenWordInputFirstOpen');
- that.setData({
- Containnerheight: main.getWindowHeight(),
- Grade:grade,
- ArticleStyle:ArticleStyle,
- IsShowFirstOpen:!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,
- });
- },
- showExample:function(){
- this.setData({
- IsShowExample:!this.data.IsShowExample,
- });
- },
- 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<that.data.Words.length;i++){
- that.data.Words[i].Focus=false;
- if (that.data.Words[i].ID==id)
- that.data.Words[i].Focus=true;
- }
- that.setData({
- Words:that.data.Words,
- });
- },
- closeHelp:function(){
- this.setData({
- IsShowFirstOpen:false,
- });
- wx.setStorageSync('HiddenWordInputFirstOpen', true);
- },
- selectBtn:function(e){
- const index=e.currentTarget.dataset.index;
- const id=e.currentTarget.dataset.id;
-
- let arr=this.data.Grade;
- if (id==1)
- arr=this.data.ArticleStyle;
- for(let i=0;i<arr.length;i++){
- arr[i].CSS="";
- if (i==index)
- arr[i].CSS="Selected";
- }
- if (id==1){
- this.setData({
- ArticleStyle:arr,
- });
- wx.setStorageSync('ArticleStyle', arr);
- }
- else{
- this.setData({
- Grade:arr,
- });
- wx.setStorageSync('Grade', arr);
- }
-
- },
- isValidInput:function(input) {
- // 正则表达式匹配:大小写字母、空格、单引号、减号
- const regex = /^[a-zA-Z\s'-]+$/;
- return regex.test(input);
- },
- goto: function (e) {
- let that=this;
- var url=e.currentTarget.dataset.url;
- app.globalData.SelectedWords=[];
- for(let i=0;i<that.data.Words.length;i++){
- if (that.data.Words[i].Word)
- app.globalData.SelectedWords.push(that.data.Words[i].Word);
- }
- app.globalData.SelectedWords=common.removeDuplicateAndTrimStrings(app.globalData.SelectedWords);
-
- if (url=="article"){
- let arr=this.data.Grade;
- for(let i=0;i<arr.length;i++){
- if (arr[i].CSS=="Selected"){
- url+="?Level="+i;
- break;
- }
- }
- arr=this.data.ArticleStyle;
- for(let i=0;i<arr.length;i++){
- if (arr[i].CSS=="Selected"){
- url+="&ArticleStyle="+arr[i].Name;
- break;
- }
- }
- }
- wx.navigateTo({
- url: url,
- });
- },
- onShareAppMessage: function () {
- return {
- title: app.globalData.ShareTitle,
- path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
- imageUrl: app.globalData.ShareImage,
- }
- },
- })
|