main.js 30 KB

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