瀏覽代碼

优化自动登录

陈龙 11 月之前
父節點
當前提交
42db4e903b
共有 3 個文件被更改,包括 51 次插入10 次删除
  1. 40 5
      source/OumanMESUni/pages/login/index.vue
  2. 4 4
      source/OumanMESUni/pages/my/index.vue
  3. 7 1
      source/OumanMESUni/utils/user.js

+ 40 - 5
source/OumanMESUni/pages/login/index.vue

@@ -1,7 +1,7 @@
 <template>
     <view class="status-bar-height"></view>
     <uni-nav-bar fixed="true" title="登录" backgroundColor="#f8f8f8" :border="false" rightIcon="gear"
-        @clickRight="openSetting()"></uni-nav-bar>
+        @clickRight="openSetting" @clickLeft="back"></uni-nav-bar>
     <view class="title padding-top-20">
         <view class="title-name">欧曼 MES 客户端</view>
     </view>
@@ -10,7 +10,7 @@
         <uni-easyinput class="padding-top-20" placeholder="密码" v-model="password" type="password"
             @confirm="login"></uni-easyinput>
         <view class="flex padding-top-20">
-            <button type="primary" class="grow-1" size="mini" @tap="login()">登录</button>
+            <button type="primary" class="grow-1" size="mini" @tap="login">登录</button>
         </view>
     </view>
 </template>
@@ -27,10 +27,26 @@
         data() {
             return {
                 username: '',
-                password: ''
+                password: '',
+                backType: '',
+                prevPage: ''
+            }
+        },
+        onLoad() {
+            if (extend.isObject(opts)) {
+                switch (opts.type) {
+                    case 'switchTab':
+                        this.backType = opts.type;
+                        break;
+                    default:
+                        this.backType = 'navigateBack';
+                        break;
+                }
+                if (extend.isNonEmptyString(opts.page)) {
+                    this.prevPage = opts.page;
+                }
             }
         },
-        onLoad() {},
         methods: {
             openSetting() {
                 uni.navigateTo({
@@ -54,8 +70,13 @@
                 if (res.success) {
                     let ures = await user.getByServer();
                     if (ures.success) {
+                        let url = extend.isNonEmptyString(this.prevPage) ? this.prevPage : '/pages/home/index';
+                        // 登录成功
+                        uni.switchTab({
+                            url: url
+                        });
                         uni.reLaunch({
-                            url: '/pages/home/index'
+                            url: url
                         });
                     }
                 } else {
@@ -66,6 +87,20 @@
                     });
                 }
                 uni.hideLoading();
+            },
+
+            back() {
+                let url = extend.isNonEmptyString(this.prevPage) ? this.prevPage : '/pages/home/index';
+                switch (this.backType) {
+                    case 'switchTab':
+                        uni.switchTab({
+                            url: url
+                        });
+                        break;
+                    default:
+                        uni.navigateBack();
+                        break;
+                }
             }
         }
     }

+ 4 - 4
source/OumanMESUni/pages/my/index.vue

@@ -55,22 +55,22 @@
             },
 
             logOff() {
+                let _this = this;
                 uni.showModal({
                     content: '要注销登录吗?',
                     success(r) {
                         if (r.confirm) {
                             token.clear();
                             user.clear();
-                            uni.reLaunch({
-                                url: '/pages/index/index'
-                            });
+                            user.clearLoginInfo();
+                            _this.login();
                         }
                     }
                 })
             },
             login() {
                 uni.navigateTo({
-                    url: '/pages/login/index'
+                    url: '/pages/login/index?type=switchTab&page=/pages/my/index'
                 });
             }
         }

+ 7 - 1
source/OumanMESUni/utils/user.js

@@ -55,7 +55,13 @@ class user {
      */
     clear() {
         extend.removeStorage('login_result');
-        extend.removeStorage('login_info');
+    }
+
+    /**
+     * 清除登录信息缓存
+     */
+    clearLoginInfo() {
+        ext.removeStorage('login_info');
     }
 
     /**