上一章介绍了 微信小程序入门六本地缓存和搜索 ,这章介绍小程序的登录注册页面。主要有表单的验证,错误信息的提示,form表单的取值,get / post 请求 ,反馈交互提示框,页面跳转 以及 页面UI。

效果图:

注册页面:基本内容有账号,密码,确认密码,也可以添加 是否同意条款

wxml源码:

1. 顶部提示错误信息

2. 输入内容长度限制

3. 点击注册进行表单验证

4. 存在问题:输入框focus 无效果

<!--
变量说明:
showTopTips : 是否显示提示信息
errorMsg : 错误信息
windowHeight :设备的窗口的高度
windowWidth : 设备的窗口的宽度
account : 账号
password :密码
subPassword :确认密码
-->
<view class="page__bd"><view class="weui-toptips weui-toptips_warn" wx:if="{{showTopTips}}">{{errorMsg}}</view><view style="height: {{windowHeight}}px; width: {{windowWidth}}px;" class="back_img"></view><view style="position:absolute;top:{{windowHeight * 0.06}}px;"><image src="../../images/meBack.jpg" style="width: {{windowWidth * 0.4}}px;height:{{windowWidth * 0.4}}px; margin-left:{{windowWidth * 0.5 - 80}}px;border-radius:{{windowWidth * 0.2}}px;"></image></view><form bindsubmit="formSubmit" bindreset="formReset"><view class="login_info" style="top:{{windowHeight * 0.35}}px;width: {{windowWidth * 0.92}}px;"><view class="weui-cells weui-cells_after-title login_form"><view class="weui-cell weui-cell_input"><view class="weui-cell__hd"><view class="weui-label">账号</view></view><view class="weui-cell__bd"><input class="weui-input" placeholder="请输入账号" type="text" maxlength="20" value="{{account}}" focus="true" name="account"/></view></view><view class="weui-cell weui-cell_input"><view class="weui-cell__hd"><view class="weui-label">密码</view></view><view class="weui-cell__bd"><input class="weui-input" placeholder="请输入密码" type="password" maxlength="10" value="{{password}}" name="password"/></view></view><view class="weui-cell weui-cell_input"><view class="weui-cell__hd"><view class="weui-label">确认密码</view></view><view class="weui-cell__bd"><input class="weui-input" placeholder="请输入确认密码" type="password" maxlength="10" value="{{subPassword}}" name="subPassword"/></view></view><view class="weui-btn-area"><button class="weui-btn" type="primary" formType="submit">注册</button></view></view></view></form>
</view>

wxss源码:

1. 背景图片以毛玻璃的形式展示

2. form表单背景透明

.back_img{background: url(../../images/meBack.jpg) no-repeat;background-size:cover;-webkit-filter: blur(10px); /* Chrome, Opera */-moz-filter: blur(10px);-ms-filter: blur(10px);    filter: blur(10px); z-index:0;position:relative;
}
.login_info{z-index: 999;position:absolute;
}
.login_form{border-radius:5px;margin-left:8%;background-color: rgba(255,255,255,0.2);
}

js源码:

1. form表单获取值

2. request请求

3. 交互反馈弹出框

4. 导航页面跳转传值

