sign.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. // pages/sign/sign.js
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. code:"",//储存微信传过来的code
  8. number:"",
  9. },
  10. verification:function(e){
  11. var that = this
  12. that.data.number = e.detail.value
  13. },
  14. //登录功能
  15. sign:function(){
  16. var that = this
  17. var trys = /^1[3-9][0-9]{9}$/
  18. var number = that.data.number
  19. if(number == "") {
  20. wx.showModal({
  21. title:'提示',
  22. showCancel:false,
  23. content:'请输入手机号'
  24. })
  25. }
  26. else if(trys.test(number) == false){
  27. wx.showModal({
  28. title:'提示',
  29. showCancel:false,
  30. content:'请输入正确的手机号'
  31. })
  32. }
  33. else {
  34. wx.login({
  35. success:function(e){
  36. console.log(e.code)
  37. wx.request({
  38. url: 'http://110.40.223.170:8120/api/minigrogram/lightcontrol/login',
  39. method:'POST',
  40. data:{
  41. code:e.code,
  42. phone:that.data.number
  43. },
  44. header:{"Content-Type": "application/json"},
  45. success:function(res){
  46. if(res.data.code == 200){
  47. wx.setStorageSync('token', res.data.data.access_token)
  48. let creatime = new Date()
  49. wx.setStorageSync('time',creatime)
  50. wx.switchTab({
  51. url: '/pages/scene/scene',
  52. })
  53. }
  54. else{
  55. console.log('登录失败')
  56. }
  57. }
  58. })
  59. }
  60. })
  61. }
  62. },
  63. /**
  64. * 生命周期函数--监听页面加载
  65. */
  66. onLoad(options) {
  67. },
  68. /**
  69. * 生命周期函数--监听页面初次渲染完成
  70. */
  71. onReady() {
  72. },
  73. /**
  74. * 生命周期函数--监听页面显示
  75. */
  76. onShow() {
  77. },
  78. /**
  79. * 生命周期函数--监听页面隐藏
  80. */
  81. onHide() {
  82. },
  83. /**
  84. * 生命周期函数--监听页面卸载
  85. */
  86. onUnload() {
  87. },
  88. /**
  89. * 页面相关事件处理函数--监听用户下拉动作
  90. */
  91. onPullDownRefresh() {
  92. },
  93. /**
  94. * 页面上拉触底事件的处理函数
  95. */
  96. onReachBottom() {
  97. },
  98. /**
  99. * 用户点击右上角分享
  100. */
  101. onShareAppMessage() {
  102. }
  103. })