公共登录类
This commit is contained in:
84
public/keyPhone.js
Normal file
84
public/keyPhone.js
Normal file
@@ -0,0 +1,84 @@
|
||||
|
||||
/**
|
||||
* Web唐明明
|
||||
* 匆匆数载恍如梦,岁月迢迢华发增。
|
||||
* 碌碌无为枉半生,一朝惊醒万事空。
|
||||
* moduleName: 一键登录
|
||||
*/
|
||||
|
||||
import { auth } from '@/apis/interfaces/auth'
|
||||
import store from '@/store/index'
|
||||
import { router } from '@/router'
|
||||
|
||||
class keyPhone {
|
||||
constructor(config) {
|
||||
this.config = {
|
||||
fullScreen: true,
|
||||
authButton: {
|
||||
normalColor: "#c82626",
|
||||
borderRadius: 0
|
||||
},
|
||||
buttons: {
|
||||
list: [{
|
||||
provider: "微信",
|
||||
iconPath: "/static/icons/wechat.png"
|
||||
}]
|
||||
},
|
||||
otherLoginButton: {
|
||||
borderColor: "#c82626",
|
||||
title: "其他手机号码登录",
|
||||
borderRadius: 0,
|
||||
textColor: "#c82626"
|
||||
},
|
||||
privacyTerm: {
|
||||
privacyItems: [{
|
||||
url: "https://baidu.com",
|
||||
title: "用户服务协议"
|
||||
}]
|
||||
}
|
||||
}
|
||||
}
|
||||
// 一键登录
|
||||
keyAuth() {
|
||||
return new Promise((resolve, reject) => {
|
||||
wx.login({
|
||||
provider : 'univerify',
|
||||
univerifyStyle : this.config,
|
||||
success : phoneToken => {
|
||||
let data = phoneToken.authResult
|
||||
auth({
|
||||
access_token: data.access_token,
|
||||
openid : data.openid
|
||||
}).then(res => {
|
||||
store.commit('setToken', res.token_type + ' ' + res.access_token)
|
||||
resolve({
|
||||
is_new: res.is_new
|
||||
})
|
||||
uni.closeAuthView()
|
||||
})
|
||||
},
|
||||
fail : err => {
|
||||
switch(err.code) {
|
||||
case '30002':
|
||||
console.log('其他登录方式')
|
||||
// router.push({name: 'Sms'})
|
||||
break
|
||||
case '30008':
|
||||
this.wxAuth()
|
||||
break
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// 微信登录
|
||||
wxAuth() {
|
||||
uni.showToast({
|
||||
title: '微信登录',
|
||||
icon : 'none'
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export default new keyPhone()
|
||||
Reference in New Issue
Block a user