Loading.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. //如果token 不合法,不存在,跳转登录页面
  48. _self.onNavTo("login");
  49. }
  50. },
  51. e => {
  52. console.log(e)
  53. });
  54. } else {
  55. //如果没有token,进入登录界面
  56. _self.onNavTo("login");
  57. }
  58. //预加载
  59. uni.preloadPage({url: "/pages/personal-page/personal/personal"});
  60. },
  61. methods: {
  62. ...mapMutations(['accountLogin']),
  63. onNavTo(navType) {
  64. // uni.hideToast();
  65. console.log('当前loading 跳转的页面是 navType:',navType);
  66. if (navType == "userInfo") {
  67. uni.redirectTo({
  68. url: "../../my-page/userInfo/userInfo"
  69. })
  70. } else if (navType == "personal") {
  71. // uni.redirectTo({
  72. uni.switchTab({
  73. url: "../../personal-page/personal/personal"
  74. })
  75. } else {
  76. uni.redirectTo({
  77. url: "../../login-page/login/login"
  78. })
  79. }
  80. }
  81. }
  82. }
  83. </script>
  84. <style>
  85. .loading-container-bg {
  86. position: absolute;
  87. left: 0;
  88. top: 0;
  89. bottom: 0;
  90. right: 0;
  91. width: 750rpx;
  92. height: 100%;
  93. }
  94. .loading-container-bg image {
  95. width: 100%;
  96. height: 100%;
  97. }
  98. </style>