App.vue 2.0 KB

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