let register = new Vue({ el: '#min', data: { registerData: { "nickName": '', "account": '', "uin": '', "password": '', "Cpassword": '', "code": '' }, Tips: { "title": '', "content": '' }, Tips_open: false, visibility: false, // 主题 默认白色: white 黑色: black theme: "white", }, created() { let theme = localStorage.getItem('theme') if (theme) { this.theme = theme } }, methods: { register() { const _this = this nickName = this.registerData.nickName account = this.registerData.account uin = this.registerData.uin password = this.registerData.password Cpassword = this.registerData.Cpassword code = this.registerData.code if (!nickName) { this.Tips.title = "请输入完整!" this.Tips.content = "请输入昵称!" this.Tips_open = true return false } if (!/^.{2,8}$/.test(nickName)) { this.Tips.title = "请输入完整!" this.Tips.content = "昵称只能2到8个字符!" this.Tips_open = true return false } if (!account) { this.Tips.title = "请输入完整!" this.Tips.content = "请输入账号!" this.Tips_open = true return false } if (!/^.{6,16}$/.test(account)) { this.Tips.title = "请输入完整!" this.Tips.content = "账号只能6到16个字符!" this.Tips_open = true return false } if (!uin) { this.Tips.title = "请输入完整!" this.Tips.content = "请输入绑定QQ!" this.Tips_open = true return false } if (!/[1-9][0-9]{4,}/.test(uin)) { this.Tips.title = "请输入完整!" this.Tips.content = "请输入正确的QQ号!" this.Tips_open = true return false } if (!password) { this.Tips.title = "请输入完整!" this.Tips.content = "请输入密码!" this.Tips_open = true return false } if (!/^.{6,16}$/.test(password)) { this.Tips.title = "请输入完整!" this.Tips.content = "密码只能6到16个字符!" this.Tips_open = true return false } if (!Cpassword) { this.Tips.title = "请输入完整!" this.Tips.content = "请输入确认密码!" this.Tips_open = true return false } if (password != Cpassword) { this.Tips.title = "请输入完整!" this.Tips.content = "输入的两次密码不一致!" this.Tips_open = true return false } if (!code) { this.Tips.title = "请输入完整!" this.Tips.content = "请输入验证码!" this.Tips_open = true return false } //ajax提交数据 $.ajax({ url: "/data/api/user/?type=register", type: "POST", data: { "nickName": nickName, "account": account, "uin": uin, "password": password, "Cpassword": Cpassword, "code": code, }, dataType: "json", error: function (error) { _this.Tips.title = "登录失败" _this.Tips.content = "网络异常" _this.Tips_open = true // 刷新验证码 $("#code_img").attr('src', src = '/data/api/code/?type=userRegisterCode&' + Math.random()); _this.loginData.code = '' console.log(error) }, success: function (data) { if (data.code == "0") { _this.Tips.title = "注册成功" _this.Tips.content = "注册成功,正在进行跳转登录..." _this.Tips_open = true setTimeout(function () { location.href = "./"; }, 1e3) } else { _this.Tips.title = "注册失败" _this.Tips.content = data.msg _this.Tips_open = true // 刷新验证码 $("#code_img").attr('src', src = '/data/api/code/?type=userRegisterCode&' + Math.random()); _this.loginData.code = '' } } }) }, // 切换主题 switch_theme() { if (this.theme == 'white') { this.theme = 'black' localStorage.setItem('theme', 'black'); } else { this.theme = 'white' localStorage.setItem('theme', 'white'); } } }, mounted: function () { //检测回车 const _this = this; var isClick = true; $(document).keypress(function (event) { if (isClick) { isClick = false; var keynum = (event.keyCode ? event.keyCode : event.which); if (keynum == '13') { _this.register(); } setTimeout(function () { isClick = true; }, 2000); } }); } });