Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
提交反馈
为 GitLab 提交贡献
登录
切换导航
iBiz-Vue-Mob-R7-Res
项目
项目
详情
动态
版本
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
iBiz-R7前端标准模板
iBiz-Vue-Mob-R7-Res
提交
d30de9d9
提交
d30de9d9
编写于
11月 10, 2020
作者:
KK
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
钉钉服务调整
上级
dd44a917
变更
1
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
42 行增加
和
79 行删除
+42
-79
DingTalkService.ts
src/ibiz-core/third-party-service/DingTalkService.ts
+42
-79
未找到文件。
src/ibiz-core/third-party-service/DingTalkService.ts
浏览文件 @
d30de9d9
import
axios
from
"axios"
;
import
*
as
dd
from
"dingtalk-jsapi"
;
import
{
Util
}
from
"@/ibiz-core/utils"
;
import
{
Util
,
Http
}
from
"@/ibiz-core/utils"
;
import
store
from
"@/store"
;
import
{
Notice
}
from
"../../utils/notice/notice"
;
/**
...
...
@@ -35,7 +35,7 @@ export class DingTalkService {
* @type {string}
* @memberof DingTalkService
*/
private
readonly
infoName
:
string
=
"
UserInfo
"
;
private
readonly
infoName
:
string
=
""
;
/**
* 企业corpId
*
...
...
@@ -43,7 +43,7 @@ export class DingTalkService {
* @type {string}
* @memberof WeChatService
*/
private
corpId
:
string
=
"
ding0466097cd833d9f9a1320dcb25e91351
"
;
private
corpId
:
string
=
""
;
/**
* 钉钉sdk
*
...
...
@@ -78,6 +78,15 @@ export class DingTalkService {
*/
public
$store
:
any
;
/**
* 请求服务对象
*
* @protected
* @type {Http}
* @memberof DingTalkService
*/
protected
http
:
Http
=
Http
.
getInstance
();
/**
* Creates an instance of DingTalkService.
* @memberof DingTalkService
...
...
@@ -90,6 +99,10 @@ export class DingTalkService {
this
.
init
();
}
/**
* 钉钉初始化 鉴权
* @memberof DingTalkService
*/
private
init
()
{
const
info
:
string
=
window
.
navigator
.
userAgent
.
toUpperCase
();
if
(
info
.
indexOf
(
"DINGTALK"
)
!==
-
1
)
{
...
...
@@ -122,7 +135,7 @@ export class DingTalkService {
}
/**
* 钉钉初始化
* 钉钉初始化
回调方法
*/
private
dd_ready
()
{
this
.
setNavBack
();
...
...
@@ -134,67 +147,43 @@ export class DingTalkService {
public
async
getAccess_token
():
Promise
<
any
>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
let
access_token
=
localStorage
.
getItem
(
"access_token"
);
if
(
access_token
)
{
let
reAccess_token
:
any
=
JSON
.
parse
(
access_token
);
if
(
access_token
&&
JSON
.
parse
(
access_token
).
time
&&
!
(
new
Date
().
getTime
()
-
JSON
.
parse
(
access_token
).
time
>
5400000
))
{
// 鉴权信息2小时过期 设置一小时五十分钟
if
(
reAccess_token
.
time
&&
!
(
new
Date
().
getTime
()
-
reAccess_token
.
tiem
>
5400000
)
)
{
resolve
(
reAccess_token
);
}
}
const
promise
:
Promise
<
any
>
=
this
.
get
(
`/uaa/dingtalk/jsapi/sign`
);
promise
.
then
((
response
:
any
)
=>
{
resolve
(
JSON
.
parse
(
access_token
));
}
else
{
let
openAccessId
=
document
.
referrer
?
document
.
referrer
:
"dingtalk"
;
let
url
=
window
.
location
.
href
.
replace
(
window
.
location
.
hash
,
''
)
const
promise
:
Promise
<
any
>
=
this
.
http
.
get
(
`/uaa/dingtalk/jsapi/sign`
,
{
openAccessId
:
openAccessId
,
url
:
url
});
promise
.
then
((
response
:
any
)
=>
{
if
(
response
&&
response
.
status
===
200
)
{
localStorage
.
setItem
(
"access_token"
,
JSON
.
stringify
(
Object
.
assign
(
response
.
data
,
{
time
:
new
Date
().
getTime
()
})
)
);
localStorage
.
setItem
(
"access_token"
,
JSON
.
stringify
(
Object
.
assign
(
response
.
data
,
{
time
:
new
Date
().
getTime
()
})));
resolve
(
response
.
data
);
}
else
{
resolve
(
response
);
}
})
.
catch
((
response
:
any
)
=>
{
console
.
error
(
response
);
// alert("sign"+JSON.stringify(response)
);
reject
(
response
);
});
.
catch
((
response
:
any
)
=>
{
console
.
error
(
response
);
reject
(
response
);
}
);
}
});
}
/**
* 钉钉登录
*
* @memberof DingTalkService
*/
public
async
login
():
Promise
<
any
>
{
const
access_token
:
any
=
await
this
.
get
(
`/uaa/open/dingtalk/access_token`
);
if
(
access_token
.
status
==
200
&&
access_token
.
data
&&
access_token
.
data
.
corp_id
)
{
localStorage
.
setItem
(
"access_token"
,
JSON
.
stringify
(
Object
.
assign
(
access_token
,
new
Date
().
getTime
))
);
const
access_token
:
any
=
await
this
.
http
.
get
(
`/uaa/open/dingtalk/access_token`
);
if
(
access_token
.
status
==
200
&&
access_token
.
data
&&
access_token
.
data
.
corp_id
)
{
localStorage
.
setItem
(
"access_token"
,
JSON
.
stringify
(
Object
.
assign
(
access_token
,
new
Date
().
getTime
)));
this
.
corpId
=
access_token
.
data
.
corp_id
;
const
res
:
any
=
await
dd
.
runtime
.
permission
.
requestAuthCode
({
corpId
:
this
.
corpId
,
});
const
res
:
any
=
await
dd
.
runtime
.
permission
.
requestAuthCode
({
corpId
:
this
.
corpId
,
});
if
(
res
&&
res
.
code
)
{
const
userInfo
:
any
=
await
this
.
get
(
`/uaa/open/dingtalk/auth/
${
res
.
code
}
`
);
if
(
userInfo
.
status
==
200
&&
userInfo
.
data
.
token
&&
userInfo
.
data
.
user
)
{
const
userInfo
:
any
=
await
this
.
http
.
get
(
`/uaa/open/dingtalk/auth/
${
res
.
code
}
`
);
if
(
userInfo
.
status
==
200
&&
userInfo
.
data
.
token
&&
userInfo
.
data
.
user
)
{
localStorage
.
setItem
(
"token"
,
userInfo
.
data
.
token
);
localStorage
.
setItem
(
"user"
,
JSON
.
stringify
(
userInfo
.
data
.
user
));
return
{
issuccess
:
true
,
message
:
""
};
...
...
@@ -289,28 +278,6 @@ export class DingTalkService {
return
dd
.
util
.
domainStorage
.
getItem
({
name
:
this
.
infoName
});
}
/**
* 请求(需要替换为项目)
*
* @private
* @param {string} url
* @returns {Promise<any>}
* @memberof DingTalkService
*/
private
async
get
(
url
:
string
):
Promise
<
any
>
{
return
new
Promise
((
resolve
)
=>
{
axios
.
get
(
url
)
.
then
((
response
:
any
)
=>
{
resolve
(
response
);
})
.
catch
((
error
:
any
)
=>
{
resolve
(
error
);
console
.
log
(
"请求异常"
);
});
});
}
/**
* 获取实例
*
...
...
@@ -347,14 +314,10 @@ export class DingTalkService {
*/
private
setNavBack
()
{
if
(
Util
.
isAndroid
())
{
document
.
addEventListener
(
"backbutton"
,
(
e
:
any
)
=>
{
e
.
preventDefault
();
this
.
controlBackEvent
();
},
false
);
document
.
addEventListener
(
"backbutton"
,
(
e
:
any
)
=>
{
e
.
preventDefault
();
this
.
controlBackEvent
();
},
false
);
}
else
{
dd
.
biz
.
navigation
.
setLeft
({
control
:
true
,
//是否控制点击事件,true 控制,false 不控制, 默认false
...
...
@@ -421,4 +384,4 @@ export class DingTalkService {
return
this
.
close
();
}
}
}
}
\ No newline at end of file
编辑
预览
Markdown
格式
0%
请重试
or
添加新附件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
先完成此消息的编辑!
取消
想要评论请
注册
或
登录