wordsinput.js 11 KB

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