You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
180 lines
3.0 KiB
180 lines
3.0 KiB
// pages/index/index.js
|
|
import Toast from './@vant/weapp/toast/toast';
|
|
var app=getApp();
|
|
Page({
|
|
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
|
|
|
|
onload: function (){
|
|
|
|
},
|
|
data: {
|
|
user:"",//输入账号
|
|
pwd:"",//输入密码
|
|
default_user:"user",//默认账号
|
|
default_pwd:"123456",//默认密码
|
|
},
|
|
//登录按钮
|
|
log_on()
|
|
{
|
|
console.log("账号",this.data.user,this.data.pwd);
|
|
if(this.data.user==this.data.default_user&& this.data.pwd==this.data.default_pwd)
|
|
{
|
|
wx.reLaunch({
|
|
url: '/pages/navigation/index/index',
|
|
})
|
|
}else{
|
|
Toast.fail('账号或密码错误');
|
|
}
|
|
},
|
|
//忘记密码
|
|
forget()
|
|
{
|
|
|
|
},
|
|
|
|
|
|
//获取用户名
|
|
getName(user) {
|
|
console.log('获取输入的用户名', user.detail.value)
|
|
this.setData({
|
|
name: user.detail.value
|
|
})
|
|
},
|
|
//获取用户账号
|
|
getZhangHao(user) {
|
|
console.log('获取输入的账号', user.detail.value)
|
|
this.setData({
|
|
zhanghao: user.detail.value
|
|
})
|
|
},
|
|
// 获取密码
|
|
getMiMa(pwd) {
|
|
console.log('获取输入的密码', pwd.detail.value)
|
|
this.setData({
|
|
mima: pwd.detail.value
|
|
})
|
|
},
|
|
|
|
|
|
//注册
|
|
zhuce() {
|
|
let name = this.data.name
|
|
let zhanghao = this.data.zhanghao
|
|
let mima = this.data.mima
|
|
console.log("点击了注册")
|
|
console.log("name", name)
|
|
console.log("zhanghao", zhanghao)
|
|
console.log("mima", mima)
|
|
//校验用户名
|
|
if (name.length < 2) {
|
|
wx.showToast({
|
|
icon: 'none',
|
|
title: '用户名至少2位',
|
|
})
|
|
return
|
|
}
|
|
if (name.length > 10) {
|
|
wx.showToast({
|
|
icon: 'none',
|
|
title: '用户名最多10位',
|
|
})
|
|
return
|
|
}
|
|
//校验账号
|
|
if (zhanghao.length < 4) {
|
|
wx.showToast({
|
|
icon: 'none',
|
|
title: '账号至少4位',
|
|
})
|
|
return
|
|
}
|
|
//校验密码
|
|
if (mima.length < 4) {
|
|
wx.showToast({
|
|
icon: 'none',
|
|
title: '密码至少4位',
|
|
})
|
|
return
|
|
}
|
|
//注册功能的实现
|
|
wx.cloud.database().collection('user').add({
|
|
data: {
|
|
user:"",//账号
|
|
pwd:"",//密码
|
|
},
|
|
success(res) {
|
|
console.log('注册成功', res)
|
|
wx.showToast({
|
|
title: '注册成功',
|
|
})
|
|
wx.navigateTo({
|
|
url: '../login/login',
|
|
})
|
|
},
|
|
fail(res) {
|
|
console.log('注册失败', res)
|
|
}
|
|
})
|
|
},
|
|
|
|
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad(options) {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
*/
|
|
onReady() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面显示
|
|
*/
|
|
onShow() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面隐藏
|
|
*/
|
|
onHide() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面卸载
|
|
*/
|
|
onUnload() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
*/
|
|
onPullDownRefresh() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面上拉触底事件的处理函数
|
|
*/
|
|
onReachBottom() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 用户点击右上角分享
|
|
*/
|
|
onShareAppMessage() {
|
|
|
|
}
|
|
}) |