提交 6a4e8659 作者: 毛细亚

同步代码

上级 e30134de
// UnifiedLogin.vue // UnifiedLogin.vue
<template> <template>
<div class="loginContent"> <div class="loginContent">
<div v-if="!showQrCode"> <div>
<div> <div>
当前组织:<span class="current-org">{{ currentOrg.name }}</span> 当前组织:<span class="current-org">{{ currentOrg.name }}</span>
<el-button type="text" @click="showOrgDialog = true">切换组织</el-button> <el-button type="text" @click="showOrgDialog = true">切换组织</el-button>
...@@ -47,15 +47,11 @@ ...@@ -47,15 +47,11 @@
<div v-if="dingUserInfo">钉钉用户:{{ dingUserInfo.name }}</div> <div v-if="dingUserInfo">钉钉用户:{{ dingUserInfo.name }}</div>
<div v-if="external_userid">企微外部联系人ID:{{ external_userid }}</div> <div v-if="external_userid">企微外部联系人ID:{{ external_userid }}</div>
</div> </div>
<div v-if="showQrCode">
跳转中 请稍等...
</div>
</div> </div>
</template> </template>
<script> <script>
import * as ww from '@wecom/jssdk' import * as ww from '@wecom/jssdk'
import * as dd from 'dingtalk-jsapi'
import { getOrganization,getAuthUser,getDingLogin,getSignature } from '@/api/user' import { getOrganization,getAuthUser,getDingLogin,getSignature } from '@/api/user'
import Cookies from 'js-cookie' import Cookies from 'js-cookie'
import { getParams } from '@/utils/index' import { getParams } from '@/utils/index'
...@@ -79,24 +75,30 @@ export default { ...@@ -79,24 +75,30 @@ export default {
qrLoading: false, // 控制二维码 loading qrLoading: false, // 控制二维码 loading
redirectUri: process.env.NODE_ENV === 'production' ? 'https://companywx.zwnet.cn/api/api/sidebar_login/ding' : 'https://companywx.zwwlkj03.top/api/api/sidebar_login/ding', redirectUri: process.env.NODE_ENV === 'production' ? 'https://companywx.zwnet.cn/api/api/sidebar_login/ding' : 'https://companywx.zwwlkj03.top/api/api/sidebar_login/ding',
DDTestUrl:'', DDTestUrl:'',
showQrCode:false,
} }
}, },
async mounted() { async mounted() {
const userid = Cookies.get('userid') await this.initOrganization();
const urlParams = getParams(); const urlParams = getParams();
const token = getToken()
const userid = Cookies.get('userid')
console.log(urlParams,'mounted') console.log(urlParams,'mounted')
await this.initOrganization();
// 如果是钉钉扫码回调页面 // 如果是钉钉扫码回调页面
if ( urlParams.type && urlParams.type === 'ding') {// 钉钉回调 if ( urlParams.type && urlParams.type === 'ding') {// 钉钉回调
this.showQrCode = true
this.handleDingCallback(); this.handleDingCallback();
}else{ if(!userid && token){ //没有企微授权过 并且 钉钉扫码成功 开始微信授权
if(!userid){ // 没有静默授权过
await this.startWeComSilentAuth(); await this.startWeComSilentAuth();
}else{ }else{
this.initDingTalkLogin(); // 已经静默授权过 初始化钉钉扫码 this.initDingTalkLogin(); // 始化钉钉扫码
} }
}else{
this.initDingTalkLogin(); // 始化钉钉扫码
}
// 每次进入页面都缓存corp_id
if(urlParams.corp_id){
this.cacheCorp_id(urlParams.corp_id) // 缓存 corp_id
} }
}, },
computed:{ computed:{
...@@ -136,23 +138,24 @@ export default { ...@@ -136,23 +138,24 @@ export default {
// 1. 企微静默授权 // 1. 企微静默授权
async startWeComSilentAuth() { async startWeComSilentAuth() {
this.urlParams = getParams(); this.urlParams = getParams();
const appid = this.urlParams.corp_id const corp_id = Cookies.get('corp_id')
this.cacheCorp_id(appid) // 缓存 corp_id
// 确定是第一次进入页面 没有 code 和 state // 确定是第一次进入页面 没有 code 和 state
if (!this.urlParams.code && !this.urlParams.state) { if (!this.urlParams.code && !this.urlParams.state) {
// 跳转企微静默授权 // 跳转企微静默授权
const redirectUri = encodeURIComponent(window.location.href); const redirectUri = encodeURIComponent(window.location.href);
const authUrl = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${redirectUri}&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect`; const authUrl = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${corp_id}&redirect_uri=${redirectUri}&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect`;
window.location.href = authUrl; window.location.href = authUrl;
return; return;
} }
// 用code // 用code
const res = await getAuthUser({ code: this.urlParams.code, url: window.location.href,corp_id:appid }); const res = await getAuthUser({ code: this.urlParams.code, url: window.location.href,corp_id:corp_id });
if (res.status_code === 1) { if (res.status_code === 1) {
this.cacheWx_userinfo(res.data) this.cacheWx_userinfo(res.data)
this.cacheuserid(res.data.userid) this.cacheuserid(res.data.userid)
this.initDingTalkLogin(); // 获取签名
await this.getSignature();
} else { } else {
console.log('获取useid失败',res)
// 错误处理 // 错误处理
} }
}, },
...@@ -165,7 +168,7 @@ export default { ...@@ -165,7 +168,7 @@ export default {
this.cacheSignData(res.data) this.cacheSignData(res.data)
try{ try{
this.registerWeComSDK(); this.registerWeComSDK();
this.$router.push('/')// 一切准备工作就绪 // this.$router.push('/')// 一切准备工作就绪
}catch(err){ }catch(err){
console.log(err,'初始化sdk 失败') console.log(err,'初始化sdk 失败')
} }
...@@ -275,6 +278,7 @@ export default { ...@@ -275,6 +278,7 @@ export default {
async handleDingCallback() { async handleDingCallback() {
// 在这里处理钉钉扫码成功的回调 // 在这里处理钉钉扫码成功的回调
const ddParams = getParams(); const ddParams = getParams();
const corp_id = Cookies.get('corp_id')
if(ddParams.code=='error' && ddParams.msg){ if(ddParams.code=='error' && ddParams.msg){
this.$message.error(ddParams.msg) this.$message.error(ddParams.msg)
return return
...@@ -284,17 +288,12 @@ export default { ...@@ -284,17 +288,12 @@ export default {
this.set_token(ddParams.token) this.set_token(ddParams.token)
}else{ }else{
console.log('没有token') console.log('没有token')
window.location.href = window.location.origin +'/company_app/index.html?corp_id='+Cookies.get('corp_id')+'&msg=notoken' window.location.href = window.location.origin +'/company_app/index.html?corp_id='+corp_id+'&msg=notoken'
} }
if(ddParams.cser_id){ if(ddParams.cser_id){
this.cacheCser(ddParams.cser_id,ddParams.cser_name) this.cacheCser(ddParams.cser_id,ddParams.cser_name)
} }
await this.getSignature();
setTimeout(() => {
// 获取联系人
console.log('获取联系人')
this.getCurExternalContact();
}, 2000);
}, },
// 8. 获取企微外部联系人 // 8. 获取企微外部联系人
getCurExternalContact() { getCurExternalContact() {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论