小程序简单的登录界面

造轮子系列复制粘贴,不多说

<view class="">
  <view class="logo h400 flex jc-ai-center">
    <image src="../../assets/images/yh.png"></image>
  </view>

  <view class="ipt-wrap">
    <view class="flex jc-center">
      <view class="p-lr20  _w100 {{ isIptactive == 1 ? 'iptactive' : ' ' }}" >
        <view class="ipt-item flex h70 _w100 jc-sb ai-center">
          <text class="iconfont font22 icon-geren"></text>
          <input type="text" data-ipt="1" placeholder="请输入手机号码" class="ipt flex1 {{isIptborder == 1 ? 'iptnoneborder' : 'iptborder'}}" maxlength="11" bindfocus="selectFoucs" bindinput="IptPhoneValue" bindblur="selectBlur"></input>
        </view>
      </view>
    </view>

    <view class="mt50 flex jc-center">
      <view class="p-lr20  _w100 {{ isIptactive == 3 ? 'iptactive' : ' ' }}" >
        <view class="ipt-item flex h70 _w100 jc-sb ai-center">
          <text class="iconfont font20 icon-mima"></text>
          <input type="password" data-ipt="3" placeholder="请输入密码" class="ipt flex1 {{isIptborder == 3 ? 'iptnoneborder' : 'iptborder'}}" bindfocus="selectFoucs" maxlength="16" bindinput="IptPassValue" bindblur="selectBlur"></input>
        </view>
      </view>
    </view>
  </view>

  <view class="r-wrap">
    <view class="loginbtn font16 _w100 mt20 color-fff" bindtap="loginGO">登录</view>
    <view class="mt10 flex jc-center">
      <text class="color-767676">没有账号?</text>
      <text class="color-279efd" data-url="../register/register" bindtap="goRedirect"> 快速注册 </text></view>
  </view>

  <view class="agreement flex ai-center f-column">
    <view class="mt50 color-767676">说明:注册、登录代表您阅读并已同意</view>
    <view class="mt10 color-279efd" data-url="../agreement/agreement" bindtap="goNavigate">天图极客网用户协议</view>          
  </view>
</view>

如果不知道icon.css的可以看我的“小程序造轮子”小图标篇 

@import "../../assets/iconfont/icon.wxss";

