Commit eab5fcef by 张立顺

恢复错误删除文件

1 parent e1840589
import { checkLoginUserInfo, setRouteData, setLoginInfo, loginModal } from '../lib/index'
import { getSessionId } from '~/utils/cache/storageApi'
import USERAPI from '~/api/usersApi/index'
import { IMG_URL } from '~/utils/constantData'
Page({
/**
* 页面的初始数据
*/
data: {
IMG_URL
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
const appEnter = wx.getEnterOptionsSync()
if (appEnter.scene == 1037) {
if (Object.keys(appEnter.referrerInfo).length) {
const { extraData } = appEnter.referrerInfo
if (extraData && Object.keys(extraData).length) this.phoneSmsLogin(extraData)
else this.init()
} else this.init()
} else this.init()
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {},
init() {
wx.nextTick(() => {
const sessionId = getSessionId(),
{ url, targetPath = url ? decodeURIComponent(url) : '' } = this.options
let path = 'pages.index',
obj = {}
if (targetPath) obj.targetPath = targetPath
if (sessionId) {
USERAPI.checkSession().then(({ code }) => {
if (code == '0') {
if (targetPath) {
path = setRouteData(targetPath).url
obj = setRouteData(targetPath).obj
}
wx.$router.reLaunch(path, obj)
} else this.autoLogin(obj)
})
} else this.autoLogin(obj)
})
},
autoLogin(obj) {
const autoLoginObject = wx.$storage.get('auto_login_object')
if (autoLoginObject) {
const { failureTime, userName, password } = autoLoginObject
if (Date.now() < failureTime) {
USERAPI.accountLogin({
userName,
password
}).then(async ({ data, code, message }) => {
if (code == '0' && data.loginUserInfoList.length) {
const { sessionId, loginUserInfoList } = data
setLoginInfo(loginUserInfoList[0], sessionId)
} else {
try {
const reload = await loginModal({
message: data.loginUserInfoList.length ? message : '登录失败请重试',
cancelText: '返回'
})
if (reload) this.onShow()
} catch (error) {
wx.$storage.rm('auto_login_object')
wx.$router.reLaunch('login.index', obj)
}
}
})
} else wx.$router.reLaunch('login.index', obj)
} else wx.$router.reLaunch('login.index', obj)
},
phoneSmsLogin(extraData) {
console.log(extraData)
USERAPI.phoneSmsLogin({
mobile: extraData.phone,
code: extraData.smscode
})
.then(({ code, data, message }) => {
if (code == '0') checkLoginUserInfo(data)
else {
wx.$api.showToast(message || '系统异常')
setTimeout(() => {
wx.$router.reLaunch('login.index')
}, 1e3)
}
})
.catch(err => {
wx.$api.showToast('系统异常')
setTimeout(() => {
wx.$router.reLaunch('login.index')
}, 1e3)
})
}
})
.layout {
width: 100vw;
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
background-color: #fff;
.loading {
height: 48rpx;
view {
width: 16rpx;
height: 100%;
display: inline-block;
background-color: #0052d9;
animation: stretchdelay 1.2s infinite ease-in-out;
margin: 0 4rpx;
&:nth-child(2) {
animation-delay: -1.1s;
}
&:nth-child(3) {
animation-delay: -1s;
}
&:nth-child(4) {
animation-delay: -.9s;
}
}
}
}
@keyframes stretchdelay {
0%,
100%,
40% {
transform: scaley(.33);
}
20% {
transform: scaley(1);
}
}
\ No newline at end of file
<view class="layout">
<image webp src="{{IMG_URL}}login/index-loading.webp" mode="widthFix" ></image>
<!-- <view class="loading">
<block wx:for="{{4}}" wx:key="index">
<view></view>
</block>
</view> -->
</view>
\ No newline at end of file
// pages/wxLogin/wxLogin.js
import api from '../../api/api.js'
Page({
/**
* 页面的初始数据
*/
data: {
password: '',
userName: '',
count: 60,
verificationCount: '',
loginType: true
},
onRoute(loginToken) {
this.setData({
loginToken
})
},
changeLoginType() {
this.setData({
loginType: !this.data.loginType
})
},
input(e) {
let { value } = e.detail
let { name } = e.currentTarget.dataset
if (wx.$util.haveEmoji(value)) value = wx.$util.replaceEmoji(value)
this.setData({
[name]: value
})
this.check()
},
check() {
let arr = [this.data.mobile, this.data.code]
this.setData({
flag: arr.findIndex(e => !e) == -1
})
},
clear(e) {
let target = e.currentTarget.dataset.name
this.setData({
[target]: ''
})
this.check()
},
getSms() {
const phoneRex = /^[1]([3-9])[0-9]{9}$/
let { mobile } = this.data
if (!mobile) {
wx.$util.showToast('请输入手机号')
return
}
if (!phoneRex.test(mobile)) {
wx.$util.showToast('请输入正确的手机号')
return
}
api
.getSMS({
mobile
})
.then(({ code, message }) => {
if (code == '0') {
wx.$util.showToast('验证码发送成功')
this.setData({
verificationFlag: true,
verificationCount: Math.round(new Date() / 1000) + 60,
countDown: true
})
this.playCountDown()
} else {
wx.$util.showToast(message)
}
})
},
smsLogin() {
let { flag, code, mobile } = this.data
if (!flag) return
wx.$util.showLoading()
api
.smsLogin({
code,
mobile
})
.then(result => {
wx.$util.showLoading()
if (result.code == 0) {
let { loginUserInfoList, sessionId } = result.data
if (loginUserInfoList.length > 0) {
wx.$util.setSessionId(sessionId)
wx.$router.reLaunch('pages.accountItems')
} else {
wx.$router.reLaunch('pages.nothing')
}
} else {
wx.hideLoading()
wx.showModal({
title: '温馨提示',
content: result.message,
showCancel: false,
confirmText: '知道了',
confirmColor: '#3582EE'
})
}
})
},
playCountDown() {
let { count, verificationCount } = this.data
this.countDownTime = setInterval(() => {
let nowTime = Math.round(new Date() / 1000)
if (nowTime == verificationCount) {
clearInterval(this.countDownTime)
this.setData({
count: 60,
countDown: false,
verificationFlag: false
})
return
}
this.setData({
count: --count
})
}, 1 * 1000)
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {},
/**
* 获取授权手机号
*/
getPhoneNumber(e) {
console.log(e)
let { loginToken } = this.data
let { encryptedData, iv } = e.detail
if (!encryptedData) return
wx.$util.showLoading('加载中...')
api
.authPhone({
encryptedData,
loginToken,
iv
})
.then(({ code, data, message }) => {
wx.hideLoading()
if (code == 0) {
let { loginUserInfoList, sessionId } = data
if (loginUserInfoList.length) {
wx.$util.setSessionId(sessionId)
wx.$router.reLaunch('pages.accountItems')
} else {
wx.$router.reLaunch('pages.nothing')
}
} else {
wx.hideLoading()
wx.showModal({
title: '温馨提示',
content: message,
showCancel: false,
confirmText: '知道了',
confirmColor: '#3582EE'
})
}
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
wx.hideHomeButton()
this.login()
},
login() {
wx.$util.showLoading()
let _this = this
wx.login({
success({ code }) {
if (code) {
api
.wxLogin({
code,
appId: wx.getAccountInfoSync().miniProgram.appId
})
.then(res => {
console.log(res)
wx.$util.hideLoading()
if (res.code == '0') {
_this.setData({
loginToken: res.data
})
}
})
} else {
wx.$util.showToast('登录失败')
}
}
})
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {}
})
{
"usingComponents": {},
"navigationStyle": "custom",
"disableScroll": true
"usingComponents": {}
}
\ No newline at end of file
<view class='layout'>
<block wx:if="{{!loginType}}">
<view class='login-form'>
<view class='input'>
<input placeholder="请输入手机号" type="number" placeholder-style="color:#999;" style="width:calc(100% - 50rpx);" bindinput="input" data-name='mobile' value="{{mobile}}" maxlength="11"></input>
<view class='clear y-center' hidden="{{!mobile}}" bindtap="clear" data-name='mobile'>
<image src="/images/clear.png"></image>
</view>
</view>
<view class="sms-box">
<view class='input'>
<input placeholder="请输入验证码" type="number" placeholder-style="color:#999;" style="width:calc(100% - 100rpx);" bindinput="input" data-name='code' value='{{code}}' maxlength="4"></input>
<view class='clear y-center' style="right:50rpx;" hidden="{{!code}}" bindtap="clear" data-name='code'>
<image src="/images/clear.png"></image>
</view>
</view>
<view class="sms {{countDown?'code-disabled':''}}" bindtap="getSms">
<block wx:if="{{countDown}}">
{{count}}秒后获取
</block>
<block wx:else>
获取验证码
</block>
</view>
</view>
</view>
</block>
<view class='box' >
<!-- <view class='box' style="top:{{loginType?'-264rpx':'0'}}"> -->
<view class="login-btn {{loginType?'mini':''}}">
<button size="default" hidden="{{!loginType}}" open-type="getPhoneNumber" bindgetphonenumber="getPhoneNumber"></button>
<view hidden="{{!loginType}}">微信登录</view>
<view hidden="{{loginType}}" bindtap="smsLogin">登录</view>
</view>
<view class='tips' bindtap="changeLoginType">{{loginType?"手机号登录":"切换为微信登录"}}</view>
</view>
</view>
\ No newline at end of file
/* pages/login/login/login.wxss */
page{
background: #fff;
}
.layout{
padding-top: 160rpx;
}
.box {
height: 264rpx;
position: relative;
z-index: 9;
/* top: -264rpx; */
background: #fff;
transition: all 0.5s;
}
.login-form {
padding: 0 40rpx;
}
.login-form .input {
height: 40rpx;
line-height: 40rpx;
width: 100%;
position: relative;
margin-bottom: 92rpx;
font-size: 28rpx;
box-sizing: border-box;
padding-left: 66rpx;
color: #333;
}
.login-form .sms-box{
display: flex;
align-items: center;
margin-bottom: 92rpx;
}
.login-form .sms-box .input{
width: 70%;
margin-bottom: 0;
}
.login-form .sms-box .sms{
width: 30%;
font-size: 24rpx;
color: #3582EE;
}
.login-form .input::after {
content: '';
position: absolute;
left: 0;
bottom: -26rpx;
width: 100%;
height: 2rpx;
background: #eee;
}
.login-form .input .icon {
width: 36rpx;
height: 36rpx;
position: absolute;
left: 0;
}
.clear {
position: absolute;
right: 0;
width: 36rpx;
height: 36rpx;
}
.login-form .input .icon-eye {
width: 36rpx;
height: 36rpx;
position: absolute;
right: 0;
}
.input .clear {
position: absolute;
right: 0;
}
.login-btn {
background-color: #3582EE;
border-radius: 40rpx;
text-align: center;
font-size: 32rpx;
color: #fff;
letter-spacing: 13.72rpx;
height: 80rpx;
line-height: 80rpx;
width: 670rpx;
margin: 0 auto;
font-weight: normal;
transition: all .5s;
position: relative;
}
.box button{
opacity: 0;
position: absolute;
top: 0;
left: 0;
padding: 0;
width: 100% !important;
height: 100%;
box-sizing: border-box;
}
.mini{
width: 368rpx;
}
.tips {
font-size: 24rpx;
color: #3582EE;
letter-spacing: 1.72rpx;
margin-top: 76rpx;
text-align: center;
}
.tip {
position: fixed;
left: 0;
bottom: 40rpx;
width: 100%;
font-size: 24rpx;
color: #999;
letter-spacing: 2rpx;
text-align: center;
}
.code-disabled {
color: #999 !important;
}
\ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!