userchange.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. // pages/userchange/userchange.js
  2. const {upLoad} = require('../../utils/util');
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. avatarUrl:'',
  9. nickName:'',
  10. phoneNumber:'',
  11. password:'',
  12. personalSignatrue:'编辑个性签名,展示我的独特态度'
  13. },
  14. /**
  15. * 生命周期函数--监听页面加载
  16. */
  17. onLoad(options) {
  18. var that = this;
  19. wx.getStorage({
  20. key: 'nickName',
  21. success (res) {
  22. that.setData({
  23. nickName:res.data
  24. })
  25. }
  26. })
  27. wx.getStorage({
  28. key: 'avatarUrl',
  29. success (res) {
  30. that.setData({
  31. avatarUrl:res.data
  32. })
  33. }
  34. })
  35. },
  36. /**
  37. * 生命周期函数--监听页面初次渲染完成
  38. */
  39. onReady() {
  40. },
  41. /**
  42. * 生命周期函数--监听页面显示
  43. */
  44. onShow() {
  45. },
  46. /**
  47. * 生命周期函数--监听页面隐藏
  48. */
  49. onHide() {
  50. },
  51. /**
  52. * 生命周期函数--监听页面卸载
  53. */
  54. onUnload() {
  55. },
  56. /**
  57. * 页面相关事件处理函数--监听用户下拉动作
  58. */
  59. onPullDownRefresh() {
  60. },
  61. /**
  62. * 页面上拉触底事件的处理函数
  63. */
  64. onReachBottom() {
  65. },
  66. /**
  67. * 用户点击右上角分享
  68. */
  69. onShareAppMessage() {
  70. },
  71. chooseImage() {
  72. wx.chooseImage({
  73. count: 1,//可选择图片数量
  74. sizeType: ['compressed'],//压缩图片
  75. sourceType: ['album','camera'],//来源
  76. success: (res) => {
  77. this.uploadImage(res.tempFilePaths[0]);
  78. }
  79. })
  80. },
  81. uploadImage(imagePath){
  82. upLoad( imagePath ).then((res) => {
  83. console.log(res);
  84. this.setData({
  85. avatarUrl: res.Url
  86. });
  87. wx.setStorage({
  88. key: 'avatarUrl',
  89. data: res.Url,
  90. success: function() {
  91. console.log('写入avatarUrl缓存成功')
  92. },
  93. fail:function() {
  94. console.log('写入avatarUrl发生错误')
  95. }
  96. });
  97. })
  98. },
  99. onChangeUsername:function(e){
  100. wx.setStorage({
  101. key: 'nickName',
  102. data: e.detail,
  103. success: function() {
  104. console.log('写入nickName缓存成功')
  105. },
  106. fail:function() {
  107. console.log('写入nickName发生错误')
  108. }
  109. })
  110. },
  111. onChangePhonenumber:function(e){
  112. wx.setStorage({
  113. key: 'phoneNumber',
  114. data: e.detail,
  115. success: function() {
  116. console.log('写入phoneNumber缓存成功')
  117. },
  118. fail:function() {
  119. console.log('写入phoneNumber发生错误')
  120. }
  121. })
  122. },
  123. onChangePassword: function(e) {
  124. wx.setStorage({
  125. key: 'password',
  126. data: e.detail,
  127. success: function() {
  128. console.log('写入password缓存成功')
  129. },
  130. fail:function() {
  131. console.log('写入password发生错误')
  132. }
  133. })
  134. },
  135. onChangePersonalSignatrue: function(e) {
  136. wx.setStorage({
  137. key: 'personalSignatrue',
  138. data: e.detail,
  139. success: function() {
  140. console.log('写入personalSignatrue缓存成功')
  141. },
  142. fail:function() {
  143. console.log('写入personalSignatrue发生错误')
  144. }
  145. })
  146. },
  147. changeInfo:function(){
  148. var avatarUrl = wx.getStorageSync('avatarUrl');
  149. var nickName = wx.getStorageSync('nickName');
  150. var phoneNumber = wx.getStorageSync('phoneNumber');
  151. var personalSignatrue = wx.getStorageSync('personalSignatrue');
  152. wx.request({
  153. url: 'http://192.168.31.28:8084/user/modify',
  154. method: 'POST',
  155. data: {
  156. "avatar": avatarUrl,
  157. "name": nickName,
  158. "phone": phoneNumber,
  159. "uid": 1,
  160. },
  161. success (res) {
  162. console.log(res)
  163. }
  164. })
  165. }
  166. })