index2.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. "use strict";
  2. function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
  3. function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
  4. function strToObj(val) {
  5. var obj = {};
  6. var str = val.substr(1);
  7. var arr = str.split('&');
  8. for (var i = 0; i < arr.length; i++) {
  9. var newArr = arr[i].split('=');
  10. obj[newArr[0]] = newArr[1];
  11. }
  12. return obj;
  13. } // if (location.search&&strToObj(location.search).code) {
  14. // let reqdata = {
  15. // url: location.href,
  16. // type: 1
  17. // }
  18. // console.log(reqdata);
  19. // postHttps('manage/wx/getWxConfig',{reqdata}).then(r => {
  20. // alert(JSON.stringify(r))
  21. // let {object:{
  22. // agentId:agentid,
  23. // appId: corpid,
  24. // nonceStr,
  25. // signature,
  26. // timestamp,
  27. // }} = r
  28. // wx.agentConfig({
  29. // corpid,
  30. // timestamp,
  31. // nonceStr,
  32. // signature,
  33. // agentid,
  34. // jsApiList: ['openUserProfile','selectEnterpriseContact','openEnterpriseChat','hideOptionMenu','hideMenuItems'],
  35. // success: function() {
  36. // // 回调
  37. // alert('success')
  38. // let { code } = strToObj(location.search)
  39. // let reqdata = {
  40. // code,
  41. // type:1,
  42. // loginType: window.screen.width>1000?2:1
  43. // }
  44. // // let {object:{userId}} = await postHttps('manage/wx/getWxUserInfo',{reqdata})
  45. // // globalUserId = userId
  46. // // app.username = username
  47. // // app.avatar = avatar
  48. // postHttps('manage/wx/getWxUserInfo',{reqdata}).then(r => {
  49. // let {object:{userId}} = r
  50. // Cookies.set('userId', userId)
  51. // location.href=location.href.split('?')[0] + (window.screen.width > 1000 ? '/repair/#/pc-list' : '/repair/#/home')
  52. // })
  53. // },
  54. // fail: function(res) {
  55. // alert(JSON.stringify(res))
  56. // if(res.errMsg.indexOf('function not exist') > -1){
  57. // alert('版本过低请升级')
  58. // }
  59. // }
  60. // })
  61. // })
  62. // } else {
  63. // getHttps('/manage/wx/getUrl/1').then(r => {
  64. // location.href = r.object
  65. // })
  66. // }
  67. window.addEventListener('load', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2() {
  68. var reqdata, _yield$postHttps, _yield$postHttps$obje, agentid, corpid, nonceStr, signature, timestamp, url, _yield$getHttps, object;
  69. return regeneratorRuntime.wrap(function _callee2$(_context2) {
  70. while (1) {
  71. switch (_context2.prev = _context2.next) {
  72. case 0:
  73. if (!(location.search && strToObj(location.search).code)) {
  74. _context2.next = 14;
  75. break;
  76. }
  77. reqdata = {
  78. url: location.href,
  79. type: 1
  80. };
  81. _context2.next = 4;
  82. return postHttps('manage/wx/getWxConfig', {
  83. reqdata: reqdata
  84. });
  85. case 4:
  86. _yield$postHttps = _context2.sent;
  87. _yield$postHttps$obje = _yield$postHttps.object;
  88. agentid = _yield$postHttps$obje.agentId;
  89. corpid = _yield$postHttps$obje.appId;
  90. nonceStr = _yield$postHttps$obje.nonceStr;
  91. signature = _yield$postHttps$obje.signature;
  92. timestamp = _yield$postHttps$obje.timestamp;
  93. wx.agentConfig({
  94. corpid: corpid,
  95. timestamp: timestamp,
  96. nonceStr: nonceStr,
  97. signature: signature,
  98. agentid: agentid,
  99. jsApiList: ['openUserProfile', 'selectEnterpriseContact', 'openEnterpriseChat'],
  100. success: function () {
  101. var _success = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(res) {
  102. var _strToObj, code, reqdata, _yield$postHttps2, _yield$postHttps2$obj, userId, avatar, username, _strToObj2, state, orderId;
  103. return regeneratorRuntime.wrap(function _callee$(_context) {
  104. while (1) {
  105. switch (_context.prev = _context.next) {
  106. case 0:
  107. // 回调
  108. _strToObj = strToObj(location.search), code = _strToObj.code;
  109. reqdata = {
  110. code: code,
  111. type: 1,
  112. loginType: window.screen.width > 1000 ? 2 : 1
  113. };
  114. _context.next = 4;
  115. return postHttps('manage/wx/getWxUserInfo', {
  116. reqdata: reqdata
  117. });
  118. case 4:
  119. _yield$postHttps2 = _context.sent;
  120. _yield$postHttps2$obj = _yield$postHttps2.object;
  121. userId = _yield$postHttps2$obj.userId;
  122. avatar = _yield$postHttps2$obj.avatar;
  123. username = _yield$postHttps2$obj.username;
  124. _strToObj2 = strToObj(location.search), state = _strToObj2.state;
  125. localStorage.setItem('avatar', avatar); //2
  126. localStorage.setItem('username', username); //2
  127. orderId = state.split('-')[1] - 0;
  128. Cookies.set('userId', userId); // location.href=location.href.split('?')[0] + (window.screen.width > 1000 ? '/pc' : orderId?'/front/#/detail/'+orderId:'/front/#/index') //2
  129. location.href = location.href.split('?')[0] + (window.screen.width > 1000 ? orderId ? '/repair1/#/pc-detail/' + orderId : '/repair1/#/pc-list' : orderId ? '/repair1/#/detail/' + orderId : '/repair1/#/home'); // location.href=location.href.split('?')[0] + (window.screen.width > 1000 ? '/repair1/#/pc-form' : '/repair1/#/info')
  130. case 15:
  131. case "end":
  132. return _context.stop();
  133. }
  134. }
  135. }, _callee);
  136. }));
  137. function success(_x) {
  138. return _success.apply(this, arguments);
  139. }
  140. return success;
  141. }(),
  142. fail: function fail(res) {
  143. alert(JSON.stringify(res));
  144. if (res.errMsg.indexOf('function not exist') > -1) {
  145. alert('版本过低请升级');
  146. }
  147. }
  148. });
  149. _context2.next = 21;
  150. break;
  151. case 14:
  152. url = '/manage/wx/getUrl/1/' + (strToObj(location.search).orderId || 0);
  153. alert(url);
  154. _context2.next = 18;
  155. return getHttps(url);
  156. case 18:
  157. _yield$getHttps = _context2.sent;
  158. object = _yield$getHttps.object;
  159. location.href = object;
  160. case 21:
  161. case "end":
  162. return _context2.stop();
  163. }
  164. }
  165. }, _callee2);
  166. })));
  167. window.addEventListener('pageshow', function (e) {
  168. if (e.persisted || window.performance && window.performance.navigation.type === 2) {
  169. window.location.reload();
  170. }
  171. }, false);