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
857efe18
authored
Apr 27, 2020
by
展昭
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
添加app_register_id逻辑
parent
af8a8dd8
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
127 additions
and
84 deletions
src/api/index.js
src/assets/js/SecurityService.js
src/main.js
src/router/index.js
src/store/modules/token.js
src/views/Bill/index.vue
src/views/Bill/record.vue
src/views/OidcCallback.vue
src/views/test.vue
src/api/index.js
View file @
857efe18
...
...
@@ -56,7 +56,8 @@ const api = {
};
function
defineHeader
()
{
const
token
=
store
.
state
.
oidc
.
access_token
;
//const token = store.state.oidc.access_token;
const
token
=
store
.
getters
.
getToken
;
headers
.
Authorization
=
"Bearer "
+
token
;
return
Promise
.
resolve
(
headers
);
}
...
...
src/assets/js/SecurityService.js
deleted
100644 → 0
View file @
af8a8dd8
This diff is collapsed.
Click to expand it.
src/main.js
View file @
857efe18
...
...
@@ -16,7 +16,7 @@ Vue.prototype.globalNavLeftArrowClick = function (callback) {
new
Vue
({
router
,
store
,
router
,
render
:
h
=>
h
(
App
)
}).
$mount
(
'#app'
)
src/router/index.js
View file @
857efe18
...
...
@@ -4,7 +4,6 @@ import moreRouters from './more-router.js'
import
billRouters
from
'./bill-router.js'
import
{
vuexOidcCreateRouterMiddleware
}
from
'vuex-oidc'
import
store
from
'../store'
import
Mgr
from
"../assets/js/SecurityService"
Vue
.
use
(
VueRouter
)
...
...
@@ -30,58 +29,8 @@ const router = new VueRouter({
}
})
const
mgr
=
new
Mgr
();
function
loginByAuthcode
(
authCode
)
{
let
loginArgs
=
{
extraQueryParams
:
{
authcode
:
authCode
}
};
mgr
.
signIn
(
loginArgs
);
}
function
autoLogin
(
comid
,
authcode
,
next
)
{
localStorage
.
setItem
(
"comid"
,
comid
);
mgr
.
getUser
().
then
(
user
=>
{
if
(
user
==
null
)
{
loginByAuthcode
(
authcode
);
}
else
{
let
companyId
=
localStorage
.
getItem
(
"companyId"
);
if
(
comid
!=
companyId
)
{
//如果已经登录,则先退出
localStorage
.
setItem
(
"authcode"
,
authcode
);
mgr
.
signOut
();
}
else
{
next
();
}
}
})
}
router
.
beforeEach
(
vuexOidcCreateRouterMiddleware
(
store
));
// router.beforeEach((to, from, next) => {
// let authcode = localStorage.getItem("authcode")
// if (authcode) {
// localStorage.removeItem("authcode");
// loginByAuthcode(authcode)
// }
// else {
// authcode = to.query.authcode;
// const comid = to.query.comId || to.query.comid;
// if (comid && authcode) {
// localStorage.setItem("autoCallback", to.path);
// autoLogin(comid, authcode, next);
// } else {
// mgr.getUser().then(user => {
// if (user == null) {
// mgr.signIn();
// } else {
// next()
// }
// });
// }
// }
// });
//TODO: 把callBack中的app_register_id逻辑替换到这里
export
default
router
src/store/modules/token.js
View file @
857efe18
import
types
from
"../types"
;
let
usermemberId
=
'206484'
let
token
=
''
const
state
=
{
usermemberId
,
token
}
const
getters
=
{
getToken
(
state
)
{
state
.
token
=
localStorage
.
getItem
(
"token"
);
return
state
.
token
;
},
}
const
mutations
=
{
[
types
.
CHANGE_TOKEN
](
state
,
token
)
{
state
.
token
=
token
;
try
{
localStorage
.
setItem
(
"token"
,
token
);
}
catch
(
error
)
{
}
},
}
const
state
=
{
usermemberId
}
const
actions
=
{
changeToken
({
commit
},
token
)
{
commit
(
types
.
CHANGE_TOKEN
,
token
);
}
}
export
default
{
state
state
,
getters
,
mutations
,
actions
}
\ No newline at end of file
src/views/Bill/index.vue
View file @
857efe18
...
...
@@ -155,7 +155,7 @@
</
template
>
<
script
>
//TODO: 根据当前时间显示日期
import
{
Icon
,
Loading
}
from
"vant"
;
import
{
TabHeader
}
from
"@/components"
;
import
*
as
utils
from
"../../utils/common"
;
...
...
src/views/Bill/record.vue
View file @
857efe18
...
...
@@ -77,7 +77,6 @@ export default {
pageSize
:
"10"
}).
then
(
resdata
=>
{
let
arr
=
resdata
.
list
;
// 如果是第一页需手动制空列表
if
(
page
.
num
===
1
)
this
.
dataList
=
[];
...
...
src/views/OidcCallback.vue
View file @
857efe18
<
template
>
<div>
</div>
<div></div>
</
template
>
<
script
>
import
{
mapActions
}
from
'vuex'
import
{
mapActions
}
from
"vuex"
;
import
{
GetCommonPms
}
from
"../assets/js/CommonPms.js"
;
import
qs
from
"qs"
;
import
axios
from
"axios"
;
import
common
from
"../utils/common.js"
;
import
store
from
"../store"
;
const
oidc_config
=
JSON
.
parse
(
process
.
env
.
VUE_APP_OIDC_CONFIG
);
export
default
{
name
:
'OidcCallback'
,
name
:
"OidcCallback"
,
methods
:
{
...
mapActions
([
'oidcSignInCallback'
])
...
mapActions
([
"oidcSignInCallback"
,
"getOidcUser"
]),
getQueryString
(
urlsearch
,
name
)
{
var
reg
=
new
RegExp
(
"(^|&)"
+
name
+
"=([^&]*)(&|$)"
);
var
r
=
urlsearch
.
match
(
reg
);
if
(
r
!=
null
)
return
unescape
(
r
[
2
]);
return
null
;
},
async
getToken
(
access_token
,
appid
,
redirectPath
)
{
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
}
`
;
console
.
log
(
"url="
,
url
);
await
axios
.
post
(
url
,
qs
.
stringify
(
pms
))
.
then
(
res
=>
{
console
.
log
(
"res="
,
res
);
if
(
res
.
status
==
200
)
{
const
accessToken
=
res
.
data
.
access_token
;
//store.dispatch("changeToken", accessToken);
localStorage
.
setItem
(
"token"
,
accessToken
);
this
.
$router
.
push
(
redirectPath
);
}
},
err
=>
{
console
.
log
(
"err="
,
err
);
}
)
.
catch
(
err
=>
{
console
.
log
(
"err="
,
err
);
this
.
$router
.
push
(
"/oidc-callback-error"
);
// Handle errors any way you want
});
}
},
mounted
()
{
mounted
()
{
this
.
oidcSignInCallback
()
.
then
((
redirectPath
)
=>
{
this
.
$router
.
push
(
redirectPath
)
})
.
catch
((
err
)
=>
{
console
.
error
(
err
)
this
.
$router
.
push
(
'/oidc-callback-error'
)
// Handle errors any way you want
.
then
(
redirectPath
=>
{
this
.
getOidcUser
()
.
then
(
res
=>
{
let
urlsearch
=
redirectPath
.
split
(
"?"
)[
1
];
let
appid
=
this
.
getQueryString
(
urlsearch
,
"appid"
);
console
.
log
(
"appid="
,
appid
);
this
.
getToken
(
res
.
access_token
,
appid
,
redirectPath
);
})
.
catch
(
err
=>
{
console
.
log
(
"err="
,
err
);
});
//this.$router.push(redirectPath);
})
.
catch
(
err
=>
{
console
.
error
(
err
);
this
.
$router
.
push
(
"/oidc-callback-error"
);
// Handle errors any way you want
});
}
}
}
;
</
script
>
\ No newline at end of file
src/views/test.vue
View file @
857efe18
...
...
@@ -9,13 +9,14 @@
<div
v-else
></div>
<div
class=
"btn"
@
click=
"getOidcUserMy"
>
getOidcUser
</div>
<div
class=
"btn"
@
click=
"authenticateOidcSilent"
>
authenticateOidcSilent
</div>
<div
class=
"btn"
@
click=
"signOutOidc"
>
signOut
</div>
</div>
</
template
>
<
script
>
import
{
TabHeader
}
from
"@/components"
;
import
{
mapGetters
,
mapActions
}
from
"vuex"
;
import
store
from
"@/store"
import
store
from
"@/store"
;
export
default
{
components
:
{
TabHeader
...
...
@@ -30,28 +31,37 @@ export default {
"oidcIdTokenExp"
,
"oidcAuthenticationIsChecked"
,
"oidcError"
]),
hasAccess
:
function
()
{
return
this
.
oidcIsAuthenticated
||
this
.
$route
.
meta
.
isPublic
;
}
])
// hasAccess: function() {
// return this.oidcIsAuthenticated || this.$route.meta.isPublic;
// }
},
mounted
()
{
this
.
oidcCheckAccess
(
this
.
$route
).
then
(
res
=>
{
console
.
log
(
"res="
,
res
);
});
},
methods
:
{
...
mapActions
([
"oidcCheckAccess"
,
"authenticateOidc"
,
// Authenticates with redirect to sign in if not signed in
"oidcSignInCallback"
,
// Handles callback from authentication redirect. Has an optional url parameter
"authenticateOidcSilent"
,
// Authenticates if signed in. No redirect is made if not signed in
"getOidcUser"
,
// Get user from oidc-client storage and update it in vuex store. Returns a promise
"signOutOidc"
,
// Signs out user in open id provider
"removeOidcUser"
// Signs out user in vuex and browser storage, but not in open id provider
"removeOidcUser"
,
// Signs out user in vuex and browser storage, but not in open id provider
"addOidcEventListener"
]),
getOidcUserMy
()
{
console
.
log
(
'store='
,
store
);
this
.
getOidcUser
().
then
(
res
=>
{
console
.
log
(
"res="
,
JSON
.
stringify
(
res
));
});
this
.
getOidcUser
()
.
then
(
res
=>
{
console
.
log
(
"res="
,
JSON
.
stringify
(
res
));
})
.
catch
(
err
=>
{
console
.
log
(
"err="
,
err
);
});
// const token=this.oidcAccessToken;
// console.log('token=',token);
}
},
data
()
{
...
...
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