Browse Source

单点登录

msx 1 week ago
parent
commit
db07d24585
5 changed files with 86 additions and 18 deletions
  1. 2 2
      common/service/config.service.js
  2. 1 1
      manifest.json
  3. 3 1
      pages/index/index.vue
  4. 51 1
      pages/login/login.vue
  5. 29 13
      pages/webview/webview.vue

+ 2 - 2
common/service/config.service.js

@@ -12,8 +12,8 @@ if (process.env.NODE_ENV == "development") {
   // BASE_URL = "http://10.120.120.164:9999"; // 察哈素
   // BASE_URL = "http://182.92.126.35:9999"; // 生产环境
   // BASE_URL = "http://172.16.53.16:9999"; // 
-  // BASE_URL = "http://10.246.167.205:9999"; //上湾
-  BASE_URL = "172.30.157.9:8092"; //元子沟
+  BASE_URL = "http://10.246.167.205:9999"; //上湾
+  // BASE_URL = "172.30.157.9:8092"; //元子沟
 
 }
 let staticDomainURL = BASE_URL + "/sys/common/static";

+ 1 - 1
manifest.json

@@ -7,7 +7,7 @@
     "transformPx" : false,
     "app-plus" : {
         "compatible" : {
-            "ignoreVersion" : false,
+            "ignoreVersion" : true,
             "runtimeVersion" : "4.23,4.29",
             "compilerVersion" : "4.29"
         },

+ 3 - 1
pages/index/index.vue

@@ -191,7 +191,9 @@ export default {
       immediate: true,
   }
 },
-  onLoad() {
+  onLoad(option) {
+	  
+	  this.$tip.success(option.ticket)
     this.changeWV();
   },
   mounted() {},

+ 51 - 1
pages/login/login.vue

@@ -76,7 +76,9 @@ export default {
       thirdUserUuid: "",
     };
   },
