diff --git a/code8.txt b/code8.txt new file mode 100644 index 0000000..85b3ead --- /dev/null +++ b/code8.txt @@ -0,0 +1,82 @@ +// pages/adlogin/adlogin.js +Page({ + data: { + account:'', + password:'' + }, + + //获取输入的账号 + getAccount(evt) { + //console.log('账号', evt.detail.value) + this.setData({ + account: evt.detail.value + }) + }, + + //获取管理员输入的密码 + getPassword(event) { + // console.log('密码', event.detail.value) + this.setData({ + password: event.detail.value + }) + }, + +//点击管理员登陆 + guanliyuanlogin() { + + let account = this.data.account + let password = this.data.password + console.log('管理员账号', account, '管理员密码', password) + if (account.length < 4) { + wx.showToast({ + icon: 'none', + title: '账号至少4位', + }) + return + } + if (password.length < 4) { + wx.showToast({ + icon: 'none', + title: '密码至少4位', + }) + return + } + + + //管理员登陆 + wx.cloud.database().collection('user').where({ + account: account + }).get({ + success(res) { + console.log("获取数据成功", res) + let manager = res.data[0] + console.log("manager", manager) + if (password == manager.password) { + console.log('登陆成功') + wx.showToast({ + title: '登陆成功', + }) + // wx.navigateTo({ + // url: '../home/home?name=' + user.name, + // }) + wx.navigateTo({ + url: '/pages/me1/me1', + }) + //保存管理员登陆状态 + wx.setStorageSync('manager', manager) + } else { + console.log('登陆失败') + wx.showToast({ + icon: 'none', + title: '账号或密码不正确', + }) + } + }, + fail(res) { + console.log("获取数据失败", res) + } + }) + + } + + }) \ No newline at end of file