App.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <script>
  2. import { mapMutations, mapActions, mapGetters } from 'vuex'
  3. import { setTimeout } from 'timers'
  4. import { getUser, wxLoginFn } from '@/utils/auth'
  5. export default {
  6. // 全端,数据共享,还可以解决页面初始化模板访问不到值得问题
  7. // 有坑 分包里的页面访问不到
  8. globalData: {
  9. },
  10. onLaunch() {
  11. // this.getAllOptions()
  12. // #ifdef MP-WEIXIN
  13. wxLoginFn()
  14. let extConfig = wx.getExtConfigSync ? wx.getExtConfigSync() : {}
  15. console.log('extConfig', extConfig)
  16. uni.setStorageSync('account', extConfig.account)
  17. // #endif
  18. // 开发
  19. uni.setStorageSync('token', 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiIsImp0aSI6IjFfMTI1MzY2MzAifQ.eyJpc3MiOiJodHRwOlwvXC9tLmhoYi5jb20iLCJhdWQiOiJodHRwOlwvXC9tLmhoYi5jb20iLCJqdGkiOiIxXzEyNTM2NjMwIiwiaWF0IjoxNTc0NDIzMDc4LCJuYmYiOjE1NzQ0MjMwNzgsImV4cCI6MTU3NDQyNjY3OCwidXNlcklkIjoxMjUzNjYzMH0.v_T9NuFRpzuI7GtwuuuNlVg6EylImaCUwqo2A6NRTE4')
  20. // uni.setStorageSync('account', '12358')
  21. // 登录
  22. if (this.$constant.source == 'business') {
  23. this.$util.getCheckLogin().then(res => {
  24. if (res) {
  25. getUser()
  26. }
  27. })
  28. }
  29. },
  30. onShow() {
  31. // this.isLogin()
  32. },
  33. onHide() {
  34. },
  35. onError(err) {
  36. console.error(err, '错误捕获')
  37. },
  38. methods: {
  39. isLogin() {
  40. let token = uni.getStorageSync('token')
  41. if (!token) {
  42. uni.reLaunch({
  43. url: '/pages/page/login/index'
  44. })
  45. }
  46. }
  47. // ...mapMutations(['setLoginInfo'])
  48. // #ifdef MP-WEIXIN
  49. // wxLogin() {
  50. // uni.login({
  51. // provider: 'weixin',
  52. // success: res => {
  53. // uni.setStorageSync('code', res.code)
  54. // console.log(res.code, 'res.code')
  55. // postWxCode({ code: res.code }).then(subRes => {
  56. // const { openid, session_key, unionid } = subRes.data
  57. // this.setLoginInfo({
  58. // openid,
  59. // session_key,
  60. // unionid
  61. // })
  62. // })
  63. // }
  64. // })
  65. // }
  66. // #endif
  67. }
  68. }
  69. </script>
  70. <style lang="scss">
  71. //没有scss变量方法的,主要引入 这样打包的时候就不会所以的组件都打包进去
  72. @import './static/iconfont/iconfont.css';
  73. @import './static/css/uni2.css';
  74. @import './static/css/base.scss';
  75. @import './static/css/common.scss';
  76. @import './static/css/reset.scss';
  77. page {
  78. height: 100%;
  79. }
  80. </style>