Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
hrs_app_h5
/
bill
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
f8876c7b
authored
Jun 16, 2020
by
展昭
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
update
parent
44b30d93
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
62 additions
and
66 deletions
src/api/More/index.js
src/api/More/urls.js
src/router/index.js
src/api/More/index.js
View file @
f8876c7b
...
...
@@ -16,5 +16,10 @@ export default {
async
getPayUrl
()
{
const
url
=
urls
.
getPayUrlUrl
();
return
AjaxRequest
.
get
(
url
);
},
async
getAccessToken
(
authcode
)
{
const
url
=
urls
.
getAccessTokenUrl
(
authcode
);
return
AjaxRequest
.
get
(
url
);
}
};
src/api/More/urls.js
View file @
f8876c7b
...
...
@@ -12,5 +12,9 @@ export default {
getPayUrlUrl
()
{
let
url
=
VUE_APP_API_BASEURL
+
'api/common/pay/getPaymentUrl'
;
return
url
;
},
getAccessTokenUrl
(
authcode
)
{
let
url
=
''
;
return
url
;
}
};
src/router/index.js
View file @
f8876c7b
...
...
@@ -4,9 +4,13 @@ import { vuexOidcCreateRouterMiddleware } from 'vuex-oidc'
import
store
from
'../store'
import
billRouters
from
'./bill-router.js'
import
moreRouters
from
'./more-router.js'
import
api
from
'../api/More'
import
qs
from
"qs"
;
import
axios
from
"axios"
;
Vue
.
use
(
VueRouter
)
const
oidc_config
=
JSON
.
parse
(
process
.
env
.
VUE_APP_OIDC_CONFIG
);
Vue
.
use
(
VueRouter
)
const
router
=
new
VueRouter
({
mode
:
'history'
,
...
...
@@ -29,90 +33,72 @@ const router = new VueRouter({
}
})
//自动登录
function
autoLogin
(
payload
=
{
autoCode
,
redirectPath
})
{
store
.
dispatch
(
"authenticateOidc"
,
{
options
:
{
extraQueryParams
:
{
authcode
:
payload
.
autoCode
},
redirectPath
:
payload
.
redirectPath
function
getAccessToken
(
authCode
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
api
.
getAccessToken
(
authCode
)
.
then
(
res
=>
{
if
(
res
&&
res
.
status
)
{
accessToken
=
res
.
data
.
accessToken
;
resolve
(
accessToken
);
}
else
{
reject
(
res
)
}
});
});
}
const
loginStorage
=
localStorage
;
const
autoLoginParamsKey
=
"autoLoginParams"
;
function
setAutoLogin
(
payload
=
{
autoCode
,
redirectPath
})
{
loginStorage
.
setItem
(
autoLoginParamsKey
,
JSON
.
stringify
(
payload
))
}
function
getAutoLoginParams
()
{
const
paramStr
=
loginStorage
.
getItem
(
autoLoginParamsKey
);
if
(
!!
paramStr
)
{
loginStorage
.
removeItem
(
autoLoginParamsKey
);
return
JSON
.
parse
(
paramStr
);
async
function
getToken
(
access_token
,
appid
,
next
)
{
let
pms
=
{
client_id
:
oidc_config
.
client_id
,
client_secret
:
oidc_config
.
client_secret
,
grant_type
:
"application"
,
scope
:
"workapps.client openid api.workapps.user api.workapps.org api.workapps.open"
,
app_register_id
:
appid
,
token
:
access_token
};
let
commonPms
=
GetCommonPms
();
let
url
=
`
${
oidc_config
.
authority
}
/connect/token?
${
commonPms
}
`
;
await
axios
.
post
(
url
,
qs
.
stringify
(
pms
))
.
then
(
res
=>
{
if
(
res
.
status
==
200
)
{
const
accessToken
=
res
.
data
.
access_token
;
localStorage
.
setItem
(
"token"
,
accessToken
);
next
()
}
},
err
=>
{
this
.
errMessage
=
err
.
response
.
data
.
error_description
;
}
return
null
;
)
.
catch
(
err
=>
{
console
.
log
(
"456err="
,
err
);
});
}
//如果有登录参数则优先登录
router
.
beforeEach
((
to
,
from
,
next
)
=>
{
const
autoLoginParams
=
getAutoLoginParams
();
if
(
autoLoginParams
)
{
autoLogin
(
autoLoginParams
);
}
else
{
next
();
}
})
router
.
beforeEach
((
to
,
from
,
next
)
=>
{
const
authcode
=
to
.
query
.
authCode
||
to
.
query
.
authcode
;
const
appid
=
to
.
query
.
appId
||
to
.
query
.
appid
;
const
userId
=
to
.
query
.
userid
||
to
.
query
.
userId
||
0
;
if
(
!!
authcode
&&
!!
appid
)
{
var
toPath
=
to
.
path
||
"/"
;
for
(
let
key
in
to
.
query
)
{
if
(
key
==
'authcode'
||
key
==
'authCode'
)
{
continue
;
}
toPath
+=
toPath
.
indexOf
(
"?"
)
>
-
1
?
"&"
:
"?"
;
toPath
+=
`
${
key
}
=
${
to
.
query
[
key
]}
`
;
}
const
storeAppId
=
localStorage
.
getItem
(
'appid'
);
store
.
dispatch
(
"getOidcUser"
).
then
(
oidcUser
=>
{
if
(
oidcUser
)
{
if
(
storeAppId
!=
appid
){
localStorage
.
setItem
(
'appid'
,
appid
);
setAutoLogin
({
autoCode
:
authcode
,
redirectPath
:
toPath
})
store
.
dispatch
(
"signOutOidc"
)
}
else
{
//如果登录用户与当前登录用户不匹配,则保存登录参数,退出
console
.
log
(
'userId='
,
userId
);
console
.
log
(
'oidcUser.profile.sub='
,
oidcUser
.
profile
.
sub
);
console
.
log
(
'oidcUser.profile.sub==userId:'
,
oidcUser
.
profile
.
sub
==
userId
);
if
(
userId
>
0
&&
oidcUser
.
profile
.
sub
!=
userId
)
{
setAutoLogin
({
autoCode
:
authcode
,
redirectPath
:
toPath
})
store
.
dispatch
(
"signOutOidc"
)
}
else
{
next
()
}
}
}
else
{
localStorage
.
setItem
(
'appid'
,
appid
);
autoLogin
({
autoCode
:
authcode
,
redirectPath
:
toPath
})
}
}).
catch
(()
=>
{
localStorage
.
setItem
(
'appid'
,
appid
);
autoLogin
({
autoCode
:
authcode
,
redirectPath
:
toPath
})
});
getAccessToken
(
authcode
).
then
(
res
=>
{
const
token
=
res
;
getToken
(
token
,
appid
,
next
);
}).
catch
(
err
=>
{
console
.
log
(
'err='
,
err
);
})
}
else
{
next
()
}
})
router
.
beforeEach
(
vuexOidcCreateRouterMiddleware
(
store
));
router
.
beforeEach
(
vuexOidcCreateRouterMiddleware
(
store
));
export
default
router
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment