info.nvue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. <template>
  2. <view class="page">
  3. <!-- 头像区 -->
  4. <view class="section">
  5. <view class="info-item" @click="changeAvatar">
  6. <text class="item-label">头像</text>
  7. <view class="item-right">
  8. <image class="avatar-preview" :src="avatar" mode="aspectFill"></image>
  9. <image class="item-arrow" src="/static/my/arrowright.png" mode="aspectFill"></image>
  10. </view>
  11. </view>
  12. </view>
  13. <!-- 基本信息 -->
  14. <view class="section">
  15. <view class="info-item" @click="editNickname">
  16. <text class="item-label">昵称</text>
  17. <view class="item-right">
  18. <text class="item-value">{{nickname}}</text>
  19. <image class="item-arrow" src="/static/my/arrowright.png" mode="aspectFill"></image>
  20. </view>
  21. </view>
  22. <view class="info-item">
  23. <text class="item-label">手机号</text>
  24. <view class="item-right">
  25. <text class="item-value">{{phone}}</text>
  26. </view>
  27. </view>
  28. <view class="info-item">
  29. <text class="item-label">AppId</text>
  30. <view class="item-right">
  31. <text class="item-value">{{appid}}</text>
  32. </view>
  33. </view>
  34. </view>
  35. <!-- 修改昵称弹窗 -->
  36. <view class="nickname-overlay" v-if="showNicknamePopup" @click="closeNicknamePopup">
  37. <view class="nickname-dialog" @click.stop="" :style="{marginBottom: keyboardHeight + 'px'}">
  38. <text class="dialog-title">修改昵称</text>
  39. <view class="input-box">
  40. <input class="nickname-input" v-model="nicknameInput" placeholder="请输入昵称" placeholder-class="input-placeholder"
  41. maxlength="12" :adjust-position="false" :focus="showNicknamePopup"
  42. @keyboardheightchange="onKeyboardHeight" />
  43. </view>
  44. <view class="dialog-btns">
  45. <view class="dialog-btn" @click="closeNicknamePopup">
  46. <text class="dialog-cancel">取消</text>
  47. </view>
  48. <view class="dialog-divider"></view>
  49. <view class="dialog-btn" @click="saveNickname">
  50. <text class="dialog-confirm">确定</text>
  51. </view>
  52. </view>
  53. </view>
  54. </view>
  55. <ay-toast ref="ayToast" />
  56. </view>
  57. </template>
  58. <script>
  59. import ayToast from '@/components/ay-toast/ay-toast.nvue'
  60. export default {
  61. components: {
  62. ayToast
  63. },
  64. data() {
  65. return {
  66. avatar: '/static/my/avator.png',
  67. nickname: '用户',
  68. phone: '',
  69. appid: '',
  70. showNicknamePopup: false,
  71. nicknameInput: '',
  72. keyboardHeight: 0
  73. }
  74. },
  75. onLoad() {
  76. this.loadUserInfo()
  77. },
  78. methods: {
  79. loadUserInfo() {
  80. const phone = uni.getStorageSync('phone') || '138****8888'
  81. const nickname = uni.getStorageSync('nickname') || '用户'
  82. const appid = uni.getStorageSync('appid') || ''
  83. const avatar = uni.getStorageSync('avatar') || '/static/my/avator.png'
  84. this.phone = phone
  85. this.nickname = nickname
  86. this.appid = appid
  87. this.avatar = avatar
  88. },
  89. changeAvatar() {
  90. uni.chooseImage({
  91. count: 1,
  92. sizeType: ['compressed'],
  93. sourceType: ['album', 'camera'],
  94. success: (res) => {
  95. const tempPath = res.tempFilePaths[0]
  96. uni.navigateTo({
  97. url: '/pages/my/crop/crop?src=' + encodeURIComponent(tempPath)
  98. })
  99. }
  100. })
  101. },
  102. editNickname() {
  103. this.nicknameInput = this.nickname
  104. this.showNicknamePopup = true
  105. },
  106. closeNicknamePopup() {
  107. this.showNicknamePopup = false
  108. this.keyboardHeight = 0
  109. },
  110. onKeyboardHeight(e) {
  111. this.keyboardHeight = e.detail.height || 0
  112. },
  113. saveNickname() {
  114. const val = this.nicknameInput.trim()
  115. if (!val) {
  116. this.$refs.ayToast.error('昵称不能为空')
  117. return
  118. }
  119. this.nickname = val
  120. uni.setStorageSync('nickname', val)
  121. this.showNicknamePopup = false
  122. this.keyboardHeight = 0
  123. this.$refs.ayToast.success('修改成功')
  124. }
  125. },
  126. onShow() {
  127. // 从裁剪页返回后刷新头像
  128. const avatar = uni.getStorageSync('avatar')
  129. if (avatar) {
  130. this.avatar = avatar
  131. }
  132. }
  133. }
  134. </script>
  135. <style>
  136. .page {
  137. flex: 1;
  138. background-color: #F5F6F8;
  139. }
  140. /* 分组 */
  141. .section {
  142. background-color: #FFFFFF;
  143. margin-top: 20rpx;
  144. border-radius: 20rpx;
  145. margin-left: 24rpx;
  146. margin-right: 24rpx;
  147. overflow: hidden;
  148. }
  149. /* 信息项 */
  150. .info-item {
  151. flex-direction: row;
  152. align-items: center;
  153. justify-content: space-between;
  154. height: 110rpx;
  155. padding-left: 32rpx;
  156. padding-right: 32rpx;
  157. border-bottom-width: 1px;
  158. border-bottom-color: #F0F0F0;
  159. border-bottom-style: solid;
  160. }
  161. .item-label {
  162. font-size: 30rpx;
  163. color: #333333;
  164. }
  165. .item-right {
  166. flex-direction: row;
  167. align-items: center;
  168. }
  169. .item-value {
  170. font-size: 30rpx;
  171. color: #999999;
  172. margin-right: 16rpx;
  173. }
  174. .item-arrow {
  175. width: 32rpx;
  176. height: 32rpx;
  177. }
  178. .avatar-preview {
  179. width: 80rpx;
  180. height: 80rpx;
  181. border-radius: 80rpx;
  182. margin-right: 16rpx;
  183. }
  184. /* 昵称修改弹窗 */
  185. .nickname-overlay {
  186. position: fixed;
  187. top: 0;
  188. left: 0;
  189. right: 0;
  190. bottom: 0;
  191. background-color: rgba(0, 0, 0, 0.4);
  192. justify-content: center;
  193. align-items: center;
  194. }
  195. .nickname-dialog {
  196. width: 600rpx;
  197. background-color: #FFFFFF;
  198. border-radius: 28rpx;
  199. align-items: center;
  200. overflow: hidden;
  201. }
  202. .dialog-title {
  203. font-size: 34rpx;
  204. color: #333333;
  205. font-weight: bold;
  206. margin-top: 48rpx;
  207. margin-bottom: 40rpx;
  208. }
  209. .input-box {
  210. width: 520rpx;
  211. height: 88rpx;
  212. background-color: #F5F6F8;
  213. border-radius: 16rpx;
  214. justify-content: center;
  215. padding-left: 24rpx;
  216. padding-right: 24rpx;
  217. margin-bottom: 48rpx;
  218. }
  219. .nickname-input {
  220. font-size: 30rpx;
  221. color: #333333;
  222. }
  223. .dialog-btns {
  224. flex-direction: row;
  225. align-self: stretch;
  226. border-top-width: 1px;
  227. border-top-color: #F0F0F0;
  228. border-top-style: solid;
  229. height: 96rpx;
  230. align-items: center;
  231. }
  232. .dialog-btn {
  233. flex: 1;
  234. height: 96rpx;
  235. justify-content: center;
  236. align-items: center;
  237. }
  238. .dialog-cancel {
  239. font-size: 32rpx;
  240. color: #999999;
  241. }
  242. .dialog-divider {
  243. width: 1px;
  244. height: 96rpx;
  245. background-color: #F0F0F0;
  246. }
  247. .dialog-confirm {
  248. font-size: 32rpx;
  249. color: #389588;
  250. font-weight: bold;
  251. }
  252. </style>