var util = require('../../utils/util.js');
var app = getApp();Page({data: {showTopTips: false,errorMsg: ""},onLoad: function () {var that = this;wx.getSystemInfo({success: function (res) {that.setData({windowHeight: res.windowHeight,windowWidth: res.windowWidth})}});},formSubmit: function (e) {// form 表单取值,格式 e.detail.value.name(name为input中自定义name值) ;使用条件:需通过<form bindsubmit="formSubmit">与<button formType="submit">一起使用var account = e.detail.value.account;var password = e.detail.value.password;var subPassword = e.detail.value.subPassword;var that = this;// 判断账号是否为空和判断该账号名是否被注册if ("" == util.trim(account)) {util.isError("账号不能为空", that);return;} else {util.clearError(that);app.ajax.req('/register/checkLoginName', {"loginName": account}, function (res) {if (!res) {util.isError("账号已经被注册过", that);return;}});}// 判断密码是否为空if ("" == util.trim(password)) {util.isError("密码不能为空", that);return;} else {util.clearError(that);}// 两个密码必须一致if (subPassword != password) {util.isError("输入密码不一致", that);return;} else {util.clearError(that);}// 验证都通过了执行注册方法app.ajax.req('/itdragon/register', {"account": account,"password": password}, function (res) {if (true == res) {// 显示模态弹窗wx.showModal({title: '注册状态',content: '注册成功,请点击确定登录吧',success: function (res) {if (res.confirm) {// 点击确定后跳转登录页面并关闭当前页面wx.redirectTo({url: '../login/login?account=' + account + '&password?=' + password + ''})}}})} else {// 显示消息提示框wx.showToast({title: '注册失败',icon: 'error',duration: 2000})}});}
})

util.js 源码(封装了一些常用的方法,如果有不懂的内容,可以参考前面几章)

function formatTime(date) {var year = date.getFullYear()var month = date.getMonth() + 1var day = date.getDate()var hour = date.getHours()var minute = date.getMinutes()var second = date.getSeconds()return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}function formatNumber(n) {n = n.toString()return n[1] ? n : '0' + n
}var rootDocment = 'https://www.itit123.cn';
function req(url,data,cb){wx.request({url: rootDocment + url,data: data,method: 'post',header: {'Content-Type':'application/x-www-form-urlencoded'},success: function(res){return typeof cb == "function" && cb(res.data)},fail: function(){return typeof cb == "function" && cb(false)}})
}function getReq(url,data,cb){wx.request({url: rootDocment + url,data: data,method: 'get',header: {'Content-Type':'application/x-www-form-urlencoded'},success: function(res){return typeof cb == "function" && cb(res.data)},fail: function(){return typeof cb == "function" && cb(false)}})
}// 去前后空格
function trim(str) {return str.replace(/(^\s*)|(\s*$)/g, "");
}// 提示错误信息
function isError(msg, that) {that.setData({showTopTips: true,errorMsg: msg})
}// 清空错误信息
function clearError(that) {that.setData({showTopTips: false,errorMsg: ""})
}module.exports = {formatTime: formatTime,req: req,trim: trim,isError: isError, clearError: clearError,getReq: getReq
}

登录页面也是一样的逻辑和代码,这里就不再贴出来,后续会提供源码(文中的请求地址可能已经失效,仅供参考)。

微信小程序入门七登录注册相关推荐

  1. 微信小程序如何实现登录注册带源码

    前几天没事随手写了个小程序端的登录注册,现在分享给大家 一.登录微信前端 这是效果图与wxml代码 这是wxss代码 input{height: 100rpx; text-align: center; ...

  2. 微信小程序版的登录注册

    ##使用微信小程序进行用户的登陆注册功能 使用了weui进行 ####1.登录界面展示: ####2.注册界面展示 ####3.代码列表展示: ####4.核心功能 #####(1)用户名密码错误: ...

  3. 微信小程序入门(登录页面)

    1.首先前往开发者工具下载安装开发工具: 2.安装后微信扫码,并填写自己的AppID选择自己的项目目录后登录: 登陆后点击工具上的编译按钮,可以在工具的左侧模拟器界面看到这个小程序的表现,也可以点击预 ...

  4. 微信小程序(七)注册

    enroll.wxml <!--pages/enroll/enroll.wxml--> <view wx:if="{{!success}}"><vie ...

  5. 【微信小程序】微信小程序入门与实战-个人笔记

    微信小程序入门与实战 文章目录 微信小程序入门与实战 1 初识微信小程序 1-1 2020版重录说明 1-2 下载小程序开发工具 1-3 新建小程序项目 1-4 小程序appid的注册 1-5 新版小 ...

  6. 做一个微信小程序给TA——程序猿小白的情人节礼物(微信小程序入门——一文学会小程序开发到发布小程序的全过程)

    # 情人节 可送给女朋友 的礼物,或者作为两人的纪念  # 效果展示:微信搜索 "王美美与曾小帅"  小程序即可查看效果 # 微信小程序入门--使用免费后端云(Bmod)搭建留言板 ...

  7. 微信小程序入门---01

    目录 微信小程序入门 一.小程序简介 二.第一个小程序 二.小程序代码的构成 三.WXML模块 四.WXSS 样式 五.JS 逻辑交互 六.组件 七.API 八.WXML 模板语法 - 数据绑定 九. ...

  8. 微信小程序入门之常用组件(04)

    常见组件 重点讲解微信小程序中常见的布局组件 view,text,rich-text,button,image,navigator,icon,swiper, radio,checkbox 等 一.vi ...

  9. 微信小程序入门-音乐播放器

    萌新,随便做做,只是了解一下微信小程序,希望可以给看到的胖友一点参考. 之前在网上看到这个人入门四天做完一个,我五天做完了,比他好看,突然有一点自信 然后发现自己特别不乐意重新看自己的代码,总觉得写的 ...

最新文章

  1. 【Qt】通过QtCreator源码学习Qt(十一):Utils::Icon,根据不同主题、不同状态变换图标
  2. docker启动odoo提示module没有安装_Windows Server 2019上的Docker 入门
  3. 深度窥探 QuickTest 视图(1)
  4. android studio资产目录,在Android Studio中设置单元测试的自定义资产目录
  5. SAP UI5 Simple form rendering
  6. Python基础 ( 十 ) —— 面向对象(多态、封装、反射、动态导入)
  7. 福建省计算机中职类高考400分多少名,重要参考!福建高职分类各院校近两年招生计划及分数线汇总来了,快收藏...
  8. 【OpenCV学习笔记】【教程翻译】四(车牌检测之SVM分类)
  9. ipad无法充电怎么办_哈尔滨Ipad死机了维修费用价目表_京宏通讯器材维修培训学校...
  10. 解除极域电子教室软件控屏的方法
  11. 秦九韶算法(java实现)
  12. 为什么现在的智能手机,都被设计成不可更换电池?
  13. 银行接口数据包(银行名称获取)
  14. 新大陆物联网Android开发实战(一)通过接入API文档获取新大陆物联网官网Logo-GETPOST多线程实战-网络资源下载
  15. 01-Spring的初体验:spring工厂的化过程
  16. 足球战术训练的几种方法
  17. 字符串中空格符 空字符
  18. Excel多个工作表合并,如何去除每个工作表中的表头,只保留一个表头
  19. 网关gataway的理解
  20. 何为非侵入式负荷监测-目标检测

热门文章

  1. DFP算法_python
  2. [W ParallelNative.cpp:212] Warning: Cannot set number of intraop threads after parallel work h
  3. led 驱动: 心跳灯
  4. 混合高斯模型(Gaussian Mixture Model,GMM)
  5. Keystone 认证服务
  6. 均方误差(mean-square error, MSE)
  7. 大爽pygame入门教程 第一节 基础知识
  8. Mac下安装sqlmap
  9. 如何构建可持续的ChatGPT高性能服务器端架构?
  10. 增强型MOS管工作相关问题