main.js 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136
  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. icon:'none',
  635. });
  636. } else {
  637. wx.showToast({
  638. title: '收藏已取消',
  639. icon:'none',
  640. });
  641. }
  642. getData("UpdateMiaoguoCardInfo?UserID=" + app.globalData.userInfo.UserID + "&MiaoguoCardID=" + id + "&IsCollect=" + collect, function (data) {
  643. if (callback)
  644. callback();
  645. });
  646. }
  647. function buildInitData(callback) {
  648. var that = this;
  649. wx.showLoading({
  650. title: '数据初始化',
  651. });
  652. setTimeout(function () {
  653. wx.hideLoading();
  654. }, 5000);
  655. getData('BuildInitData?UserID=' + app.globalData.userInfo.UserID, function (data) {
  656. wx.hideLoading();
  657. if (data) {
  658. if (callback)
  659. callback();
  660. }
  661. });
  662. }
  663. function getMemoryLevelAll() {
  664. return constant.arrMemoryLevelAll;
  665. }
  666. function getMemoryLevel(index, number, time) {
  667. var arr = getMemoryLevelAll();
  668. if (index < 1)
  669. return arr[index].Value[number].Name;
  670. else
  671. return replaceStr(time);
  672. function replaceStr(data) {
  673. var result = "";
  674. if (data.indexOf("d") > 0) {
  675. var dayNum = Number(data.replace("d", ""));
  676. if (dayNum >= 365) {
  677. var year1 = Math.floor(dayNum / 365);
  678. var year = year1 + Math.round(10 * (dayNum - year1 * 365) / 365) / 10;
  679. result = year + "年后";
  680. } else {
  681. if (dayNum > 31) {
  682. var month1 = Math.floor(dayNum / 30);
  683. var month = month1 + Math.round(10 * (dayNum - month1 * 30) / 30) / 10;
  684. result = month + "月后";
  685. } else {
  686. result = Number(data.replace("d", ""));
  687. if (result == 1)
  688. result = "明天";
  689. else if (result == 2)
  690. result = "后天";
  691. else
  692. result = (result - 1) + "天后";
  693. }
  694. }
  695. } else if (data.indexOf("m") > 0)
  696. result = data.replace("m", "分钟内");
  697. return result;
  698. }
  699. }
  700. //得到要检验的汉字列表
  701. function GetHanziUnitWords(unitsID, testType, callback) {
  702. getData('GetHanziUnitWords?UnitID=' + unitsID, function (data) {
  703. if (data) {
  704. var TaskList = [];
  705. var words = data;
  706. for (var k = 0; k < words.length; k++) {
  707. var taskInfo = {
  708. FontSize: 144,
  709. TagWidth: 136,
  710. Content: [{
  711. ContentType: 0,
  712. Content: []
  713. },
  714. {
  715. ContentType: 1,
  716. Content: []
  717. },
  718. {
  719. ContentType: 2,
  720. Content: []
  721. },
  722. ]
  723. };
  724. taskInfo.Word = words[k].Name;
  725. var pinyinNormal = "(" + getPinyinNormal(words[k].Pinyin) + ")";
  726. var combineWords = common.ReplaceAllString(words[k].CombineWords, words[k].Name, words[k].Name + pinyinNormal);
  727. taskInfo.ReadString = words[k].Name + pinyinNormal + "," + combineWords + "的" + words[k].Name + pinyinNormal;
  728. if (testType == "read") {
  729. taskInfo.Content[0].Content = ["怎么念"];
  730. var question = words[k].CombineWords;
  731. question = common.ReplaceAllString(question, words[k].Name, "(" + words[k].Name + ")");
  732. taskInfo.Content[1].Content = question;
  733. var answer = "[读 src='" + taskInfo.ReadString + "']" + words[k].Pinyin + "[/读]";
  734. taskInfo.Content[2].Content = answer;
  735. if (words[k].CombineWords.length > 6) {
  736. taskInfo.FontSize = 108;
  737. if (words[k].CombineWords.length > 10) {
  738. taskInfo.FontSize = 68;
  739. }
  740. }
  741. } else if (testType == "write") {
  742. taskInfo.Content[0].Content = ["怎么写"];
  743. var question = words[k].CombineWords;
  744. var question2 = common.ReplaceAllString(question, words[k].Name, words[k].Pinyin);
  745. question = "[读 src='" + taskInfo.ReadString + "']" + question2 + "[/读]"
  746. taskInfo.Content[1].Content = question;
  747. var answer = words[k].Name;
  748. answer += "[图 w='650' h='650']" + words[k].BiShunUrl + "[/图]";
  749. taskInfo.Content[2].Content = answer;
  750. if (question2.length > 6) {
  751. taskInfo.FontSize = 108;
  752. if (question2.length > 10) {
  753. taskInfo.FontSize = 68;
  754. if (question2.length > 14) {
  755. taskInfo.FontSize = 48;
  756. }
  757. }
  758. }
  759. }
  760. taskInfo.ContentNew = changeStringToView(taskInfo.Content);
  761. TaskList.push(taskInfo);
  762. }
  763. callback(TaskList);
  764. } else {
  765. callback([]);
  766. }
  767. });
  768. }
  769. function GetTestReportInfo(reportid, callback) {
  770. var UserTestReport = wx.getStorageSync('UserTestReport');
  771. for (var n = 0; n < UserTestReport.length; n++) {
  772. if (UserTestReport[n].ID == reportid) {
  773. var name1 = UserTestReport[n].Name[0].split(" ");
  774. var name2 = UserTestReport[n].Name[1];
  775. if (name1[0].indexOf("英语") >= 0) {
  776. //todo
  777. //console.log("英语");
  778. var arrEnglist = wx.getStorageSync("EnglishAll");
  779. if (arrEnglist)
  780. arrEnglist = JSON.parse(arrEnglist);
  781. else
  782. arrEnglist = [];
  783. var wordStr = "";
  784. for (var i = 0; i < arrEnglist.length; i++) {
  785. if (arrEnglist[i].Name == name1[1]) {
  786. for (var j = 0; j < arrEnglist[i].Units.length; j++) {
  787. if (arrEnglist[i].Units[j].Name == name2) {
  788. wordStr = arrEnglist[i].Units[j].Words.join(",");
  789. break;
  790. }
  791. }
  792. }
  793. }
  794. var userTestReportInfo = UserTestReport[n];
  795. var bookid = Number(name1[1].substr(4)) + 12;
  796. var tempRight = "," + userTestReportInfo.TestRightStr + ",";
  797. var tempWrong = "," + userTestReportInfo.TestWrongStr + ",";
  798. var tempSkip = "," + userTestReportInfo.TestSkipStr + ",";
  799. var tempExist = "," + userTestReportInfo.TestExistStr + ",";
  800. getData('GetTestEnglishWords?UserID=' + app.globalData.userInfo.UserID + '&Words=' + wordStr, function (data) {
  801. if (data) {
  802. var result = {};
  803. result.ID = userTestReportInfo.ID;
  804. result.IsFinished = userTestReportInfo.IsFinished;
  805. result.Name = userTestReportInfo.Name.join("#");
  806. result.TestType = userTestReportInfo.TestType;
  807. result.BookID = bookid;
  808. var TaskList = [];
  809. var words = data;
  810. for (var k = 0; k < words.length; k++) {
  811. var taskInfo = words[k];
  812. taskInfo.TagWidth = 364;
  813. taskInfo.ContentNew = changeStringToView(taskInfo.Content);
  814. if (tempRight.indexOf("," + taskInfo.Word + ",") >= 0)
  815. taskInfo.Result = 1;
  816. if (tempWrong.indexOf("," + taskInfo.Word + ",") >= 0)
  817. taskInfo.Result = -1;
  818. if (tempSkip.indexOf("," + taskInfo.Word + ",") >= 0)
  819. taskInfo.Result = 0;
  820. if (tempExist.indexOf("," + taskInfo.Word + ",") >= 0)
  821. taskInfo.Css = "Select2";
  822. TaskList.push(taskInfo);
  823. }
  824. result.TestRightStr = "";
  825. result.TestWrongStr = "";
  826. result.TestSkipStr = "";
  827. result.TestExistStr = "";
  828. if (userTestReportInfo.TestRightStr)
  829. result.TestRightStr = userTestReportInfo.TestRightStr;
  830. if (userTestReportInfo.TestWrongStr)
  831. result.TestWrongStr = userTestReportInfo.TestWrongStr;
  832. if (userTestReportInfo.TestSkipStr)
  833. result.TestSkipStr = userTestReportInfo.TestSkipStr;
  834. if (userTestReportInfo.TestExistStr)
  835. result.TestExistStr = userTestReportInfo.TestExistStr;
  836. result.List = TaskList;
  837. callback(result);
  838. } else {
  839. callback({});
  840. }
  841. });
  842. } else {
  843. name1 = name1[0] + name1[1].substr(2, 2)+"能力" + name1[2].substr(0, 1);
  844. var HanziAll = wx.getStorageSync('HanziAll');
  845. HanziAll = JSON.parse(HanziAll);
  846. for (var i = 0; i < HanziAll.length; i++) {
  847. if (name1 == HanziAll[i].Name) {
  848. for (var j = 0; j < HanziAll[i].Units.length; j++) {
  849. if (name2 == HanziAll[i].Units[j].Name) {
  850. var obj = UserTestReport[n];
  851. GetHanziUnitWords(HanziAll[i].Units[j].ID, obj.TestType, function (list) {
  852. if (list) {
  853. for (var k = 0; k < list.length; k++) {
  854. if (obj.TestRightStr && obj.TestRightStr.indexOf(list[k].Word) >= 0)
  855. list[k].Result = 1;
  856. else if (obj.TestWrongStr && obj.TestWrongStr.indexOf(list[k].Word) >= 0)
  857. list[k].Result = -1;
  858. else if (obj.TestSkipStr && obj.TestSkipStr.indexOf(list[k].Word) >= 0)
  859. list[k].Result = 0;
  860. if (obj.TestExistStr && obj.TestExistStr.indexOf(list[k].Word) >= 0)
  861. list[k].Css = "Select2";
  862. }
  863. var result = {};
  864. result.ID = reportid;
  865. result.TestType = obj.TestType;
  866. result.Name = obj.Name.join("#");
  867. result.IsFinished = obj.IsFinished;
  868. result.TestRightStr = obj.TestRightStr;
  869. result.TestWrongStr = obj.TestWrongStr;
  870. result.TestSkipStr = obj.TestSkipStr;
  871. result.TestExistStr = obj.TestExistStr;
  872. result.List = list;
  873. callback(result);
  874. } else
  875. callback({});
  876. });
  877. }
  878. }
  879. }
  880. }
  881. }
  882. }
  883. }
  884. }
  885. function getDetailColor(index) {
  886. var arrDetailColor = constant.arrDetailColor;
  887. if (index > 0)
  888. return arrDetailColor[index];
  889. else if (index == 0)
  890. return arrDetailColor[common.random(1, arr.length - 1)];
  891. else if (index == -1)
  892. return arrDetailColor;
  893. }
  894. function getShareImageBackColor() {
  895. var arr = constant.arrShareImageBackColor;
  896. return arr[common.random(0, arr.length - 1)];
  897. }
  898. function getPinyinNormal(pinyin) {
  899. var result = "";
  900. var arr = constant.arrPinyin;
  901. for (var i = 0; i < arr.length; i++) {
  902. if (arr[i][1] == pinyin) {
  903. result = arr[i][0];
  904. break;
  905. }
  906. }
  907. return result;
  908. }
  909. function getHanzi(callback) {
  910. var that = this;
  911. wx.showLoading({
  912. title: '请稍候',
  913. mask: true,
  914. });
  915. var time = wx.getStorageSync("HanziUpdateTime");
  916. getData('GetHanziAll2?HasEnglish=true&HasHanziWrite=true&UpdateTime=' + time, function (data) {
  917. wx.hideLoading();
  918. if (data) {
  919. var arr = [];
  920. if (data.List) {
  921. arr = common.Decrypt(data.List);
  922. wx.setStorageSync("HanziAll", arr);
  923. var arrEng = common.Decrypt(data.EngList);
  924. wx.setStorageSync("EnglishAll", arrEng);
  925. wx.setStorageSync("HanziUpdateTime", data.UpdateTime);
  926. } else {
  927. arr = wx.getStorageSync("HanziAll");
  928. if (arr)
  929. arr = JSON.parse(arr);
  930. }
  931. callback(arr);
  932. }
  933. });
  934. }
  935. function UploadUserConfig(callback) {
  936. var that = this;
  937. var param1 = {};
  938. param1.CardType = wx.getStorageSync("CardType");
  939. param1.CardMaxNumberNew = wx.getStorageSync("CardMaxNumberNew");
  940. param1.CardMaxNumberHistory = wx.getStorageSync("CardMaxNumberHistory");
  941. param1.CardMaxNumberNewUrgent = wx.getStorageSync("CardMaxNumberNewUrgent");
  942. param1.CardMaxNumberHistoryUrgent = wx.getStorageSync("CardMaxNumberHistoryUrgent");
  943. param1.SortTypeIndex = wx.getStorageSync("SortTypeIndex");
  944. param1.MemoryLevel = wx.getStorageSync("MemoryLevel");
  945. param1.ClickType = wx.getStorageSync("ClickType");
  946. param1.SecondConfigArray = wx.getStorageSync("SecondConfigArray").join(",");
  947. param1.ColorIndexArr = wx.getStorageSync("ColorIndexArr").join(",");
  948. var symboMain = wx.getStorageSync("SymbolMain");
  949. var symbol1 = [];
  950. for (var i = 0; i < symboMain.length; i++) {
  951. symbol1.push(symboMain[i].Name);
  952. }
  953. symbol1 = JSON.stringify(symbol1);
  954. param1.SymbolList = symbol1;
  955. that.postData('UploadUserConfig?Type=update&UserID=' + app.globalData.userInfo.UserID, param1, function (data) {
  956. if (callback) {
  957. callback();
  958. }
  959. });
  960. }
  961. function getUserConfig() {
  962. var that = this;
  963. postData('UploadUserConfig?Type=getData&UserID=' + app.globalData.userInfo.UserID, {}, function (data) {
  964. if (!data.CardType)
  965. data.CardType=0;
  966. wx.setStorageSync("CardType", data.CardType);
  967. wx.setStorageSync("CardMaxNumberNew", data.CardMaxNumberNew);
  968. wx.setStorageSync("CardMaxNumberHistory", data.CardMaxNumberHistory);
  969. wx.setStorageSync("CardMaxNumberNewUrgent", data.CardMaxNumberNewUrgent);
  970. wx.setStorageSync("CardMaxNumberHistoryUrgent", data.CardMaxNumberHistoryUrgent);
  971. wx.setStorageSync("SortTypeIndex", data.SortTypeIndex);
  972. wx.setStorageSync("MemoryLevel", data.MemoryLevel);
  973. wx.setStorageSync("ClickType", data.ClickType);
  974. wx.setStorageSync("SecondConfigArray", data.SecondConfigArray.split(","));
  975. wx.setStorageSync("ColorIndexArr", data.ColorIndexArr.split(","));
  976. var symbol1 = [];
  977. if (data.SymbolList) {
  978. for (var i = 0; i < data.SymbolList.length; i++) {
  979. var obj = {};
  980. obj.Name = data.SymbolList[i];
  981. obj.CSS = "btn2";
  982. symbol1.push(obj);
  983. }
  984. }
  985. else {
  986. symbol1 = app.globalData.SymbolMain;
  987. }
  988. wx.setStorageSync("SymboMain", symbol1);
  989. app.globalData.SymbolMain=symbol1;
  990. });
  991. }
  992. module.exports = {
  993. getData: getData,
  994. postData: postData,
  995. payMoney: payMoney,
  996. getLocalHost: getLocalHost,
  997. getTimeFormat: getTimeFormat,
  998. getWindowHeight: getWindowHeight,
  999. getStorageValue: getStorageValue,
  1000. getProgramList: getProgramList,
  1001. gotoFeedback: gotoFeedback,
  1002. getDetailColor: getDetailColor,
  1003. changeStringToView: changeStringToView,
  1004. changeViewToString: changeViewToString,
  1005. encryptUrl: EncryptUrl,
  1006. decryptUrl: DecryptUrl,
  1007. saveTempImage: saveTempImage,
  1008. getTempImage: getTempImage,
  1009. getTaskTodayList: getTaskTodayList,
  1010. updateSearchList: updateSearchList,
  1011. checkIsIPhoneX: checkIsIPhoneX,
  1012. getMemoryLevelAll: getMemoryLevelAll,
  1013. getMemoryLevel: getMemoryLevel,
  1014. getShareImageBackColor: getShareImageBackColor,
  1015. UpdateMiaoguoCardTodayAll: UpdateMiaoguoCardTodayAll,
  1016. setCollect: setCollect,
  1017. UploadUserConfig: UploadUserConfig,
  1018. getServerImage: getServerImage,
  1019. getBaiduToken: getBaiduToken,
  1020. buildInitData: buildInitData,
  1021. getPinyinNormal: getPinyinNormal,
  1022. getHanzi: getHanzi,
  1023. GetHanziUnitWords: GetHanziUnitWords,
  1024. GetTestReportInfo: GetTestReportInfo,
  1025. getUserConfig: getUserConfig
  1026. }