Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
提交反馈
为 GitLab 提交贡献
登录
切换导航
iBiz-Vue-R7-Res
项目
项目
详情
动态
版本
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
iBiz-R7前端标准模板
iBiz-Vue-R7-Res
提交
e03e0de7
提交
e03e0de7
编写于
11月 30, 2020
作者:
tony001
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
新增应用刷新token逻辑
上级
6d31ef09
变更
4
显示空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
86 行增加
和
41 行删除
+86
-41
login.vue
src/components/login/login.vue
+4
-38
interceptor.ts
src/utils/interceptor/interceptor.ts
+31
-1
util.d.ts
src/utils/types/util.d.ts
+16
-2
util.ts
src/utils/util/util.ts
+35
-0
未找到文件。
src/components/login/login.vue
浏览文件 @
e03e0de7
...
...
@@ -74,7 +74,7 @@
<
script
lang=
"ts"
>
import
{
Vue
,
Component
,
Watch
}
from
'vue-property-decorator'
;
import
{
Environment
}
from
'@/environments/environment'
;
//import Divider from "ibiz-vue-lib/lib/ibiz-vue-lib.common"
;
import
{
Util
}
from
'@/utils'
;
@
Component
({
components
:
{}
...
...
@@ -141,7 +141,7 @@ export default class Login extends Vue {
}
public
mounted
()
{
this
.
getCookie
(
"loginname"
);
Util
.
getCookie
(
"loginname"
);
}
/**
...
...
@@ -181,13 +181,13 @@ export default class Login extends Vue {
const
data
=
response
.
data
;
if
(
data
&&
data
.
token
)
{
localStorage
.
setItem
(
'token'
,
data
.
token
);
this
.
setCookie
(
'ibzuaa-token'
,
data
.
token
,
0
);
Util
.
setCookie
(
'ibzuaa-token'
,
data
.
token
,
0
);
}
if
(
data
&&
data
.
user
){
localStorage
.
setItem
(
'user'
,
JSON
.
stringify
(
data
.
user
));
}
// 设置cookie,保存账号密码7天
this
.
setCookie
(
"loginname"
,
loginname
,
7
);
Util
.
setCookie
(
"loginname"
,
loginname
,
7
);
// 跳转首页
const
url
:
any
=
this
.
$route
.
query
.
redirect
?
this
.
$route
.
query
.
redirect
:
'*'
;
this
.
$router
.
push
({
path
:
url
});
...
...
@@ -223,40 +223,6 @@ export default class Login extends Vue {
_this
.
form
=
{
loginname
:
'ibzadmin'
,
password
:
'123456'
}
}
/**
* 设置cookie
*
* @memberof Login
*/
public
setCookie
(
name
:
any
,
value
:
any
,
day
:
any
)
{
if
(
day
!==
0
)
{
//当设置的时间等于0时,不设置expires属性,cookie在浏览器关闭后删除
let
curDate
=
new
Date
();
let
curTamp
=
curDate
.
getTime
();
let
curWeeHours
=
new
Date
(
curDate
.
toLocaleDateString
()).
getTime
()
-
1
;
let
passedTamp
=
curTamp
-
curWeeHours
;
let
leftTamp
=
24
*
60
*
60
*
1000
-
passedTamp
;
let
leftTime
=
new
Date
();
leftTime
.
setTime
(
leftTamp
+
curTamp
);
document
.
cookie
=
name
+
"="
+
escape
(
value
)
+
";expires="
+
leftTime
.
toUTCString
();
}
else
{
document
.
cookie
=
name
+
"="
+
escape
(
value
);
}
}
/**
* 获取cookie
*
* @memberof Login
*/
public
getCookie
(
name
:
any
):
any
{
let
arr
;
let
reg
=
new
RegExp
(
"(^| )"
+
name
+
"=([^;]*)(;|$)"
);
if
(
arr
=
document
.
cookie
.
match
(
reg
))
return
unescape
(
arr
[
2
]);
else
return
null
;
}
/**
* qq授权登录
* @param thirdpart
...
...
src/utils/interceptor/interceptor.ts
浏览文件 @
e03e0de7
...
...
@@ -3,6 +3,9 @@ import axios from 'axios';
import
Router
from
'vue-router'
;
import
i18n
from
'@/locale'
;
import
{
Environment
}
from
'@/environments/environment'
;
import
{
Http
}
from
'@/http/http'
;
import
{
Util
}
from
'@/util/util'
;
/**
* 拦截器
*
...
...
@@ -117,8 +120,12 @@ export class Interceptors {
res
.
data
.
entityName
=
res
.
headers
[
'x-ibz-params'
];
}
if
(
res
.
status
===
401
)
{
if
(
res
.
headers
&&
res
.
headers
[
'refreshToken'
]
&&
localStorage
.
getItem
(
'token'
)){
this
.
refreshToken
(
_data
.
data
);
}
else
{
this
.
doNoLogin
(
_data
.
data
);
}
}
if
(
res
.
status
===
403
){
if
(
res
.
data
&&
res
.
data
.
status
&&
Object
.
is
(
res
.
data
.
status
,
"FORBIDDEN"
)){
let
alertMessage
:
string
=
"非常抱歉,您无权操作此数据,如需操作请联系管理员!"
;
...
...
@@ -174,4 +181,27 @@ export class Interceptors {
}
}
/**
* 刷新token
*
* @private
* @param {*} [data={}]
* @memberof Interceptors
*/
private
refreshToken
(
data
:
any
=
{}):
void
{
Http
.
getInstance
().
post
(
'/uaa/refreshToken'
,{
oldToken
:
localStorage
.
getItem
(
'token'
)},
false
).
then
((
response
:
any
)
=>
{
if
(
response
&&
response
.
status
===
200
)
{
const
data
=
response
.
data
;
if
(
data
&&
data
.
token
)
{
localStorage
.
setItem
(
'token'
,
data
.
token
);
Util
.
setCookie
(
'ibzuaa-token'
,
data
.
token
,
0
);
}
}
else
{
this
.
doNoLogin
(
data
);
}
}).
catch
((
error
:
any
)
=>
{
this
.
doNoLogin
(
data
);
});
}
}
\ No newline at end of file
src/utils/types/util.d.ts
浏览文件 @
e03e0de7
...
...
@@ -153,7 +153,7 @@ export declare interface Util {
* @returns {string}
* @memberof Util
*/
dateFormat
(
date
:
any
,
fmt
?:
string
):
string
dateFormat
(
date
:
any
,
fmt
?:
string
):
string
;
/**
* 表单项校验
...
...
@@ -164,7 +164,21 @@ export declare interface Util {
* @returns {Promise}
* @memberof Util
*/
validateItem
(
property
:
string
,
data
:
any
,
rules
:
any
):
Promise
<
any
>
validateItem
(
property
:
string
,
data
:
any
,
rules
:
any
):
Promise
<
any
>
;
/**
* 设置cookie
*
* @memberof Util
*/
setCookie
(
name
:
any
,
value
:
any
,
day
:
any
):
void
;
/**
* 获取cookie
*
* @memberof Util
*/
getCookie
(
name
:
any
):
any
;
}
declare
module
"vue/types/vue"
{
...
...
src/utils/util/util.ts
浏览文件 @
e03e0de7
...
...
@@ -427,4 +427,39 @@ export class Util {
// 校验返回Promise
return
schema
.
validate
({
[
property
]:
value
})
}
/**
* 设置cookie
*
* @memberof Util
*/
public
static
setCookie
(
name
:
any
,
value
:
any
,
day
:
any
)
{
if
(
day
!==
0
)
{
//当设置的时间等于0时,不设置expires属性,cookie在浏览器关闭后删除
let
curDate
=
new
Date
();
let
curTamp
=
curDate
.
getTime
();
let
curWeeHours
=
new
Date
(
curDate
.
toLocaleDateString
()).
getTime
()
-
1
;
let
passedTamp
=
curTamp
-
curWeeHours
;
let
leftTamp
=
24
*
60
*
60
*
1000
-
passedTamp
;
let
leftTime
=
new
Date
();
leftTime
.
setTime
(
leftTamp
+
curTamp
);
document
.
cookie
=
name
+
"="
+
escape
(
value
)
+
";expires="
+
leftTime
.
toUTCString
();
}
else
{
document
.
cookie
=
name
+
"="
+
escape
(
value
);
}
}
/**
* 获取cookie
*
* @memberof Util
*/
public
static
getCookie
(
name
:
any
):
any
{
let
arr
;
let
reg
=
new
RegExp
(
"(^| )"
+
name
+
"=([^;]*)(;|$)"
);
if
(
arr
=
document
.
cookie
.
match
(
reg
))
return
unescape
(
arr
[
2
]);
else
return
null
;
}
}
\ No newline at end of file
编辑
预览
Markdown
格式
0%
请重试
or
添加新附件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
先完成此消息的编辑!
取消
想要评论请
注册
或
登录