From 5c3f69b4059bbe806be4b00dca0ae864d7391d7b Mon Sep 17 00:00:00 2001 From: lqz <2426350504@qq.com> Date: Fri, 18 Nov 2022 20:47:32 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- code4.txt | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 code4.txt diff --git a/code4.txt b/code4.txt new file mode 100644 index 0000000..6966f83 --- /dev/null +++ b/code4.txt @@ -0,0 +1,90 @@ +Page({ + data: { + name: '', + account: '', + password: '' + }, + //获取用户名 + getName(event) { + console.log('获取输入的用户名', event.detail.value) + this.setData({ + name: event.detail.value + }) + }, + //获取用户账号 + getAccount(event) { + console.log('获取输入的账号', event.detail.value) + this.setData({ + account: event.detail.value + }) + }, + // 获取密码 + getPassword(event) { + console.log('获取输入的密码', event.detail.value) + this.setData({ + password: event.detail.value + }) + }, + + //注册 + zhuce1() { + let name = this.data.name + let account = this.data.account + let password = this.data.password + console.log("点击了注册") + console.log("name", name) + console.log("account", account) + console.log("password", password) + //校验用户名 + if (name.length < 2) { + wx.showToast({ + icon: 'none', + title: '用户名至少2位', + }) + return + } + if (name.length > 10) { + wx.showToast({ + icon: 'none', + title: '用户名最多10位', + }) + return + } + //校验账号 + 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').add({ + data: { + name: name, + account: account, + password: password + }, + success(res) { + console.log('注册成功', res) + wx.showToast({ + title: '注册成功', + }) + wx.navigateTo({ + url: '../adlogin/adlogin', + }) + }, + fail(res) { + console.log('注册失败', res) + } + }) + } + }) \ No newline at end of file