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