From 0a48655d2162b709ecb80d249a4085971add6140 Mon Sep 17 00:00:00 2001
From: Houjie <714924425@qq.com>
Date: 星期一, 07 七月 2025 17:26:30 +0800
Subject: [PATCH] 企业微信

---
 pages/login/loginOauth2.vue |  302 ++++++++++++++++++++++++++------------------------
 1 files changed, 157 insertions(+), 145 deletions(-)

diff --git a/pages/login/loginOauth2.vue b/pages/login/loginOauth2.vue
index 0e7665b..8df0d77 100644
--- a/pages/login/loginOauth2.vue
+++ b/pages/login/loginOauth2.vue
@@ -1,12 +1,12 @@
 <template>
-    <view class="zai-box">
-        <!-- 鐧诲綍鍔犺浇寮圭獥 -->
-        <view class="cu-load load-modal">
-            <image src="https://static.jeecg.com/upload/test/login4_1595818039175.png" mode="aspectFit"
-                   class="round"></image>
-            <view class="gray-text">姝e湪鐧诲綍涓�...</view>
-        </view>
+  <view class="zai-box">
+    <!-- 鐧诲綍鍔犺浇寮圭獥 -->
+    <view class="cu-load load-modal">
+      <image src="https://static.jeecg.com/upload/test/login4_1595818039175.png" mode="aspectFit"
+             class="round"></image>
+      <view class="gray-text">姝e湪鐧诲綍涓�...</view>
     </view>
+  </view>
 
 </template>
 
