xieheng_79 06月04日
微信小程序如何保存登录密码?
login.wxml代码:
<view>
<view class="login-icon"> 
<image class="login-img" src="../../image/11.png"></image> 
</view>
<view class="usermotto">
<text class="user-motto">{{motto}}</text>
<form bindsubmit='login'>
<view class="first">
<input id="username" placeholder="请输入用户名" 
placeholder-class="plas" class="inputs" type="text" name="username" 
value="{{strloginUser}}"></input>
</view>
<view class="second">
<input id="password" placeholder="请输入密码" 
placeholder-class="plas" class="inputs" type="password" name="password" 
value="{{strloginpassword}}"></input>
</view>
<view class="{{RemberPass}}" style="width:30%;text-
align:left;margin-left:40rpx;float:left;font-size:13px;margin-
top:20rpx;margin-bottom:20rpx;">
<switch type="checkbox" checked="{{switchChecked}}" 
bindswitcheck="switchChecked" bindchange="bindswitchchange" 
style="transform:scale(0.8)"/>记住密码
</view>
<view>
<button class="loginBtn" type="primary" form-type='submit'>登录
</button>
</view>
</form>
</view>
</view>

login.js代码:
const app = getApp();
Page({
data: { motto: '欢迎',
username:'',
password:'',
strloginUser:'',//用户名
strloginpassword:'',//密码
checkedValue:'',//选中按钮
},
login: function (e) {
var me = this;
var formObject = e.detail.value;
console.log(e.detail);
var username = formObject.username;
var password = formObject.password;
console.log("username..." + username);
console.log("password....." + password);
wx.request({
url: 'http://127.0.0.1/sqxt/login.php',
method: 'POST',
data: {
'username': e.detail.value.username,
'password': e.detail.value.password
},
header: {
'content-type': 'application/x-www-form-urlencoded'
},
success(res) {
console.log(res.data)
if ("success" == res.data.replace(/^\s+|\s+$/g, '') ) {
wx.navigateTo({
url: '../sqxt/sqxt'
})
} else if ("name or password is wrong" == res.data.replace(/^\s+|\s+$/g, '')) {wx.showModal({title: '提示',content: '用户名为空或用户名、密码错误',showCancel: "false",success(res) {console.log('用户点击确定');
wx.redirectTo({
url: '../login/login'
})
}
})
}
}
})
},
loginUser(e) {
this.setData({
strloginUser: e.detail.value
})
},
loginpassword(e) {
this.setData({
strloginpassword: e.detail.value
})
},
onLoad: function (options) {
var _this = this;
_this.setData({
strloginUser: wx.getStorageSync("strloginUser"),
strloginpassword: wx.getStorageSync("strloginpassword"),
switchChecked:wx.getStorageSync('checkedValue')
})
},
bindswitchchange: function (event) {
var checkedValue = event.detail.value;
// console.log(checkedValue);
var _this = this;
if (checkedValue == true){
_this.setData({
switchChecked:true,
})
console.log(checkedValue);
} else if (checkedValue == false) {
_this.setData({
switchChecked: false
})
}
},
LoginForm: function (e) { 
var that = this;
var checkedValue = that.data.switchChecked;
console.log(checkedValue);
if (checkedValue == true) {
wx.setStorageSync("strloginUser",that.data.strloginUser);
wx.setStorageSync("strloginpassword",that.data.strloginpassword);
wx.setStorageSync("checkedValue", that.data.switchChecked);
} else if (checkedValue == false) {
wx.setStorageSync("strloginUser","");
wx.setStorageSync("strloginpassword","");
}
},
})

 

...全文
52 点赞 收藏 回复
写回复
回复

还没有回复,快来抢沙发~

发动态
发帖子
JavaScript
创建于2007-09-28

5.1w+

社区成员

22.3w+

社区内容

Web 开发 JavaScript
社区公告
暂无公告