main.js 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696
  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 && str.constructor && 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. if (str.substr(0, 1) == "\n")
  243. str = str.substr(1);
  244. }
  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. if (obj.Content.lastIndexOf("fm=58")>=0)
  310. obj.IsShowBishun=true;
  311. else if (obj.Content.indexOf("hanyu-word-gif")>0)
  312. obj.IsShowKaiti=true;
  313. result.Images.push(obj.Content);
  314. }
  315. arrResult.push(obj);
  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 = [],
  319. temp = arr[k];
  320. do {
  321. var num1 = temp.indexOf("[线]");
  322. var num2 = temp.indexOf("[光]");
  323. if (num1 >= 0 || num2 >= 0) {
  324. if ((num1 < num2 && num1 >= 0 && num2 >= 0) || (num1 >= 0 && num2 < 0)) {
  325. var temp1 = temp.substring(0, temp.indexOf("[线]"));
  326. if (temp1) {
  327. content.push({
  328. key: "normal",
  329. value: temp1,
  330. });
  331. } else {
  332. if (temp && temp.indexOf("[线]") < 0) {
  333. content.push({
  334. key: "normal",
  335. value: temp,
  336. });
  337. temp = "";
  338. }
  339. }
  340. } else if ((num1 > num2 && num1 >= 0 && num2 >= 0) || (num1 < 0 && num2 >= 0)) {
  341. var temp1 = temp.substring(0, temp.indexOf("[光]"));
  342. if (temp1) {
  343. content.push({
  344. key: "normal",
  345. value: temp1,
  346. });
  347. } else {
  348. if (temp && temp.indexOf("[光]") < 0) {
  349. content.push({
  350. key: "normal",
  351. value: temp,
  352. });
  353. temp = "";
  354. }
  355. }
  356. } else {
  357. content.push({
  358. key: "normal",
  359. value: temp,
  360. });
  361. temp = "";
  362. }
  363. } else {
  364. content.push({
  365. key: "normal",
  366. value: temp,
  367. });
  368. temp = "";
  369. }
  370. if (temp.length > 0 && (num1 >= 0 || num2 >= 0)) {
  371. if ((num1 < num2 && num1 >= 0 && num2 >= 0) || (num1 >= 0 && num2 < 0)) {
  372. temp = temp.substr(temp.indexOf("[线]") + 3);
  373. temp1 = temp.substring(0, temp.indexOf("[/线]"));
  374. if (temp1) {
  375. content.push({
  376. key: "line",
  377. value: temp1,
  378. });
  379. }
  380. temp = temp.substr(temp.indexOf("[/线]") + 4);
  381. } else if ((num1 > num2 && num1 >= 0 && num2 >= 0) || (num1 < 0 && num2 >= 0)) {
  382. temp = temp.substr(temp.indexOf("[光]") + 3);
  383. temp1 = temp.substring(0, temp.indexOf("[/光]"));
  384. if (temp1) {
  385. content.push({
  386. key: "highlighter",
  387. value: temp1,
  388. });
  389. }
  390. temp = temp.substr(temp.indexOf("[/光]") + 4);
  391. } else
  392. temp = "";
  393. } else
  394. temp = "";
  395. }
  396. while (temp.length > 0);
  397. obj = {};
  398. obj.Type = "line";
  399. obj.Content = content;
  400. arrResult.push(obj);
  401. } else if (arr[k].indexOf("[读") >= 0 && arr[k].indexOf("[/读]") > 0) {
  402. var obj = {};
  403. obj.Type = "sound";
  404. if (arr[k].indexOf("[读]") >= 0) {
  405. obj.Content = arr[k].substring(arr[k].indexOf("[读]") + 3, arr[k].indexOf("[/读]"));
  406. } else {
  407. var tempIndex = arr[k].indexOf("\']") + 2;
  408. obj.Content = arr[k].substring(tempIndex, arr[k].indexOf("[/读]"));
  409. obj.SoundMark = arr[k].substring(arr[k].indexOf("src='") + 5, arr[k].indexOf("']"));;
  410. }
  411. arrResult.push(obj);
  412. } else if (arr[k].indexOf("[音") >= 0 && arr[k].indexOf("[/音]") > 0) {
  413. var obj = {};
  414. obj.Type = "recorder";
  415. var tempIndex = arr[k].indexOf("\']") + 2;
  416. //obj.Content = arr[k].substring(tempIndex, arr[k].indexOf("[/音]"));
  417. obj.SoundMark = arr[k].substring(arr[k].indexOf("url='") + 5, arr[k].indexOf("']"));;
  418. arrResult.push(obj);
  419. } else if (arr[k] != "") {
  420. var obj = {};
  421. obj.Type = "normal";
  422. obj.Content = arr[k];
  423. arrResult.push(obj);
  424. } else if (k > 0 && arr[k] == "") {
  425. var obj = {};
  426. obj.Type = "br";
  427. obj.Content = "";
  428. arrResult.push(obj);
  429. }
  430. var obj = {};
  431. obj.Type = "return";
  432. arrResult.push(obj);
  433. }
  434. //去掉前回车换行
  435. // while (arrResult[0].Type == "return" ||
  436. // arrResult[0].Type == "br") {
  437. // arrResult.shift();
  438. // if (arrResult.length == 0)
  439. // break;
  440. // }
  441. //去掉后回车换行
  442. for (var i = arrResult.length - 1; i >= 0; i--) {
  443. if (arrResult[i].Type == "return" ||
  444. arrResult[i].Type == "br")
  445. arrResult.pop();
  446. else {
  447. break;
  448. }
  449. }
  450. result.Field.push(arrResult);
  451. } else {
  452. result.Field.push([]);
  453. }
  454. }
  455. }
  456. return result;
  457. }
  458. //得到当天任务
  459. function getTaskTodayList(callback) {
  460. var isNotData = true;
  461. var intervalTask = setTimeout(function () {
  462. if (isNotData) {
  463. wx.showLoading({
  464. title: '请稍候',
  465. mask: true,
  466. });
  467. setTimeout(function () {
  468. wx.hideLoading();
  469. }, 60000);
  470. }
  471. }, 2000);
  472. var that = this;
  473. var url = 'GetMiaoguoCardToday2?UserID=' + app.globalData.userInfo.UserID;
  474. getData(url, function (data) {
  475. clearTimeout(intervalTask);
  476. if (isNotData) {
  477. wx.hideLoading();
  478. }
  479. isNotData = false;
  480. if (data) {
  481. app.globalData.TaskToday = data;
  482. callback(data);
  483. }
  484. });
  485. }
  486. function getTempImage(serverUrl) {
  487. if (serverUrl.indexOf("miaguo-1253256735") >= 0) {
  488. var list = wx.getStorageSync("TempImageList");
  489. if (!list)
  490. list = [];
  491. for (var i = 0; i < list.length; i++) {
  492. if (list[i].ServerUrl == serverUrl) {
  493. return list[i].TempUrl;
  494. break;
  495. }
  496. }
  497. }
  498. return serverUrl;
  499. }
  500. function getServerImage(tempUrl) {
  501. if (tempUrl.indexOf("http") < 0) {
  502. var list = wx.getStorageSync("TempImageList");
  503. if (!list)
  504. list = [];
  505. for (var i = 0; i < list.length; i++) {
  506. if (list[i].TempUrl == tempUrl) {
  507. return list[i].ServerUrl;
  508. break;
  509. }
  510. }
  511. return ""
  512. }
  513. }
  514. function saveTempImage(serverUrl, tempUrl) {
  515. if (tempUrl.indexOf("http") < 0) {
  516. var list = wx.getStorageSync("TempImageList");
  517. if (!list)
  518. list = [];
  519. var b = false;
  520. for (var i = 0; i < list.length; i++) {
  521. if (list[i].ServerUrl == serverUrl) {
  522. list[i].TempUrl = tempUrl;
  523. b = true;
  524. break;
  525. }
  526. }
  527. if (!b) {
  528. list.push({
  529. "ServerUrl": serverUrl,
  530. "TempUrl": tempUrl
  531. });
  532. }
  533. if (list.length > 200) {
  534. list.pop();
  535. }
  536. wx.setStorageSync("TempImageList", list);
  537. }
  538. }
  539. function UpdateMiaoguoCardTodayAll(isShowLoading, callback) {
  540. var that = this;
  541. if (isShowLoading) {
  542. wx.showLoading({
  543. title: '请稍候',
  544. mask: true,
  545. });
  546. clearTimeout(dataSendTimeout);
  547. dataSendTimeout = setTimeout(function () {
  548. wx.hideLoading();
  549. wx.reLaunch({
  550. url: '../index/index',
  551. })
  552. }, 60000);
  553. }
  554. var list = wx.getStorageSync("ListTaskFinished");
  555. if (list && list.length > 0) {
  556. var arr = [];
  557. for (var i = 0; i < list.length; i++) {
  558. var obj = {};
  559. obj.MiaoguoCardID = list[i].Card.MiaoguoCardID;
  560. obj.IntervalTime = list[i].IntervalTime;
  561. obj.BtnNumber = list[i].BtnNumber;
  562. obj.FontSize = list[i].Card.FontSize;
  563. obj.Duration = list[i].Duration;
  564. obj.LearningType = list[i].LearningType;
  565. obj.IsCollect = list[i].Card.IsCollect;
  566. obj.LastTime = list[i].LastTime;
  567. arr.push(obj);
  568. }
  569. that.postData('UpdateMiaoguoCardTodayAll?UserID=' + app.globalData.userInfo.UserID, {
  570. List: arr,
  571. }, function (data) {
  572. if (isShowLoading) {
  573. wx.hideLoading();
  574. clearTimeout(dataSendTimeout);
  575. }
  576. if (data) {
  577. wx.removeStorageSync("ListTaskFinished");
  578. }
  579. if (callback) {
  580. callback();
  581. }
  582. });
  583. } else {
  584. wx.hideLoading();
  585. clearTimeout(dataSendTimeout);
  586. if (callback) {
  587. callback();
  588. }
  589. }
  590. }
  591. function updateSearchList(obj,callback) {
  592. var arr = wx.getStorageSync("SearchWord3");
  593. if (!arr)
  594. arr = [];
  595. if (obj && obj.Type && obj.Type == "shici") {
  596. if (obj.Value.CHN.ShiciTitle)
  597. obj.Key = obj.Value.CHN.ShiciTitle;
  598. if (obj.Key.indexOf("《") == 0)
  599. obj.Key = obj.Key.substring(1, obj.Key.length - 1);
  600. }
  601. for (var i = 0; i < arr.length; i++) {
  602. if (obj.Key && arr[i].Key == obj.Key) {
  603. if (obj.Type == "shici") {
  604. if (arr[i].ShiciUrl == obj.ShiciUrl) {
  605. obj.Value = arr[i].Value;
  606. arr.splice(i, 1);
  607. break;
  608. }
  609. } else {
  610. var b=true;
  611. if (obj.Type && arr[i].Type && arr[i].Type != obj.Type)
  612. b=false;
  613. if (obj.Author && arr[i].Author && arr[i].Author != obj.Author)
  614. b=false;
  615. if (b){
  616. obj.Value = arr[i].Value;
  617. arr.splice(i, 1);
  618. break;
  619. }
  620. }
  621. }
  622. }
  623. if (obj.Key)
  624. arr.unshift(obj);
  625. if (arr.length > 30) {
  626. arr.pop();
  627. }
  628. wx.setStorageSync("SearchWord3", arr);
  629. app.globalData.SearchItem = obj.Value;
  630. if (obj.TypeName)
  631. app.globalData.SearchItem.TypeName = obj.TypeName;
  632. if (callback)
  633. callback();
  634. }
  635. function checkIsIPhoneX() {
  636. var isIphoneX = false;
  637. if (app.globalData.systemInfo.model.indexOf("iPhone X") >= 0 ||
  638. app.globalData.systemInfo.model.indexOf("iPhone X") >= 0) {
  639. isIphoneX = true;
  640. }
  641. return isIphoneX;
  642. }
  643. //设置收藏
  644. function setCollect(id, collect, callback) {
  645. var that = this;
  646. if (collect) {
  647. wx.showToast({
  648. title: '加注成功',
  649. image: '../images/universalpic_star_white_120x120.png',
  650. });
  651. } else {
  652. wx.showToast({
  653. title: '清除成功',
  654. image: '../images/universalpic_star_whiteline_120x120.png',
  655. });
  656. }
  657. getData("UpdateMiaoguoCardInfo?UserID=" + app.globalData.userInfo.UserID + "&MiaoguoCardID=" + id + "&IsCollect=" + collect, function (data) {
  658. if (callback)
  659. callback();
  660. });
  661. }
  662. function buildInitData(callback) {
  663. var that = this;
  664. wx.showLoading({
  665. title: '数据初始化',
  666. });
  667. setTimeout(function () {
  668. wx.hideLoading();
  669. }, 5000);
  670. getData('BuildInitData?UserID=' + app.globalData.userInfo.UserID, function (data) {
  671. wx.hideLoading();
  672. if (data) {
  673. if (callback)
  674. callback();
  675. }
  676. });
  677. }
  678. function getMemoryLevelAll() {
  679. return constant.arrMemoryLevelAll;
  680. }
  681. function getMemoryLevel(index, number, time) {
  682. var arr = getMemoryLevelAll();
  683. if (index < 1)
  684. return arr[index].Value[number].Name;
  685. else
  686. return replaceStr(time);
  687. function replaceStr(data) {
  688. var result = "";
  689. if (data.indexOf("d") > 0) {
  690. var dayNum = Number(data.replace("d", ""));
  691. if (dayNum >= 365) {
  692. var year1 = Math.floor(dayNum / 365);
  693. var year = year1 + Math.round(10 * (dayNum - year1 * 365) / 365) / 10;
  694. result = year + "年后";
  695. } else {
  696. if (dayNum > 31) {
  697. var month1 = Math.floor(dayNum / 30);
  698. var month = month1 + Math.round(10 * (dayNum - month1 * 30) / 30) / 10;
  699. result = month + "月后";
  700. } else {
  701. result = Number(data.replace("d", ""));
  702. if (result == 1)
  703. result = "明天";
  704. else if (result == 2)
  705. result = "后天";
  706. else
  707. result = (result - 1) + "天后";
  708. }
  709. }
  710. } else if (data.indexOf("m") > 0)
  711. result = data.replace("m", "分钟内");
  712. return result;
  713. }
  714. }
  715. //得到要检验的汉字列表
  716. function GetHanziUnitWords(unitsID, testType, callback) {
  717. var url='GetHanziUnitWords?UnitID=' + unitsID;
  718. if (testType)
  719. url+="&TestType="+testType;
  720. getData(url, function (data) {
  721. if (data) {
  722. var TaskList = [];
  723. var words = data;
  724. //若是单字
  725. if (words[0].Pinyin){
  726. for (var k = 0; k < words.length; k++) {
  727. var taskInfo = {
  728. FontSize: 144,
  729. TagWidth: 136,
  730. Content: [{
  731. ContentType: 0,
  732. Content: []
  733. },
  734. {
  735. ContentType: 1,
  736. Content: []
  737. },
  738. {
  739. ContentType: 2,
  740. Content: []
  741. },
  742. ]
  743. };
  744. taskInfo.Word = words[k].Name;
  745. var pinyinNormal = "(" + getPinyinNormal(words[k].Pinyin) + ")";
  746. var combineWords = common.ReplaceAllString(words[k].CombineWords, words[k].Name, words[k].Name + pinyinNormal);
  747. taskInfo.ReadString = words[k].Name + pinyinNormal + "," + combineWords + "的" + words[k].Name + pinyinNormal;
  748. if (testType == "read") {
  749. taskInfo.Content[0].Content = ["怎么念"];
  750. var question = words[k].CombineWords;
  751. question = common.ReplaceAllString(question, words[k].Name, "(" + words[k].Name + ")");
  752. taskInfo.Content[1].Content = question;
  753. var answer = "[读 src='" + taskInfo.ReadString + "']" + words[k].Pinyin + "[/读]";
  754. taskInfo.Content[2].Content = answer;
  755. if (words[k].CombineWords.length > 6) {
  756. taskInfo.FontSize = 108;
  757. if (words[k].CombineWords.length > 10) {
  758. taskInfo.FontSize = 68;
  759. }
  760. }
  761. } else if (testType == "write") {
  762. taskInfo.Content[0].Content = ["怎么写"];
  763. var question = words[k].CombineWords;
  764. var question2 = common.ReplaceAllString(question, words[k].Name, words[k].Pinyin);
  765. question = "[读 src='" + taskInfo.ReadString + "']" + question2 + "[/读]"
  766. taskInfo.Content[1].Content = question;
  767. var answer = words[k].Name;
  768. answer += "[图 w='650' h='650']" + words[k].BiShunUrl + "[/图]";
  769. taskInfo.Content[2].Content = answer;
  770. if (question2.length > 6) {
  771. taskInfo.FontSize = 108;
  772. if (question2.length > 10) {
  773. taskInfo.FontSize = 68;
  774. if (question2.length > 14) {
  775. taskInfo.FontSize = 48;
  776. }
  777. }
  778. }
  779. }
  780. taskInfo.ContentNew = changeStringToView(taskInfo.Content);
  781. TaskList.push(taskInfo);
  782. }
  783. }
  784. else{ //若是词语
  785. for (var k = 0; k < words.length; k++) {
  786. var taskInfo = words[k];
  787. taskInfo.ContentNew = changeStringToView(taskInfo.Content);
  788. TaskList.push(taskInfo);
  789. }
  790. }
  791. callback(TaskList);
  792. } else {
  793. callback([]);
  794. }
  795. });
  796. }
  797. function GetTestReportInfo(reportid, callback) {
  798. var UserTestReport = wx.getStorageSync('UserTestReport');
  799. for (var n = 0; n < UserTestReport.length; n++) {
  800. if (UserTestReport[n].ID == reportid) {
  801. var name1 = UserTestReport[n].Name[0].split(" ");
  802. var name2 = UserTestReport[n].Name[1];
  803. if (name1[0].indexOf("英语") >= 0) {
  804. //console.log("英语");
  805. var wordStr = "";
  806. var userTestReportInfo = UserTestReport[n];
  807. var bookid = userTestReportInfo.BookID;
  808. var arrEnglist = [];
  809. if (bookid<110){
  810. if (name1[1]=="英文字母"){
  811. bookid=100;
  812. wordStr="A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z";
  813. }
  814. }
  815. else if (bookid>110 && bookid<120){
  816. arrEnglist = wx.getStorageSync("EnglishAll");
  817. arrEnglist = JSON.parse(arrEnglist);
  818. for (var i = 0; i < arrEnglist.length; i++) {
  819. if (arrEnglist[i].Name == name1[1]) {
  820. for (var j = 0; j < arrEnglist[i].Units.length; j++) {
  821. if (arrEnglist[i].Units[j].Name == name2) {
  822. wordStr = arrEnglist[i].Units[j].Words.join(",");
  823. break;
  824. }
  825. }
  826. }
  827. }
  828. }
  829. var tempRight = "," + userTestReportInfo.TestRightStr + ",";
  830. var tempWrong = "," + userTestReportInfo.TestWrongStr + ",";
  831. var tempSkip = "," + userTestReportInfo.TestSkipStr + ",";
  832. var tempExist = "," + userTestReportInfo.TestExistStr + ",";
  833. var unitsid="";
  834. if (bookid>100 && bookid<110 && UserTestReport[n].Name[2]){
  835. unitsid=Number(UserTestReport[n].Name[2]);
  836. }
  837. else if (bookid>120 && bookid<=124){
  838. unitsid=Number(name2.replace("Lesson ",""));
  839. }
  840. else if (bookid>130 && bookid<=140 && UserTestReport[n].Name[2]){
  841. unitsid=Number(UserTestReport[n].Name[2]);
  842. }
  843. getData('GetTestEnglishWords?UserID=' + app.globalData.userInfo.UserID+'&BookID='+bookid+'&LessonID='+unitsid+ '&Words=' + wordStr+"&TestType="+userTestReportInfo.TestType, function (data) {
  844. if (data) {
  845. var result = {};
  846. result.ID = userTestReportInfo.ID;
  847. result.IsFinished = userTestReportInfo.IsFinished;
  848. result.Name = userTestReportInfo.Name.join("#");
  849. result.TestType = userTestReportInfo.TestType;
  850. result.BookID = bookid;
  851. var TaskList = [];
  852. var words = data;
  853. for (var k = 0; k < words.length; k++) {
  854. var taskInfo = words[k];
  855. if (userTestReportInfo.TestType=="read"){
  856. taskInfo.TagWidth=212;
  857. taskInfo.FontSize=108;
  858. }
  859. else{
  860. taskInfo.TagWidth=186;
  861. taskInfo.FontSize=36;
  862. }
  863. taskInfo.ContentNew = changeStringToView(taskInfo.Content);
  864. if (tempRight.indexOf("," + taskInfo.Word + ",") >= 0)
  865. taskInfo.Result = 1;
  866. if (tempWrong.indexOf("," + taskInfo.Word + ",") >= 0)
  867. taskInfo.Result = -1;
  868. if (tempSkip.indexOf("," + taskInfo.Word + ",") >= 0)
  869. taskInfo.Result = 0;
  870. if (tempExist.indexOf("," + taskInfo.Word + ",") >= 0)
  871. taskInfo.Css = "Select2";
  872. TaskList.push(taskInfo);
  873. }
  874. result.TestRightStr = "";
  875. result.TestWrongStr = "";
  876. result.TestSkipStr = "";
  877. result.TestExistStr = "";
  878. if (userTestReportInfo.TestRightStr)
  879. result.TestRightStr = userTestReportInfo.TestRightStr;
  880. if (userTestReportInfo.TestWrongStr)
  881. result.TestWrongStr = userTestReportInfo.TestWrongStr;
  882. if (userTestReportInfo.TestSkipStr)
  883. result.TestSkipStr = userTestReportInfo.TestSkipStr;
  884. if (userTestReportInfo.TestExistStr)
  885. result.TestExistStr = userTestReportInfo.TestExistStr;
  886. result.List = TaskList;
  887. callback(result);
  888. } else {
  889. callback({});
  890. }
  891. });
  892. }
  893. else if (name1[1].indexOf("拼音") >= 0) {
  894. //console.log("拼音");
  895. var userTestReportInfo = UserTestReport[n];
  896. var bookid = userTestReportInfo.BookID;
  897. var tempRight = "," + userTestReportInfo.TestRightStr + ",";
  898. var tempWrong = "," + userTestReportInfo.TestWrongStr + ",";
  899. var tempSkip = "," + userTestReportInfo.TestSkipStr + ",";
  900. var tempExist = "," + userTestReportInfo.TestExistStr + ",";
  901. var unitsid="";
  902. var name2=userTestReportInfo.Name[1];
  903. if (bookid==43){
  904. switch(name2){
  905. case "声母1":
  906. unitsid=431;
  907. break;
  908. case "声母2":
  909. unitsid=432;
  910. break;
  911. case "声母3":
  912. unitsid=433;
  913. break;
  914. case "韵母1":
  915. unitsid=434;
  916. break;
  917. case "韵母2":
  918. unitsid=435;
  919. break;
  920. case "韵母3":
  921. unitsid=436;
  922. break;
  923. case "整体认读1":
  924. unitsid=437;
  925. break;
  926. case "整体认读2":
  927. unitsid=438;
  928. break;
  929. }
  930. }
  931. getData('GetPinyinUnitWords?UserID='+app.globalData.userInfo.UserID+'&BookID='+bookid+'&UnitID='+unitsid+'&Word='+name2, function (data) {
  932. if (data) {
  933. var result = {};
  934. result.ID = userTestReportInfo.ID;
  935. result.IsFinished = userTestReportInfo.IsFinished;
  936. result.Name = userTestReportInfo.Name.join("#");
  937. result.TestType = userTestReportInfo.TestType;
  938. result.BookID = bookid;
  939. var TaskList = [];
  940. var words = data;
  941. for (var k = 0; k < words.length; k++) {
  942. var taskInfo = words[k];
  943. taskInfo.TagWidth=230;
  944. taskInfo.FontSize=108;
  945. taskInfo.ContentNew = changeStringToView(taskInfo.Content);
  946. if (tempRight.indexOf("," + taskInfo.Word + ",") >= 0)
  947. taskInfo.Result = 1;
  948. if (tempWrong.indexOf("," + taskInfo.Word + ",") >= 0)
  949. taskInfo.Result = -1;
  950. if (tempSkip.indexOf("," + taskInfo.Word + ",") >= 0)
  951. taskInfo.Result = 0;
  952. if (tempExist.indexOf("," + taskInfo.Word + ",") >= 0)
  953. taskInfo.Css = "Select2";
  954. TaskList.push(taskInfo);
  955. }
  956. result.TestRightStr = "";
  957. result.TestWrongStr = "";
  958. result.TestSkipStr = "";
  959. result.TestExistStr = "";
  960. if (userTestReportInfo.TestRightStr)
  961. result.TestRightStr = userTestReportInfo.TestRightStr;
  962. if (userTestReportInfo.TestWrongStr)
  963. result.TestWrongStr = userTestReportInfo.TestWrongStr;
  964. if (userTestReportInfo.TestSkipStr)
  965. result.TestSkipStr = userTestReportInfo.TestSkipStr;
  966. if (userTestReportInfo.TestExistStr)
  967. result.TestExistStr = userTestReportInfo.TestExistStr;
  968. result.List = TaskList;
  969. callback(result);
  970. } else {
  971. callback({});
  972. }
  973. });
  974. }
  975. else if (name2=="古诗文") {
  976. //todo
  977. //console.log("古诗文");
  978. var userTestReportInfo = UserTestReport[n];
  979. var tempRight = "," + userTestReportInfo.TestRightStr + ",";
  980. var tempWrong = "," + userTestReportInfo.TestWrongStr + ",";
  981. var tempSkip = "," + userTestReportInfo.TestSkipStr + ",";
  982. var tempExist = "," + userTestReportInfo.TestExistStr + ",";
  983. getData('GetTestAncientPoetryList?UserID=' + app.globalData.userInfo.UserID + '&BookID=' + userTestReportInfo.BookID, function (data) {
  984. if (data) {
  985. var result = {};
  986. result.ID = userTestReportInfo.ID;
  987. result.IsFinished = userTestReportInfo.IsFinished;
  988. result.Name = userTestReportInfo.Name.join("#");
  989. result.TestType = userTestReportInfo.TestType;
  990. result.BookID = userTestReportInfo.BookID;
  991. var TaskList = [];
  992. for (var k = 0; k < data.length; k++) {
  993. var taskInfo = data[k];
  994. taskInfo.TagWidth=336;
  995. if (taskInfo.Word.length>9)
  996. taskInfo.FontSize=48;
  997. else
  998. taskInfo.FontSize=64;
  999. taskInfo.ContentNew = changeStringToView(taskInfo.Content);
  1000. if (tempRight.indexOf("," + taskInfo.Word + ",") >= 0)
  1001. taskInfo.Result = 1;
  1002. if (tempWrong.indexOf("," + taskInfo.Word + ",") >= 0)
  1003. taskInfo.Result = -1;
  1004. if (tempSkip.indexOf("," + taskInfo.Word + ",") >= 0)
  1005. taskInfo.Result = 0;
  1006. if (tempExist.indexOf("," + taskInfo.Word + ",") >= 0)
  1007. taskInfo.Css = "Select2";
  1008. TaskList.push(taskInfo);
  1009. }
  1010. result.TestRightStr = "";
  1011. result.TestWrongStr = "";
  1012. result.TestSkipStr = "";
  1013. result.TestExistStr = "";
  1014. if (userTestReportInfo.TestRightStr)
  1015. result.TestRightStr = userTestReportInfo.TestRightStr;
  1016. if (userTestReportInfo.TestWrongStr)
  1017. result.TestWrongStr = userTestReportInfo.TestWrongStr;
  1018. if (userTestReportInfo.TestSkipStr)
  1019. result.TestSkipStr = userTestReportInfo.TestSkipStr;
  1020. if (userTestReportInfo.TestExistStr)
  1021. result.TestExistStr = userTestReportInfo.TestExistStr;
  1022. result.List = TaskList;
  1023. callback(result);
  1024. } else {
  1025. callback({});
  1026. }
  1027. });
  1028. }
  1029. else {
  1030. var obj = UserTestReport[n];
  1031. if (obj.BookID>=43 && obj.BookID<=60)
  1032. name1 = name1[0] + "生词" + name1[2].substr(0, 1);
  1033. else
  1034. name1 = name1[0] + name1[1].substr(2, 2) + "能力" + name1[2].substr(0, 1);
  1035. var HanziAll = wx.getStorageSync('HanziAll');
  1036. HanziAll = JSON.parse(HanziAll);
  1037. for (var i = 0; i < HanziAll.length; i++) {
  1038. if (name1 == HanziAll[i].Name) {
  1039. for (var j = 0; j < HanziAll[i].Units.length; j++) {
  1040. if (name2 == HanziAll[i].Units[j].Name) {
  1041. GetHanziUnitWords(HanziAll[i].Units[j].ID, obj.TestType, function (list) {
  1042. if (list) {
  1043. for (var k = 0; k < list.length; k++) {
  1044. if (obj.TestRightStr && obj.TestRightStr.indexOf(list[k].Word) >= 0)
  1045. list[k].Result = 1;
  1046. else if (obj.TestWrongStr && obj.TestWrongStr.indexOf(list[k].Word) >= 0)
  1047. list[k].Result = -1;
  1048. else if (obj.TestSkipStr && obj.TestSkipStr.indexOf(list[k].Word) >= 0)
  1049. list[k].Result = 0;
  1050. if (obj.TestExistStr && obj.TestExistStr.indexOf(list[k].Word) >= 0)
  1051. list[k].Css = "Select2";
  1052. }
  1053. var result = {};
  1054. result.ID = reportid;
  1055. result.BookID=obj.BookID;
  1056. result.TestType = obj.TestType;
  1057. result.Name = obj.Name.join("#");
  1058. result.IsFinished = obj.IsFinished;
  1059. result.TestRightStr = obj.TestRightStr;
  1060. result.TestWrongStr = obj.TestWrongStr;
  1061. result.TestSkipStr = obj.TestSkipStr;
  1062. result.TestExistStr = obj.TestExistStr;
  1063. result.List = list;
  1064. callback(result);
  1065. } else
  1066. callback({});
  1067. });
  1068. }
  1069. }
  1070. }
  1071. }
  1072. }
  1073. }
  1074. }
  1075. }
  1076. function getDetailColor(index) {
  1077. var arrDetailColor = constant.arrDetailColor;
  1078. if (index > 0)
  1079. return arrDetailColor[index];
  1080. else if (index == 0)
  1081. return arrDetailColor[common.random(1, arrDetailColor.length - 1)];
  1082. else if (index == -1)
  1083. return arrDetailColor;
  1084. }
  1085. function getShareImageBackColor() {
  1086. var arr = constant.arrShareImageBackColor;
  1087. return arr[common.random(0, arr.length - 1)];
  1088. }
  1089. function getPinyinNormal(pinyin) {
  1090. var result = "";
  1091. var arr = constant.arrPinyin;
  1092. for (var i = 0; i < arr.length; i++) {
  1093. if (arr[i][1] == pinyin) {
  1094. result = arr[i][0];
  1095. break;
  1096. }
  1097. }
  1098. return result;
  1099. }
  1100. function getHanzi(callback) {
  1101. var that = this;
  1102. wx.showLoading({
  1103. title: '请稍候',
  1104. mask: true,
  1105. });
  1106. var time = wx.getStorageSync("HanziUpdateTime");
  1107. getData('GetHanziAll2?HasEnglish=true&HasHanziWrite=true&UpdateTime=' + time, function (data) {
  1108. wx.hideLoading();
  1109. if (data) {
  1110. var arr = [];
  1111. if (data.List) {
  1112. arr = common.Decrypt(data.List);
  1113. wx.setStorageSync("HanziAll", arr);
  1114. var arrEng = common.Decrypt(data.EngList);
  1115. var arrNewConceptEngList = common.Decrypt(data.NewConceptEngList);
  1116. var arrCambridgeEngList = common.Decrypt(data.CambridgeEngList);
  1117. var arrPhoneticEngList = common.Decrypt(data.PhoneticEngList);
  1118. wx.setStorageSync("EnglishAll", arrEng);
  1119. wx.setStorageSync("NewConceptEngList", arrNewConceptEngList);
  1120. wx.setStorageSync("CambridgeEngList", arrCambridgeEngList);
  1121. wx.setStorageSync("PhoneticEngList", arrPhoneticEngList);
  1122. wx.setStorageSync("HanziUpdateTime", data.UpdateTime);
  1123. } else {
  1124. arr = wx.getStorageSync("HanziAll");
  1125. if (arr)
  1126. arr = JSON.parse(arr);
  1127. }
  1128. callback(arr);
  1129. }
  1130. });
  1131. }
  1132. function UploadUserConfig(callback) {
  1133. var that = this;
  1134. var param1 = {};
  1135. param1.CardType = wx.getStorageSync("CardType");
  1136. param1.CardMaxNumberNew = wx.getStorageSync("CardMaxNumberNew");
  1137. param1.CardMaxNumberHistory = wx.getStorageSync("CardMaxNumberHistory");
  1138. param1.CardMaxNumberNewUrgent = wx.getStorageSync("CardMaxNumberNewUrgent");
  1139. param1.CardMaxNumberHistoryUrgent = wx.getStorageSync("CardMaxNumberHistoryUrgent");
  1140. param1.SortTypeIndex = wx.getStorageSync("SortTypeIndex");
  1141. param1.MemoryLevel = wx.getStorageSync("MemoryLevel");
  1142. param1.ClickType = wx.getStorageSync("ClickType");
  1143. param1.SecondConfigArray = wx.getStorageSync("SecondConfigArray").join(",");
  1144. param1.ColorIndexArr = wx.getStorageSync("ColorIndexArr").join(",");
  1145. param1.IsFolderPractice = wx.getStorageSync("IsFolderPractice");
  1146. param1.IsAutoSound = wx.getStorageSync("IsAutoSound");
  1147. var symboMain = wx.getStorageSync("SymbolMain");
  1148. var symbol1 = [];
  1149. for (var i = 0; i < symboMain.length; i++) {
  1150. symbol1.push(symboMain[i].Name);
  1151. }
  1152. symbol1 = JSON.stringify(symbol1);
  1153. param1.SymbolList = symbol1;
  1154. var folderOrder=wx.getStorageSync("FolderOrderStr");
  1155. if (folderOrder)
  1156. param1.FolderOrder = folderOrder;
  1157. //console.log(param1);
  1158. that.postData('UploadUserConfig?Type=update&UserID=' + app.globalData.userInfo.UserID, param1, function (data) {
  1159. if (callback) {
  1160. callback();
  1161. }
  1162. });
  1163. }
  1164. function getAwardData(callback) {
  1165. var that = this;
  1166. that.getData('GetAwardInfo?UserID=' + app.globalData.userInfo.UserID, function (data) {
  1167. if (data) {
  1168. callback(data);
  1169. } else
  1170. callback([]);
  1171. });
  1172. }
  1173. function getUserConfig() {
  1174. var that = this;
  1175. postData('UploadUserConfig?Type=getData&UserID=' + app.globalData.userInfo.UserID, {}, function (data) {
  1176. if (data && !data.CardType)
  1177. data.CardType = 0;
  1178. wx.setStorageSync("CardType", data.CardType);
  1179. wx.setStorageSync("CardMaxNumberNew", data.CardMaxNumberNew);
  1180. wx.setStorageSync("CardMaxNumberHistory", data.CardMaxNumberHistory);
  1181. wx.setStorageSync("CardMaxNumberNewUrgent", data.CardMaxNumberNewUrgent);
  1182. wx.setStorageSync("CardMaxNumberHistoryUrgent", data.CardMaxNumberHistoryUrgent);
  1183. wx.setStorageSync("SortTypeIndex", data.SortTypeIndex);
  1184. wx.setStorageSync("MemoryLevel", data.MemoryLevel);
  1185. wx.setStorageSync("ClickType", data.ClickType);
  1186. wx.setStorageSync("SecondConfigArray", data.SecondConfigArray.split(","));
  1187. wx.setStorageSync("ColorIndexArr", data.ColorIndexArr.split(","));
  1188. wx.setStorageSync("FolderOrderStr", data.FolderOrder);
  1189. wx.setStorageSync("IsFolderPractice", data.IsFolderPractice);
  1190. wx.setStorageSync("IsAutoSound", data.IsAutoSound);
  1191. var symbol1 = [];
  1192. if (data.SymbolList) {
  1193. for (var i = 0; i < data.SymbolList.length; i++) {
  1194. var obj = {};
  1195. obj.Name = data.SymbolList[i];
  1196. obj.CSS = "btn2";
  1197. symbol1.push(obj);
  1198. }
  1199. } else {
  1200. symbol1 = app.globalData.SymbolMain;
  1201. }
  1202. if (symbol1.length>0){
  1203. wx.setStorageSync("SymboMain", symbol1);
  1204. app.globalData.SymbolMain = symbol1;
  1205. }
  1206. });
  1207. }
  1208. function replaceCardInfoString(str) {
  1209. var that = this;
  1210. //str = str.replace(/\[图]/g, "");
  1211. //str = str.replace(/\[\/图\]/g, "");
  1212. var str2 = "";
  1213. if (str.indexOf("[读 src=") >= 0) {
  1214. str2 = str.substr(str.indexOf("[读 src="));
  1215. str2 = str2.substring(0, str2.indexOf("/读]") + 3);
  1216. }
  1217. str = str.replace(str2, "");
  1218. if (str.indexOf("[读 src=") >= 0) {
  1219. str2 = str.substr(str.indexOf("[读 src"));
  1220. str2 = str2.substring(0, str2.indexOf("/读]") + 3);
  1221. }
  1222. str = str.replace(str2, "");
  1223. str = str.replace(/\[读]/g, "");
  1224. str = str.replace(/\[\/读\]/g, "");
  1225. var str3 = "";
  1226. if (str.indexOf("[图") >= 0) {
  1227. str3 = str.substr(str.indexOf("[图"));
  1228. str3 = str3.substring(0, str3.indexOf("/图]") + 3);
  1229. }
  1230. str = str.replace(str3, "");
  1231. if (str.indexOf("[图") >= 0) {
  1232. str3 = str.substr(str.indexOf("[图"));
  1233. str3 = str3.substring(0, str3.indexOf("/图]") + 3);
  1234. }
  1235. str = str.replace(str3, "");
  1236. str = str.replace(/\[线]/g, "");
  1237. str = str.replace(/\[\/线\]/g, "");
  1238. str = that.encryptUrl(str);
  1239. return str;
  1240. }
  1241. function searchInfomation(search,searchtype,author,shiciurl,callback){
  1242. var WORD_LENGTH=18;
  1243. wx.showLoading({
  1244. title: '查询中',
  1245. });
  1246. var timeout=setTimeout(function () {
  1247. wx.hideLoading();
  1248. }, 5000);
  1249. var url = 'GetMiaoguoAISearch2?UserID=' + app.globalData.userInfo.UserID;
  1250. url += "&Word=" + encodeURI(search);
  1251. if (searchtype)
  1252. url += "&SearchType=" + searchtype;
  1253. if (author)
  1254. url += "&Author=" + encodeURI(author);
  1255. if (shiciurl)
  1256. url += "&ShiciUrl=" + shiciurl;
  1257. getData(url, function (data) {
  1258. wx.hideLoading();
  1259. clearTimeout(timeout);
  1260. if (data) {
  1261. //console.log(data);
  1262. if (data.List) {
  1263. var len = WORD_LENGTH;
  1264. var list = data.List;
  1265. for (var i = 0; i < list.length; i++) {
  1266. var item = list[i];
  1267. if (item.TypeName == "字词") {
  1268. if (item.Key.length == 1)
  1269. item.TypeName = "Z";
  1270. else
  1271. item.TypeName = "C";
  1272. } else if (item.TypeName == "诗词") {
  1273. item.TypeName = "S";
  1274. item.Remark = item.Author + " " + item.Dynasty;
  1275. } else if (item.TypeName == "翻译") {
  1276. item.TypeName = "D";
  1277. }
  1278. if (item.Content && item.Content.length > len)
  1279. item.Content = item.Content.substr(0, len) + "...";
  1280. }
  1281. callback(list);
  1282. } else if (data.CHN || data.ENG) {
  1283. var obj = {};
  1284. obj.Key = search;
  1285. obj.Value = data;
  1286. if (data.CHN && data.CHN.Author)
  1287. obj.Author = data.CHN.Author;
  1288. if (data.CHN && data.CHN.Dynasty)
  1289. obj.Dynasty = data.CHN.Dynasty;
  1290. if (data.CHN && data.CHN.PeomContent) {
  1291. obj.Type = "shici";
  1292. obj.TypeName = "诗词";
  1293. obj.Content = data.CHN.PeomContent.join("").substr(0, WORD_LENGTH);
  1294. obj.ShiciUrl = shiciurl;
  1295. obj.TypeName="S";
  1296. } else if (data.CHN) {
  1297. obj.Type = "zici";
  1298. if (data.CHN.PinYin && data.CHN.PinYin[0] && data.CHN.PinYin[0].pinyin)
  1299. obj.Remark = data.CHN.PinYin[0].pinyin;
  1300. if (data.CHN.PinYin && data.CHN.PinYin[0] && data.CHN.PinYin[0].explain) {
  1301. obj.Content = data.CHN.PinYin[0].explain.substr(0, WORD_LENGTH);
  1302. obj.Content = obj.Content.replace("<p>", "");
  1303. obj.Content = obj.Content.replace("</p>", "");
  1304. if (obj.Content.length >= WORD_LENGTH)
  1305. obj.Content += "..."
  1306. }
  1307. if (obj.Key.length == 1)
  1308. obj.TypeName = "Z";
  1309. else
  1310. obj.TypeName = "C";
  1311. }
  1312. if (data.ENG && !data.CHN) {
  1313. obj.Type = "eng";
  1314. obj.TypeName = "D";
  1315. if (data.ENG.Soundmark && data.ENG.Soundmark.Eng)
  1316. obj.Remark = data.ENG.Soundmark.Eng;
  1317. if (data.ENG.Paraphrase.length > 0) {
  1318. if (common.checkIsArray(data.ENG.Paraphrase) && data.ENG.Paraphrase[0].ParaphraseList)
  1319. obj.Content = data.ENG.Paraphrase[0].ParaphraseList.join("; ").substr(0, WORD_LENGTH);
  1320. else
  1321. obj.Content = data.ENG.Paraphrase.substr(0, WORD_LENGTH) + "...";
  1322. }
  1323. }
  1324. app.globalData.TempSearchBackNumber = 2;
  1325. //app.globalData.CardList=[];
  1326. app.globalData.CardList2=[];
  1327. callback([],obj);
  1328. }
  1329. else{
  1330. callback([]);
  1331. }
  1332. } else {
  1333. callback([]);
  1334. }
  1335. });
  1336. }
  1337. function downloadBishunKaitiImage(url,serverUrl,dataType,Fields,callback){
  1338. var param={};
  1339. param.Url=url;
  1340. param.DataType=dataType;
  1341. if (param.Url==serverUrl){
  1342. postData("GetBiShunByKaitiUrl",param, function (data) {
  1343. if (data) {
  1344. wx.downloadFile({
  1345. url: data, // 仅为示例,并非真实的资源
  1346. success(res) {
  1347. // 只要服务器有响应数据,就会把响应内容写入文件并进入 success 回调,业务需要自行判断是否下载到了想要的内容
  1348. if (res.statusCode === 200) {
  1349. //console.log("serverUrl2:" + serverUrl);
  1350. console.log(res.tempFilePath);
  1351. callback(change(Fields,res.tempFilePath,param));
  1352. }
  1353. },
  1354. complete(){
  1355. }
  1356. });
  1357. }
  1358. });
  1359. }
  1360. else{
  1361. callback(change(Fields,serverUrl,param));
  1362. }
  1363. function change(Fields,filepath,param){
  1364. var iStart=0;
  1365. if (Fields.length==4)
  1366. iStart=1
  1367. for (var i = iStart; i < Fields.length; i++) {
  1368. for (var j = 0; j < Fields[i].length; j++) {
  1369. if (Fields[i][j].Type == "image") {
  1370. if (Fields[i][j].Content==param.Url){
  1371. Fields[i][j].Content = filepath;
  1372. if (param.DataType=="bishun"){
  1373. Fields[i][j].IsShowKaiti=true;
  1374. Fields[i][j].IsShowBishun=false;
  1375. }
  1376. else if (param.DataType=="kaiti"){
  1377. Fields[i][j].IsShowKaiti=false;
  1378. Fields[i][j].IsShowBishun=true;
  1379. }
  1380. }
  1381. }
  1382. }
  1383. }
  1384. return Fields;
  1385. }
  1386. }
  1387. function GetSoundError(str) {
  1388. var arr=constant.arrSoundError;
  1389. var result=str;
  1390. for(var i=0;i<arr.length;i++){
  1391. if (str.indexOf(arr[i].Word)>0){
  1392. result=common.ReplaceAllString(str,arr[i].Word,arr[i].Sound);
  1393. break;
  1394. }
  1395. else if (str==arr[i].Word){
  1396. result=arr[i].Sound;
  1397. }
  1398. }
  1399. return result;
  1400. }
  1401. function GetTestReportList(userID,callback){
  1402. var GradeArr = constant.testGradeArr;
  1403. for (var i = 0; i < GradeArr.length; i++) {
  1404. for (var j = 0; j < GradeArr[i].List.length; j++) {
  1405. GradeArr[i].List[j].Finish = 0;
  1406. }
  1407. }
  1408. getData('GetTestReportList?UserID=' + userID, function (data) {
  1409. if (data) {
  1410. var dataTemp = [];
  1411. for (var i = 0; i < data.length; i++) {
  1412. for (var j = 0; j < dataTemp.length; j++) {
  1413. if (dataTemp[j].Name[0] == data[i].Name[0] &&
  1414. dataTemp[j].Name[1] == data[i].Name[1] &&
  1415. dataTemp[j].TestType == data[i].TestType &&
  1416. data[i].IsFinished == 1
  1417. ) {
  1418. dataTemp.splice(j, 1);
  1419. break;
  1420. }
  1421. }
  1422. dataTemp.push(data[i]);
  1423. if (data[i].Name[0].indexOf("英语")>=0 || data[i].Name[0].indexOf("语文词语")>=0 || data[i].Name[0].indexOf("识字 上学期")>=0 || data[i].Name[0].indexOf("拼音")>=0 || data[i].Name[1].indexOf("古诗文")>=0){
  1424. if (data[i].TestRightStr){
  1425. data[i].TestRightStr=data[i].TestRightStr.split(",");
  1426. }
  1427. if (data[i].TestWrongStr){
  1428. data[i].TestWrongStr=data[i].TestWrongStr.split(",");
  1429. }
  1430. if (data[i].TestSkipStr){
  1431. data[i].TestSkipStr=data[i].TestSkipStr.split(",");
  1432. }
  1433. if (data[i].TestExistStr){
  1434. data[i].TestExistStr=data[i].TestExistStr.split(",");
  1435. }
  1436. }
  1437. if (!data[i].TestRightStr)
  1438. data[i].TestRightStr="";
  1439. if (!data[i].TestWrongStr)
  1440. data[i].TestWrongStr="";
  1441. if (!data[i].TestSkipStr)
  1442. data[i].TestSkipStr="";
  1443. if (!data[i].TestExistStr)
  1444. data[i].TestExistStr="";
  1445. }
  1446. for (var i = 0; i < dataTemp.length; i++) {
  1447. var name = dataTemp[i].Name[0].split(" ");
  1448. for (var j = 0; j < GradeArr.length; j++) {
  1449. var item = GradeArr[j];
  1450. if (name[0] == item.Name) {
  1451. for (var k = 0; k < item.List.length; k++) {
  1452. //音标计算进度
  1453. if (item.List[k].ID==101 && dataTemp[i].BookID==101){
  1454. for(var n=1;n<=4;n++){
  1455. if (Number(dataTemp[i].Name[2])==n && dataTemp[i].IsFinished==1)
  1456. item.List[k].Finish++;
  1457. }
  1458. }
  1459. //古诗词计算进度
  1460. else if (item.List[k].ID==dataTemp[i].BookID && dataTemp[i].TestType=="recite" && dataTemp[i].IsFinished == 1)
  1461. item.List[k].Finish=1;
  1462. else{
  1463. if (name[1] == item.List[k].Name && name[2] == item.List[k].Name2) {
  1464. if (dataTemp[i].IsFinished == 1)
  1465. item.List[k].Finish++;
  1466. }
  1467. }
  1468. }
  1469. }
  1470. }
  1471. }
  1472. for (var j = 0; j < GradeArr.length; j++) {
  1473. var item = GradeArr[j];
  1474. for (var k = 0; k < item.List.length; k++) {
  1475. item.List[k].Finished = Math.round(100 * item.List[k].Finish / item.List[k].Total);
  1476. item.List[k].NameStr=item.List[k].Name.replace("语文","");
  1477. }
  1478. }
  1479. wx.setStorageSync("UserTestReport", data);
  1480. callback(data,GradeArr);
  1481. }
  1482. });
  1483. }
  1484. module.exports = {
  1485. getData: getData,
  1486. postData: postData,
  1487. payMoney: payMoney,
  1488. getLocalHost: getLocalHost,
  1489. getTimeFormat: getTimeFormat,
  1490. getWindowHeight: getWindowHeight,
  1491. getStorageValue: getStorageValue,
  1492. getProgramList: getProgramList,
  1493. gotoFeedback: gotoFeedback,
  1494. getDetailColor: getDetailColor,
  1495. changeStringToView: changeStringToView,
  1496. changeViewToString: changeViewToString,
  1497. encryptUrl: EncryptUrl,
  1498. decryptUrl: DecryptUrl,
  1499. saveTempImage: saveTempImage,
  1500. getTempImage: getTempImage,
  1501. getTaskTodayList: getTaskTodayList,
  1502. updateSearchList: updateSearchList,
  1503. checkIsIPhoneX: checkIsIPhoneX,
  1504. getMemoryLevelAll: getMemoryLevelAll,
  1505. getMemoryLevel: getMemoryLevel,
  1506. getShareImageBackColor: getShareImageBackColor,
  1507. UpdateMiaoguoCardTodayAll: UpdateMiaoguoCardTodayAll,
  1508. setCollect: setCollect,
  1509. UploadUserConfig: UploadUserConfig,
  1510. getServerImage: getServerImage,
  1511. getBaiduToken: getBaiduToken,
  1512. buildInitData: buildInitData,
  1513. getPinyinNormal: getPinyinNormal,
  1514. getHanzi: getHanzi,
  1515. GetHanziUnitWords: GetHanziUnitWords,
  1516. GetTestReportInfo: GetTestReportInfo,
  1517. getUserConfig: getUserConfig,
  1518. getAwardData: getAwardData,
  1519. replaceCardInfoString: replaceCardInfoString,
  1520. searchInfomation:searchInfomation,
  1521. downloadBishunKaitiImage:downloadBishunKaitiImage,
  1522. GetSoundError:GetSoundError,
  1523. GetTestReportList:GetTestReportList,
  1524. }