@@ -17,184 +17,196 @@
 import configService from '@/common/service/config.service.js';
 
 export default {
-    data() {
-        return {
-            loading: false,
-            env: {
-                thirdType: '',
-                thirdApp: false,
-                wxWork: false,
-                dingtalk: false,
-            },
-            redirectUrl: ''
-        };
+  data() {
+    return {
+      loading: false,
+      env: {
+        thirdType: '',
+        thirdApp: false,
+        wxWork: false,
+        dingtalk: false,
+      },
+      redirectUrl: ''
+    };
+  },
+  beforeCreate() {
+    // 濡傛灉褰撳墠 涓嶆槸 OAuth2APP鐜锛屽氨閲嶅畾鍚戝埌 /user/login 椤甸潰
+    if (!isOAuth2AppEnv()) {
+      this.$Router.replace({name: 'login'})
+    }
+  },
+  created() {
+    this.checkEnv()
+    this.doOAuth2Login()
+  },
+  methods: {
+    ...mapActions(['ThirdLogin']),
+    /** 妫�娴嬪綋鍓嶇殑鐜 */
+    checkEnv() {
+      // 鍒ゆ柇褰撴椂鏄惁鏄紒涓氬井淇$幆澧�
+      if (/wxwork/i.test(navigator.userAgent)) {
+        this.env.thirdApp = true
+        this.env.wxWork = true
+        this.env.thirdType = 'wechat_enterprise'
+      }
+      // 鍒ゆ柇褰撴椂鏄惁鏄拤閽夌幆澧�
+      if (/dingtalk/i.test(navigator.userAgent)) {
+        this.env.thirdApp = true
+        this.env.dingtalk = true
+        //this.env.thirdType='dingtalk'
+      }
     },
-    beforeCreate() {
-        // 濡傛灉褰撳墠 涓嶆槸 OAuth2APP鐜锛屽氨閲嶅畾鍚戝埌 /user/login 椤甸潰
-        if (!isOAuth2AppEnv()) {
-            this.$Router.replace({name: 'login'})
+
+    /** 杩涜OAuth2鐧诲綍鎿嶄綔 */
+    doOAuth2Login() {
+      if (this.env.thirdApp) {
+        // 鍒ゆ柇鏄惁鎼哄甫浜員oken锛屾槸灏辫鏄庣櫥褰曟垚鍔�
+        this.redirectUrl = ''
+        let search = window.location.search;
+        if (search.indexOf('hasToken') > 0) {
+          let obj = getUrlParams(search);
+          if (obj.params.redirect) {
+            this.redirectUrl = decodeURIComponent(decodeURIComponent(obj.params.redirect));
+            this.goRedirectUrl();
+          } else {
+            alert('hasToken鍙傛暟閿欒!')
+          }
+        } else if (search.indexOf('oauth2LoginToken') > 0) {
+          let obj = getUrlParams(search);
+          this.env.thirdType = obj.params.thirdType;
+          let token = obj.params.oauth2LoginToken;
+          if (obj.params.redirect) {
+            this.redirectUrl = decodeURIComponent(obj.params.redirect)
+          }
+          this.doThirdLogin(token)
+        } else if (this.env.wxWork) {
+          this.doWechatEnterpriseOAuth2Login()
+        } else if (this.env.dingtalk) {
+          this.doDingTalkOAuth2Login()
         }
+      }
     },
-    created() {
-        this.checkEnv()
-        this.doOAuth2Login()
+
+    // 鏍规嵁token鎵ц鐧诲綍
+    doThirdLogin(token) {
+      this.ThirdLogin({token: token, thirdType: this.env.thirdType}).then(res => {
+        if (res.data.success) {
+          uni.showToast({
+            title: '鐧诲綍',
+            icon: 'none',
+            duration: 3000,
+            content: res
+          });
+          this.loginSuccess()
+
+        } else {
+          this.requestFailed(res)
+        }
+      }).catch((e) => {
+        alert(e.message || e)
+      })
     },
-    methods: {
-        ...mapActions(['ThirdLogin']),
-        /** 妫�娴嬪綋鍓嶇殑鐜 */
-        checkEnv() {
-            // 鍒ゆ柇褰撴椂鏄惁鏄紒涓氬井淇$幆澧�
-            if (/wxwork/i.test(navigator.userAgent)) {
-                this.env.thirdApp = true
-                this.env.wxWork = true
-                //this.env.thirdType='wechat_enterprise'
-            }
-            // 鍒ゆ柇褰撴椂鏄惁鏄拤閽夌幆澧�
-            if (/dingtalk/i.test(navigator.userAgent)) {
-                this.env.thirdApp = true
-                this.env.dingtalk = true
-                //this.env.thirdType='dingtalk'
-            }
-        },
+    loginSuccess() {
+      this.$Router.replaceAll({name: 'index'})
+    },
+    requestFailed(err) {
+      uni.showToast({
+        title: '鐧诲綍',
+        icon: 'none',
+        duration: 3000,
+        content: err
+      });
+    },
+    goRedirectUrl() {
+      let obj = getUrlParams(this.redirectUrl);
+      let path = obj.url;
+      let params = obj.params;
+      if (params.info) {
+        let temp = JSON.parse(params.info);
+        let query = {
+          instanceId: temp.procInsId,
+          taskId: temp.taskId,
+          taskDefKey: temp.taskDefKey
+        }
+        if (temp.claim == 1) {
+          query['claim'] = 1
+        }
+        this.$Router.replaceAll({path, query})
+      } else {
+        this.$Router.replaceAll({path})
+      }
+    },
+    /** 浼佷笟寰俊OAuth2鐧诲綍 */
+    doWechatEnterpriseOAuth2Login() {
+      this.sysOAuth2Login('wechat_enterprise')
+    },
 
-        /** 杩涜OAuth2鐧诲綍鎿嶄綔 */
-        doOAuth2Login() {
-            if (this.env.thirdApp) {
-                // 鍒ゆ柇鏄惁鎼哄甫浜員oken锛屾槸灏辫鏄庣櫥褰曟垚鍔�
-                this.redirectUrl = ''
-                let search = window.location.search;
-                if (search.indexOf('hasToken') > 0) {
-                    let obj = getUrlParams(search);
-                    if (obj.params.redirect) {
-                        this.redirectUrl = decodeURIComponent(decodeURIComponent(obj.params.redirect));
-                        this.goRedirectUrl();
-                    } else {
-                        alert('hasToken鍙傛暟閿欒!')
-                    }
-                } else if (search.indexOf('oauth2LoginToken') > 0) {
-                    let obj = getUrlParams(search);
-                    this.env.thirdType = obj.params.thirdType;
-                    let token = obj.params.oauth2LoginToken;
-                    if (obj.params.redirect) {
-                        this.redirectUrl = decodeURIComponent(obj.params.redirect)
-                    }
-                    this.doThirdLogin(token)
-                } else if (this.env.wxWork) {
-                    this.doWechatEnterpriseOAuth2Login()
-                } else if (this.env.dingtalk) {
-                    this.doDingTalkOAuth2Login()
-                }
-            }
-        },
+    /** 閽夐拤OAuth2鐧诲綍 */
+    doDingTalkOAuth2Login() {
+      this.sysOAuth2Login('dingtalk')
+    },
 
-        // 鏍规嵁token鎵ц鐧诲綍
-        doThirdLogin(token) {
-            this.ThirdLogin({token: token, thirdType: this.env.thirdType}).then(res => {
-                if (res.data.success) {
-                    this.loginSuccess()
-                } else {
-                    this.requestFailed(res)
-                }
-            }).catch((e) => {
-                alert(e.message || e)
-            })
-        },
-        loginSuccess() {
-		      	this.$Router.replaceAll({name: 'index'})
-        },
-        requestFailed(err) {
-            this.$message.warning("鐧诲綍澶辫触")
-        },
-        goRedirectUrl() {
-            let obj = getUrlParams(this.redirectUrl);
-            let path = obj.url;
-            let params = obj.params;
-            if (params.info) {
-                let temp = JSON.parse(params.info);
-                let query = {
-                    instanceId: temp.procInsId,
-                    taskId: temp.taskId,
-                    taskDefKey: temp.taskDefKey
-                }
-                if (temp.claim == 1) {
-                    query['claim'] = 1
-                }
-                this.$Router.replaceAll({path, query})
-            } else {
-                this.$Router.replaceAll({path})
-            }
-        },
-        /** 浼佷笟寰俊OAuth2鐧诲綍 */
-        doWechatEnterpriseOAuth2Login() {
-            this.sysOAuth2Login('wechat_enterprise')
-        },
-
-        /** 閽夐拤OAuth2鐧诲綍 */
-        doDingTalkOAuth2Login() {
-            this.sysOAuth2Login('dingtalk')
-        },
-
-        /** 鍚庡彴鏋勯�爋auth2鐧诲綍鍦板潃 */
-        sysOAuth2Login(source) {
+    /** 鍚庡彴鏋勯�爋auth2鐧诲綍鍦板潃 */
+    sysOAuth2Login(source) {
             let domainURL = configService.apiUrl;
-            let url = `${domainURL}/sys/thirdLogin/oauth2/${source}/login`;
+            let url = `http://houjie.xalxzn.com:8866/jeecg-boot/sys/thirdLogin/oauth2/${source}/login`;
             let state = window.location.origin + window.location.search
             url += `?state=${encodeURIComponent(state)}`;
             console.log('sysOAuth2Login====銆�', url)
-            window.location.href = url;
-        },
-    }
+            window.location.href = url;		     
+    },
+  }
 }
 </script>
 
 <style>
 .login-paddingtop {
-    padding-top: 100 upx;
+  padding-top: 100upx;
 }
 
 .zai-box {
-    padding: 0 20 upx;
-    padding-top: 100 upx;
-    position: relative;
+  padding: 0 20upx;
+  padding-top: 100upx;
+  position: relative;
 }
 
 .zai-logo {
-    width: 200 upx;
-    height: 150px;
+  width: 200upx;
+  height: 150px;
 }
 
 .zai-title {
-    font-size: 58 upx;
-    color: #000000;
-    text-align: center;
+  font-size: 58upx;
+  color: #000000;
+  text-align: center;
 }
 
 .input-placeholder, .zai-input {
-    color: #94afce;
+  color: #94afce;
 }
 
 .zai-label {
-    padding: 60 upx 0;
-    text-align: center;
-    font-size: 30 upx;
-    color: #a7b6d0;
+  padding: 60upx 0;
+  text-align: center;
+  font-size: 30upx;
+  color: #a7b6d0;
 }
 
 .zai-btn {
-    background: #ff65a3;
-    color: #fff;
-    border: 0;
-    border-radius: 100 upx;
-    font-size: 36 upx;
+  background: #ff65a3;
+  color: #fff;
+  border: 0;
+  border-radius: 100upx;
+  font-size: 36upx;
 }
 
 .zai-btn:after {
-    border: 0;
+  border: 0;
 }
 
 /*鎸夐挳鐐瑰嚮鏁堟灉*/
 .zai-btn.button-hover {
-    transform: translate(1 upx, 1 upx);
+  transform: translate(1upx, 1upx);
 }
 
 </style>

--
Gitblit v1.9.3