wordsinput.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430
  1. import common from '../../utils/util';
  2. import main from '../../utils/main';
  3. import animation from '../../utils/animation';
  4. import commonBehavior from '../behaviors/commonBehavior';
  5. const app = getApp();
  6. let isFocus=true;
  7. Page({
  8. behaviors: [commonBehavior],
  9. data: {
  10. Words:[],
  11. IsShowAlert:false,
  12. IsShowSetPanel:false,
  13. IsShowFirstOpen:false,
  14. IsShowExample:false,
  15. IsShowRemind:false,
  16. IsShowGuideContainer:false,
  17. IsShowGuideRemind:false,
  18. },
  19. onLoad: function (options) {
  20. let that = this;
  21. const IsShowFirstOpen=wx.getStorageSync('IsShowFirstOpen');
  22. const IsShowGuideContainer=wx.getStorageSync('IsShowGuideContainer');
  23. if (!IsShowGuideContainer && !IsShowFirstOpen){
  24. that.setData({
  25. IsShowFirstOpen:1,
  26. });
  27. }
  28. else{
  29. const IsShowGuideRemind=wx.getStorageSync('IsShowGuideRemind');
  30. if (!IsShowGuideRemind){
  31. that.setData({
  32. IsShowGuideRemind:1,
  33. });
  34. }
  35. }
  36. that.setData({
  37. Containnerheight: main.getWindowHeight(),
  38. KeyboardBtnName:"next",
  39. });
  40. that.initMenu();
  41. main.checkGenerating();
  42. if (options.goto=="selectword"){
  43. wx.navigateTo({
  44. url: options.goto,
  45. })
  46. }
  47. },
  48. onShow:function(e){
  49. let that = this;
  50. that.initWords();
  51. that.isShowAlert();
  52. that.initGuide(null);
  53. },
  54. onHide:function(e){
  55. this.getInputData();
  56. },
  57. initWords:function(){
  58. let that = this;
  59. app.globalData.SelectedWords=common.removeDuplicateAndTrimStrings(app.globalData.SelectedWords);
  60. that.data.Words=[];
  61. for(let i=0;i<10;i++){
  62. let obj={};
  63. obj.ID=i+1;
  64. if (app.globalData.SelectedWords[i]){
  65. obj.Word=app.globalData.SelectedWords[i];
  66. obj.CSS="txtWordFinished";
  67. if (obj.Word && !that.isValidInput(obj.Word)){
  68. obj.IsError=true;
  69. }
  70. else
  71. obj.IsError=false;
  72. }
  73. else{
  74. obj.Word="";
  75. obj.CSS="";
  76. obj.IsError=false;
  77. }
  78. that.data.Words.push(obj);
  79. }
  80. //console.log(app.globalData.SelectedWords);
  81. that.setData({
  82. Words:that.data.Words,
  83. });
  84. },
  85. initGuide:function(e){
  86. let that=this;
  87. if (e && e.currentTarget.dataset.isstart){
  88. wx.setStorageSync('IsShowGuideContainer', true);
  89. //wx.setStorageSync('IsShowGuideRemind', 2);
  90. wx.navigateBack({
  91. delta: 1,
  92. });
  93. }
  94. else if (wx.getStorageSync("IsShowGuideContainer")){
  95. that.setData({
  96. IsShowGuideContainer:true,
  97. IsShowGuideRemind:false,
  98. });
  99. app.globalData.SelectedWords=["penguin","asia","mammal","panda","","fish","bird","dolphin","",""];
  100. that.initWords();
  101. main.showGuideContainer(that,"#txtWord5",134,-238,"pic_ha02",0,2);
  102. }
  103. },
  104. initMenu:function(){
  105. let that = this;
  106. let level=app.globalData.GenerateConfig.Level;
  107. level[0].CSS="Selected";
  108. for(let i=1;i<level.length;i++){
  109. level[i].CSS="";
  110. }
  111. let articleStyle=app.globalData.GenerateConfig.ArticleStyle;
  112. articleStyle[0].CSS="Selected";
  113. for(let i=1;i<articleStyle.length;i++){
  114. articleStyle[i].CSS="";
  115. }
  116. that.setData({
  117. GradeArr:level,
  118. ArticleStyleArr:articleStyle,
  119. AIVersionArr:app.globalData.GenerateConfig.AIVersion,
  120. });
  121. },
  122. bindKeyInput: function (e) {
  123. let that=this;
  124. let id=e.currentTarget.dataset.id;
  125. let word=e.detail.value;
  126. const inputWord="smart";
  127. if (wx.getStorageSync("IsShowGuideContainer") && word.toString().toLowerCase()==inputWord){
  128. that.data.Words[4].Focus=false;
  129. that.data.Words[4].Word=inputWord;
  130. that.setData({
  131. Words:that.data.Words,
  132. });
  133. main.showGuideContainer(that,"#btnNext",37,-130,"pic_ha03",0,2);
  134. }
  135. else if (that.data.IsShowGuideContainer){
  136. return;
  137. }
  138. for(let i=0;i<10;i++){
  139. if (i+1==id){
  140. that.data.Words[i].Word=word;
  141. that.data.Words[i].CSS="txtWordFinished";
  142. if (word && !that.isValidInput(word)){
  143. that.data.Words[i].IsError=true;
  144. }
  145. else{
  146. that.data.Words[i].IsError=false;
  147. if (!word)
  148. that.data.Words[i].CSS="";
  149. }
  150. break;
  151. }
  152. }
  153. that.setData({
  154. Words:that.data.Words,
  155. });
  156. that.isShowAlert();
  157. },
  158. isShowAlert:function(){
  159. let that=this;
  160. let b=false;
  161. for(let i=0;i<10;i++){
  162. if (that.data.Words[i].IsError){
  163. b=true;
  164. break;
  165. }
  166. }
  167. that.setData({
  168. IsShowAlert:b,
  169. AlertContent:"请勿使用数字、符号、句子等非英语单词内容"
  170. });
  171. },
  172. setArticleParam:function(e){
  173. let that=this;
  174. let count=0;
  175. app.globalData.SelectedWords=[];
  176. for(let i=0;i<10;i++){
  177. if (that.data.Words[i].CSS=="txtWordFinished"){
  178. app.globalData.SelectedWords.push(that.data.Words[i].Word);
  179. count++
  180. }
  181. }
  182. if (count<5){
  183. that.setData({
  184. IsShowAlert:true,
  185. AlertContent:"请输入至少5个英语单词或词组"
  186. });
  187. }
  188. else{
  189. that.checkMsgSec(function(result){
  190. if (result){
  191. that.setData({
  192. IsShowAlert:false,
  193. IsShowSetPanel:true,
  194. });
  195. if (wx.getStorageSync("IsShowGuideContainer")){
  196. main.showGuideContainer(that,"#btnLevel1",150,-50,"pic_ha04",135,167);
  197. }
  198. }
  199. });
  200. }
  201. },
  202. //敏感词判断
  203. checkMsgSec:function(callback){
  204. let that=this;
  205. var content = app.globalData.SelectedWords.join(",");
  206. main.postData("MsgSecCheck2", {
  207. Content: content,
  208. ProgramID:app.globalData.ProgramID,
  209. UserID:app.globalData.userInfo.UserID,
  210. },
  211. function (data) {
  212. if (data && data.errcode == 0) {
  213. callback(true);
  214. } else {
  215. if (data.errmsg) {
  216. wx.showToast({
  217. title: data.errmsg,
  218. duration: 2000,
  219. image: "../images/sysIcon_b16.png",
  220. });
  221. }
  222. callback(false);
  223. }
  224. });
  225. },
  226. keyboardOK:function(e){
  227. if (wx.getStorageSync('IsShowGuideContainer')){
  228. return ;
  229. }
  230. let that=this;
  231. let id=e.currentTarget.dataset.id;
  232. id++;
  233. that.setFocus({currentTarget:{dataset:{id:id}}});
  234. },
  235. setFocus:function(e){
  236. let that=this;
  237. let id=e.currentTarget.dataset.id;
  238. for(let i=0;i<that.data.Words.length;i++){
  239. that.data.Words[i].Focus=false;
  240. if (that.data.Words[i].ID==id)
  241. that.data.Words[i].Focus=true;
  242. }
  243. that.setData({
  244. Words:that.data.Words,
  245. });
  246. },
  247. closeIsShowFirstOpen:function(){
  248. this.setData({
  249. IsShowFirstOpen:false,
  250. IsShowGuideRemind:true,
  251. });
  252. wx.setStorageSync('IsShowFirstOpen', 2);
  253. },
  254. selectBtn:function(e){
  255. let that=this;
  256. const index=e.currentTarget.dataset.index;
  257. const id=e.currentTarget.dataset.id;
  258. let arr=this.data.GradeArr;
  259. if (id==1)
  260. arr=this.data.ArticleStyleArr;
  261. else if (id==2)
  262. arr=this.data.AIVersionArr;
  263. for(let i=0;i<arr.length;i++){
  264. arr[i].CSS="";
  265. if (i==index)
  266. arr[i].CSS="Selected";
  267. }
  268. if (id==1){
  269. this.setData({
  270. ArticleStyleArr:arr,
  271. });
  272. wx.setStorageSync('ArticleStyle', index);
  273. if (wx.getStorageSync("IsShowGuideContainer")){
  274. main.showGuideContainer(that,"#btnBuild",20,-128,"pic_ha06",240,0);
  275. }
  276. }
  277. else if (id==2){
  278. this.setData({
  279. AIVersionArr:arr,
  280. });
  281. wx.setStorageSync('AIVersion', index);
  282. }
  283. else{
  284. this.setData({
  285. GradeArr:arr,
  286. });
  287. wx.setStorageSync('Grade', index);
  288. if (wx.getStorageSync("IsShowGuideContainer")){
  289. main.showGuideContainer(that,"#btnArticleStyle1",75,-12,"pic_ha05",100,145);
  290. }
  291. }
  292. },
  293. isValidInput:function(input) {
  294. // 正则表达式匹配:大小写字母、空格、单引号、减号
  295. const regex = /^[a-zA-Z\s'-]+$/;
  296. return regex.test(input);
  297. },
  298. goto: function (e) {
  299. let that=this;
  300. var url=e.currentTarget.dataset.url;
  301. that.getInputData();
  302. if (url=="article" && app.globalData.Generating){
  303. animation.toggleRemindWithAnimation(that, {
  304. remindKey:'IsShowRemindWait',
  305. showAnimation: 'remind-slide-up'
  306. });
  307. return ;
  308. }
  309. else if (url=="article"){
  310. let arr=this.data.GradeArr;
  311. for(let i=0;i<arr.length;i++){
  312. if (arr[i].CSS=="Selected"){
  313. url+="?Level="+i;
  314. break;
  315. }
  316. }
  317. arr=this.data.ArticleStyleArr;
  318. for(let i=0;i<arr.length;i++){
  319. if (arr[i].CSS=="Selected"){
  320. url+="&ArticleStyle="+arr[i].Name;
  321. break;
  322. }
  323. }
  324. arr=this.data.AIVersionArr;
  325. for(let i=0;i<arr.length;i++){
  326. if (arr[i].CSS=="Selected"){
  327. url+="&AIVersion="+arr[i].Version+"&BuildSecond="+arr[i].BuildSecond;
  328. break;
  329. }
  330. }
  331. if (wx.getStorageSync("IsShowGuideContainer")){
  332. wx.navigateTo({
  333. url: "article?ID=1&Type=Guide",
  334. });
  335. return;
  336. }
  337. }
  338. if (url=="../main/ocr" || url=="../main/selectword"){
  339. if ( app.globalData.SelectedWords.length>=10){
  340. that.showRemind();
  341. return;
  342. }
  343. if (app.globalData.OCRWords.length>0){
  344. url="../main/selectword";
  345. }
  346. else{
  347. url="../main/ocr"
  348. }
  349. }
  350. wx.navigateTo({
  351. url: url,
  352. });
  353. },
  354. getInputData:function(){
  355. let that=this;
  356. app.globalData.SelectedWords=[];
  357. for(let i=0;i<that.data.Words.length;i++){
  358. if (that.data.Words[i].Word)
  359. app.globalData.SelectedWords.push(that.data.Words[i].Word);
  360. }
  361. app.globalData.SelectedWords=common.removeDuplicateAndTrimStrings(app.globalData.SelectedWords);
  362. },
  363. clearInput:function(e){
  364. let that=this;
  365. const id=e.currentTarget.dataset.id;
  366. if (id=="0"){
  367. app.globalData.SelectedWords=[];
  368. for(let i=0;i<that.data.Words.length;i++){
  369. let obj=that.data.Words[i];
  370. obj.Word="";
  371. obj.CSS="";
  372. obj.IsError=false;
  373. }
  374. that.setData({
  375. Words:that.data.Words,
  376. });
  377. }
  378. else{
  379. for(let i=0;i<10;i++){
  380. if (i+1==id){
  381. that.data.Words[i].Word="";
  382. that.data.Words[i].CSS="";
  383. that.data.Words[i].IsError=false;
  384. app.globalData.SelectedWords.splice(i,1);
  385. break;
  386. }
  387. }
  388. that.setData({
  389. Words:that.data.Words,
  390. });
  391. that.isShowAlert();
  392. }
  393. },
  394. showRemind:function(e){
  395. let type1="IsShowRemind"
  396. if (e.currentTarget.dataset.type)
  397. type1=e.currentTarget.dataset.type;
  398. animation.toggleRemindWithAnimation(this, {
  399. remindKey:type1,
  400. showAnimation: 'remind-slide-down'
  401. });
  402. },
  403. catchTouchMove: main.catchTouchMove,
  404. onShareAppMessage: function () {
  405. return {
  406. title: app.globalData.ShareTitle,
  407. path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
  408. imageUrl: app.globalData.ShareImage,
  409. }
  410. },
  411. })