wordsinput.js 11 KB

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