index.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. function strToObj(val) {
  2. let obj = {}
  3. let str = val.substr(1)
  4. let arr = str.split('&')
  5. for (let i = 0; i < arr.length; i++) {
  6. let newArr = arr[i].split('=')
  7. obj[newArr[0]] = newArr[1]
  8. }
  9. return obj
  10. }
  11. // if (location.search&&strToObj(location.search).code) {
  12. // let reqdata = {
  13. // url: location.href,
  14. // type: 1
  15. // }
  16. // console.log(reqdata);
  17. // postHttps('manage/wx/getWxConfig',{reqdata}).then(r => {
  18. // alert(JSON.stringify(r))
  19. // let {object:{
  20. // agentId:agentid,
  21. // appId: corpid,
  22. // nonceStr,
  23. // signature,
  24. // timestamp,
  25. // }} = r
  26. // wx.agentConfig({
  27. // corpid,
  28. // timestamp,
  29. // nonceStr,
  30. // signature,
  31. // agentid,
  32. // jsApiList: ['openUserProfile','selectEnterpriseContact','openEnterpriseChat','hideOptionMenu','hideMenuItems'],
  33. // success: function() {
  34. // // 回调
  35. // alert('success')
  36. // let { code } = strToObj(location.search)
  37. // let reqdata = {
  38. // code,
  39. // type:1,
  40. // loginType: window.screen.width>1000?2:1
  41. // }
  42. // // let {object:{userId}} = await postHttps('manage/wx/getWxUserInfo',{reqdata})
  43. // // globalUserId = userId
  44. // // app.username = username
  45. // // app.avatar = avatar
  46. // postHttps('manage/wx/getWxUserInfo',{reqdata}).then(r => {
  47. // let {object:{userId}} = r
  48. // Cookies.set('userId', userId)
  49. // location.href=location.href.split('?')[0] + (window.screen.width > 1000 ? '/repair/#/pc-list' : '/repair/#/home')
  50. // })
  51. // },
  52. // fail: function(res) {
  53. // alert(JSON.stringify(res))
  54. // if(res.errMsg.indexOf('function not exist') > -1){
  55. // alert('版本过低请升级')
  56. // }
  57. // }
  58. // })
  59. // })
  60. // } else {
  61. // getHttps('/manage/wx/getUrl/1').then(r => {
  62. // location.href = r.object
  63. // })
  64. // }
  65. window.addEventListener('load', async () => {
  66. if (location.search&&strToObj(location.search).code) {
  67. let reqdata = {
  68. url: location.href,
  69. type: 1
  70. }
  71. let {object:{
  72. agentId:agentid,
  73. appId: corpid,
  74. nonceStr,
  75. signature,
  76. timestamp,
  77. }} = await postHttps('manage/wx/getWxConfig',{reqdata})
  78. wx.agentConfig({
  79. corpid,
  80. timestamp,
  81. nonceStr,
  82. signature,
  83. agentid,
  84. jsApiList: ['openUserProfile','selectEnterpriseContact','openEnterpriseChat'],
  85. success: async function(res) {
  86. // 回调
  87. alert('success')
  88. let { code } = strToObj(location.search)
  89. let reqdata = {
  90. code,
  91. type:1,
  92. loginType: window.screen.width>1000?2:1
  93. }
  94. let {object:{userId}} = await postHttps('manage/wx/getWxUserInfo',{reqdata})
  95. // alert(JSON.stringify(object))
  96. // globalUserId = userId
  97. // app.username = username
  98. // app.avatar = avatar
  99. let {state} = strToObj(location.search)
  100. let orderId = state.split('-')[1] - 0
  101. Cookies.set('userId', userId)
  102. location.href=location.href.split('?')[0] + (window.screen.width > 1000 ? orderId?'/repair1/#/pc-detail/'+orderId:'/repair1/#/pc-list' : orderId?'/repair1/#/detail/'+orderId:'/repair1/#/home')
  103. // app.page = (window.screen.width > 1000 ? 22 : 1)
  104. },
  105. fail: function(res) {
  106. alert(JSON.stringify(res))
  107. if(res.errMsg.indexOf('function not exist') > -1){
  108. alert('版本过低请升级')
  109. }
  110. }
  111. })
  112. } else {
  113. let url = '/manage/wx/getUrl/1/' + (strToObj(location.search).orderId||0)
  114. let {object} = await getHttps(url)
  115. location.href = object
  116. }
  117. })
  118. window.addEventListener('pageshow', function (e) {
  119.     if(e.persisted || (window.performance && window.performance.navigation.type === 2)){
  120.         window.location.reload();
  121.     }
  122. },false);