445 lines
11 KiB
Vue
445 lines
11 KiB
Vue
<template>
|
|
<!-- 空登陆页 -->
|
|
<s-layout navbar="inner" title="登录" navPreset="float">
|
|
<view class="login">
|
|
<view class="login_top_img w100" :style="{ top: -height + 'px' }">
|
|
<image src="@/static/index/login_bg.png" mode="widthFix" class="w100" />
|
|
</view>
|
|
<view class="login_con w100 flex-column ju-between">
|
|
<view class="login_top">
|
|
<view class="font-Heavy size52 c1">Hello!</view>
|
|
<view class="font-Heavy size52 c1">欢迎使用优购商城</view>
|
|
</view>
|
|
<view class=" bottomCon">
|
|
<view class="login_bottom">
|
|
<view class="size40 f500 title">{{ dataObj.con[type].title }}</view>
|
|
<view class="form">
|
|
<uni-forms ref="form" label-position="top">
|
|
<view v-for="(v, i) in dataObj.con[type].arr" :key="i">
|
|
<uni-forms-item
|
|
:required="false"
|
|
:label="dataObj.formArr[v].title"
|
|
:name="dataObj.formArr[v].value"
|
|
>
|
|
<view class="flex-center border_bottom">
|
|
<image class="input-icon" :src="inputIconMap[v]" mode="aspectFit" />
|
|
<uni-easyinput
|
|
v-model="formData[dataObj.formArr[v].value]"
|
|
:placeholder="dataObj.formArr[v].placeholder"
|
|
:type="dataObj.formArr[v].type"
|
|
:inputBorder="false"
|
|
:maxlength="dataObj.formArr[v].max"
|
|
/>
|
|
<view v-if="v == 2" class="c_code size28" @click="getCode">{{
|
|
num > 0 && num < 60 ? num + 's后重新获取' : '获取验证码'
|
|
}}</view>
|
|
</view>
|
|
</uni-forms-item>
|
|
</view>
|
|
</uni-forms>
|
|
</view>
|
|
<view class="flex-row ju-between size28 btns">
|
|
<view class="flex-row">
|
|
<view class="">{{ dataObj.con[type].text }}</view>
|
|
<view
|
|
class="c_switch"
|
|
@click="typeChange(dataObj.btns[dataObj.con[type].btn1].value)"
|
|
>{{ dataObj.btns[dataObj.con[type].btn1].text }}</view
|
|
>
|
|
</view>
|
|
<view
|
|
class="c_switch"
|
|
@click="typeChange(dataObj.btns[dataObj.con[type].btn2].value)"
|
|
v-if="dataObj.con[type].btn2"
|
|
>{{ dataObj.btns[dataObj.con[type].btn2]?.text }}</view
|
|
>
|
|
</view>
|
|
<view class="submit-btn" @click="$debounce(sub, 1000)">
|
|
{{ dataObj.con[type].sub }}
|
|
</view>
|
|
</view>
|
|
|
|
<view class="radio-box">
|
|
<radio-group @change="radioChange">
|
|
<label class="flex-center">
|
|
<radio color="#C02F3B" class="radio" value="1" :checked="false" />
|
|
<view class="flex-center size24">
|
|
我已阅读并同意
|
|
<text class="c_agreement" @click="go(2)">《用户服务协议》</text>
|
|
和
|
|
<text class="c_agreement" @click="go(1)">《隐私政策》</text>
|
|
</view>
|
|
</label>
|
|
</radio-group>
|
|
</view>
|
|
</view>
|
|
</view>
|
|
</view>
|
|
</s-layout>
|
|
</template>
|
|
|
|
<script setup>
|
|
import { ref, reactive } from 'vue';
|
|
import sheep from '@/sheep';
|
|
import { onLoad } from '@dcloudio/uni-app';
|
|
import AuthUtil from '@/sheep/api/member/auth';
|
|
let type = ref(2);
|
|
let formData = reactive({});
|
|
let num = ref(0);
|
|
const inputIconMap = {
|
|
1: '/static/icon/icon1.png',
|
|
2: '/static/icon/icon2.png',
|
|
3: '/static/icon/icon3.png',
|
|
4: '/static/icon/icon3.png',
|
|
5: '/static/icon/icon4.png',
|
|
};
|
|
let dataObj = reactive({
|
|
con: {
|
|
1: {
|
|
title: '验证码登录',
|
|
arr: [1, 2],
|
|
text: '还没账号?',
|
|
btn1: 1,
|
|
btn2: 2,
|
|
sub: '立即登录',
|
|
toast: '登录成功',
|
|
},
|
|
2: {
|
|
title: '密码登录',
|
|
arr: [1, 3],
|
|
text: '还没账号?',
|
|
btn1: 1,
|
|
btn2: 3,
|
|
sub: '立即登录',
|
|
toast: '登录成功',
|
|
},
|
|
3: {
|
|
title: '用户注册',
|
|
arr: [1, 4, 5],
|
|
// arr: [1, 2, 4, 5],
|
|
text: '已有账号,',
|
|
btn1: 4,
|
|
btn2: 3,
|
|
sub: '立即注册',
|
|
toast: '注册成功',
|
|
},
|
|
4: {
|
|
title: '忘记密码',
|
|
arr: [1, 2, 4, 5],
|
|
text: '已有账号,',
|
|
btn1: 4,
|
|
btn2: 2,
|
|
sub: '修改密码',
|
|
toast: '修改成功',
|
|
},
|
|
},
|
|
formArr: {
|
|
1: {
|
|
title: '手机号',
|
|
type: 'number',
|
|
value: 'mobile',
|
|
max: 11,
|
|
placeholder: '请输入手机号',
|
|
},
|
|
2: {
|
|
title: '验证码',
|
|
type: 'number',
|
|
value: 'code',
|
|
max: 4,
|
|
placeholder: '请输入验证码',
|
|
},
|
|
3: {
|
|
title: '密码',
|
|
type: 'password',
|
|
value: 'password',
|
|
placeholder: '请输入密码',
|
|
},
|
|
4: {
|
|
title: '设置密码',
|
|
type: 'password',
|
|
value: 'password',
|
|
placeholder: '请输入您的密码',
|
|
},
|
|
5: {
|
|
title: '确认密码',
|
|
type: 'password',
|
|
value: 'confirmPassword',
|
|
placeholder: '请再次输入您的密码',
|
|
},
|
|
},
|
|
btns: {
|
|
1: {
|
|
text: '去注册',
|
|
value: 3,
|
|
},
|
|
2: {
|
|
text: '密码登录',
|
|
value: 2,
|
|
},
|
|
3: {
|
|
text: '验证码登录',
|
|
value: 1,
|
|
},
|
|
4: {
|
|
text: '去登录',
|
|
value: 2,
|
|
},
|
|
},
|
|
});
|
|
const rules = reactive({
|
|
mobile: [
|
|
{
|
|
required: true,
|
|
message: '请输入手机号',
|
|
trigger: 'blur',
|
|
},
|
|
{
|
|
pattern: /^1[3456789]\d{8}$/,
|
|
message: '手机号格式不正确',
|
|
trigger: 'blur',
|
|
},
|
|
],
|
|
code: [
|
|
{
|
|
required: true,
|
|
message: '请输入验证码',
|
|
trigger: 'blur',
|
|
},
|
|
],
|
|
password: [
|
|
{
|
|
required: true,
|
|
message: '请输入密码',
|
|
trigger: 'blur',
|
|
},
|
|
],
|
|
});
|
|
|
|
const typeChange = (val) => {
|
|
console.log(val);
|
|
type.value = val;
|
|
clearInterval(timer.value);
|
|
num.value = 0;
|
|
};
|
|
const radioValue = ref();
|
|
const radioChange = (e) => {
|
|
radioValue.value = e.detail.value;
|
|
};
|
|
const sub = async () => {
|
|
if (!radioValue.value) {
|
|
uni.showToast({
|
|
title: '请阅读服务协议和隐私协议',
|
|
duration: 1000,
|
|
icon: 'none',
|
|
});
|
|
return;
|
|
}
|
|
let arr = dataObj.con[type.value].arr;
|
|
let obj = {};
|
|
for (let i = 0; i < arr.length; i++) {
|
|
if (!formData[dataObj.formArr[arr[i]].value]) {
|
|
uni.showToast({
|
|
title: dataObj.formArr[arr[i]].placeholder,
|
|
icon: 'none',
|
|
});
|
|
return;
|
|
}
|
|
obj[dataObj.formArr[arr[i]].value] = formData[dataObj.formArr[arr[i]].value];
|
|
}
|
|
let url = '';
|
|
switch (type.value) {
|
|
case 1: //密码登录
|
|
url = AuthUtil.smsLogin;
|
|
break;
|
|
case 2: //验证码登录
|
|
url = AuthUtil.login;
|
|
break;
|
|
case 3: //注册
|
|
if (obj.password != obj.confirmPassword) {
|
|
uni.showToast({
|
|
title: '两次密码不一致',
|
|
icon: 'none',
|
|
});
|
|
return;
|
|
}
|
|
url = AuthUtil.register;
|
|
break;
|
|
case 4: //忘记密码
|
|
break;
|
|
}
|
|
url(obj).then((res) => {
|
|
if (res.code === 0) {
|
|
if (type.value == 3) {
|
|
typeChange(2);
|
|
return;
|
|
}
|
|
sheep.$store('user').getInfo();
|
|
setTimeout(() => {
|
|
uni.reLaunch({ url: '/pages/index/index' });
|
|
}, 1000);
|
|
}
|
|
});
|
|
};
|
|
let timer = ref();
|
|
const getCode = () => {
|
|
if (num.value > 0 && num.value < 60) {
|
|
return;
|
|
}
|
|
if (!radioValue.value) {
|
|
uni.showToast({
|
|
title: '请阅读服务协议和隐私协议',
|
|
duration: 1000,
|
|
icon: 'none',
|
|
});
|
|
return;
|
|
}
|
|
// 发送验证码
|
|
if (!formData.mobile) {
|
|
uni.showToast({
|
|
title: '请输入手机号',
|
|
icon: 'none',
|
|
});
|
|
return;
|
|
} else {
|
|
sendCode();
|
|
}
|
|
};
|
|
const sendCode = async () => {
|
|
let numType = 1;
|
|
switch (type.value) {
|
|
case 1: //验证码登录1
|
|
numType = 1;
|
|
break;
|
|
case 2: //密码登录1
|
|
numType = 1;
|
|
break;
|
|
case 3: //注册6
|
|
numType = 6;
|
|
break;
|
|
case 4: //忘记密码4
|
|
numType = 4;
|
|
break;
|
|
}
|
|
AuthUtil.sendSmsCode({ mobile: formData.mobile, scene: numType }).then((res) => {
|
|
if (res.code === 0) {
|
|
num.value = 60;
|
|
timer.value = setInterval(() => {
|
|
num.value--;
|
|
if (num.value <= 0) {
|
|
clearInterval(timer.value);
|
|
num.value = 60;
|
|
}
|
|
}, 1000);
|
|
}
|
|
});
|
|
};
|
|
const go = (type) => {
|
|
uni.navigateTo({ url: '/pages/home/agreement?type=' + type });
|
|
};
|
|
onLoad(async () => {});
|
|
let sysInfo = uni.getSystemInfoSync();
|
|
const windowHeight = sysInfo.windowHeight;
|
|
let height = ref(0);
|
|
height.value = sysInfo.statusBarHeight + uni.upx2px(88);
|
|
</script>
|
|
<style lang="scss" scoped>
|
|
.login {
|
|
position: relative;
|
|
min-height: 100vh;
|
|
.login_top_img {
|
|
position: absolute;
|
|
z-index: 1;
|
|
}
|
|
.login_con {
|
|
position: relative;
|
|
height: 100vh;
|
|
padding-top: 50rpx;
|
|
box-sizing: border-box;
|
|
z-index: 1;
|
|
// position: absolute;
|
|
// top: 166rpx;
|
|
// left: 0;
|
|
// z-index: 2;
|
|
// background-color: #F2F4F7;
|
|
}
|
|
}
|
|
.login_top {
|
|
padding-left: 50rpx;
|
|
margin-bottom: 48rpx;
|
|
}
|
|
.bottomCon {
|
|
width: 90%;
|
|
margin: 0 auto;
|
|
background-color: #ffffff;
|
|
border-radius: 40rpx;
|
|
position: absolute;
|
|
top:220rpx;
|
|
left: 5%;
|
|
box-sizing: border-box;
|
|
overflow: hidden;
|
|
padding: 0 0 20rpx;
|
|
}
|
|
.login_bottom {
|
|
// background: linear-gradient(144deg, #19203b 0%, #070c18 100%);
|
|
border-radius: 40rpx;
|
|
padding: 40rpx;
|
|
box-sizing: border-box;
|
|
}
|
|
.border_bottom {
|
|
background-color: #f3f4f7;
|
|
border-radius: 10rpx;
|
|
padding: 0 24rpx;
|
|
box-sizing: border-box;
|
|
min-height: 80rpx;
|
|
}
|
|
.submit-btn {
|
|
margin-top: 40rpx;
|
|
height: 108rpx;
|
|
border-radius: 54rpx;
|
|
font-size: 36rpx;
|
|
font-weight: 700;
|
|
background: linear-gradient(
|
|
135deg,
|
|
var(--primary-grad-start, #2c8cfa) 0%,
|
|
var(--primary-grad-end, #3d5efb) 100%
|
|
);
|
|
box-shadow: 0 18rpx 44rpx var(--primary-shadow, rgba(47, 124, 246, 0.35));
|
|
}
|
|
.input-icon {
|
|
width: 40rpx;
|
|
height: 40rpx;
|
|
margin-right: 16rpx;
|
|
flex-shrink: 0;
|
|
}
|
|
.radio-box {
|
|
padding-top: 20rpx;
|
|
padding-bottom: 36rpx;
|
|
// background-color: #ffffff;
|
|
}
|
|
.radio {
|
|
transform: scale(0.6);
|
|
}
|
|
.btns {
|
|
margin-top: 40rpx;
|
|
}
|
|
.title {
|
|
margin-bottom: 30rpx;
|
|
}
|
|
:deep(.uni-radio-input) {
|
|
background-color: transparent;
|
|
}
|
|
.c_agreement {
|
|
color: #c02f3b;
|
|
}
|
|
.c_switch {
|
|
color: #c02f3b;
|
|
}
|
|
.c_code {
|
|
color: #c02f3b;
|
|
}
|
|
:deep(.border_bottom .uni-easyinput__content) {
|
|
border: none !important;
|
|
background: transparent !important;
|
|
}
|
|
</style>
|