| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371 |
- import common from '../../utils/util';
- import main from '../../utils/main';
- import animation from '../../utils/animation';
- const app = getApp();
- let isFocus=true;
- Page({
- data: {
- Words:[],
- IsShowAlert:false,
- IsShowSetPanel:false,
- IsShowFirstOpen:false,
- IsShowExample:false,
- IsShowRemind:false,
- },
- onLoad: function (options) {
- let that = this;
-
- const hiddenhelp=wx.getStorageSync('HiddenWordInputFirstOpen');
- that.setData({
- Containnerheight: main.getWindowHeight(),
- IsShowFirstOpen:!hiddenhelp,
- KeyboardBtnName:"next",
- });
- that.initMenu();
- main.checkGenerating();
- },
- onShow:function(e){
- 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,
- });
- that.isShowAlert();
- },
- onHide:function(e){
- this.getInputData();
- },
- initMenu:function(){
- let that = this;
- let GradeArr=[{Name:"小学",CSS:"Selected"},{Name:"初中",CSS:""},{Name:"高中",CSS:""},{Name:"大学",CSS:""}];
- let grade=wx.getStorageSync('Grade');
- if (grade && grade>=0 && grade<=3){
- for(let i=0;i<GradeArr.length;i++){
- GradeArr[i].CSS="";
- if (grade==i)
- GradeArr[i].CSS="Selected";
- }
- }
- let ArticleStyleArr=[{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:""}];
- let ArticleStyle=wx.getStorageSync('ArticleStyle');
- if (ArticleStyle && ArticleStyle>=0 && ArticleStyle<=12){
- for(let i=0;i<ArticleStyleArr.length;i++){
- ArticleStyleArr[i].CSS="";
- if (ArticleStyle==i)
- ArticleStyleArr[i].CSS="Selected";
- }
- }
- let AIVersionArr=[{Version:"1.0",Content:"词句丰富,结构简明\n平均30秒生成",CSS:"Selected"},{Version:"1.5",Content:"深度表达,更多要素\n平均60秒生成",CSS:""}];
- let AIVersion=wx.getStorageSync('AIVersion');
- if (AIVersion && AIVersion>=0 && AIVersion<=2){
- for(let i=0;i<AIVersionArr.length;i++){
- AIVersionArr[i].CSS="";
- if (AIVersion==i)
- AIVersionArr[i].CSS="Selected";
- }
- }
-
- that.setData({
- GradeArr:GradeArr,
- ArticleStyleArr:ArticleStyleArr,
- AIVersionArr:AIVersionArr,
- });
- },
- 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(){
- let 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){
- 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){
- that.setData({
- IsShowAlert:true,
- AlertContent:"请输入至少5个英语单词或词组"
- });
- }
- else{
- that.checkMsgSec(function(result){
- if (result){
- that.setData({
- IsShowAlert:false,
- IsShowSetPanel:true,
- });
- }
- });
- }
- },
- //敏感词判断
- 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);
- }
- });
- },
- setMenu:function(){
- this.setData({
- IsShowSetPanel:!this.data.IsShowSetPanel,
- });
- },
- showExample:function(){
- this.setData({
- IsShowExample:!this.data.IsShowExample,
- });
- },
- keyboardOK:function(e){
- 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,
- });
- },
- 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.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);
- }
- else if (id==2){
- this.setData({
- AIVersionArr:arr,
- });
- wx.setStorageSync('AIVersion', index);
- }
- else{
- this.setData({
- GradeArr:arr,
- });
- wx.setStorageSync('Grade', index);
- }
-
- },
- 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"){
- 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;
- break;
- }
- }
- }
-
- 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){
- animation.toggleRemindWithAnimation(this);
- },
- // 阻止示例面板的触摸事件传递到底层
- catchTouchMove: function(e) {
- // 这个函数不需要做任何事情,只需要捕获事件防止冒泡
- return false;
- },
- onShareAppMessage: function () {
- return {
- title: app.globalData.ShareTitle,
- path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
- imageUrl: app.globalData.ShareImage,
- }
- },
- })
|