今天來把登陸注冊頁面搞定,開沖谷丸!
一堡掏、登陸頁面搭建
- 新建signin頁面应结,在signin頁面:
<template>
<view class="content">
<!-- 頂欄 -->
<view class="top-bar">
<view class="top-bar-right"><view class="text">注冊</view></view>
</view>
<!-- 圖標(biāo) -->
<view class="logo"><image src="../../static/images/index/logo.png" class="logo-image"></image></view>
<!-- 登陸 -->
<view class="main">
<view class="title">登陸</view>
<view class="slogan">您好刨疼,歡迎來到 小哈職友!</view>
<view class="inputs">
<input class="input" type="text" placeholder="用戶名/郵箱" placeholder-style="color:#aaa;font-weight:400;" />
<input class="input" type="text" placeholder="密碼" placeholder-style="color:#aaa;font-weight:400;" password="true" />
</view>
</view>
<!-- 登陸按鈕 -->
<view class="submit">登陸</view>
</view>
</template>
<script>
export default {
data() {
return {};
},
methods: {}
};
</script>
<style lang="scss">
.content {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.top-bar {
position: absolute;
top: 0;
width: 100%;
height: 88rpx;
padding-top: var(--status-bar-height);
box-sizing: border-box;
background: $uni-bg-color;
// box-shadow: 0rpx 1rpx 0rpx 0rpx rgba(0, 0, 0, 0.1);
margin-top: 16rpx;
.top-bar-right {
float: right;
margin-bottom: 30rpx;
.text {
font-size: 36rpx;
font-family: PingFangSC-Medium, PingFang SC;
font-weight: 510;
color: rgba(51, 51, 51, 1);
line-height: 88rpx;
padding-right: 56rpx;
}
}
}
.logo {
padding-top: 100rpx;
.logo-image {
width: 300rpx;
height: 300rpx;
}
}
.main {
width: 100%;
padding-left: 62rpx;
.title {
font-size: 56rpx;
font-family: PingFangSC-Medium, PingFang SC;
font-weight: 500;
color: rgba(39, 40, 50, 1);
line-height: 80rpx;
}
.slogan {
font-size: 40rpx;
font-family: PingFangSC-Regular, PingFang SC;
font-weight: 400;
color: rgba(39, 40, 50, 0.5);
line-height: 56rpx;
}
.inputs {
padding-top: 48rpx;
padding-bottom: 120rpx;
.input {
height: 88rpx;
width: 628rpx;
font-size: $uni-font-size-lg;
font-weight: 500;
color: $uni-text-color;
line-height: 88rpx;
border-bottom: 1rpx solid $uni-border-color;
}
}
}
.submit {
margin: 0 auto;
width: 520rpx;
height: 96rpx;
background: rgba(255, 228, 49, 1);
box-shadow:0px 25px 16px -18px rgba(255,228,49,0.4);
border-radius:48rpx;
font-size: $uni-font-size-lg;
font-weight: 520;
color: rgba(39, 40, 50, 1);
line-height: 96rpx;
text-align: center;
}
</style>
效果如圖:
二鹅龄、注冊頁面創(chuàng)建
- 新建頁面register,register.vue中:
<template>
<view class="content">
<!-- 頂欄 -->
<view class="top-bar">
<view class="top-bar-left"><image class="back" src="../../static/images/register/back.png"></image></view>
<view class="top-bar-right"><image class="close" src="../../static/images/register/close.png"></image></view>
</view>
<!-- 圖標(biāo) -->
<view class="logo"><image src="../../static/images/index/logo.png" class="logo-image"></image></view>
<!-- 登陸 -->
<view class="main">
<view class="title">注冊</view>
<view class="inputs">
<view class="inputs-div">
<input class="input" type="text" placeholder="請取個名字" placeholder-style="color:#aaa;font-weight:400;" @blur="isname"
v-model="name"/>
<view class="employ" v-show="employ">已占用</view>
<image src="../../static/images/register/right.png" class="ok" v-show="isuser"></image>
</view>
<view class="inputs-div">
<input class="input" type="text" placeholder="在這里輸入郵箱" placeholder-style="color:#aaa;font-weight:400;" @blur="ismail" v-model="email" />
<view class="employ" v-show="employ">已占用</view>
<view class="invalid" v-show="invalid">郵箱無效</view>
<image src="../../static/images/register/right.png" class="ok" v-show="isemail"></image>
</view>
<view class="inputs-div">
<input class="input" :type="type" placeholder="設(shè)置密碼" placeholder-style="color:#aaa;font-weight:400;" />
<view class="employ" v-show="employ">已占用</view>
<image :src="showurl" class="show" @tap="showon"></image>
</view>
</view>
</view>
<!-- 登陸按鈕 -->
<view class="submit">注冊</view>
</view>
</template>
<script>
export default {
data() {
return {
type: 'password',
isuser: 0, //用戶名是否占用
isemail: 0, //郵箱是否占位
show: false, // 是否顯示密碼
invalid: false, // 郵箱是否符合
employ: false, //是否被占用
showurl: '../../static/images/register/showin.png',
email: '',
name: ''
};
},
methods: {
//密碼是否顯隱
showon: function() {
if (this.show) {
this.type = 'password';
this.show = !this.show;
this.showurl = '../../static/images/register/showin.png';
} else {
this.type = 'text';
this.show = !this.show;
this.showurl = '../../static/images/register/showon.png';
}
},
//判斷郵箱
ismail: function() {
var strRegex = /^(\w-*\.*)+@(\w-?)+(\.\w{2,})+$/;
if (this.email.length > 0) {
if (!strRegex.test(this.email)) {
this.invalid = true;
this.isemail = false;
} else {
this.invalid = false;
this.isemail = true;
}
}
},
isname: function() {
if (this.name.length > 0) {
this.isuser = true;
} else {
this.isuser = false;
}
}
}
};
</script>
<style lang="scss">
.content {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.top-bar {
position: absolute;
top: 0;
width: 100%;
height: 88rpx;
padding-top: var(--status-bar-height);
box-sizing: border-box;
background: $uni-bg-color;
// box-shadow: 0rpx 1rpx 0rpx 0rpx rgba(0, 0, 0, 0.1);
margin-top: 16rpx;
.top-bar-left {
float: left;
padding-left: 24rpx;
padding-top: 20rpx;
.back {
width: 48rpx;
height: 48rpx;
}
}
.top-bar-right {
float: right;
margin-bottom: 30rpx;
padding-right: 24rpx;
padding-top: 20rpx;
.close {
width: 48rpx;
height: 48rpx;
}
}
}
.logo {
padding-top: 100rpx;
.logo-image {
width: 300rpx;
height: 300rpx;
}
}
.main {
padding: 54rpx $uni-spacing-row-lg 120rpx;
.title {
font-size: 56rpx;
font-family: PingFangSC-Medium, PingFang SC;
font-weight: 500;
color: rgba(39, 40, 50, 1);
line-height: 80rpx;
}
.inputs {
padding-top: 48rpx;
.input {
font-size: $uni-font-size-lg;
font-weight: 500;
color: $uni-text-color;
line-height: 88rpx;
border-bottom: 1rpx solid $uni-border-color;
width: 636rpx;
z-index: 1;
}
.inputs-div {
position: relative;
padding: 20rpx;
}
.employ,
.invalid {
position: absolute;
right: 20rpx;
top: 20rpx;
float: right;
font-size: $uni-font-size-base;
font-family: PingFangSC-Medium, PingFang SC;
font-weight: 500;
color: rgba(255, 93, 91, 1);
line-height: 40rpx;
padding-left: 10rpx;
}
.show {
position: absolute;
right: 20rpx;
top: 20rpx;
width: 42rpx;
height: 32rpx;
}
.ok {
position: absolute;
top: 20rpx;
right: 20rpx;
width: 42rpx;
height: 32rpx;
}
}
}
.submit {
margin: 0 auto;
width: 520rpx;
height: 96rpx;
background: rgba(39, 40, 50, 0.2);
box-shadow: 0px 25px 16px -18px rgba(39, 40, 50, 0.2);
border-radius: 48rpx;
font-size: $uni-font-size-lg;
font-weight: 520;
color: rgba(255, 255, 255, 1);
line-height: 96rpx;
text-align: center;
&:active {
background-color: rgba(255, 228, 49, 1);
}
}
</style>
效果如圖
三揩慕、登陸注冊之間的數(shù)據(jù)交互和頁面跳轉(zhuǎn)
- 注冊登陸路由跳轉(zhuǎn):
舉例一個方法,以此類推:
goLogin: function() {
uni.navigateTo({
url: '../signin/signin'
});
- 獲取登陸數(shù)據(jù)內(nèi)容
通過v-model來獲取數(shù)據(jù)扮休,就不代碼演示了 - 設(shè)置登陸按鈕函數(shù)
onlogin() {
if (this.user && this.password) {
console.log('提交');
} else {
this.login = true;
}
}