App.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <script>
  2. import config from './config'
  3. import store from '@/store'
  4. import { getToken,getTokens,getSsoAdminToken } from '@/utils/auth'
  5. export default {
  6. onLaunch: function() {
  7. this.initApp()
  8. },
  9. methods: {
  10. // 初始化应用
  11. initApp() {
  12. // 初始化应用配置
  13. this.initConfig()
  14. // 检查用户登录状态
  15. //#ifdef H5
  16. //this.checkLogins()
  17. //#endif
  18. },
  19. initConfig() {
  20. this.globalData.config = config
  21. // if (this.globalData.config.VITE_SSO_LOGIN == true&&!getToken()) {
  22. // this.$tab.reLaunch('/pages/loginSso')
  23. // // getSsoToken();
  24. // };
  25. },
  26. checkLogin() {
  27. if (!getToken()) {
  28. this.$tab.reLaunch('/pages/login')
  29. }
  30. },
  31. checkLogins() {
  32. if (!getToken()) {
  33. // this.$tab.reLaunch('/pages/work/CleanGov/')
  34. // // 非静默授权,第一次有弹框
  35. this.code = ''
  36. var callback_url = 'https://tools-m.huaxiazhizao.com/#/pages/trade/shoe-style/index'
  37. // 获取页面url
  38. var appid = 'wx2cfd24c7380cdc08'
  39. this.code = this.getUrlCode().code
  40. // 截取code
  41. if (this.code == null || this.code === '') {
  42. // 如果没有code,则去请求
  43. window.location.href =
  44. `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${encodeURIComponent( callback_url )}&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect`
  45. } else {
  46. // 当code不等于空时,调用后端接口获取用户信息
  47. this.getUserInfo()
  48. // 你自己的业务逻辑
  49. }
  50. }else{
  51. var options = uni.getStorageSync('options')
  52. if (options) {
  53. this.$tab.reLaunch('/pages/trade/shoe-style/ShoeStyleView')
  54. } else { //如果没有上一页返回首页
  55. this.$tab.reLaunch('/pages/trade/shoe-style/index')
  56. }
  57. }
  58. },
  59. getUrlCode() {
  60. // 截取url中的code方法
  61. var url = location.search
  62. var theRequest = new Object()
  63. if (url.indexOf('?') != -1) {
  64. var str = url.substr(1)
  65. var strs = str.split('&')
  66. for (var i = 0; i < strs.length; i++) {
  67. theRequest[strs[i].split('=')[0]] = strs[i].split('=')[1]
  68. }
  69. }
  70. return theRequest
  71. },
  72. getUserInfo() {
  73. let data = {}
  74. data.code = this.code
  75. data.appid = 'wx2cfd24c7380cdc08'
  76. authorizeLogin(data).then(res => {
  77. uni.setStorageSync('X-Token', res.data.token)
  78. }).catch(() => {})
  79. },
  80. }
  81. }
  82. </script>
  83. <style lang="scss">
  84. @import '@/static/scss/index.scss'
  85. uni-list-item .uni-list-item__extra{
  86. flex:1
  87. }
  88. .uni-list-item .uni-list-item__content{
  89. flex: none;
  90. }
  91. </style>