main.js 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109
  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 UploadUserConfig(callback) {
  550. var that = this;
  551. var param1 = {};
  552. param1.CardType = wx.getStorageSync("CardType");
  553. param1.CardMaxNumberNew = wx.getStorageSync("CardMaxNumberNew");
  554. param1.CardMaxNumberHistory = wx.getStorageSync("CardMaxNumberHistory");
  555. param1.CardMaxNumberNewUrgent = wx.getStorageSync("CardMaxNumberNewUrgent");
  556. param1.CardMaxNumberHistoryUrgent = wx.getStorageSync("CardMaxNumberHistoryUrgent");
  557. param1.SortTypeIndex = wx.getStorageSync("SortTypeIndex");
  558. param1.MemoryLevel = wx.getStorageSync("MemoryLevel");
  559. param1.ClickType = wx.getStorageSync("ClickType");
  560. param1.SecondConfigArray = wx.getStorageSync("SecondConfigArray");
  561. param1.ColorIndexArr = wx.getStorageSync("ColorIndexArr");
  562. that.postData('UploadUserConfig?Type=update&UserID=' + app.globalData.userInfo.UserID, param1, function (data) {
  563. if (callback){
  564. callback();
  565. }
  566. });
  567. }
  568. function UpdateMiaoguoCardTodayAll(isShowLoading, callback) {
  569. var that = this;
  570. if (isShowLoading) {
  571. wx.showLoading({
  572. title: '请稍候',
  573. mask: true,
  574. });
  575. clearTimeout(dataSendTimeout);
  576. dataSendTimeout = setTimeout(function () {
  577. wx.hideLoading();
  578. wx.reLaunch({
  579. url: '../index/index',
  580. })
  581. }, 60000);
  582. }
  583. var list = wx.getStorageSync("ListTaskFinished");
  584. if (list && list.length > 0) {
  585. var arr = [];
  586. for (var i = 0; i < list.length; i++) {
  587. var obj = {};
  588. obj.MiaoguoCardID = list[i].Card.MiaoguoCardID;
  589. obj.IntervalTime = list[i].IntervalTime;
  590. obj.BtnNumber = list[i].BtnNumber;
  591. obj.FontSize = list[i].Card.FontSize;
  592. obj.Duration = list[i].Duration;
  593. obj.LearningType = list[i].LearningType;
  594. obj.IsCollect = list[i].Card.IsCollect;
  595. arr.push(obj);
  596. }
  597. that.postData('UpdateMiaoguoCardTodayAll?UserID=' + app.globalData.userInfo.UserID, {
  598. List: arr,
  599. }, function (data) {
  600. if (isShowLoading) {
  601. wx.hideLoading();
  602. clearTimeout(dataSendTimeout);
  603. }
  604. if (data) {
  605. wx.removeStorageSync("ListTaskFinished");
  606. }
  607. if (callback) {
  608. callback();
  609. }
  610. });
  611. } else {
  612. wx.hideLoading();
  613. clearTimeout(dataSendTimeout);
  614. if (callback) {
  615. callback();
  616. }
  617. }
  618. }
  619. function updateSearchList(obj) {
  620. var arr = wx.getStorageSync("SearchWord3");
  621. if (!arr)
  622. arr = [];
  623. if (obj.Type == "shici") {
  624. if (obj.Value.CHN.ShiciTitle)
  625. obj.Key=obj.Value.CHN.ShiciTitle;
  626. if (obj.Key.indexOf("《") == 0)
  627. obj.Key = obj.Key.substring(1, obj.Key.length - 1);
  628. }
  629. for (var i = 0; i < arr.length; i++) {
  630. if (arr[i].Key == obj.Key &&
  631. arr[i].Type == obj.Type &&
  632. arr[i].Author == obj.Author
  633. ) {
  634. if (obj.Type == "shici") {
  635. if (arr[i].ShiciUrl == obj.ShiciUrl) {
  636. obj.Value = arr[i].Value;
  637. arr.splice(i, 1);
  638. break;
  639. }
  640. } else {
  641. obj.Value = arr[i].Value;
  642. arr.splice(i, 1);
  643. break;
  644. }
  645. }
  646. }
  647. if (obj.Key)
  648. arr.unshift(obj);
  649. if (arr.length > 100) {
  650. arr.pop();
  651. }
  652. wx.setStorageSync("SearchWord3", arr);
  653. app.globalData.SearchItem = obj.Value;
  654. }
  655. function checkIsIPhoneX() {
  656. var isIphoneX = false;
  657. if (app.globalData.systemInfo.model.indexOf("iPhone X") >= 0 ||
  658. app.globalData.systemInfo.model.indexOf("iPhone X") >= 0) {
  659. isIphoneX = true;
  660. }
  661. return isIphoneX;
  662. }
  663. //设置收藏
  664. function setCollect(id, collect, callback) {
  665. var that = this;
  666. if (collect) {
  667. wx.showToast({
  668. title: '已收藏',
  669. duration: 2000,
  670. image: "../images/universalpic_fav_white_120x110.png",
  671. });
  672. } else {
  673. wx.showToast({
  674. title: '取消收藏',
  675. duration: 2000,
  676. image: "../images/universalpic_fav_white_120x110.png",
  677. });
  678. }
  679. getData("UpdateMiaoguoCardInfo?UserID=" + app.globalData.userInfo.UserID + "&MiaoguoCardID=" + id + "&IsCollect=" + collect, function (data) {
  680. if (callback)
  681. callback();
  682. });
  683. }
  684. function buildInitData(callback) {
  685. var that = this;
  686. wx.showLoading({
  687. title: '数据初始化',
  688. });
  689. setTimeout(function () {
  690. wx.hideLoading();
  691. }, 5000);
  692. getData('BuildInitData?UserID=' + app.globalData.userInfo.UserID, function (data) {
  693. wx.hideLoading();
  694. if (data) {
  695. if (callback)
  696. callback();
  697. }
  698. });
  699. }
  700. function getMemoryLevelAll() {
  701. return constant.arrMemoryLevelAll;
  702. }
  703. function getMemoryLevel(index, number, time) {
  704. var arr = getMemoryLevelAll();
  705. if (index < 1)
  706. return arr[index].Value[number].Name;
  707. else
  708. return replaceStr(time);
  709. function replaceStr(data) {
  710. var result = "";
  711. if (data.indexOf("d") > 0) {
  712. var dayNum = Number(data.replace("d", ""));
  713. if (dayNum >= 365) {
  714. var year1 = Math.floor(dayNum / 365);
  715. var year = year1 + Math.round(10 * (dayNum - year1 * 365) / 365) / 10;
  716. result = year + "年后";
  717. } else {
  718. if (dayNum > 31) {
  719. var month1 = Math.floor(dayNum / 30);
  720. var month = month1 + Math.round(10 * (dayNum - month1 * 30) / 30) / 10;
  721. result = month + "月后";
  722. } else{
  723. result = Number(data.replace("d", ""));
  724. if (result==1)
  725. result="明天";
  726. else if (result==2)
  727. result="后天";
  728. else
  729. result=(result-1)+"天后";
  730. }
  731. }
  732. } else if (data.indexOf("m") > 0)
  733. result = data.replace("m", "分钟内");
  734. return result;
  735. }
  736. }
  737. //得到要检验的汉字列表
  738. function GetHanziUnitWords(unitsID, testType, callback) {
  739. getData('GetHanziUnitWords?UnitID=' + unitsID, function (data) {
  740. if (data) {
  741. var TaskList = [];
  742. var words = data;
  743. for (var k = 0; k < words.length; k++) {
  744. var taskInfo = {
  745. FontSize: 144,
  746. TagWidth: 136,
  747. Content: [{
  748. ContentType: 0,
  749. Content: []
  750. },
  751. {
  752. ContentType: 1,
  753. Content: []
  754. },
  755. {
  756. ContentType: 2,
  757. Content: []
  758. },
  759. ]
  760. };
  761. taskInfo.Word = words[k].Name;
  762. var pinyinNormal = "(" + getPinyinNormal(words[k].Pinyin) + ")";
  763. var combineWords = common.ReplaceAllString(words[k].CombineWords, words[k].Name, words[k].Name+pinyinNormal);
  764. taskInfo.ReadString = words[k].Name + pinyinNormal + "," + combineWords + "的" + words[k].Name + pinyinNormal;
  765. if (testType == "read") {
  766. taskInfo.Content[0].Content = ["怎么念"];
  767. var question = words[k].CombineWords;
  768. question = common.ReplaceAllString(question, words[k].Name, "(" + words[k].Name + ")");
  769. taskInfo.Content[1].Content = question;
  770. var answer = "[读 src='" + taskInfo.ReadString + "']" + words[k].Pinyin + "[/读]";
  771. taskInfo.Content[2].Content = answer;
  772. if (words[k].CombineWords.length > 6) {
  773. taskInfo.FontSize = 108;
  774. if (words[k].CombineWords.length > 10) {
  775. taskInfo.FontSize = 68;
  776. }
  777. }
  778. } else if (testType == "write") {
  779. taskInfo.Content[0].Content = ["怎么写"];
  780. var question = words[k].CombineWords;
  781. var question2 = common.ReplaceAllString(question, words[k].Name, words[k].Pinyin);
  782. question = "[读 src='" + taskInfo.ReadString + "']" + question2 + "[/读]"
  783. taskInfo.Content[1].Content = question;
  784. var answer = words[k].Name;
  785. answer += "[图 w='650' h='650']" + words[k].BiShunUrl + "[/图]";
  786. taskInfo.Content[2].Content = answer;
  787. if (question2.length > 6) {
  788. taskInfo.FontSize = 108;
  789. if (question2.length > 10) {
  790. taskInfo.FontSize = 68;
  791. if (question2.length > 14) {
  792. taskInfo.FontSize = 48;
  793. }
  794. }
  795. }
  796. }
  797. taskInfo.ContentNew = changeStringToView(taskInfo.Content);
  798. TaskList.push(taskInfo);
  799. }
  800. callback(TaskList);
  801. } else {
  802. callback([]);
  803. }
  804. });
  805. }
  806. function GetTestReportInfo(reportid, callback) {
  807. var UserTestReport = wx.getStorageSync('UserTestReport');
  808. for (var n = 0; n < UserTestReport.length; n++) {
  809. if (UserTestReport[n].ID == reportid) {
  810. var name1 = UserTestReport[n].Name[0].split(" ");
  811. var name2 = UserTestReport[n].Name[1];
  812. if (name1[0].indexOf("英语") >= 0) {
  813. //todo
  814. //console.log("英语");
  815. var arrEnglist = wx.getStorageSync("EnglishAll");
  816. if (arrEnglist)
  817. arrEnglist = JSON.parse(arrEnglist);
  818. else
  819. arrEnglist = [];
  820. var wordStr = "";
  821. for (var i = 0; i < arrEnglist.length; i++) {
  822. if (arrEnglist[i].Name == name1[1]) {
  823. for (var j = 0; j < arrEnglist[i].Units.length; j++) {
  824. if (arrEnglist[i].Units[j].Name == name2) {
  825. wordStr = arrEnglist[i].Units[j].Words.join(",");
  826. break;
  827. }
  828. }
  829. }
  830. }
  831. var userTestReportInfo = UserTestReport[n];
  832. var bookid = Number(name1[1].substr(4)) + 12;
  833. var tempRight = "," + userTestReportInfo.TestRightStr + ",";
  834. var tempWrong = "," + userTestReportInfo.TestWrongStr + ",";
  835. var tempSkip = "," + userTestReportInfo.TestSkipStr + ",";
  836. var tempExist = "," + userTestReportInfo.TestExistStr + ",";
  837. getData('GetTestEnglishWords?UserID=' + app.globalData.userInfo.UserID + '&Words=' + wordStr, function (data) {
  838. if (data) {
  839. var result = {};
  840. result.ID = userTestReportInfo.ID;
  841. result.IsFinished = userTestReportInfo.IsFinished;
  842. result.Name = userTestReportInfo.Name.join("#");
  843. result.TestType = userTestReportInfo.TestType;
  844. result.BookID = bookid;
  845. var TaskList = [];
  846. var words = data;
  847. for (var k = 0; k < words.length; k++) {
  848. var taskInfo = words[k];
  849. taskInfo.TagWidth = 364;
  850. taskInfo.ContentNew = changeStringToView(taskInfo.Content);
  851. if (tempRight.indexOf("," + taskInfo.Word + ",") >= 0)
  852. taskInfo.Result = 1;
  853. if (tempWrong.indexOf("," + taskInfo.Word + ",") >= 0)
  854. taskInfo.Result = -1;
  855. if (tempSkip.indexOf("," + taskInfo.Word + ",") >= 0)
  856. taskInfo.Result = 0;
  857. if (tempExist.indexOf("," + taskInfo.Word + ",") >= 0)
  858. taskInfo.Css = "Select2";
  859. TaskList.push(taskInfo);
  860. }
  861. result.TestRightStr = "";
  862. result.TestWrongStr = "";
  863. result.TestSkipStr = "";
  864. result.TestExistStr = "";
  865. if (userTestReportInfo.TestRightStr)
  866. result.TestRightStr = userTestReportInfo.TestRightStr;
  867. if (userTestReportInfo.TestWrongStr)
  868. result.TestWrongStr = userTestReportInfo.TestWrongStr;
  869. if (userTestReportInfo.TestSkipStr)
  870. result.TestSkipStr = userTestReportInfo.TestSkipStr;
  871. if (userTestReportInfo.TestExistStr)
  872. result.TestExistStr = userTestReportInfo.TestExistStr;
  873. result.List = TaskList;
  874. callback(result);
  875. } else {
  876. callback({});
  877. }
  878. });
  879. } else {
  880. name1 = name1[0] + "识字能力" + name1[2].substr(0, 1);
  881. var HanziAll = wx.getStorageSync('HanziAll');
  882. HanziAll = JSON.parse(HanziAll);
  883. for (var i = 0; i < HanziAll.length; i++) {
  884. if (name1 == HanziAll[i].Name) {
  885. for (var j = 0; j < HanziAll[i].Units.length; j++) {
  886. if (name2 == HanziAll[i].Units[j].Name) {
  887. var obj = UserTestReport[n];
  888. GetHanziUnitWords(HanziAll[i].Units[j].ID, obj.TestType, function (list) {
  889. if (list) {
  890. for (var k = 0; k < list.length; k++) {
  891. if (obj.TestRightStr && obj.TestRightStr.indexOf(list[k].Word) >= 0)
  892. list[k].Result = 1;
  893. else if (obj.TestWrongStr && obj.TestWrongStr.indexOf(list[k].Word) >= 0)
  894. list[k].Result = -1;
  895. else if (obj.TestSkipStr && obj.TestSkipStr.indexOf(list[k].Word) >= 0)
  896. list[k].Result = 0;
  897. if (obj.TestExistStr && obj.TestExistStr.indexOf(list[k].Word) >= 0)
  898. list[k].Css = "Select2";
  899. }
  900. var result = {};
  901. result.ID = reportid;
  902. result.TestType = obj.TestType;
  903. result.Name = obj.Name.join("#");
  904. result.IsFinished = obj.IsFinished;
  905. result.TestRightStr = obj.TestRightStr;
  906. result.TestWrongStr = obj.TestWrongStr;
  907. result.TestSkipStr = obj.TestSkipStr;
  908. result.TestExistStr = obj.TestExistStr;
  909. result.List = list;
  910. callback(result);
  911. } else
  912. callback({});
  913. });
  914. }
  915. }
  916. }
  917. }
  918. }
  919. }
  920. }
  921. }
  922. function getDetailColor(index) {
  923. var arrDetailColor = constant.arrDetailColor;
  924. if (index > 0)
  925. return arrDetailColor[index];
  926. else if (index == 0)
  927. return arrDetailColor[common.random(1, arr.length - 1)];
  928. else if (index == -1)
  929. return arrDetailColor;
  930. }
  931. function getShareImageBackColor() {
  932. var arr = constant.arrShareImageBackColor;
  933. return arr[common.random(0, arr.length - 1)];
  934. }
  935. function getPinyinNormal(pinyin) {
  936. var result = "";
  937. var arr = constant.arrPinyin;
  938. for (var i = 0; i < arr.length; i++) {
  939. if (arr[i][1] == pinyin) {
  940. result = arr[i][0];
  941. break;
  942. }
  943. }
  944. return result;
  945. }
  946. function getHanzi(callback) {
  947. var that = this;
  948. wx.showLoading({
  949. title: '请稍候',
  950. mask: true,
  951. });
  952. var time = wx.getStorageSync("HanziUpdateTime");
  953. getData('GetHanziAll?HasEnglish=true&UpdateTime=' + time, function (data) {
  954. wx.hideLoading();
  955. if (data) {
  956. var arr = [];
  957. if (data.List) {
  958. arr = common.Decrypt(data.List);
  959. wx.setStorageSync("HanziAll", arr);
  960. var arrEng = common.Decrypt(data.EngList);
  961. wx.setStorageSync("EnglishAll", arrEng);
  962. wx.setStorageSync("HanziUpdateTime", data.UpdateTime);
  963. } else {
  964. arr = wx.getStorageSync("HanziAll");
  965. if (arr)
  966. arr = JSON.parse(arr);
  967. }
  968. callback(arr);
  969. }
  970. });
  971. }
  972. module.exports = {
  973. getData: getData,
  974. postData: postData,
  975. payMoney: payMoney,
  976. getLocalHost: getLocalHost,
  977. getTimeFormat: getTimeFormat,
  978. getWindowHeight: getWindowHeight,
  979. getStorageValue: getStorageValue,
  980. getProgramList: getProgramList,
  981. gotoFeedback: gotoFeedback,
  982. getDetailColor: getDetailColor,
  983. changeStringToView: changeStringToView,
  984. changeViewToString: changeViewToString,
  985. encryptUrl: EncryptUrl,
  986. decryptUrl: DecryptUrl,
  987. saveTempImage: saveTempImage,
  988. getTempImage: getTempImage,
  989. getTaskTodayList: getTaskTodayList,
  990. updateSearchList: updateSearchList,
  991. checkIsIPhoneX: checkIsIPhoneX,
  992. getMemoryLevelAll: getMemoryLevelAll,
  993. getMemoryLevel: getMemoryLevel,
  994. getShareImageBackColor: getShareImageBackColor,
  995. UpdateMiaoguoCardTodayAll: UpdateMiaoguoCardTodayAll,
  996. setCollect: setCollect,
  997. UploadUserConfig: UploadUserConfig,
  998. getServerImage: getServerImage,
  999. getBaiduToken: getBaiduToken,
  1000. buildInitData: buildInitData,
  1001. getPinyinNormal: getPinyinNormal,
  1002. getHanzi: getHanzi,
  1003. GetHanziUnitWords: GetHanziUnitWords,
  1004. GetTestReportInfo: GetTestReportInfo
  1005. }