main.js 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153
  1. import common from '../utils/util';
  2. import constant from '../utils/constant';
  3. var app = getApp();
  4. var dataSendTimeout = 0;
  5. function getData(url, callback) {
  6. if (!app.globalData.IsProduction)
  7. console.log("加密前的结果为===", url);
  8. var url = common.Encrypt(url);
  9. //console.log("加密后的结果为===",url);
  10. wx.request({
  11. url: app.globalData.serverUrl + url,
  12. success: function (res) {
  13. if (res.statusCode)
  14. common.checkError(res.statusCode);
  15. var data = res.data.result;
  16. callback(data);
  17. },
  18. fail: function () {
  19. wx.showToast({
  20. title: '服务器忙,请稍候再试!',
  21. duration: 3000
  22. });
  23. },
  24. });
  25. }
  26. function postData(url, postData, callback) {
  27. var url = common.Encrypt(url);
  28. //console.log("加密后的结果为===",url);
  29. wx.request({
  30. url: app.globalData.serverUrl + url,
  31. method: "POST",
  32. data: postData,
  33. success: function (res) {
  34. if (res.statusCode)
  35. common.checkError(res.statusCode);
  36. var data = res.data.result;
  37. callback(data);
  38. },
  39. fail: function () {
  40. wx.showToast({
  41. title: '服务器忙,请稍候再试!',
  42. duration: 3000
  43. });
  44. },
  45. });
  46. }
  47. function getLocalHost(callback) {
  48. if (!app.globalData.IsProduction) {
  49. var url = common.Encrypt("Ping");
  50. wx.request({
  51. url: app.globalData.serverUrlLocalhost + url,
  52. success: function (res) {
  53. app.globalData.serverUrl = app.globalData.serverUrlLocalhost;
  54. callback();
  55. },
  56. fail: function () {
  57. app.globalData.serverUrl = app.globalData.serverUrlServer;
  58. callback();
  59. },
  60. });
  61. } else {
  62. app.globalData.serverUrl = app.globalData.serverUrlServer;
  63. callback();
  64. }
  65. }
  66. function getBaiduToken() {
  67. getData('GetBaiduToken', function (data) {
  68. if (data) {
  69. app.globalData.BaiduToken = data;
  70. //console.log(app.globalData.BaiduToken);
  71. }
  72. });
  73. }
  74. function payMoney(payType, remark, money, detail, callback) {
  75. console.log(money);
  76. if (app.globalData.userInfo.UserID < 8)
  77. money = 0.01;
  78. //登录认证
  79. wx.login({
  80. success: function (res) {
  81. if (res.code) {
  82. console.log('获取用户登录态成功!' + res.code);
  83. //预支付
  84. getData('ProductPayLogin500?code=' + res.code + '&payType=7&money=' + money + '&detail=' + detail + '&productID=' + app.globalData.ProgramID + '&Remark=' + remark, function (data) {
  85. if (data && data.timeStamp) {
  86. //微信支付
  87. wx.requestPayment({
  88. 'timeStamp': data.timeStamp.toString(),
  89. 'nonceStr': data.nonceStr,
  90. 'package': data.package,
  91. 'signType': 'MD5',
  92. 'paySign': data.paySign,
  93. 'success': function (res3) {
  94. console.log("success:" + res3);
  95. callback(data);
  96. },
  97. 'fail': function (err) {
  98. if (err && err.errMsg && err.errMsg.indexOf("fail cancel")) {
  99. } else {
  100. wx.showToast({
  101. title: '服务器忙,请稍候再试!',
  102. duration: 3000
  103. });
  104. }
  105. }
  106. });
  107. }
  108. });
  109. } else {
  110. console.log('获取用户登录态失败!' + res.errMsg);
  111. wx.showToast({
  112. title: '服务器忙,请稍候再试!',
  113. duration: 3000
  114. });
  115. }
  116. }
  117. });
  118. }
  119. function getTimeFormat(duration) {
  120. //console.log("duration:" + duration);
  121. var arr = ['', '', '']
  122. if (duration.indexOf("'") > 0)
  123. arr[0] = duration.substring(0, duration.indexOf("'"));
  124. if (duration.indexOf(".") > 0) {
  125. arr[1] = duration.substring(duration.indexOf("'") + 1, duration.indexOf(".") + 1);
  126. arr[2] = duration.substring(duration.indexOf(".") + 1, duration.indexOf('"'));
  127. } else {
  128. arr[1] = duration.substring(duration.indexOf("'") + 1, duration.indexOf('"'));
  129. }
  130. return arr;
  131. }
  132. function getWindowHeight() {
  133. var height = app.globalData.systemInfo.windowHeight;
  134. //console.log("app.globalData.systemInfo.windowHeight:" + app.globalData.systemInfo.windowHeight * 2);
  135. if (app.globalData.systemInfo.model) {
  136. if (height == 504 && (
  137. app.globalData.systemInfo.model.indexOf("iPhone 6<") >= 0 ||
  138. app.globalData.systemInfo.model.indexOf("iPhone 7<") >= 0 ||
  139. app.globalData.systemInfo.model.indexOf("iPhone 6s<") >= 0 ||
  140. app.globalData.systemInfo.model.indexOf("iPhone 5") >= 0 ||
  141. app.globalData.systemInfo.model.indexOf("iPhone SE") >= 0
  142. )) {
  143. height = 596;
  144. } else if (app.globalData.systemInfo.model.indexOf("iPad") >= 0) {
  145. height = 470;
  146. }
  147. }
  148. height = height * 2;
  149. if (app.globalData.systemInfo.system && app.globalData.systemInfo.system.indexOf("Android") >= 0) {
  150. height = height + 168;
  151. } else {
  152. height = height + 50;
  153. }
  154. //console.log("height:" + height);
  155. //var height = app.globalData.systemInfo.screenHeight * 2;
  156. return height;
  157. }
  158. //获取存储数据,若不存在,则获得缺省值。
  159. function getStorageValue(obj, name, defaultStatus, callback) {
  160. wx.getStorage({
  161. key: name,
  162. success: function (res) {
  163. obj.data[name] = res.data;
  164. obj.setData(obj.data);
  165. callback();
  166. },
  167. fail: function (res) {
  168. obj.data[name] = defaultStatus;
  169. obj.setData(obj.data);
  170. callback();
  171. },
  172. });
  173. }
  174. function getProgramList() {
  175. return [{
  176. id: 89,
  177. appId: 'wx46a7b4c420e6d38f',
  178. path: 'pages/index/start?SourceID=' + app.globalData.ProgramID,
  179. },
  180. {
  181. id: 98,
  182. appId: 'wx331e8dd070f01d0e',
  183. path: 'pages/index/index?SourceID=' + app.globalData.ProgramID,
  184. },
  185. {
  186. id: 99,
  187. appId: 'wxb54a6d5aff836ee3',
  188. path: 'pages/index/index?SourceID=' + app.globalData.ProgramID,
  189. },
  190. {
  191. id: 106,
  192. appId: 'wx313a8f2c0741efe1',
  193. path: 'pages/index/index?SourceID=' + app.globalData.ProgramID,
  194. },
  195. ];
  196. }
  197. function gotoFeedback() {
  198. wx.navigateToMiniProgram({
  199. appId: "wx80059777521b897c",
  200. path: "pages/index/feedback",
  201. extraData: {},
  202. success(res) {
  203. // 打开成功
  204. }
  205. });
  206. }
  207. function changeViewToString(content) {
  208. var str = content;
  209. if (str.constructor == Array) {
  210. if (str.length > 0)
  211. str = str.join(",");
  212. else
  213. str = "";
  214. }
  215. if (!str)
  216. str = ""
  217. else {
  218. str = str.replace(/\n\n\n/g, "\n\n");
  219. if (str.indexOf("\n") == 0 && str.indexOf("[") == 1) {
  220. str = str.substr(1);
  221. }
  222. if (str.lastIndexOf("\n") == str.length - 1) {
  223. str = str.substr(0, str.length - 1);
  224. }
  225. }
  226. return str;
  227. }
  228. function EncryptUrl(str) {
  229. if (str.constructor == Array) {
  230. if (str.length > 0)
  231. str = str.join(",");
  232. else
  233. str = "";
  234. }
  235. if (str) {
  236. str = str.replace(/baidu.com/g, "#####1#####");
  237. str = str.replace(/iciba.com/g, "#####2#####");
  238. str = str.replace(/https:\/\/pinyin.kylx365.com\/sounds/g, "#####3#####");
  239. str = str.replace(/https:\/\/miaguo-1253256735.file.myqcloud.com/g, "#####4#####");
  240. }
  241. if (str.substr(0, 1) == "\n")
  242. str = str.substr(1);
  243. return str;
  244. }
  245. function DecryptUrl(str) {
  246. if (str.constructor == Array) {
  247. if (str.length > 0)
  248. str = str.join(",");
  249. else
  250. str = "";
  251. }
  252. if (str) {
  253. str = str.replace(/#####1#####/g, "baidu.com");
  254. str = str.replace(/#####2#####/g, "iciba.com");
  255. str = str.replace(/#####3#####/g, "https://pinyin.kylx365.com/sounds");
  256. str = str.replace(/#####4#####/g, "https://miaguo-1253256735.file.myqcloud.com");
  257. }
  258. return str;
  259. }
  260. function changeStringToView(field) {
  261. var result = {};
  262. result.Field = [
  263. []
  264. ];
  265. result.Images = [];
  266. for (var j = 0; j < field.length; j++) {
  267. if (j == 0) {
  268. if (field[j].ContentType == 0 && field[j].Content && field[j].Content.length > 0) {
  269. result.Tags = field[j].Content.toString().split(",");
  270. } else {
  271. result.Tags = [];
  272. }
  273. } else {
  274. if (field[j].ContentType == j && field[j].Content && field[j].Content.length > 0) {
  275. var arrResult = [],
  276. arrSoundMark = [];
  277. var str = field[j].Content.toString();
  278. str = DecryptUrl(str);
  279. if (str.indexOf("[读") > 0)
  280. str = str.replace(/\[读/g, "\n[读");
  281. str = str.replace(/\[图/g, "\n[图");
  282. if (str.indexOf("[音") > 0)
  283. str = str.replace(/\[音/g, "\n[音");
  284. str = str.replace(/\[\/读\]/g, "[\/读]\n");
  285. str = str.replace(/\[\/图\]/g, "[\/图]\n");
  286. str = str.replace(/\[\/音\]/g, "[\/音]\n");
  287. str = str.replace(/\n\n\n/g, "\n\n");
  288. var arr = str.split("\n");
  289. for (var k = 0; k < arr.length; k++) {
  290. if (arr[k].indexOf("[图") >= 0 && arr[k].indexOf("[/图]") > 0) {
  291. var obj = {};
  292. obj.Type = "image";
  293. if (arr[k].indexOf("[图") >= 0) {
  294. obj.ContentServer = arr[k].substring(arr[k].indexOf("[图") + 3, arr[k].indexOf("[/图]"));
  295. const w = 650;
  296. if (obj.ContentServer.indexOf("w='") >= 0 && obj.ContentServer.indexOf("h='") >= 0) {
  297. obj.Width = obj.ContentServer.substring(obj.ContentServer.indexOf("w='") + 3, obj.ContentServer.indexOf("h='") - 2);
  298. obj.Height = obj.ContentServer.substring(obj.ContentServer.indexOf("h='") + 3, obj.ContentServer.indexOf("']"));
  299. obj.Height = Math.round((w * Number(obj.Height)) / Number(obj.Width));
  300. obj.Width = w;
  301. } else {
  302. obj.Width = "";
  303. obj.Height = "";
  304. }
  305. obj.ContentServer = obj.ContentServer.substring(obj.ContentServer.indexOf("]") + 1);
  306. obj.Content = getTempImage(obj.ContentServer);
  307. result.Images.push(obj.Content);
  308. }
  309. arrResult.push(obj);
  310. } else if ((arr[k].indexOf("[线]") >= 0 && arr[k].indexOf("[/线]") > 0) || (arr[k].indexOf("[光]") >= 0 && arr[k].indexOf("[/光]") > 0)) {
  311. var obj;
  312. var content = [],
  313. temp = arr[k];
  314. do {
  315. var num1 = temp.indexOf("[线]");
  316. var num2 = temp.indexOf("[光]");
  317. if (num1 >= 0 || num2 >= 0) {
  318. if ((num1 < num2 && num1 >= 0 && num2 >= 0) || (num1 >= 0 && num2 < 0)) {
  319. var temp1 = temp.substring(0, temp.indexOf("[线]"));
  320. if (temp1) {
  321. content.push({
  322. key: "normal",
  323. value: temp1,
  324. });
  325. } else {
  326. if (arr[k].indexOf("[线]") > 0) {
  327. content.push({
  328. key: "normal",
  329. value: temp,
  330. });
  331. temp = "";
  332. } else {
  333. if (temp && temp.indexOf("[线]") < 0) {
  334. content.push({
  335. key: "normal",
  336. value: temp,
  337. });
  338. temp = "";
  339. }
  340. }
  341. }
  342. } else if ((num1 > num2 && num1 >= 0 && num2 >= 0) || (num1 < 0 && num2 >= 0)) {
  343. var temp1 = temp.substring(0, temp.indexOf("[光]"));
  344. if (temp1) {
  345. content.push({
  346. key: "normal",
  347. value: temp1,
  348. });
  349. } else {
  350. if (arr[k].indexOf("[光]") > 0) {
  351. content.push({
  352. key: "normal",
  353. value: temp,
  354. });
  355. temp = "";
  356. } else {
  357. if (temp && temp.indexOf("[光]") < 0) {
  358. content.push({
  359. key: "normal",
  360. value: temp,
  361. });
  362. temp = "";
  363. }
  364. }
  365. }
  366. } else {
  367. content.push({
  368. key: "normal",
  369. value: temp,
  370. });
  371. temp = "";
  372. }
  373. } else {
  374. content.push({
  375. key: "normal",
  376. value: temp,
  377. });
  378. temp = "";
  379. }
  380. if (temp.length > 0 && (num1 >= 0 || num2 >= 0)) {
  381. if ((num1 < num2 && num1 >= 0 && num2 >= 0) || (num1 >= 0 && num2 < 0)) {
  382. temp = temp.substr(temp.indexOf("[线]") + 3);
  383. temp1 = temp.substring(0, temp.indexOf("[/线]"));
  384. if (temp1) {
  385. content.push({
  386. key: "line",
  387. value: temp1,
  388. });
  389. }
  390. temp = temp.substr(temp.indexOf("[/线]") + 4);
  391. } else if ((num1 > num2 && num1 >= 0 && num2 >= 0) || (num1 < 0 && num2 >= 0)) {
  392. temp = temp.substr(temp.indexOf("[光]") + 3);
  393. temp1 = temp.substring(0, temp.indexOf("[/光]"));
  394. if (temp1) {
  395. content.push({
  396. key: "highlighter",
  397. value: temp1,
  398. });
  399. }
  400. temp = temp.substr(temp.indexOf("[/光]") + 4);
  401. } else
  402. temp = "";
  403. } else
  404. temp = "";
  405. }
  406. while (temp.length > 0);
  407. obj = {};
  408. obj.Type = "line";
  409. obj.Content = content;
  410. arrResult.push(obj);
  411. } else if (arr[k].indexOf("[读") >= 0 && arr[k].indexOf("[/读]") > 0) {
  412. var obj = {};
  413. obj.Type = "sound";
  414. if (arr[k].indexOf("[读]") >= 0) {
  415. obj.Content = arr[k].substring(arr[k].indexOf("[读]") + 3, arr[k].indexOf("[/读]"));
  416. } else {
  417. var tempIndex = arr[k].indexOf("\']") + 2;
  418. obj.Content = arr[k].substring(tempIndex, arr[k].indexOf("[/读]"));
  419. obj.SoundMark = arr[k].substring(arr[k].indexOf("src='") + 5, arr[k].indexOf("']"));;
  420. }
  421. arrResult.push(obj);
  422. } else if (arr[k].indexOf("[音") >= 0 && arr[k].indexOf("[/音]") > 0) {
  423. var obj = {};
  424. obj.Type = "recorder";
  425. var tempIndex = arr[k].indexOf("\']") + 2;
  426. //obj.Content = arr[k].substring(tempIndex, arr[k].indexOf("[/音]"));
  427. obj.SoundMark = arr[k].substring(arr[k].indexOf("url='") + 5, arr[k].indexOf("']"));;
  428. arrResult.push(obj);
  429. } else if (arr[k] != "") {
  430. var obj = {};
  431. obj.Type = "normal";
  432. obj.Content = arr[k];
  433. arrResult.push(obj);
  434. } else if (k > 0 && arr[k] == "") {
  435. var obj = {};
  436. obj.Type = "br";
  437. obj.Content = "";
  438. arrResult.push(obj);
  439. }
  440. var obj = {};
  441. obj.Type = "return";
  442. arrResult.push(obj);
  443. }
  444. //去掉前回车换行
  445. // while (arrResult[0].Type == "return" ||
  446. // arrResult[0].Type == "br") {
  447. // arrResult.shift();
  448. // if (arrResult.length == 0)
  449. // break;
  450. // }
  451. //去掉后回车换行
  452. for (var i = arrResult.length - 1; i >= 0; i--) {
  453. if (arrResult[i].Type == "return" ||
  454. arrResult[i].Type == "br")
  455. arrResult.pop();
  456. else {
  457. break;
  458. }
  459. }
  460. result.Field.push(arrResult);
  461. } else {
  462. result.Field.push([]);
  463. }
  464. }
  465. }
  466. return result;
  467. }
  468. //得到当天任务
  469. function getTaskTodayList(callback) {
  470. var isNotData = true;
  471. var intervalTask = setTimeout(function () {
  472. if (isNotData) {
  473. wx.showLoading({
  474. title: '请稍候',
  475. mask: true,
  476. });
  477. setTimeout(function () {
  478. wx.hideLoading();
  479. }, 60000);
  480. }
  481. }, 2000);
  482. var that = this;
  483. var url = 'GetMiaoguoCardToday2?UserID=' + app.globalData.userInfo.UserID;
  484. getData(url, function (data) {
  485. clearTimeout(intervalTask);
  486. if (isNotData) {
  487. wx.hideLoading();
  488. }
  489. isNotData = false;
  490. if (data) {
  491. app.globalData.TaskToday = data;
  492. callback(data);
  493. }
  494. });
  495. }
  496. function getTempImage(serverUrl) {
  497. if (serverUrl.indexOf("miaguo-1253256735") >= 0) {
  498. var list = wx.getStorageSync("TempImageList");
  499. if (!list)
  500. list = [];
  501. for (var i = 0; i < list.length; i++) {
  502. if (list[i].ServerUrl == serverUrl) {
  503. return list[i].TempUrl;
  504. break;
  505. }
  506. }
  507. }
  508. return serverUrl;
  509. }
  510. function getServerImage(tempUrl) {
  511. if (tempUrl.indexOf("http") < 0) {
  512. var list = wx.getStorageSync("TempImageList");
  513. if (!list)
  514. list = [];
  515. for (var i = 0; i < list.length; i++) {
  516. if (list[i].TempUrl == tempUrl) {
  517. return list[i].ServerUrl;
  518. break;
  519. }
  520. }
  521. return ""
  522. }
  523. }
  524. function saveTempImage(serverUrl, tempUrl) {
  525. if (tempUrl.indexOf("http") < 0) {
  526. var list = wx.getStorageSync("TempImageList");
  527. if (!list)
  528. list = [];
  529. var b = false;
  530. for (var i = 0; i < list.length; i++) {
  531. if (list[i].ServerUrl == serverUrl) {
  532. list[i].TempUrl = tempUrl;
  533. b = true;
  534. break;
  535. }
  536. }
  537. if (!b) {
  538. list.push({
  539. "ServerUrl": serverUrl,
  540. "TempUrl": tempUrl
  541. });
  542. }
  543. if (list.length > 200) {
  544. list.pop();
  545. }
  546. wx.setStorageSync("TempImageList", list);
  547. }
  548. }
  549. function UpdateMiaoguoCardTodayAll(isShowLoading, callback) {
  550. var that = this;
  551. if (isShowLoading) {
  552. wx.showLoading({
  553. title: '请稍候',
  554. mask: true,
  555. });
  556. clearTimeout(dataSendTimeout);
  557. dataSendTimeout = setTimeout(function () {
  558. wx.hideLoading();
  559. wx.reLaunch({
  560. url: '../index/index',
  561. })
  562. }, 60000);
  563. }
  564. var list = wx.getStorageSync("ListTaskFinished");
  565. if (list && list.length > 0) {
  566. var arr = [];
  567. for (var i = 0; i < list.length; i++) {
  568. var obj = {};
  569. obj.MiaoguoCardID = list[i].Card.MiaoguoCardID;
  570. obj.IntervalTime = list[i].IntervalTime;
  571. obj.BtnNumber = list[i].BtnNumber;
  572. obj.FontSize = list[i].Card.FontSize;
  573. obj.Duration = list[i].Duration;
  574. obj.LearningType = list[i].LearningType;
  575. obj.IsCollect = list[i].Card.IsCollect;
  576. arr.push(obj);
  577. }
  578. that.postData('UpdateMiaoguoCardTodayAll?UserID=' + app.globalData.userInfo.UserID, {
  579. List: arr,
  580. }, function (data) {
  581. if (isShowLoading) {
  582. wx.hideLoading();
  583. clearTimeout(dataSendTimeout);
  584. }
  585. if (data) {
  586. wx.removeStorageSync("ListTaskFinished");
  587. }
  588. if (callback) {
  589. callback();
  590. }
  591. });
  592. } else {
  593. wx.hideLoading();
  594. clearTimeout(dataSendTimeout);
  595. if (callback) {
  596. callback();
  597. }
  598. }
  599. }
  600. function updateSearchList(obj) {
  601. var arr = wx.getStorageSync("SearchWord3");
  602. if (!arr)
  603. arr = [];
  604. if (obj.Type == "shici") {
  605. if (obj.Value.CHN.ShiciTitle)
  606. obj.Key = obj.Value.CHN.ShiciTitle;
  607. if (obj.Key.indexOf("《") == 0)
  608. obj.Key = obj.Key.substring(1, obj.Key.length - 1);
  609. }
  610. for (var i = 0; i < arr.length; i++) {
  611. if (arr[i].Key == obj.Key &&
  612. arr[i].Type == obj.Type &&
  613. arr[i].Author == obj.Author
  614. ) {
  615. if (obj.Type == "shici") {
  616. if (arr[i].ShiciUrl == obj.ShiciUrl) {
  617. obj.Value = arr[i].Value;
  618. arr.splice(i, 1);
  619. break;
  620. }
  621. } else {
  622. obj.Value = arr[i].Value;
  623. arr.splice(i, 1);
  624. break;
  625. }
  626. }
  627. }
  628. if (obj.Key)
  629. arr.unshift(obj);
  630. if (arr.length > 100) {
  631. arr.pop();
  632. }
  633. wx.setStorageSync("SearchWord3", arr);
  634. app.globalData.SearchItem = obj.Value;
  635. }
  636. function checkIsIPhoneX() {
  637. var isIphoneX = false;
  638. if (app.globalData.systemInfo.model.indexOf("iPhone X") >= 0 ||
  639. app.globalData.systemInfo.model.indexOf("iPhone X") >= 0) {
  640. isIphoneX = true;
  641. }
  642. return isIphoneX;
  643. }
  644. //设置收藏
  645. function setCollect(id, collect, callback) {
  646. var that = this;
  647. if (collect) {
  648. wx.showToast({
  649. title: '已收藏',
  650. duration: 2000,
  651. image: "../images/universalpic_fav_white_120x110.png",
  652. });
  653. } else {
  654. wx.showToast({
  655. title: '取消收藏',
  656. duration: 2000,
  657. image: "../images/universalpic_fav_white_120x110.png",
  658. });
  659. }
  660. getData("UpdateMiaoguoCardInfo?UserID=" + app.globalData.userInfo.UserID + "&MiaoguoCardID=" + id + "&IsCollect=" + collect, function (data) {
  661. if (callback)
  662. callback();
  663. });
  664. }
  665. function buildInitData(callback) {
  666. var that = this;
  667. wx.showLoading({
  668. title: '数据初始化',
  669. });
  670. setTimeout(function () {
  671. wx.hideLoading();
  672. }, 5000);
  673. getData('BuildInitData?UserID=' + app.globalData.userInfo.UserID, function (data) {
  674. wx.hideLoading();
  675. if (data) {
  676. if (callback)
  677. callback();
  678. }
  679. });
  680. }
  681. function getMemoryLevelAll() {
  682. return constant.arrMemoryLevelAll;
  683. }
  684. function getMemoryLevel(index, number, time) {
  685. var arr = getMemoryLevelAll();
  686. if (index < 1)
  687. return arr[index].Value[number].Name;
  688. else
  689. return replaceStr(time);
  690. function replaceStr(data) {
  691. var result = "";
  692. if (data.indexOf("d") > 0) {
  693. var dayNum = Number(data.replace("d", ""));
  694. if (dayNum >= 365) {
  695. var year1 = Math.floor(dayNum / 365);
  696. var year = year1 + Math.round(10 * (dayNum - year1 * 365) / 365) / 10;
  697. result = year + "年后";
  698. } else {
  699. if (dayNum > 31) {
  700. var month1 = Math.floor(dayNum / 30);
  701. var month = month1 + Math.round(10 * (dayNum - month1 * 30) / 30) / 10;
  702. result = month + "月后";
  703. } else {
  704. result = Number(data.replace("d", ""));
  705. if (result == 1)
  706. result = "明天";
  707. else if (result == 2)
  708. result = "后天";
  709. else
  710. result = (result - 1) + "天后";
  711. }
  712. }
  713. } else if (data.indexOf("m") > 0)
  714. result = data.replace("m", "分钟内");
  715. return result;
  716. }
  717. }
  718. //得到要检验的汉字列表
  719. function GetHanziUnitWords(unitsID, testType, callback) {
  720. getData('GetHanziUnitWords?UnitID=' + unitsID, function (data) {
  721. if (data) {
  722. var TaskList = [];
  723. var words = data;
  724. for (var k = 0; k < words.length; k++) {
  725. var taskInfo = {
  726. FontSize: 144,
  727. TagWidth: 136,
  728. Content: [{
  729. ContentType: 0,
  730. Content: []
  731. },
  732. {
  733. ContentType: 1,
  734. Content: []
  735. },
  736. {
  737. ContentType: 2,
  738. Content: []
  739. },
  740. ]
  741. };
  742. taskInfo.Word = words[k].Name;
  743. var pinyinNormal = "(" + getPinyinNormal(words[k].Pinyin) + ")";
  744. var combineWords = common.ReplaceAllString(words[k].CombineWords, words[k].Name, words[k].Name + pinyinNormal);
  745. taskInfo.ReadString = words[k].Name + pinyinNormal + "," + combineWords + "的" + words[k].Name + pinyinNormal;
  746. if (testType == "read") {
  747. taskInfo.Content[0].Content = ["怎么念"];
  748. var question = words[k].CombineWords;
  749. question = common.ReplaceAllString(question, words[k].Name, "(" + words[k].Name + ")");
  750. taskInfo.Content[1].Content = question;
  751. var answer = "[读 src='" + taskInfo.ReadString + "']" + words[k].Pinyin + "[/读]";
  752. taskInfo.Content[2].Content = answer;
  753. if (words[k].CombineWords.length > 6) {
  754. taskInfo.FontSize = 108;
  755. if (words[k].CombineWords.length > 10) {
  756. taskInfo.FontSize = 68;
  757. }
  758. }
  759. } else if (testType == "write") {
  760. taskInfo.Content[0].Content = ["怎么写"];
  761. var question = words[k].CombineWords;
  762. var question2 = common.ReplaceAllString(question, words[k].Name, words[k].Pinyin);
  763. question = "[读 src='" + taskInfo.ReadString + "']" + question2 + "[/读]"
  764. taskInfo.Content[1].Content = question;
  765. var answer = words[k].Name;
  766. answer += "[图 w='650' h='650']" + words[k].BiShunUrl + "[/图]";
  767. taskInfo.Content[2].Content = answer;
  768. if (question2.length > 6) {
  769. taskInfo.FontSize = 108;
  770. if (question2.length > 10) {
  771. taskInfo.FontSize = 68;
  772. if (question2.length > 14) {
  773. taskInfo.FontSize = 48;
  774. }
  775. }
  776. }
  777. }
  778. taskInfo.ContentNew = changeStringToView(taskInfo.Content);
  779. TaskList.push(taskInfo);
  780. }
  781. callback(TaskList);
  782. } else {
  783. callback([]);
  784. }
  785. });
  786. }
  787. function GetTestReportInfo(reportid, callback) {
  788. var UserTestReport = wx.getStorageSync('UserTestReport');
  789. for (var n = 0; n < UserTestReport.length; n++) {
  790. if (UserTestReport[n].ID == reportid) {
  791. var name1 = UserTestReport[n].Name[0].split(" ");
  792. var name2 = UserTestReport[n].Name[1];
  793. if (name1[0].indexOf("英语") >= 0) {
  794. //todo
  795. //console.log("英语");
  796. var arrEnglist = wx.getStorageSync("EnglishAll");
  797. if (arrEnglist)
  798. arrEnglist = JSON.parse(arrEnglist);
  799. else
  800. arrEnglist = [];
  801. var wordStr = "";
  802. for (var i = 0; i < arrEnglist.length; i++) {
  803. if (arrEnglist[i].Name == name1[1]) {
  804. for (var j = 0; j < arrEnglist[i].Units.length; j++) {
  805. if (arrEnglist[i].Units[j].Name == name2) {
  806. wordStr = arrEnglist[i].Units[j].Words.join(",");
  807. break;
  808. }
  809. }
  810. }
  811. }
  812. var userTestReportInfo = UserTestReport[n];
  813. var bookid = Number(name1[1].substr(4)) + 12;
  814. var tempRight = "," + userTestReportInfo.TestRightStr + ",";
  815. var tempWrong = "," + userTestReportInfo.TestWrongStr + ",";
  816. var tempSkip = "," + userTestReportInfo.TestSkipStr + ",";
  817. var tempExist = "," + userTestReportInfo.TestExistStr + ",";
  818. getData('GetTestEnglishWords?UserID=' + app.globalData.userInfo.UserID + '&Words=' + wordStr, function (data) {
  819. if (data) {
  820. var result = {};
  821. result.ID = userTestReportInfo.ID;
  822. result.IsFinished = userTestReportInfo.IsFinished;
  823. result.Name = userTestReportInfo.Name.join("#");
  824. result.TestType = userTestReportInfo.TestType;
  825. result.BookID = bookid;
  826. var TaskList = [];
  827. var words = data;
  828. for (var k = 0; k < words.length; k++) {
  829. var taskInfo = words[k];
  830. taskInfo.TagWidth = 364;
  831. taskInfo.ContentNew = changeStringToView(taskInfo.Content);
  832. if (tempRight.indexOf("," + taskInfo.Word + ",") >= 0)
  833. taskInfo.Result = 1;
  834. if (tempWrong.indexOf("," + taskInfo.Word + ",") >= 0)
  835. taskInfo.Result = -1;
  836. if (tempSkip.indexOf("," + taskInfo.Word + ",") >= 0)
  837. taskInfo.Result = 0;
  838. if (tempExist.indexOf("," + taskInfo.Word + ",") >= 0)
  839. taskInfo.Css = "Select2";
  840. TaskList.push(taskInfo);
  841. }
  842. result.TestRightStr = "";
  843. result.TestWrongStr = "";
  844. result.TestSkipStr = "";
  845. result.TestExistStr = "";
  846. if (userTestReportInfo.TestRightStr)
  847. result.TestRightStr = userTestReportInfo.TestRightStr;
  848. if (userTestReportInfo.TestWrongStr)
  849. result.TestWrongStr = userTestReportInfo.TestWrongStr;
  850. if (userTestReportInfo.TestSkipStr)
  851. result.TestSkipStr = userTestReportInfo.TestSkipStr;
  852. if (userTestReportInfo.TestExistStr)
  853. result.TestExistStr = userTestReportInfo.TestExistStr;
  854. result.List = TaskList;
  855. callback(result);
  856. } else {
  857. callback({});
  858. }
  859. });
  860. } else {
  861. name1 = name1[0] + "识字能力" + name1[2].substr(0, 1);
  862. var HanziAll = wx.getStorageSync('HanziAll');
  863. HanziAll = JSON.parse(HanziAll);
  864. for (var i = 0; i < HanziAll.length; i++) {
  865. if (name1 == HanziAll[i].Name) {
  866. for (var j = 0; j < HanziAll[i].Units.length; j++) {
  867. if (name2 == HanziAll[i].Units[j].Name) {
  868. var obj = UserTestReport[n];
  869. GetHanziUnitWords(HanziAll[i].Units[j].ID, obj.TestType, function (list) {
  870. if (list) {
  871. for (var k = 0; k < list.length; k++) {
  872. if (obj.TestRightStr && obj.TestRightStr.indexOf(list[k].Word) >= 0)
  873. list[k].Result = 1;
  874. else if (obj.TestWrongStr && obj.TestWrongStr.indexOf(list[k].Word) >= 0)
  875. list[k].Result = -1;
  876. else if (obj.TestSkipStr && obj.TestSkipStr.indexOf(list[k].Word) >= 0)
  877. list[k].Result = 0;
  878. if (obj.TestExistStr && obj.TestExistStr.indexOf(list[k].Word) >= 0)
  879. list[k].Css = "Select2";
  880. }
  881. var result = {};
  882. result.ID = reportid;
  883. result.TestType = obj.TestType;
  884. result.Name = obj.Name.join("#");
  885. result.IsFinished = obj.IsFinished;
  886. result.TestRightStr = obj.TestRightStr;
  887. result.TestWrongStr = obj.TestWrongStr;
  888. result.TestSkipStr = obj.TestSkipStr;
  889. result.TestExistStr = obj.TestExistStr;
  890. result.List = list;
  891. callback(result);
  892. } else
  893. callback({});
  894. });
  895. }
  896. }
  897. }
  898. }
  899. }
  900. }
  901. }
  902. }
  903. function getDetailColor(index) {
  904. var arrDetailColor = constant.arrDetailColor;
  905. if (index > 0)
  906. return arrDetailColor[index];
  907. else if (index == 0)
  908. return arrDetailColor[common.random(1, arr.length - 1)];
  909. else if (index == -1)
  910. return arrDetailColor;
  911. }
  912. function getShareImageBackColor() {
  913. var arr = constant.arrShareImageBackColor;
  914. return arr[common.random(0, arr.length - 1)];
  915. }
  916. function getPinyinNormal(pinyin) {
  917. var result = "";
  918. var arr = constant.arrPinyin;
  919. for (var i = 0; i < arr.length; i++) {
  920. if (arr[i][1] == pinyin) {
  921. result = arr[i][0];
  922. break;
  923. }
  924. }
  925. return result;
  926. }
  927. function getHanzi(callback) {
  928. var that = this;
  929. wx.showLoading({
  930. title: '请稍候',
  931. mask: true,
  932. });
  933. var time = wx.getStorageSync("HanziUpdateTime");
  934. getData('GetHanziAll?HasEnglish=true&UpdateTime=' + time, function (data) {
  935. wx.hideLoading();
  936. if (data) {
  937. var arr = [];
  938. if (data.List) {
  939. arr = common.Decrypt(data.List);
  940. wx.setStorageSync("HanziAll", arr);
  941. var arrEng = common.Decrypt(data.EngList);
  942. wx.setStorageSync("EnglishAll", arrEng);
  943. wx.setStorageSync("HanziUpdateTime", data.UpdateTime);
  944. } else {
  945. arr = wx.getStorageSync("HanziAll");
  946. if (arr)
  947. arr = JSON.parse(arr);
  948. }
  949. callback(arr);
  950. }
  951. });
  952. }
  953. function UploadUserConfig(callback) {
  954. var that = this;
  955. var param1 = {};
  956. param1.CardType = wx.getStorageSync("CardType");
  957. param1.CardMaxNumberNew = wx.getStorageSync("CardMaxNumberNew");
  958. param1.CardMaxNumberHistory = wx.getStorageSync("CardMaxNumberHistory");
  959. param1.CardMaxNumberNewUrgent = wx.getStorageSync("CardMaxNumberNewUrgent");
  960. param1.CardMaxNumberHistoryUrgent = wx.getStorageSync("CardMaxNumberHistoryUrgent");
  961. param1.SortTypeIndex = wx.getStorageSync("SortTypeIndex");
  962. param1.MemoryLevel = wx.getStorageSync("MemoryLevel");
  963. param1.ClickType = wx.getStorageSync("ClickType");
  964. param1.SecondConfigArray = wx.getStorageSync("SecondConfigArray").join(",");
  965. param1.ColorIndexArr = wx.getStorageSync("ColorIndexArr").join(",");
  966. var symboMain = wx.getStorageSync("SymbolMain");
  967. var symbol1 = [];
  968. for (var i = 0; i < symboMain.length; i++) {
  969. symbol1.push(symboMain[i].Name);
  970. }
  971. symbol1 = JSON.stringify(symbol1);
  972. param1.SymbolList = symbol1;
  973. that.postData('UploadUserConfig?Type=update&UserID=' + app.globalData.userInfo.UserID, param1, function (data) {
  974. if (callback) {
  975. callback();
  976. }
  977. });
  978. }
  979. function getUserConfig() {
  980. var that = this;
  981. postData('UploadUserConfig?Type=getData&UserID=' + app.globalData.userInfo.UserID, {}, function (data) {
  982. var cardType = wx.getStorageSync("CardType");
  983. wx.setStorageSync("CardType", data.CardType);
  984. wx.setStorageSync("CardMaxNumberNew", data.CardMaxNumberNew);
  985. wx.setStorageSync("CardMaxNumberHistory", data.CardMaxNumberHistory);
  986. wx.setStorageSync("CardMaxNumberNewUrgent", data.CardMaxNumberNewUrgent);
  987. wx.setStorageSync("CardMaxNumberHistoryUrgent", data.CardMaxNumberHistoryUrgent);
  988. wx.setStorageSync("SortTypeIndex", data.SortTypeIndex);
  989. wx.setStorageSync("MemoryLevel", data.MemoryLevel);
  990. wx.setStorageSync("ClickType", data.ClickType);
  991. wx.setStorageSync("SecondConfigArray", data.SecondConfigArray.split(","));
  992. wx.setStorageSync("ColorIndexArr", data.ColorIndexArr.split(","));
  993. var symbol1 = [];
  994. if (data.SymbolList) {
  995. for (var i = 0; i < data.SymbolList.length; i++) {
  996. var obj = {};
  997. obj.Name = data.SymbolList[i];
  998. obj.CSS = "btn2";
  999. symbol1.push(obj);
  1000. }
  1001. }
  1002. else {
  1003. symbol1 = app.globalData.SymbolMain;
  1004. }
  1005. wx.setStorageSync("SymboMain", symbol1);
  1006. app.globalData.SymbolMain=symbol1;
  1007. });
  1008. }
  1009. module.exports = {
  1010. getData: getData,
  1011. postData: postData,
  1012. payMoney: payMoney,
  1013. getLocalHost: getLocalHost,
  1014. getTimeFormat: getTimeFormat,
  1015. getWindowHeight: getWindowHeight,
  1016. getStorageValue: getStorageValue,
  1017. getProgramList: getProgramList,
  1018. gotoFeedback: gotoFeedback,
  1019. getDetailColor: getDetailColor,
  1020. changeStringToView: changeStringToView,
  1021. changeViewToString: changeViewToString,
  1022. encryptUrl: EncryptUrl,
  1023. decryptUrl: DecryptUrl,
  1024. saveTempImage: saveTempImage,
  1025. getTempImage: getTempImage,
  1026. getTaskTodayList: getTaskTodayList,
  1027. updateSearchList: updateSearchList,
  1028. checkIsIPhoneX: checkIsIPhoneX,
  1029. getMemoryLevelAll: getMemoryLevelAll,
  1030. getMemoryLevel: getMemoryLevel,
  1031. getShareImageBackColor: getShareImageBackColor,
  1032. UpdateMiaoguoCardTodayAll: UpdateMiaoguoCardTodayAll,
  1033. setCollect: setCollect,
  1034. UploadUserConfig: UploadUserConfig,
  1035. getServerImage: getServerImage,
  1036. getBaiduToken: getBaiduToken,
  1037. buildInitData: buildInitData,
  1038. getPinyinNormal: getPinyinNormal,
  1039. getHanzi: getHanzi,
  1040. GetHanziUnitWords: GetHanziUnitWords,
  1041. GetTestReportInfo: GetTestReportInfo,
  1042. getUserConfig: getUserConfig
  1043. }