register.js 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. // pages/register/register.js
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. userName: null,
  8. phone: null,
  9. email: null,
  10. carNum:null,
  11. password: null,
  12. rePassword: null,
  13. checkPass: false,
  14. errorMsg: ''
  15. },
  16. /**
  17. * 生命周期函数--监听页面加载
  18. */
  19. onLoad: function(options) {
  20. //var that = this;
  21. //查看是否授权
  22. //wx.getSetting({
  23. //success(res) {
  24. //console.log(res);
  25. //if (res.authSetting['scope.userInfo']) {
  26. //that.setData({
  27. //authSet: true
  28. //});
  29. //已经授权,可以直接调用 getUserInfo 获取头像昵称
  30. //wx.getUserInfo({
  31. //success(res) {
  32. //console.log(res)
  33. //that.setData({
  34. //userInfo: res.userInfo
  35. //});
  36. //}
  37. //});
  38. //}
  39. //}
  40. //});
  41. },
  42. bindGetUserInfo(e) {
  43. //console.log(e);
  44. //console.log(e.detail.userInfo)
  45. if (wx.getUserProfile) {
  46. console.info("11111111111111111")
  47. }
  48. console.info("2222222222222222222222222222")
  49. wx.getUserProfile({
  50. desc: '用于获取用户昵称以及头像', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
  51. success: (res) => {
  52. // this.setData({
  53. // userInfo: res.userInfo,
  54. // hasUserInfo: true
  55. // })
  56. console.info("sssssssssssssssssssssssssssss")
  57. console.info(res)
  58. let {
  59. nickName: userName,
  60. gender: sex,
  61. avatarUrl: avatar
  62. } = res.userInfo;
  63. let {
  64. userName: loginName,
  65. password,
  66. phone,
  67. carNum,
  68. email
  69. } = this.data;
  70. wx.login({
  71. success(res) {
  72. //console.log(res);
  73. if (res.code) {
  74. wx.request({
  75. url: getApp().globalData.postHeadAgreement + '/restapi/wechat/register',
  76. data: {
  77. userName,
  78. sex,
  79. avatar,
  80. loginName,
  81. password,
  82. phonenumber: phone,
  83. email,
  84. license_number: carNum,
  85. code: res.code
  86. },
  87. method: 'POST',
  88. success(res1) {
  89. //console.log(res1);
  90. //console.log(res1.data.code == 1);
  91. if (res1.data.code == 1) {
  92. that.setData({
  93. errorMsg: res1.data.msg
  94. })
  95. } else {
  96. //返回该用户
  97. //跳转到上一页
  98. wx.setStorageSync("userInfo", res1.data);
  99. wx.setStorageSync("isLogin", true);
  100. wx.navigateBack();
  101. //let url = `/pages/ucenter/index/index`;
  102. //wx.redirectTo({
  103. //url
  104. //});
  105. }
  106. }
  107. });
  108. } else {
  109. console.log('登录失败!' + res.errMsg)
  110. }
  111. }
  112. });
  113. }})
  114. let that = this;
  115. },
  116. inputAccount(e) {
  117. this.setData({
  118. userName: e.detail.value
  119. });
  120. this.checkAll();
  121. },
  122. inputPassword(e) {
  123. this.setData({
  124. password: e.detail.value
  125. });
  126. this.checkAll();
  127. },
  128. inputRepassword(e) {
  129. this.setData({
  130. rePassword: e.detail.value
  131. });
  132. this.checkAll();
  133. },
  134. inputPhone(e) {
  135. this.setData({
  136. phone: e.detail.value
  137. });
  138. this.checkAll();
  139. },
  140. inputEmail(e) {
  141. this.setData({
  142. email: e.detail.value
  143. });
  144. this.checkAll();
  145. },
  146. inputCarNum(e){
  147. this.setData({
  148. carNum: e.detail.value
  149. });
  150. this.checkAll();
  151. },
  152. checkPassword() {
  153. if (!this.data.password || !this.data.rePassword || this.data.password != this.data.rePassword) {
  154. return false;
  155. }
  156. return true;
  157. },
  158. checkPhone() {
  159. if (!(/^1[3456789]\d{9}$/.test(this.data.phone))) {
  160. return false;
  161. }
  162. return true;
  163. },
  164. checkMail() {
  165. if (!(/^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.[a-zA-Z0-9]{2,6}$/.test(this.data.email))) {
  166. return false;
  167. }
  168. return true;
  169. },
  170. checkCarNum(){
  171. if (this.data.carNum){
  172. 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))) {
  173. return false;
  174. }
  175. }
  176. return true;
  177. },
  178. checkAll() {
  179. if (!this.data.userName || !this.data.userName.replace(/(^\s*)|(\s*$)/g,"")) {
  180. this.setData({
  181. errorMsg: '账号不能为空'
  182. });
  183. this.setData({
  184. checkPass: false
  185. });
  186. return;
  187. } else if (this.data.userName.length < 2 || this.data.userName.length > 20) {
  188. this.setData({
  189. errorMsg: '账号长度应为2-20'
  190. });
  191. this.setData({
  192. checkPass: false
  193. });
  194. return;
  195. } else if (!(/^[a-zA-Z0-9_.\u4e00-\u9fa5]+$/.test(this.data.userName))) {
  196. this.setData({
  197. errorMsg: '账号只能包含字母、数字、中文、下划线和点'
  198. });
  199. this.setData({
  200. checkPass: false
  201. });
  202. return;
  203. }else{
  204. this.setData({
  205. errorMsg: ''
  206. });
  207. }
  208. if (!this.checkPhone()) {
  209. this.setData({
  210. errorMsg: '手机号输入有误,请重新输入'
  211. });
  212. this.setData({
  213. checkPass: false
  214. });
  215. return;
  216. } else {
  217. this.setData({
  218. errorMsg: ''
  219. });
  220. }
  221. // if (!this.checkMail()) {
  222. // this.setData({
  223. // errorMsg: '邮箱输入有误,请重新输入'
  224. // });
  225. // this.setData({
  226. // checkPass: false
  227. // });
  228. // return;
  229. // } else {
  230. // this.setData({
  231. // errorMsg: ''
  232. // });
  233. // }
  234. if (!this.checkCarNum()) {
  235. this.setData({
  236. errorMsg: '车牌号输入有误,请重新输入'
  237. });
  238. this.setData({
  239. checkPass: false
  240. });
  241. return;
  242. } else {
  243. this.setData({
  244. errorMsg: ''
  245. });
  246. }
  247. if (this.data.password && (this.data.password.length < 5 || this.data.password.length > 20)) {
  248. this.setData({
  249. errorMsg: '密码长度应为5-20'
  250. });
  251. this.setData({
  252. checkPass: false
  253. });
  254. return;
  255. }
  256. // if (!this.checkPassword()) {
  257. // this.setData({
  258. // errorMsg: '两次密码输入不一致,请重新输入'
  259. // });
  260. // this.setData({
  261. // checkPass: false
  262. // });
  263. // return;
  264. // } else {
  265. // this.setData({
  266. // errorMsg: ''
  267. // });
  268. // }
  269. this.setData({
  270. checkPass: true
  271. });
  272. },
  273. /**
  274. * 生命周期函数--监听页面初次渲染完成
  275. */
  276. onReady: function() {
  277. },
  278. /**
  279. * 生命周期函数--监听页面显示
  280. */
  281. onShow: function() {
  282. },
  283. /**
  284. * 生命周期函数--监听页面隐藏
  285. */
  286. onHide: function() {
  287. },
  288. /**
  289. * 生命周期函数--监听页面卸载
  290. */
  291. onUnload: function() {
  292. },
  293. /**
  294. * 页面相关事件处理函数--监听用户下拉动作
  295. */
  296. onPullDownRefresh: function() {
  297. },
  298. /**
  299. * 页面上拉触底事件的处理函数
  300. */
  301. onReachBottom: function() {
  302. },
  303. /**
  304. * 用户点击右上角分享
  305. */
  306. onShareAppMessage: function() {
  307. }
  308. })