register.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. // pages/register.js
  2. const app = getApp()
  3. const defaultAvatarUrl = 'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0'
  4. const {upLoad} = require('../../utils/util');
  5. var clientWidth = wx.getSystemInfoSync().windowWidth;
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. avatarUrl: defaultAvatarUrl,
  12. theme: wx.getSystemInfoSync().theme,
  13. },
  14. /**
  15. * 生命周期函数--监听页面加载
  16. */
  17. /**
  18. * 生命周期函数--监听页面初次渲染完成
  19. */
  20. onReady() {
  21. },
  22. /**
  23. * 生命周期函数--监听页面显示
  24. */
  25. onShow() {
  26. },
  27. /**
  28. * 生命周期函数--监听页面隐藏
  29. */
  30. onHide() {
  31. },
  32. /**
  33. * 生命周期函数--监听页面卸载
  34. */
  35. onUnload() {
  36. },
  37. /**
  38. * 页面相关事件处理函数--监听用户下拉动作
  39. */
  40. onPullDownRefresh() {
  41. },
  42. /**
  43. * 页面上拉触底事件的处理函数
  44. */
  45. onReachBottom() {
  46. },
  47. /**
  48. * 用户点击右上角分享
  49. */
  50. onShareAppMessage() {
  51. },
  52. onLoad() {
  53. this.setData({
  54. left:clientWidth/2-40+'px'
  55. })
  56. wx.onThemeChange((result) => {
  57. this.setData({
  58. theme: result.theme
  59. })
  60. })
  61. },
  62. // onChooseAvatar(e) {
  63. // const { avatarUrl } = e.detail
  64. // this.setData({
  65. // avatarUrl,
  66. // })
  67. // },
  68. onChooseAvatar1(){
  69. wx.chooseImage({
  70. count: 1,//可选择图片数量
  71. sizeType: ['compressed'],//压缩图片
  72. sourceType: ['album','camera'],//来源
  73. success: (res) => {
  74. this.uploadImage(res.tempFilePaths[0]);
  75. }
  76. })
  77. },
  78. uploadImage(imagePath){
  79. upLoad( imagePath ).then((res) => {
  80. console.log(res);
  81. this.setData({
  82. avatarUrl: res.Url
  83. });
  84. wx.setStorage({
  85. key: 'avatarUrl',
  86. data: res.Url,
  87. success: function() {
  88. console.log('写入avatarUrl缓存成功')
  89. },
  90. fail:function() {
  91. console.log('写入avatarUrl发生错误')
  92. }
  93. });
  94. })
  95. },
  96. onInputUsername:function(e){
  97. console.log(e);
  98. wx.setStorage({
  99. key: 'nickName',
  100. data: e.detail.value,
  101. success: function() {
  102. console.log('写入nickName缓存成功')
  103. },
  104. fail:function() {
  105. console.log('写入nickName发生错误')
  106. }
  107. })
  108. },
  109. register(){
  110. var avatar = wx.getStorageSync('avatarUrl');
  111. var name = wx.getStorageSync('nickName');
  112. console.log(avatar);
  113. console.log(name);
  114. wx.request({
  115. url: 'http://192.168.31.29:8084/user/register',
  116. method: 'POST',
  117. data: {
  118. avatar: avatar,
  119. name: name,
  120. vid: wx.getStorageSync('vid'),
  121. phone: '',
  122. sign: '',
  123. },
  124. success(res){
  125. console.log(res);
  126. wx.request({
  127. url: 'http://192.168.31.29:8084/user/login',
  128. method: 'POST',
  129. header: {
  130. 'content-type': 'application/x-www-form-urlencoded'
  131. },
  132. data:{
  133. vid: wx.getStorageSync('vid')
  134. },
  135. success(res){
  136. console.log(res);
  137. wx.setStorageSync('token', res.data.data.token);
  138. wx.setStorageSync('uid', res.data.data.Uid);
  139. wx.switchTab({
  140. url: '/pages/home/home',
  141. })
  142. }
  143. })
  144. }
  145. })
  146. }
  147. })