user.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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. console.log(e, 'eeee')
  123. let params = {
  124. iv: e.detail.iv,
  125. encryptedData: e.detail.encryptedData,
  126. }
  127. bindPhoneApi(params).then(res => {
  128. console.log(res, 'rrr')
  129. })
  130. },
  131. loginOut() {
  132. down()
  133. logout()
  134. wx.removeStorageSync('userInfo')
  135. wx.removeStorageSync('userId')
  136. wx.removeStorageSync('token')
  137. getApp().globalData.hasLogin = false
  138. wx.switchTab({
  139. url: '/pages/mine/mine',
  140. })
  141. },
  142. logOff() {
  143. wx.showModal({
  144. title: '确认注销账号?',
  145. content: '注销账号后xxxxx',
  146. success: res => {
  147. if (res.confirm) {
  148. console.log('用户点击确定')
  149. down()
  150. logOffApi().then(res => {
  151. wx.removeStorageSync('userInfo')
  152. wx.removeStorageSync('userId')
  153. wx.removeStorageSync('token')
  154. getApp().globalData.hasLogin = false
  155. wx.switchTab({
  156. url: '/pages/mine/mine',
  157. })
  158. })
  159. } else if (res.cancel) {
  160. console.log('用户点击取消')
  161. }
  162. },
  163. })
  164. },
  165. },
  166. }
  167. </script>
  168. <style scoped lang="scss">
  169. .uesrInfo {
  170. background: #fff;
  171. overflow: hidden;
  172. padding: 0 15px;
  173. }
  174. .userPhoto {
  175. width: 74px;
  176. height: 74px;
  177. position: relative;
  178. margin: 30px auto 30px auto;
  179. position: relative;
  180. .img {
  181. width: 100%;
  182. height: 100%;
  183. border-radius: 50%;
  184. background: #dedede;
  185. }
  186. .icon {
  187. height: 20px;
  188. width: 20px;
  189. position: absolute;
  190. right: 0;
  191. bottom: 0;
  192. }
  193. }
  194. .list {
  195. // margin: 0 10px;
  196. }
  197. .right {
  198. display: flex;
  199. justify-content: center;
  200. align-items: center;
  201. }
  202. .button {
  203. display: inline-block;
  204. font-size: 11px;
  205. font-weight: 500;
  206. // width: 34px;
  207. height: 22px;
  208. border-radius: 11px;
  209. line-height: 22px;
  210. padding: 0 10px;
  211. margin-right: 5px;
  212. }
  213. .bottom {
  214. position: absolute;
  215. width: 100%;
  216. height: 18px;
  217. display: flex;
  218. justify-content: center;
  219. bottom: 0;
  220. margin-bottom: 30px;
  221. .line {
  222. width: 1px;
  223. height: 100%;
  224. background: #000;
  225. // margin: 0 30px;
  226. }
  227. .textButton {
  228. font-size: 13px;
  229. text-decoration: underline;
  230. width: 50%;
  231. text-align: center;
  232. }
  233. }
  234. </style>
  235. <style scoped>
  236. .listItem >>> .uni-list-item__extra-text {
  237. color: #000;
  238. font-size: 14px;
  239. font-weight: 600;
  240. }
  241. .userPhoto >>> .uni-file-picker__lists {
  242. display: none !important;
  243. }
  244. </style>