Loading.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <!-- 初始化判断页面 -->
  2. <template>
  3. <view>
  4. <view class="loading-container-bg">
  5. <!-- <image mode="aspectFill" src="../../../static/loading.jpg"></image> -->
  6. </view>
  7. </view>
  8. </template>
  9. <script>
  10. import config from '../../../common/config.js';
  11. import reqUtil from "@/util/util-js/requstUtil.js";
  12. import {
  13. mapState,
  14. mapMutations
  15. } from 'vuex'
  16. export default {
  17. data() {
  18. return {}
  19. },
  20. computed: mapState(['bNewUser']),
  21. onLoad() {},
  22. onShow() {
  23. let bCanLoading = false;
  24. //验证登录存储
  25. //如果登录过,直接跳转登录页面
  26. const value = uni.getStorageSync('token');
  27. var _self = this;
  28. if (value) {
  29. console.log("验证登录Token值:",value,config.URL.VERIFICATION);
  30. reqUtil.requestData(config.URL.VERIFICATION, {
  31. token: value
  32. }).then(res => {
  33. console.log('requestData VERIFICATION =====', res);
  34. if (res.code == 0) {
  35. // TODO token时效性问题
  36. _self.$store.state.token = value;
  37. _self.$store.state.bNewUser = res.data.newUser;
  38. _self.accountLogin(function() {
  39. // console.log("======");
  40. if (_self.bNewUser) {
  41. _self.onNavTo("userInfo");
  42. } else {
  43. _self.onNavTo("personal");
  44. }
  45. });
  46. } else {
  47. //清空保存的storage
  48. uni.clearStorageSync();
  49. //如果token 不合法,不存在,跳转登录页面
  50. _self.onNavTo("login");
  51. }
  52. },
  53. e => {
  54. console.log(e)
  55. });
  56. } else {
  57. //如果没有token,进入登录界面
  58. _self.onNavTo("login");
  59. }
  60. //预加载
  61. // uni.preloadPage({url: "../../platform/app-plus/subNVue/guide"});
  62. },
  63. methods: {
  64. ...mapMutations(['accountLogin']),
  65. onNavTo(navType) {
  66. // uni.hideToast();
  67. console.log('当前loading 跳转的页面是 navType:',navType);
  68. if (navType == "userInfo") {
  69. uni.redirectTo({
  70. url: "../../my-page/userInfo/userInfo"
  71. })
  72. } else if (navType == "personal") {
  73. // uni.redirectTo({
  74. uni.switchTab({
  75. url: "../../personal-page/personal/personal"
  76. })
  77. } else {
  78. uni.redirectTo({
  79. url: "../../login-page/login/login"
  80. })
  81. }
  82. }
  83. }
  84. }
  85. </script>
  86. <style>
  87. .loading-container-bg {
  88. position: absolute;
  89. left: 0;
  90. top: 0;
  91. bottom: 0;
  92. right: 0;
  93. width: 750rpx;
  94. height: 100%;
  95. }
  96. .loading-container-bg image {
  97. width: 100%;
  98. height: 100%;
  99. }
  100. </style>