| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431 |
- import common from '../../utils/util';
- import main from '../../utils/main';
- import animation from '../../utils/animation';
- import commonBehavior from '../behaviors/commonBehavior';
- const app = getApp();
- let isFocus=true;
- Page({
- behaviors: [commonBehavior],
- data: {
- Words:[],
- IsShowSetPanel:false,
- IsShowFirstOpen:false,
- IsShowExample:false,
- IsShowRemind:false,
- IsShowGuideContainer:false,
- IsShowGuideRemind:false,
- },
- onLoad: function (options) {
- let that = this;
- const IsShowFirstOpen=wx.getStorageSync('IsShowFirstOpen');
- const IsShowGuideContainer=wx.getStorageSync('IsShowGuideContainer');
- if (!IsShowGuideContainer && !IsShowFirstOpen){
- that.setData({
- IsShowFirstOpen:1,
- });
- }
- else{
- const IsShowGuideRemind=wx.getStorageSync('IsShowGuideRemind');
-
- if (!IsShowGuideRemind){
- that.setData({
- IsShowGuideRemind:1,
- });
- }
- }
- that.setData({
- Containnerheight: main.getWindowHeight(),
- KeyboardBtnName:"next",
- });
- that.initMenu();
- main.checkGenerating();
- if (options.goto=="selectword"){
- wx.navigateTo({
- url: options.goto,
- })
- }
- },
- onShow:function(e){
- let that = this;
- that.initWords();
- that.isShowAlert();
- that.initGuide(null);
- },
- onHide:function(e){
- this.getInputData();
- },
-
- initWords:function(){
- let 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";
- if (obj.Word && !that.isValidInput(obj.Word)){
- obj.IsError=true;
- }
- else
- obj.IsError=false;
- }
- else{
- obj.Word="";
- obj.CSS="";
- obj.IsError=false;
- }
- that.data.Words.push(obj);
- }
- //console.log(app.globalData.SelectedWords);
- that.setData({
- Words:that.data.Words,
- });
- },
- initGuide:function(e){
- let that=this;
- if (e && e.currentTarget.dataset.isstart){
- wx.setStorageSync('IsShowGuideContainer', true);
- //wx.setStorageSync('IsShowGuideRemind', 2);
- wx.navigateBack({
- delta: 1,
- });
- }
- else if (wx.getStorageSync("IsShowGuideContainer")){
- that.setData({
- IsShowGuideContainer:true,
- IsShowGuideRemind:false,
- });
- app.globalData.SelectedWords=["penguin","asia","mammal","panda","","fish","bird","dolphin","",""];
- that.initWords();
- main.showGuideContainer(that,"#txtWord5",134,-238,"pic_ha02",0,2);
- }
- },
- initMenu:function(){
- let that = this;
- let level=app.globalData.GenerateConfig.Level;
- level[0].CSS="Selected";
- for(let i=1;i<level.length;i++){
- level[i].CSS="";
- }
- let articleStyle=app.globalData.GenerateConfig.ArticleStyle;
- articleStyle[0].CSS="Selected";
- for(let i=1;i<articleStyle.length;i++){
- articleStyle[i].CSS="";
- }
- that.setData({
- GradeArr:level,
- ArticleStyleArr:articleStyle,
- AIVersionArr:app.globalData.GenerateConfig.AIVersion,
- });
- },
- bindKeyInput: function (e) {
- let that=this;
- let id=e.currentTarget.dataset.id;
- let word=e.detail.value;
- const inputWord="smart";
- if (wx.getStorageSync("IsShowGuideContainer") && word.toString().toLowerCase()==inputWord){
- that.data.Words[4].Focus=false;
- that.data.Words[4].Word=inputWord;
- that.setData({
- Words:that.data.Words,
- });
- main.showGuideContainer(that,"#btnNext",37,-130,"pic_ha03",0,2);
- }
- else if (that.data.IsShowGuideContainer){
- return;
- }
-
- 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(){
- let that=this;
- let b=false;
- for(let i=0;i<10;i++){
- if (that.data.Words[i].IsError){
- b=true;
- break;
- }
- }
- if (b){
- this.selectComponent('#alertTip').showAlert("请勿使用数字、符号、句子等非英语单词内容");
- return false;
- }
- else{
- return true;
- }
- },
- setArticleParam:function(e){
- let that=this;
- let count=0;
- app.globalData.SelectedWords=[];
- for(let i=0;i<10;i++){
- if (that.data.Words[i].CSS=="txtWordFinished"){
- app.globalData.SelectedWords.push(that.data.Words[i].Word);
- count++
- }
- }
- if (count<5){
- this.selectComponent('#alertTip').showAlert("请输入至少5个英语单词或词组");
- }
- else{
- if (that.isShowAlert()){
- that.checkMsgSec(function(result){
- if (result){
- that.setData({
- IsShowSetPanel:true,
- });
- if (wx.getStorageSync("IsShowGuideContainer")){
-
- main.showGuideContainer(that,"#btnLevel1",150,-50,"pic_ha04",135,167);
- }
- }
- });
- }
- }
- },
- //敏感词判断
- checkMsgSec:function(callback){
- let that=this;
- var content = app.globalData.SelectedWords.join(",");
- main.postData("MsgSecCheck2", {
- Content: content,
- ProgramID:app.globalData.ProgramID,
- UserID:app.globalData.userInfo.UserID,
- },
- function (data) {
- if (data && data.errcode == 0) {
- callback(true);
- } else {
- if (data.errmsg) {
- wx.showToast({
- title: data.errmsg,
- duration: 2000,
- image: "../images/sysIcon_b16.png",
- });
- }
- callback(false);
- }
- });
- },
- keyboardOK:function(e){
- if (wx.getStorageSync('IsShowGuideContainer')){
- return ;
- }
- let that=this;
- let id=e.currentTarget.dataset.id;
- id++;
- that.setFocus({currentTarget:{dataset:{id:id}}});
- },
- setFocus:function(e){
- let 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,
- });
- },
- closeIsShowFirstOpen:function(){
- this.setData({
- IsShowFirstOpen:false,
- IsShowGuideRemind:true,
- });
- wx.setStorageSync('IsShowFirstOpen', 2);
- },
- selectBtn:function(e){
- let that=this;
- const index=e.currentTarget.dataset.index;
- const id=e.currentTarget.dataset.id;
- let arr=this.data.GradeArr;
- if (id==1)
- arr=this.data.ArticleStyleArr;
- else if (id==2)
- arr=this.data.AIVersionArr;
-
- for(let i=0;i<arr.length;i++){
- arr[i].CSS="";
- if (i==index)
- arr[i].CSS="Selected";
- }
- if (id==1){
- this.setData({
- ArticleStyleArr:arr,
- });
- wx.setStorageSync('ArticleStyle', index);
- if (wx.getStorageSync("IsShowGuideContainer")){
- main.showGuideContainer(that,"#btnBuild",20,-128,"pic_ha06",240,0);
- }
- }
- else if (id==2){
- this.setData({
- AIVersionArr:arr,
- });
- wx.setStorageSync('AIVersion', index);
- }
- else{
- this.setData({
- GradeArr:arr,
- });
- wx.setStorageSync('Grade', index);
- if (wx.getStorageSync("IsShowGuideContainer")){
- main.showGuideContainer(that,"#btnArticleStyle1",75,-12,"pic_ha05",100,145);
- }
- }
-
- },
- 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;
- that.getInputData();
- if (url=="article" && app.globalData.Generating){
- animation.toggleRemindWithAnimation(that, {
- remindKey:'IsShowRemindWait',
- showAnimation: 'remind-slide-up'
- });
- return ;
- }
- else if (url=="article"){
- let arr=this.data.GradeArr;
- for(let i=0;i<arr.length;i++){
- if (arr[i].CSS=="Selected"){
- url+="?Level="+i;
- break;
- }
- }
- arr=this.data.ArticleStyleArr;
- for(let i=0;i<arr.length;i++){
- if (arr[i].CSS=="Selected"){
- url+="&ArticleStyle="+arr[i].Name;
- break;
- }
- }
- arr=this.data.AIVersionArr;
- for(let i=0;i<arr.length;i++){
- if (arr[i].CSS=="Selected"){
- url+="&AIVersion="+arr[i].Version+"&BuildSecond="+arr[i].BuildSecond;
- break;
- }
- }
- if (wx.getStorageSync("IsShowGuideContainer")){
- wx.navigateTo({
- url: "article?ID=1&Type=Guide",
- });
- return;
- }
- }
-
- if (url=="../main/ocr" || url=="../main/selectword"){
- if ( app.globalData.SelectedWords.length>=10){
- that.showRemind();
- return;
- }
- if (app.globalData.OCRWords.length>0){
- url="../main/selectword";
- }
- else{
- url="../main/ocr"
- }
- }
- wx.navigateTo({
- url: url,
- });
- },
- getInputData:function(){
- let that=this;
- 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);
-
- },
- clearInput:function(e){
- let that=this;
- const id=e.currentTarget.dataset.id;
- if (id=="0"){
- app.globalData.SelectedWords=[];
- for(let i=0;i<that.data.Words.length;i++){
- let obj=that.data.Words[i];
- obj.Word="";
- obj.CSS="";
- obj.IsError=false;
- }
- that.setData({
- Words:that.data.Words,
- });
- }
- else{
- for(let i=0;i<10;i++){
- if (i+1==id){
- that.data.Words[i].Word="";
- that.data.Words[i].CSS="";
- that.data.Words[i].IsError=false;
- app.globalData.SelectedWords.splice(i,1);
- break;
- }
- }
- that.setData({
- Words:that.data.Words,
- });
- that.isShowAlert();
- }
- },
- showRemind:function(e){
- let type1="IsShowRemind"
- if (e.currentTarget.dataset.type)
- type1=e.currentTarget.dataset.type;
- animation.toggleRemindWithAnimation(this, {
- remindKey:type1,
- showAnimation: 'remind-slide-down'
- });
- },
- catchTouchMove: main.catchTouchMove,
- onShareAppMessage: function () {
- return {
- title: app.globalData.ShareTitle,
- path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
- imageUrl: app.globalData.ShareImage,
- }
- },
- })
|