微信小程序教程笔记7

用户登录
在这里插入图片描述
在这里插入图片描述
app.json

{
  "pages": [
    "pages/index/index",
    "pages/login/login",
    "pages/user/user"
  ],
  "window": {
    "backgroundTextStyle": "light",
    "navigationBarBackgroundColor": "#fff",
    "navigationBarTitleText": "用户登录",
    "navigationBarTextStyle": "black"
  },


  "tabBar": {
    "list": [
      {
        "pagePath": "pages/index/index",
        "text": "首页"
      },
      {
        "pagePath": "pages/user/user",
        "text": "用户中心"
      }
    ]
  },

  "sitemapLocation": "sitemap.json"
}
/**app.wxss**/
.container {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 200rpx 0;
  box-sizing: border-box;
} 

project.config.json

{
	"description": "项目配置文件",
	"packOptions": {
		"ignore": []
	},
	"setting": {
		"urlCheck": true,
		"es6": true,
		"postcss": true,
		"minified": true,
		"newFeature": true,
		"autoAudits": false,
		"coverView": true,
		"showShadowRootInWxmlPanel": true,
		"scopeDataCheck": false
	},
	"compileType": "miniprogram",
	"libVersion": "2.10.2",
	"appid": "wx085539193831c8f7",
	"projectname": "miniprogram-1",
	"debugOptions": {
		"hidedInDevtools": []
	},
	"isGameTourist": false,
	"simulatorType": "wechat",
	"simulatorPluginLibVersion": {},
	"condition": {
		"search": {
			"current": -1,
			"list": []
		},
		"conversation": {
			"current": -1,
			"list": []
		},
		"game": {
			"currentL": -1,
			"list": []
		},
		"miniprogram": {
			"current": -1,
			"list": []
		}
	}
}

sitemap.json

{
  "desc": "关于本文件的更多信息,请参考文档 

https://developers.weixin.qq.com/miniprogram/dev/framework/sitemap.html",
  "rules": [{
  "action": "allow",
  "page": "*"
  }]
}

app.js

App({
  onLaunch: function () {
    console.log('App Launch')
  },
  onShow: function () {
    console.log('App Show')
  },
  onHide: function () {
    console.log('App Hide')
  },

  appData : {
    userinfo : null,
  }
<!--index.wxml-->
<view class="index-container">
   <image  src="/image/index.jpg" ></image>
</view>

index.wxss

.index-container{
  width: 100%;
  height: 100%;
}

.index-container image{
  width: 100%;
  height: 1500px;
}

index.js

Page({
  data:{
    // text:"这是一个页面"
  },
  onLoad:function(options){
    // 页面初始化 options为页面跳转所带来的参数
  },
  onReady:function(){
    // 页面渲染完成
  },
  onShow:function(){
    // 页面显示
  },
  onHide:function(){
    // 页面隐藏
  },
  onUnload:function(){
    // 页面关闭
  }
})

index.wxml

<view class="mcontainer">
    <view class="item">
        <image src="/image/logo.png" class="image"/>
    </view>

    <view class="item">
       <view class="login-item">
       	    <view class="login-item-info">用户名</view>
            <view><input bindinput="usernameInput" /></view>
       </view>
       <view class="login-item">
            <view class="login-item-info">密码</view>
            <view class="login-pwd">
            
            <input style="flex-grow:1" password="true"  bindinput="passwordInput"/> 
            <text> 忘记密码 </text>
            
            </view>
       </view>
       <view class="login-item bottom">
            <button class="login-btn" bindtap="loginBtnClick">登录</button>
       </view>
    </view>


    <view class="item bottom-info">
       <view> 没有账户? <text> 注册 </text> </view>
       <view class="wechat-icon">
            <image src="/image/wechat.png"  />
       </view>
    </view>


</view>

login.wxss

.mcontainer {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
} 

.item{
    flex-grow:1;
    height: 30%;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    width: 96%;
    padding: 0 2%;
}

.image{
    width: 500rpx;
    height: 120rpx;  
}

.login-item{
    width: 90%;
    margin-top: 30rpx;
    border-bottom: 1px solid #eee;
    flex-grow:1;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    padding-bottom: 20rpx;
}

 .bottom{
     border-bottom: 0px;
}

.login-item-info{
    font-size: 8px;
    color: #888;
     padding-bottom: 20rpx;
}

.login-pwd{
    display: flex;
    justify-content: space-between;
    flex-grow: 1;
    align-items: center;
  
}

.login-pwd text{
    height: 100%;
    font-size: 14px;
    color: #888;
    display: flex;
     
}
.login-btn{
    width: 80%;
    color: white;
    background-color: green;
    border-radius: 0;
    font-size: 14px;

}

.login-btn:hover{
    width: 80%;
    color: white;
    border-radius: 0;

}

.bottom-info{

}

.wechat-icon{
    margin-top: 30px;
    width: 30px;
    height: 30px;
    border: 1px solid seagreen;
    border-radius: 50%;
    padding: 10px;
}

.wechat-icon image{
    width: 30px;
    height: 30px;
}
})

login.js

var app = getApp();

Page({
  data:{
    username:null,
    password:null,
  },
  onLoad:function(options){
   
  },
  onReady:function(){
    
  },
  onShow:function(){
    // 页面显示
  },
  onHide:function(){
    // 页面隐藏
  },
  onUnload:function(){
    // 页面关闭
  },

  loginBtnClick:function (){

    // 用户名和密码验证的过程

    app.appData.userinfo = { username: this.data.username, password: this.data.password 

}
    wx.redirectTo({
      url: '../user/user',
    })
  },

  usernameInput : function (event){

    console.log({event})
    this.setData({username:event.detail.value})
  },

  passwordInput : function (event){
    console.log({event})
    this.setData({ password:event.detail.value})
  }


})

user.wxml

<view class="index-container">
   <image  src="/image/uc.jpg" ></image>
   <view class="nickname">
      {{username}}
   </view>
</view>

user.wxss

.index-container{
  width: 100%;
  height: 100%;
  position: relative;
}

.index-container image{
  width: 100%;
  height: 550px;
}

.nickname{
  position: absolute;
  top: 170px;
  left: 120px;
  font-size: 25px;
}

user.js

var app = getApp();
Page({
  data:{
    username:null
  },
  onLoad:function(options){
    if(app.appData.userinfo == null ){
     // wx.navigateTo({url:"../login/login"})

        wx.redirectTo({url:"../login/login"})
    }else{

      this.setData({username:app.appData.userinfo.username})


    }


  },
  onReady:function(){
    // 页面渲染完成
  },
  onShow:function(){
    // 页面显示
  },
  onHide:function(){
    // 页面隐藏
  },
  onUnload:function(){
    // 页面关闭
  }
})
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值