main.js 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747
  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. }, 60000);
  550. }
  551. var list = wx.getStorageSync("ListTaskFinished");
  552. if (list && list.length > 0) {
  553. var arr = [];
  554. for (var i = 0; i < list.length; i++) {
  555. var obj = {};
  556. obj.MiaoguoCardID = list[i].Card.MiaoguoCardID;
  557. obj.IntervalTime = list[i].IntervalTime;
  558. obj.BtnNumber = list[i].BtnNumber;
  559. obj.FontSize = list[i].Card.FontSize;
  560. obj.Duration = list[i].Duration;
  561. obj.LearningType = list[i].LearningType;
  562. obj.IsCollect = list[i].Card.IsCollect;
  563. obj.LastTime = list[i].LastTime;
  564. arr.push(obj);
  565. }
  566. that.postData('UpdateMiaoguoCardTodayAll?UserID=' + app.globalData.userInfo.UserID, {
  567. List: arr,
  568. }, function (data) {
  569. if (isShowLoading) {
  570. wx.hideLoading();
  571. clearTimeout(dataSendTimeout);
  572. }
  573. if (data) {
  574. wx.removeStorageSync("ListTaskFinished");
  575. }
  576. if (callback) {
  577. callback();
  578. }
  579. });
  580. } else {
  581. wx.hideLoading();
  582. clearTimeout(dataSendTimeout);
  583. if (callback) {
  584. callback();
  585. }
  586. }
  587. }
  588. function updateSearchList(obj, callback) {
  589. var arr = wx.getStorageSync("SearchWord3");
  590. if (!arr)
  591. arr = [];
  592. if (obj && obj.Type && obj.Type == "shici") {
  593. if (obj.Value.CHN.ShiciTitle)
  594. obj.Key = obj.Value.CHN.ShiciTitle;
  595. if (obj.Key.indexOf("《") == 0)
  596. obj.Key = obj.Key.substring(1, obj.Key.length - 1);
  597. }
  598. for (var i = 0; i < arr.length; i++) {
  599. if (obj.Key && arr[i].Key == obj.Key) {
  600. if (obj.Type == "shici") {
  601. if (arr[i].ShiciUrl == obj.ShiciUrl) {
  602. obj.Value = arr[i].Value;
  603. arr.splice(i, 1);
  604. break;
  605. }
  606. } else {
  607. var b = true;
  608. if (obj.Type && arr[i].Type && arr[i].Type != obj.Type)
  609. b = false;
  610. if (obj.Author && arr[i].Author && arr[i].Author != obj.Author)
  611. b = false;
  612. if (b) {
  613. obj.Value = arr[i].Value;
  614. arr.splice(i, 1);
  615. break;
  616. }
  617. }
  618. }
  619. }
  620. if (obj.Key)
  621. arr.unshift(obj);
  622. if (arr.length > 30) {
  623. arr.pop();
  624. }
  625. wx.setStorageSync("SearchWord3", arr);
  626. app.globalData.SearchItem = obj.Value;
  627. if (obj.TypeName)
  628. app.globalData.SearchItem.TypeName = obj.TypeName;
  629. if (callback)
  630. callback();
  631. }
  632. function checkIsIPhoneX() {
  633. var isIphoneX = false;
  634. if (app.globalData.systemInfo.model.indexOf("iPhone X") >= 0 ||
  635. app.globalData.systemInfo.model.indexOf("iPhone X") >= 0) {
  636. isIphoneX = true;
  637. }
  638. return isIphoneX;
  639. }
  640. //设置收藏
  641. function setCollect(id, collect, callback) {
  642. var that = this;
  643. if (collect) {
  644. wx.showToast({
  645. title: '加注成功',
  646. image: '../images/universalpic_star_white_120x120.png',
  647. });
  648. } else {
  649. wx.showToast({
  650. title: '清除成功',
  651. image: '../images/universalpic_star_whiteline_120x120.png',
  652. });
  653. }
  654. getData("UpdateMiaoguoCardInfo?UserID=" + app.globalData.userInfo.UserID + "&MiaoguoCardID=" + id + "&IsCollect=" + collect, function (data) {
  655. if (callback)
  656. callback();
  657. });
  658. }
  659. function buildInitData(callback) {
  660. var that = this;
  661. wx.showLoading({
  662. title: '数据初始化',
  663. });
  664. setTimeout(function () {
  665. wx.hideLoading();
  666. }, 5000);
  667. getData('BuildInitData?UserID=' + app.globalData.userInfo.UserID, function (data) {
  668. wx.hideLoading();
  669. if (data) {
  670. if (callback)
  671. callback();
  672. }
  673. });
  674. }
  675. function getMemoryLevelAll() {
  676. return constant.arrMemoryLevelAll;
  677. }
  678. function getMemoryLevel(index, number, time) {
  679. var arr = getMemoryLevelAll();
  680. if (index < 1)
  681. return arr[index].Value[number].Name;
  682. else
  683. return replaceStr(time);
  684. function replaceStr(data) {
  685. var result = "";
  686. if (data.indexOf("d") > 0) {
  687. var dayNum = Number(data.replace("d", ""));
  688. if (dayNum >= 365) {
  689. var year1 = Math.floor(dayNum / 365);
  690. var year = year1 + Math.round(10 * (dayNum - year1 * 365) / 365) / 10;
  691. result = year + "年后";
  692. } else {
  693. if (dayNum > 31) {
  694. var month1 = Math.floor(dayNum / 30);
  695. var month = month1 + Math.round(10 * (dayNum - month1 * 30) / 30) / 10;
  696. result = month + "月后";
  697. } else {
  698. result = Number(data.replace("d", ""));
  699. if (result == 1)
  700. result = "明天";
  701. else if (result == 2)
  702. result = "后天";
  703. else
  704. result = (result - 1) + "天后";
  705. }
  706. }
  707. } else if (data.indexOf("m") > 0)
  708. result = data.replace("m", "分钟内");
  709. return result;
  710. }
  711. }
  712. //得到要检验的汉字列表
  713. function GetHanziUnitWords(unitsID, testType, callback) {
  714. var url = 'GetHanziUnitWords?UnitID=' + unitsID;
  715. if (testType)
  716. url += "&TestType=" + testType;
  717. getData(url, function (data) {
  718. if (data) {
  719. var TaskList = [];
  720. var words = data;
  721. //若是单字
  722. if (words[0].Pinyin) {
  723. for (var k = 0; k < words.length; k++) {
  724. var taskInfo = {
  725. FontSize: 144,
  726. TagWidth: 136,
  727. Content: [{
  728. ContentType: 0,
  729. Content: []
  730. },
  731. {
  732. ContentType: 1,
  733. Content: []
  734. },
  735. {
  736. ContentType: 2,
  737. Content: []
  738. },
  739. ]
  740. };
  741. taskInfo.Word = words[k].Name;
  742. var pinyinNormal = "(" + getPinyinNormal(words[k].Pinyin) + ")";
  743. var combineWords = common.ReplaceAllString(words[k].CombineWords, words[k].Name, words[k].Name + pinyinNormal);
  744. taskInfo.ReadString = words[k].Name + pinyinNormal + "," + combineWords + "的" + words[k].Name + pinyinNormal;
  745. if (testType == "read") {
  746. taskInfo.Content[0].Content = ["怎么念"];
  747. var question = words[k].CombineWords;
  748. question = common.ReplaceAllString(question, words[k].Name, "(" + words[k].Name + ")");
  749. taskInfo.Content[1].Content = question;
  750. var answer = "[读 src='" + taskInfo.ReadString + "']" + words[k].Pinyin + "[/读]";
  751. taskInfo.Content[2].Content = answer;
  752. if (words[k].CombineWords.length > 6) {
  753. taskInfo.FontSize = 108;
  754. if (words[k].CombineWords.length > 10) {
  755. taskInfo.FontSize = 68;
  756. }
  757. }
  758. } else if (testType == "write") {
  759. taskInfo.Content[0].Content = ["怎么写"];
  760. var question = words[k].CombineWords;
  761. //var question2 = common.ReplaceAllString(question, words[k].Name, words[k].Pinyin);
  762. var question2 = words[k].CombineWords2;
  763. question = "[读 src='" + taskInfo.ReadString + "']" + question2 + "[/读]"
  764. taskInfo.Content[1].Content = question;
  765. var answer = words[k].Name;
  766. answer += "[图 w='650' h='650']" + words[k].BiShunUrl + "[/图]";
  767. taskInfo.Content[2].Content = answer;
  768. if (question2.length > 6) {
  769. taskInfo.FontSize = 108;
  770. if (question2.length > 10) {
  771. taskInfo.FontSize = 68;
  772. if (question2.length > 14) {
  773. taskInfo.FontSize = 48;
  774. }
  775. }
  776. }
  777. }
  778. taskInfo.ContentNew = changeStringToView(taskInfo.Content);
  779. TaskList.push(taskInfo);
  780. }
  781. } else { //若是词语
  782. for (var k = 0; k < words.length; k++) {
  783. var taskInfo = words[k];
  784. taskInfo.ContentNew = changeStringToView(taskInfo.Content);
  785. TaskList.push(taskInfo);
  786. }
  787. }
  788. callback(TaskList);
  789. } else {
  790. callback([]);
  791. }
  792. });
  793. }
  794. function GetTestReportInfo(reportid, callback) {
  795. var UserTestReport = wx.getStorageSync('UserTestReport');
  796. for (var n = 0; n < UserTestReport.length; n++) {
  797. if (UserTestReport[n].ID == reportid) {
  798. var name1 = UserTestReport[n].Name[0].split(" ");
  799. var name2 = UserTestReport[n].Name[1];
  800. if (name1[0].indexOf("英语") >= 0) {
  801. //console.log("英语");
  802. var wordStr = "";
  803. var userTestReportInfo = UserTestReport[n];
  804. var bookid = userTestReportInfo.BookID;
  805. var arrEnglist = [];
  806. if (bookid < 110) {
  807. if (name1[1] == "英文字母") {
  808. bookid = 100;
  809. 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";
  810. }
  811. } else if (bookid > 110 && bookid < 120) {
  812. arrEnglist = wx.getStorageSync("EnglishAll");
  813. arrEnglist = JSON.parse(arrEnglist);
  814. for (var i = 0; i < arrEnglist.length; i++) {
  815. if (arrEnglist[i].Name == name1[1]) {
  816. for (var j = 0; j < arrEnglist[i].Units.length; j++) {
  817. if (arrEnglist[i].Units[j].Name == name2) {
  818. wordStr = arrEnglist[i].Units[j].Words.join(",");
  819. break;
  820. }
  821. }
  822. }
  823. }
  824. }
  825. var tempRight = "," + userTestReportInfo.TestRightStr + ",";
  826. var tempWrong = "," + userTestReportInfo.TestWrongStr + ",";
  827. var tempSkip = "," + userTestReportInfo.TestSkipStr + ",";
  828. var tempExist = "," + userTestReportInfo.TestExistStr + ",";
  829. var unitsid = "";
  830. if (bookid > 100 && bookid < 110 && UserTestReport[n].Name[2]) {
  831. unitsid = Number(UserTestReport[n].Name[2]);
  832. } else if (bookid > 120 && bookid <= 124) {
  833. unitsid = Number(name2.replace("Lesson ", ""));
  834. } else if (bookid > 130 && bookid <= 140 && UserTestReport[n].Name[2]) {
  835. unitsid = Number(UserTestReport[n].Name[2]);
  836. }
  837. getData('GetTestEnglishWords?UserID=' + app.globalData.userInfo.UserID + '&BookID=' + bookid + '&LessonID=' + unitsid + '&Words=' + wordStr + "&TestType=" + userTestReportInfo.TestType, function (data) {
  838. if (data) {
  839. var result = {};
  840. result.ID = userTestReportInfo.ID;
  841. result.IsFinished = userTestReportInfo.IsFinished;
  842. result.Name = userTestReportInfo.Name.join("#");
  843. result.TestType = userTestReportInfo.TestType;
  844. result.BookID = bookid;
  845. var TaskList = [];
  846. var words = data;
  847. for (var k = 0; k < words.length; k++) {
  848. var taskInfo = words[k];
  849. if (userTestReportInfo.TestType == "read") {
  850. taskInfo.TagWidth = 212;
  851. taskInfo.FontSize = 108;
  852. } else {
  853. taskInfo.TagWidth = 186;
  854. taskInfo.FontSize = 36;
  855. }
  856. taskInfo.ContentNew = changeStringToView(taskInfo.Content);
  857. if (tempRight.indexOf("," + taskInfo.Word + ",") >= 0)
  858. taskInfo.Result = 1;
  859. if (tempWrong.indexOf("," + taskInfo.Word + ",") >= 0)
  860. taskInfo.Result = -1;
  861. if (tempSkip.indexOf("," + taskInfo.Word + ",") >= 0)
  862. taskInfo.Result = 0;
  863. if (tempExist.indexOf("," + taskInfo.Word + ",") >= 0)
  864. taskInfo.Css = "Select2";
  865. TaskList.push(taskInfo);
  866. }
  867. result.TestRightStr = "";
  868. result.TestWrongStr = "";
  869. result.TestSkipStr = "";
  870. result.TestExistStr = "";
  871. if (userTestReportInfo.TestRightStr)
  872. result.TestRightStr = userTestReportInfo.TestRightStr;
  873. if (userTestReportInfo.TestWrongStr)
  874. result.TestWrongStr = userTestReportInfo.TestWrongStr;
  875. if (userTestReportInfo.TestSkipStr)
  876. result.TestSkipStr = userTestReportInfo.TestSkipStr;
  877. if (userTestReportInfo.TestExistStr)
  878. result.TestExistStr = userTestReportInfo.TestExistStr;
  879. result.List = TaskList;
  880. callback(result);
  881. } else {
  882. callback({});
  883. }
  884. });
  885. } else if (name1[1].indexOf("拼音") >= 0) {
  886. //console.log("拼音");
  887. var userTestReportInfo = UserTestReport[n];
  888. var bookid = userTestReportInfo.BookID;
  889. var tempRight = "," + userTestReportInfo.TestRightStr + ",";
  890. var tempWrong = "," + userTestReportInfo.TestWrongStr + ",";
  891. var tempSkip = "," + userTestReportInfo.TestSkipStr + ",";
  892. var tempExist = "," + userTestReportInfo.TestExistStr + ",";
  893. var unitsid = "";
  894. var name2 = userTestReportInfo.Name[1];
  895. if (bookid == 43) {
  896. switch (name2) {
  897. case "声母1":
  898. unitsid = 431;
  899. break;
  900. case "声母2":
  901. unitsid = 432;
  902. break;
  903. case "声母3":
  904. unitsid = 433;
  905. break;
  906. case "韵母1":
  907. unitsid = 434;
  908. break;
  909. case "韵母2":
  910. unitsid = 435;
  911. break;
  912. case "韵母3":
  913. unitsid = 436;
  914. break;
  915. case "整体认读1":
  916. unitsid = 437;
  917. break;
  918. case "整体认读2":
  919. unitsid = 438;
  920. break;
  921. }
  922. }
  923. getData('GetPinyinUnitWords?UserID=' + app.globalData.userInfo.UserID + '&BookID=' + bookid + '&UnitID=' + unitsid + '&Word=' + name2, function (data) {
  924. if (data) {
  925. var result = {};
  926. result.ID = userTestReportInfo.ID;
  927. result.IsFinished = userTestReportInfo.IsFinished;
  928. result.Name = userTestReportInfo.Name.join("#");
  929. result.TestType = userTestReportInfo.TestType;
  930. result.BookID = bookid;
  931. var TaskList = [];
  932. var words = data;
  933. for (var k = 0; k < words.length; k++) {
  934. var taskInfo = words[k];
  935. taskInfo.TagWidth = 230;
  936. taskInfo.FontSize = 108;
  937. taskInfo.ContentNew = changeStringToView(taskInfo.Content);
  938. if (tempRight.indexOf("," + taskInfo.Word + ",") >= 0)
  939. taskInfo.Result = 1;
  940. if (tempWrong.indexOf("," + taskInfo.Word + ",") >= 0)
  941. taskInfo.Result = -1;
  942. if (tempSkip.indexOf("," + taskInfo.Word + ",") >= 0)
  943. taskInfo.Result = 0;
  944. if (tempExist.indexOf("," + taskInfo.Word + ",") >= 0)
  945. taskInfo.Css = "Select2";
  946. TaskList.push(taskInfo);
  947. }
  948. result.TestRightStr = "";
  949. result.TestWrongStr = "";
  950. result.TestSkipStr = "";
  951. result.TestExistStr = "";
  952. if (userTestReportInfo.TestRightStr)
  953. result.TestRightStr = userTestReportInfo.TestRightStr;
  954. if (userTestReportInfo.TestWrongStr)
  955. result.TestWrongStr = userTestReportInfo.TestWrongStr;
  956. if (userTestReportInfo.TestSkipStr)
  957. result.TestSkipStr = userTestReportInfo.TestSkipStr;
  958. if (userTestReportInfo.TestExistStr)
  959. result.TestExistStr = userTestReportInfo.TestExistStr;
  960. result.List = TaskList;
  961. callback(result);
  962. } else {
  963. callback({});
  964. }
  965. });
  966. } else if (name2 == "古诗文") {
  967. //todo
  968. //console.log("古诗文");
  969. var userTestReportInfo = UserTestReport[n];
  970. var tempRight = "," + userTestReportInfo.TestRightStr + ",";
  971. var tempWrong = "," + userTestReportInfo.TestWrongStr + ",";
  972. var tempSkip = "," + userTestReportInfo.TestSkipStr + ",";
  973. var tempExist = "," + userTestReportInfo.TestExistStr + ",";
  974. getData('GetTestAncientPoetryList?UserID=' + app.globalData.userInfo.UserID + '&BookID=' + userTestReportInfo.BookID, function (data) {
  975. if (data) {
  976. var result = {};
  977. result.ID = userTestReportInfo.ID;
  978. result.IsFinished = userTestReportInfo.IsFinished;
  979. result.Name = userTestReportInfo.Name.join("#");
  980. result.TestType = userTestReportInfo.TestType;
  981. result.BookID = userTestReportInfo.BookID;
  982. var TaskList = [];
  983. for (var k = 0; k < data.length; k++) {
  984. var taskInfo = data[k];
  985. taskInfo.TagWidth = 336;
  986. if (taskInfo.Word.length > 9)
  987. taskInfo.FontSize = 48;
  988. else
  989. taskInfo.FontSize = 64;
  990. taskInfo.ContentNew = changeStringToView(taskInfo.Content);
  991. if (tempRight.indexOf("," + taskInfo.Word + ",") >= 0)
  992. taskInfo.Result = 1;
  993. if (tempWrong.indexOf("," + taskInfo.Word + ",") >= 0)
  994. taskInfo.Result = -1;
  995. if (tempSkip.indexOf("," + taskInfo.Word + ",") >= 0)
  996. taskInfo.Result = 0;
  997. if (tempExist.indexOf("," + taskInfo.Word + ",") >= 0)
  998. taskInfo.Css = "Select2";
  999. TaskList.push(taskInfo);
  1000. }
  1001. result.TestRightStr = "";
  1002. result.TestWrongStr = "";
  1003. result.TestSkipStr = "";
  1004. result.TestExistStr = "";
  1005. if (userTestReportInfo.TestRightStr)
  1006. result.TestRightStr = userTestReportInfo.TestRightStr;
  1007. if (userTestReportInfo.TestWrongStr)
  1008. result.TestWrongStr = userTestReportInfo.TestWrongStr;
  1009. if (userTestReportInfo.TestSkipStr)
  1010. result.TestSkipStr = userTestReportInfo.TestSkipStr;
  1011. if (userTestReportInfo.TestExistStr)
  1012. result.TestExistStr = userTestReportInfo.TestExistStr;
  1013. result.List = TaskList;
  1014. callback(result);
  1015. } else {
  1016. callback({});
  1017. }
  1018. });
  1019. } else {
  1020. var obj = UserTestReport[n];
  1021. if (obj.BookID >= 43 && obj.BookID <= 60)
  1022. name1 = name1[0] + "生词" + name1[2].substr(0, 1);
  1023. else
  1024. name1 = name1[0] + name1[1].substr(2, 2) + "能力" + name1[2].substr(0, 1);
  1025. var HanziAll = wx.getStorageSync('HanziAll');
  1026. HanziAll = JSON.parse(HanziAll);
  1027. for (var i = 0; i < HanziAll.length; i++) {
  1028. if (name1 == HanziAll[i].Name) {
  1029. for (var j = 0; j < HanziAll[i].Units.length; j++) {
  1030. if (name2 == HanziAll[i].Units[j].Name) {
  1031. GetHanziUnitWords(HanziAll[i].Units[j].ID, obj.TestType, function (list) {
  1032. if (list) {
  1033. for (var k = 0; k < list.length; k++) {
  1034. if (obj.TestRightStr && obj.TestRightStr.indexOf(list[k].Word) >= 0)
  1035. list[k].Result = 1;
  1036. else if (obj.TestWrongStr && obj.TestWrongStr.indexOf(list[k].Word) >= 0)
  1037. list[k].Result = -1;
  1038. else if (obj.TestSkipStr && obj.TestSkipStr.indexOf(list[k].Word) >= 0)
  1039. list[k].Result = 0;
  1040. if (obj.TestExistStr && obj.TestExistStr.indexOf(list[k].Word) >= 0)
  1041. list[k].Css = "Select2";
  1042. }
  1043. var result = {};
  1044. result.ID = reportid;
  1045. result.BookID = obj.BookID;
  1046. result.TestType = obj.TestType;
  1047. result.Name = obj.Name.join("#");
  1048. result.IsFinished = obj.IsFinished;
  1049. result.TestRightStr = obj.TestRightStr;
  1050. result.TestWrongStr = obj.TestWrongStr;
  1051. result.TestSkipStr = obj.TestSkipStr;
  1052. result.TestExistStr = obj.TestExistStr;
  1053. result.List = list;
  1054. callback(result);
  1055. } else
  1056. callback({});
  1057. });
  1058. }
  1059. }
  1060. }
  1061. }
  1062. }
  1063. }
  1064. }
  1065. }
  1066. function getDetailColor(index) {
  1067. var arrDetailColor = constant.arrDetailColor;
  1068. if (index > 0)
  1069. return arrDetailColor[index];
  1070. else if (index == 0)
  1071. return arrDetailColor[common.random(1, arrDetailColor.length - 1)];
  1072. else if (index == -1)
  1073. return arrDetailColor;
  1074. }
  1075. function getShareImageBackColor() {
  1076. var arr = constant.arrShareImageBackColor;
  1077. return arr[common.random(0, arr.length - 1)];
  1078. }
  1079. function getPinyinNormal(pinyin) {
  1080. var result = "";
  1081. var arr = constant.arrPinyin;
  1082. for (var i = 0; i < arr.length; i++) {
  1083. if (arr[i][1] == pinyin) {
  1084. result = arr[i][0];
  1085. break;
  1086. }
  1087. }
  1088. return result;
  1089. }
  1090. function getHanzi(callback) {
  1091. var that = this;
  1092. wx.showLoading({
  1093. title: '请稍候',
  1094. mask: true,
  1095. });
  1096. var time = wx.getStorageSync("HanziUpdateTime");
  1097. getData('GetHanziAll3?UpdateTime=' + time, function (data) {
  1098. wx.hideLoading();
  1099. if (data) {
  1100. var arr = [];
  1101. if (data.List) {
  1102. arr = common.Decrypt(data.List);
  1103. wx.setStorageSync("HanziAll", arr);
  1104. wx.setStorageSync("HanziUpdateTime", data.UpdateTime);
  1105. callback(true);
  1106. } else {
  1107. callback(false);
  1108. }
  1109. }
  1110. });
  1111. }
  1112. function getEnglish(callback) {
  1113. var that = this;
  1114. wx.showLoading({
  1115. title: '请稍候',
  1116. mask: true,
  1117. });
  1118. var time = wx.getStorageSync("HanziUpdateTime");
  1119. getData('GetEnglishAll3?UpdateTime=' + time, function (data) {
  1120. wx.hideLoading();
  1121. if (data.EngList) {
  1122. var arrEng = common.Decrypt(data.EngList);
  1123. var arrNewConceptEngList = common.Decrypt(data.NewConceptEngList);
  1124. var arrCambridgeEngList = common.Decrypt(data.CambridgeEngList);
  1125. var arrPhoneticEngList = common.Decrypt(data.PhoneticEngList);
  1126. wx.setStorageSync("EnglishAll", arrEng);
  1127. wx.setStorageSync("NewConceptEngList", arrNewConceptEngList);
  1128. wx.setStorageSync("CambridgeEngList", arrCambridgeEngList);
  1129. wx.setStorageSync("PhoneticEngList", arrPhoneticEngList);
  1130. wx.setStorageSync("EnglishUpdateTime", data.UpdateTime);
  1131. callback(true);
  1132. } else {
  1133. callback(false);
  1134. }
  1135. });
  1136. }
  1137. function UploadUserConfig(callback) {
  1138. var that = this;
  1139. var param1 = {};
  1140. param1.CardType = wx.getStorageSync("CardType");
  1141. param1.CardMaxNumberNew = wx.getStorageSync("CardMaxNumberNew");
  1142. param1.CardMaxNumberHistory = wx.getStorageSync("CardMaxNumberHistory");
  1143. param1.CardMaxNumberNewUrgent = wx.getStorageSync("CardMaxNumberNewUrgent");
  1144. param1.CardMaxNumberHistoryUrgent = wx.getStorageSync("CardMaxNumberHistoryUrgent");
  1145. param1.SortTypeIndex = wx.getStorageSync("SortTypeIndex");
  1146. param1.MemoryLevel = wx.getStorageSync("MemoryLevel");
  1147. param1.ClickType = wx.getStorageSync("ClickType");
  1148. param1.SecondConfigArray = wx.getStorageSync("SecondConfigArray").join(",");
  1149. param1.ColorIndexArr = wx.getStorageSync("ColorIndexArr").join(",");
  1150. param1.IsFolderPractice = wx.getStorageSync("IsFolderPractice");
  1151. param1.IsAutoSound = wx.getStorageSync("IsAutoSound");
  1152. var symboMain = wx.getStorageSync("SymbolMain");
  1153. var symbol1 = [];
  1154. for (var i = 0; i < symboMain.length; i++) {
  1155. symbol1.push(symboMain[i].Name);
  1156. }
  1157. symbol1 = JSON.stringify(symbol1);
  1158. param1.SymbolList = symbol1;
  1159. var folderOrder = wx.getStorageSync("FolderOrderStr");
  1160. if (folderOrder)
  1161. param1.FolderOrder = folderOrder;
  1162. //console.log(param1);
  1163. that.postData('UploadUserConfig?Type=update&UserID=' + app.globalData.userInfo.UserID, param1, function (data) {
  1164. if (callback) {
  1165. callback();
  1166. }
  1167. });
  1168. }
  1169. function getAwardData(callback) {
  1170. var that = this;
  1171. that.getData('GetAwardInfo?UserID=' + app.globalData.userInfo.UserID, function (data) {
  1172. if (data) {
  1173. callback(data);
  1174. } else
  1175. callback([]);
  1176. });
  1177. }
  1178. function getUserConfig() {
  1179. var that = this;
  1180. postData('UploadUserConfig?Type=getData&UserID=' + app.globalData.userInfo.UserID, {}, function (data) {
  1181. if (data && !data.CardType)
  1182. data.CardType = 0;
  1183. wx.setStorageSync("CardType", data.CardType);
  1184. wx.setStorageSync("CardMaxNumberNew", data.CardMaxNumberNew);
  1185. wx.setStorageSync("CardMaxNumberHistory", data.CardMaxNumberHistory);
  1186. wx.setStorageSync("CardMaxNumberNewUrgent", data.CardMaxNumberNewUrgent);
  1187. wx.setStorageSync("CardMaxNumberHistoryUrgent", data.CardMaxNumberHistoryUrgent);
  1188. wx.setStorageSync("SortTypeIndex", data.SortTypeIndex);
  1189. wx.setStorageSync("MemoryLevel", data.MemoryLevel);
  1190. wx.setStorageSync("ClickType", data.ClickType);
  1191. wx.setStorageSync("SecondConfigArray", data.SecondConfigArray.split(","));
  1192. wx.setStorageSync("ColorIndexArr", data.ColorIndexArr.split(","));
  1193. wx.setStorageSync("FolderOrderStr", data.FolderOrder);
  1194. wx.setStorageSync("IsFolderPractice", data.IsFolderPractice);
  1195. wx.setStorageSync("IsAutoSound", data.IsAutoSound);
  1196. var symbol1 = [];
  1197. if (data.SymbolList) {
  1198. for (var i = 0; i < data.SymbolList.length; i++) {
  1199. var obj = {};
  1200. obj.Name = data.SymbolList[i];
  1201. obj.CSS = "btn2";
  1202. symbol1.push(obj);
  1203. }
  1204. } else {
  1205. symbol1 = app.globalData.SymbolMain;
  1206. }
  1207. if (symbol1.length > 0) {
  1208. wx.setStorageSync("SymboMain", symbol1);
  1209. app.globalData.SymbolMain = symbol1;
  1210. }
  1211. });
  1212. }
  1213. function replaceCardInfoString(str) {
  1214. var that = this;
  1215. //str = str.replace(/\[图]/g, "");
  1216. //str = str.replace(/\[\/图\]/g, "");
  1217. console.log(str);
  1218. if (str && str!=null) {
  1219. var str2 = "";
  1220. if (str.indexOf("[读 src=") >= 0) {
  1221. str2 = str.substr(str.indexOf("[读 src="));
  1222. str2 = str2.substring(0, str2.indexOf("]") + 1);
  1223. }
  1224. str = str.replace(str2, "");
  1225. if (str.indexOf("[/读") >= 0) {
  1226. str2 = str.substr(str.indexOf("[/读"));
  1227. str2 = str2.substring(0, 4);
  1228. }
  1229. str = str.replace(str2, "");
  1230. if (str.indexOf("[读 src=") >= 0) {
  1231. str2 = str.substr(str.indexOf("[读 src"));
  1232. str2 = str2.substring(0, str2.indexOf("/读]") + 3);
  1233. }
  1234. str = str.replace(str2, "");
  1235. if (str.indexOf("[/读") >= 0) {
  1236. str2 = str.substr(str.indexOf("[/读"));
  1237. str2 = str2.substring(0, 4);
  1238. }
  1239. str = str.replace(str2, "");
  1240. str = str.replace(/\[读]/g, "");
  1241. str = str.replace(/\[\/读\]/g, "");
  1242. var str3 = "";
  1243. if (str.indexOf("[图") >= 0) {
  1244. str3 = str.substr(str.indexOf("[图"));
  1245. str3 = str3.substring(0, str3.indexOf("/图]") + 3);
  1246. }
  1247. str = str.replace(str3, "");
  1248. if (str.indexOf("[图") >= 0) {
  1249. str3 = str.substr(str.indexOf("[图"));
  1250. str3 = str3.substring(0, str3.indexOf("/图]") + 3);
  1251. }
  1252. str = str.replace(str3, "");
  1253. str = str.replace(/\[线]/g, "");
  1254. str = str.replace(/\[\/线\]/g, "");
  1255. str = that.encryptUrl(str);
  1256. }
  1257. return str;
  1258. }
  1259. function searchInfomation(search, searchtype, author, shiciurl, callback) {
  1260. var WORD_LENGTH = 18;
  1261. wx.showLoading({
  1262. title: '查询中',
  1263. });
  1264. var timeout = setTimeout(function () {
  1265. wx.hideLoading();
  1266. }, 5000);
  1267. var url = 'GetMiaoguoAISearch2?UserID=' + app.globalData.userInfo.UserID;
  1268. url += "&Word=" + encodeURI(search);
  1269. if (searchtype)
  1270. url += "&SearchType=" + searchtype;
  1271. if (author)
  1272. url += "&Author=" + encodeURI(author);
  1273. if (shiciurl)
  1274. url += "&ShiciUrl=" + shiciurl;
  1275. getData(url, function (data) {
  1276. wx.hideLoading();
  1277. clearTimeout(timeout);
  1278. if (data) {
  1279. //console.log(data);
  1280. if (data.List) {
  1281. var len = WORD_LENGTH;
  1282. var list = data.List;
  1283. for (var i = 0; i < list.length; i++) {
  1284. var item = list[i];
  1285. if (item.TypeName == "字词") {
  1286. if (item.Key.length == 1)
  1287. item.TypeName = "Z";
  1288. else
  1289. item.TypeName = "C";
  1290. } else if (item.TypeName == "诗词") {
  1291. item.TypeName = "S";
  1292. item.Remark = item.Author + " " + item.Dynasty;
  1293. } else if (item.TypeName == "翻译") {
  1294. item.TypeName = "D";
  1295. }
  1296. if (item.Content && item.Content.length > len)
  1297. item.Content = item.Content.substr(0, len) + "...";
  1298. }
  1299. callback(list);
  1300. } else if (data.CHN || data.ENG) {
  1301. var obj = {};
  1302. obj.Key = search;
  1303. obj.Value = data;
  1304. if (data.CHN && data.CHN.Author)
  1305. obj.Author = data.CHN.Author;
  1306. if (data.CHN && data.CHN.Dynasty)
  1307. obj.Dynasty = data.CHN.Dynasty;
  1308. if (data.CHN && data.CHN.PeomContent) {
  1309. obj.Type = "shici";
  1310. obj.TypeName = "诗词";
  1311. obj.Content = data.CHN.PeomContent.join("").substr(0, WORD_LENGTH);
  1312. obj.ShiciUrl = shiciurl;
  1313. obj.TypeName = "S";
  1314. } else if (data.CHN) {
  1315. obj.Type = "zici";
  1316. if (data.CHN.PinYin && data.CHN.PinYin[0] && data.CHN.PinYin[0].pinyin)
  1317. obj.Remark = data.CHN.PinYin[0].pinyin;
  1318. if (data.CHN.PinYin && data.CHN.PinYin[0] && data.CHN.PinYin[0].explain) {
  1319. obj.Content = data.CHN.PinYin[0].explain.substr(0, WORD_LENGTH);
  1320. obj.Content = obj.Content.replace("<p>", "");
  1321. obj.Content = obj.Content.replace("</p>", "");
  1322. if (obj.Content.length >= WORD_LENGTH)
  1323. obj.Content += "..."
  1324. }
  1325. if (obj.Key.length == 1)
  1326. obj.TypeName = "Z";
  1327. else
  1328. obj.TypeName = "C";
  1329. }
  1330. if (data.ENG && !data.CHN) {
  1331. obj.Type = "eng";
  1332. obj.TypeName = "D";
  1333. if (data.ENG.Soundmark && data.ENG.Soundmark.Eng)
  1334. obj.Remark = data.ENG.Soundmark.Eng;
  1335. if (data.ENG.Paraphrase.length > 0) {
  1336. if (common.checkIsArray(data.ENG.Paraphrase) && data.ENG.Paraphrase[0].ParaphraseList)
  1337. obj.Content = data.ENG.Paraphrase[0].ParaphraseList.join("; ").substr(0, WORD_LENGTH);
  1338. else
  1339. obj.Content = data.ENG.Paraphrase.substr(0, WORD_LENGTH) + "...";
  1340. }
  1341. }
  1342. app.globalData.TempSearchBackNumber = 2;
  1343. //app.globalData.CardList=[];
  1344. app.globalData.CardList2 = [];
  1345. callback([], obj);
  1346. } else {
  1347. callback([]);
  1348. }
  1349. } else {
  1350. callback([]);
  1351. }
  1352. });
  1353. }
  1354. function downloadBishunKaitiImage(url, serverUrl, dataType, Fields, callback) {
  1355. var param = {};
  1356. param.Url = url;
  1357. param.DataType = dataType;
  1358. if (param.Url == serverUrl) {
  1359. postData("GetBiShunByKaitiUrl", param, function (data) {
  1360. if (data) {
  1361. wx.downloadFile({
  1362. url: data, // 仅为示例,并非真实的资源
  1363. success(res) {
  1364. // 只要服务器有响应数据,就会把响应内容写入文件并进入 success 回调,业务需要自行判断是否下载到了想要的内容
  1365. if (res.statusCode === 200) {
  1366. //console.log("serverUrl2:" + serverUrl);
  1367. console.log(res.tempFilePath);
  1368. callback(change(Fields, res.tempFilePath, param));
  1369. }
  1370. },
  1371. complete() {
  1372. }
  1373. });
  1374. }
  1375. });
  1376. } else {
  1377. callback(change(Fields, serverUrl, param));
  1378. }
  1379. function change(Fields, filepath, param) {
  1380. var iStart = 0;
  1381. if (Fields.length == 4)
  1382. iStart = 1
  1383. for (var i = iStart; i < Fields.length; i++) {
  1384. for (var j = 0; j < Fields[i].length; j++) {
  1385. if (Fields[i][j].Type == "image") {
  1386. if (Fields[i][j].Content == param.Url) {
  1387. Fields[i][j].Content = filepath;
  1388. if (param.DataType == "bishun") {
  1389. Fields[i][j].IsShowKaiti = true;
  1390. Fields[i][j].IsShowBishun = false;
  1391. } else if (param.DataType == "kaiti") {
  1392. Fields[i][j].IsShowKaiti = false;
  1393. Fields[i][j].IsShowBishun = true;
  1394. }
  1395. }
  1396. }
  1397. }
  1398. }
  1399. return Fields;
  1400. }
  1401. }
  1402. function GetSoundError(str) {
  1403. var arr = constant.arrSoundError;
  1404. var result = str;
  1405. for (var i = 0; i < arr.length; i++) {
  1406. if (str.indexOf(arr[i].Word) > 0) {
  1407. result = common.ReplaceAllString(str, arr[i].Word, arr[i].Sound);
  1408. break;
  1409. } else if (str == arr[i].Word) {
  1410. result = arr[i].Sound;
  1411. }
  1412. }
  1413. return result;
  1414. }
  1415. function GetTestReportList(userID, callback) {
  1416. getData('GetTestGradeArr', function (GradeArr) {
  1417. for (var i = 0; i < GradeArr.length; i++) {
  1418. for (var j = 0; j < GradeArr[i].List.length; j++) {
  1419. GradeArr[i].List[j].Finish = 0;
  1420. }
  1421. }
  1422. getData('GetTestReportList?UserID=' + userID, function (data) {
  1423. if (data) {
  1424. var dataTemp = [];
  1425. for (var i = 0; i < data.length; i++) {
  1426. for (var j = 0; j < dataTemp.length; j++) {
  1427. if (dataTemp[j].Name[0] == data[i].Name[0] &&
  1428. dataTemp[j].Name[1] == data[i].Name[1] &&
  1429. dataTemp[j].TestType == data[i].TestType &&
  1430. data[i].IsFinished == 1
  1431. ) {
  1432. dataTemp.splice(j, 1);
  1433. break;
  1434. }
  1435. }
  1436. dataTemp.push(data[i]);
  1437. 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) {
  1438. if (data[i].TestRightStr) {
  1439. data[i].TestRightStr = data[i].TestRightStr.split(",");
  1440. }
  1441. if (data[i].TestWrongStr) {
  1442. data[i].TestWrongStr = data[i].TestWrongStr.split(",");
  1443. }
  1444. if (data[i].TestSkipStr) {
  1445. data[i].TestSkipStr = data[i].TestSkipStr.split(",");
  1446. }
  1447. if (data[i].TestExistStr) {
  1448. data[i].TestExistStr = data[i].TestExistStr.split(",");
  1449. }
  1450. }
  1451. if (!data[i].TestRightStr)
  1452. data[i].TestRightStr = "";
  1453. if (!data[i].TestWrongStr)
  1454. data[i].TestWrongStr = "";
  1455. if (!data[i].TestSkipStr)
  1456. data[i].TestSkipStr = "";
  1457. if (!data[i].TestExistStr)
  1458. data[i].TestExistStr = "";
  1459. }
  1460. for (var i = 0; i < dataTemp.length; i++) {
  1461. var name = dataTemp[i].Name[0].split(" ");
  1462. for (var j = 0; j < GradeArr.length; j++) {
  1463. var item = GradeArr[j];
  1464. if (name[0] == item.Name) {
  1465. for (var k = 0; k < item.List.length; k++) {
  1466. //音标计算进度
  1467. if (item.List[k].ID == 101 && dataTemp[i].BookID == 101) {
  1468. for (var n = 1; n <= 4; n++) {
  1469. if (Number(dataTemp[i].Name[2]) == n && dataTemp[i].IsFinished == 1)
  1470. item.List[k].Finish++;
  1471. }
  1472. }
  1473. //古诗词计算进度
  1474. else if (item.List[k].ID == dataTemp[i].BookID && dataTemp[i].TestType == "recite" && dataTemp[i].IsFinished == 1)
  1475. item.List[k].Finish = 1;
  1476. else {
  1477. if (name[1] == item.List[k].Name && name[2] == item.List[k].Name2) {
  1478. if (dataTemp[i].IsFinished == 1)
  1479. item.List[k].Finish++;
  1480. }
  1481. }
  1482. }
  1483. }
  1484. }
  1485. }
  1486. for (var j = 0; j < GradeArr.length; j++) {
  1487. var item = GradeArr[j];
  1488. for (var k = 0; k < item.List.length; k++) {
  1489. item.List[k].Finished = Math.round(100 * item.List[k].Finish / item.List[k].Total);
  1490. item.List[k].NameStr = item.List[k].Name.replace("语文", "");
  1491. }
  1492. }
  1493. wx.setStorageSync("UserTestReport", data);
  1494. callback(data, GradeArr);
  1495. }
  1496. });
  1497. });
  1498. }
  1499. function showHelp(obj,myClass,textTopDirection,helpText,closePos){
  1500. setTimeout(function(){
  1501. wx.createSelectorQuery().select(myClass).boundingClientRect(function (rect) {
  1502. console.log("rect.left:"+rect.left);
  1503. console.log("rect.top:"+rect.top);
  1504. console.log("rect.width:"+rect.width);
  1505. console.log("rect.height:"+rect.height);
  1506. var textTop=rect.bottom+5;
  1507. if (textTopDirection=="up")
  1508. textTop=rect.top-47;
  1509. if (!closePos)
  1510. closePos="Right";
  1511. obj.setData({
  1512. HelpTop:rect.top,
  1513. HelpWidth1:rect.left,
  1514. HelpHeight1:rect.height,
  1515. HelpLeft2:rect.right,
  1516. HelpHeight2:rect.height,
  1517. HelpBottom:rect.bottom-1,
  1518. HelpTextTop:textTop,
  1519. HelpText:helpText,
  1520. HelpClosePos:closePos,
  1521. });
  1522. }).exec();
  1523. },500);
  1524. }
  1525. module.exports = {
  1526. getData: getData,
  1527. postData: postData,
  1528. payMoney: payMoney,
  1529. getLocalHost: getLocalHost,
  1530. getTimeFormat: getTimeFormat,
  1531. getWindowHeight: getWindowHeight,
  1532. getStorageValue: getStorageValue,
  1533. getProgramList: getProgramList,
  1534. gotoFeedback: gotoFeedback,
  1535. getDetailColor: getDetailColor,
  1536. changeStringToView: changeStringToView,
  1537. changeViewToString: changeViewToString,
  1538. encryptUrl: EncryptUrl,
  1539. decryptUrl: DecryptUrl,
  1540. saveTempImage: saveTempImage,
  1541. getTempImage: getTempImage,
  1542. getTaskTodayList: getTaskTodayList,
  1543. updateSearchList: updateSearchList,
  1544. checkIsIPhoneX: checkIsIPhoneX,
  1545. getMemoryLevelAll: getMemoryLevelAll,
  1546. getMemoryLevel: getMemoryLevel,
  1547. getShareImageBackColor: getShareImageBackColor,
  1548. UpdateMiaoguoCardTodayAll: UpdateMiaoguoCardTodayAll,
  1549. setCollect: setCollect,
  1550. UploadUserConfig: UploadUserConfig,
  1551. getServerImage: getServerImage,
  1552. getBaiduToken: getBaiduToken,
  1553. buildInitData: buildInitData,
  1554. getPinyinNormal: getPinyinNormal,
  1555. getHanzi: getHanzi,
  1556. getEnglish: getEnglish,
  1557. GetHanziUnitWords: GetHanziUnitWords,
  1558. GetTestReportInfo: GetTestReportInfo,
  1559. getUserConfig: getUserConfig,
  1560. getAwardData: getAwardData,
  1561. replaceCardInfoString: replaceCardInfoString,
  1562. searchInfomation: searchInfomation,
  1563. downloadBishunKaitiImage: downloadBishunKaitiImage,
  1564. GetSoundError: GetSoundError,
  1565. GetTestReportList: GetTestReportList,
  1566. ShowHelp:showHelp,
  1567. }