App.vue 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. onLaunch() {
  10. // this.getAllOptions()
  11. // 删除缓存
  12. if (process.env.NODE_ENV == "production") {
  13. uni.removeStorageSync("shopUser");
  14. }
  15. // #ifdef MP-WEIXIN
  16. // wxLoginFn()
  17. // uni.clearStorage()
  18. const extConfig = wx.getExtConfigSync ? wx.getExtConfigSync() : {};
  19. uni.setStorageSync("account", extConfig.account);
  20. // #endif
  21. // #ifdef H5
  22. // H5开发环境无法微信授权,使用固定的用户 shish 2020.4.30
  23. if (process.env.NODE_ENV == "development") {
  24. uni.setStorageSync(
  25. "token",
  26. "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiIsImp0aSI6IjBfMTI1NDM0MzEifQ.eyJpc3MiOiJodHRwczpcL1wvYXBpLm1hbGwuaHVhbWwuY29tIiwiYXVkIjoiaHR0cHM6XC9cL2FwaS5tYWxsLmh1YW1sLmNvbSIsImp0aSI6IjBfMTI1NDM0MzEiLCJpYXQiOjE1ODgyMzAwMjgsIm5iZiI6MTU4ODIzMDAyOCwiZXhwIjoxNTk2ODcwMDI4LCJ1bmlxdWVJZCI6IjEyNTQzNDMxIiwic291cmNlSWQiOjB9.Tmw2h9pucpyctvtB--i0dg-zTcVMIJZ1PtnWTLLwEEo"
  27. );
  28. uni.setStorageSync("account", "12358");
  29. }
  30. // #endif
  31. },
  32. onShow() {
  33. // this.isLogin()
  34. },
  35. onHide() {},
  36. onError(err) {
  37. console.error(err, "错误捕获");
  38. },
  39. methods: {
  40. isLogin() {
  41. let token = uni.getStorageSync("token");
  42. if (!token) {
  43. uni.reLaunch({
  44. url: "/pages/page/login/index"
  45. });
  46. }
  47. }
  48. // ...mapMutations(['setLoginInfo'])
  49. // #ifdef MP-WEIXIN
  50. // wxLogin() {
  51. // uni.login({
  52. // provider: 'weixin',
  53. // success: res => {
  54. // uni.setStorageSync('code', res.code)
  55. // console.log(res.code, 'res.code')
  56. // postWxCode({ code: res.code }).then(subRes => {
  57. // const { openid, session_key, unionid } = subRes.data
  58. // this.setLoginInfo({
  59. // openid,
  60. // session_key,
  61. // unionid
  62. // })
  63. // })
  64. // }
  65. // })
  66. // }
  67. // #endif
  68. }
  69. };
  70. </script>
  71. <style lang="scss">
  72. //没有scss变量方法的,主要引入 这样打包的时候就不会所有的组件都打包进去
  73. @import "./static/iconfont/iconfont.css";
  74. @import "./static/css/uni2.css";
  75. @import "./static/css/base.scss";
  76. @import "./static/css/common.scss";
  77. @import "./static/css/reset.scss";
  78. page {
  79. height: 100%;
  80. }
  81. </style>