zhangzengfei
2021-06-07 e23a219e6e6056f6da5405881768a90c39097933
pages/main/main.vue
@@ -8,8 +8,7 @@
         <view class="chart-income">6.3</view>
         <view class="charts-box">
            <qiun-data-charts type="line" :chartData="chartData" :errorShow="false"
               :eopts="{seriesTemplate:{smooth:true}}"
               background="none"/>
               :eopts="{seriesTemplate:{smooth:true}}" background="none" />
         </view>
      </view>
@@ -82,10 +81,6 @@
      mapMutations
   } from 'vuex'
   import {
      univerifyLogin
   } from '@/common/univerify.js'
   export default {
      data() {
         return {
@@ -143,72 +138,23 @@
         let uniIdToken = uni.getStorageSync('uni_id_token')
         if (uniIdToken) {
            this.login(uni.getStorageSync('username'))
            uniCloud.callFunction({
               name: 'user-center',
               data: {
                  action: 'checkToken',
               },
               success: (e) => {
                  console.log('checkToken success', e);
                  if (e.result.code > 0) {
                     //token过期或token不合法,重新登录
                     if (this.forcedLogin) {
                        uni.reLaunch({
                           url: '../login/login'
                        });
                     } else {
                        uni.navigateTo({
                           url: '../login/login'
                        });
                     }
                  }
               },
               fail(e) {
                  uni.showModal({
                     content: JSON.stringify(e),
                     showCancel: false
                  })
               }
            })
            // 验证token
            if (false) {
               uni.reLaunch({
                  url: '../login/login'
               });
            }
         } else {
            this.guideToLogin()
            uni.reLaunch({
               url: '../login/login'
            });
         }
      },
      methods: {
         ...mapMutations(['login']),
         handleClick(tabName) {
            this.activeName = tabName;
         },
         guideToLogin() {
            uni.showModal({
               title: '未登录',
               content: '您未登录,需要登录后才能继续',
               /**
                * 如果需要强制登录,不显示取消按钮
                */
               showCancel: !this.forcedLogin,
               success: (res) => {
                  if (res.confirm) {
                     univerifyLogin().catch((err) => {
                        if (err === false) return;
                        /**
                         * 如果需要强制登录,使用reLaunch方式
                         */
                        if (this.forcedLogin) {
                           uni.reLaunch({
                              url: '../login/login'
                           });
                        } else {
                           uni.navigateTo({
                              url: '../login/login'
                           });
                        }
                     })
                  }
               }
            });
            this.activeName = tabName;
         }
      }