['设置中心']
This commit is contained in:
135
public/userAuth.js
Normal file
135
public/userAuth.js
Normal file
@@ -0,0 +1,135 @@
|
||||
|
||||
/**
|
||||
* Web唐明明
|
||||
* 匆匆数载恍如梦,岁月迢迢华发增。
|
||||
* 碌碌无为枉半生,一朝惊醒万事空。
|
||||
* moduleName: 登录
|
||||
*/
|
||||
|
||||
import { router } from '../router'
|
||||
import { keyAuth } from '../apis/interfaces/auth'
|
||||
import store from '../store'
|
||||
|
||||
class userAuth {
|
||||
constructor() {
|
||||
this.univerfyConfig = {
|
||||
fullScreen : true,
|
||||
authButton: {
|
||||
'title': '一键登录',
|
||||
'normalColor': '#c82626',
|
||||
'highlightColor': '#a61010',
|
||||
'disabledColor': '#d86767',
|
||||
'borderRadius': '0'
|
||||
},
|
||||
otherLoginButton: {
|
||||
'title': '其他手机号码',
|
||||
'borderColor': '#c82626',
|
||||
'borderRadius': '0',
|
||||
'textColor': '#c82626'
|
||||
},
|
||||
privacyTerms: {
|
||||
'checkedImage': '/static/icons/checked-icon.png',
|
||||
'uncheckedImage': '/static/icons/unchecked-icon.png',
|
||||
'textColor': '#555555',
|
||||
'termsColor': '#c82626',
|
||||
'suffix': '并使用本机号码登录/注册',
|
||||
'privacyItems': [{
|
||||
'url': 'https://www.baidu.com',
|
||||
'title': '用户隐私规格'
|
||||
},{
|
||||
'url': 'https://www.baidu.com',
|
||||
'title': '用户服务协议'
|
||||
}]
|
||||
},
|
||||
buttons: {
|
||||
'iconWidth': '45px',
|
||||
'list': [{
|
||||
"provider": '微信登录',
|
||||
"iconPath": '/static/icons/wechat.png',
|
||||
}]
|
||||
}
|
||||
}
|
||||
}
|
||||
// 预登录
|
||||
Login(){
|
||||
return new Promise((resolve, reject) => {
|
||||
uni.showLoading({
|
||||
title: '加载中',
|
||||
mask : true
|
||||
})
|
||||
uni.preLogin({
|
||||
provider: 'univerify',
|
||||
success : res=> {
|
||||
this.keyLogin().then(() => {
|
||||
resolve({
|
||||
auth: true
|
||||
})
|
||||
}).catch(errMsg => {
|
||||
reject(errMsg)
|
||||
})
|
||||
},
|
||||
fail : err=> {
|
||||
router.push({name: 'Login'})
|
||||
},
|
||||
complete() {
|
||||
uni.hideLoading()
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
// 一键登录
|
||||
keyLogin(){
|
||||
return new Promise((resolve, reject) => {
|
||||
uni.login({
|
||||
provider : 'univerify',
|
||||
univerifyStyle : {...this.univerfyConfig},
|
||||
success: authResult => {
|
||||
keyAuth({
|
||||
access_token: authResult.authResult.access_token,
|
||||
openid : authResult.authResult.openid
|
||||
}).then(res => {
|
||||
uni.closeAuthView()
|
||||
store.commit('setToken', res.token_type + ' ' + res.access_token)
|
||||
resolve()
|
||||
if(!res.is_company){
|
||||
router.push({name: "Registered"})
|
||||
return
|
||||
}
|
||||
}).catch(err => {
|
||||
reject(err)
|
||||
})
|
||||
},
|
||||
fail : err => {
|
||||
uni.closeAuthView()
|
||||
switch(err.code){
|
||||
case 30002:
|
||||
router.push({name: "Login"})
|
||||
break
|
||||
case 30008:
|
||||
this.wechatAuth()
|
||||
break
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 微信登录
|
||||
*/
|
||||
wechatAuth(){
|
||||
uni.showToast({
|
||||
title: '微信登录',
|
||||
icon : 'none'
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理登录状态维护
|
||||
*/
|
||||
updAuthToken(){
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
export default userAuth
|
||||
Reference in New Issue
Block a user