Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
C
company_app
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
毛细亚
company_app
Commits
6a4e8659
提交
6a4e8659
authored
5月 23, 2025
作者:
毛细亚
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
同步代码
上级
e30134de
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
24 行增加
和
25 行删除
+24
-25
login.vue
src/views/login.vue
+24
-25
没有找到文件。
src/views/login.vue
浏览文件 @
6a4e8659
// UnifiedLogin.vue
<
template
>
<div
class=
"loginContent"
>
<div
v-if=
"!showQrCode"
>
<div>
<div>
当前组织:
<span
class=
"current-org"
>
{{
currentOrg
.
name
}}
</span>
<el-button
type=
"text"
@
click=
"showOrgDialog = true"
>
切换组织
</el-button>
...
...
@@ -47,15 +47,11 @@
<div
v-if=
"dingUserInfo"
>
钉钉用户:
{{
dingUserInfo
.
name
}}
</div>
<div
v-if=
"external_userid"
>
企微外部联系人ID:
{{
external_userid
}}
</div>
</div>
<div
v-if=
"showQrCode"
>
跳转中 请稍等...
</div>
</div>
</
template
>
<
script
>
import
*
as
ww
from
'@wecom/jssdk'
import
*
as
dd
from
'dingtalk-jsapi'
import
{
getOrganization
,
getAuthUser
,
getDingLogin
,
getSignature
}
from
'@/api/user'
import
Cookies
from
'js-cookie'
import
{
getParams
}
from
'@/utils/index'
...
...
@@ -79,24 +75,30 @@ export default {
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'
,
DDTestUrl
:
''
,
showQrCode
:
false
,
}
},
async
mounted
()
{
const
userid
=
Cookies
.
get
(
'userid'
)
await
this
.
initOrganization
();
const
urlParams
=
getParams
();
const
token
=
getToken
()
const
userid
=
Cookies
.
get
(
'userid'
)
console
.
log
(
urlParams
,
'mounted'
)
await
this
.
initOrganization
();
// 如果是钉钉扫码回调页面
if
(
urlParams
.
type
&&
urlParams
.
type
===
'ding'
)
{
// 钉钉回调
this
.
showQrCode
=
true
this
.
handleDingCallback
();
}
else
{
if
(
!
userid
){
// 没有静默授权过
if
(
!
userid
&&
token
){
//没有企微授权过 并且 钉钉扫码成功 开始微信授权
await
this
.
startWeComSilentAuth
();
}
else
{
this
.
initDingTalkLogin
();
// 已经静默授权过 初始化钉钉扫码
this
.
initDingTalkLogin
();
// 始化钉钉扫码
}
}
else
{
this
.
initDingTalkLogin
();
// 始化钉钉扫码
}
// 每次进入页面都缓存corp_id
if
(
urlParams
.
corp_id
){
this
.
cacheCorp_id
(
urlParams
.
corp_id
)
// 缓存 corp_id
}
},
computed
:{
...
...
@@ -136,23 +138,24 @@ export default {
// 1. 企微静默授权
async
startWeComSilentAuth
()
{
this
.
urlParams
=
getParams
();
const
appid
=
this
.
urlParams
.
corp_id
this
.
cacheCorp_id
(
appid
)
// 缓存 corp_id
const
corp_id
=
Cookies
.
get
(
'corp_id'
)
// 确定是第一次进入页面 没有 code 和 state
if
(
!
this
.
urlParams
.
code
&&
!
this
.
urlParams
.
state
)
{
// 跳转企微静默授权
const
redirectUri
=
encodeURIComponent
(
window
.
location
.
href
);
const
authUrl
=
`https://open.weixin.qq.com/connect/oauth2/authorize?appid=
${
app
id
}
&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
;
return
;
}
// 用code
const
res
=
await
getAuthUser
({
code
:
this
.
urlParams
.
code
,
url
:
window
.
location
.
href
,
corp_id
:
app
id
});
const
res
=
await
getAuthUser
({
code
:
this
.
urlParams
.
code
,
url
:
window
.
location
.
href
,
corp_id
:
corp_
id
});
if
(
res
.
status_code
===
1
)
{
this
.
cacheWx_userinfo
(
res
.
data
)
this
.
cacheuserid
(
res
.
data
.
userid
)
this
.
initDingTalkLogin
();
// 获取签名
await
this
.
getSignature
();
}
else
{
console
.
log
(
'获取useid失败'
,
res
)
// 错误处理
}
},
...
...
@@ -165,7 +168,7 @@ export default {
this
.
cacheSignData
(
res
.
data
)
try
{
this
.
registerWeComSDK
();
this
.
$router
.
push
(
'/'
)
// 一切准备工作就绪
//
this.$router.push('/')// 一切准备工作就绪
}
catch
(
err
){
console
.
log
(
err
,
'初始化sdk 失败'
)
}
...
...
@@ -275,6 +278,7 @@ export default {
async
handleDingCallback
()
{
// 在这里处理钉钉扫码成功的回调
const
ddParams
=
getParams
();
const
corp_id
=
Cookies
.
get
(
'corp_id'
)
if
(
ddParams
.
code
==
'error'
&&
ddParams
.
msg
){
this
.
$message
.
error
(
ddParams
.
msg
)
return
...
...
@@ -284,17 +288,12 @@ export default {
this
.
set_token
(
ddParams
.
token
)
}
else
{
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
){
this
.
cacheCser
(
ddParams
.
cser_id
,
ddParams
.
cser_name
)
}
await
this
.
getSignature
();
setTimeout
(()
=>
{
// 获取联系人
console
.
log
(
'获取联系人'
)
this
.
getCurExternalContact
();
},
2000
);
},
// 8. 获取企微外部联系人
getCurExternalContact
()
{
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论