This commit is contained in:
唐明明
2022-06-07 16:37:03 +08:00
parent b1e8d774ff
commit 1c6091371e
1706 changed files with 225309 additions and 1 deletions

31
public/date.js Normal file
View File

@@ -0,0 +1,31 @@
/**
* Web唐明明
* 匆匆数载恍如梦,岁月迢迢华发增。
* 碌碌无为枉半生,一朝惊醒万事空。
* moduleName: 日期
*/
export default getDate = (type) =>{
return new Promise((resolve, reject) => {
const date = new Date()
const year = date.getFullYear()
const month = (date.getMonth() + 1) <= 9 ? '0' + (date.getMonth() + 1) : (date.getMonth() + 1)
const day = date.getDate()
switch(type){
case 'day':
resolve(year + '-' + month + '-' + day)
break
case 'month':
resolve(year + '-' + month)
break
case 'year':
resolve(year)
break
default:
resolve(year + '-' + month + '-' + day)
}
})
}

133
public/userAuth.js Normal file
View File

@@ -0,0 +1,133 @@
/**
* 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': '#34CE98',
'highlightColor': '#16b17a',
'disabledColor': '#aae4cc',
},
otherLoginButton: {
'title': '其他手机号码',
'borderColor': '#34CE98',
'textColor': '#34CE98'
},
privacyTerms: {
'checkedImage': '/static/icon/checked-icon.png',
'uncheckedImage': '/static/icon/unchecked-icon.png',
'textColor': '#999',
'termsColor': '#34CE98',
'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() {
//#ifdef H5
router.push({
name: 'Auth'
})
return
//#endif
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: 'Auth'
})
},
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)
// 在这里登录成功链接IM服务
getImToken().then(res => {
im.connect(res.token, res.userInfo, () => {})
})
resolve()
}).catch(err => {
reject(err)
})
},
fail: err => {
uni.closeAuthView()
switch (err.code) {
case 30002:
router.push({
name: 'Auth',
params: {
keyPhone: 1
}
})
break
}
}
})
})
}
}
export default userAuth