main.js 34 KB

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