-  onLoad: function () {
+  onLoad: function (option) {
+        console.log("=======option.ticket======"+JSON.stringify(option.ticket));
+		this.loginCas(option.ticket)
     // #ifdef APP-PLUS
     var that = this;
     plus.runtime.getProperty(plus.runtime.appid, function (wgtinfo) {
@@ -156,6 +158,51 @@ export default {
           this.loading = false;
         });
     },
+	
+	loginCas(value) {
+	  var than = this;
+	  
+	  // this.$tip.success(configService.apiUrl);
+	  var ser = configService.apiUrl;
+	  ser = ser.replace(9999, 8092);
+	          // this.$tip.success(ser);
+	  new Promise((resolve, reject) => {
+	    api
+	      .validateCasLogin("", "?ticket=" + value + "&service=" + encodeURIComponent(ser))
+	      .then((response) => {
+	          // than.$tip.success("登录成功1");
+			  
+	        // if (response.data.code == 200) {
+	        // 	uni.setStorageSync(ACCESS_TOKEN, response.data.result.token);
+	        // } else {
+	        // }
+	        const result = response.data.result;
+	        const userInfo = result.userInfo;
+	        uni.setStorageSync(ACCESS_TOKEN, result.token);
+	        uni.setStorageSync(USER_INFO, userInfo);
+	        console.log("userInfo=" + userInfo);
+	        than.$store.commit("SET_TOKEN", result.token);
+	        console.log("result.token=" + result.token);
+	        than.$store.commit("SET_DICT", result.sysAllDictItems);
+	        than.$store.commit("SET_AVATAR", userInfo.avatar);
+	        than.$store.commit("SET_NAME", {
+	          username: userInfo.username,
+	          realname: userInfo.realname,
+	        });
+	
+	          // than.$tip.success("loginCas=");
+	        than.getPermissionList();
+	      })
+	      .catch((error) => {
+	        debugger;
+	        console.log("catch===>response", error);
+	        // uni.navigateTo({
+	        //   url: "/pages/home/home",
+	        // });
+	      });
+	  });
+	},
+	
     //获取权限菜单
     getPermissionList() {
       new Promise((resolve, reject) => {
@@ -277,9 +324,11 @@ export default {
       console.log("changeloginType====");
       var tourl = configService.apiUrl;
       tourl = tourl.replace(9999, 8092);
+              // this.$tip.success("tourl="+tourl);
       var rastourl =
         "https://id.shendong.com.cn/default" +
         "/login?service=" + tourl;
+		// rastourl ="http://182.92.126.35:8092/?ticket=234";
       console.log("===========" + rastourl);
       this.openBrowser(rastourl);
       // window.location.href='/pages/index/index?ticket=123'
@@ -288,6 +337,7 @@ export default {
     openBrowser(url) {
       // 使用uni.navigateTo打开内置浏览器
       console.log("----url---------------" + url);
+              // this.$tip.success("url="+url);
       uni.navigateTo({
         url: "/pages/webview/webview?url=" + encodeURIComponent(url),
       });

+ 29 - 13
pages/webview/webview.vue

@@ -69,6 +69,7 @@ export default {
       });
     },
     startListening() {
+		var than = this
       this.timer = setInterval(() => {
         var pages = getCurrentPages();
         var page = pages[pages.length - 1];
@@ -86,12 +87,19 @@ export default {
           tourl = tourl.substring(tourl.indexOf("ticket") + 7, tourl.length);
           var pos = tourl.indexOf("&");
           if (pos != -1) tourl = tourl.substring(0, pos);
-          uni.navigateTo({
-            url: "/pages/login/login",
-          });
-          this.loginCas(tourl);
+        console.log("=======ticket======", tourl);
+		
+		uni.navigateTo({
+		  url: "/pages/login/login?ticket="+tourl,
+		});
+		  // setTimeout(()=>{
+    //       uni.navigateTo({
+    //         url: "/pages/index/index",
+    //       });
+		  // },10000)
+          // than.loginCas(tourl);
         }
-      }, 1000); // 间隔3秒检查一次
+      }, 200); // 间隔3秒检查一次
     },
     stopListening() {
       if (this.timer) {
@@ -102,12 +110,17 @@ export default {
 
     loginCas(value) {
       var than = this;
-      var ser = this.src;
+	  
+	  this.$tip.success(configService.apiUrl);
+	  var ser = configService.apiUrl;
+	  ser = tourl.replace(9999, 8092);
+              this.$tip.success(ser);
       new Promise((resolve, reject) => {
         api
           .validateCasLogin("", "?ticket=" + value + "&service=" + ser)
           .then((response) => {
-            debugger;
+              than.$tip.success(response.message);
+			  
             // console.log("response===>response", JSON.stringify(response));
             // if (response.data.code == 200) {
             // 	uni.setStorageSync(ACCESS_TOKEN, response.data.result.token);
@@ -118,16 +131,16 @@ export default {
             uni.setStorageSync(ACCESS_TOKEN, result.token);
             uni.setStorageSync(USER_INFO, userInfo);
             console.log("userInfo=" + userInfo);
-            this.$store.commit("SET_TOKEN", result.token);
+            than.$store.commit("SET_TOKEN", result.token);
             console.log("result.token=" + result.token);
-            this.$store.commit("SET_DICT", result.sysAllDictItems);
-            this.$store.commit("SET_AVATAR", userInfo.avatar);
-            this.$store.commit("SET_NAME", {
+            than.$store.commit("SET_DICT", result.sysAllDictItems);
+            than.$store.commit("SET_AVATAR", userInfo.avatar);
+            than.$store.commit("SET_NAME", {
               username: userInfo.username,
               realname: userInfo.realname,
             });
 
-            console.log("getPermissionList-----------");
+              than.$tip.success("loginCas=");
             than.getPermissionList();
           })
           .catch((error) => {
@@ -142,6 +155,8 @@ export default {
 
     //获取权限菜单
     getPermissionList() {
+      var than = this;
+              this.$tip.success("getPermissionList");
       console.log("getPermissionList=========================");
       new Promise((resolve, reject) => {
         api
@@ -153,7 +168,8 @@ export default {
               let dataBtn = response.data.result.appauth;
               uni.setStorageSync("menuPermission", data);
               uni.setStorageSync("btnPermission", dataBtn);
-              this.$tip.success("登录成功!");
+              than.$tip.success("登录成功!");
+              than.$tip.success("navigateTo="+pages/index/index);
               uni.navigateTo({
                 url: "/pages/index/index",
               });