You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
409 lines
11 KiB
409 lines
11 KiB
<template>
|
|
<view class="container">
|
|
<image class="bkg" src="~@/static/login/bkg.png" mode="aspectFill"></image>
|
|
<view class="icon">
|
|
<image src="~@/static/logo.png" mode="aspectFit"></image>
|
|
</view>
|
|
<view class="title">
|
|
<image class="title1" v-if="!isSmsLogin" src="~@/static/login/title.png" mode="aspectFit"></image>
|
|
<image class="title2" v-else src="~@/static/login/title2.png" mode="aspectFit"></image>
|
|
</view>
|
|
|
|
<view class="btns" v-if="!isSmsLogin">
|
|
<u-button
|
|
shape="circle"
|
|
:hair-line="false"
|
|
ripple
|
|
open-type="getPhoneNumber"
|
|
:custom-style="{...btnStyle,'color': '#fff','background':'#e47829'}"
|
|
@getphonenumber="authLogin">一键登录</u-button>
|
|
<u-button
|
|
shape="circle"
|
|
:hair-line="false"
|
|
ripple
|
|
:custom-style="{...btnStyle,'color':'#e47829','margin-top':'2.6vh'}"
|
|
@click="isSmsLogin = true">短信验证</u-button>
|
|
<u-button
|
|
shape="circle"
|
|
:hair-line="false"
|
|
ripple
|
|
:custom-style="{...btnStyle,'color':'#e47829','margin-top':'2.6vh'}"
|
|
@click="$u.route({
|
|
url: 'pages/index/index',
|
|
type: 'tab'
|
|
})">游客模式</u-button>
|
|
</view>
|
|
<view class="login-panel" v-if="isSmsLogin">
|
|
<u-form :model="form" ref="uForm" :border-bottom="false">
|
|
<u-form-item :border-bottom="false">
|
|
<view style="position:relative;">
|
|
<view class="login-panel__mobile input-wrap">
|
|
<u-input v-model="form.mobile" :height="40" :clearable="false" placeholder="请输入手机号..."></u-input>
|
|
</view>
|
|
<view class="input-wrap__text">手机号</view>
|
|
</view>
|
|
</u-form-item>
|
|
<u-form-item :border-bottom="false">
|
|
<view style="position:relative;margin-top: 4.6vh;">
|
|
<view class="login-panel__code input-wrap">
|
|
<u-input
|
|
style="flex: 1;"
|
|
v-model="form.code"
|
|
:height="40"
|
|
:clearable="false"
|
|
placeholder="请输入验证码..."
|
|
:custom-style="{
|
|
}"></u-input>
|
|
<u-button
|
|
ripple
|
|
:hair-line="false"
|
|
:custom-style="{
|
|
'background': 'linear-gradient(-29deg, #e77817 0%, #fc9d4a 99%, #fc9d4a 100%)',
|
|
'color': '#f6f6f6',
|
|
'float': 'right',
|
|
'border-radius': '0 25rpx 25rpx 0',
|
|
'height': '100rpx',
|
|
'line-height': '100rpx',
|
|
'padding': '0 28rpx',
|
|
'font-size': '24rpx'
|
|
}"
|
|
@click="getCode">{{ tips }}</u-button>
|
|
<u-verification-code
|
|
keep-running
|
|
ref="uCode"
|
|
@change="text => tips = text"></u-verification-code>
|
|
</view>
|
|
<view class="input-wrap__text">验证码</view>
|
|
</view>
|
|
</u-form-item>
|
|
</u-form>
|
|
<u-button
|
|
shape="circle"
|
|
ripple
|
|
:custom-style="{
|
|
'background': 'linear-gradient(-29deg, #e77817 0%, #fc9d4a 99%, #fc9d4a 100%)',
|
|
'color': '#fff',
|
|
'font-size': '34rpx',
|
|
'height': '77rpx',
|
|
'line-height': '77rpx',
|
|
'width': '450rpx',
|
|
'margin': '6.8vh auto 0',
|
|
'letter-spacing': '2rpx',
|
|
'font-weight': '500'
|
|
}"
|
|
@click="mobileLogin">登录</u-button>
|
|
<view class="back" @click.stop="isSmsLogin = false">
|
|
<u-icon name="arrow-leftward"></u-icon>
|
|
</view>
|
|
</view>
|
|
<view class="auth safe-area-inset-bottom">
|
|
<u-checkbox v-model="isAuth" shape="circle" active-color="#e47829">
|
|
<text style="padding-left: 18rpx;">我已阅读并同意</text>
|
|
<text style="color: #e47829;" @click.stop.prevent="openPrivacyContract">《用户协议》</text>
|
|
<text>和</text>
|
|
<text style="color: #e47829;" @click.stop.prevent="openPrivacyContract">《隐私协议》</text>
|
|
</u-checkbox>
|
|
</view>
|
|
|
|
<image class="book" src="/static/login/book.png" mode="aspectFit"></image>
|
|
<u-toast ref="uToast" />
|
|
</view>
|
|
</template>
|
|
|
|
<script>
|
|
export default {
|
|
data() {
|
|
return {
|
|
tips: '',
|
|
isSmsLogin: false,
|
|
isAuth: false,
|
|
btnStyle: {
|
|
width: '450rpx',
|
|
height: '76rpx',
|
|
'line-height': '76rpx',
|
|
'padding': '0',
|
|
'letter-spacing': '3rpx',
|
|
'border-color': '#e47829',
|
|
'border-width': '1rpx',
|
|
'border-style': 'solid'
|
|
},
|
|
form: {
|
|
mobile: '',
|
|
code: ''
|
|
},
|
|
rules: {
|
|
mobile: [
|
|
{
|
|
required: true,
|
|
message: '请填写手机号',
|
|
trigger: ['change','blur']
|
|
}
|
|
],
|
|
code: [
|
|
{
|
|
required: true,
|
|
message: '请填写验证码',
|
|
trigger: ['change','blur']
|
|
}
|
|
]
|
|
}
|
|
};
|
|
},
|
|
methods: {
|
|
async mobileLogin() {
|
|
if (!this.form.code) {
|
|
this.$refs.uToast.show({
|
|
title: '请先填写验证码',
|
|
type: 'warning',
|
|
duration: '2000'
|
|
})
|
|
return
|
|
}
|
|
if (!this.isAuth) {
|
|
this.$refs.uToast.show({
|
|
title: '请先阅读协议',
|
|
type: 'warning',
|
|
duration: '2000'
|
|
})
|
|
return
|
|
}
|
|
try {
|
|
const res = await this.$u.api.bindMobile(this.form)
|
|
this.$u.vuex('vuex_user', res)
|
|
this.$u.route({
|
|
type: 'switchTab',
|
|
url: '/pages/index/index'
|
|
})
|
|
} catch (err) {
|
|
console.error(err)
|
|
}
|
|
},
|
|
async getCode() {
|
|
if (!this.form.mobile) {
|
|
this.$refs.uToast.show({
|
|
title: '请先填写手机号',
|
|
type: 'warning',
|
|
duration: '2000'
|
|
})
|
|
return
|
|
}
|
|
if(this.$refs.uCode.canGetCode) {
|
|
// 模拟向后端请求验证码
|
|
try {
|
|
uni.showLoading({
|
|
title: '正在获取验证码'
|
|
})
|
|
const res = await this.$u.api.sendSms({
|
|
mobile: this.form.mobile
|
|
})
|
|
uni.hideLoading();
|
|
// 这里此提示会被this.start()方法中的提示覆盖
|
|
this.$u.toast('验证码已发送');
|
|
// 通知验证码组件内部开始倒计时
|
|
this.$refs.uCode.start();
|
|
} catch (err) {
|
|
console.error(err)
|
|
} finally {
|
|
uni.hideLoading();
|
|
}
|
|
} else {
|
|
this.$u.toast('倒计时结束后再发送');
|
|
}
|
|
},
|
|
async authLogin(e) {
|
|
if (!this.isAuth) {
|
|
this.$refs.uToast.show({
|
|
title: '请先阅读协议',
|
|
type: 'warning',
|
|
duration: '2000'
|
|
})
|
|
return
|
|
}
|
|
if (this.vuex_user.mobile) {
|
|
this.$u.route({
|
|
type: 'switchTab',
|
|
url: '/pages/index/index'
|
|
})
|
|
}
|
|
try {
|
|
if (e.detail.code) {
|
|
const res = await this.$u.api.mobile({
|
|
code: e.detail.code
|
|
})
|
|
if (res.mobile) {
|
|
await this.$u.api.updateUser({
|
|
mobile: res.mobile
|
|
})
|
|
const { user } = await this.$u.api.getUserInfo()
|
|
this.$u.vuex('vuex_user', user)
|
|
this.$u.route({
|
|
type: 'switchTab',
|
|
url: '/pages/index/index'
|
|
})
|
|
}
|
|
}
|
|
} catch (err) {
|
|
console.error(err)
|
|
}
|
|
},
|
|
openPrivacyContract() {
|
|
wx.openPrivacyContract({
|
|
success: () => {
|
|
},
|
|
fail: () => {
|
|
uni.showToast({
|
|
title: '遇到错误',
|
|
icon: 'error',
|
|
});
|
|
},
|
|
});
|
|
},
|
|
},
|
|
onShow() {
|
|
if (!this.vuex_token) {
|
|
uni.login({
|
|
provider: 'weixin', //使用微信登录
|
|
success: async (loginRes) => {
|
|
try {
|
|
const {token} = await this.$u.api.appletLogin({
|
|
code: loginRes.code
|
|
})
|
|
this.$u.vuex('vuex_token', token)
|
|
const { user } = await this.$u.api.getUserInfo()
|
|
this.$u.vuex('vuex_user', user)
|
|
} catch (err) {
|
|
console.error(err)
|
|
}
|
|
},
|
|
fail:err => {
|
|
console.log(err)
|
|
}
|
|
});
|
|
}
|
|
},
|
|
}
|
|
</script>
|
|
|
|
<style lang="scss" scoped>
|
|
::v-deep .u-form-item {
|
|
padding: 0 !important;
|
|
}
|
|
.container {
|
|
width: 100vw;
|
|
min-height: 100vh;
|
|
position: relative;
|
|
|
|
.bkg {
|
|
position: fixed;
|
|
height: 100vh;
|
|
width: 100vw;
|
|
top: 0;
|
|
left: 0;
|
|
}
|
|
.icon {
|
|
display: flex;
|
|
justify-content: center;
|
|
position: relative;
|
|
z-index: 2;
|
|
padding-top: 14.5vh;
|
|
|
|
image {
|
|
width: 172rpx;
|
|
height: 172rpx;
|
|
}
|
|
}
|
|
.title {
|
|
display: flex;
|
|
justify-content: center;
|
|
position: relative;
|
|
z-index: 2;
|
|
margin-top: 3.8vh;
|
|
|
|
.title1 {
|
|
width: 432rpx;
|
|
height: 110rpx;
|
|
}
|
|
.title2 {
|
|
width: 223rpx;
|
|
height: 49rpx;
|
|
}
|
|
}
|
|
.btns {
|
|
position: relative;
|
|
z-index: 2;
|
|
margin-top: 9vh;
|
|
}
|
|
.login-panel {
|
|
position: relative;
|
|
z-index: 2;
|
|
margin-top: 6.2vh;
|
|
|
|
.input-wrap {
|
|
width: 590rpx;
|
|
padding: 30rpx 46rpx;
|
|
border: 1rpx solid #999;
|
|
border-radius: 25rpx;
|
|
position: relative;
|
|
margin: 0 auto;
|
|
clip-path: polygon(0 0, 52rpx 0,52rpx 20rpx, 149rpx 20rpx, 149rpx 0, 100% 0, 100% 100%, 0 100%);
|
|
|
|
&__text {
|
|
position: absolute;
|
|
color: #999;
|
|
background: transparent;
|
|
left: calc((100vw - 590rpx) / 2 + 52rpx);
|
|
top: -20rpx;
|
|
font-size: 26rpx;
|
|
letter-spacing: 1px;
|
|
line-height: 40rpx;
|
|
padding: 0 10rpx;
|
|
}
|
|
}
|
|
&__mobile {
|
|
//&::after {
|
|
// content: "手机号";
|
|
//}
|
|
}
|
|
&__code {
|
|
//&::after {
|
|
// content: "验证码";
|
|
//}
|
|
display: flex;
|
|
align-items: center;
|
|
padding: 0 0 0 46rpx !important;
|
|
}
|
|
|
|
.back {
|
|
color: #666;
|
|
text-align: center;
|
|
margin: 3vh auto 0;
|
|
display: flex;
|
|
justify-content: center;
|
|
width: 70rpx;
|
|
height: 70rpx;
|
|
border-radius: 100%;
|
|
border: 2rpx solid #666;
|
|
}
|
|
}
|
|
.book {
|
|
z-index: 1;
|
|
position: absolute;
|
|
width: 460rpx;
|
|
height: 148rpx;
|
|
bottom: 17vh;
|
|
left: calc(50% - 230rpx);
|
|
}
|
|
.auth {
|
|
font-size: 22rpx;
|
|
color: #999;
|
|
font-weight: 500;
|
|
position: absolute;
|
|
z-index: 3;
|
|
width: 100vw;
|
|
display: flex;
|
|
justify-content: center;
|
|
bottom: 2.7vh;
|
|
}
|
|
}
|
|
</style>
|