Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mayi-mp-shop
Overview
Overview
Details
Activity
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
程默
mayi-mp-shop
Commits
f2a0ac00
Commit
f2a0ac00
authored
May 08, 2021
by
程默
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
第三方跳转 sso
parent
5babe6db
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
125 additions
and
100 deletions
+125
-100
src/api/login.js
+5
-0
src/pages/login/index.vue
+102
-87
src/pages/wxArticle/index.vue
+16
-12
src/pages/wxArticle/main.json
+2
-1
No files found.
src/api/login.js
View file @
f2a0ac00
...
...
@@ -15,6 +15,10 @@ console.log(process.env,'-----------------config------')
//check unionid
checkUnionid
(
options
){
return
requestGET
(
`
${
process
.
env
.
OLSHOP_URL
}
/wx/mini_check_union_id`
,
options
)
},
// sso登录
getSsoBcakUrl
(
options
)
{
return
requestPOST
(
`
${
process
.
env
.
OLSHOP_URL
}
/common/getSsoCallbackUrl`
,
options
)
}
}
\ No newline at end of file
src/pages/login/index.vue
View file @
f2a0ac00
...
...
@@ -2,19 +2,27 @@
<div
class=
"domain"
>
<div
class=
"toCLogin"
>
<image
class=
"img"
mode=
"aspectFit"
:src=
"logoUrl"
/>
<p
class=
"shopName"
v-if=
"shopName"
>
{{
shopName
}}
</p>
<p
class=
"shopName"
v-if=
"shopName"
>
{{
shopName
}}
</p>
<div
class=
"btn_info"
>
<button
class=
"btn"
lang=
"zh_CN"
@
click=
"getUserProfile"
>
微信一键登录
</button>
<button
class=
"btn"
lang=
"zh_CN"
@
click=
"getUserProfile"
>
微信一键登录
</button>
</div>
</div>
<div
class=
"toCLogin1"
v-if=
"isShowPhone"
>
<div
class=
"btn_info1"
>
<h1>
绑定手机号
</h1>
<span
class=
"hint"
>
检测到您的账号还未绑定手机号,请绑定手机号
</span>
<button
class=
"btn"
open-type=
"getPhoneNumber"
@
getphonenumber=
"getPhoneNumber"
>
绑定手机号一键绑定
</button>
<button
class=
"btn"
open-type=
"getPhoneNumber"
@
getphonenumber=
"getPhoneNumber"
>
绑定手机号一键绑定
</button>
<div
class=
"btn2"
@
click=
"handbindHandle"
>
手动绑定手机号
</div>
</div>
<div
class=
"layer"
@
click=
"isShowPhone
=
false"
></div>
<div
class=
"layer"
@
click=
"isShowPhone
=
false"
></div>
</div>
</div>
</
template
>
...
...
@@ -54,44 +62,44 @@ export default {
test_sessionId
:
""
,
test_isHaveUnion
:
""
,
test_unionId
:
""
,
fromType
:
''
,
//来源类型 mini:小程序跳转到当前登录页
scene
:
''
//场景
fromType
:
""
,
//来源类型 mini:小程序跳转到当前登录页
scene
:
""
,
//场景
};
},
onShow
()
{
wx
.
checkSession
({
success
:
()
=>
{
success
:
()
=>
{
//session_key 未过期,并且在本生命周期一直有效
wx
.
login
({
success
:
res
=>
{
success
:
(
res
)
=>
{
this
.
code
=
res
.
code
;
},
fail
:
err
=>
{
fail
:
(
err
)
=>
{
reject
(
err
);
}
})
//重新登录
},
fail
:
()
=>
{
});
//重新登录
},
fail
:
()
=>
{
// session_key 已经失效,需要重新执行登录流程
wx
.
login
({
success
:
res
=>
{
success
:
(
res
)
=>
{
this
.
code
=
res
.
code
;
},
fail
:
err
=>
{
fail
:
(
err
)
=>
{
reject
(
err
);
}
})
//重新登录
}
})
}
,
})
;
//重新登录
}
,
})
;
},
onLoad
(
options
)
{
Object
.
assign
(
this
.
$data
,
this
.
$options
.
data
());
//mpvue 的混合周期 使用小程序生命周期数据未初始化
options
.
scene
&&
(
this
.
scene
=
options
.
scene
)
options
.
scene
&&
(
this
.
scene
=
options
.
scene
);
if
(
options
.
back
)
{
this
.
backPath
=
options
.
back
;
}
if
(
options
.
params
)
{
this
.
defalutBackParams
=
serialize
(
options
.
params
);
this
.
defalutBackParams
=
serialize
(
options
.
params
);
this
.
backParams
=
this
.
defalutBackParams
;
let
params
=
JSON
.
parse
(
options
.
params
);
this
.
fromType
=
params
.
fromType
;
...
...
@@ -103,18 +111,18 @@ export default {
this
.
shopName
=
wx
.
getStorageSync
(
"shopName"
);
this
.
logoUrl
=
wx
.
getStorageSync
(
"logoUrl"
);
if
(
!
(
this
.
shopName
&&
this
.
logoUrl
))
{
shop
.
getShopInfo
().
then
(
res
=>
{
shop
.
getShopInfo
().
then
(
(
res
)
=>
{
if
(
res
.
data
.
code
==
200
)
{
this
.
shopName
=
res
.
data
.
data
.
shopName
;
this
.
logoUrl
=
process
.
env
.
IMG_DOMAIN
+
res
.
data
.
data
.
logoUrl
;
wx
.
setStorage
({
key
:
"shopName"
,
data
:
res
.
data
.
data
.
shopName
data
:
res
.
data
.
data
.
shopName
,
});
wx
.
setStorage
({
key
:
"logoUrl"
,
data
:
process
.
env
.
IMG_DOMAIN
+
res
.
data
.
data
.
logoUrl
data
:
process
.
env
.
IMG_DOMAIN
+
res
.
data
.
data
.
logoUrl
,
});
}
});
...
...
@@ -123,65 +131,65 @@ export default {
init
()
{
return
new
Promise
((
resolve
,
reject
)
=>
{
login
.
miniLogin
({
code
:
this
.
code
,
spokesmanRelId
:
''
,
spokesmanGroupId
:
''
,
spokesmanShopId
:
''
.
miniLogin
({
code
:
this
.
code
,
spokesmanRelId
:
""
,
spokesmanGroupId
:
""
,
spokesmanShopId
:
""
,
})
.
then
(
res
=>
{
.
then
((
res
)
=>
{
if
(
res
.
data
.
code
==
200
)
{
resolve
(
res
);
}
else
{
reject
(
res
.
data
.
msg
);
}
})
.
catch
(
err
=>
{
.
catch
((
err
)
=>
{
reject
(
err
);
});
});
},
addRecord
(
flag
)
{
console
.
log
(
wx
.
getStorageSync
(
'attractingCustomerChannelId'
))
console
.
log
(
this
.
openid
)
console
.
log
(
99999
)
console
.
log
(
wx
.
getStorageSync
(
"attractingCustomerChannelId"
));
console
.
log
(
this
.
openid
)
;
console
.
log
(
99999
)
;
//埋点引客渠道
if
(
wx
.
getStorageSync
(
'attractingCustomerChannelId'
))
{
indexApi
.
addRecord
(
{
attractingCustomersChannelId
:
wx
.
getStorageSync
(
'attractingCustomerChannelId'
),
if
(
wx
.
getStorageSync
(
"attractingCustomerChannelId"
))
{
indexApi
.
addRecord
({
attractingCustomersChannelId
:
wx
.
getStorageSync
(
"attractingCustomerChannelId"
),
miniOpenId
:
this
.
openid
,
registerFlag
:
1
,
newRegisterFlag
:
flag
?
1
:
0
,
//1是新注册用户
}
).
then
(
ele
=>
{
wx
.
setStorageSync
(
'attractingCustomerChannelId'
,
''
)
newRegisterFlag
:
flag
?
1
:
0
,
//1是新注册用户
})
.
then
((
ele
)
=>
{
wx
.
setStorageSync
(
"attractingCustomerChannelId"
,
""
);
});
}
},
getUserProfile
()
{
// 推荐使用wx.getUserProfile获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认
// 开发者妥善保管用户快速填写的头像昵称,避免重复弹窗
wx
.
getUserProfile
({
desc
:
'用于完善会员资料'
,
// 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
desc
:
"用于完善会员资料"
,
// 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
success
:
(
e
)
=>
{
this
.
init
()
.
then
(
res
=>
{
.
then
(
(
res
)
=>
{
//存入openid
try
{
wx
.
setStorageSync
(
'openid'
,
res
.
data
.
data
.
openid
)
wx
.
setStorageSync
(
"openid"
,
res
.
data
.
data
.
openid
);
}
catch
(
e
)
{
console
.
log
(
'存入openid失败'
,
e
)
console
.
log
(
"存入openid失败"
,
e
);
}
if
(
res
.
data
.
data
.
isHaveUnion
==
"true"
)
{
//有账号
this
.
backParams
+=
`&sessionid=
${
res
.
data
.
data
.
sessionId
}
&needCertified=
${
res
.
data
.
data
.
NEED_CERTIFIED
}
`
;
this
.
backParams
+=
`&sessionid=
${
res
.
data
.
data
.
sessionId
}
&needCertified=
${
res
.
data
.
data
.
NEED_CERTIFIED
}
`
;
this
.
NEED_CERTIFIED
=
res
.
data
.
data
.
NEED_CERTIFIED
;
wx
.
setStorage
({
key
:
"sessionid"
,
data
:
res
.
data
.
data
.
sessionId
data
:
res
.
data
.
data
.
sessionId
,
});
this
.
isHaveUnion
=
true
;
...
...
@@ -193,23 +201,23 @@ export default {
this
.
appid
=
res
.
data
.
data
.
appid
;
this
.
session_key
=
res
.
data
.
data
.
session_key
;
this
.
openid
=
res
.
data
.
data
.
openid
;
this
.
unionId
=
res
.
data
.
data
.
unionId
||
''
;
this
.
unionId
=
res
.
data
.
data
.
unionId
||
""
;
this
.
isShow
=
true
;
//checkLogind
this
.
checkLogin
(
e
);
})
.
catch
(
err
=>
{
.
catch
(
(
err
)
=>
{
console
.
log
(
"err"
,
err
);
wx
.
hideLoading
();
wx
.
showToast
({
title
:
err
,
icon
:
"none"
});
});
}
})
}
,
})
;
},
checkLogin
(
e
)
{
this
.
userInfo
=
e
.
userInfo
;
this
.
$store
.
commit
(
'setUserInfo'
,
this
.
userInfo
)
this
.
$store
.
commit
(
"setUserInfo"
,
this
.
userInfo
);
if
(
this
.
isHaveUnion
)
{
wx
.
hideLoading
();
//是会员 直接登录
...
...
@@ -220,19 +228,17 @@ export default {
if
(
this
.
unionId
)
{
login
.
checkUnionid
({
unionId
:
this
.
unionId
,
openId
:
this
.
openid
})
.
then
(
res
=>
{
.
then
(
(
res
)
=>
{
wx
.
hideLoading
();
if
(
res
.
data
.
code
==
200
)
{
if
(
res
.
data
.
data
.
isHaveUnion
==
"true"
)
{
this
.
NEED_CERTIFIED
=
res
.
data
.
data
.
NEED_CERTIFIED
;
this
.
backParams
+=
`&sessionid=
${
res
.
data
.
data
.
sessionId
}
&needCertified=
${
res
.
data
.
data
.
NEED_CERTIFIED
}
`
;
this
.
backParams
+=
`&sessionid=
${
res
.
data
.
data
.
sessionId
}
&needCertified=
${
res
.
data
.
data
.
NEED_CERTIFIED
}
`
;
wx
.
setStorage
({
key
:
"sessionid"
,
data
:
res
.
data
.
data
.
sessionId
data
:
res
.
data
.
data
.
sessionId
,
});
this
.
addRecord
(
false
)
this
.
addRecord
(
false
)
;
// 跳转回小程序页面
this
.
pushPageType
();
// wx.reLaunch({
...
...
@@ -243,11 +249,11 @@ export default {
}
else
{
//不是会员需要绑定手机号
this
.
isShowPhone
=
true
;
this
.
addRecord
(
true
)
this
.
addRecord
(
true
)
;
}
}
})
.
catch
(
err
=>
{
.
catch
(
(
err
)
=>
{
wx
.
hideLoading
();
wx
.
showToast
({
title
:
err
,
icon
:
"none"
});
});
...
...
@@ -255,26 +261,36 @@ export default {
wx
.
hideLoading
();
//不是会员需要绑定手机号
this
.
isShowPhone
=
true
;
this
.
addRecord
(
true
)
this
.
addRecord
(
true
)
;
}
}
},
// 是否跳转h5或小程序
pushPageType
(){
if
(
this
.
fromType
==
'mini'
){
pushPageType
()
{
console
.
log
(
'2700000'
,
this
.
backPath
)
if
(
this
.
fromType
==
"mini"
)
{
wx
.
navigateBack
({
delta
:
1
delta
:
1
,
});
}
else
if
(
this
.
scene
==
'sso'
)
{
}
else
if
(
this
.
scene
==
"sso"
)
{
let
op
=
{
callbackUrl
:
this
.
backPath
,
email
:
""
,
fromAppid
:
"VsEOuDJqBnGNyXZJWCQS"
,
mobilephone
:
'15821335747'
,
toAppid
:
"hgFTLLhgnBmeOyCkcbyv"
,
//道可
wxAvatarUrl
:
this
.
userInfo
.
avatarUrl
,
};
login
.
getSsoBcakUrl
(
op
).
then
((
res
)
=>
{
wx
.
redirectTo
({
url
:
`../wxArticle/main?link=
${
this
.
backPath
}
`
,
url
:
`../wxArticle/main?link=
${
res
.
data
.
data
}
`
,
});
});
}
else
{
}
else
{
wx
.
reLaunch
({
url
:
`../index/main?from=login&backpath=
${
this
.
backPath
}
¶ms=
${
encodeURIComponent
(
this
.
backParams
)}
`
}
¶ms=
${
encodeURIComponent
(
this
.
backParams
)}
`
,
});
}
},
...
...
@@ -297,7 +313,7 @@ export default {
fail
:
()
=>
{
// session_key 已经失效,需要重新执行登录流程
// wx.login() //重新登录
}
}
,
});
},
bindUser
()
{
...
...
@@ -312,7 +328,8 @@ export default {
province
:
this
.
userInfo
.
province
,
city
:
this
.
userInfo
.
city
,
otherPhone
:
0
,
articleId
:
wx
.
getStorageSync
(
this
.
$store
.
state
.
mixid
+
"articleId"
)
||
''
articleId
:
wx
.
getStorageSync
(
this
.
$store
.
state
.
mixid
+
"articleId"
)
||
""
,
};
if
(
this
.
$store
.
state
.
spokesmanGroupId
!=
""
)
{
query
.
spokesmanRelId
=
this
.
$store
.
state
.
spokesmanRelId
;
...
...
@@ -323,17 +340,15 @@ export default {
console
.
log
(
query
,
"query"
);
login
.
bindUser
(
query
)
.
then
(
res
=>
{
.
then
(
(
res
)
=>
{
//绑定成功
if
(
res
.
data
.
code
==
200
)
{
wx
.
setStorageSync
(
this
.
$store
.
state
.
mixid
+
'articleId'
,
false
)
wx
.
setStorageSync
(
this
.
$store
.
state
.
mixid
+
"articleId"
,
false
);
this
.
NEED_CERTIFIED
=
res
.
data
.
data
.
NEED_CERTIFIED
;
this
.
backParams
+=
`&sessionid=
${
res
.
data
.
data
.
sessionId
}
&needCertified=
${
res
.
data
.
data
.
NEED_CERTIFIED
}
`
;
this
.
backParams
+=
`&sessionid=
${
res
.
data
.
data
.
sessionId
}
&needCertified=
${
res
.
data
.
data
.
NEED_CERTIFIED
}
`
;
wx
.
setStorage
({
key
:
"sessionid"
,
data
:
res
.
data
.
data
.
sessionId
data
:
res
.
data
.
data
.
sessionId
,
});
// 跳转回小程序页面
this
.
pushPageType
();
...
...
@@ -344,7 +359,7 @@ export default {
// });
}
})
.
catch
(
err
=>
{
.
catch
(
(
err
)
=>
{
console
.
log
(
err
,
"bindusererr"
);
});
},
...
...
@@ -360,7 +375,7 @@ export default {
eLogin
()
{
//企业员工登录
wx
.
redirectTo
({
url
:
`../index/main?from=login&backpath=/login/accountLogin`
url
:
`../index/main?from=login&backpath=/login/accountLogin`
,
});
},
handbindHandle
()
{
...
...
@@ -372,16 +387,16 @@ export default {
nickname
:
this
.
userInfo
.
nickName
,
country
:
this
.
userInfo
.
country
,
province
:
this
.
userInfo
.
province
,
city
:
this
.
userInfo
.
city
city
:
this
.
userInfo
.
city
,
};
//绑定手机号
wx
.
navigateTo
({
url
:
`../index/main?from=login&backpath=/login/wxRegister¶ms=
${
encodeURIComponent
(
serialize
(
query
)
)}
`
)}
`
,
});
}
}
}
,
};
</
script
>
...
...
@@ -449,7 +464,7 @@ export default {
margin
:
10px
15px
;
font-weight
:
normal
;
}
.hint
{
.hint
{
color
:
#888
;
font-size
:
15px
;
text-align
:
center
;
...
...
@@ -458,8 +473,8 @@ export default {
}
.btn
{
margin-top
:
25px
;
background-color
:
#5
CB83B
;
color
:
#
FFFAFA
;
background-color
:
#5
cb83b
;
color
:
#
fffafa
;
height
:
45px
;
border-radius
:
22.5px
;
font-size
:
15px
;
...
...
src/pages/wxArticle/index.vue
View file @
f2a0ac00
...
...
@@ -26,38 +26,42 @@ export default {
};
},
async
onLoad
(
options
)
{
console
.
log
(
'wxarticle'
,
options
)
// options.scene="64a77cd6aeac4c1db46e3f7d53596fe6"
if
(
options
.
link
)
{
this
.
link
=
decodeURIComponent
(
options
.
link
);
}
else
if
(
options
.
scene
)
{
//扫码
let
data
=
await
this
.
getParams
(
options
.
scene
||
"959ce6ac97cf4f43a1759eb41ec12798"
);
if
(
data
.
sso
==
"sso"
&&
!
wx
.
getStorageSync
(
"sessionid"
))
{
let
data
=
await
this
.
getParams
(
options
.
scene
);
if
(
data
.
sso
)
{
if
(
!
wx
.
getStorageSync
(
"sessionid"
))
{
wx
.
redirectTo
({
url
:
`../login/main?scene=sso&back=
${
data
.
link
}
`
,
});
}
else
{
let
link
=
decodeURIComponent
(
data
.
link
).
replace
(
"${token}"
,
wx
.
getStorageSync
(
"sessionid"
)
);
wx
.
redirectTo
({
url
:
`../login/main?scene=sso&back=
${
link
}
`
,
});
}
else
{
this
.
link
=
data
.
link
;
this
.
link
=
decodeURIComponent
(
link
);
}
}
}
},
methods
:
{
getParams
(
options
)
{
return
indexApi
return
new
Promise
((
resolve
,
reject
)
=>
{
indexApi
.
getShareSceneRecord
(
options
)
.
then
((
res
)
=>
{
if
(
res
.
data
.
code
==
"200"
)
{
console
.
log
(
"5666666"
,
res
);
let
scene
=
JSON
.
parse
(
res
.
data
.
data
.
scene
);
resolve
(
scene
.
link
);
resolve
(
scene
);
}
})
.
catch
((
err
)
=>
{});
});
},
//加载成功
handleLoad
()
{
...
...
src/pages/wxArticle/main.json
View file @
f2a0ac00
{
"navigationBarTitleText"
:
"文章"
}
\ 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