user.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. <template>
  2. <view class="container">
  3. <view class="uesrInfo">
  4. <view class="userPhoto">
  5. <image class="img" :src="userInfo.avatar"></image>
  6. <uni-file-picker
  7. ref="picker"
  8. class="picker"
  9. limit="1"
  10. mode="list"
  11. file-mediatype="image"
  12. @select="select"
  13. @progress="progress"
  14. @success="success"
  15. @fail="fail"
  16. >
  17. <image class="icon" :src="$fileUrl() + '/mine/icon1.png'" mode="widthFix"></image>
  18. </uni-file-picker>
  19. </view>
  20. <uni-list class="list">
  21. <uni-list-item
  22. class="listItem"
  23. title="用户昵称"
  24. :rightText="userInfo.nickname"
  25. showArrow
  26. clickable
  27. @click="editName"
  28. />
  29. <uni-list-item class="listItem" title="手机号" :rightText="userInfo.mobile">
  30. <template v-slot:footer>
  31. <view class="right">
  32. <button class="m_button button" open-type="getPhoneNumber" @getphonenumber="decryptPhoneNumber">
  33. <!-- <span v-if="userInfo.mobile">更换</span> -->
  34. <span>绑定</span>
  35. </button>
  36. <span>{{ userInfo.mobile }}</span>
  37. </view>
  38. </template>
  39. </uni-list-item>
  40. </uni-list>
  41. </view>
  42. <view class="bottom">
  43. <view class="textButton textColor5" @click="logOff">注销账号</view>
  44. <view class="line"></view>
  45. <view class="textButton" @click="loginOut">退出登录</view>
  46. </view>
  47. </view>
  48. </template>
  49. <script>
  50. import { logOffApi, bindPhoneApi, userInfoApi, profileApi } from '@/api/user.js'
  51. import { uploadApi } from '@/api/common.js'
  52. export default {
  53. data() {
  54. return {
  55. userInfo: {},
  56. }
  57. },
  58. onShow() {
  59. this.getUserInfo()
  60. },
  61. methods: {
  62. // 获取上传状态
  63. select(e) {
  64. let _this = this
  65. console.log('选择文件:', e)
  66. // let file = e.tempFiles[0]
  67. wx.uploadFile({
  68. url: 'https://mall.rongtongh.cn/wx/storage/upload',
  69. filePath: e.tempFilePaths[0],
  70. name: 'file',
  71. success: function (res) {
  72. let data = JSON.parse(res.data)
  73. console.log(data, 'data')
  74. _this.save(data.data.url, '')
  75. _this.$refs.picker.clearFiles()
  76. },
  77. })
  78. },
  79. // 获取上传进度
  80. progress(e) {
  81. console.log('上传进度:', e)
  82. },
  83. // 上传成功
  84. success(e) {
  85. console.log(e, '上传成功')
  86. },
  87. // 上传失败
  88. fail(e) {
  89. console.log('上传失败:', e)
  90. },
  91. editName() {
  92. // 修改用户名称
  93. wx.navigateTo({
  94. url: '/pages/user/editUser/editUser',
  95. })
  96. },
  97. save(url) {
  98. let _this = this
  99. let params = {
  100. avatarUrl: url,
  101. }
  102. profileApi(params).then(res => {
  103. console.log(res, 'res')
  104. wx.showToast({
  105. title: '修改成功',
  106. })
  107. this.getUserInfo()
  108. })
  109. },
  110. getUserInfo() {
  111. userInfoApi().then(res => {
  112. this.userInfo = res.data
  113. console.log(this.userInfo, '用户信息')
  114. })
  115. },
  116. decryptPhoneNumber(e) {
  117. console.log(e, 'eeee')
  118. let params = {
  119. iv: e.detail.iv,
  120. encryptedData: e.detail.encryptedData,
  121. }
  122. bindPhoneApi(params).then(res => {
  123. console.log(res, 'rrr')
  124. })
  125. },
  126. loginOut() {
  127. wx.removeStorageSync('userInfo')
  128. wx.removeStorageSync('userId')
  129. wx.removeStorageSync('token')
  130. getApp().globalData.hasLogin = false
  131. wx.switchTab({
  132. url: '/pages/mine/mine',
  133. })
  134. },
  135. logOff() {
  136. wx.showModal({
  137. title: '确认注销账号?',
  138. content: '注销账号后xxxxx',
  139. success: res => {
  140. if (res.confirm) {
  141. console.log('用户点击确定')
  142. logOffApi().then(res => {
  143. wx.removeStorageSync('userInfo')
  144. wx.removeStorageSync('userId')
  145. wx.removeStorageSync('token')
  146. getApp().globalData.hasLogin = false
  147. wx.switchTab({
  148. url: '/pages/mine/mine',
  149. })
  150. })
  151. } else if (res.cancel) {
  152. console.log('用户点击取消')
  153. }
  154. },
  155. })
  156. },
  157. },
  158. }
  159. </script>
  160. <style scoped lang="scss">
  161. .uesrInfo {
  162. background: #fff;
  163. overflow: hidden;
  164. padding: 0 15px;
  165. }
  166. .userPhoto {
  167. width: 74px;
  168. height: 74px;
  169. position: relative;
  170. margin: 30px auto 30px auto;
  171. position: relative;
  172. .img {
  173. width: 100%;
  174. height: 100%;
  175. border-radius: 50%;
  176. background: #dedede;
  177. }
  178. .icon {
  179. height: 20px;
  180. width: 20px;
  181. position: absolute;
  182. right: 0;
  183. bottom: 0;
  184. }
  185. }
  186. .list {
  187. // margin: 0 10px;
  188. }
  189. .right {
  190. display: flex;
  191. justify-content: center;
  192. align-items: center;
  193. }
  194. .button {
  195. display: inline-block;
  196. font-size: 11px;
  197. font-weight: 500;
  198. // width: 34px;
  199. height: 22px;
  200. border-radius: 11px;
  201. line-height: 22px;
  202. padding: 0 10px;
  203. margin-right: 5px;
  204. }
  205. .bottom {
  206. position: absolute;
  207. width: 100%;
  208. height: 18px;
  209. display: flex;
  210. justify-content: center;
  211. bottom: 0;
  212. margin-bottom: 30px;
  213. .line {
  214. width: 1px;
  215. height: 100%;
  216. background: #000;
  217. // margin: 0 30px;
  218. }
  219. .textButton {
  220. font-size: 13px;
  221. text-decoration: underline;
  222. width: 50%;
  223. text-align: center;
  224. }
  225. }
  226. </style>
  227. <style scoped>
  228. .listItem >>> .uni-list-item__extra-text {
  229. color: #000;
  230. font-size: 14px;
  231. font-weight: 600;
  232. }
  233. .userPhoto >>> .uni-file-picker__lists {
  234. display: none !important;
  235. }
  236. </style>