main.js 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514
  1. import common from '../utils/util';
  2. import constant from '../utils/constant';
  3. var app = getApp();
  4. var dataSendTimeout = 0;
  5. function getData(url, callback) {
  6. if (!app.globalData.IsProduction)
  7. console.log("加密前的结果为===", url);
  8. var url = common.Encrypt(url);
  9. //console.log("加密后的结果为===",url);
  10. wx.request({
  11. url: app.globalData.serverUrl + url,
  12. success: function (res) {
  13. if (res.statusCode)
  14. common.checkError(res.statusCode);
  15. var data = res.data.result;
  16. callback(data);
  17. },
  18. fail: function () {
  19. wx.showToast({
  20. title: '系统忙请稍候',
  21. // image: "../images/universalpic_warning_white_126x120.png",
  22. duration: 3000
  23. });
  24. },
  25. });
  26. }
  27. function postData(url, postData, callback) {
  28. var url = common.Encrypt(url);
  29. //console.log("加密后的结果为===",url);
  30. wx.request({
  31. url: app.globalData.serverUrl + url,
  32. method: "POST",
  33. data: postData,
  34. success: function (res) {
  35. if (res.statusCode)
  36. common.checkError(res.statusCode);
  37. var data = res.data.result;
  38. callback(data);
  39. },
  40. fail: function () {
  41. wx.showToast({
  42. title: '系统忙请稍候',
  43. duration: 3000
  44. });
  45. },
  46. });
  47. }
  48. function getLocalHost(callback) {
  49. if (!app.globalData.IsProduction) {
  50. var url = common.Encrypt("Ping");
  51. wx.request({
  52. url: app.globalData.serverUrlLocalhost + url,
  53. success: function (res) {
  54. app.globalData.serverUrl = app.globalData.serverUrlLocalhost;
  55. callback();
  56. },
  57. fail: function () {
  58. app.globalData.serverUrl = app.globalData.serverUrlServer;
  59. callback();
  60. },
  61. });
  62. } else {
  63. app.globalData.serverUrl = app.globalData.serverUrlServer;
  64. callback();
  65. }
  66. }
  67. function getBaiduToken() {
  68. getData('GetBaiduToken', function (data) {
  69. if (data) {
  70. app.globalData.BaiduToken = data;
  71. //console.log(app.globalData.BaiduToken);
  72. }
  73. });
  74. }
  75. function payMoney(payType, remark, money, detail, callback) {
  76. console.log(money);
  77. if (app.globalData.userInfo.UserID < 8 ||
  78. app.globalData.userInfo.UserID == 3089)
  79. money = 0.01;
  80. //登录认证
  81. wx.login({
  82. success: function (res) {
  83. if (res.code) {
  84. console.log('获取用户登录态成功!' + res.code);
  85. //预支付
  86. getData('ProductPayLogin500?code=' + res.code + '&payType=' + payType + '&money=' + money + '&detail=' + detail + '&productID=' + app.globalData.ProgramID + '&Remark=' + remark, function (data) {
  87. if (data && data.timeStamp) {
  88. //微信支付
  89. wx.requestPayment({
  90. 'timeStamp': data.timeStamp.toString(),
  91. 'nonceStr': data.nonceStr,
  92. 'package': data.package,
  93. 'signType': 'MD5',
  94. 'paySign': data.paySign,
  95. 'success': function (res3) {
  96. console.log("success:" + res3);
  97. callback(data);
  98. },
  99. 'fail': function (err) {
  100. if (err && err.errMsg && err.errMsg.indexOf("fail cancel")) {
  101. } else {
  102. wx.showToast({
  103. title: '系统忙请稍候',
  104. duration: 3000
  105. });
  106. }
  107. }
  108. });
  109. }
  110. });
  111. } else {
  112. console.log('获取用户登录态失败!' + res.errMsg);
  113. wx.showToast({
  114. title: '系统忙请稍候',
  115. duration: 3000
  116. });
  117. }
  118. }
  119. });
  120. }
  121. function getTimeFormat(duration) {
  122. //console.log("duration:" + duration);
  123. var arr = ['', '', '']
  124. if (duration.indexOf("'") > 0)
  125. arr[0] = duration.substring(0, duration.indexOf("'"));
  126. if (duration.indexOf(".") > 0) {
  127. arr[1] = duration.substring(duration.indexOf("'") + 1, duration.indexOf(".") + 1);
  128. arr[2] = duration.substring(duration.indexOf(".") + 1, duration.indexOf('"'));
  129. } else {
  130. arr[1] = duration.substring(duration.indexOf("'") + 1, duration.indexOf('"'));
  131. }
  132. return arr;
  133. }
  134. function getWindowHeight() {
  135. var height = app.globalData.systemInfo.windowHeight;
  136. //console.log("app.globalData.systemInfo.windowHeight:" + app.globalData.systemInfo.windowHeight * 2);
  137. if (app.globalData.systemInfo.model) {
  138. if (height == 504 && (
  139. app.globalData.systemInfo.model.indexOf("iPhone 6<") >= 0 ||
  140. app.globalData.systemInfo.model.indexOf("iPhone 7<") >= 0 ||
  141. app.globalData.systemInfo.model.indexOf("iPhone 6s<") >= 0 ||
  142. app.globalData.systemInfo.model.indexOf("iPhone 5") >= 0 ||
  143. app.globalData.systemInfo.model.indexOf("iPhone SE") >= 0
  144. )) {
  145. height = 596;
  146. } else if (app.globalData.systemInfo.model.indexOf("iPad") >= 0) {
  147. height = 470;
  148. }
  149. }
  150. height = height * 2;
  151. if (app.globalData.systemInfo.system && app.globalData.systemInfo.system.indexOf("Android") >= 0) {
  152. height = height + 168;
  153. } else {
  154. height = height + 50;
  155. }
  156. //console.log("height:" + height);
  157. //var height = app.globalData.systemInfo.screenHeight * 2;
  158. return height;
  159. }
  160. //获取存储数据,若不存在,则获得缺省值。
  161. function getStorageValue(obj, name, defaultStatus, callback) {
  162. wx.getStorage({
  163. key: name,
  164. success: function (res) {
  165. obj.data[name] = res.data;
  166. obj.setData(obj.data);
  167. callback();
  168. },
  169. fail: function (res) {
  170. obj.data[name] = defaultStatus;
  171. obj.setData(obj.data);
  172. callback();
  173. },
  174. });
  175. }
  176. function getProgramList() {
  177. return [{
  178. id: 89,
  179. appId: 'wx46a7b4c420e6d38f',
  180. path: 'pages/index/start?SourceID=' + app.globalData.ProgramID,
  181. },
  182. {
  183. id: 98,
  184. appId: 'wx331e8dd070f01d0e',
  185. path: 'pages/index/index?SourceID=' + app.globalData.ProgramID,
  186. },
  187. {
  188. id: 99,
  189. appId: 'wxb54a6d5aff836ee3',
  190. path: 'pages/index/index?SourceID=' + app.globalData.ProgramID,
  191. },
  192. {
  193. id: 106,
  194. appId: 'wx313a8f2c0741efe1',
  195. path: 'pages/index/index?SourceID=' + app.globalData.ProgramID,
  196. },
  197. ];
  198. }
  199. function gotoFeedback() {
  200. wx.navigateToMiniProgram({
  201. appId: "wx80059777521b897c",
  202. path: "pages/index/feedback",
  203. extraData: {},
  204. success(res) {
  205. // 打开成功
  206. }
  207. });
  208. }
  209. function changeViewToString(content) {
  210. var str = content;
  211. if (str.constructor == Array) {
  212. if (str.length > 0)
  213. str = str.join(",");
  214. else
  215. str = "";
  216. }
  217. if (!str)
  218. str = ""
  219. else {
  220. str = str.replace(/\n\n\n/g, "\n\n");
  221. if (str.indexOf("\n") == 0 && str.indexOf("[") == 1) {
  222. str = str.substr(1);
  223. }
  224. if (str.lastIndexOf("\n") == str.length - 1) {
  225. str = str.substr(0, str.length - 1);
  226. }
  227. }
  228. return str;
  229. }
  230. function EncryptUrl(str) {
  231. if (str && str.constructor && str.constructor == Array) {
  232. if (str.length > 0)
  233. str = str.join(",");
  234. else
  235. str = "";
  236. }
  237. if (str) {
  238. str = str.replace(/baidu.com/g, "#####1#####");
  239. str = str.replace(/iciba.com/g, "#####2#####");
  240. str = str.replace(/https:\/\/pinyin.kylx365.com\/sounds/g, "#####3#####");
  241. str = str.replace(/https:\/\/miaguo-1253256735.file.myqcloud.com/g, "#####4#####");
  242. if (str.substr(0, 1) == "\n")
  243. str = str.substr(1);
  244. }
  245. return str;
  246. }
  247. function DecryptUrl(str) {
  248. if (str.constructor == Array) {
  249. if (str.length > 0)
  250. str = str.join(",");
  251. else
  252. str = "";
  253. }
  254. if (str) {
  255. str = str.replace(/#####1#####/g, "baidu.com");
  256. str = str.replace(/#####2#####/g, "iciba.com");
  257. str = str.replace(/#####3#####/g, "https://pinyin.kylx365.com/sounds");
  258. str = str.replace(/#####4#####/g, "https://miaguo-1253256735.file.myqcloud.com");
  259. }
  260. return str;
  261. }
  262. function changeStringToView(field) {
  263. var result = {};
  264. result.Field = [
  265. []
  266. ];
  267. result.Images = [];
  268. for (var j = 0; j < field.length; j++) {
  269. if (j == 0) {
  270. if (field[j].ContentType == 0 && field[j].Content && field[j].Content.length > 0) {
  271. result.Tags = field[j].Content.toString().split(",");
  272. } else {
  273. result.Tags = [];
  274. }
  275. } else {
  276. if (field[j].ContentType == j && field[j].Content && field[j].Content.length > 0) {
  277. var arrResult = [],
  278. arrSoundMark = [];
  279. var str = field[j].Content.toString();
  280. str = DecryptUrl(str);
  281. if (str.indexOf("[读") > 0)
  282. str = str.replace(/\[读/g, "\n[读");
  283. str = str.replace(/\[图/g, "\n[图");
  284. if (str.indexOf("[音") > 0)
  285. str = str.replace(/\[音/g, "\n[音");
  286. str = str.replace(/\[\/读\]/g, "[\/读]\n");
  287. str = str.replace(/\[\/图\]/g, "[\/图]\n");
  288. str = str.replace(/\[\/音\]/g, "[\/音]\n");
  289. str = str.replace(/\n\n\n/g, "\n\n");
  290. var arr = str.split("\n");
  291. for (var k = 0; k < arr.length; k++) {
  292. if (arr[k].indexOf("[图") >= 0 && arr[k].indexOf("[/图]") > 0) {
  293. var obj = {};
  294. obj.Type = "image";
  295. if (arr[k].indexOf("[图") >= 0) {
  296. obj.ContentServer = arr[k].substring(arr[k].indexOf("[图") + 3, arr[k].indexOf("[/图]"));
  297. const w = 650;
  298. if (obj.ContentServer.indexOf("w='") >= 0 && obj.ContentServer.indexOf("h='") >= 0) {
  299. obj.Width = obj.ContentServer.substring(obj.ContentServer.indexOf("w='") + 3, obj.ContentServer.indexOf("h='") - 2);
  300. obj.Height = obj.ContentServer.substring(obj.ContentServer.indexOf("h='") + 3, obj.ContentServer.indexOf("']"));
  301. obj.Height = Math.round((w * Number(obj.Height)) / Number(obj.Width));
  302. obj.Width = w;
  303. } else {
  304. obj.Width = "";
  305. obj.Height = "";
  306. }
  307. obj.ContentServer = obj.ContentServer.substring(obj.ContentServer.indexOf("]") + 1);
  308. obj.Content = getTempImage(obj.ContentServer);
  309. if (obj.Content.lastIndexOf("fm=58")>=0)
  310. obj.IsShowBishun=true;
  311. else if (obj.Content.indexOf("hanyu-word-gif")>0)
  312. obj.IsShowKaiti=true;
  313. result.Images.push(obj.Content);
  314. }
  315. arrResult.push(obj);
  316. } else if ((arr[k].indexOf("[线]") >= 0 && arr[k].indexOf("[/线]") > 0) || (arr[k].indexOf("[光]") >= 0 && arr[k].indexOf("[/光]") > 0)) {
  317. var obj;
  318. var content = [],
  319. temp = arr[k];
  320. do {
  321. var num1 = temp.indexOf("[线]");
  322. var num2 = temp.indexOf("[光]");
  323. if (num1 >= 0 || num2 >= 0) {
  324. if ((num1 < num2 && num1 >= 0 && num2 >= 0) || (num1 >= 0 && num2 < 0)) {
  325. var temp1 = temp.substring(0, temp.indexOf("[线]"));
  326. if (temp1) {
  327. content.push({
  328. key: "normal",
  329. value: temp1,
  330. });
  331. } else {
  332. if (temp && temp.indexOf("[线]") < 0) {
  333. content.push({
  334. key: "normal",
  335. value: temp,
  336. });
  337. temp = "";
  338. }
  339. }
  340. } else if ((num1 > num2 && num1 >= 0 && num2 >= 0) || (num1 < 0 && num2 >= 0)) {
  341. var temp1 = temp.substring(0, temp.indexOf("[光]"));
  342. if (temp1) {
  343. content.push({
  344. key: "normal",
  345. value: temp1,
  346. });
  347. } else {
  348. if (temp && temp.indexOf("[光]") < 0) {
  349. content.push({
  350. key: "normal",
  351. value: temp,
  352. });
  353. temp = "";
  354. }
  355. }
  356. } else {
  357. content.push({
  358. key: "normal",
  359. value: temp,
  360. });
  361. temp = "";
  362. }
  363. } else {
  364. content.push({
  365. key: "normal",
  366. value: temp,
  367. });
  368. temp = "";
  369. }
  370. if (temp.length > 0 && (num1 >= 0 || num2 >= 0)) {
  371. if ((num1 < num2 && num1 >= 0 && num2 >= 0) || (num1 >= 0 && num2 < 0)) {
  372. temp = temp.substr(temp.indexOf("[线]") + 3);
  373. temp1 = temp.substring(0, temp.indexOf("[/线]"));
  374. if (temp1) {
  375. content.push({
  376. key: "line",
  377. value: temp1,
  378. });
  379. }
  380. temp = temp.substr(temp.indexOf("[/线]") + 4);
  381. } else if ((num1 > num2 && num1 >= 0 && num2 >= 0) || (num1 < 0 && num2 >= 0)) {
  382. temp = temp.substr(temp.indexOf("[光]") + 3);
  383. temp1 = temp.substring(0, temp.indexOf("[/光]"));
  384. if (temp1) {
  385. content.push({
  386. key: "highlighter",
  387. value: temp1,
  388. });
  389. }
  390. temp = temp.substr(temp.indexOf("[/光]") + 4);
  391. } else
  392. temp = "";
  393. } else
  394. temp = "";
  395. }
  396. while (temp.length > 0);
  397. obj = {};
  398. obj.Type = "line";
  399. obj.Content = content;
  400. arrResult.push(obj);
  401. } else if (arr[k].indexOf("[读") >= 0 && arr[k].indexOf("[/读]") > 0) {
  402. var obj = {};
  403. obj.Type = "sound";
  404. if (arr[k].indexOf("[读]") >= 0) {
  405. obj.Content = arr[k].substring(arr[k].indexOf("[读]") + 3, arr[k].indexOf("[/读]"));
  406. } else {
  407. var tempIndex = arr[k].indexOf("\']") + 2;
  408. obj.Content = arr[k].substring(tempIndex, arr[k].indexOf("[/读]"));
  409. obj.SoundMark = arr[k].substring(arr[k].indexOf("src='") + 5, arr[k].indexOf("']"));;
  410. }
  411. arrResult.push(obj);
  412. } else if (arr[k].indexOf("[音") >= 0 && arr[k].indexOf("[/音]") > 0) {
  413. var obj = {};
  414. obj.Type = "recorder";
  415. var tempIndex = arr[k].indexOf("\']") + 2;
  416. //obj.Content = arr[k].substring(tempIndex, arr[k].indexOf("[/音]"));
  417. obj.SoundMark = arr[k].substring(arr[k].indexOf("url='") + 5, arr[k].indexOf("']"));;
  418. arrResult.push(obj);
  419. } else if (arr[k] != "") {
  420. var obj = {};
  421. obj.Type = "normal";
  422. obj.Content = arr[k];
  423. arrResult.push(obj);
  424. } else if (k > 0 && arr[k] == "") {
  425. var obj = {};
  426. obj.Type = "br";
  427. obj.Content = "";
  428. arrResult.push(obj);
  429. }
  430. var obj = {};
  431. obj.Type = "return";
  432. arrResult.push(obj);
  433. }
  434. //去掉前回车换行
  435. // while (arrResult[0].Type == "return" ||
  436. // arrResult[0].Type == "br") {
  437. // arrResult.shift();
  438. // if (arrResult.length == 0)
  439. // break;
  440. // }
  441. //去掉后回车换行
  442. for (var i = arrResult.length - 1; i >= 0; i--) {
  443. if (arrResult[i].Type == "return" ||
  444. arrResult[i].Type == "br")
  445. arrResult.pop();
  446. else {
  447. break;
  448. }
  449. }
  450. result.Field.push(arrResult);
  451. } else {
  452. result.Field.push([]);
  453. }
  454. }
  455. }
  456. return result;
  457. }
  458. //得到当天任务
  459. function getTaskTodayList(callback) {
  460. var isNotData = true;
  461. var intervalTask = setTimeout(function () {
  462. if (isNotData) {
  463. wx.showLoading({
  464. title: '请稍候',
  465. mask: true,
  466. });
  467. setTimeout(function () {
  468. wx.hideLoading();
  469. }, 60000);
  470. }
  471. }, 2000);
  472. var that = this;
  473. var url = 'GetMiaoguoCardToday2?UserID=' + app.globalData.userInfo.UserID;
  474. getData(url, function (data) {
  475. clearTimeout(intervalTask);
  476. if (isNotData) {
  477. wx.hideLoading();
  478. }
  479. isNotData = false;
  480. if (data) {
  481. app.globalData.TaskToday = data;
  482. callback(data);
  483. }
  484. });
  485. }
  486. function getTempImage(serverUrl) {
  487. if (serverUrl.indexOf("miaguo-1253256735") >= 0) {
  488. var list = wx.getStorageSync("TempImageList");
  489. if (!list)
  490. list = [];
  491. for (var i = 0; i < list.length; i++) {
  492. if (list[i].ServerUrl == serverUrl) {
  493. return list[i].TempUrl;
  494. break;
  495. }
  496. }
  497. }
  498. return serverUrl;
  499. }
  500. function getServerImage(tempUrl) {
  501. if (tempUrl.indexOf("http") < 0) {
  502. var list = wx.getStorageSync("TempImageList");
  503. if (!list)
  504. list = [];
  505. for (var i = 0; i < list.length; i++) {
  506. if (list[i].TempUrl == tempUrl) {
  507. return list[i].ServerUrl;
  508. break;
  509. }
  510. }
  511. return ""
  512. }
  513. }
  514. function saveTempImage(serverUrl, tempUrl) {
  515. if (tempUrl.indexOf("http") < 0) {
  516. var list = wx.getStorageSync("TempImageList");
  517. if (!list)
  518. list = [];
  519. var b = false;
  520. for (var i = 0; i < list.length; i++) {
  521. if (list[i].ServerUrl == serverUrl) {
  522. list[i].TempUrl = tempUrl;
  523. b = true;
  524. break;
  525. }
  526. }
  527. if (!b) {
  528. list.push({
  529. "ServerUrl": serverUrl,
  530. "TempUrl": tempUrl
  531. });
  532. }
  533. if (list.length > 200) {
  534. list.pop();
  535. }
  536. wx.setStorageSync("TempImageList", list);
  537. }
  538. }
  539. function UpdateMiaoguoCardTodayAll(isShowLoading, callback) {
  540. var that = this;
  541. if (isShowLoading) {
  542. wx.showLoading({
  543. title: '请稍候',
  544. mask: true,
  545. });
  546. clearTimeout(dataSendTimeout);
  547. dataSendTimeout = setTimeout(function () {
  548. wx.hideLoading();
  549. wx.reLaunch({
  550. url: '../index/index',
  551. })
  552. }, 60000);
  553. }
  554. var list = wx.getStorageSync("ListTaskFinished");
  555. if (list && list.length > 0) {
  556. var arr = [];
  557. for (var i = 0; i < list.length; i++) {
  558. var obj = {};
  559. obj.MiaoguoCardID = list[i].Card.MiaoguoCardID;
  560. obj.IntervalTime = list[i].IntervalTime;
  561. obj.BtnNumber = list[i].BtnNumber;
  562. obj.FontSize = list[i].Card.FontSize;
  563. obj.Duration = list[i].Duration;
  564. obj.LearningType = list[i].LearningType;
  565. obj.IsCollect = list[i].Card.IsCollect;
  566. obj.LastTime = list[i].LastTime;
  567. arr.push(obj);
  568. }
  569. that.postData('UpdateMiaoguoCardTodayAll?UserID=' + app.globalData.userInfo.UserID, {
  570. List: arr,
  571. }, function (data) {
  572. if (isShowLoading) {
  573. wx.hideLoading();
  574. clearTimeout(dataSendTimeout);
  575. }
  576. if (data) {
  577. wx.removeStorageSync("ListTaskFinished");
  578. }
  579. if (callback) {
  580. callback();
  581. }
  582. });
  583. } else {
  584. wx.hideLoading();
  585. clearTimeout(dataSendTimeout);
  586. if (callback) {
  587. callback();
  588. }
  589. }
  590. }
  591. function updateSearchList(obj,callback) {
  592. var arr = wx.getStorageSync("SearchWord3");
  593. if (!arr)
  594. arr = [];
  595. if (obj.Type == "shici") {
  596. if (obj.Value.CHN.ShiciTitle)
  597. obj.Key = obj.Value.CHN.ShiciTitle;
  598. if (obj.Key.indexOf("《") == 0)
  599. obj.Key = obj.Key.substring(1, obj.Key.length - 1);
  600. }
  601. for (var i = 0; i < arr.length; i++) {
  602. if (arr[i].Key == obj.Key
  603. ) {
  604. if (obj.Type == "shici") {
  605. if (arr[i].ShiciUrl == obj.ShiciUrl) {
  606. obj.Value = arr[i].Value;
  607. arr.splice(i, 1);
  608. break;
  609. }
  610. } else {
  611. var b=true;
  612. if (obj.Type && arr[i].Type && arr[i].Type != obj.Type)
  613. b=false;
  614. if (obj.Author && arr[i].Author && arr[i].Author != obj.Author)
  615. b=false;
  616. if (b){
  617. obj.Value = arr[i].Value;
  618. arr.splice(i, 1);
  619. break;
  620. }
  621. }
  622. }
  623. }
  624. if (obj.Key)
  625. arr.unshift(obj);
  626. if (arr.length > 30) {
  627. arr.pop();
  628. }
  629. wx.setStorageSync("SearchWord3", arr);
  630. app.globalData.SearchItem = obj.Value;
  631. if (obj.TypeName)
  632. app.globalData.SearchItem.TypeName = obj.TypeName;
  633. if (callback)
  634. callback();
  635. }
  636. function checkIsIPhoneX() {
  637. var isIphoneX = false;
  638. if (app.globalData.systemInfo.model.indexOf("iPhone X") >= 0 ||
  639. app.globalData.systemInfo.model.indexOf("iPhone X") >= 0) {
  640. isIphoneX = true;
  641. }
  642. return isIphoneX;
  643. }
  644. //设置收藏
  645. function setCollect(id, collect, callback) {
  646. var that = this;
  647. if (collect) {
  648. wx.showToast({
  649. title: '加注成功',
  650. image: '../images/universalpic_star_white_120x120.png',
  651. });
  652. } else {
  653. wx.showToast({
  654. title: '清除成功',
  655. image: '../images/universalpic_star_whiteline_120x120.png',
  656. });
  657. }
  658. getData("UpdateMiaoguoCardInfo?UserID=" + app.globalData.userInfo.UserID + "&MiaoguoCardID=" + id + "&IsCollect=" + collect, function (data) {
  659. if (callback)
  660. callback();
  661. });
  662. }
  663. function buildInitData(callback) {
  664. var that = this;
  665. wx.showLoading({
  666. title: '数据初始化',
  667. });
  668. setTimeout(function () {
  669. wx.hideLoading();
  670. }, 5000);
  671. getData('BuildInitData?UserID=' + app.globalData.userInfo.UserID, function (data) {
  672. wx.hideLoading();
  673. if (data) {
  674. if (callback)
  675. callback();
  676. }
  677. });
  678. }
  679. function getMemoryLevelAll() {
  680. return constant.arrMemoryLevelAll;
  681. }
  682. function getMemoryLevel(index, number, time) {
  683. var arr = getMemoryLevelAll();
  684. if (index < 1)
  685. return arr[index].Value[number].Name;
  686. else
  687. return replaceStr(time);
  688. function replaceStr(data) {
  689. var result = "";
  690. if (data.indexOf("d") > 0) {
  691. var dayNum = Number(data.replace("d", ""));
  692. if (dayNum >= 365) {
  693. var year1 = Math.floor(dayNum / 365);
  694. var year = year1 + Math.round(10 * (dayNum - year1 * 365) / 365) / 10;
  695. result = year + "年后";
  696. } else {
  697. if (dayNum > 31) {
  698. var month1 = Math.floor(dayNum / 30);
  699. var month = month1 + Math.round(10 * (dayNum - month1 * 30) / 30) / 10;
  700. result = month + "月后";
  701. } else {
  702. result = Number(data.replace("d", ""));
  703. if (result == 1)
  704. result = "明天";
  705. else if (result == 2)
  706. result = "后天";
  707. else
  708. result = (result - 1) + "天后";
  709. }
  710. }
  711. } else if (data.indexOf("m") > 0)
  712. result = data.replace("m", "分钟内");
  713. return result;
  714. }
  715. }
  716. //得到要检验的汉字列表
  717. function GetHanziUnitWords(unitsID, testType, callback) {
  718. var url='GetHanziUnitWords?UnitID=' + unitsID;
  719. if (testType)
  720. url+="&TestType="+testType;
  721. getData(url, function (data) {
  722. if (data) {
  723. var TaskList = [];
  724. var words = data;
  725. //若是单字
  726. if (words[0].Pinyin){
  727. for (var k = 0; k < words.length; k++) {
  728. var taskInfo = {
  729. FontSize: 144,
  730. TagWidth: 136,
  731. Content: [{
  732. ContentType: 0,
  733. Content: []
  734. },
  735. {
  736. ContentType: 1,
  737. Content: []
  738. },
  739. {
  740. ContentType: 2,
  741. Content: []
  742. },
  743. ]
  744. };
  745. taskInfo.Word = words[k].Name;
  746. var pinyinNormal = "(" + getPinyinNormal(words[k].Pinyin) + ")";
  747. var combineWords = common.ReplaceAllString(words[k].CombineWords, words[k].Name, words[k].Name + pinyinNormal);
  748. taskInfo.ReadString = words[k].Name + pinyinNormal + "," + combineWords + "的" + words[k].Name + pinyinNormal;
  749. if (testType == "read") {
  750. taskInfo.Content[0].Content = ["怎么念"];
  751. var question = words[k].CombineWords;
  752. question = common.ReplaceAllString(question, words[k].Name, "(" + words[k].Name + ")");
  753. taskInfo.Content[1].Content = question;
  754. var answer = "[读 src='" + taskInfo.ReadString + "']" + words[k].Pinyin + "[/读]";
  755. taskInfo.Content[2].Content = answer;
  756. if (words[k].CombineWords.length > 6) {
  757. taskInfo.FontSize = 108;
  758. if (words[k].CombineWords.length > 10) {
  759. taskInfo.FontSize = 68;
  760. }
  761. }
  762. } else if (testType == "write") {
  763. taskInfo.Content[0].Content = ["怎么写"];
  764. var question = words[k].CombineWords;
  765. var question2 = common.ReplaceAllString(question, words[k].Name, words[k].Pinyin);
  766. question = "[读 src='" + taskInfo.ReadString + "']" + question2 + "[/读]"
  767. taskInfo.Content[1].Content = question;
  768. var answer = words[k].Name;
  769. answer += "[图 w='650' h='650']" + words[k].BiShunUrl + "[/图]";
  770. taskInfo.Content[2].Content = answer;
  771. if (question2.length > 6) {
  772. taskInfo.FontSize = 108;
  773. if (question2.length > 10) {
  774. taskInfo.FontSize = 68;
  775. if (question2.length > 14) {
  776. taskInfo.FontSize = 48;
  777. }
  778. }
  779. }
  780. }
  781. taskInfo.ContentNew = changeStringToView(taskInfo.Content);
  782. TaskList.push(taskInfo);
  783. }
  784. }
  785. else{ //若是词语
  786. for (var k = 0; k < words.length; k++) {
  787. var taskInfo = words[k];
  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. //console.log("英语");
  806. var wordStr = "";
  807. var userTestReportInfo = UserTestReport[n];
  808. var bookid = userTestReportInfo.BookID;
  809. var arrEnglist = [];
  810. if (bookid<110){
  811. if (name1[1]=="英文字母"){
  812. bookid=100;
  813. 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";
  814. }
  815. }
  816. else if (bookid>110 && bookid<120){
  817. arrEnglist = wx.getStorageSync("EnglishAll");
  818. arrEnglist = JSON.parse(arrEnglist);
  819. for (var i = 0; i < arrEnglist.length; i++) {
  820. if (arrEnglist[i].Name == name1[1]) {
  821. for (var j = 0; j < arrEnglist[i].Units.length; j++) {
  822. if (arrEnglist[i].Units[j].Name == name2) {
  823. wordStr = arrEnglist[i].Units[j].Words.join(",");
  824. break;
  825. }
  826. }
  827. }
  828. }
  829. }
  830. var tempRight = "," + userTestReportInfo.TestRightStr + ",";
  831. var tempWrong = "," + userTestReportInfo.TestWrongStr + ",";
  832. var tempSkip = "," + userTestReportInfo.TestSkipStr + ",";
  833. var tempExist = "," + userTestReportInfo.TestExistStr + ",";
  834. var unitsid="";
  835. if (bookid>100 && bookid<110 && UserTestReport[n].Name[2]){
  836. unitsid=Number(UserTestReport[n].Name[2]);
  837. }
  838. else if (bookid>120 && bookid<=124){
  839. unitsid=Number(name2.replace("Lesson ",""));
  840. }
  841. else if (bookid>130 && bookid<=140 && UserTestReport[n].Name[2]){
  842. unitsid=Number(UserTestReport[n].Name[2]);
  843. }
  844. getData('GetTestEnglishWords?UserID=' + app.globalData.userInfo.UserID+'&BookID='+bookid+'&LessonID='+unitsid+ '&Words=' + wordStr+"&TestType="+userTestReportInfo.TestType, function (data) {
  845. if (data) {
  846. var result = {};
  847. result.ID = userTestReportInfo.ID;
  848. result.IsFinished = userTestReportInfo.IsFinished;
  849. result.Name = userTestReportInfo.Name.join("#");
  850. result.TestType = userTestReportInfo.TestType;
  851. result.BookID = bookid;
  852. var TaskList = [];
  853. var words = data;
  854. for (var k = 0; k < words.length; k++) {
  855. var taskInfo = words[k];
  856. if (userTestReportInfo.TestType=="read"){
  857. taskInfo.TagWidth=212;
  858. taskInfo.FontSize=108;
  859. }
  860. else{
  861. taskInfo.TagWidth=186;
  862. taskInfo.FontSize=36;
  863. }
  864. taskInfo.ContentNew = changeStringToView(taskInfo.Content);
  865. if (tempRight.indexOf("," + taskInfo.Word + ",") >= 0)
  866. taskInfo.Result = 1;
  867. if (tempWrong.indexOf("," + taskInfo.Word + ",") >= 0)
  868. taskInfo.Result = -1;
  869. if (tempSkip.indexOf("," + taskInfo.Word + ",") >= 0)
  870. taskInfo.Result = 0;
  871. if (tempExist.indexOf("," + taskInfo.Word + ",") >= 0)
  872. taskInfo.Css = "Select2";
  873. TaskList.push(taskInfo);
  874. }
  875. result.TestRightStr = "";
  876. result.TestWrongStr = "";
  877. result.TestSkipStr = "";
  878. result.TestExistStr = "";
  879. if (userTestReportInfo.TestRightStr)
  880. result.TestRightStr = userTestReportInfo.TestRightStr;
  881. if (userTestReportInfo.TestWrongStr)
  882. result.TestWrongStr = userTestReportInfo.TestWrongStr;
  883. if (userTestReportInfo.TestSkipStr)
  884. result.TestSkipStr = userTestReportInfo.TestSkipStr;
  885. if (userTestReportInfo.TestExistStr)
  886. result.TestExistStr = userTestReportInfo.TestExistStr;
  887. result.List = TaskList;
  888. callback(result);
  889. } else {
  890. callback({});
  891. }
  892. });
  893. }
  894. else if (name2=="古诗文") {
  895. //todo
  896. //console.log("古诗文");
  897. var userTestReportInfo = UserTestReport[n];
  898. var tempRight = "," + userTestReportInfo.TestRightStr + ",";
  899. var tempWrong = "," + userTestReportInfo.TestWrongStr + ",";
  900. var tempSkip = "," + userTestReportInfo.TestSkipStr + ",";
  901. var tempExist = "," + userTestReportInfo.TestExistStr + ",";
  902. getData('GetTestAncientPoetryList?UserID=' + app.globalData.userInfo.UserID + '&BookID=' + userTestReportInfo.BookID, function (data) {
  903. if (data) {
  904. var result = {};
  905. result.ID = userTestReportInfo.ID;
  906. result.IsFinished = userTestReportInfo.IsFinished;
  907. result.Name = userTestReportInfo.Name.join("#");
  908. result.TestType = userTestReportInfo.TestType;
  909. result.BookID = userTestReportInfo.BookID;
  910. var TaskList = [];
  911. for (var k = 0; k < data.length; k++) {
  912. var taskInfo = data[k];
  913. taskInfo.TagWidth=336;
  914. if (taskInfo.Word.length>9)
  915. taskInfo.FontSize=48;
  916. else
  917. taskInfo.FontSize=64;
  918. taskInfo.ContentNew = changeStringToView(taskInfo.Content);
  919. if (tempRight.indexOf("," + taskInfo.Word + ",") >= 0)
  920. taskInfo.Result = 1;
  921. if (tempWrong.indexOf("," + taskInfo.Word + ",") >= 0)
  922. taskInfo.Result = -1;
  923. if (tempSkip.indexOf("," + taskInfo.Word + ",") >= 0)
  924. taskInfo.Result = 0;
  925. if (tempExist.indexOf("," + taskInfo.Word + ",") >= 0)
  926. taskInfo.Css = "Select2";
  927. TaskList.push(taskInfo);
  928. }
  929. result.TestRightStr = "";
  930. result.TestWrongStr = "";
  931. result.TestSkipStr = "";
  932. result.TestExistStr = "";
  933. if (userTestReportInfo.TestRightStr)
  934. result.TestRightStr = userTestReportInfo.TestRightStr;
  935. if (userTestReportInfo.TestWrongStr)
  936. result.TestWrongStr = userTestReportInfo.TestWrongStr;
  937. if (userTestReportInfo.TestSkipStr)
  938. result.TestSkipStr = userTestReportInfo.TestSkipStr;
  939. if (userTestReportInfo.TestExistStr)
  940. result.TestExistStr = userTestReportInfo.TestExistStr;
  941. result.List = TaskList;
  942. callback(result);
  943. } else {
  944. callback({});
  945. }
  946. });
  947. }
  948. else {
  949. var obj = UserTestReport[n];
  950. if (obj.BookID>=43 && obj.BookID<=60)
  951. name1 = name1[0] + "生词" + name1[2].substr(0, 1);
  952. else
  953. name1 = name1[0] + name1[1].substr(2, 2) + "能力" + name1[2].substr(0, 1);
  954. var HanziAll = wx.getStorageSync('HanziAll');
  955. HanziAll = JSON.parse(HanziAll);
  956. for (var i = 0; i < HanziAll.length; i++) {
  957. if (name1 == HanziAll[i].Name) {
  958. for (var j = 0; j < HanziAll[i].Units.length; j++) {
  959. if (name2 == HanziAll[i].Units[j].Name) {
  960. GetHanziUnitWords(HanziAll[i].Units[j].ID, obj.TestType, function (list) {
  961. if (list) {
  962. for (var k = 0; k < list.length; k++) {
  963. if (obj.TestRightStr && obj.TestRightStr.indexOf(list[k].Word) >= 0)
  964. list[k].Result = 1;
  965. else if (obj.TestWrongStr && obj.TestWrongStr.indexOf(list[k].Word) >= 0)
  966. list[k].Result = -1;
  967. else if (obj.TestSkipStr && obj.TestSkipStr.indexOf(list[k].Word) >= 0)
  968. list[k].Result = 0;
  969. if (obj.TestExistStr && obj.TestExistStr.indexOf(list[k].Word) >= 0)
  970. list[k].Css = "Select2";
  971. }
  972. var result = {};
  973. result.ID = reportid;
  974. result.TestType = obj.TestType;
  975. result.Name = obj.Name.join("#");
  976. result.IsFinished = obj.IsFinished;
  977. result.TestRightStr = obj.TestRightStr;
  978. result.TestWrongStr = obj.TestWrongStr;
  979. result.TestSkipStr = obj.TestSkipStr;
  980. result.TestExistStr = obj.TestExistStr;
  981. result.List = list;
  982. callback(result);
  983. } else
  984. callback({});
  985. });
  986. }
  987. }
  988. }
  989. }
  990. }
  991. }
  992. }
  993. }
  994. function getDetailColor(index) {
  995. var arrDetailColor = constant.arrDetailColor;
  996. if (index > 0)
  997. return arrDetailColor[index];
  998. else if (index == 0)
  999. return arrDetailColor[common.random(1, arrDetailColor.length - 1)];
  1000. else if (index == -1)
  1001. return arrDetailColor;
  1002. }
  1003. function getShareImageBackColor() {
  1004. var arr = constant.arrShareImageBackColor;
  1005. return arr[common.random(0, arr.length - 1)];
  1006. }
  1007. function getPinyinNormal(pinyin) {
  1008. var result = "";
  1009. var arr = constant.arrPinyin;
  1010. for (var i = 0; i < arr.length; i++) {
  1011. if (arr[i][1] == pinyin) {
  1012. result = arr[i][0];
  1013. break;
  1014. }
  1015. }
  1016. return result;
  1017. }
  1018. function getHanzi(callback) {
  1019. var that = this;
  1020. wx.showLoading({
  1021. title: '请稍候',
  1022. mask: true,
  1023. });
  1024. var time = wx.getStorageSync("HanziUpdateTime");
  1025. getData('GetHanziAll2?HasEnglish=true&HasHanziWrite=true&UpdateTime=' + time, function (data) {
  1026. wx.hideLoading();
  1027. if (data) {
  1028. var arr = [];
  1029. if (data.List) {
  1030. arr = common.Decrypt(data.List);
  1031. wx.setStorageSync("HanziAll", arr);
  1032. var arrEng = common.Decrypt(data.EngList);
  1033. var arrNewConceptEngList = common.Decrypt(data.NewConceptEngList);
  1034. var arrCambridgeEngList = common.Decrypt(data.CambridgeEngList);
  1035. var arrPhoneticEngList = common.Decrypt(data.PhoneticEngList);
  1036. wx.setStorageSync("EnglishAll", arrEng);
  1037. wx.setStorageSync("NewConceptEngList", arrNewConceptEngList);
  1038. wx.setStorageSync("CambridgeEngList", arrCambridgeEngList);
  1039. wx.setStorageSync("PhoneticEngList", arrPhoneticEngList);
  1040. wx.setStorageSync("HanziUpdateTime", data.UpdateTime);
  1041. } else {
  1042. arr = wx.getStorageSync("HanziAll");
  1043. if (arr)
  1044. arr = JSON.parse(arr);
  1045. }
  1046. callback(arr);
  1047. }
  1048. });
  1049. }
  1050. function UploadUserConfig(callback) {
  1051. var that = this;
  1052. var param1 = {};
  1053. param1.CardType = wx.getStorageSync("CardType");
  1054. param1.CardMaxNumberNew = wx.getStorageSync("CardMaxNumberNew");
  1055. param1.CardMaxNumberHistory = wx.getStorageSync("CardMaxNumberHistory");
  1056. param1.CardMaxNumberNewUrgent = wx.getStorageSync("CardMaxNumberNewUrgent");
  1057. param1.CardMaxNumberHistoryUrgent = wx.getStorageSync("CardMaxNumberHistoryUrgent");
  1058. param1.SortTypeIndex = wx.getStorageSync("SortTypeIndex");
  1059. param1.MemoryLevel = wx.getStorageSync("MemoryLevel");
  1060. param1.ClickType = wx.getStorageSync("ClickType");
  1061. param1.SecondConfigArray = wx.getStorageSync("SecondConfigArray").join(",");
  1062. param1.ColorIndexArr = wx.getStorageSync("ColorIndexArr").join(",");
  1063. param1.IsFolderPractice = wx.getStorageSync("IsFolderPractice");
  1064. param1.IsAutoSound = wx.getStorageSync("IsAutoSound");
  1065. var symboMain = wx.getStorageSync("SymbolMain");
  1066. var symbol1 = [];
  1067. for (var i = 0; i < symboMain.length; i++) {
  1068. symbol1.push(symboMain[i].Name);
  1069. }
  1070. symbol1 = JSON.stringify(symbol1);
  1071. param1.SymbolList = symbol1;
  1072. var folderOrder=wx.getStorageSync("FolderOrderStr");
  1073. if (folderOrder)
  1074. param1.FolderOrder = folderOrder;
  1075. //console.log(param1);
  1076. that.postData('UploadUserConfig?Type=update&UserID=' + app.globalData.userInfo.UserID, param1, function (data) {
  1077. if (callback) {
  1078. callback();
  1079. }
  1080. });
  1081. }
  1082. function getAwardData(callback) {
  1083. var that = this;
  1084. that.getData('GetAwardInfo?UserID=' + app.globalData.userInfo.UserID, function (data) {
  1085. if (data) {
  1086. callback(data);
  1087. } else
  1088. callback([]);
  1089. });
  1090. }
  1091. function getUserConfig() {
  1092. var that = this;
  1093. postData('UploadUserConfig?Type=getData&UserID=' + app.globalData.userInfo.UserID, {}, function (data) {
  1094. if (data && !data.CardType)
  1095. data.CardType = 0;
  1096. wx.setStorageSync("CardType", data.CardType);
  1097. wx.setStorageSync("CardMaxNumberNew", data.CardMaxNumberNew);
  1098. wx.setStorageSync("CardMaxNumberHistory", data.CardMaxNumberHistory);
  1099. wx.setStorageSync("CardMaxNumberNewUrgent", data.CardMaxNumberNewUrgent);
  1100. wx.setStorageSync("CardMaxNumberHistoryUrgent", data.CardMaxNumberHistoryUrgent);
  1101. wx.setStorageSync("SortTypeIndex", data.SortTypeIndex);
  1102. wx.setStorageSync("MemoryLevel", data.MemoryLevel);
  1103. wx.setStorageSync("ClickType", data.ClickType);
  1104. wx.setStorageSync("SecondConfigArray", data.SecondConfigArray.split(","));
  1105. wx.setStorageSync("ColorIndexArr", data.ColorIndexArr.split(","));
  1106. wx.setStorageSync("FolderOrderStr", data.FolderOrder);
  1107. wx.setStorageSync("IsFolderPractice", data.IsFolderPractice);
  1108. wx.setStorageSync("IsAutoSound", data.IsAutoSound);
  1109. var symbol1 = [];
  1110. if (data.SymbolList) {
  1111. for (var i = 0; i < data.SymbolList.length; i++) {
  1112. var obj = {};
  1113. obj.Name = data.SymbolList[i];
  1114. obj.CSS = "btn2";
  1115. symbol1.push(obj);
  1116. }
  1117. } else {
  1118. symbol1 = app.globalData.SymbolMain;
  1119. }
  1120. if (symbol1.length>0){
  1121. wx.setStorageSync("SymboMain", symbol1);
  1122. app.globalData.SymbolMain = symbol1;
  1123. }
  1124. });
  1125. }
  1126. function replaceCardInfoString(str) {
  1127. var that = this;
  1128. //str = str.replace(/\[图]/g, "");
  1129. //str = str.replace(/\[\/图\]/g, "");
  1130. var str2 = "";
  1131. if (str.indexOf("[读 src=") >= 0) {
  1132. str2 = str.substr(str.indexOf("[读 src="));
  1133. str2 = str2.substring(0, str2.indexOf("/读]") + 3);
  1134. }
  1135. str = str.replace(str2, "");
  1136. if (str.indexOf("[读 src=") >= 0) {
  1137. str2 = str.substr(str.indexOf("[读 src"));
  1138. str2 = str2.substring(0, str2.indexOf("/读]") + 3);
  1139. }
  1140. str = str.replace(str2, "");
  1141. str = str.replace(/\[读]/g, "");
  1142. str = str.replace(/\[\/读\]/g, "");
  1143. var str3 = "";
  1144. if (str.indexOf("[图") >= 0) {
  1145. str3 = str.substr(str.indexOf("[图"));
  1146. str3 = str3.substring(0, str3.indexOf("/图]") + 3);
  1147. }
  1148. str = str.replace(str3, "");
  1149. if (str.indexOf("[图") >= 0) {
  1150. str3 = str.substr(str.indexOf("[图"));
  1151. str3 = str3.substring(0, str3.indexOf("/图]") + 3);
  1152. }
  1153. str = str.replace(str3, "");
  1154. str = str.replace(/\[线]/g, "");
  1155. str = str.replace(/\[\/线\]/g, "");
  1156. str = that.encryptUrl(str);
  1157. return str;
  1158. }
  1159. function searchInfomation(search,searchtype,author,shiciurl,callback){
  1160. var WORD_LENGTH=18;
  1161. wx.showLoading({
  1162. title: '查询中',
  1163. });
  1164. var timeout=setTimeout(function () {
  1165. wx.hideLoading();
  1166. }, 5000);
  1167. var url = 'GetMiaoguoAISearch2?UserID=' + app.globalData.userInfo.UserID;
  1168. url += "&Word=" + encodeURI(search);
  1169. if (searchtype)
  1170. url += "&SearchType=" + searchtype;
  1171. if (author)
  1172. url += "&Author=" + encodeURI(author);
  1173. if (shiciurl)
  1174. url += "&ShiciUrl=" + shiciurl;
  1175. getData(url, function (data) {
  1176. wx.hideLoading();
  1177. clearTimeout(timeout);
  1178. if (data) {
  1179. //console.log(data);
  1180. if (data.List) {
  1181. var len = WORD_LENGTH;
  1182. var list = data.List;
  1183. for (var i = 0; i < list.length; i++) {
  1184. var item = list[i];
  1185. if (item.TypeName == "字词") {
  1186. if (item.Key.length == 1)
  1187. item.TypeName = "Z";
  1188. else
  1189. item.TypeName = "C";
  1190. } else if (item.TypeName == "诗词") {
  1191. item.TypeName = "S";
  1192. item.Remark = item.Author + " " + item.Dynasty;
  1193. } else if (item.TypeName == "翻译") {
  1194. item.TypeName = "D";
  1195. }
  1196. if (item.Content && item.Content.length > len)
  1197. item.Content = item.Content.substr(0, len) + "...";
  1198. }
  1199. callback(list);
  1200. } else if (data.CHN || data.ENG) {
  1201. var obj = {};
  1202. obj.Key = search;
  1203. obj.Value = data;
  1204. if (data.CHN && data.CHN.Author)
  1205. obj.Author = data.CHN.Author;
  1206. if (data.CHN && data.CHN.Dynasty)
  1207. obj.Dynasty = data.CHN.Dynasty;
  1208. if (data.CHN && data.CHN.PeomContent) {
  1209. obj.Type = "shici";
  1210. obj.TypeName = "诗词";
  1211. obj.Content = data.CHN.PeomContent.join("").substr(0, WORD_LENGTH);
  1212. obj.ShiciUrl = shiciurl;
  1213. obj.TypeName="S";
  1214. } else if (data.CHN) {
  1215. obj.Type = "zici";
  1216. if (data.CHN.PinYin && data.CHN.PinYin[0] && data.CHN.PinYin[0].pinyin)
  1217. obj.Remark = data.CHN.PinYin[0].pinyin;
  1218. if (data.CHN.PinYin && data.CHN.PinYin[0] && data.CHN.PinYin[0].explain) {
  1219. obj.Content = data.CHN.PinYin[0].explain.substr(0, WORD_LENGTH);
  1220. obj.Content = obj.Content.replace("<p>", "");
  1221. obj.Content = obj.Content.replace("</p>", "");
  1222. if (obj.Content.length >= WORD_LENGTH)
  1223. obj.Content += "..."
  1224. }
  1225. if (obj.Key.length == 1)
  1226. obj.TypeName = "Z";
  1227. else
  1228. obj.TypeName = "C";
  1229. }
  1230. if (data.ENG && !data.CHN) {
  1231. obj.Type = "eng";
  1232. obj.TypeName = "D";
  1233. if (data.ENG.Soundmark && data.ENG.Soundmark.Eng)
  1234. obj.Remark = data.ENG.Soundmark.Eng;
  1235. if (data.ENG.Paraphrase.length > 0) {
  1236. if (common.checkIsArray(data.ENG.Paraphrase) && data.ENG.Paraphrase[0].ParaphraseList)
  1237. obj.Content = data.ENG.Paraphrase[0].ParaphraseList.join("; ").substr(0, WORD_LENGTH);
  1238. else
  1239. obj.Content = data.ENG.Paraphrase.substr(0, WORD_LENGTH) + "...";
  1240. }
  1241. }
  1242. app.globalData.TempSearchBackNumber = 2;
  1243. //app.globalData.CardList=[];
  1244. app.globalData.CardList2=[];
  1245. callback([],obj);
  1246. }
  1247. else{
  1248. callback([]);
  1249. }
  1250. } else {
  1251. callback([]);
  1252. }
  1253. });
  1254. }
  1255. function downloadBishunKaitiImage(url,serverUrl,dataType,Fields,callback){
  1256. var param={};
  1257. param.Url=url;
  1258. param.DataType=dataType;
  1259. if (param.Url==serverUrl){
  1260. postData("GetBiShunByKaitiUrl",param, function (data) {
  1261. if (data) {
  1262. wx.downloadFile({
  1263. url: data, // 仅为示例,并非真实的资源
  1264. success(res) {
  1265. // 只要服务器有响应数据,就会把响应内容写入文件并进入 success 回调,业务需要自行判断是否下载到了想要的内容
  1266. if (res.statusCode === 200) {
  1267. //console.log("serverUrl2:" + serverUrl);
  1268. console.log(res.tempFilePath);
  1269. callback(change(Fields,res.tempFilePath,param));
  1270. }
  1271. },
  1272. complete(){
  1273. }
  1274. });
  1275. }
  1276. });
  1277. }
  1278. else{
  1279. callback(change(Fields,serverUrl,param));
  1280. }
  1281. function change(Fields,filepath,param){
  1282. var iStart=0;
  1283. if (Fields.length==4)
  1284. iStart=1
  1285. for (var i = iStart; i < Fields.length; i++) {
  1286. for (var j = 0; j < Fields[i].length; j++) {
  1287. if (Fields[i][j].Type == "image") {
  1288. if (Fields[i][j].Content==param.Url){
  1289. Fields[i][j].Content = filepath;
  1290. if (param.DataType=="bishun"){
  1291. Fields[i][j].IsShowKaiti=true;
  1292. Fields[i][j].IsShowBishun=false;
  1293. }
  1294. else if (param.DataType=="kaiti"){
  1295. Fields[i][j].IsShowKaiti=false;
  1296. Fields[i][j].IsShowBishun=true;
  1297. }
  1298. }
  1299. }
  1300. }
  1301. }
  1302. return Fields;
  1303. }
  1304. }
  1305. function GetSoundError(str) {
  1306. var arr=constant.arrSoundError;
  1307. var result=str;
  1308. for(var i=0;i<arr.length;i++){
  1309. if (str.indexOf(arr[i].Word)>0){
  1310. result=common.ReplaceAllString(str,arr[i].Word,arr[i].Sound);
  1311. break;
  1312. }
  1313. else if (str==arr[i].Word){
  1314. result=arr[i].Sound;
  1315. }
  1316. }
  1317. return result;
  1318. }
  1319. module.exports = {
  1320. getData: getData,
  1321. postData: postData,
  1322. payMoney: payMoney,
  1323. getLocalHost: getLocalHost,
  1324. getTimeFormat: getTimeFormat,
  1325. getWindowHeight: getWindowHeight,
  1326. getStorageValue: getStorageValue,
  1327. getProgramList: getProgramList,
  1328. gotoFeedback: gotoFeedback,
  1329. getDetailColor: getDetailColor,
  1330. changeStringToView: changeStringToView,
  1331. changeViewToString: changeViewToString,
  1332. encryptUrl: EncryptUrl,
  1333. decryptUrl: DecryptUrl,
  1334. saveTempImage: saveTempImage,
  1335. getTempImage: getTempImage,
  1336. getTaskTodayList: getTaskTodayList,
  1337. updateSearchList: updateSearchList,
  1338. checkIsIPhoneX: checkIsIPhoneX,
  1339. getMemoryLevelAll: getMemoryLevelAll,
  1340. getMemoryLevel: getMemoryLevel,
  1341. getShareImageBackColor: getShareImageBackColor,
  1342. UpdateMiaoguoCardTodayAll: UpdateMiaoguoCardTodayAll,
  1343. setCollect: setCollect,
  1344. UploadUserConfig: UploadUserConfig,
  1345. getServerImage: getServerImage,
  1346. getBaiduToken: getBaiduToken,
  1347. buildInitData: buildInitData,
  1348. getPinyinNormal: getPinyinNormal,
  1349. getHanzi: getHanzi,
  1350. GetHanziUnitWords: GetHanziUnitWords,
  1351. GetTestReportInfo: GetTestReportInfo,
  1352. getUserConfig: getUserConfig,
  1353. getAwardData: getAwardData,
  1354. replaceCardInfoString: replaceCardInfoString,
  1355. searchInfomation:searchInfomation,
  1356. downloadBishunKaitiImage:downloadBishunKaitiImage,
  1357. GetSoundError:GetSoundError,
  1358. }