小程序实战中登录页面代码分享
发布于 2 年前 作者 qiangbai 3455 次浏览 来自 分享

由于视频教程(https://developers.weixin.qq.com/community/business/doc/00008c2f9d83a040de5ad3a945b80d)中仅仅是布置了编写登录页面的作业,在下一节并没有代码呈现,所以我把我编写好的代码发出来,供大家交流使用:

  • login.json文件
{
  "usingComponents": {},
  "navigationBarBackgroundColor""#fff",
  "navigationBarTitleText""洞主登录",
  "navigationBarTextStyle":"black"
}
  • login.wxml文件
<!--pages/login/login.wxml-->
<view class="background">
    <view class="first">
        <input id='account' placeholder="用户名/邮箱/手机号" placeholder-class="plas" type="text" class="inputs" bindinput="accountInput" />
    </view>
    <view class="second">
        <input id='pwd' placeholder="登录密码" placeholder-class="plas" type="password" class="inputs" bindinput=passwordInput" />
    </view>
    <view id='btn' class="click" bindtap='signin'>注册</view>
    <view class="cha">
        <text class="no" bindtap="regist">还没有账号?点我注册</text>
    </view>
</view>
  • login.wxss
/* pages/login/login.wxss */
pages {
    left0rpx;
    right0rpx;
    background-color: white;
}

.first {
    width90%;
    height100rpx;
    margin-top80rpx;
    margin-left5%;
    margin-right5%;
    display: flex;
    /*Flex是Flexible Box的缩写,意为"弹性布局",用来为盒状模型提供最大的灵活性*/
    flex-direction: row;
    align-items: center;
    justify-content: center;
    background-color#f2f2f2;
}

.second {
    width90%;
    height100rpx;
    margin-top30rpx;
    margin-left5%;
    margin-right5%;
    display: flex;
    /*Flex是Flexible Box的缩写,意为"弹性布局",用来为盒状模型提供最大的灵活性*/
    flex-direction: row;
    align-items: center;
    justify-content: center;
    background-color#f2f2f2;
}

.flas {
    font-size30rpx;
    color#CCCCCC;
}

.inputs {
    line-height100rpx;
    font-size30rpx;
    color#000000;
    margin: auto;
    margin-left20rpx;
    width100%;
}

.click {
    width90%;
    height100rpx;
    line-height100rpx;
    margin: auto;
    margin-top80rpx;
    margin-left5%;
    margin-right5%;
    background-color#F76968;
    text-align: center;
    color: white;
    font-size33rpx;
}

.cha {
    width90%;
    height50rpx;
    margin: auto;
    margin-top30rpx;
    margin-left5%;
    margin-right5%;
}

.no {
    color: black;
    font-size28rpx;
    margin-left15rpx;
    font-family: PingFangSC-regular;
}
  • login.js
// pages/login/login.js
Page({

    /**
     * 页面的初始数据
     */
    data: {
        account:'',
        password:''
    },

    accountInput:function (e) {
        this.data.account = e.detail.value
    },

    passwordInput:function (e) {
        this.data.password = e.detail.value
    },

    regist:function (e) {
        wx.navigateTo({
          url: '../enroll/enroll',
        })
    },

    signin:function (e) {
        var that = this
        if(that.data.account==''){
            wx.showModal({
              title:"提示",
              content:"请输入用户名/邮箱/手机号",
              showCancel:false,
              success(res){}
              })
        }else if(that.data.password==''){
            wx.showModal({
                title:"提示",
                content:"请输入密码",
                showCancel:false,
                success(res){}
                })
        }else{
            console.log('success')
        }
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {

    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})

代码如上。希望我的代码能给你们带来帮助。

如果觉得对你们有帮助,可以给文章点个赞哦~

7 回复

感觉写的很不错,有学到东西,赞~

很好哦,加油嗷!一会我也去看/doge

不错不错,写一下这种小案例对练习和熟悉开发都很有帮助。加油!!

不错,下次可以尝试着把一些核心的代码粘贴出来,突出重点

不错不错继续加油~

收藏了收藏了

我觉得你是来骗赞的 不过巧了我也是来骗赞的 呼哈哈嗝

回到顶部