main.js 61 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958
  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. var err={};
  25. err.errCode=100;
  26. err.errMsg="网络错误";
  27. callback(null,err);
  28. },
  29. });
  30. }
  31. function postData(url, postData, callback) {
  32. var url = common.Encrypt(url);
  33. //console.log("加密后的结果为===",url);
  34. wx.request({
  35. url: app.globalData.serverUrl + url,
  36. method: "POST",
  37. data: postData,
  38. success: function (res) {
  39. if (res.statusCode)
  40. common.checkError(res.statusCode);
  41. var data = res.data.result;
  42. callback(data);
  43. },
  44. fail: function () {
  45. wx.showToast({
  46. title: '系统忙请稍候',
  47. duration: 3000
  48. });
  49. },
  50. });
  51. }
  52. function getLocalHost(callback) {
  53. if (!app.globalData.IsProduction) {
  54. var url = common.Encrypt("Ping");
  55. wx.request({
  56. url: app.globalData.serverUrlLocalhost + url,
  57. success: function (res) {
  58. app.globalData.serverUrl = app.globalData.serverUrlLocalhost;
  59. callback();
  60. },
  61. fail: function () {
  62. app.globalData.serverUrl = app.globalData.serverUrlServer;
  63. callback();
  64. },
  65. });
  66. } else {
  67. app.globalData.serverUrl = app.globalData.serverUrlServer;
  68. callback();
  69. }
  70. }
  71. function getBaiduToken() {
  72. var that = this
  73. //调用登录接口
  74. wx.login({
  75. success: function (res0) {
  76. getData('GetBaiduToken20220922?ProgramID='+app.globalData.ProgramID+'&Code='+res0.code, function (data) {
  77. if (data) {
  78. app.globalData.BaiduToken = data;
  79. //console.log(app.globalData.BaiduToken);
  80. }
  81. });
  82. }
  83. });
  84. }
  85. function payMoney(payType, remark, money, detail, callback) {
  86. console.log(money);
  87. if (app.globalData.userInfo.UserID < 8 ||
  88. app.globalData.userInfo.UserID == 3089)
  89. money = 0.01;
  90. //登录认证
  91. wx.login({
  92. success: function (res) {
  93. if (res.code) {
  94. console.log('获取用户登录态成功!' + res.code);
  95. //预支付
  96. getData('ProductPayLogin500?code=' + res.code + '&payType=' + payType + '&money=' + money + '&detail=' + detail + '&productID=' + app.globalData.ProgramID + '&Remark=' + remark+'&UserID='+app.globalData.userInfo.ShowUserID, function (data) {
  97. if (data && data.timeStamp) {
  98. //微信支付
  99. wx.requestPayment({
  100. 'timeStamp': data.timeStamp.toString(),
  101. 'nonceStr': data.nonceStr,
  102. 'package': data.package,
  103. 'signType': 'MD5',
  104. 'paySign': data.paySign,
  105. 'success': function (res3) {
  106. console.log("success:" + res3);
  107. callback(data);
  108. },
  109. 'fail': function (err) {
  110. if (err && err.errMsg && err.errMsg.indexOf("fail cancel")) {
  111. } else {
  112. wx.showToast({
  113. title: '系统忙请稍候',
  114. duration: 3000
  115. });
  116. }
  117. }
  118. });
  119. }
  120. });
  121. } else {
  122. console.log('获取用户登录态失败!' + res.errMsg);
  123. wx.showToast({
  124. title: '系统忙请稍候',
  125. duration: 3000
  126. });
  127. }
  128. }
  129. });
  130. }
  131. function getTimeFormat(duration) {
  132. //console.log("duration:" + duration);
  133. var arr = ['', '', '']
  134. if (duration.indexOf("'") > 0)
  135. arr[0] = duration.substring(0, duration.indexOf("'"));
  136. if (duration.indexOf(".") > 0) {
  137. arr[1] = duration.substring(duration.indexOf("'") + 1, duration.indexOf(".") + 1);
  138. arr[2] = duration.substring(duration.indexOf(".") + 1, duration.indexOf('"'));
  139. } else {
  140. arr[1] = duration.substring(duration.indexOf("'") + 1, duration.indexOf('"'));
  141. }
  142. return arr;
  143. }
  144. function getWindowHeight() {
  145. var height = app.globalData.systemInfo.windowHeight;
  146. //console.log("app.globalData.systemInfo.windowHeight:" + app.globalData.systemInfo.windowHeight * 2);
  147. if (app.globalData.systemInfo.model) {
  148. if (height == 504 && (
  149. app.globalData.systemInfo.model.indexOf("iPhone 6<") >= 0 ||
  150. app.globalData.systemInfo.model.indexOf("iPhone 7<") >= 0 ||
  151. app.globalData.systemInfo.model.indexOf("iPhone 6s<") >= 0 ||
  152. app.globalData.systemInfo.model.indexOf("iPhone 5") >= 0 ||
  153. app.globalData.systemInfo.model.indexOf("iPhone SE") >= 0
  154. )) {
  155. height = 596;
  156. } else if (app.globalData.systemInfo.model.indexOf("iPad") >= 0) {
  157. height = 470;
  158. }
  159. }
  160. height = height * 2;
  161. if (app.globalData.systemInfo.system && app.globalData.systemInfo.system.indexOf("Android") >= 0) {
  162. height = height + 168;
  163. } else {
  164. height = height + 50;
  165. }
  166. //console.log("height:" + height);
  167. //var height = app.globalData.systemInfo.screenHeight * 2;
  168. return height;
  169. }
  170. //获取存储数据,若不存在,则获得缺省值。
  171. function getStorageValue(obj, name, defaultStatus, callback) {
  172. wx.getStorage({
  173. key: name,
  174. success: function (res) {
  175. obj.data[name] = res.data;
  176. obj.setData(obj.data);
  177. callback();
  178. },
  179. fail: function (res) {
  180. obj.data[name] = defaultStatus;
  181. obj.setData(obj.data);
  182. callback();
  183. },
  184. });
  185. }
  186. function getProgramList() {
  187. return [{
  188. id: 89,
  189. appId: 'wx46a7b4c420e6d38f',
  190. path: 'pages/index/start?SourceID=' + app.globalData.ProgramID,
  191. },
  192. {
  193. id: 98,
  194. appId: 'wx331e8dd070f01d0e',
  195. path: 'pages/index/index?SourceID=' + app.globalData.ProgramID,
  196. },
  197. {
  198. id: 99,
  199. appId: 'wxb54a6d5aff836ee3',
  200. path: 'pages/index/index?SourceID=' + app.globalData.ProgramID,
  201. },
  202. {
  203. id: 106,
  204. appId: 'wx313a8f2c0741efe1',
  205. path: 'pages/index/index?SourceID=' + app.globalData.ProgramID,
  206. },
  207. ];
  208. }
  209. function gotoFeedback() {
  210. wx.navigateToMiniProgram({
  211. appId: "wx80059777521b897c",
  212. path: "pages/index/feedback",
  213. extraData: {},
  214. success(res) {
  215. // 打开成功
  216. }
  217. });
  218. }
  219. function changeViewToString(content) {
  220. var str = content;
  221. if (str.constructor == Array) {
  222. if (str.length > 0)
  223. str = str.join(",");
  224. else
  225. str = "";
  226. }
  227. if (!str)
  228. str = ""
  229. else {
  230. str = str.replace(/\n\n\n/g, "\n\n");
  231. if (str.indexOf("\n") == 0 && str.indexOf("[") == 1) {
  232. str = str.substr(1);
  233. }
  234. if (str.lastIndexOf("\n") == str.length - 1) {
  235. str = str.substr(0, str.length - 1);
  236. }
  237. }
  238. return str;
  239. }
  240. function EncryptUrl(str) {
  241. if (str && str.constructor && str.constructor == Array) {
  242. if (str.length > 0)
  243. str = str.join(",");
  244. else
  245. str = "";
  246. }
  247. if (str) {
  248. str = str.replace(/baidu.com/g, "#####1#####");
  249. str = str.replace(/iciba.com/g, "#####2#####");
  250. str = str.replace(/https:\/\/pinyin-1253256735.file.myqcloud.com\/sounds/g, "#####3#####");
  251. str = str.replace(/https:\/\/miaguo-1253256735.file.myqcloud.com/g, "#####4#####");
  252. if (str.substr(0, 1) == "\n")
  253. str = str.substr(1);
  254. }
  255. return str;
  256. }
  257. function DecryptUrl(str) {
  258. if (str.constructor == Array) {
  259. if (str.length > 0)
  260. str = str.join(",");
  261. else
  262. str = "";
  263. }
  264. if (str) {
  265. str = str.replace(/#####1#####/g, "baidu.com");
  266. str = str.replace(/#####2#####/g, "iciba.com");
  267. str = str.replace(/#####3#####/g, "https://pinyin.kylx365.com/sounds");
  268. str = str.replace(/#####4#####/g, "https://miaguo-1253256735.file.myqcloud.com");
  269. }
  270. return str;
  271. }
  272. function changeStringToView(field) {
  273. var result = {};
  274. result.Field = [
  275. []
  276. ];
  277. result.Images = [];
  278. for (var j = 0; j < field.length; j++) {
  279. if (j == 0) {
  280. if (field[j].ContentType == 0 && field[j].Content && field[j].Content.length > 0) {
  281. result.Tags = field[j].Content.toString().split(",");
  282. } else {
  283. result.Tags = [];
  284. }
  285. } else {
  286. if (field[j].ContentType == j && field[j].Content && field[j].Content.length > 0) {
  287. var arrResult = [],
  288. arrSoundMark = [];
  289. var str = field[j].Content.toString();
  290. str = DecryptUrl(str);
  291. if (str.indexOf("[读") > 0)
  292. str = str.replace(/\[读/g, "\n[读");
  293. str = str.replace(/\[图/g, "\n[图");
  294. if (str.indexOf("[音") > 0)
  295. str = str.replace(/\[音/g, "\n[音");
  296. str = str.replace(/\[\/读\]/g, "[\/读]\n");
  297. str = str.replace(/\[\/图\]/g, "[\/图]\n");
  298. str = str.replace(/\[\/音\]/g, "[\/音]\n");
  299. str = str.replace(/\n\n\n/g, "\n\n");
  300. var arr = str.split("\n");
  301. for (var k = 0; k < arr.length; k++) {
  302. if (arr[k].indexOf("[图") >= 0 && arr[k].indexOf("[/图]") > 0) {
  303. var obj = {};
  304. obj.Type = "image";
  305. if (arr[k].indexOf("[图") >= 0) {
  306. obj.ContentServer = arr[k].substring(arr[k].indexOf("[图") + 3, arr[k].indexOf("[/图]"));
  307. const w = 650;
  308. if (obj.ContentServer.indexOf("w='") >= 0 && obj.ContentServer.indexOf("h='") >= 0) {
  309. obj.Width = obj.ContentServer.substring(obj.ContentServer.indexOf("w='") + 3, obj.ContentServer.indexOf("h='") - 2);
  310. obj.Height = obj.ContentServer.substring(obj.ContentServer.indexOf("h='") + 3, obj.ContentServer.indexOf("']"));
  311. obj.Height = Math.round((w * Number(obj.Height)) / Number(obj.Width));
  312. obj.Width = w;
  313. } else {
  314. obj.Width = "";
  315. obj.Height = "";
  316. }
  317. obj.ContentServer = obj.ContentServer.substring(obj.ContentServer.indexOf("]") + 1);
  318. obj.Content = getTempImage(obj.ContentServer);
  319. if (obj.Content.lastIndexOf("fm=58") >= 0)
  320. obj.IsShowBishun = true;
  321. else if (obj.Content.indexOf("hanyu-word-gif") > 0)
  322. obj.IsShowKaiti = true;
  323. result.Images.push(obj.Content);
  324. }
  325. arrResult.push(obj);
  326. } else if (arr[k].indexOf("[特]") >= 0 && arr[k].indexOf("[/特]") > 0) {
  327. var obj = {};
  328. obj.Type = "bigword";
  329. var content = arr[k].substring(arr[k].indexOf("[特]")+3,arr[k].indexOf("[/特]"));
  330. obj.Content = content;
  331. arrResult.push(obj);
  332. } else if ((arr[k].indexOf("[线]") >= 0 && arr[k].indexOf("[/线]") > 0) || (arr[k].indexOf("[光]") >= 0 && arr[k].indexOf("[/光]") > 0)) {
  333. var obj;
  334. var content = [],
  335. temp = arr[k];
  336. do {
  337. var num1 = temp.indexOf("[线]");
  338. var num2 = temp.indexOf("[光]");
  339. if (num1 >= 0 || num2 >= 0) {
  340. 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 if ((num1 > num2 && num1 >= 0 && num2 >= 0) || (num1 < 0 && num2 >= 0)) {
  357. var temp1 = temp.substring(0, temp.indexOf("[光]"));
  358. if (temp1) {
  359. content.push({
  360. key: "normal",
  361. value: temp1,
  362. });
  363. } else {
  364. if (temp && temp.indexOf("[光]") < 0) {
  365. content.push({
  366. key: "normal",
  367. value: temp,
  368. });
  369. temp = "";
  370. }
  371. }
  372. } else {
  373. content.push({
  374. key: "normal",
  375. value: temp,
  376. });
  377. temp = "";
  378. }
  379. } else {
  380. content.push({
  381. key: "normal",
  382. value: temp,
  383. });
  384. temp = "";
  385. }
  386. if (temp.length > 0 && (num1 >= 0 || num2 >= 0)) {
  387. if ((num1 < num2 && num1 >= 0 && num2 >= 0) || (num1 >= 0 && num2 < 0)) {
  388. temp = temp.substr(temp.indexOf("[线]") + 3);
  389. temp1 = temp.substring(0, temp.indexOf("[/线]"));
  390. if (temp1) {
  391. content.push({
  392. key: "line",
  393. value: temp1,
  394. });
  395. }
  396. temp = temp.substr(temp.indexOf("[/线]") + 4);
  397. } else if ((num1 > num2 && num1 >= 0 && num2 >= 0) || (num1 < 0 && num2 >= 0)) {
  398. temp = temp.substr(temp.indexOf("[光]") + 3);
  399. temp1 = temp.substring(0, temp.indexOf("[/光]"));
  400. if (temp1) {
  401. content.push({
  402. key: "highlighter",
  403. value: temp1,
  404. });
  405. }
  406. temp = temp.substr(temp.indexOf("[/光]") + 4);
  407. } else
  408. temp = "";
  409. } else
  410. temp = "";
  411. }
  412. while (temp.length > 0);
  413. obj = {};
  414. obj.Type = "line";
  415. obj.Content = content;
  416. arrResult.push(obj);
  417. } else if (arr[k].indexOf("[读") >= 0 && arr[k].indexOf("[/读]") > 0) {
  418. var obj = {};
  419. obj.Type = "sound";
  420. if (arr[k].indexOf("[读]") >= 0) {
  421. obj.Content = arr[k].substring(arr[k].indexOf("[读]") + 3, arr[k].indexOf("[/读]"));
  422. } else {
  423. var tempIndex = arr[k].indexOf("\']") + 2;
  424. obj.Content = arr[k].substring(tempIndex, arr[k].indexOf("[/读]"));
  425. obj.SoundMark = arr[k].substring(arr[k].indexOf("src='") + 5, arr[k].indexOf("']"));;
  426. }
  427. arrResult.push(obj);
  428. } else if (arr[k].indexOf("[音") >= 0 && arr[k].indexOf("[/音]") > 0) {
  429. var obj = {};
  430. obj.Type = "recorder";
  431. var tempIndex = arr[k].indexOf("\']") + 2;
  432. //obj.Content = arr[k].substring(tempIndex, arr[k].indexOf("[/音]"));
  433. obj.SoundMark = arr[k].substring(arr[k].indexOf("url='") + 5, arr[k].indexOf("']"));;
  434. arrResult.push(obj);
  435. } else if (arr[k] != "") {
  436. var obj = {};
  437. obj.Type = "normal";
  438. obj.Content = arr[k];
  439. arrResult.push(obj);
  440. } else if (k > 0 && arr[k] == "") {
  441. var obj = {};
  442. obj.Type = "br";
  443. obj.Content = "";
  444. arrResult.push(obj);
  445. }
  446. var obj = {};
  447. obj.Type = "return";
  448. arrResult.push(obj);
  449. }
  450. //去掉前回车换行
  451. // while (arrResult[0].Type == "return" ||
  452. // arrResult[0].Type == "br") {
  453. // arrResult.shift();
  454. // if (arrResult.length == 0)
  455. // break;
  456. // }
  457. //去掉后回车换行
  458. for (var i = arrResult.length - 1; i >= 0; i--) {
  459. if (arrResult[i].Type == "return" ||
  460. arrResult[i].Type == "br")
  461. arrResult.pop();
  462. else {
  463. break;
  464. }
  465. }
  466. result.Field.push(arrResult);
  467. } else {
  468. result.Field.push([]);
  469. }
  470. }
  471. }
  472. return result;
  473. }
  474. //得到当天任务
  475. function getTaskTodayList(callback) {
  476. var isNotData = true;
  477. var intervalTask = setTimeout(function () {
  478. if (isNotData) {
  479. wx.showLoading({
  480. title: '请稍候',
  481. mask: true,
  482. });
  483. setTimeout(function () {
  484. wx.hideLoading();
  485. }, 60000);
  486. }
  487. }, 2000);
  488. var that = this;
  489. var url = 'GetMiaoguoCardToday2?UserID=' + app.globalData.userInfo.UserID;
  490. getData(url, function (data) {
  491. clearTimeout(intervalTask);
  492. if (isNotData) {
  493. wx.hideLoading();
  494. }
  495. isNotData = false;
  496. if (data) {
  497. app.globalData.TaskToday = data;
  498. callback(data);
  499. }
  500. });
  501. }
  502. function getTempImage(serverUrl) {
  503. if (serverUrl.indexOf("miaguo-1253256735") >= 0) {
  504. var list = wx.getStorageSync("TempImageList");
  505. if (!list)
  506. list = [];
  507. for (var i = 0; i < list.length; i++) {
  508. if (list[i].ServerUrl == serverUrl) {
  509. return list[i].TempUrl;
  510. break;
  511. }
  512. }
  513. }
  514. return serverUrl;
  515. }
  516. function getServerImage(tempUrl) {
  517. if (tempUrl.indexOf("http") < 0) {
  518. var list = wx.getStorageSync("TempImageList");
  519. if (!list)
  520. list = [];
  521. for (var i = 0; i < list.length; i++) {
  522. if (list[i].TempUrl == tempUrl) {
  523. return list[i].ServerUrl;
  524. break;
  525. }
  526. }
  527. return ""
  528. }
  529. }
  530. function saveTempImage(serverUrl, tempUrl) {
  531. if (tempUrl.indexOf("http") < 0) {
  532. var list = wx.getStorageSync("TempImageList");
  533. if (!list)
  534. list = [];
  535. var b = false;
  536. for (var i = 0; i < list.length; i++) {
  537. if (list[i].ServerUrl == serverUrl) {
  538. list[i].TempUrl = tempUrl;
  539. b = true;
  540. break;
  541. }
  542. }
  543. if (!b) {
  544. list.push({
  545. "ServerUrl": serverUrl,
  546. "TempUrl": tempUrl
  547. });
  548. }
  549. if (list.length > 200) {
  550. list.pop();
  551. }
  552. wx.setStorageSync("TempImageList", list);
  553. }
  554. }
  555. function UpdateMiaoguoCardTodayAll(isShowLoading, callback) {
  556. var that = this;
  557. if (isShowLoading) {
  558. wx.showLoading({
  559. title: '请稍候',
  560. mask: true,
  561. });
  562. clearTimeout(dataSendTimeout);
  563. dataSendTimeout = setTimeout(function () {
  564. wx.hideLoading();
  565. }, 60000);
  566. }
  567. var list = wx.getStorageSync("ListTaskFinished");
  568. if (list && list.length > 0) {
  569. var arr = [];
  570. for (var i = 0; i < list.length; i++) {
  571. var obj = {};
  572. obj.MiaoguoCardID = list[i].Card.MiaoguoCardID;
  573. obj.IntervalTime = list[i].IntervalTime;
  574. obj.BtnNumber = list[i].BtnNumber;
  575. obj.FontSize = list[i].Card.FontSize;
  576. obj.Duration = list[i].Duration;
  577. obj.LearningType = list[i].LearningType;
  578. obj.IsCollect = list[i].Card.IsCollect;
  579. obj.LastTime = list[i].LastTime;
  580. arr.push(obj);
  581. }
  582. var userid=wx.getStorageSync("ListTaskFinishedUserID");
  583. that.postData('UpdateMiaoguoCardTodayAll?UserID=' + userid, {
  584. List: arr,
  585. }, function (data) {
  586. if (isShowLoading) {
  587. wx.hideLoading();
  588. clearTimeout(dataSendTimeout);
  589. }
  590. if (data) {
  591. wx.removeStorageSync("ListTaskFinished");
  592. wx.removeStorageSync("ListTaskFinishedUserID");
  593. }
  594. if (callback) {
  595. callback();
  596. }
  597. });
  598. } else {
  599. wx.hideLoading();
  600. clearTimeout(dataSendTimeout);
  601. if (callback) {
  602. callback();
  603. }
  604. }
  605. }
  606. function updateSearchList(obj, callback) {
  607. var arr = wx.getStorageSync("SearchWord3");
  608. if (!arr)
  609. arr = [];
  610. if (obj && obj.Type && obj.Type == "shici") {
  611. if (obj.Value.CHN.ShiciTitle)
  612. obj.Key = obj.Value.CHN.ShiciTitle;
  613. if (obj.Key.indexOf("《") == 0)
  614. obj.Key = obj.Key.substring(1, obj.Key.length - 1);
  615. }
  616. for (var i = 0; i < arr.length; i++) {
  617. if (obj.Key && arr[i].Key == obj.Key) {
  618. if (obj.Type == "shici") {
  619. if (arr[i].ShiciUrl == obj.ShiciUrl) {
  620. obj.Value = arr[i].Value;
  621. arr.splice(i, 1);
  622. break;
  623. }
  624. } else {
  625. var b = true;
  626. if (obj.Type && arr[i].Type && arr[i].Type != obj.Type)
  627. b = false;
  628. if (obj.Author && arr[i].Author && arr[i].Author != obj.Author)
  629. b = false;
  630. if (b) {
  631. obj.Value = arr[i].Value;
  632. arr.splice(i, 1);
  633. break;
  634. }
  635. }
  636. }
  637. }
  638. if (obj.Key)
  639. arr.unshift(obj);
  640. if (arr.length > 30) {
  641. arr.pop();
  642. }
  643. wx.setStorageSync("SearchWord3", arr);
  644. app.globalData.SearchItem = obj.Value;
  645. if (obj.TypeName)
  646. app.globalData.SearchItem.TypeName = obj.TypeName;
  647. if (callback)
  648. callback();
  649. }
  650. function checkIsIPhoneX() {
  651. var isIphoneX = false;
  652. if (app.globalData.systemInfo.model.indexOf("iPhone X") >= 0 ||
  653. app.globalData.systemInfo.model.indexOf("iPhone X") >= 0) {
  654. isIphoneX = true;
  655. }
  656. return isIphoneX;
  657. }
  658. //设置收藏
  659. function setCollect(id, collect, callback) {
  660. var that = this;
  661. if (collect) {
  662. wx.showToast({
  663. title: '加注成功',
  664. image: '../images/universalpic_star_white_120x120.png',
  665. });
  666. } else {
  667. wx.showToast({
  668. title: '清除成功',
  669. image: '../images/universalpic_star_whiteline_120x120.png',
  670. });
  671. }
  672. getData("UpdateMiaoguoCardInfo?UserID=" + app.globalData.userInfo.UserID + "&MiaoguoCardID=" + id + "&IsCollect=" + collect, function (data) {
  673. if (callback)
  674. callback();
  675. });
  676. }
  677. function getMemoryLevelAll() {
  678. return constant.arrMemoryLevelAll;
  679. }
  680. function getMemoryLevel(index, number, time) {
  681. var arr = getMemoryLevelAll();
  682. if (index < 1)
  683. return arr[index].Value[number].Name;
  684. else
  685. return replaceStr(time);
  686. function replaceStr(data) {
  687. var result = "";
  688. if (data.indexOf("d") > 0) {
  689. var dayNum = Number(data.replace("d", ""));
  690. if (dayNum >= 365) {
  691. var year1 = Math.floor(dayNum / 365);
  692. var year = year1 + Math.round(10 * (dayNum - year1 * 365) / 365) / 10;
  693. result = year + "年后";
  694. } else {
  695. if (dayNum > 31) {
  696. var month1 = Math.floor(dayNum / 30);
  697. var month = month1 + Math.round(10 * (dayNum - month1 * 30) / 30) / 10;
  698. result = month + "月后";
  699. } else {
  700. result = Number(data.replace("d", ""));
  701. if (result == 1)
  702. result = "明天";
  703. else if (result == 2)
  704. result = "后天";
  705. else
  706. result = (result - 1) + "天后";
  707. }
  708. }
  709. } else if (data.indexOf("m") > 0)
  710. result = data.replace("m", "分钟内");
  711. return result;
  712. }
  713. }
  714. //得到要检验的汉字列表
  715. function GetHanziUnitWords(unitsID, testType, callback) {
  716. var url = 'GetHanziUnitWords?UnitID=' + unitsID;
  717. if (testType)
  718. url += "&TestType=" + testType;
  719. getData(url, function (data) {
  720. if (data) {
  721. var TaskList = [];
  722. var words = data;
  723. //若是单字
  724. if (words[0].Pinyin) {
  725. for (var k = 0; k < words.length; k++) {
  726. var taskInfo = {
  727. FontSize: 144,
  728. TagWidth: 136,
  729. Content: [{
  730. ContentType: 0,
  731. Content: []
  732. },
  733. {
  734. ContentType: 1,
  735. Content: []
  736. },
  737. {
  738. ContentType: 2,
  739. Content: []
  740. },
  741. ]
  742. };
  743. taskInfo.Word = words[k].Name;
  744. var pinyinNormal = "(" + getPinyinNormal(words[k].Pinyin) + ")";
  745. var combineWords = common.ReplaceAllString(words[k].CombineWords, words[k].Name, words[k].Name + pinyinNormal);
  746. taskInfo.ReadString = words[k].Name + pinyinNormal + "," + combineWords + "的" + words[k].Name + pinyinNormal;
  747. if (testType == "read") {
  748. taskInfo.Content[0].Content = ["怎么念"];
  749. var question = words[k].CombineWords;
  750. question = common.ReplaceAllString(question, words[k].Name, "(" + words[k].Name + ")");
  751. taskInfo.Content[1].Content = question;
  752. var answer = "[读 src='" + taskInfo.ReadString + "']" + words[k].Pinyin + "[/读]";
  753. taskInfo.Content[2].Content = answer;
  754. if (words[k].CombineWords.length > 6) {
  755. taskInfo.FontSize = 108;
  756. if (words[k].CombineWords.length > 10) {
  757. taskInfo.FontSize = 68;
  758. }
  759. }
  760. } else if (testType == "write") {
  761. taskInfo.Content[0].Content = ["怎么写"];
  762. var question = words[k].CombineWords;
  763. //var question2 = common.ReplaceAllString(question, words[k].Name, words[k].Pinyin);
  764. var question2 = words[k].CombineWords2;
  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].KaitiUrl + "[/图]";
  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.TagWidth=136;
  788. taskInfo.ContentNew = changeStringToView(taskInfo.Content);
  789. TaskList.push(taskInfo);
  790. }
  791. }
  792. callback(TaskList);
  793. } else {
  794. callback([]);
  795. }
  796. });
  797. }
  798. function GetTestReportInfo(reportid, callback) {
  799. var UserTestReport = wx.getStorageSync('UserTestReport');
  800. for (var n = 0; n < UserTestReport.length; n++) {
  801. if (UserTestReport[n].ID == reportid) {
  802. var name1 = UserTestReport[n].Name[0].split(" ");
  803. var name2 = UserTestReport[n].Name[1];
  804. if (name1[0].indexOf("英语") >= 0
  805. ||name1[0].indexOf("KET") >= 0
  806. ||name1[0].indexOf("单词") >= 0
  807. || name1[0].indexOf("1000") >= 0
  808. || name1[0].indexOf("2000") >= 0
  809. || name1[0].indexOf("4000") >= 0) {
  810. //console.log("英语");
  811. var wordStr = "";
  812. var userTestReportInfo = UserTestReport[n];
  813. var bookid = userTestReportInfo.BookID;
  814. var arrEnglist = [];
  815. if (bookid < 110) {
  816. if (name1[1] == "英文字母") {
  817. bookid = 100;
  818. 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";
  819. }
  820. } else if (bookid > 110 && bookid < 120) {
  821. arrEnglist = wx.getStorageSync("EnglishAll");
  822. arrEnglist = JSON.parse(arrEnglist);
  823. for (var i = 0; i < arrEnglist.length; i++) {
  824. if (arrEnglist[i].Name == name1[1]) {
  825. for (var j = 0; j < arrEnglist[i].Units.length; j++) {
  826. if (arrEnglist[i].Units[j].Name == name2) {
  827. wordStr = arrEnglist[i].Units[j].Words.join(",");
  828. break;
  829. }
  830. }
  831. }
  832. }
  833. }
  834. var tempRight = "," + userTestReportInfo.TestRightStr + ",";
  835. var tempWrong = "," + userTestReportInfo.TestWrongStr + ",";
  836. var tempSkip = "," + userTestReportInfo.TestSkipStr + ",";
  837. var tempExist = "," + userTestReportInfo.TestExistStr + ",";
  838. var unitsid = "";
  839. if (bookid > 100 && bookid < 110 && UserTestReport[n].Name[2]) {
  840. unitsid = Number(UserTestReport[n].Name[2]);
  841. } else if (bookid > 120 && bookid <= 124) {
  842. unitsid = Number(name2.replace("Lesson ", ""));
  843. } else if (bookid > 130 && bookid <= 170 && UserTestReport[n].Name[2]) {
  844. unitsid = Number(UserTestReport[n].Name[2]);
  845. }
  846. getData('GetTestEnglishWords?UserID=' + app.globalData.userInfo.UserID + '&BookID=' + bookid + '&LessonID=' + unitsid + '&Words=' + wordStr + "&TestType=" + userTestReportInfo.TestType, function (data) {
  847. if (data) {
  848. var result = {};
  849. result.ID = userTestReportInfo.ID;
  850. result.IsFinished = userTestReportInfo.IsFinished;
  851. result.Name = userTestReportInfo.Name.join("#");
  852. result.TestType = userTestReportInfo.TestType;
  853. result.BookID = bookid;
  854. var TaskList = [];
  855. var words = data;
  856. for (var k = 0; k < words.length; k++) {
  857. var taskInfo = words[k];
  858. if (userTestReportInfo.TestType == "read") {
  859. taskInfo.TagWidth = 212;
  860. if ((name1[0].indexOf("1000")<0) && (name1[0].indexOf("4000")<0))
  861. taskInfo.FontSize = 108;
  862. } else if (userTestReportInfo.TestType == "write") {
  863. taskInfo.TagWidth = 186;
  864. taskInfo.FontSize = 36;
  865. }
  866. taskInfo.ContentNew = changeStringToView(taskInfo.Content);
  867. if (tempRight.indexOf("," + taskInfo.Word + ",") >= 0)
  868. taskInfo.Result = 1;
  869. if (tempWrong.indexOf("," + taskInfo.Word + ",") >= 0)
  870. taskInfo.Result = -1;
  871. if (tempSkip.indexOf("," + taskInfo.Word + ",") >= 0)
  872. taskInfo.Result = 0;
  873. if (tempExist.indexOf("," + taskInfo.Word + ",") >= 0)
  874. taskInfo.Css = "Select2";
  875. TaskList.push(taskInfo);
  876. }
  877. result.TestRightStr = "";
  878. result.TestWrongStr = "";
  879. result.TestSkipStr = "";
  880. result.TestExistStr = "";
  881. if (userTestReportInfo.TestRightStr)
  882. result.TestRightStr = userTestReportInfo.TestRightStr;
  883. if (userTestReportInfo.TestWrongStr)
  884. result.TestWrongStr = userTestReportInfo.TestWrongStr;
  885. if (userTestReportInfo.TestSkipStr)
  886. result.TestSkipStr = userTestReportInfo.TestSkipStr;
  887. if (userTestReportInfo.TestExistStr)
  888. result.TestExistStr = userTestReportInfo.TestExistStr;
  889. result.List = TaskList;
  890. callback(result);
  891. } else {
  892. callback({});
  893. }
  894. });
  895. } else if (name1[1].indexOf("拼音") >= 0) {
  896. //console.log("拼音");
  897. var userTestReportInfo = UserTestReport[n];
  898. var bookid = userTestReportInfo.BookID;
  899. var tempRight = "," + userTestReportInfo.TestRightStr + ",";
  900. var tempWrong = "," + userTestReportInfo.TestWrongStr + ",";
  901. var tempSkip = "," + userTestReportInfo.TestSkipStr + ",";
  902. var tempExist = "," + userTestReportInfo.TestExistStr + ",";
  903. var unitsid = "";
  904. var name2 = userTestReportInfo.Name[1];
  905. if (bookid == 43) {
  906. switch (name2) {
  907. case "声母1":
  908. unitsid = 431;
  909. break;
  910. case "声母2":
  911. unitsid = 432;
  912. break;
  913. case "声母3":
  914. unitsid = 433;
  915. break;
  916. case "韵母1":
  917. unitsid = 434;
  918. break;
  919. case "韵母2":
  920. unitsid = 435;
  921. break;
  922. case "韵母3":
  923. unitsid = 436;
  924. break;
  925. case "整体认读1":
  926. unitsid = 437;
  927. break;
  928. case "整体认读2":
  929. unitsid = 438;
  930. break;
  931. }
  932. }
  933. getData('GetPinyinUnitWords?TestType='+userTestReportInfo.TestType+'&UserID=' + app.globalData.userInfo.UserID + '&BookID=' + bookid + '&UnitID=' + unitsid + '&Word=' + name2, function (data) {
  934. if (data) {
  935. var result = {};
  936. result.ID = userTestReportInfo.ID;
  937. result.IsFinished = userTestReportInfo.IsFinished;
  938. result.Name = userTestReportInfo.Name.join("#");
  939. result.TestType = userTestReportInfo.TestType;
  940. result.BookID = bookid;
  941. var TaskList = [];
  942. var words = data;
  943. for (var k = 0; k < words.length; k++) {
  944. var taskInfo = words[k];
  945. taskInfo.TagWidth = 230;
  946. taskInfo.FontSize = 108;
  947. taskInfo.ContentNew = changeStringToView(taskInfo.Content);
  948. if (tempRight.indexOf("," + taskInfo.Word + ",") >= 0)
  949. taskInfo.Result = 1;
  950. if (tempWrong.indexOf("," + taskInfo.Word + ",") >= 0)
  951. taskInfo.Result = -1;
  952. if (tempSkip.indexOf("," + taskInfo.Word + ",") >= 0)
  953. taskInfo.Result = 0;
  954. if (tempExist.indexOf("," + taskInfo.Word + ",") >= 0)
  955. taskInfo.Css = "Select2";
  956. TaskList.push(taskInfo);
  957. }
  958. result.TestRightStr = "";
  959. result.TestWrongStr = "";
  960. result.TestSkipStr = "";
  961. result.TestExistStr = "";
  962. if (userTestReportInfo.TestRightStr)
  963. result.TestRightStr = userTestReportInfo.TestRightStr;
  964. if (userTestReportInfo.TestWrongStr)
  965. result.TestWrongStr = userTestReportInfo.TestWrongStr;
  966. if (userTestReportInfo.TestSkipStr)
  967. result.TestSkipStr = userTestReportInfo.TestSkipStr;
  968. if (userTestReportInfo.TestExistStr)
  969. result.TestExistStr = userTestReportInfo.TestExistStr;
  970. result.List = TaskList;
  971. callback(result);
  972. } else {
  973. callback({});
  974. }
  975. });
  976. } else if (name2 == "古诗文") {
  977. //todo
  978. //console.log("古诗文");
  979. var userTestReportInfo = UserTestReport[n];
  980. var tempRight = "," + userTestReportInfo.TestRightStr + ",";
  981. var tempWrong = "," + userTestReportInfo.TestWrongStr + ",";
  982. var tempSkip = "," + userTestReportInfo.TestSkipStr + ",";
  983. var tempExist = "," + userTestReportInfo.TestExistStr + ",";
  984. getData('GetTestAncientPoetryList?UserID=' + app.globalData.userInfo.UserID + '&BookID=' + userTestReportInfo.BookID, function (data) {
  985. if (data) {
  986. var result = {};
  987. result.ID = userTestReportInfo.ID;
  988. result.IsFinished = userTestReportInfo.IsFinished;
  989. result.Name = userTestReportInfo.Name.join("#");
  990. result.TestType = userTestReportInfo.TestType;
  991. result.BookID = userTestReportInfo.BookID;
  992. var TaskList = [];
  993. for (var k = 0; k < data.length; k++) {
  994. var taskInfo = data[k];
  995. taskInfo.TagWidth = 336;
  996. if (taskInfo.Word.length > 9)
  997. taskInfo.FontSize = 48;
  998. else
  999. taskInfo.FontSize = 64;
  1000. taskInfo.ContentNew = changeStringToView(taskInfo.Content);
  1001. if (tempRight.indexOf("," + taskInfo.Word + ",") >= 0)
  1002. taskInfo.Result = 1;
  1003. if (tempWrong.indexOf("," + taskInfo.Word + ",") >= 0)
  1004. taskInfo.Result = -1;
  1005. if (tempSkip.indexOf("," + taskInfo.Word + ",") >= 0)
  1006. taskInfo.Result = 0;
  1007. if (tempExist.indexOf("," + taskInfo.Word + ",") >= 0)
  1008. taskInfo.Css = "Select2";
  1009. TaskList.push(taskInfo);
  1010. }
  1011. result.TestRightStr = "";
  1012. result.TestWrongStr = "";
  1013. result.TestSkipStr = "";
  1014. result.TestExistStr = "";
  1015. if (userTestReportInfo.TestRightStr)
  1016. result.TestRightStr = userTestReportInfo.TestRightStr;
  1017. if (userTestReportInfo.TestWrongStr)
  1018. result.TestWrongStr = userTestReportInfo.TestWrongStr;
  1019. if (userTestReportInfo.TestSkipStr)
  1020. result.TestSkipStr = userTestReportInfo.TestSkipStr;
  1021. if (userTestReportInfo.TestExistStr)
  1022. result.TestExistStr = userTestReportInfo.TestExistStr;
  1023. result.List = TaskList;
  1024. callback(result);
  1025. } else {
  1026. callback({});
  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 if (obj.BookID == 73)
  1034. name1 = name1[1].substr(2, 3) + name1[2];
  1035. else if (obj.BookID == 86)
  1036. name1 = name1[1] + name1[2];
  1037. else
  1038. name1 = name1[0] + name1[1].substr(2, 2) + "能力" + name1[2].substr(0, 1);
  1039. var HanziAll = wx.getStorageSync('HanziAll');
  1040. HanziAll = JSON.parse(HanziAll);
  1041. for (var i = 0; i < HanziAll.length; i++) {
  1042. if (name1 == HanziAll[i].Name) {
  1043. for (var j = 0; j < HanziAll[i].Units.length; j++) {
  1044. if (name2 == HanziAll[i].Units[j].Name) {
  1045. GetHanziUnitWords(HanziAll[i].Units[j].ID, obj.TestType, function (list) {
  1046. if (list) {
  1047. for (var k = 0; k < list.length; k++) {
  1048. if (obj.TestRightStr && obj.TestRightStr.indexOf(list[k].Word) >= 0)
  1049. list[k].Result = 1;
  1050. else if (obj.TestWrongStr && obj.TestWrongStr.indexOf(list[k].Word) >= 0)
  1051. list[k].Result = -1;
  1052. else if (obj.TestSkipStr && obj.TestSkipStr.indexOf(list[k].Word) >= 0)
  1053. list[k].Result = 0;
  1054. if (obj.TestExistStr && obj.TestExistStr.indexOf(list[k].Word) >= 0)
  1055. list[k].Css = "Select2";
  1056. }
  1057. var result = {};
  1058. result.ID = reportid;
  1059. result.BookID = obj.BookID;
  1060. result.TestType = obj.TestType;
  1061. result.Name = obj.Name.join("#");
  1062. result.IsFinished = obj.IsFinished;
  1063. result.TestRightStr = obj.TestRightStr;
  1064. result.TestWrongStr = obj.TestWrongStr;
  1065. result.TestSkipStr = obj.TestSkipStr;
  1066. result.TestExistStr = obj.TestExistStr;
  1067. result.List = list;
  1068. callback(result);
  1069. } else
  1070. callback({});
  1071. });
  1072. }
  1073. }
  1074. }
  1075. }
  1076. }
  1077. }
  1078. }
  1079. }
  1080. function getDetailColor(index) {
  1081. var arrDetailColor = constant.arrDetailColor;
  1082. if (index > 0)
  1083. return arrDetailColor[index];
  1084. else if (index == 0)
  1085. return arrDetailColor[common.random(1, arrDetailColor.length - 1)];
  1086. else if (index == -1)
  1087. return arrDetailColor;
  1088. }
  1089. function getShareImageBackColor() {
  1090. var arr = constant.arrShareImageBackColor;
  1091. return arr[common.random(0, arr.length - 1)];
  1092. }
  1093. function getPinyinNormal(pinyin) {
  1094. var result = "";
  1095. var arr = constant.arrPinyin;
  1096. for (var i = 0; i < arr.length; i++) {
  1097. if (arr[i][1] == pinyin) {
  1098. result = arr[i][0];
  1099. break;
  1100. }
  1101. }
  1102. return result;
  1103. }
  1104. function getHanzi(callback) {
  1105. var that = this;
  1106. wx.showLoading({
  1107. title: '请稍候',
  1108. mask: true,
  1109. });
  1110. var time = wx.getStorageSync("HanziUpdateTime");
  1111. getData('GetHanziAll3?UpdateTime=' + time, function (data) {
  1112. wx.hideLoading();
  1113. if (data) {
  1114. var arr = [];
  1115. if (data.List) {
  1116. arr = common.Decrypt(data.List);
  1117. wx.setStorageSync("HanziAll", arr);
  1118. wx.setStorageSync("HanziUpdateTime", data.UpdateTime);
  1119. callback(true);
  1120. } else {
  1121. callback(false);
  1122. }
  1123. }
  1124. });
  1125. }
  1126. function getServerSoundErrorArr(){
  1127. var time = wx.getStorageSync("SoundErrorUpdateTime");
  1128. getData('GetSoundErrorArr?UpdateTime=' + time, function (data) {
  1129. if (data && data.List) {
  1130. wx.setStorageSync("SoundErrorArr", data.List);
  1131. wx.setStorageSync("SoundErrorUpdateTime", data.UpdateTime);
  1132. }
  1133. });
  1134. }
  1135. function getEnglish(callback) {
  1136. var that = this;
  1137. wx.showLoading({
  1138. title: '请稍候',
  1139. mask: true,
  1140. });
  1141. var time = wx.getStorageSync("HanziUpdateTime");
  1142. getData('GetEnglishAll3?UpdateTime=' + time, function (data) {
  1143. wx.hideLoading();
  1144. if (data.EngList) {
  1145. var arrEng = common.Decrypt(data.EngList);
  1146. var arrNewConceptEngList = common.Decrypt(data.NewConceptEngList);
  1147. var arrCambridgeEngList = common.Decrypt(data.CambridgeEngList);
  1148. var arrEEWEngList = common.Decrypt(data.EEWEngList);
  1149. var arrCEWEngList = common.Decrypt(data.CEWEngList);
  1150. var arrBEWEngList = common.Decrypt(data.BEWEngList);
  1151. var arrMiddleSchoolTestWords = common.Decrypt(data.MiddleSchoolTestWords);
  1152. var arrPhoneticEngList = common.Decrypt(data.PhoneticEngList);
  1153. wx.setStorageSync("EnglishAll", arrEng);
  1154. wx.setStorageSync("NewConceptEngList", arrNewConceptEngList);
  1155. wx.setStorageSync("CambridgeEngList", arrCambridgeEngList);
  1156. wx.setStorageSync("EEWEngList", arrEEWEngList);
  1157. wx.setStorageSync("CEWEngList", arrCEWEngList);
  1158. wx.setStorageSync("BEWEngList", arrBEWEngList);
  1159. wx.setStorageSync("MiddleSchoolTestWords", arrMiddleSchoolTestWords);
  1160. wx.setStorageSync("PhoneticEngList", arrPhoneticEngList);
  1161. wx.setStorageSync("EnglishUpdateTime", data.UpdateTime);
  1162. callback(true);
  1163. } else {
  1164. callback(false);
  1165. }
  1166. });
  1167. }
  1168. function UploadUserConfig(callback) {
  1169. var that = this;
  1170. var param1 = {};
  1171. param1.CardType = wx.getStorageSync("CardType");
  1172. param1.CardMaxNumberNew = wx.getStorageSync("CardMaxNumberNew");
  1173. param1.CardMaxNumberHistory = wx.getStorageSync("CardMaxNumberHistory");
  1174. param1.CardMaxNumberNewUrgent = wx.getStorageSync("CardMaxNumberNewUrgent");
  1175. param1.CardMaxNumberHistoryUrgent = wx.getStorageSync("CardMaxNumberHistoryUrgent");
  1176. param1.SortTypeIndex = wx.getStorageSync("SortTypeIndex");
  1177. param1.MemoryLevel = wx.getStorageSync("MemoryLevel");
  1178. param1.ClickType = wx.getStorageSync("ClickType");
  1179. param1.SecondConfigArray = wx.getStorageSync("SecondConfigArray").join(",");
  1180. param1.ColorIndexArr = wx.getStorageSync("ColorIndexArr").join(",");
  1181. param1.IsFolderPractice = wx.getStorageSync("IsFolderPractice");
  1182. param1.IsAutoSound = wx.getStorageSync("IsAutoSound");
  1183. var symboMain = wx.getStorageSync("SymbolMain");
  1184. var symbol1 = [];
  1185. for (var i = 0; i < symboMain.length; i++) {
  1186. symbol1.push(symboMain[i].Name);
  1187. }
  1188. symbol1 = JSON.stringify(symbol1);
  1189. param1.SymbolList = symbol1;
  1190. var folderOrder = wx.getStorageSync("FolderOrderStr");
  1191. if (folderOrder)
  1192. param1.FolderOrder = folderOrder;
  1193. //console.log(param1);
  1194. that.postData('UploadUserConfig?Type=update&UserID=' + app.globalData.userInfo.UserID, param1, function (data) {
  1195. if (callback) {
  1196. callback();
  1197. }
  1198. });
  1199. }
  1200. function getAwardData(callback) {
  1201. var that = this;
  1202. that.getData('GetAwardInfo?UserID=' + app.globalData.userInfo.UserID, function (data) {
  1203. if (data) {
  1204. callback(data);
  1205. } else
  1206. callback([]);
  1207. });
  1208. }
  1209. function getUserConfig() {
  1210. var that = this;
  1211. postData('UploadUserConfig?Type=getData&UserID=' + app.globalData.userInfo.UserID, {}, function (data) {
  1212. if (data && !data.CardType)
  1213. data.CardType = 0;
  1214. wx.setStorageSync("CardType", data.CardType);
  1215. wx.setStorageSync("CardMaxNumberNew", data.CardMaxNumberNew);
  1216. wx.setStorageSync("CardMaxNumberHistory", data.CardMaxNumberHistory);
  1217. wx.setStorageSync("CardMaxNumberNewUrgent", data.CardMaxNumberNewUrgent);
  1218. wx.setStorageSync("CardMaxNumberHistoryUrgent", data.CardMaxNumberHistoryUrgent);
  1219. wx.setStorageSync("SortTypeIndex", data.SortTypeIndex);
  1220. wx.setStorageSync("MemoryLevel", data.MemoryLevel);
  1221. wx.setStorageSync("ClickType", data.ClickType);
  1222. wx.setStorageSync("SecondConfigArray", data.SecondConfigArray.split(","));
  1223. wx.setStorageSync("ColorIndexArr", data.ColorIndexArr.split(","));
  1224. wx.setStorageSync("FolderOrderStr", data.FolderOrder);
  1225. wx.setStorageSync("IsFolderPractice", data.IsFolderPractice);
  1226. wx.setStorageSync("IsAutoSound", data.IsAutoSound);
  1227. var symbol1 = [];
  1228. if (data.SymbolList) {
  1229. for (var i = 0; i < data.SymbolList.length; i++) {
  1230. var obj = {};
  1231. obj.Name = data.SymbolList[i];
  1232. obj.CSS = "btn2";
  1233. symbol1.push(obj);
  1234. }
  1235. } else {
  1236. symbol1 = app.globalData.SymbolMain;
  1237. }
  1238. if (symbol1.length > 0) {
  1239. wx.setStorageSync("SymboMain", symbol1);
  1240. app.globalData.SymbolMain = symbol1;
  1241. }
  1242. });
  1243. }
  1244. function replaceCardInfoString(str) {
  1245. var that = this;
  1246. //str = str.replace(/\[图]/g, "");
  1247. //str = str.replace(/\[\/图\]/g, "");
  1248. //console.log(str);
  1249. if (str && str!=null) {
  1250. var str2 = "";
  1251. if (str.indexOf("[读 src=") >= 0) {
  1252. str2 = str.substr(str.indexOf("[读 src="));
  1253. str2 = str2.substring(0, str2.indexOf("]") + 1);
  1254. }
  1255. str = str.replace(str2, "");
  1256. if (str.indexOf("[/读") >= 0) {
  1257. str2 = str.substr(str.indexOf("[/读"));
  1258. str2 = str2.substring(0, 4);
  1259. }
  1260. str = str.replace(str2, "");
  1261. if (str.indexOf("[读 src=") >= 0) {
  1262. str2 = str.substr(str.indexOf("[读 src"));
  1263. str2 = str2.substring(0, str2.indexOf("/读]") + 3);
  1264. }
  1265. str = str.replace(str2, "");
  1266. if (str.indexOf("[/读") >= 0) {
  1267. str2 = str.substr(str.indexOf("[/读"));
  1268. str2 = str2.substring(0, 4);
  1269. }
  1270. str = str.replace(str2, "");
  1271. str = str.replace(/\[读]/g, "");
  1272. str = str.replace(/\[\/读\]/g, "");
  1273. var str3 = "";
  1274. if (str.indexOf("[图") >= 0) {
  1275. str3 = str.substr(str.indexOf("[图"));
  1276. str3 = str3.substring(0, str3.indexOf("/图]") + 3);
  1277. }
  1278. str = str.replace(str3, "");
  1279. if (str.indexOf("[图") >= 0) {
  1280. str3 = str.substr(str.indexOf("[图"));
  1281. str3 = str3.substring(0, str3.indexOf("/图]") + 3);
  1282. }
  1283. str = str.replace(str3, "");
  1284. str = str.replace(/\[线]/g, "");
  1285. str = str.replace(/\[\/线\]/g, "");
  1286. str = that.encryptUrl(str);
  1287. }
  1288. return str;
  1289. }
  1290. function searchInfomation(search, searchtype, author, shiciurl, callback) {
  1291. var WORD_LENGTH = 18;
  1292. wx.showLoading({
  1293. title: '查询中',
  1294. });
  1295. var timeout = setTimeout(function () {
  1296. wx.hideLoading();
  1297. }, 5000);
  1298. var url = 'GetMiaoguoAISearch2?UserID=' + app.globalData.userInfo.UserID;
  1299. url += "&Word=" + encodeURI(search);
  1300. if (searchtype)
  1301. url += "&SearchType=" + searchtype;
  1302. if (author)
  1303. url += "&Author=" + encodeURI(author);
  1304. if (shiciurl)
  1305. url += "&ShiciUrl=" + shiciurl;
  1306. getData(url, function (data) {
  1307. wx.hideLoading();
  1308. clearTimeout(timeout);
  1309. if (data) {
  1310. //console.log(data);
  1311. if (data.List) {
  1312. var len = WORD_LENGTH;
  1313. var list = data.List;
  1314. for (var i = 0; i < list.length; i++) {
  1315. var item = list[i];
  1316. if (item.TypeName == "字词") {
  1317. if (item.Key.length == 1)
  1318. item.TypeName = "Z";
  1319. else
  1320. item.TypeName = "C";
  1321. } else if (item.TypeName == "诗词") {
  1322. item.TypeName = "S";
  1323. item.Remark = item.Author + " " + item.Dynasty;
  1324. } else if (item.TypeName == "翻译") {
  1325. item.TypeName = "D";
  1326. }
  1327. if (item.Content && item.Content.length > len)
  1328. item.Content = item.Content.substr(0, len) + "...";
  1329. }
  1330. callback(list);
  1331. } else if (data.CHN || data.ENG) {
  1332. var obj = {};
  1333. obj.Key = search;
  1334. obj.Value = data;
  1335. if (data.CHN && data.CHN.Author)
  1336. obj.Author = data.CHN.Author;
  1337. if (data.CHN && data.CHN.Dynasty)
  1338. obj.Dynasty = data.CHN.Dynasty;
  1339. if (data.CHN && data.CHN.PeomContent) {
  1340. obj.Type = "shici";
  1341. obj.TypeName = "诗词";
  1342. obj.Content = data.CHN.PeomContent.join("").substr(0, WORD_LENGTH);
  1343. obj.ShiciUrl = shiciurl;
  1344. obj.TypeName = "S";
  1345. } else if (data.CHN) {
  1346. obj.Type = "zici";
  1347. if (data.CHN.PinYin && data.CHN.PinYin[0] && data.CHN.PinYin[0].pinyin)
  1348. obj.Remark = data.CHN.PinYin[0].pinyin;
  1349. if (data.CHN.PinYin && data.CHN.PinYin[0] && data.CHN.PinYin[0].explain) {
  1350. obj.Content = data.CHN.PinYin[0].explain.substr(0, WORD_LENGTH);
  1351. obj.Content = obj.Content.replace("<p>", "");
  1352. obj.Content = obj.Content.replace("</p>", "");
  1353. if (obj.Content.length >= WORD_LENGTH)
  1354. obj.Content += "..."
  1355. }
  1356. if (obj.Key.length == 1)
  1357. obj.TypeName = "Z";
  1358. else
  1359. obj.TypeName = "C";
  1360. }
  1361. if (data.ENG && !data.CHN) {
  1362. obj.Type = "eng";
  1363. obj.TypeName = "D";
  1364. if (data.ENG.Soundmark && data.ENG.Soundmark.Eng)
  1365. obj.Remark = data.ENG.Soundmark.Eng;
  1366. if (data.ENG.Paraphrase.length > 0) {
  1367. if (common.checkIsArray(data.ENG.Paraphrase) && data.ENG.Paraphrase[0].ParaphraseList)
  1368. obj.Content = data.ENG.Paraphrase[0].ParaphraseList.join("; ").substr(0, WORD_LENGTH);
  1369. else
  1370. obj.Content = data.ENG.Paraphrase.substr(0, WORD_LENGTH) + "...";
  1371. }
  1372. }
  1373. app.globalData.TempSearchBackNumber = 2;
  1374. //app.globalData.CardList=[];
  1375. app.globalData.CardList2 = [];
  1376. callback([], obj);
  1377. } else {
  1378. callback([]);
  1379. }
  1380. } else {
  1381. callback([]);
  1382. }
  1383. });
  1384. }
  1385. function downloadBishunKaitiImage(url, serverUrl, dataType, Fields, callback) {
  1386. var param = {};
  1387. param.Url = url;
  1388. param.DataType = dataType;
  1389. if (param.Url == serverUrl) {
  1390. postData("GetBiShunByKaitiUrl", param, function (data) {
  1391. if (data) {
  1392. wx.downloadFile({
  1393. url: data, // 仅为示例,并非真实的资源
  1394. success(res) {
  1395. // 只要服务器有响应数据,就会把响应内容写入文件并进入 success 回调,业务需要自行判断是否下载到了想要的内容
  1396. if (res.statusCode === 200) {
  1397. //console.log("serverUrl2:" + serverUrl);
  1398. console.log(res.tempFilePath);
  1399. callback(change(Fields, res.tempFilePath, param));
  1400. }
  1401. },
  1402. complete() {
  1403. }
  1404. });
  1405. }
  1406. });
  1407. } else {
  1408. callback(change(Fields, serverUrl, param));
  1409. }
  1410. function change(Fields, filepath, param) {
  1411. var iStart = 0;
  1412. if (Fields.length == 4)
  1413. iStart = 1
  1414. for (var i = iStart; i < Fields.length; i++) {
  1415. for (var j = 0; j < Fields[i].length; j++) {
  1416. if (Fields[i][j].Type == "image") {
  1417. if (Fields[i][j].Content == param.Url) {
  1418. Fields[i][j].Content = filepath;
  1419. if (param.DataType == "bishun") {
  1420. Fields[i][j].IsShowKaiti = true;
  1421. Fields[i][j].IsShowBishun = false;
  1422. } else if (param.DataType == "kaiti") {
  1423. Fields[i][j].IsShowKaiti = false;
  1424. Fields[i][j].IsShowBishun = true;
  1425. }
  1426. }
  1427. }
  1428. }
  1429. }
  1430. return Fields;
  1431. }
  1432. }
  1433. function GetSoundError(str) {
  1434. var result = str;
  1435. var arr = wx.getStorageSync('SoundErrorArr');
  1436. if (arr && arr.length>0){
  1437. for (var i = 0; i < arr.length; i++) {
  1438. if (str.indexOf(arr[i].Word) > 0) {
  1439. result = common.ReplaceAllString(str, arr[i].Word, arr[i].Sound);
  1440. break;
  1441. } else if (str == arr[i].Word) {
  1442. result = arr[i].Sound;
  1443. }
  1444. }
  1445. }
  1446. return result;
  1447. }
  1448. function GetTestReportList(userID, callback) {
  1449. getData('GetTestGradeArr', function (GradeArr) {
  1450. for (var i = 0; i < GradeArr.length; i++) {
  1451. for (var j = 0; j < GradeArr[i].List.length; j++) {
  1452. GradeArr[i].List[j].Finish = 0;
  1453. }
  1454. }
  1455. getData('GetTestReportList?UserID=' + userID, function (data) {
  1456. if (data) {
  1457. var dataTemp = [];
  1458. for (var i = 0; i < data.length; i++) {
  1459. for (var j = 0; j < dataTemp.length; j++) {
  1460. if (dataTemp[j].Name[0] == data[i].Name[0] &&
  1461. dataTemp[j].Name[1] == data[i].Name[1] &&
  1462. dataTemp[j].TestType == data[i].TestType &&
  1463. data[i].IsFinished == 1
  1464. ) {
  1465. dataTemp.splice(j, 1);
  1466. break;
  1467. }
  1468. }
  1469. dataTemp.push(data[i]);
  1470. if (data[i].Name[0].indexOf("英语") >= 0
  1471. || data[i].Name[0].indexOf("单词") >= 0
  1472. || data[i].Name[0].indexOf("KET") >= 0
  1473. || data[i].Name[0].indexOf("1000") >= 0
  1474. || data[i].Name[0].indexOf("2000") >= 0
  1475. || data[i].Name[0].indexOf("4000") >= 0
  1476. || data[i].Name[0].indexOf("语文词语") >= 0
  1477. || data[i].Name[0].indexOf("识字 上学期") >= 0
  1478. || data[i].Name[0].indexOf("拼音") >= 0
  1479. || data[i].Name[1].indexOf("古诗文") >= 0
  1480. || data[i].Name[0].indexOf("文言文") >= 0
  1481. || data[i].Name[0].indexOf("小古文") >= 0) {
  1482. if (data[i].TestRightStr) {
  1483. data[i].TestRightStr = data[i].TestRightStr.split(",");
  1484. }
  1485. if (data[i].TestWrongStr) {
  1486. data[i].TestWrongStr = data[i].TestWrongStr.split(",");
  1487. }
  1488. if (data[i].TestSkipStr) {
  1489. data[i].TestSkipStr = data[i].TestSkipStr.split(",");
  1490. }
  1491. if (data[i].TestExistStr) {
  1492. data[i].TestExistStr = data[i].TestExistStr.split(",");
  1493. }
  1494. }
  1495. if (!data[i].TestRightStr)
  1496. data[i].TestRightStr = "";
  1497. if (!data[i].TestWrongStr)
  1498. data[i].TestWrongStr = "";
  1499. if (!data[i].TestSkipStr)
  1500. data[i].TestSkipStr = "";
  1501. if (!data[i].TestExistStr)
  1502. data[i].TestExistStr = "";
  1503. }
  1504. for (var i = 0; i < dataTemp.length; i++) {
  1505. var name = dataTemp[i].Name[0].split(" ");
  1506. for (var j = 0; j < GradeArr.length; j++) {
  1507. var item = GradeArr[j];
  1508. if (name[0] == item.Name) {
  1509. for (var k = 0; k < item.List.length; k++) {
  1510. //音标计算进度
  1511. if (item.List[k].ID == 101 && dataTemp[i].BookID == 101) {
  1512. for (var n = 1; n <= 4; n++) {
  1513. if (Number(dataTemp[i].Name[2]) == n && dataTemp[i].IsFinished == 1)
  1514. item.List[k].Finish++;
  1515. }
  1516. }
  1517. //古诗词计算进度
  1518. else if (item.List[k].ID == dataTemp[i].BookID && dataTemp[i].TestType == "recite" && dataTemp[i].IsFinished == 1)
  1519. item.List[k].Finish = 1;
  1520. else {
  1521. if (name[1] == item.List[k].Name && name[2] == item.List[k].Name2) {
  1522. if (dataTemp[i].IsFinished == 1)
  1523. item.List[k].Finish++;
  1524. }
  1525. }
  1526. }
  1527. }
  1528. }
  1529. }
  1530. for (var j = 0; j < GradeArr.length; j++) {
  1531. var item = GradeArr[j];
  1532. for (var k = 0; k < item.List.length; k++) {
  1533. item.List[k].Finished = Math.round(100 * item.List[k].Finish / item.List[k].Total);
  1534. item.List[k].NameStr = item.List[k].Name.replace("语文", "");
  1535. }
  1536. }
  1537. wx.setStorageSync("UserTestReport", data);
  1538. callback(data, GradeArr);
  1539. }
  1540. });
  1541. });
  1542. }
  1543. function showHelp(obj,myClass,textTopDirection,helpText,closePos){
  1544. setTimeout(function(){
  1545. wx.createSelectorQuery().select(myClass).boundingClientRect(function (rect) {
  1546. console.log("rect.left:"+rect.left);
  1547. console.log("rect.top:"+rect.top);
  1548. console.log("rect.width:"+rect.width);
  1549. console.log("rect.height:"+rect.height);
  1550. var textTop=rect.bottom+5;
  1551. if (textTopDirection=="up")
  1552. textTop=rect.top-47;
  1553. if (!closePos)
  1554. closePos="Right";
  1555. obj.setData({
  1556. HelpTop:rect.top,
  1557. HelpWidth1:rect.left,
  1558. HelpHeight1:rect.height,
  1559. HelpLeft2:rect.right,
  1560. HelpHeight2:rect.height,
  1561. HelpBottom:rect.bottom-1,
  1562. HelpTextTop:textTop,
  1563. HelpText:helpText,
  1564. HelpClosePos:closePos,
  1565. });
  1566. }).exec();
  1567. },500);
  1568. }
  1569. function gotoTaskList(id,cardType) {
  1570. wx.showLoading({
  1571. title: '请稍候',
  1572. });
  1573. setTimeout(function () {
  1574. wx.hideLoading();
  1575. }, 5000);
  1576. var that = this;
  1577. //未练完的题卡
  1578. if (id == 1) {
  1579. getTaskTodayList(function (task) {
  1580. var list = [];
  1581. for (var i = 0; i < task.ListNew.length; i++) {
  1582. list.push(task.ListNew[i]);
  1583. }
  1584. for (var i = 0; i < task.ListHistory.length; i++) {
  1585. list.push(task.ListHistory[i]);
  1586. }
  1587. for (var i = 0; i < task.ListReview.length; i++) {
  1588. list.push(task.ListReview[i]);
  1589. }
  1590. app.globalData.CardList = list;
  1591. wx.navigateTo({
  1592. url: '../main/mainlist?type=1&Count=' + list.length,
  1593. });
  1594. });
  1595. } else {
  1596. var url = 'GetMiaoguoCardList2?UserID=' + app.globalData.userInfo.UserID + "&IsToday=2&CardType="+ cardType +"&OrderType=ac.LastTime desc";
  1597. getData(url, function (data) {
  1598. if (data) {
  1599. var list = [];
  1600. for (var i = 0; i < data.List.length; i++) {
  1601. data.List[i].LastTimeStr = common.formatDateCHS(data.List[i].LastTime);
  1602. list.push(data.List[i]);
  1603. }
  1604. app.globalData.CardList = list;
  1605. wx.navigateTo({
  1606. url: '../main/mainlist?type=2&Count=' + data.length,
  1607. });
  1608. }
  1609. });
  1610. }
  1611. }
  1612. function resetTodayTask(){
  1613. wx.showModal({
  1614. title: '提醒',
  1615. content: '此操作无法撤销。确认重置今天的任务量吗?',
  1616. showCancel:true,
  1617. cancelText:"确定",
  1618. confirmColor:"#000000",
  1619. confirmText:"取消",
  1620. success (res) {
  1621. if (res.confirm) {
  1622. //console.log('用户点击取消');
  1623. } else if (res.cancel) {
  1624. //console.log('用户点击确定')
  1625. var url = "ResetMiaoguoCardTask?UserID=" + app.globalData.userInfo.UserID;
  1626. getData(url, function (data) {
  1627. if (data) {
  1628. wx.showModal({
  1629. title: '提醒',
  1630. content: '重置已完成。请重新开始今天的练习吧。',
  1631. showCancel:false,
  1632. confirmColor:"#000000",
  1633. confirmText:"返回首页",
  1634. success (res) {
  1635. wx.navigateBack({
  1636. delta: 2,
  1637. });
  1638. }
  1639. });
  1640. }
  1641. });
  1642. }
  1643. }
  1644. });
  1645. }
  1646. //下载图片
  1647. function downloadFile(url,isShowLoading,callback){
  1648. if (isShowLoading){
  1649. wx.showLoading({
  1650. title: '下载中',
  1651. });
  1652. setTimeout(function () {
  1653. wx.hideLoading();
  1654. }, 5000);
  1655. }
  1656. wx.downloadFile({
  1657. url: url,
  1658. success(resDownload) {
  1659. // 只要服务器有响应数据,就会把响应内容写入文件并进入 success 回调,业务需要自行判断是否下载到了想要的内容
  1660. if (resDownload.statusCode === 200) {
  1661. callback(resDownload.tempFilePath);
  1662. }
  1663. else if (resDownload.statusCode === 404){
  1664. wx.showToast({
  1665. title: '图片不存在',
  1666. });
  1667. }
  1668. if (isShowLoading)
  1669. wx.hideLoading();
  1670. },
  1671. fail: function (e) {
  1672. if (isShowLoading)
  1673. wx.hideLoading();
  1674. wx.showToast({
  1675. title: '下载失败',
  1676. });
  1677. }
  1678. });
  1679. }
  1680. //生成图片
  1681. function buildImage(width,height,canvas,callback){
  1682. var that=this;
  1683. wx.showLoading({
  1684. title: '生成中',
  1685. });
  1686. setTimeout(function () {
  1687. //console.log("生成后1");
  1688. wx.canvasToTempFilePath({
  1689. x: 0,
  1690. y: 0,
  1691. width: width,
  1692. height: height,
  1693. destWidth: width,
  1694. destHeight: height,
  1695. canvas: canvas,
  1696. success: function (res2) {
  1697. wx.hideLoading();
  1698. //console.log("生成后2");
  1699. wx.previewImage({
  1700. current: res2.tempFilePath, // 当前显示图片的http链接
  1701. urls: [res2.tempFilePath] // 需要预览的图片http链接列表
  1702. });
  1703. callback();
  1704. },
  1705. fail: function (e) {
  1706. wx.hideLoading();
  1707. //console.log("生成错误:"+e);
  1708. }
  1709. })
  1710. }, 500);
  1711. }
  1712. function showHelpImage() {
  1713. var arr=[];
  1714. arr.push(app.globalData.uploadImageUrl+"web/doc_xnl_36_1.png")
  1715. arr.push(app.globalData.uploadImageUrl+"web/doc_xnl_36_2.png")
  1716. wx.previewImage({
  1717. current: arr[0],
  1718. urls: arr,
  1719. });
  1720. }
  1721. module.exports = {
  1722. getData: getData,
  1723. postData: postData,
  1724. payMoney: payMoney,
  1725. getLocalHost: getLocalHost,
  1726. getTimeFormat: getTimeFormat,
  1727. getWindowHeight: getWindowHeight,
  1728. getStorageValue: getStorageValue,
  1729. getProgramList: getProgramList,
  1730. gotoFeedback: gotoFeedback,
  1731. getDetailColor: getDetailColor,
  1732. changeStringToView: changeStringToView,
  1733. changeViewToString: changeViewToString,
  1734. encryptUrl: EncryptUrl,
  1735. decryptUrl: DecryptUrl,
  1736. saveTempImage: saveTempImage,
  1737. getTempImage: getTempImage,
  1738. getTaskTodayList: getTaskTodayList,
  1739. updateSearchList: updateSearchList,
  1740. checkIsIPhoneX: checkIsIPhoneX,
  1741. getMemoryLevelAll: getMemoryLevelAll,
  1742. getMemoryLevel: getMemoryLevel,
  1743. getShareImageBackColor: getShareImageBackColor,
  1744. UpdateMiaoguoCardTodayAll: UpdateMiaoguoCardTodayAll,
  1745. setCollect: setCollect,
  1746. UploadUserConfig: UploadUserConfig,
  1747. getServerImage: getServerImage,
  1748. getBaiduToken: getBaiduToken,
  1749. getPinyinNormal: getPinyinNormal,
  1750. getHanzi: getHanzi,
  1751. getEnglish: getEnglish,
  1752. GetHanziUnitWords: GetHanziUnitWords,
  1753. GetTestReportInfo: GetTestReportInfo,
  1754. getUserConfig: getUserConfig,
  1755. getAwardData: getAwardData,
  1756. replaceCardInfoString: replaceCardInfoString,
  1757. searchInfomation: searchInfomation,
  1758. downloadBishunKaitiImage: downloadBishunKaitiImage,
  1759. GetSoundError: GetSoundError,
  1760. GetTestReportList: GetTestReportList,
  1761. ShowHelp:showHelp,
  1762. GotoTaskList:gotoTaskList,
  1763. ResetTodayTask:resetTodayTask,
  1764. DownloadFile:downloadFile,
  1765. BuildImage:buildImage,
  1766. ShowHelpImage:showHelpImage,
  1767. getServerSoundErrorArr:getServerSoundErrorArr,
  1768. }