wordsinput.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429
  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. IsShowSetPanel:false,
  12. IsShowFirstOpen:false,
  13. IsShowExample:false,
  14. IsShowRemind:false,
  15. IsShowGuideContainer:false,
  16. IsShowGuideRemind:false,
  17. },
  18. onLoad: function (options) {
  19. let that = this;
  20. const IsShowFirstOpen=wx.getStorageSync('IsShowFirstOpen');
  21. const IsShowGuideContainer=wx.getStorageSync('IsShowGuideContainer');
  22. if (!IsShowGuideContainer && !IsShowFirstOpen){
  23. that.setData({
  24. IsShowFirstOpen:1,
  25. });
  26. }
  27. else{
  28. const IsShowGuideRemind=wx.getStorageSync('IsShowGuideRemind');
  29. if (!IsShowGuideRemind){
  30. that.setData({
  31. IsShowGuideRemind:1,
  32. });
  33. }
  34. }
  35. that.setData({
  36. Containnerheight: main.getWindowHeight(),
  37. KeyboardBtnName:"next",
  38. });
  39. that.initMenu();
  40. main.checkGenerating();
  41. if (options.goto=="selectword"){
  42. wx.navigateTo({
  43. url: options.goto,
  44. })
  45. }
  46. },
  47. onShow:function(e){
  48. let that = this;
  49. that.initWords();
  50. that.isShowAlert();
  51. that.initGuide(null);
  52. },
  53. onHide:function(e){
  54. this.getInputData();
  55. },
  56. initWords:function(){
  57. let that = this;
  58. app.globalData.SelectedWords=common.removeDuplicateAndTrimStrings(app.globalData.SelectedWords);
  59. that.data.Words=[];
  60. for(let i=0;i<10;i++){
  61. let obj={};
  62. obj.ID=i+1;
  63. if (app.globalData.SelectedWords[i]){
  64. obj.Word=app.globalData.SelectedWords[i];
  65. obj.CSS="txtWordFinished";
  66. if (obj.Word && !that.isValidInput(obj.Word)){
  67. obj.IsError=true;
  68. }
  69. else
  70. obj.IsError=false;
  71. }
  72. else{
  73. obj.Word="";
  74. obj.CSS="";
  75. obj.IsError=false;
  76. }
  77. that.data.Words.push(obj);
  78. }
  79. //console.log(app.globalData.SelectedWords);
  80. that.setData({
  81. Words:that.data.Words,
  82. });
  83. },
  84. initGuide:function(e){
  85. let that=this;
  86. if (e && e.currentTarget.dataset.isstart){
  87. wx.setStorageSync('IsShowGuideContainer', true);
  88. //wx.setStorageSync('IsShowGuideRemind', 2);
  89. wx.navigateBack({
  90. delta: 1,
  91. });
  92. }
  93. else if (wx.getStorageSync("IsShowGuideContainer")){
  94. that.setData({
  95. IsShowGuideContainer:true,
  96. IsShowGuideRemind:false,
  97. });
  98. app.globalData.SelectedWords=["penguin","asia","mammal","panda","","fish","bird","dolphin","",""];
  99. that.initWords();
  100. main.showGuideContainer(that,"#txtWord5",134,-238,"pic_ha02",0,2);
  101. }
  102. },
  103. initMenu:function(){
  104. let that = this;
  105. let level=app.globalData.GenerateConfig.Level;
  106. level[0].CSS="Selected";
  107. for(let i=1;i<level.length;i++){
  108. level[i].CSS="";
  109. }
  110. let articleStyle=app.globalData.GenerateConfig.ArticleStyle;
  111. articleStyle[0].CSS="Selected";
  112. for(let i=1;i<articleStyle.length;i++){
  113. articleStyle[i].CSS="";
  114. }
  115. that.setData({
  116. GradeArr:level,
  117. ArticleStyleArr:articleStyle,
  118. AIVersionArr:app.globalData.GenerateConfig.AIVersion,
  119. });
  120. },
  121. bindKeyInput: function (e) {
  122. let that=this;
  123. let id=e.currentTarget.dataset.id;
  124. let word=e.detail.value;
  125. const inputWord="smart";
  126. if (wx.getStorageSync("IsShowGuideContainer") && word.toString().toLowerCase()==inputWord){
  127. that.data.Words[4].Focus=false;
  128. that.data.Words[4].Word=inputWord;
  129. that.setData({
  130. Words:that.data.Words,
  131. });
  132. main.showGuideContainer(that,"#btnNext",37,-130,"pic_ha03",0,2);
  133. }
  134. else if (that.data.IsShowGuideContainer){
  135. return;
  136. }
  137. for(let i=0;i<10;i++){
  138. if (i+1==id){
  139. that.data.Words[i].Word=word;
  140. that.data.Words[i].CSS="txtWordFinished";
  141. if (word && !that.isValidInput(word)){
  142. that.data.Words[i].IsError=true;
  143. }
  144. else{
  145. that.data.Words[i].IsError=false;
  146. if (!word)
  147. that.data.Words[i].CSS="";
  148. }
  149. break;
  150. }
  151. }
  152. that.setData({
  153. Words:that.data.Words,
  154. });
  155. that.isShowAlert();
  156. },
  157. isShowAlert:function(){
  158. let that=this;
  159. let b=false;
  160. for(let i=0;i<10;i++){
  161. if (that.data.Words[i].IsError){
  162. b=true;
  163. break;
  164. }
  165. }
  166. if (b){
  167. this.selectComponent('#alertTip').showAlert("请勿使用数字、符号、句子等非英语单词内容");
  168. return false;
  169. }
  170. else{
  171. return true;
  172. }
  173. },
  174. setArticleParam:function(e){
  175. let that=this;
  176. let count=0;
  177. app.globalData.SelectedWords=[];
  178. for(let i=0;i<10;i++){
  179. if (that.data.Words[i].CSS=="txtWordFinished"){
  180. app.globalData.SelectedWords.push(that.data.Words[i].Word);
  181. count++
  182. }
  183. }
  184. if (count<5){
  185. this.selectComponent('#alertTip').showAlert("请输入至少5个英语单词或词组");
  186. }
  187. else{
  188. if (that.isShowAlert()){
  189. that.checkMsgSec(function(result){
  190. if (result){
  191. that.setData({
  192. IsShowSetPanel:true,
  193. });
  194. if (wx.getStorageSync("IsShowGuideContainer")){
  195. main.showGuideContainer(that,"#btnLevel1",150,-50,"pic_ha04",135,167);
  196. }
  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. })