Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
study
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Damon
study
Commits
89385bfb
Commit
89385bfb
authored
Jul 12, 2021
by
Damon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 登录授权
parent
9d446897
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
50 additions
and
43 deletions
+50
-43
common.js
src/api/common.js
+2
-2
index.js
src/api/index.js
+8
-8
http.interceptor.js
src/common/http.interceptor.js
+26
-25
index.vue
src/pages/login/index.vue
+14
-8
No files found.
src/api/common.js
View file @
89385bfb
let
commonApiFun
=
function
(
vm
)
{
let
commonApiFun
=
function
(
vm
)
{
let
loginWechatAuth
=
async
(
params
=
{})
=>
await
vm
.
$u
.
post
(
'/authorization'
,
params
)
let
loginWechatAuth
=
async
(
params
=
{})
=>
await
vm
.
$u
.
post
(
'/
wxapp/unify/
authorization'
,
params
)
const
commonApi
=
{
const
commonApi
=
{
loginWechatAuth
loginWechatAuth
...
...
src/api/index.js
View file @
89385bfb
import
{
commonApiFun
}
from
'./common.js'
;
import
{
commonApiFun
}
from
'./common.js'
const
apiFun
=
function
(
vm
)
{
const
apiFun
=
function
(
vm
)
{
let
commonApi
=
commonApiFun
(
vm
);
let
commonApi
=
commonApiFun
(
vm
)
let
apiUrl
=
{
let
apiUrl
=
{
...
commonApi
,
...
commonApi
,
...
@@ -9,5 +9,5 @@ const apiFun = function(vm) {
...
@@ -9,5 +9,5 @@ const apiFun = function(vm) {
}
}
module
.
exports
=
{
module
.
exports
=
{
apiFun
apiFun
,
}
}
src/common/http.interceptor.js
View file @
89385bfb
...
@@ -9,7 +9,8 @@ const install = (Vue, vm) => {
...
@@ -9,7 +9,8 @@ const install = (Vue, vm) => {
channel
:
'Applets'
,
channel
:
'Applets'
,
'content-type'
:
'application/json; charset=utf-8'
,
'content-type'
:
'application/json; charset=utf-8'
,
},
},
originalData
:
true
loadingTime
:
0
,
originalData
:
true
,
})
})
// 请求拦截,配置Token等参数
// 请求拦截,配置Token等参数
...
@@ -37,7 +38,6 @@ const install = (Vue, vm) => {
...
@@ -37,7 +38,6 @@ const install = (Vue, vm) => {
const
data
=
res
.
data
const
data
=
res
.
data
if
(
res
.
statusCode
===
200
)
{
if
(
res
.
statusCode
===
200
)
{
if
(
data
.
code
===
0
)
{
if
(
data
.
code
===
0
)
{
// res为服务端返回值,可能有code,result等字段
return
data
.
data
return
data
.
data
}
else
if
(
data
.
code
===
401
)
{
}
else
if
(
data
.
code
===
401
)
{
vm
.
$u
.
toast
(
data
.
msg
)
vm
.
$u
.
toast
(
data
.
msg
)
...
@@ -55,7 +55,8 @@ const install = (Vue, vm) => {
...
@@ -55,7 +55,8 @@ const install = (Vue, vm) => {
vm
.
$u
.
toast
(
data
.
msg
)
vm
.
$u
.
toast
(
data
.
msg
)
return
false
return
false
}
}
}
else
{
// HTTP状态非200
}
else
{
// HTTP状态非200
vm
.
$u
.
toast
(
data
.
msg
||
'服务器错误'
)
vm
.
$u
.
toast
(
data
.
msg
||
'服务器错误'
)
}
}
}
}
...
...
src/pages/login/index.vue
View file @
89385bfb
...
@@ -17,8 +17,7 @@ export default {
...
@@ -17,8 +17,7 @@ export default {
host
:
''
,
//配置为自己的额服务器即可
host
:
''
,
//配置为自己的额服务器即可
}
}
},
},
onShow
()
{
onShow
()
{},
},
methods
:
{
methods
:
{
wxLogin
()
{
wxLogin
()
{
// 获取code 小程序专有,用户登录凭证。
// 获取code 小程序专有,用户登录凭证。
...
@@ -31,12 +30,19 @@ export default {
...
@@ -31,12 +30,19 @@ export default {
provider
:
'weixin'
,
provider
:
'weixin'
,
success
:
(
code_res
)
=>
{
success
:
(
code_res
)
=>
{
if
(
code_res
.
errMsg
==
'login:ok'
)
{
if
(
code_res
.
errMsg
==
'login:ok'
)
{
let
code
=
code_res
.
code
const
code
=
code_res
.
code
console
.
log
(
'user, code'
,
user
,
code
)
const
userInfo
=
user
.
userInfo
this
.
$u
.
vuex
(
'vuex_token'
,
code
)
const
data
=
{
this
.
$u
.
vuex
(
'userInfo'
,
user
.
userInfo
)
code
:
code
,
avatar
:
userInfo
.
avatarUrl
,
nickname
:
userInfo
.
nickName
,
}
this
.
$u
.
api
.
loginWechatAuth
(
data
).
then
((
res
)
=>
{
this
.
$u
.
vuex
(
'vuex_token'
,
res
.
token
)
this
.
$u
.
vuex
(
'userInfo'
,
userInfo
)
this
.
$u
.
route
({
this
.
$u
.
route
({
type
:
'back'
type
:
'back'
,
})
})
})
}
}
},
},
...
...
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