main.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611
  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. str = str.replace(/baidu.com/g, "#####1#####");
  293. str = str.replace(/iciba.com/g, "#####2#####");
  294. return str;
  295. }
  296. function DecryptUrl(str) {
  297. str = str.replace(/#####1#####/g, "baidu.com");
  298. str = str.replace(/#####2#####/g, "iciba.com");
  299. return str;
  300. }
  301. function changeStringToView(field) {
  302. var result = {};
  303. result.Field = [[]];
  304. for (var j = 0; j < field.length; j++) {
  305. if (j == 0) {
  306. if (field[j].ContentType == 0 && field[j].Content && field[j].Content.length > 0) {
  307. result.Tags = field[j].Content.toString().split(",");
  308. }
  309. else {
  310. result.Tags = [];
  311. }
  312. }
  313. else {
  314. if (field[j].ContentType == j && field[j].Content && field[j].Content.length > 0) {
  315. var arrResult = [], arrSoundMark = [];
  316. var str = field[j].Content.toString();
  317. str = DecryptUrl(str);
  318. str = str.replace(/\[读/g, "\n[读");
  319. str = str.replace(/\[图/g, "\n[图");
  320. str = str.replace(/\[\/读\]/g, "[\/读]\n");
  321. str = str.replace(/\[\/图\]/g, "[\/图]\n");
  322. str = str.replace(/\n\n/g, "\n");
  323. var arr = str.split("\n");
  324. for (var k = 0; k < arr.length; k++) {
  325. if (arr[k].indexOf("[图]") >= 0 && arr[k].indexOf("[/图]") > 0) {
  326. var obj = {};
  327. obj.Type = "image";
  328. obj.Content = arr[k].substring(arr[k].indexOf("[图]") + 3, arr[k].indexOf("[/图]"));
  329. arrResult.push(obj);
  330. }
  331. else if (arr[k].indexOf("[线]") >= 0 && arr[k].indexOf("[/线]") > 0) {
  332. var obj;
  333. var content = ["", "", ""];
  334. if (arr[k].indexOf("[线]") > 0) {
  335. content[0] = arr[k].substring(0, arr[k].indexOf("[线]"));
  336. }
  337. content[1] = arr[k].substring(arr[k].indexOf("[线]") + 3, arr[k].indexOf("[/线]"));
  338. if (arr[k].length > arr[k].indexOf("[/线]") + 4) {
  339. content[2] = arr[k].substring(arr[k].indexOf("[/线]") + 4);
  340. }
  341. obj = {};
  342. obj.Type = "line";
  343. obj.Content = content;
  344. arrResult.push(obj);
  345. }
  346. else if (arr[k].indexOf("[读") >= 0 && arr[k].indexOf("[/读]") > 0) {
  347. var obj = {};
  348. obj.Type = "sound";
  349. if (arr[k].indexOf("[读]") >= 0) {
  350. obj.Content = arr[k].substring(arr[k].indexOf("[读]") + 3, arr[k].indexOf("[/读]"));
  351. obj.SoundImageName = "png";
  352. }
  353. else {
  354. var tempIndex = arr[k].indexOf("\']") + 2;
  355. obj.Content = arr[k].substring(tempIndex, arr[k].indexOf("[/读]"));
  356. obj.SoundMark = arr[k].substring(arr[k].indexOf("src='") + 5, arr[k].indexOf("']"));;
  357. obj.SoundImageName = "png";
  358. }
  359. arrResult.push(obj);
  360. }
  361. else if (arr[k] != "") {
  362. var obj = {};
  363. obj.Type = "normal";
  364. obj.Content = arr[k];
  365. arrResult.push(obj);
  366. }
  367. var obj = {};
  368. obj.Type = "return";
  369. arrResult.push(obj);
  370. }
  371. result.Field.push(arrResult);
  372. }
  373. else {
  374. result.Field.push([]);
  375. }
  376. }
  377. }
  378. return result;
  379. }
  380. function getDetailColor() {
  381. var arr = [
  382. {//配色1
  383. BackColor: "#F44336",
  384. FrontColor: "#ffffff",
  385. SelectBackColor: "#ffffff",
  386. SelectFrontColor: "#1E1E1E",
  387. TagBackColor: "#9C2880",
  388. },
  389. {//配色2
  390. BackColor: "#D81B60",
  391. FrontColor: "#ffffff",
  392. SelectBackColor: "#ffffff",
  393. SelectFrontColor: "#1E1E1E",
  394. TagBackColor: "#E86D24",
  395. },
  396. {//配色3
  397. BackColor: "#8E24AA",
  398. FrontColor: "#ffffff",
  399. SelectBackColor: "#ffffff",
  400. SelectFrontColor: "#1E1E1E",
  401. TagBackColor: "#E86D24",
  402. },
  403. {//配色4
  404. BackColor: "#6639B5",
  405. FrontColor: "#ffffff",
  406. SelectBackColor: "#ffffff",
  407. SelectFrontColor: "#1E1E1E",
  408. TagBackColor: "#E86D24",
  409. },
  410. {//配色5
  411. BackColor: "#3F51B5",
  412. FrontColor: "#ffffff",
  413. SelectBackColor: "#ffffff",
  414. SelectFrontColor: "#1E1E1E",
  415. TagBackColor: "#E54627",
  416. },
  417. {//配色6
  418. BackColor: "#1E88E5",
  419. FrontColor: "#ffffff",
  420. SelectBackColor: "#ffffff",
  421. SelectFrontColor: "#1E1E1E",
  422. TagBackColor: "#E54627",
  423. },
  424. {//配色7
  425. BackColor: "#039BE5",
  426. FrontColor: "#ffffff",
  427. SelectBackColor: "#ffffff",
  428. SelectFrontColor: "#1E1E1E",
  429. TagBackColor: "#E54627",
  430. },
  431. {//配色8
  432. BackColor: "#00ACC1",
  433. FrontColor: "#ffffff",
  434. SelectBackColor: "#ffffff",
  435. SelectFrontColor: "#1E1E1E",
  436. TagBackColor: "#E54627",
  437. },
  438. {//配色9
  439. BackColor: "#009688",
  440. FrontColor: "#ffffff",
  441. SelectBackColor: "#ffffff",
  442. SelectFrontColor: "#1E1E1E",
  443. TagBackColor: "#2A6358",
  444. },
  445. {//配色10
  446. BackColor: "#43A047",
  447. FrontColor: "#ffffff",
  448. SelectBackColor: "#ffffff",
  449. SelectFrontColor: "#1E1E1E",
  450. TagBackColor: "#2A6358",
  451. },
  452. {//配色11
  453. BackColor: "#71B12D",
  454. FrontColor: "#ffffff",
  455. SelectBackColor: "#ffffff",
  456. SelectFrontColor: "#1E1E1E",
  457. TagBackColor: "#2A6358",
  458. },
  459. {//配色12
  460. BackColor: "#CFDA37",
  461. FrontColor: "#1e1e1e",
  462. SelectBackColor: "#868E25",
  463. SelectFrontColor: "#FFFFFF",
  464. TagBackColor: "#868E25",
  465. },
  466. {//配色13
  467. BackColor: "#F9D342",
  468. FrontColor: "#1e1e1e",
  469. SelectBackColor: "#C46C28",
  470. SelectFrontColor: "#FFFFFF",
  471. TagBackColor: "#C46C28",
  472. },
  473. {//配色14
  474. BackColor: "#FF9F33",
  475. FrontColor: "#1e1e1e",
  476. SelectBackColor: "#C46C28",
  477. SelectFrontColor: "#FFFFFF",
  478. TagBackColor: "#C46C28",
  479. },
  480. {//配色15
  481. BackColor: "#EE7F33",
  482. FrontColor: "#ffffff",
  483. SelectBackColor: "#ffffff",
  484. SelectFrontColor: "#1E1E1E",
  485. TagBackColor: "#C43928",
  486. },
  487. {//配色16
  488. BackColor: "#FF5722",
  489. FrontColor: "#ffffff",
  490. SelectBackColor: "#ffffff",
  491. SelectFrontColor: "#1E1E1E",
  492. TagBackColor: "#C42843",
  493. },
  494. {//配色17
  495. BackColor: "#795548",
  496. FrontColor: "#ffffff",
  497. SelectBackColor: "#ffffff",
  498. SelectFrontColor: "#1E1E1E",
  499. TagBackColor: "#CC2A38",
  500. },
  501. {//配色18
  502. BackColor: "#616161",
  503. FrontColor: "#ffffff",
  504. SelectBackColor: "#ffffff",
  505. SelectFrontColor: "#1E1E1E",
  506. TagBackColor: "#9C3724",
  507. },
  508. {//配色19
  509. BackColor: "#FFBC00",
  510. FrontColor: "#1e1e1e",
  511. SelectBackColor: "#9C6226",
  512. SelectFrontColor: "#ffffff",
  513. TagBackColor: "#9C6226",
  514. },
  515. {//配色20
  516. BackColor: "#ACC6AA",
  517. FrontColor: "#1e1e1e",
  518. SelectBackColor: "#6F7F6D",
  519. SelectFrontColor: "#ffffff",
  520. TagBackColor: "#6F7F6D",
  521. },
  522. {//配色21
  523. BackColor: "#74B49B",
  524. FrontColor: "#ffffff",
  525. SelectBackColor: "#ffffff",
  526. SelectFrontColor: "#1e1e1e",
  527. TagBackColor: "#9A4391",
  528. },
  529. {//配色22
  530. BackColor: "#0B8457",
  531. FrontColor: "#ffffff",
  532. SelectBackColor: "#ffffff",
  533. SelectFrontColor: "#1e1e1e",
  534. TagBackColor: "#9A4391",
  535. },
  536. {//配色23
  537. BackColor: "#34699A",
  538. FrontColor: "#ffffff",
  539. SelectBackColor: "#ffffff",
  540. SelectFrontColor: "#1e1e1e",
  541. TagBackColor: "#D44139",
  542. },
  543. {//配色24
  544. BackColor: "#234A9A",
  545. FrontColor: "#ffffff",
  546. SelectBackColor: "#ffffff",
  547. SelectFrontColor: "#1e1e1e",
  548. TagBackColor: "#D44139",
  549. },
  550. {//配色25
  551. BackColor: "#786489",
  552. FrontColor: "#ffffff",
  553. SelectBackColor: "#ffffff",
  554. SelectFrontColor: "#1e1e1e",
  555. TagBackColor: "#E69109",
  556. },
  557. ];
  558. return arr;
  559. }
  560. module.exports = {
  561. getData: getData,
  562. postData: postData,
  563. shareGroup: shareGroup,
  564. payMoney: payMoney,
  565. downloadImage: downloadImage,
  566. getLocalHost: getLocalHost,
  567. getTimeFormat: getTimeFormat,
  568. getWindowHeight: getWindowHeight,
  569. getStorageValue: getStorageValue,
  570. getDifficulty: getDifficulty,
  571. getProgramList: getProgramList,
  572. gotoFeedback: gotoFeedback,
  573. getDetailColor: getDetailColor,
  574. changeStringToView: changeStringToView,
  575. changeViewToString: changeViewToString,
  576. encryptUrl: EncryptUrl,
  577. decryptUrl: DecryptUrl,
  578. }