profile.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. <template>
  2. <view class="profile-container">
  3. <view class="profile-header">个人信息</view>
  4. <view class="profile-list">
  5. <!-- 头像 -->
  6. <view class="profile-item" @click="chooseAvatar">
  7. <view class="item-label">头像</view>
  8. <image class="avatar" :src="avatarUrl" mode="aspectFill" />
  9. <text class="arrow">›</text>
  10. </view>
  11. <!-- 昵称 -->
  12. <view class="profile-item" @click="editNickname">
  13. <view class="item-label">昵称</view>
  14. <view class="item-value">{{ nickname }}</view>
  15. <text class="arrow">›</text>
  16. </view>
  17. <!-- 更换手机号 -->
  18. <view class="profile-item" @click="goToChangePhone">
  19. <view class="item-label">更换手机号</view>
  20. <view class="item-value">{{ phone }}</view>
  21. <text class="arrow">›</text>
  22. </view>
  23. <!-- 微信绑定(可选) -->
  24. <view class="profile-item" @click="goToUnbindWechat">
  25. <view class="item-label">解绑微信</view>
  26. <image src="/static/wechat.png" class="wechat-icon" />
  27. <view class="item-value">{{ wechatName }}</view>
  28. <text class="arrow">›</text>
  29. </view>
  30. <!-- 设置密码 -->
  31. <view class="profile-item" @click="goToSetPassword">
  32. <view class="item-label">设置密码</view>
  33. <text class="arrow">›</text>
  34. </view>
  35. <!-- 账号注销 -->
  36. <view class="profile-item" @click="goToCancelAccount">
  37. <view class="item-label">账号注销</view>
  38. <text class="arrow">›</text>
  39. </view>
  40. </view>
  41. <!-- 昵称编辑弹窗 -->
  42. <view v-if="showNicknamePopup" class="popup-mask">
  43. <view class="popup-content">
  44. <input v-model="editNicknameValue" placeholder="请输入新昵称" />
  45. <view class="popup-btns">
  46. <button @click="showNicknamePopup=false">取消</button>
  47. <button @click="saveNickname">保存</button>
  48. </view>
  49. </view>
  50. </view>
  51. </view>
  52. </template>
  53. <script>
  54. export default {
  55. data() {
  56. return {
  57. avatarUrl: '',
  58. nickname: '',
  59. phone: '',
  60. wechatName: '',
  61. editNicknameValue: '',
  62. showNicknamePopup: false
  63. }
  64. },
  65. onLoad() {
  66. this.getUserInfo()
  67. },
  68. methods: {
  69. async getUserInfo() {
  70. const uid = uni.getStorageSync('uid')
  71. const res = await uni.request({
  72. url: `http://localhost:9527/api/getUid?uid=${uid}`,
  73. method: 'GET'
  74. })
  75. if (res.statusCode === 200 && res.data.code === 200) {
  76. const data = res.data.data
  77. this.avatarUrl = data.avatarUrl
  78. this.nickname = data.nickname
  79. this.phone = data.phone
  80. this.wechatName = data.wechatName || ''
  81. }
  82. },
  83. // 选择并上传头像
  84. chooseAvatar() {
  85. uni.chooseImage({
  86. count: 1,
  87. success: async (chooseRes) => {
  88. const filePath = chooseRes.tempFilePaths[0]
  89. // 这里假设你有后端/OSS直传接口
  90. const uploadRes = await uni.uploadFile({
  91. url: '你的OSS上传接口', // TODO: 替换为你的OSS上传接口
  92. filePath,
  93. name: 'file'
  94. })
  95. // 上传成功后,更新头像
  96. const avatarUrl = JSON.parse(uploadRes.data).url
  97. await uni.request({
  98. url: 'http://localhost:9527/api/updateUser',
  99. method: 'POST',
  100. data: { uid: uni.getStorageSync('uid'), avatarUrl }
  101. })
  102. this.avatarUrl = avatarUrl
  103. uni.showToast({ title: '头像已更新', icon: 'success' })
  104. }
  105. })
  106. },
  107. // 编辑昵称
  108. editNickname() {
  109. this.editNicknameValue = this.nickname
  110. this.showNicknamePopup = true
  111. },
  112. async saveNickname() {
  113. await uni.request({
  114. url: 'http://localhost:9527/api/updateUser',
  115. method: 'POST',
  116. data: { uid: uni.getStorageSync('uid'), nickname: this.editNicknameValue }
  117. })
  118. this.nickname = this.editNicknameValue
  119. this.showNicknamePopup = false
  120. uni.showToast({ title: '昵称已更新', icon: 'success' })
  121. },
  122. // 跳转更换手机号
  123. goToChangePhone() {
  124. uni.navigateTo({ url: '/pages/mine/changePhone' })
  125. },
  126. // 跳转设置密码
  127. goToSetPassword() {
  128. uni.navigateTo({ url: '/pages/mine/setPassword' })
  129. },
  130. // 跳转账号注销
  131. goToCancelAccount() {
  132. uni.navigateTo({ url: '/pages/mine/cancelAccount' })
  133. },
  134. // 跳转解绑微信
  135. goToUnbindWechat() {
  136. uni.navigateTo({ url: '/pages/mine/unbindWechat' })
  137. }
  138. }
  139. }
  140. </script>
  141. <style scoped>
  142. .profile-container {
  143. background: #f7f8fa;
  144. min-height: 100vh;
  145. }
  146. .profile-header {
  147. text-align: center;
  148. font-size: 36rpx;
  149. font-weight: bold;
  150. padding: 40rpx 0 20rpx 0;
  151. background: #fff;
  152. }
  153. .profile-list {
  154. margin-top: 20rpx;
  155. background: #fff;
  156. border-radius: 20rpx;
  157. overflow: hidden;
  158. }
  159. .profile-item {
  160. display: flex;
  161. align-items: center;
  162. padding: 0 32rpx;
  163. height: 100rpx;
  164. border-bottom: 1rpx solid #f0f0f0;
  165. }
  166. .profile-item:last-child {
  167. border-bottom: none;
  168. }
  169. .item-label {
  170. flex: 0 0 180rpx;
  171. color: #333;
  172. font-size: 30rpx;
  173. }
  174. .item-value {
  175. flex: 1;
  176. color: #666;
  177. font-size: 28rpx;
  178. text-align: right;
  179. margin-right: 16rpx;
  180. }
  181. .avatar {
  182. width: 70rpx;
  183. height: 70rpx;
  184. border-radius: 50%;
  185. margin-left: auto;
  186. margin-right: 8rpx;
  187. background: #eee;
  188. }
  189. .wechat-icon {
  190. width: 36rpx;
  191. height: 36rpx;
  192. margin-right: 8rpx;
  193. }
  194. .arrow {
  195. color: #bbb;
  196. font-size: 36rpx;
  197. margin-left: 8rpx;
  198. }
  199. .popup-mask {
  200. position: fixed;
  201. left: 0; right: 0; top: 0; bottom: 0;
  202. background: rgba(0,0,0,0.3);
  203. display: flex;
  204. align-items: center;
  205. justify-content: center;
  206. z-index: 1000;
  207. }
  208. .popup-content {
  209. background: #fff;
  210. border-radius: 16rpx;
  211. padding: 40rpx;
  212. min-width: 400rpx;
  213. display: flex;
  214. flex-direction: column;
  215. align-items: center;
  216. }
  217. .popup-content input {
  218. width: 300rpx;
  219. border: 1rpx solid #eee;
  220. border-radius: 8rpx;
  221. padding: 16rpx;
  222. margin-bottom: 24rpx;
  223. }
  224. .popup-btns {
  225. display: flex;
  226. width: 100%;
  227. justify-content: space-between;
  228. }
  229. .popup-btns button {
  230. flex: 1;
  231. margin: 0 8rpx;
  232. background: #409EFF;
  233. color: #fff;
  234. border: none;
  235. border-radius: 8rpx;
  236. padding: 16rpx 0;
  237. font-size: 28rpx;
  238. }
  239. </style>