main.js 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138
  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 (temp && temp.indexOf("[线]") < 0) {
  327. content.push({
  328. key: "normal",
  329. value: temp,
  330. });
  331. temp = "";
  332. }
  333. }
  334. } else if ((num1 > num2 && num1 >= 0 && num2 >= 0) || (num1 < 0 && num2 >= 0)) {
  335. var temp1 = temp.substring(0, temp.indexOf("[光]"));
  336. if (temp1) {
  337. content.push({
  338. key: "normal",
  339. value: temp1,
  340. });
  341. } else {
  342. if (temp && temp.indexOf("[光]") < 0) {
  343. content.push({
  344. key: "normal",
  345. value: temp,
  346. });
  347. temp = "";
  348. }
  349. }
  350. } else {
  351. content.push({
  352. key: "normal",
  353. value: temp,
  354. });
  355. temp = "";
  356. }
  357. } else {
  358. content.push({
  359. key: "normal",
  360. value: temp,
  361. });
  362. temp = "";
  363. }
  364. if (temp.length > 0 && (num1 >= 0 || num2 >= 0)) {
  365. if ((num1 < num2 && num1 >= 0 && num2 >= 0) || (num1 >= 0 && num2 < 0)) {
  366. temp = temp.substr(temp.indexOf("[线]") + 3);
  367. temp1 = temp.substring(0, temp.indexOf("[/线]"));
  368. if (temp1) {
  369. content.push({
  370. key: "line",
  371. value: temp1,
  372. });
  373. }
  374. temp = temp.substr(temp.indexOf("[/线]") + 4);
  375. } else if ((num1 > num2 && num1 >= 0 && num2 >= 0) || (num1 < 0 && num2 >= 0)) {
  376. temp = temp.substr(temp.indexOf("[光]") + 3);
  377. temp1 = temp.substring(0, temp.indexOf("[/光]"));
  378. if (temp1) {
  379. content.push({
  380. key: "highlighter",
  381. value: temp1,
  382. });
  383. }
  384. temp = temp.substr(temp.indexOf("[/光]") + 4);
  385. } else
  386. temp = "";
  387. } else
  388. temp = "";
  389. }
  390. while (temp.length > 0);
  391. obj = {};
  392. obj.Type = "line";
  393. obj.Content = content;
  394. arrResult.push(obj);
  395. } else if (arr[k].indexOf("[读") >= 0 && arr[k].indexOf("[/读]") > 0) {
  396. var obj = {};
  397. obj.Type = "sound";
  398. if (arr[k].indexOf("[读]") >= 0) {
  399. obj.Content = arr[k].substring(arr[k].indexOf("[读]") + 3, arr[k].indexOf("[/读]"));
  400. } else {
  401. var tempIndex = arr[k].indexOf("\']") + 2;
  402. obj.Content = arr[k].substring(tempIndex, arr[k].indexOf("[/读]"));
  403. obj.SoundMark = arr[k].substring(arr[k].indexOf("src='") + 5, arr[k].indexOf("']"));;
  404. }
  405. arrResult.push(obj);
  406. } else if (arr[k].indexOf("[音") >= 0 && arr[k].indexOf("[/音]") > 0) {
  407. var obj = {};
  408. obj.Type = "recorder";
  409. var tempIndex = arr[k].indexOf("\']") + 2;
  410. //obj.Content = arr[k].substring(tempIndex, arr[k].indexOf("[/音]"));
  411. obj.SoundMark = arr[k].substring(arr[k].indexOf("url='") + 5, arr[k].indexOf("']"));;
  412. arrResult.push(obj);
  413. } else if (arr[k] != "") {
  414. var obj = {};
  415. obj.Type = "normal";
  416. obj.Content = arr[k];
  417. arrResult.push(obj);
  418. } else if (k > 0 && arr[k] == "") {
  419. var obj = {};
  420. obj.Type = "br";
  421. obj.Content = "";
  422. arrResult.push(obj);
  423. }
  424. var obj = {};
  425. obj.Type = "return";
  426. arrResult.push(obj);
  427. }
  428. //去掉前回车换行
  429. // while (arrResult[0].Type == "return" ||
  430. // arrResult[0].Type == "br") {
  431. // arrResult.shift();
  432. // if (arrResult.length == 0)
  433. // break;
  434. // }
  435. //去掉后回车换行
  436. for (var i = arrResult.length - 1; i >= 0; i--) {
  437. if (arrResult[i].Type == "return" ||
  438. arrResult[i].Type == "br")
  439. arrResult.pop();
  440. else {
  441. break;
  442. }
  443. }
  444. result.Field.push(arrResult);
  445. } else {
  446. result.Field.push([]);
  447. }
  448. }
  449. }
  450. return result;
  451. }
  452. //得到当天任务
  453. function getTaskTodayList(callback) {
  454. var isNotData = true;
  455. var intervalTask = setTimeout(function () {
  456. if (isNotData) {
  457. wx.showLoading({
  458. title: '请稍候',
  459. mask: true,
  460. });
  461. setTimeout(function () {
  462. wx.hideLoading();
  463. }, 60000);
  464. }
  465. }, 2000);
  466. var that = this;
  467. var url = 'GetMiaoguoCardToday2?UserID=' + app.globalData.userInfo.UserID;
  468. getData(url, function (data) {
  469. clearTimeout(intervalTask);
  470. if (isNotData) {
  471. wx.hideLoading();
  472. }
  473. isNotData = false;
  474. if (data) {
  475. app.globalData.TaskToday = data;
  476. callback(data);
  477. }
  478. });
  479. }
  480. function getTempImage(serverUrl) {
  481. if (serverUrl.indexOf("miaguo-1253256735") >= 0) {
  482. var list = wx.getStorageSync("TempImageList");
  483. if (!list)
  484. list = [];
  485. for (var i = 0; i < list.length; i++) {
  486. if (list[i].ServerUrl == serverUrl) {
  487. return list[i].TempUrl;
  488. break;
  489. }
  490. }
  491. }
  492. return serverUrl;
  493. }
  494. function getServerImage(tempUrl) {
  495. if (tempUrl.indexOf("http") < 0) {
  496. var list = wx.getStorageSync("TempImageList");
  497. if (!list)
  498. list = [];
  499. for (var i = 0; i < list.length; i++) {
  500. if (list[i].TempUrl == tempUrl) {
  501. return list[i].ServerUrl;
  502. break;
  503. }
  504. }
  505. return ""
  506. }
  507. }
  508. function saveTempImage(serverUrl, tempUrl) {
  509. if (tempUrl.indexOf("http") < 0) {
  510. var list = wx.getStorageSync("TempImageList");
  511. if (!list)
  512. list = [];
  513. var b = false;
  514. for (var i = 0; i < list.length; i++) {
  515. if (list[i].ServerUrl == serverUrl) {
  516. list[i].TempUrl = tempUrl;
  517. b = true;
  518. break;
  519. }
  520. }
  521. if (!b) {
  522. list.push({
  523. "ServerUrl": serverUrl,
  524. "TempUrl": tempUrl
  525. });
  526. }
  527. if (list.length > 200) {
  528. list.pop();
  529. }
  530. wx.setStorageSync("TempImageList", list);
  531. }
  532. }
  533. function UpdateMiaoguoCardTodayAll(isShowLoading, callback) {
  534. var that = this;
  535. if (isShowLoading) {
  536. wx.showLoading({
  537. title: '请稍候',
  538. mask: true,
  539. });
  540. clearTimeout(dataSendTimeout);
  541. dataSendTimeout = setTimeout(function () {
  542. wx.hideLoading();
  543. wx.reLaunch({
  544. url: '../index/index',
  545. })
  546. }, 60000);
  547. }
  548. var list = wx.getStorageSync("ListTaskFinished");
  549. if (list && list.length > 0) {
  550. var arr = [];
  551. for (var i = 0; i < list.length; i++) {
  552. var obj = {};
  553. obj.MiaoguoCardID = list[i].Card.MiaoguoCardID;
  554. obj.IntervalTime = list[i].IntervalTime;
  555. obj.BtnNumber = list[i].BtnNumber;
  556. obj.FontSize = list[i].Card.FontSize;
  557. obj.Duration = list[i].Duration;
  558. obj.LearningType = list[i].LearningType;
  559. obj.IsCollect = list[i].Card.IsCollect;
  560. arr.push(obj);
  561. }
  562. that.postData('UpdateMiaoguoCardTodayAll?UserID=' + app.globalData.userInfo.UserID, {
  563. List: arr,
  564. }, function (data) {
  565. if (isShowLoading) {
  566. wx.hideLoading();
  567. clearTimeout(dataSendTimeout);
  568. }
  569. if (data) {
  570. wx.removeStorageSync("ListTaskFinished");
  571. }
  572. if (callback) {
  573. callback();
  574. }
  575. });
  576. } else {
  577. wx.hideLoading();
  578. clearTimeout(dataSendTimeout);
  579. if (callback) {
  580. callback();
  581. }
  582. }
  583. }
  584. function updateSearchList(obj) {
  585. var arr = wx.getStorageSync("SearchWord3");
  586. if (!arr)
  587. arr = [];
  588. if (obj.Type == "shici") {
  589. if (obj.Value.CHN.ShiciTitle)
  590. obj.Key = obj.Value.CHN.ShiciTitle;
  591. if (obj.Key.indexOf("《") == 0)
  592. obj.Key = obj.Key.substring(1, obj.Key.length - 1);
  593. }
  594. for (var i = 0; i < arr.length; i++) {
  595. if (arr[i].Key == obj.Key &&
  596. arr[i].Type == obj.Type &&
  597. arr[i].Author == obj.Author
  598. ) {
  599. if (obj.Type == "shici") {
  600. if (arr[i].ShiciUrl == obj.ShiciUrl) {
  601. obj.Value = arr[i].Value;
  602. arr.splice(i, 1);
  603. break;
  604. }
  605. } else {
  606. obj.Value = arr[i].Value;
  607. arr.splice(i, 1);
  608. break;
  609. }
  610. }
  611. }
  612. if (obj.Key)
  613. arr.unshift(obj);
  614. if (arr.length > 100) {
  615. arr.pop();
  616. }
  617. wx.setStorageSync("SearchWord3", arr);
  618. app.globalData.SearchItem = obj.Value;
  619. }
  620. function checkIsIPhoneX() {
  621. var isIphoneX = false;
  622. if (app.globalData.systemInfo.model.indexOf("iPhone X") >= 0 ||
  623. app.globalData.systemInfo.model.indexOf("iPhone X") >= 0) {
  624. isIphoneX = true;
  625. }
  626. return isIphoneX;
  627. }
  628. //设置收藏
  629. function setCollect(id, collect, callback) {
  630. var that = this;
  631. if (collect) {
  632. wx.showToast({
  633. title: '已收藏',
  634. duration: 2000,
  635. image: "../images/universalpic_fav_white_120x110.png",
  636. });
  637. } else {
  638. wx.showToast({
  639. title: '取消收藏',
  640. duration: 2000,
  641. image: "../images/universalpic_fav_white_120x110.png",
  642. });
  643. }
  644. getData("UpdateMiaoguoCardInfo?UserID=" + app.globalData.userInfo.UserID + "&MiaoguoCardID=" + id + "&IsCollect=" + collect, function (data) {
  645. if (callback)
  646. callback();
  647. });
  648. }
  649. function buildInitData(callback) {
  650. var that = this;
  651. wx.showLoading({
  652. title: '数据初始化',
  653. });
  654. setTimeout(function () {
  655. wx.hideLoading();
  656. }, 5000);
  657. getData('BuildInitData?UserID=' + app.globalData.userInfo.UserID, function (data) {
  658. wx.hideLoading();
  659. if (data) {
  660. if (callback)
  661. callback();
  662. }
  663. });
  664. }
  665. function getMemoryLevelAll() {
  666. return constant.arrMemoryLevelAll;
  667. }
  668. function getMemoryLevel(index, number, time) {
  669. var arr = getMemoryLevelAll();
  670. if (index < 1)
  671. return arr[index].Value[number].Name;
  672. else
  673. return replaceStr(time);
  674. function replaceStr(data) {
  675. var result = "";
  676. if (data.indexOf("d") > 0) {
  677. var dayNum = Number(data.replace("d", ""));
  678. if (dayNum >= 365) {
  679. var year1 = Math.floor(dayNum / 365);
  680. var year = year1 + Math.round(10 * (dayNum - year1 * 365) / 365) / 10;
  681. result = year + "年后";
  682. } else {
  683. if (dayNum > 31) {
  684. var month1 = Math.floor(dayNum / 30);
  685. var month = month1 + Math.round(10 * (dayNum - month1 * 30) / 30) / 10;
  686. result = month + "月后";
  687. } else {
  688. result = Number(data.replace("d", ""));
  689. if (result == 1)
  690. result = "明天";
  691. else if (result == 2)
  692. result = "后天";
  693. else
  694. result = (result - 1) + "天后";
  695. }
  696. }
  697. } else if (data.indexOf("m") > 0)
  698. result = data.replace("m", "分钟内");
  699. return result;
  700. }
  701. }
  702. //得到要检验的汉字列表
  703. function GetHanziUnitWords(unitsID, testType, callback) {
  704. getData('GetHanziUnitWords?UnitID=' + unitsID, function (data) {
  705. if (data) {
  706. var TaskList = [];
  707. var words = data;
  708. for (var k = 0; k < words.length; k++) {
  709. var taskInfo = {
  710. FontSize: 144,
  711. TagWidth: 136,
  712. Content: [{
  713. ContentType: 0,
  714. Content: []
  715. },
  716. {
  717. ContentType: 1,
  718. Content: []
  719. },
  720. {
  721. ContentType: 2,
  722. Content: []
  723. },
  724. ]
  725. };
  726. taskInfo.Word = words[k].Name;
  727. var pinyinNormal = "(" + getPinyinNormal(words[k].Pinyin) + ")";
  728. var combineWords = common.ReplaceAllString(words[k].CombineWords, words[k].Name, words[k].Name + pinyinNormal);
  729. taskInfo.ReadString = words[k].Name + pinyinNormal + "," + combineWords + "的" + words[k].Name + pinyinNormal;
  730. if (testType == "read") {
  731. taskInfo.Content[0].Content = ["怎么念"];
  732. var question = words[k].CombineWords;
  733. question = common.ReplaceAllString(question, words[k].Name, "(" + words[k].Name + ")");
  734. taskInfo.Content[1].Content = question;
  735. var answer = "[读 src='" + taskInfo.ReadString + "']" + words[k].Pinyin + "[/读]";
  736. taskInfo.Content[2].Content = answer;
  737. if (words[k].CombineWords.length > 6) {
  738. taskInfo.FontSize = 108;
  739. if (words[k].CombineWords.length > 10) {
  740. taskInfo.FontSize = 68;
  741. }
  742. }
  743. } else if (testType == "write") {
  744. taskInfo.Content[0].Content = ["怎么写"];
  745. var question = words[k].CombineWords;
  746. var question2 = common.ReplaceAllString(question, words[k].Name, words[k].Pinyin);
  747. question = "[读 src='" + taskInfo.ReadString + "']" + question2 + "[/读]"
  748. taskInfo.Content[1].Content = question;
  749. var answer = words[k].Name;
  750. answer += "[图 w='650' h='650']" + words[k].BiShunUrl + "[/图]";
  751. taskInfo.Content[2].Content = answer;
  752. if (question2.length > 6) {
  753. taskInfo.FontSize = 108;
  754. if (question2.length > 10) {
  755. taskInfo.FontSize = 68;
  756. if (question2.length > 14) {
  757. taskInfo.FontSize = 48;
  758. }
  759. }
  760. }
  761. }
  762. taskInfo.ContentNew = changeStringToView(taskInfo.Content);
  763. TaskList.push(taskInfo);
  764. }
  765. callback(TaskList);
  766. } else {
  767. callback([]);
  768. }
  769. });
  770. }
  771. function GetTestReportInfo(reportid, callback) {
  772. var UserTestReport = wx.getStorageSync('UserTestReport');
  773. for (var n = 0; n < UserTestReport.length; n++) {
  774. if (UserTestReport[n].ID == reportid) {
  775. var name1 = UserTestReport[n].Name[0].split(" ");
  776. var name2 = UserTestReport[n].Name[1];
  777. if (name1[0].indexOf("英语") >= 0) {
  778. //todo
  779. //console.log("英语");
  780. var arrEnglist = wx.getStorageSync("EnglishAll");
  781. if (arrEnglist)
  782. arrEnglist = JSON.parse(arrEnglist);
  783. else
  784. arrEnglist = [];
  785. var wordStr = "";
  786. for (var i = 0; i < arrEnglist.length; i++) {
  787. if (arrEnglist[i].Name == name1[1]) {
  788. for (var j = 0; j < arrEnglist[i].Units.length; j++) {
  789. if (arrEnglist[i].Units[j].Name == name2) {
  790. wordStr = arrEnglist[i].Units[j].Words.join(",");
  791. break;
  792. }
  793. }
  794. }
  795. }
  796. var userTestReportInfo = UserTestReport[n];
  797. var bookid = Number(name1[1].substr(4)) + 12;
  798. var tempRight = "," + userTestReportInfo.TestRightStr + ",";
  799. var tempWrong = "," + userTestReportInfo.TestWrongStr + ",";
  800. var tempSkip = "," + userTestReportInfo.TestSkipStr + ",";
  801. var tempExist = "," + userTestReportInfo.TestExistStr + ",";
  802. getData('GetTestEnglishWords?UserID=' + app.globalData.userInfo.UserID + '&Words=' + wordStr, function (data) {
  803. if (data) {
  804. var result = {};
  805. result.ID = userTestReportInfo.ID;
  806. result.IsFinished = userTestReportInfo.IsFinished;
  807. result.Name = userTestReportInfo.Name.join("#");
  808. result.TestType = userTestReportInfo.TestType;
  809. result.BookID = bookid;
  810. var TaskList = [];
  811. var words = data;
  812. for (var k = 0; k < words.length; k++) {
  813. var taskInfo = words[k];
  814. taskInfo.TagWidth = 364;
  815. taskInfo.ContentNew = changeStringToView(taskInfo.Content);
  816. if (tempRight.indexOf("," + taskInfo.Word + ",") >= 0)
  817. taskInfo.Result = 1;
  818. if (tempWrong.indexOf("," + taskInfo.Word + ",") >= 0)
  819. taskInfo.Result = -1;
  820. if (tempSkip.indexOf("," + taskInfo.Word + ",") >= 0)
  821. taskInfo.Result = 0;
  822. if (tempExist.indexOf("," + taskInfo.Word + ",") >= 0)
  823. taskInfo.Css = "Select2";
  824. TaskList.push(taskInfo);
  825. }
  826. result.TestRightStr = "";
  827. result.TestWrongStr = "";
  828. result.TestSkipStr = "";
  829. result.TestExistStr = "";
  830. if (userTestReportInfo.TestRightStr)
  831. result.TestRightStr = userTestReportInfo.TestRightStr;
  832. if (userTestReportInfo.TestWrongStr)
  833. result.TestWrongStr = userTestReportInfo.TestWrongStr;
  834. if (userTestReportInfo.TestSkipStr)
  835. result.TestSkipStr = userTestReportInfo.TestSkipStr;
  836. if (userTestReportInfo.TestExistStr)
  837. result.TestExistStr = userTestReportInfo.TestExistStr;
  838. result.List = TaskList;
  839. callback(result);
  840. } else {
  841. callback({});
  842. }
  843. });
  844. } else {
  845. name1 = name1[0] + "识字能力" + name1[2].substr(0, 1);
  846. var HanziAll = wx.getStorageSync('HanziAll');
  847. HanziAll = JSON.parse(HanziAll);
  848. for (var i = 0; i < HanziAll.length; i++) {
  849. if (name1 == HanziAll[i].Name) {
  850. for (var j = 0; j < HanziAll[i].Units.length; j++) {
  851. if (name2 == HanziAll[i].Units[j].Name) {
  852. var obj = UserTestReport[n];
  853. GetHanziUnitWords(HanziAll[i].Units[j].ID, obj.TestType, function (list) {
  854. if (list) {
  855. for (var k = 0; k < list.length; k++) {
  856. if (obj.TestRightStr && obj.TestRightStr.indexOf(list[k].Word) >= 0)
  857. list[k].Result = 1;
  858. else if (obj.TestWrongStr && obj.TestWrongStr.indexOf(list[k].Word) >= 0)
  859. list[k].Result = -1;
  860. else if (obj.TestSkipStr && obj.TestSkipStr.indexOf(list[k].Word) >= 0)
  861. list[k].Result = 0;
  862. if (obj.TestExistStr && obj.TestExistStr.indexOf(list[k].Word) >= 0)
  863. list[k].Css = "Select2";
  864. }
  865. var result = {};
  866. result.ID = reportid;
  867. result.TestType = obj.TestType;
  868. result.Name = obj.Name.join("#");
  869. result.IsFinished = obj.IsFinished;
  870. result.TestRightStr = obj.TestRightStr;
  871. result.TestWrongStr = obj.TestWrongStr;
  872. result.TestSkipStr = obj.TestSkipStr;
  873. result.TestExistStr = obj.TestExistStr;
  874. result.List = list;
  875. callback(result);
  876. } else
  877. callback({});
  878. });
  879. }
  880. }
  881. }
  882. }
  883. }
  884. }
  885. }
  886. }
  887. function getDetailColor(index) {
  888. var arrDetailColor = constant.arrDetailColor;
  889. if (index > 0)
  890. return arrDetailColor[index];
  891. else if (index == 0)
  892. return arrDetailColor[common.random(1, arr.length - 1)];
  893. else if (index == -1)
  894. return arrDetailColor;
  895. }
  896. function getShareImageBackColor() {
  897. var arr = constant.arrShareImageBackColor;
  898. return arr[common.random(0, arr.length - 1)];
  899. }
  900. function getPinyinNormal(pinyin) {
  901. var result = "";
  902. var arr = constant.arrPinyin;
  903. for (var i = 0; i < arr.length; i++) {
  904. if (arr[i][1] == pinyin) {
  905. result = arr[i][0];
  906. break;
  907. }
  908. }
  909. return result;
  910. }
  911. function getHanzi(callback) {
  912. var that = this;
  913. wx.showLoading({
  914. title: '请稍候',
  915. mask: true,
  916. });
  917. var time = wx.getStorageSync("HanziUpdateTime");
  918. getData('GetHanziAll?HasEnglish=true&UpdateTime=' + time, function (data) {
  919. wx.hideLoading();
  920. if (data) {
  921. var arr = [];
  922. if (data.List) {
  923. arr = common.Decrypt(data.List);
  924. wx.setStorageSync("HanziAll", arr);
  925. var arrEng = common.Decrypt(data.EngList);
  926. wx.setStorageSync("EnglishAll", arrEng);
  927. wx.setStorageSync("HanziUpdateTime", data.UpdateTime);
  928. } else {
  929. arr = wx.getStorageSync("HanziAll");
  930. if (arr)
  931. arr = JSON.parse(arr);
  932. }
  933. callback(arr);
  934. }
  935. });
  936. }
  937. function UploadUserConfig(callback) {
  938. var that = this;
  939. var param1 = {};
  940. param1.CardType = wx.getStorageSync("CardType");
  941. param1.CardMaxNumberNew = wx.getStorageSync("CardMaxNumberNew");
  942. param1.CardMaxNumberHistory = wx.getStorageSync("CardMaxNumberHistory");
  943. param1.CardMaxNumberNewUrgent = wx.getStorageSync("CardMaxNumberNewUrgent");
  944. param1.CardMaxNumberHistoryUrgent = wx.getStorageSync("CardMaxNumberHistoryUrgent");
  945. param1.SortTypeIndex = wx.getStorageSync("SortTypeIndex");
  946. param1.MemoryLevel = wx.getStorageSync("MemoryLevel");
  947. param1.ClickType = wx.getStorageSync("ClickType");
  948. param1.SecondConfigArray = wx.getStorageSync("SecondConfigArray").join(",");
  949. param1.ColorIndexArr = wx.getStorageSync("ColorIndexArr").join(",");
  950. var symboMain = wx.getStorageSync("SymbolMain");
  951. var symbol1 = [];
  952. for (var i = 0; i < symboMain.length; i++) {
  953. symbol1.push(symboMain[i].Name);
  954. }
  955. symbol1 = JSON.stringify(symbol1);
  956. param1.SymbolList = symbol1;
  957. that.postData('UploadUserConfig?Type=update&UserID=' + app.globalData.userInfo.UserID, param1, function (data) {
  958. if (callback) {
  959. callback();
  960. }
  961. });
  962. }
  963. function getUserConfig() {
  964. var that = this;
  965. postData('UploadUserConfig?Type=getData&UserID=' + app.globalData.userInfo.UserID, {}, function (data) {
  966. if (!data.CardType)
  967. data.CardType=0;
  968. wx.setStorageSync("CardType", data.CardType);
  969. wx.setStorageSync("CardMaxNumberNew", data.CardMaxNumberNew);
  970. wx.setStorageSync("CardMaxNumberHistory", data.CardMaxNumberHistory);
  971. wx.setStorageSync("CardMaxNumberNewUrgent", data.CardMaxNumberNewUrgent);
  972. wx.setStorageSync("CardMaxNumberHistoryUrgent", data.CardMaxNumberHistoryUrgent);
  973. wx.setStorageSync("SortTypeIndex", data.SortTypeIndex);
  974. wx.setStorageSync("MemoryLevel", data.MemoryLevel);
  975. wx.setStorageSync("ClickType", data.ClickType);
  976. wx.setStorageSync("SecondConfigArray", data.SecondConfigArray.split(","));
  977. wx.setStorageSync("ColorIndexArr", data.ColorIndexArr.split(","));
  978. var symbol1 = [];
  979. if (data.SymbolList) {
  980. for (var i = 0; i < data.SymbolList.length; i++) {
  981. var obj = {};
  982. obj.Name = data.SymbolList[i];
  983. obj.CSS = "btn2";
  984. symbol1.push(obj);
  985. }
  986. }
  987. else {
  988. symbol1 = app.globalData.SymbolMain;
  989. }
  990. wx.setStorageSync("SymboMain", symbol1);
  991. app.globalData.SymbolMain=symbol1;
  992. });
  993. }
  994. module.exports = {
  995. getData: getData,
  996. postData: postData,
  997. payMoney: payMoney,
  998. getLocalHost: getLocalHost,
  999. getTimeFormat: getTimeFormat,
  1000. getWindowHeight: getWindowHeight,
  1001. getStorageValue: getStorageValue,
  1002. getProgramList: getProgramList,
  1003. gotoFeedback: gotoFeedback,
  1004. getDetailColor: getDetailColor,
  1005. changeStringToView: changeStringToView,
  1006. changeViewToString: changeViewToString,
  1007. encryptUrl: EncryptUrl,
  1008. decryptUrl: DecryptUrl,
  1009. saveTempImage: saveTempImage,
  1010. getTempImage: getTempImage,
  1011. getTaskTodayList: getTaskTodayList,
  1012. updateSearchList: updateSearchList,
  1013. checkIsIPhoneX: checkIsIPhoneX,
  1014. getMemoryLevelAll: getMemoryLevelAll,
  1015. getMemoryLevel: getMemoryLevel,
  1016. getShareImageBackColor: getShareImageBackColor,
  1017. UpdateMiaoguoCardTodayAll: UpdateMiaoguoCardTodayAll,
  1018. setCollect: setCollect,
  1019. UploadUserConfig: UploadUserConfig,
  1020. getServerImage: getServerImage,
  1021. getBaiduToken: getBaiduToken,
  1022. buildInitData: buildInitData,
  1023. getPinyinNormal: getPinyinNormal,
  1024. getHanzi: getHanzi,
  1025. GetHanziUnitWords: GetHanziUnitWords,
  1026. GetTestReportInfo: GetTestReportInfo,
  1027. getUserConfig: getUserConfig
  1028. }