sunlupeng преди 1 година
родител
ревизия
e494a83c47
променени са 4 файла, в които са добавени 64 реда и са изтрити 68 реда
  1. 3 57
      App.vue
  2. 59 5
      permission.js
  3. 1 3
      utils/request.js
  4. 1 3
      utils/upload.js

+ 3 - 57
App.vue

@@ -1,23 +1,7 @@
 <script>
   import config from './config'
   import { getAccessToken } from '@/utils/auth'
-  import { authLogin } from "@/api/login";
-  import { setToken, setTenantId } from '@/utils/auth'
-  import { openAuth } from "dingtalk-design-libs/biz/openAuth";
-  import * as dd from "dingtalk-jsapi";
-  function getQueryString() {
-     let url = window.location.href; //获取url中"?"符后的字串
-	 console.log(url)
-      if (url.indexOf("?") != -1) { 
-         let str = url.substr(1); 
-         let strs = str.split("=");
-		 let index = strs[1].indexOf("#")
-		 let corpId = strs[1].substring(0, index);
-		 console.log(corpId)
-         return corpId;          
-      }
-  };
-  
+
   export default {
     onLaunch: function() {
       this.initApp()
@@ -29,53 +13,15 @@
         this.initConfig()
         // 检查用户登录状态
         //#ifdef H5
-        this.checkLogin()
+        // this.checkLogin()
         //#endif
       },
       initConfig() {
         this.globalData.config = config
       },
       checkLogin() {
-		  let that = this;
-		  debugger
-		let corpId = getQueryString();
-		console.log(corpId);
         if (!getAccessToken()) {
-			if (dd.env.platform !== "notInDingTalk") {
-				debugger
-			  return new Promise((resolve, reject) => {
-			    dd.ready(function () {
-			      // 唤起授权--统一授权套件SDK
-			      openAuth({
-			        clientId: "suite7tssbigaaqsejgth", // 应用ID(唯一标识)
-			        corpId: corpId, // 当前组织的corpId
-			        rpcScope: "Contact.User.Read", //通讯录
-			        fieldScope: "Contact.User.mobile", //手机号
-			        type: 0, // 0 标识授权个人信息;1 标识授权组织信息
-			      }).then((res) => {
-			        // 处理返回数据
-			        console.log("统一授权套件SDK==res=", res);
-					console.log("corpId", corpId);
-			        authLogin({ code: res.result.authCode, corpId: corpId })
-			          .then((res) => {
-			            console.log("===登录授权=", res);
-			            setToken(res.data);
-			            setTenantId(res.msg)
-						// 设置用户信息
-						that.$store.dispatch('GetInfo').then(res => {
-							that.$tab.reLaunch('/pages/index')
-						})
-			            resolve();
-			          })
-			          .catch((err) => {
-			            reject();
-			          });
-			      });
-			    });
-			  });
-			}else{
-				this.$tab.reLaunch('/pages/login')
-			}
+			this.$tab.reLaunch('/pages/login')
         }
       }
     }

+ 59 - 5
permission.js

@@ -1,4 +1,21 @@
+import store from './store'
 import { getAccessToken } from '@/utils/auth'
+import { authLogin } from "@/api/login";
+import { setToken, setTenantId } from '@/utils/auth'
+import { openAuth } from "dingtalk-design-libs/biz/openAuth";
+import * as dd from "dingtalk-jsapi";
+function getQueryString() {
+  let url = window.location.href; //获取url中"?"符后的字串
+  console.log(url)
+  if (url.indexOf("?") != -1) {
+    let str = url.substr(1);
+    let strs = str.split("=");
+    let index = strs[1].indexOf("#")
+    let corpId = strs[1].substring(0, index);
+    console.log(corpId)
+    return corpId;
+  }
+};
 // 登录页面
 const loginPage = "/pages/login"
 
@@ -18,18 +35,55 @@ let list = ["navigateTo", "redirectTo", "reLaunch", "switchTab"]
 list.forEach(item => {
   uni.addInterceptor(item, {
     invoke(to) {
+      debugger
+      let corpId = getQueryString();
+      console.log(corpId);
       if (getAccessToken()) {
         if (to.path === loginPage) {
           uni.reLaunch({ url: "/" })
         }
         return true
       } else {
-        if (checkWhite(to.url)) {
-          return true
+        if (dd.env.platform !== "notInDingTalk") {
+          debugger
+          return new Promise((resolve, reject) => {
+            dd.ready(function () {
+              // 唤起授权--统一授权套件SDK
+              openAuth({
+                clientId: "suite7tssbigaaqsejgth", // 应用ID(唯一标识)
+                corpId: corpId, // 当前组织的corpId
+                rpcScope: "Contact.User.Read", //通讯录
+                fieldScope: "Contact.User.mobile", //手机号
+                type: 0, // 0 标识授权个人信息;1 标识授权组织信息
+              }).then((res) => {
+                // 处理返回数据
+                console.log("统一授权套件SDK==res=", res);
+                console.log("corpId", corpId);
+                authLogin({ code: res.result.authCode, corpId: corpId })
+                  .then((res) => {
+                    console.log("===登录授权=", res);
+                    setToken(res.data);
+                    setTenantId(res.msg)
+                    uni.reLaunch({ url: "/" })
+                    // 设置用户信息
+                    store.dispatch('GetInfo').then(res => {
+                      that.$tab.reLaunch('/pages/index')
+                    })
+                    resolve();
+                  })
+                  .catch((err) => {
+                    reject();
+                  });
+              });
+            });
+          });
+        } else {
+          if (checkWhite(to.url)) {
+            return true
+          }
+          uni.reLaunch({ url: loginPage })
+          return false
         }
-        uni.reLaunch({ url: loginPage })
-        return false
-        
       }
     },
     fail(err) {

+ 1 - 3
utils/request.js

@@ -43,9 +43,7 @@ const request = config => {
         if (code === 401) {
           showConfirm('登录状态已过期,您可以继续留在该页面,或者重新登录?').then(res => {
             if (res.confirm) {
-              store.dispatch('LogOut').then(res => {
-                uni.reLaunch({ url: '/pages/login' })
-              })
+              uni.reLaunch({ url: '/' })
             }
           })
           reject('无效的会话,或者会话已过期,请重新登录。')

+ 1 - 3
utils/upload.js

@@ -40,9 +40,7 @@ const upload = config => {
           } else if (code == 401) {
             showConfirm("登录状态已过期,您可以继续留在该页面,或者重新登录?").then(res => {
               if (res.confirm) {
-                store.dispatch('LogOut').then(res => {
-                  uni.reLaunch({ url: '/pages/login/login' })
-                })
+                uni.reLaunch({ url: '/' })
               }
             })
             reject('无效的会话,或者会话已过期,请重新登录。')