App.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <script>
  2. export default {
  3. onLaunch: function () {
  4. // console.log('App Launch')
  5. //判断客户端类别
  6. if (/MicroMessenger/.test(window.navigator.userAgent)) {
  7. uni.setStorage({
  8. key: 'userAgent',
  9. data: 'wxAgent'
  10. });
  11. console.log('微信客户端');
  12. } else if (/AlipayClient/.test(window.navigator.userAgent)) {
  13. uni.setStorage({
  14. key: 'userAgent',
  15. data: 'aliAgent'
  16. });
  17. console.log('支付宝客户端');
  18. } else {
  19. uni.setStorage({
  20. key: 'userAgent',
  21. data: 'otherAgent'
  22. });
  23. console.log('其他浏览器');
  24. }
  25. // 判断从什么入口进入 车位锁等页面无需调用
  26. const backUrl = location.href,
  27. openidPage = this.config.onlyWxLogin, // 只需要穿openid的页面集合
  28. needValidPage = openidPage.filter((item) => backUrl.indexOf(item) > -1); // 是否为需要验证的页面集合
  29. const { openId } = this.vuex_wxinfo;
  30. console.log('openId', openId);
  31. console.log('needValidPage', needValidPage);
  32. if (openId && needValidPage.length === 0) {
  33. this.getUserInfo(openId);
  34. }
  35. // 获取参数
  36. this.getFreeTime();
  37. },
  38. onShow: function () {
  39. console.log('App Show');
  40. },
  41. onHide: function () {
  42. // console.log('App Hide')
  43. },
  44. methods: {
  45. /**
  46. * @description:
  47. * @param {*} openId
  48. * @return {*}
  49. */
  50. async getUserInfo(openId) {
  51. try {
  52. const queryParams = {
  53. loginType: 1,
  54. openid: openId,
  55. nickName: this?.vuex_wxinfo?.nickname,
  56. avatar: this?.vuex_wxinfo?.headImgUrl
  57. };
  58. const userInfo = await this.$u.api.userLoginApi.openidLoginApi({ ...queryParams });
  59. const { accessToken, needVerify } = userInfo.data;
  60. this.$u.vuex('vuex_token', accessToken);
  61. this.$u.vuex('vuex_hasLogin', true);
  62. if (needVerify) {
  63. localStorage.setItem('backUrl', this.backUrl);
  64. this.$u.route({
  65. url: 'pages/center/phoneLogin/phoneLogin',
  66. type: 'reLaunch'
  67. });
  68. }
  69. } catch (error) {
  70. this.$refs.uToast.show({
  71. title: '获取用户信息失败!',
  72. type: 'error'
  73. });
  74. }
  75. },
  76. /**
  77. * @description: 获取参数免费时长
  78. * @return {*}
  79. */
  80. async getFreeTime() {
  81. try {
  82. const { msg } = await this.$u.api.getParamsApi({ key: 'park.lock.freetime' });
  83. this.$u.vuex('free_time', msg);
  84. } catch (error) {
  85. console.log(error);
  86. }
  87. }
  88. }
  89. };
  90. </script>
  91. <style lang="scss">
  92. @import '/static/quill/quill.bubble.scss';
  93. @import '/static/quill/quill.snow.scss';
  94. @import '/static/quill/quill.core.scss';
  95. @import './static/css/iconfont.css';
  96. @import 'uview-ui/index.scss';
  97. /*每个页面公共css */
  98. </style>