App.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. const paramsPage = ['pages/goldPlan/goldPlan', 'pages/wechatLogin/wechatLogin', 'pages/VehicleInquiry/VehicleInquiry'],
  37. paramsValidPage = paramsPage.filter((item) => backUrl.indexOf(item) > -1);
  38. if (paramsValidPage.length === 0) {
  39. this.getFreeTime();
  40. }
  41. },
  42. onShow: function () {
  43. console.log('App Show');
  44. },
  45. onHide: function () {
  46. // console.log('App Hide')
  47. },
  48. methods: {
  49. /**
  50. * @description:
  51. * @param {*} openId
  52. * @return {*}
  53. */
  54. async getUserInfo(openId) {
  55. try {
  56. const queryParams = {
  57. loginType: 1,
  58. openid: openId,
  59. nickName: this?.vuex_wxinfo?.nickname,
  60. avatar: this?.vuex_wxinfo?.headImgUrl
  61. };
  62. const userInfo = await this.$u.api.userLoginApi.openidLoginApi({ ...queryParams });
  63. const { accessToken, needVerify } = userInfo.data;
  64. this.$u.vuex('vuex_token', accessToken);
  65. this.$u.vuex('vuex_hasLogin', true);
  66. if (needVerify) {
  67. localStorage.setItem('backUrl', this.backUrl);
  68. this.$u.route({
  69. url: 'pages/center/phoneLogin/phoneLogin',
  70. type: 'reLaunch'
  71. });
  72. }
  73. } catch (error) {
  74. this.$refs.uToast.show({
  75. title: '获取用户信息失败!',
  76. type: 'error'
  77. });
  78. }
  79. },
  80. /**
  81. * @description: 获取参数免费时长
  82. * @return {*}
  83. */
  84. async getFreeTime() {
  85. try {
  86. const { msg } = await this.$u.api.getParamsApi({ key: 'park.lock.freetime' });
  87. this.$u.vuex('free_time', msg);
  88. } catch (error) {
  89. console.log(error);
  90. }
  91. }
  92. }
  93. };
  94. </script>
  95. <style lang="scss">
  96. @import '/static/quill/quill.bubble.scss';
  97. @import '/static/quill/quill.snow.scss';
  98. @import '/static/quill/quill.core.scss';
  99. @import './static/css/iconfont.css';
  100. @import 'uview-ui/index.scss';
  101. /*每个页面公共css */
  102. </style>