user.vue 5.5 KB

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