.logo>image{
  width: 250rpx;
  height: 208rpx;
}
.iptactive{
  box-shadow: 0 0rpx 10rpx #ccc;
  border-radius: 8rpx;
}
.iptnoneborder{
  border-bottom:1px solid transparent;
}
.iptborder{
  border-bottom:1px solid #e7f2ff;
}
.ipt-item{
  position: relative;
}
.ipt{
  margin-left: 20rpx;
  height: 60rpx;
  padding-top: 5rpx;
  padding-bottom: 5rpx;
  padding-left: 10rpx;
}
.loginbtn{
  text-align: center;
  height: 80rpx;
  line-height: 80rpx;
  margin: 80rpx auto 20rpx;
  border-radius: 10rpx;
  background: linear-gradient(to right, #66ded0, #229dfe);
}
.ipt-wrap, .r-wrap, .agreement{
  padding: 0 100rpx;
}
const common = require('../../utils/common');
const api = require('../../utils/api');
const app = getApp();

Page({
  data: {
    isIptactive: 0,
    isIptborder: 0,
    phoneNum:0,
    userPass:0,
    // code:''
  },
  selectFoucs: function (e) {
    let ipt = e.target.dataset.ipt;
    this.setData({ isIptactive: ipt, isIptborder: ipt });
  },
  selectBlur: function () {
    this.setData({ isIptactive: 0, isIptborder: 0 });
  },
  IptPhoneValue: function (e) {
    this.setData({ phoneNum: e.detail.value });
  },
  IptPassValue: function (e) {
    this.setData({ userPass: e.detail.value });
  },
  goNavigate: function (e) {
    common.NAVIGATE(e.target.dataset.url);
  },
  goRedirect: function (e){
    common.REDIRECT(e.target.dataset.url);
  },  
  onLoad(){
   
  },

  loginGO: function () {
  
    var that = this
    var phoneNum = that.data.phoneNum
    var userPass = that.data.userPass
    var url = api.SINGLOGIN.singLogin

    console.log("userLogin:" + url)

    if (!common.ISPHONE(phoneNum)) {
      common.SHOWTIPS('请输入11位有效手机号码', 'none'); return;
    } else if (!common.ISPASS(userPass)) {
      common.SHOWTIPS('密码必须大于6位且小于16位,由数字和字母组合构成', 'none');      
      return;
    } else {
      common.LOADTIPS('正在登录', function () {
        wx.login({
          success(res) {
            that.setData({
              code: res.code
            })
            wx.request({
              url: url,
              method: 'post',
              data: {
                code:that.data.code,
                loginName: that.data.phoneNum,
                password: that.data.userPass,
                deviceType: 0,
                userType: 0,
              },
              success(res) {
                console.log(res.data)
                wx.hideLoading();
                if (res.data.head.statusCode == "USR_003") {
                  common.MODALTIPS('该手机号码未注册', '是否前往注册', function (res) {
                    if (res.confirm) {
                      common.REDIRECT('../register/register');
                    } else if (res.cancel) {
                      return;
                    }
                  });
                } else if (res.data.head.status == 1) {
                  common.SHOWTIPS('登录成功', 'success');
                  app.globalData.loginName = res.data.data.loginName;
                  app.globalData.imageUrl = res.data.data.imageUrl;
                  app.globalData.token = res.data.data.token;
                  app.globalData.inviteCode = res.data.data.inviteCode;
                  app.globalData.phone = res.data.data.phone;
                  app.globalData.userType = res.data.data.userType;
                  app.globalData.isLogin = 1;
                  app.globalData.loginWay = 'app';
                  common.SETSTORAGE('userID', res.data.data.token);
                  setTimeout(function () {
                    common.SWITCHTAB('../personal/personal')
                  }, 1500);
                } else if (res.data.head.statusCode == "USR_005") {
                  common.SHOWTIPS(res.data.head.message, 'none');
                } else {
                  common.SHOWTIPS('未知错误,请重试', 'none');
                }
              },
            })
          }
        })
        
      })
    }
  },
  onShareAppMessage: function () {
    common.share()
  }
})

 

  • 1
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
小程序的登陆界面是使用 WXML 和 WXSS 来实现的,而不是使用 HTML 和 CSS。以下是一个简单小程序登陆界面的 WXML 代码示例: ```wxml <view class="container"> <view class="logo"> <image src="/images/logo.png"></image> <text>小程序名称</text> </view> <form> <input type="text" placeholder="请输入用户名" bindinput="onInputUsername" /> <input type="password" placeholder="请输入密码" bindinput="onInputPassword" /> <button type="primary" bindtap="onLogin">登录</button> </form> </view> ``` 在这个示例中,我们使用了 `<view>` 来创建一个容器,并设置了一个带有图标和名称的标志。然后,我们创建了一个表单,其中包含一个用于输入用户名的文本框和一个用于输入密码的密码框,以及一个用于提交表单的按钮。 小程序的样式是使用 WXSS 来实现的。以下是一个简单的示例: ```wxss .container { display: flex; flex-direction: column; justify-content: center; align-items: center; height: 100vh; } .logo { display: flex; align-items: center; } .logo image { width: 80rpx; height: 80rpx; } .logo text { font-size: 28rpx; margin-left: 10rpx; } form input { width: 90%; height: 80rpx; margin-top: 30rpx; padding-left: 20rpx; font-size: 28rpx; border: 1rpx solid #ccc; border-radius: 10rpx; } form button { width: 90%; height: 80rpx; margin-top: 30rpx; background-color: #007aff; color: #fff; font-size: 32rpx; border-radius: 10rpx; } ``` 在这个示例中,我们设置了容器的样式,包括将其设置为 flex 布局并垂直居中。我们还设置了标志的样式和表单元素的样式,包括设置输入框和按钮的大小、颜色和边框等属性。 请注意,这只是一个示例,你可以根据你的需求修改样式和布局。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值