Logon.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. <script>
  2. import wx from 'weixin-js-sdk';
  3. import {
  4. SY
  5. } from '@/api/index.js'
  6. import {
  7. HTTP
  8. } from '@/api/http.js'
  9. import {
  10. setUserInfo, //存储用户信息
  11. setToken //储存用户token
  12. } from "@/utils/auth.js";
  13. import {
  14. jieqiFn,
  15. BASE_URL,
  16. CDX
  17. } from '@/config'
  18. export default {
  19. onLaunch: function() {
  20. console.log('App Launch')
  21. },
  22. onShow: function() {
  23. console.log('App Show')
  24. },
  25. onHide: function() {
  26. console.log('App Hide')
  27. },
  28. data() {
  29. return {
  30. page: "",
  31. code: "",
  32. data: undefined,
  33. url: undefined
  34. };
  35. },
  36. methods: {
  37. // 获取链接上带的参数
  38. getQueryString(name) {
  39. var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
  40. var r = window.location.search.substr(1).match(reg);
  41. console.log(window.location.search, '我是链接里携带的参数');
  42. if (r != null) {
  43. return unescape(r[2]);
  44. }
  45. return null;
  46. },
  47. infff(data) {
  48. console.log('url', this.url, data)
  49. /* eslint-disable */
  50. let lat = this;
  51. wx.ready(() => { //需在用户可能点击分享按钮前就先调用
  52. wx.updateTimelineShareData({
  53. title: '《阳光少年·二十四节气养生文化夏令营》活动火热进行中', // 分享标题
  54. link: lat.url, // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
  55. imgUrl: data.img_url, // 分享图标
  56. success: () => {
  57. // 设置成功
  58. console.log('1 设置成功')
  59. wx.updateAppMessageShareData({
  60. title: '《阳光少年·二十四节气养生文化夏令营》活动火热进行中', // 分享标题
  61. // 您的好友“张三”和阳光少年“王五”送您一个花神红包,请点击领取
  62. desc: '您的好友“' + data.user_name +
  63. '”和阳光少年“' + data.receive_user_name +
  64. '”送您一个花神红包,请点击领取', // 分享描述
  65. link: lat.url, // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
  66. imgUrl: data.img_url, // 分享图标
  67. success: function() {
  68. uni.setStorageSync("fenXiang", "true")
  69. // 设置成功
  70. console.log('2 设置成功')
  71. let state = lat.getQueryString("state") || "";
  72. console.log('state', state)
  73. let strings = state.split("-");
  74. console.log('strings', strings)
  75. if (strings.length > 2) {
  76. let string = strings[0];
  77. let string1 = strings[1];
  78. let share_user_Id = undefined;
  79. let bFxren = undefined;
  80. if (string && string.indexOf('sid_') > -1) {
  81. share_user_Id = string.split('sid_')[1];
  82. }
  83. if (string1 && string1.indexOf('bFxen_') > -1) {
  84. bFxren = string1.split('_')[1];
  85. }
  86. // this.$router.push({path:'/redict',share_user_Id:share_user_Id,beifenxiang_id:bFxren})
  87. uni.navigateTo({
  88. url: '/pages/luoDi/luoDi?share_user_Id=' +
  89. share_user_Id +
  90. '&beifenxiang_id=' + bFxren
  91. })
  92. }
  93. },
  94. fail: (e) => {
  95. console.log('2', e)
  96. }
  97. })
  98. },
  99. fail: (e) => {
  100. console.log('1', e)
  101. }
  102. })
  103. })
  104. wx.error(function(res) {
  105. // config信息验证失败会执行error函数,如签名过期导致验证失败,具体错误信息可以打开config的debug模式查看,也可以在返回的res参数中查看,对于SPA可以在这里更新签名。
  106. console.log(res)
  107. })
  108. },
  109. // 解析参数
  110. getQueryParams(url) {
  111. const params = new URLSearchParams(new URL(url).search);
  112. const obj = {};
  113. for (const [key, value] of params.entries()) {
  114. obj[key] = value;
  115. }
  116. return obj;
  117. }
  118. },
  119. created() {
  120. if(CDX == ""){//没有重定向就直接去首页
  121. uni.reLaunch({
  122. url:"/pages/index/index"
  123. })
  124. }
  125. // console.log("记录了吗啊")
  126. if (CDX != "") { //有重定向
  127. uni.removeStorageSync("fenXiang")
  128. this.code = this.getQueryString("code") || ""; //授权登录信息
  129. let lat = this;
  130. if (window.location.href.indexOf('share_user_id') > -1) {
  131. let wx_url =
  132. "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxf1f500397f18b91d&redirect_uri=https://ygsn.lastbs.com?page=null&response_type=code&scope=snsapi_userinfo&state=sid_" +
  133. this.getQueryString("share_user_id") + "-bFxen_" + this.getQueryString("bfxren") +
  134. "-#wechat_redirect";
  135. window.location.href = wx_url; // 跳转路径 移动端
  136. }
  137. if (this.code) {
  138. let state = lat.getQueryString("state") || "";
  139. console.log('state', state)
  140. let strings = state.split("-");
  141. console.log('strings', strings)
  142. let share_user_Id = undefined;
  143. let bFxren = undefined;
  144. if (strings.length > 2) {
  145. let string = strings[0];
  146. let string1 = strings[1];
  147. // let share_user_Id = undefined;
  148. // let bFxren = undefined;
  149. if (string && string.indexOf('sid_') > -1) {
  150. share_user_Id = string.split('sid_')[1];
  151. }
  152. if (string1 && string1.indexOf('bFxen_') > -1) {
  153. bFxren = string1.split('_')[1];
  154. }
  155. // this.$router.push({path:'/redict',share_user_Id:share_user_Id,beifenxiang_id:bFxren})
  156. uni.navigateTo({
  157. url: '/pages/luoDi/luoDi?share_user_Id=' +
  158. share_user_Id +
  159. '&beifenxiang_id=' + bFxren
  160. })
  161. }
  162. // 登录逻辑
  163. SY.login({
  164. code: lat.code,
  165. share_user_id: share_user_Id,
  166. relation_id: bFxren
  167. }).then((res) => {
  168. console.log('登录信息', res, lat.code);
  169. if (res.code == 200) {
  170. setToken(res.data.app_token)
  171. uni.setStorageSync('open_id', res.data.open_id);
  172. console.log('用户id', res.data.user_id)
  173. lat.url = window.location.href.split("#")[0] + '?page=shareUrl&&share_user_id=' + res
  174. .data
  175. .user_id + "&&bfxren=";
  176. let chae = undefined;
  177. SY.shareData().then(res => {
  178. chae = res.data;
  179. console.log('SY.shareData()_1', res)
  180. lat.url = lat.url + res.data.user_flora_id;
  181. // console.log('SY.shareData()', lat.data)
  182. console.log('lat.url', lat.url)
  183. HTTP.SY.getWxConfig({
  184. url: window.location.href.split("#")[0]
  185. })
  186. .then((res) => {
  187. var result = res.data
  188. // eslint-disable-next-line
  189. if (!wx) {
  190. console.log('请升级当前微信版本')
  191. }
  192. wx.checkJsApi({
  193. jsApiList: ['updateTimelineShareData',
  194. 'updateAppMessageShareData',
  195. 'onMenuShareTimeline',
  196. 'onMenuShareAppMessage'
  197. ], // 需要检测的JS接口列表,所有JS接口列表见附录2,
  198. success: function(res) {
  199. console.log('res', res)
  200. }
  201. });
  202. wx.config({
  203. debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
  204. appId: result.appId, // 必填,公众号的唯一标识
  205. timestamp: result.timestamp, // 必填,生成签名的时间戳
  206. nonceStr: result.nonceStr, // 必填,生成签名的随机串
  207. signature: result.signature, // 必填,签名
  208. jsApiList: ['updateTimelineShareData',
  209. 'updateAppMessageShareData',
  210. 'onMenuShareTimeline',
  211. 'onMenuShareAppMessage'
  212. ] // 必填,需要使用的JS接口列表
  213. })
  214. setTimeout((res) => {
  215. console.log("需要使用的JS接口列表:ok", res)
  216. lat.infff(chae)
  217. }, 500)
  218. })
  219. })
  220. }
  221. })
  222. } else {
  223. let wx_url =
  224. `https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxf1f500397f18b91d&redirect_uri=${CDX}?page=null&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect`;
  225. window.location.href = wx_url; // 跳转路径 移动端
  226. }
  227. }
  228. }
  229. }
  230. </script>
  231. <style lang='scss'>
  232. page {
  233. background-color: #fff;
  234. }
  235. /*每个页面公共css */
  236. </style>