main.js 34 KB

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