user.vue 5.0 KB

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