小程序入门之注册页面

注册页面:基本内容有账号,密码,确认密码

wxml源码:

1. 顶部提示错误信息

2. 输入内容长度限制

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

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

 1 
11 
12 if="{{showTopTips}}">{{errorMsg}}
13 
14 
15 
16 
17 
18 
19 50
51

 

wxss源码:
1. 背景图片以毛玻璃的形式展示

2. form表单背景透明

 1 .back_img{
 2 background: url(../../images/meBack.jpg) no-repeat;
 3 background-size:cover;
 4 -webkit-filter: blur(10px); /* Chrome, Opera */
 5 -moz-filter: blur(10px);
 6 -ms-filter: blur(10px); 
 7 filter: blur(10px); 
 8 z-index:0;
 9 position:relative;
10 }
11 .login_info{
12 z-index: 999;
13 position:absolute;
14 }
15 .login_form{
16 border-radius:5px;
17 margin-left:8%;
18 background-color: rgba(255,255,255,0.2);
19 }

 

js源码:
1. form表单获取值

2. request请求

3. 交互反馈弹出框

4. 导航页面跳转传值

 

 1 var util = require('../../utils/util.js');
 2 var app = getApp();
 3 
 4 Page({
 5 data: {
 6 showTopTips: false,
 7 errorMsg: ""
 8 },
 9 onLoad: function () {
10 var that = this;
11 wx.getSystemInfo({
12 success: function (res) {
13 that.setData({
14 windowHeight: res.windowHeight,
15 windowWidth: res.windowWidth
16 })
17 }
18 });
19 },
20 
21 formSubmit: function (e) {
22 // form 表单取值,格式 e.detail.value.name(name为input中自定义name值) ;使用条件:需通过

 

util.js 源码(封装了一些常用的方法)

 1 function formatTime(date) {
 2 var year = date.getFullYear()
 3 var month = date.getMonth() + 1
 4 var day = date.getDate()
 5 
 6 var hour = date.getHours()
 7 var minute = date.getMinutes()
 8 var second = date.getSeconds()
 9 
10 return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
11 }
12 
13 function formatNumber(n) {
14 n = n.toString()
15 return n[1] ? n : '0' + n
16 }
17 
18 var rootDocment = 'https://www.itit123.cn';
19 function req(url,data,cb){
20 wx.request({
21 url: rootDocment + url,
22 data: data,
23 method: 'post',
24 header: {'Content-Type':'application/x-www-form-urlencoded'},
25 success: function(res){
26 return typeof cb == "function" && cb(res.data)
27 },
28 fail: function(){
29 return typeof cb == "function" && cb(false)
30 }
31 })
32 }
33 
34 function getReq(url,data,cb){
35 wx.request({
36 url: rootDocment + url,
37 data: data,
38 method: 'get',
39 header: {'Content-Type':'application/x-www-form-urlencoded'},
40 success: function(res){
41 return typeof cb == "function" && cb(res.data)
42 },
43 fail: function(){
44 return typeof cb == "function" && cb(false)
45 }
46 })
47 }
48 
49 // 去前后空格
50 function trim(str) {
51 return str.replace(/(^\s*)|(\s*$)/g, "");
52 }
53 
54 // 提示错误信息
55 function isError(msg, that) {
56 that.setData({
57 showTopTips: true,
58 errorMsg: msg
59 })
60 }
61 
62 // 清空错误信息
63 function clearError(that) {
64 that.setData({
65 showTopTips: false,
66 errorMsg: ""
67 })
68 }
69 
70 module.exports = {
71 formatTime: formatTime,
72 req: req,
73 trim: trim,
74 isError: isError, 
75 clearError: clearError,
76 getReq: getReq
77 }

你可能感兴趣的:(小程序入门之注册页面)