Implementation of a simple login page for WeChat applet (with source code)

Implementation of a simple login page for WeChat applet (with source code)

1. Picture above

2. User does not exist

3. Upload the code

3.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:
  • WeChat applet implements login page
  • JSF implements a simple login page for WeChat applet (with source code)
  • WeChat applet implements login interface
  • WeChat Mini Program Practice: Login Page Production (5)
  • WeChat applet local storage and login page processing example detailed explanation
  • WeChat applet login interface example

<<:  Share 8 CSS tools to improve web design

>>:  About installing python3.8 image in docker

Recommend

Three ways to implement waterfall flow layout

Preface When I was browsing Xianyu today, I notic...

jQuery implements sliding tab

This article example shares the specific code of ...

About installing python3.8 image in docker

Docker Hub official website 1. Search for Python ...

Briefly describe the difference between MySQL and Oracle

1. Oracle is a large database while MySQL is a sm...

Detailed tutorial on building an ETCD cluster for Docker microservices

Table of contents Features of etcd There are thre...

A brief discussion on group by in MySQL

Table of contents 1. Introduction 2. Prepare the ...

CSS float property diagram float property details

Using the CSS float property correctly can become...

Vue3 slot usage summary

Table of contents 1. Introduction to v-slot 2. An...

Tomcat server security settings method

Tomcat is an HTTP server that is the official ref...

Cross-browser local storage Ⅰ

Original text: http://www.planabc.net/2008/08/05/...

The use of anchor points in HTML_PowerNode Java Academy

Now let's summarize several situations of con...

Tutorial on building an FTP server in Ubuntu 16.04

Ubuntu 16.04 builds FTP server Install ftp Instal...