1. Picture above2. User does not exist 3. Upload the code3.1login.wxml <view class="v1" style="height:{{clientHeight?clientHeight+'px':'auto'}}"> <!-- v2 parent container child view uses absolute layout --> <view class="v2"> <view class="dltext" style="width: 232rpx; height: 92rpx; display: block; box-sizing: border-box; left: 0rpx; top: -2rpx">Login</view> <!-- Phone Number--> <view class="phoneCs"> <!-- <image src="/images/zhang.png" class="ph"></image> --> <input placeholder="Please enter your account number" type="number" bindinput="content" /> </view> <!-- Password --> <view class=passwordCs"> <!-- <image src="/images/mi.png" class="ps"></image> --> <input placeholder="Please enter your password" type="password" bindinput="password" /> </view> <!-- Login Button--> <view class="denglu"> <button class="btn-dl" type="primary" bindtap="goadmin">Log in</button> </view> </view> </view> 3.2login.css /* pages/login/login.wxss *//* The largest parent element*/ .v1{ display: block; position:absolute; width: 100%; background-color: rgb(250, 248, 248); } /* White area */ .v1 .v2{ position: relative; margin-top: 150rpx; left: 100rpx; width: 545rpx; height: 600rpx; background-color: rgb(250, 248, 248); border-radius: 50rpx; } /* Login text in the white area*/ .v1 .v2 .dltext{ margin-top: 50rpx; position: absolute; margin-left:50rpx; width: 150rpx; height: 100rpx; font-size: 60rpx; font-family: Helvetica; color: #000000; line-height: 100rpx; letter-spacing: 2rpx; } /* Mobile phone picture + input box + underline parent container view */ .v1 .v2 .phoneCs{ margin-top: 200rpx; margin-left: 25rpx; position: absolute; display: flex; width:480rpx; height: 90rpx ; background-color: white; } /* Mobile phone icon */ .v1 .v2 .phoneCs .ph{ margin-top: 5rpx; margin-left: 30rpx; width: 55rpx; height: 55rpx; } /* Phone number input box*/ .v1 .v2 .phoneCs input{ width: 400rpx; font-size: 30rpx ; margin-top: 25rpx; margin-left: 30rpx; } /* Password icon + input box + small eye icon + underline parent container view */ .v1 .v2 .passwordCs{ margin-top: 350rpx; margin-left: 25rpx; position: absolute; display: flex; width:480rpx; height: 90rpx ; background-color: white; } /* Password icon */ .v1 .v2 .passwordCs .ps{ margin-top: 5rpx; margin-left: 30rpx; width: 55rpx; height: 55rpx; } /* Eye icon */ .v1 .v2 .passwordCs .eye{ margin-top: 5rpx; margin-left: 65rpx; width: 55rpx; height: 55rpx; } /* Password input box*/ .v1 .v2 .passwordCs input{ width: 400rpx; font-size: 30rpx ; margin-top: 25rpx; margin-left: 30rpx; } /* Login button container view */ .v1 .v2 .denglu{ width: 480rpx; height: 80rpx; position: absolute; margin-top:515rpx; margin-left:25rpx; } /* Login button */ .v1 .v2 .denglu button{ padding: 0rpx; line-height: 70rpx; font-size: 30rpx; width: 100%; height: 100%; border-radius: 5rpx; } 3.3login.js //index.js //Get the application instance const app = getApp() let username='' let password='' Page({ data: { username: '', password: '', clientHeight:'' }, onLoad(){ var that=this wx.getSystemInfo({ success: function (res) { console.log(res.windowHeight) that.setData({ clientHeight:res.windowHeight }); } }) }, //Protocol goxieyi(){ wx.navigateTo({ url: '/pages/oppoint/oppoint', }) }, //Get the input content content(e){ username=e.detail.value }, password(e){ password=e.detail.value }, //Login event goadmin(){ let flag = false // indicates whether the account exists, false is the initial value if (username=='') { wx.showToast({ icon:'none', title: 'Account cannot be empty', }) }else if(password==''){ wx.showToast({ icon:'none', title: 'The password cannot be empty', }) }else{ wx.cloud.database().collection('adminShop') .get({ success:(res)=>{ console.log(res.data) let admin = res.data for (let i = 0; i < admin.length; i++) { //Traverse the database object collection if (username === admin[i].username) { //Account already exists flag=true; if (password !== admin[i].password) { //Judge whether the password is correct or not wx.showToast({ //Show password error information title: 'Wrong password!!', icon: 'error', duration: 2500 }); break; } else { wx.showToast({ //Show login success information title: 'Login successful!!', icon: 'success', duration: 2500 }) flag=true; wx.setStorageSync('admin', password) wx.navigateTo({ url: '/pages/admin/admin', }) break; } } }; if(flag==false)//After traversing the data, it is found that there is no such account { wx.showToast({ title: 'This user does not exist', icon: 'error', duration: 2500 }) } } }) } }, }) This is the end of this article about the simple login page of WeChat applet (with source code). For more relevant WeChat applet simple login page content, please search 123WORDPRESS.COM’s previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Share 8 CSS tools to improve web design
>>: About installing python3.8 image in docker
Say it in advance On a whim, I want to know what ...
Introducing vue and vue-router <script src=&qu...
Table of contents Preface What are asynchronous i...
Problem description: The user has a requirement t...
This article shares the specific code for importi...
Table of contents background Solution 1 Ideas: Co...
1. Problem description The storage installed in t...
Table of contents 1. Shallow cloning 2. Deep clon...
Table of contents 1. Initialization structure 2. ...
Preface A classmate is investigating MLSQL Stack&...
Preface If you use the overflow: scroll attribute...
Preface Relational databases are more likely to b...
Format Encoding 1. Please set the page width with...
Mysql query time period intersection Usage scenar...
Common utf8mb4 sorting rules in MySQL are: utf8mb...