App - 副本.vue 2.2 KB

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