user.vue 5.7 KB

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