Browse Source

登录优先使用本地权限

xiaohaizhao 4 months ago
parent
commit
c55a79f3e8
1 changed files with 69 additions and 31 deletions
  1. 69 31
      pages/login/login.vue

+ 69 - 31
pages/login/login.vue

@@ -395,7 +395,7 @@ function handleLogin(data) {
 let account_list = reactive([]);
 let remember = ref(uni.getStorageSync('remember') || false);
 
-function handleLogin1(data) {
+async function handleLogin1(data) {
     loading.value = false;
     uni.removeStorageSync('userMsg');
     uni.setStorageSync('userMsg', data);
@@ -409,37 +409,75 @@ function handleLogin1(data) {
         uni.removeStorageSync('accountnoPwd');
         uni.setStorageSync('accountnoPwd', '');
     }
-
-
-    $Http.basic({
-        "classname": "sysmanage.develop.userauth.userauth",
-        "method": "query_userauth", //获取用户权限
-        content: {
-            nocache: true
-        }
-    }).then(res => {
-        if (!res.data.length) {
-            uni.showToast({
-                title: '当前用户无使用权限,请联系管理员',
-                icon: 'none',
-            });
-        } else {
-            uni.removeStorageSync('isAdmin');
-            uni.removeStorageSync('isViewSkus');
-            try {
-                let app = res.data.find(v => v.system == "service").modules.find(v => v.systemmodule == "wserve").apps.find(v => v.name == "wxchatserve").meta.auth.map(v => v.option);
-                uni.setStorageSync('isAdmin', app.includes('admin'));
-                uni.setStorageSync('isViewSkus', app.includes('skus'));
-            } catch (error) {
-                console.log(error)
-                uni.setStorageSync('isAdmin', false);
-                uni.setStorageSync('isViewSkus', false);
+    let auth = uni.getStorageSync("userAuth");
+    if (auth) {
+        console.log("使用缓存权限")
+        $Http.basic({
+            "classname": "sysmanage.develop.userauth.userauth",
+            "method": "query_userauth", //获取用户权限
+            content: {
+                nocache: true
             }
-            uni.redirectTo({
-                url: '/pages/index/index',
-            });
-        }
-    })
+        }).then(res => {
+            if (!res.data.length) {
+                uni.showToast({
+                    title: '当前用户无使用权限,请联系管理员',
+                    icon: 'none',
+                });
+            } else {
+                uni.removeStorageSync('isAdmin');
+                uni.removeStorageSync('isViewSkus');
+                uni.removeStorageSync('userAuth');
+                uni.setStorageSync('userAuth', res.data)
+                try {
+                    let app = res.data.find(v => v.system == "service").modules.find(v => v.systemmodule == "wserve").apps.find(v => v.name == "wxchatserve").meta.auth.map(v => v.option);
+                    uni.setStorageSync('isAdmin', app.includes('admin'));
+                    uni.setStorageSync('isViewSkus', app.includes('skus'));
+                } catch (error) {
+                    console.log(error)
+                    uni.setStorageSync('isAdmin', false);
+                    uni.setStorageSync('isViewSkus', false);
+                }
+            }
+        })
+        uni.redirectTo({
+            url: '/pages/index/index',
+        });
+    } else {
+        console.log("重新获取权限")
+        $Http.basic({
+            "classname": "sysmanage.develop.userauth.userauth",
+            "method": "query_userauth", //获取用户权限
+            content: {
+                nocache: true
+            }
+        }).then(res => {
+            if (!res.data.length) {
+                uni.showToast({
+                    title: '当前用户无使用权限,请联系管理员',
+                    icon: 'none',
+                });
+            } else {
+                uni.removeStorageSync('isAdmin');
+                uni.removeStorageSync('isViewSkus');
+                uni.removeStorageSync('userAuth');
+                uni.setStorageSync('userAuth', res.data)
+                try {
+                    let app = res.data.find(v => v.system == "service").modules.find(v => v.systemmodule == "wserve").apps.find(v => v.name == "wxchatserve").meta.auth.map(v => v.option);
+                    uni.setStorageSync('isAdmin', app.includes('admin'));
+                    uni.setStorageSync('isViewSkus', app.includes('skus'));
+                } catch (error) {
+                    console.log(error)
+                    uni.setStorageSync('isAdmin', false);
+                    uni.setStorageSync('isViewSkus', false);
+                }
+                uni.redirectTo({
+                    url: '/pages/index/index',
+                });
+            }
+        })
+    }
+
 
     $Http.basic({
         "classname": "webmanage.site.site",