提交 4ec437f6 作者: 毛细亚

更新代码

上级 0756ad59
......@@ -78,9 +78,11 @@ router.beforeEach((to, from, next) => {
const wecomUserId = Cookies.get('userid')
const cser_id = Cookies.get('cser_id')
const token = Cookies.get('token')
const external_userid = Cookies.get('external_userid')
const urlParams = getParams();
console.log(urlParams,'urlParams')
if (needAuth) {
if (wecomUserId && cser_id && token) {
if (wecomUserId && token && external_userid) {
// 登录信息齐全,允许进入
next()
} else {
......
......@@ -52,7 +52,7 @@
<script>
import * as ww from '@wecom/jssdk'
import { getOrganization,getAuthUser,getDingLogin,getSignature } from '@/api/user'
import { getOrganization,getAuthUser,getSignature } from '@/api/user'
import Cookies from 'js-cookie'
import { getParams } from '@/utils/index'
import { mapMutations,mapState } from 'vuex'
......@@ -79,20 +79,17 @@ export default {
async mounted() {
await this.initOrganization();
const urlParams = getParams();
const token = getToken()
const userid = Cookies.get('userid')
console.log(urlParams,'mounted')
// 如果是钉钉扫码回调页面
if ( urlParams.type && urlParams.type === 'ding') {// 钉钉回调
this.handleDingCallback();
if(!userid && token){ //没有企微授权过 并且 钉钉扫码成功 开始微信授权
}else{
if(!userid){ //没有企微授权过 并且 钉钉扫码成功 开始微信授权
await this.startWeComSilentAuth();
}else{
this.initDingTalkLogin(); // 始化钉钉扫码
}
}else{
this.initDingTalkLogin(); // 始化钉钉扫码
}
// 每次进入页面都缓存corp_id
......@@ -151,8 +148,6 @@ export default {
if (res.status_code === 1) {
this.cacheWx_userinfo(res.data)
this.cacheuserid(res.data.userid)
// 获取签名
await this.getSignature();
} else {
console.log('获取useid失败',res)
// 错误处理
......@@ -194,6 +189,7 @@ export default {
onAgentConfigSuccess: (res) => {
console.log('注册成功可以调用企微 js-sdk',res)
// 注册成功后不立即获取外部联系人,等钉钉扫码后再获取
this.getCurExternalContact()
},
onAgentConfigFail: (err) => {
console.log('注册失败不能使用企微js-sdk',err)
......@@ -207,7 +203,6 @@ export default {
async initOrganization() {
const res = await getOrganization();
if (res.data.status_code === 1) {
console.log(3333)
this.orgList = res.data.data.data;
// 默认组织逻辑:可根据业务自定义
this.initCurrentApp();
......@@ -250,6 +245,7 @@ export default {
window.attachEvent('onmessage', this.handleDingTalkLogin)
}
},
// https://companywx.jianshuwenhua.com/company_app/login?code=success&cser_id=4090&cser_name=%E6%AF%9B%E7%BB%86%E4%BA%9A&token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOjQwOTAsImRhdGEiOnsiY3Nlcl9pZCI6NDA5MCwiY3Nlcl9uYW1lIjoi5q-b57uG5LqaIn0sImlhdCI6MTc0Nzk5MDM0MiwiZXhwIjoxNzUwNTgyMzQyLCJuYmYiOjE3NDc5OTAzNDIsInN1YiI6InRva2Vu6K6k6K-BIiwianRpIjoiYzYzYTM4NGYzMTFmODVlMGQ2Nzg2ZmJiMTdhNjQzN2EifQ.5ADPtqISjxOqbrDOzlKkCpfTr78Sv0Sdi-_Y1RRiMH0&type=ding
// 5. 切换组织
switchOrg(org) {
......@@ -271,11 +267,12 @@ export default {
const url = `https://oapi.dingtalk.com/connect/oauth2/sns_authorize?appid=${appid}&response_type=code&scope=snsapi_login&state=${state}&redirect_uri=${this.redirectUri}&loginTmpCode=${loginTmpCode}`;
console.log(url,'回调 url')
this.DDTestUrl = url
// window.location.href = url;
window.location.href = url;
},
// 7. 钉钉扫码回调页面处理
async handleDingCallback() {
// 在这里处理钉钉扫码成功的回调
console.log('扫码成功')
const ddParams = getParams();
const corp_id = Cookies.get('corp_id')
if(ddParams.code=='error' && ddParams.msg){
......@@ -285,6 +282,8 @@ export default {
if(ddParams.token && ddParams.token!='undefined'){
setToken(ddParams.token)
this.set_token(ddParams.token)
// 获取签名
await this.getSignature();
}else{
console.log('没有token')
window.location.href = window.location.origin +'/company_app/index.html?corp_id='+corp_id+'&msg=notoken'
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论