main.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627
  1. import common from '../utils/util';
  2. var app = getApp();
  3. function getData(url, callback) {
  4. if (!app.globalData.IsProduction)
  5. console.log("加密前的结果为===", url);
  6. var url = common.Encrypt(url);
  7. //console.log("加密后的结果为===",url);
  8. wx.request({
  9. url: app.globalData.serverUrl + url,
  10. success: function (res) {
  11. if (res.statusCode)
  12. common.checkError(res.statusCode);
  13. var data = res.data.result;
  14. callback(data);
  15. },
  16. fail: function () {
  17. wx.redirectTo({
  18. url: './error',
  19. });
  20. },
  21. });
  22. }
  23. function postData(url, postData, callback) {
  24. var url = common.Encrypt(url);
  25. //console.log("加密后的结果为===",url);
  26. wx.request({
  27. url: app.globalData.serverUrl + url,
  28. method: "POST",
  29. data: postData,
  30. success: function (res) {
  31. if (res.statusCode)
  32. common.checkError(res.statusCode);
  33. var data = res.data.result;
  34. callback(data);
  35. },
  36. fail: function () {
  37. wx.showToast({
  38. title: '服务器忙,请稍候再试!',
  39. duration: 3000
  40. });
  41. wx.redirectTo({
  42. url: './error',
  43. });
  44. },
  45. });
  46. }
  47. function getLocalHost(callback) {
  48. if (!app.globalData.IsProduction) {
  49. var url = common.Encrypt("Ping");
  50. wx.request({
  51. url: app.globalData.serverUrlLocalhost + url,
  52. success: function (res) {
  53. app.globalData.serverUrl = app.globalData.serverUrlLocalhost;
  54. callback();
  55. },
  56. fail: function () {
  57. app.globalData.serverUrl = app.globalData.serverUrlServer;
  58. callback();
  59. },
  60. });
  61. }
  62. else {
  63. app.globalData.serverUrl = app.globalData.serverUrlServer;
  64. callback();
  65. }
  66. }
  67. function shareGroup(shareTickets, isShared) {
  68. // 转发成功
  69. console.log("shareTickets:" + shareTickets);
  70. if (shareTickets && shareTickets.length > 0) {
  71. var that = this;
  72. for (var i = 0; i < shareTickets.length; i++) {
  73. wx.getShareInfo({
  74. shareTicket: shareTickets[i],
  75. success: function (groupInfo) {
  76. wx.login({
  77. success: function (res0) {
  78. console.log("groupInfo:" + groupInfo);
  79. that.postData('AddSpatialIntelligenceGroup', {
  80. Code: res0.code,
  81. UserID: app.globalData.userInfo.UserID,
  82. GroupInfo: groupInfo,
  83. IsShared: isShared,
  84. }, function (data) {
  85. });
  86. }
  87. });
  88. },
  89. fail: function (err) {
  90. console.log(err);
  91. },
  92. });
  93. }
  94. }
  95. }
  96. function payMoney(payType, money, callback) {
  97. console.log(money);
  98. //登录认证
  99. wx.login({
  100. success: function (res) {
  101. if (res.code) {
  102. console.log('获取用户登录态成功!' + res.code);
  103. //预支付
  104. getData('PayLogin?code=' + res.code + '&payType=' + payType + '&money=' + money, function (data) {
  105. if (data && data.timeStamp) {
  106. //微信支付
  107. wx.requestPayment({
  108. 'timeStamp': data.timeStamp.toString(),
  109. 'nonceStr': data.nonceStr,
  110. 'package': data.package,
  111. 'signType': 'MD5',
  112. 'paySign': data.paySign,
  113. 'success': function (res3) {
  114. console.log("success:" + res3);
  115. callback();
  116. },
  117. 'fail': function (err) {
  118. if (err && err.errMsg && err.errMsg.indexOf("fail cancel")) {
  119. }
  120. else {
  121. wx.showToast({
  122. title: '服务器忙,请稍候再试!',
  123. duration: 3000
  124. });
  125. wx.redirectTo({
  126. url: './error',
  127. });
  128. }
  129. }
  130. });
  131. }
  132. });
  133. } else {
  134. console.log('获取用户登录态失败!' + res.errMsg);
  135. }
  136. }
  137. });
  138. }
  139. function downloadImage(scoreID) {
  140. wx.showLoading({
  141. title: '下载中_然后长按保存',
  142. });
  143. var that = this;
  144. getData('MakeSchulteShare?ScoreID=' + scoreID, function (data) {
  145. setTimeout(function () {
  146. wx.downloadFile({
  147. url: "https://schulte-1253256735.file.myqcloud.com/share" + scoreID + ".jpg",
  148. success: function (res) {
  149. wx.hideLoading();
  150. wx.previewImage({
  151. current: res.tempFilePath, // 当前显示图片的http链接
  152. urls: [res.tempFilePath] // 需要预览的图片http链接列表
  153. })
  154. },
  155. fail: function () {
  156. wx.hideLoading();
  157. getData('MakeSchulteShare?ScoreID=' + scoreID, function (data) { });
  158. wx.showToast({
  159. title: '请稍候再试!',
  160. duration: 2000
  161. });
  162. }
  163. });
  164. }, 2000);
  165. });
  166. }
  167. function getTimeFormat(duration) {
  168. //console.log("duration:" + duration);
  169. var arr = ['', '', '']
  170. if (duration.indexOf("'") > 0)
  171. arr[0] = duration.substring(0, duration.indexOf("'"));
  172. if (duration.indexOf(".") > 0) {
  173. arr[1] = duration.substring(duration.indexOf("'") + 1, duration.indexOf(".") + 1);
  174. arr[2] = duration.substring(duration.indexOf(".") + 1, duration.indexOf('"'));
  175. }
  176. else {
  177. arr[1] = duration.substring(duration.indexOf("'") + 1, duration.indexOf('"'));
  178. }
  179. return arr;
  180. }
  181. function getWindowHeight() {
  182. var height = app.globalData.systemInfo.windowHeight;
  183. //console.log("app.globalData.systemInfo.windowHeight:" + app.globalData.systemInfo.windowHeight * 2);
  184. if (app.globalData.systemInfo.model) {
  185. if (height == 504 && (
  186. app.globalData.systemInfo.model.indexOf("iPhone 6<") >= 0
  187. || app.globalData.systemInfo.model.indexOf("iPhone 7<") >= 0
  188. || app.globalData.systemInfo.model.indexOf("iPhone 6s<") >= 0
  189. || app.globalData.systemInfo.model.indexOf("iPhone 5") >= 0
  190. || app.globalData.systemInfo.model.indexOf("iPhone SE") >= 0
  191. )) {
  192. height = 596;
  193. }
  194. }
  195. height = height * 2;
  196. if (app.globalData.systemInfo.system && app.globalData.systemInfo.system.indexOf("Android") >= 0) {
  197. height = height + 168;
  198. }
  199. else {
  200. height = height + 50;
  201. }
  202. //console.log("height:" + height);
  203. return height;
  204. }
  205. //获取存储数据,若不存在,则获得缺省值。
  206. function getStorageValue(obj, name, defaultStatus, callback) {
  207. wx.getStorage({
  208. key: name,
  209. success: function (res) {
  210. obj.data[name] = res.data;
  211. obj.setData(obj.data);
  212. callback();
  213. },
  214. fail: function (res) {
  215. obj.data[name] = defaultStatus;
  216. obj.setData(obj.data);
  217. callback();
  218. },
  219. });
  220. }
  221. function getDifficulty(num) {
  222. switch (Number(num)) {
  223. case 3:
  224. case 4:
  225. case 5:
  226. return "EASY";
  227. case 6:
  228. case 7:
  229. return "HARD";
  230. case 8:
  231. case 9:
  232. return "SUPER";
  233. }
  234. }
  235. function getProgramList() {
  236. return [
  237. {
  238. id: 89,
  239. appId: 'wx46a7b4c420e6d38f',
  240. path: 'pages/index/start?SourceID=' + app.globalData.ProgramID,
  241. },
  242. {
  243. id: 98,
  244. appId: 'wx331e8dd070f01d0e',
  245. path: 'pages/index/index?SourceID=' + app.globalData.ProgramID,
  246. },
  247. {
  248. id: 99,
  249. appId: 'wxb54a6d5aff836ee3',
  250. path: 'pages/index/index?SourceID=' + app.globalData.ProgramID,
  251. },
  252. {
  253. id: 106,
  254. appId: 'wx313a8f2c0741efe1',
  255. path: 'pages/index/index?SourceID=' + app.globalData.ProgramID,
  256. },
  257. ];
  258. }
  259. function gotoFeedback() {
  260. wx.navigateToMiniProgram({
  261. appId: "wx80059777521b897c",
  262. path: "pages/index/feedback",
  263. extraData: {
  264. },
  265. success(res) {
  266. // 打开成功
  267. }
  268. });
  269. }
  270. function changeViewToString(content) {
  271. var str = content;
  272. if (str.constructor == Array) {
  273. if (str.length > 0)
  274. str = str.join(",");
  275. else
  276. str = "";
  277. }
  278. if (!str)
  279. str = ""
  280. else {
  281. str = str.replace(/\n\n/g, "\n");
  282. if (str.indexOf("\n") == 0) {
  283. str = str.substr(1);
  284. }
  285. if (str.lastIndexOf("\n") == str.length - 1) {
  286. str = str.substr(0, str.length - 1);
  287. }
  288. }
  289. return str;
  290. }
  291. function EncryptUrl(str) {
  292. if (str.constructor == Array) {
  293. if (str.length > 0)
  294. str = str.join(",");
  295. else
  296. str = "";
  297. }
  298. if (str) {
  299. str = str.replace(/baidu.com/g, "#####1#####");
  300. str = str.replace(/iciba.com/g, "#####2#####");
  301. }
  302. return str;
  303. }
  304. function DecryptUrl(str) {
  305. if (str.constructor == Array) {
  306. if (str.length > 0)
  307. str = str.join(",");
  308. else
  309. str = "";
  310. }
  311. if (str) {
  312. str = str.replace(/#####1#####/g, "baidu.com");
  313. str = str.replace(/#####2#####/g, "iciba.com");
  314. }
  315. return str;
  316. }
  317. function changeStringToView(field) {
  318. var result = {};
  319. result.Field = [[]];
  320. for (var j = 0; j < field.length; j++) {
  321. if (j == 0) {
  322. if (field[j].ContentType == 0 && field[j].Content && field[j].Content.length > 0) {
  323. result.Tags = field[j].Content.toString().split(",");
  324. }
  325. else {
  326. result.Tags = [];
  327. }
  328. }
  329. else {
  330. if (field[j].ContentType == j && field[j].Content && field[j].Content.length > 0) {
  331. var arrResult = [], arrSoundMark = [];
  332. var str = field[j].Content.toString();
  333. str = DecryptUrl(str);
  334. str = str.replace(/\[读/g, "\n[读");
  335. str = str.replace(/\[图/g, "\n[图");
  336. str = str.replace(/\[\/读\]/g, "[\/读]\n");
  337. str = str.replace(/\[\/图\]/g, "[\/图]\n");
  338. str = str.replace(/\n\n/g, "\n");
  339. var arr = str.split("\n");
  340. for (var k = 0; k < arr.length; k++) {
  341. if (arr[k].indexOf("[图]") >= 0 && arr[k].indexOf("[/图]") > 0) {
  342. var obj = {};
  343. obj.Type = "image";
  344. obj.Content = arr[k].substring(arr[k].indexOf("[图]") + 3, arr[k].indexOf("[/图]"));
  345. arrResult.push(obj);
  346. }
  347. else if (arr[k].indexOf("[线]") >= 0 && arr[k].indexOf("[/线]") > 0) {
  348. var obj;
  349. var content = ["", "", ""];
  350. if (arr[k].indexOf("[线]") > 0) {
  351. content[0] = arr[k].substring(0, arr[k].indexOf("[线]"));
  352. }
  353. content[1] = arr[k].substring(arr[k].indexOf("[线]") + 3, arr[k].indexOf("[/线]"));
  354. if (arr[k].length > arr[k].indexOf("[/线]") + 4) {
  355. content[2] = arr[k].substring(arr[k].indexOf("[/线]") + 4);
  356. }
  357. obj = {};
  358. obj.Type = "line";
  359. obj.Content = content;
  360. arrResult.push(obj);
  361. }
  362. else if (arr[k].indexOf("[读") >= 0 && arr[k].indexOf("[/读]") > 0) {
  363. var obj = {};
  364. obj.Type = "sound";
  365. if (arr[k].indexOf("[读]") >= 0) {
  366. obj.Content = arr[k].substring(arr[k].indexOf("[读]") + 3, arr[k].indexOf("[/读]"));
  367. obj.SoundImageName = "png";
  368. }
  369. else {
  370. var tempIndex = arr[k].indexOf("\']") + 2;
  371. obj.Content = arr[k].substring(tempIndex, arr[k].indexOf("[/读]"));
  372. obj.SoundMark = arr[k].substring(arr[k].indexOf("src='") + 5, arr[k].indexOf("']"));;
  373. obj.SoundImageName = "png";
  374. }
  375. arrResult.push(obj);
  376. }
  377. else if (arr[k] != "") {
  378. var obj = {};
  379. obj.Type = "normal";
  380. obj.Content = arr[k];
  381. arrResult.push(obj);
  382. }
  383. var obj = {};
  384. obj.Type = "return";
  385. arrResult.push(obj);
  386. }
  387. result.Field.push(arrResult);
  388. }
  389. else {
  390. result.Field.push([]);
  391. }
  392. }
  393. }
  394. return result;
  395. }
  396. function getDetailColor() {
  397. var arr = [
  398. {//配色1
  399. BackColor: "#F44336",
  400. FrontColor: "#ffffff",
  401. SelectBackColor: "#ffffff",
  402. SelectFrontColor: "#1E1E1E",
  403. TagBackColor: "#9C2880",
  404. },
  405. {//配色2
  406. BackColor: "#D81B60",
  407. FrontColor: "#ffffff",
  408. SelectBackColor: "#ffffff",
  409. SelectFrontColor: "#1E1E1E",
  410. TagBackColor: "#E86D24",
  411. },
  412. {//配色3
  413. BackColor: "#8E24AA",
  414. FrontColor: "#ffffff",
  415. SelectBackColor: "#ffffff",
  416. SelectFrontColor: "#1E1E1E",
  417. TagBackColor: "#E86D24",
  418. },
  419. {//配色4
  420. BackColor: "#6639B5",
  421. FrontColor: "#ffffff",
  422. SelectBackColor: "#ffffff",
  423. SelectFrontColor: "#1E1E1E",
  424. TagBackColor: "#E86D24",
  425. },
  426. {//配色5
  427. BackColor: "#3F51B5",
  428. FrontColor: "#ffffff",
  429. SelectBackColor: "#ffffff",
  430. SelectFrontColor: "#1E1E1E",
  431. TagBackColor: "#E54627",
  432. },
  433. {//配色6
  434. BackColor: "#1E88E5",
  435. FrontColor: "#ffffff",
  436. SelectBackColor: "#ffffff",
  437. SelectFrontColor: "#1E1E1E",
  438. TagBackColor: "#E54627",
  439. },
  440. {//配色7
  441. BackColor: "#039BE5",
  442. FrontColor: "#ffffff",
  443. SelectBackColor: "#ffffff",
  444. SelectFrontColor: "#1E1E1E",
  445. TagBackColor: "#E54627",
  446. },
  447. {//配色8
  448. BackColor: "#00ACC1",
  449. FrontColor: "#ffffff",
  450. SelectBackColor: "#ffffff",
  451. SelectFrontColor: "#1E1E1E",
  452. TagBackColor: "#E54627",
  453. },
  454. {//配色9
  455. BackColor: "#009688",
  456. FrontColor: "#ffffff",
  457. SelectBackColor: "#ffffff",
  458. SelectFrontColor: "#1E1E1E",
  459. TagBackColor: "#2A6358",
  460. },
  461. {//配色10
  462. BackColor: "#43A047",
  463. FrontColor: "#ffffff",
  464. SelectBackColor: "#ffffff",
  465. SelectFrontColor: "#1E1E1E",
  466. TagBackColor: "#2A6358",
  467. },
  468. {//配色11
  469. BackColor: "#71B12D",
  470. FrontColor: "#ffffff",
  471. SelectBackColor: "#ffffff",
  472. SelectFrontColor: "#1E1E1E",
  473. TagBackColor: "#2A6358",
  474. },
  475. {//配色12
  476. BackColor: "#CFDA37",
  477. FrontColor: "#1e1e1e",
  478. SelectBackColor: "#868E25",
  479. SelectFrontColor: "#FFFFFF",
  480. TagBackColor: "#868E25",
  481. },
  482. {//配色13
  483. BackColor: "#F9D342",
  484. FrontColor: "#1e1e1e",
  485. SelectBackColor: "#C46C28",
  486. SelectFrontColor: "#FFFFFF",
  487. TagBackColor: "#C46C28",
  488. },
  489. {//配色14
  490. BackColor: "#FF9F33",
  491. FrontColor: "#1e1e1e",
  492. SelectBackColor: "#C46C28",
  493. SelectFrontColor: "#FFFFFF",
  494. TagBackColor: "#C46C28",
  495. },
  496. {//配色15
  497. BackColor: "#EE7F33",
  498. FrontColor: "#ffffff",
  499. SelectBackColor: "#ffffff",
  500. SelectFrontColor: "#1E1E1E",
  501. TagBackColor: "#C43928",
  502. },
  503. {//配色16
  504. BackColor: "#FF5722",
  505. FrontColor: "#ffffff",
  506. SelectBackColor: "#ffffff",
  507. SelectFrontColor: "#1E1E1E",
  508. TagBackColor: "#C42843",
  509. },
  510. {//配色17
  511. BackColor: "#795548",
  512. FrontColor: "#ffffff",
  513. SelectBackColor: "#ffffff",
  514. SelectFrontColor: "#1E1E1E",
  515. TagBackColor: "#CC2A38",
  516. },
  517. {//配色18
  518. BackColor: "#616161",
  519. FrontColor: "#ffffff",
  520. SelectBackColor: "#ffffff",
  521. SelectFrontColor: "#1E1E1E",
  522. TagBackColor: "#9C3724",
  523. },
  524. {//配色19
  525. BackColor: "#FFBC00",
  526. FrontColor: "#1e1e1e",
  527. SelectBackColor: "#9C6226",
  528. SelectFrontColor: "#ffffff",
  529. TagBackColor: "#9C6226",
  530. },
  531. {//配色20
  532. BackColor: "#ACC6AA",
  533. FrontColor: "#1e1e1e",
  534. SelectBackColor: "#6F7F6D",
  535. SelectFrontColor: "#ffffff",
  536. TagBackColor: "#6F7F6D",
  537. },
  538. {//配色21
  539. BackColor: "#74B49B",
  540. FrontColor: "#ffffff",
  541. SelectBackColor: "#ffffff",
  542. SelectFrontColor: "#1e1e1e",
  543. TagBackColor: "#9A4391",
  544. },
  545. {//配色22
  546. BackColor: "#0B8457",
  547. FrontColor: "#ffffff",
  548. SelectBackColor: "#ffffff",
  549. SelectFrontColor: "#1e1e1e",
  550. TagBackColor: "#9A4391",
  551. },
  552. {//配色23
  553. BackColor: "#34699A",
  554. FrontColor: "#ffffff",
  555. SelectBackColor: "#ffffff",
  556. SelectFrontColor: "#1e1e1e",
  557. TagBackColor: "#D44139",
  558. },
  559. {//配色24
  560. BackColor: "#234A9A",
  561. FrontColor: "#ffffff",
  562. SelectBackColor: "#ffffff",
  563. SelectFrontColor: "#1e1e1e",
  564. TagBackColor: "#D44139",
  565. },
  566. {//配色25
  567. BackColor: "#786489",
  568. FrontColor: "#ffffff",
  569. SelectBackColor: "#ffffff",
  570. SelectFrontColor: "#1e1e1e",
  571. TagBackColor: "#E69109",
  572. },
  573. ];
  574. return arr;
  575. }
  576. module.exports = {
  577. getData: getData,
  578. postData: postData,
  579. shareGroup: shareGroup,
  580. payMoney: payMoney,
  581. downloadImage: downloadImage,
  582. getLocalHost: getLocalHost,
  583. getTimeFormat: getTimeFormat,
  584. getWindowHeight: getWindowHeight,
  585. getStorageValue: getStorageValue,
  586. getDifficulty: getDifficulty,
  587. getProgramList: getProgramList,
  588. gotoFeedback: gotoFeedback,
  589. getDetailColor: getDetailColor,
  590. changeStringToView: changeStringToView,
  591. changeViewToString: changeViewToString,
  592. encryptUrl: EncryptUrl,
  593. decryptUrl: DecryptUrl,
  594. }