index.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // pages/start/index.js
  2. const app = getApp();
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. phone: "",
  8. data: {
  9. id: "",
  10. userInfo: {
  11. phone: ""
  12. },
  13. },
  14. onLoad(e) {
  15. const that = this;
  16. // 获取用户信息
  17. wx.getSetting({
  18. success: r => {
  19. if (!r.authSetting['scope.userInfo']) return
  20. // 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
  21. wx.getUserInfo({
  22. success: res => {
  23. const p = {
  24. ...res.userInfo
  25. };
  26. app.globalData.userInfo = p;
  27. that.setData({
  28. userInfo: p
  29. })
  30. }
  31. })
  32. }
  33. })
  34. },
  35. bindgetuserinfo(data) {
  36. app.globalData.userInfo = {
  37. ...(app.globalData.userInfo || {}),
  38. ...(data.detail.userInfo || {})
  39. }
  40. this.setData({
  41. userInfo: app.globalData.userInfo
  42. })
  43. },
  44. goSign() {
  45. if (!this.phone) return wx.showToast({
  46. title: '请输入正确的手机号',
  47. icon: "none"
  48. })
  49. app.globalData.userInfo.phone = this.phone;
  50. wx.showLoading()
  51. wx.cloud.callFunction({
  52. name: "quickstartFunctions",
  53. data: {
  54. type: "createUser",
  55. data: app.globalData.userInfo
  56. }
  57. }).then(res => {
  58. wx.hideLoading({
  59. success: (res) => {
  60. wx.redirectTo({
  61. url: '/pages/select/index',
  62. })
  63. },
  64. })
  65. }).catch(err => {
  66. wx.hideLoading({
  67. success: (res) => {
  68. wx.showToast({
  69. title: '服务走丢了~',
  70. icon: "none"
  71. })
  72. },
  73. })
  74. })
  75. },
  76. phoneNum(e) {
  77. if (!/1[0-9]{10}/.test(e.detail.value)) return
  78. this.phone = e.detail.value || 0
  79. }
  80. })