123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337 |
- // pages/register/register.js
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- userName: null,
- phone: null,
- email: null,
- carNum:null,
- password: null,
- rePassword: null,
- checkPass: false,
- errorMsg: ''
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function(options) {
- //var that = this;
- //查看是否授权
- //wx.getSetting({
- //success(res) {
- //console.log(res);
- //if (res.authSetting['scope.userInfo']) {
- //that.setData({
- //authSet: true
- //});
- //已经授权,可以直接调用 getUserInfo 获取头像昵称
- //wx.getUserInfo({
- //success(res) {
- //console.log(res)
- //that.setData({
- //userInfo: res.userInfo
- //});
- //}
- //});
- //}
- //}
- //});
- },
- bindGetUserInfo(e) {
- //console.log(e);
- //console.log(e.detail.userInfo)
- if (wx.getUserProfile) {
- console.info("11111111111111111")
- }
- console.info("2222222222222222222222222222")
- wx.getUserProfile({
- desc: '用于获取用户昵称以及头像', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
- success: (res) => {
- // this.setData({
- // userInfo: res.userInfo,
- // hasUserInfo: true
- // })
- console.info("sssssssssssssssssssssssssssss")
- console.info(res)
- let {
- nickName: userName,
- gender: sex,
- avatarUrl: avatar
- } = res.userInfo;
- let {
- userName: loginName,
- password,
- phone,
- carNum,
- email
- } = this.data;
- wx.login({
- success(res) {
- //console.log(res);
- if (res.code) {
- wx.request({
- url: getApp().globalData.postHeadAgreement + '/restapi/wechat/register',
- data: {
- userName,
- sex,
- avatar,
- loginName,
- password,
- phonenumber: phone,
- email,
- license_number: carNum,
- code: res.code
- },
- method: 'POST',
- success(res1) {
- //console.log(res1);
- //console.log(res1.data.code == 1);
- if (res1.data.code == 1) {
- that.setData({
- errorMsg: res1.data.msg
- })
- } else {
- //返回该用户
- //跳转到上一页
- wx.setStorageSync("userInfo", res1.data);
- wx.setStorageSync("isLogin", true);
- wx.navigateBack();
- //let url = `/pages/ucenter/index/index`;
- //wx.redirectTo({
- //url
- //});
- }
- }
- });
- } else {
- console.log('登录失败!' + res.errMsg)
- }
- }
- });
-
- }})
- let that = this;
- },
- inputAccount(e) {
- this.setData({
- userName: e.detail.value
- });
- this.checkAll();
- },
- inputPassword(e) {
- this.setData({
- password: e.detail.value
- });
- this.checkAll();
- },
- inputRepassword(e) {
- this.setData({
- rePassword: e.detail.value
- });
- this.checkAll();
- },
- inputPhone(e) {
- this.setData({
- phone: e.detail.value
- });
- this.checkAll();
- },
- inputEmail(e) {
- this.setData({
- email: e.detail.value
- });
- this.checkAll();
- },
- inputCarNum(e){
- this.setData({
- carNum: e.detail.value
- });
- this.checkAll();
- },
- checkPassword() {
- if (!this.data.password || !this.data.rePassword || this.data.password != this.data.rePassword) {
- return false;
- }
- return true;
- },
- checkPhone() {
- if (!(/^1[3456789]\d{9}$/.test(this.data.phone))) {
- return false;
- }
- return true;
- },
- checkMail() {
- if (!(/^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.[a-zA-Z0-9]{2,6}$/.test(this.data.email))) {
- return false;
- }
- return true;
- },
- checkCarNum(){
- if (this.data.carNum){
- if (!(/^(([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-Z](([0-9]{5}[DF])|([DF]([A-HJ-NP-Z0-9])[0-9]{4})))|([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-Z][A-HJ-NP-Z0-9]{4}[A-HJ-NP-Z0-9挂学警港澳使领]))$/.test(this.data.carNum))) {
- return false;
- }
- }
- return true;
- },
- checkAll() {
- if (!this.data.userName || !this.data.userName.replace(/(^\s*)|(\s*$)/g,"")) {
- this.setData({
- errorMsg: '账号不能为空'
- });
- this.setData({
- checkPass: false
- });
- return;
- } else if (this.data.userName.length < 2 || this.data.userName.length > 20) {
- this.setData({
- errorMsg: '账号长度应为2-20'
- });
- this.setData({
- checkPass: false
- });
- return;
- } else if (!(/^[a-zA-Z0-9_.\u4e00-\u9fa5]+$/.test(this.data.userName))) {
- this.setData({
- errorMsg: '账号只能包含字母、数字、中文、下划线和点'
- });
- this.setData({
- checkPass: false
- });
- return;
- }else{
- this.setData({
- errorMsg: ''
- });
- }
- if (!this.checkPhone()) {
- this.setData({
- errorMsg: '手机号输入有误,请重新输入'
- });
- this.setData({
- checkPass: false
- });
- return;
- } else {
- this.setData({
- errorMsg: ''
- });
- }
- // if (!this.checkMail()) {
- // this.setData({
- // errorMsg: '邮箱输入有误,请重新输入'
- // });
- // this.setData({
- // checkPass: false
- // });
- // return;
- // } else {
- // this.setData({
- // errorMsg: ''
- // });
- // }
- if (!this.checkCarNum()) {
- this.setData({
- errorMsg: '车牌号输入有误,请重新输入'
- });
- this.setData({
- checkPass: false
- });
- return;
- } else {
- this.setData({
- errorMsg: ''
- });
- }
- if (this.data.password && (this.data.password.length < 5 || this.data.password.length > 20)) {
- this.setData({
- errorMsg: '密码长度应为5-20'
- });
- this.setData({
- checkPass: false
- });
- return;
- }
- // if (!this.checkPassword()) {
- // this.setData({
- // errorMsg: '两次密码输入不一致,请重新输入'
- // });
- // this.setData({
- // checkPass: false
- // });
- // return;
- // } else {
- // this.setData({
- // errorMsg: ''
- // });
- // }
- this.setData({
- checkPass: true
- });
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function() {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function() {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function() {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function() {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function() {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function() {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function() {
- }
- })
|