微信小程序 - 商城项目 - 个人中心

时间:2024-12-18 07:23:53

页面布局

 

  1. <view class="userInfo">
  2. <image src="{{}}" bindtap="handleTap"></image>
  3. <view>{{}}</view>
  4. </view>
  5. <mp-cells>
  6. <mp-cell value="完善信息">
  7. <mp-icon slot="icon" type="field" icon="me" color="#14c145" size="{{25}}"></mp-icon>
  8. <mp-icon slot="icon" type="field" icon="arrow" size="{{25}}" slot="footer"></mp-icon>
  9. </mp-cell>
  10. <mp-cell value="个性设置">
  11. <mp-icon slot="icon" type="field" icon="like" color="#14c145" size="{{25}}"></mp-icon>
  12. <mp-icon slot="icon" type="field" icon="arrow" size="{{25}}" slot="footer"></mp-icon>
  13. </mp-cell>
  14. </mp-cells>
  1. {
  2. "usingComponents": {
  3. "mp-cells": "weui-miniprogram/cells/cells",
  4. "mp-cell": "weui-miniprogram/cell/cell",
  5. "mp-icon": "weui-miniprogram/icon/icon"
  6. },
  7. "navigationBarTitleText": "个人中心"
  8. }

 页面显示进行授权判断,若存储过 token ,取出数据,渲染页面的头像及名字等个人信息

  1. /*** 生命周期函数--监听页面显示 */
  2. onShow() {
  3. CheckAuth(()=>{
  4. ({
  5. userInfo:('token')
  6. })
  7. })
  8. },

点击头像更换图片

()

  1. // 点击头像切换照片
  2. handleTap(){
  3. wx.chooseMedia({
  4. count: 9,
  5. mediaType: ['image','video'],
  6. sourceType: ['album', 'camera'],
  7. maxDuration: 30,
  8. camera: 'back',
  9. success:(res)=> {
  10. const temFilePaths = [0].tempFilePath
  11. this.setData({
  12. userInfo:{
  13. ...,
  14. avatarUrl:temFilePaths
  15. }
  16. })
  17. }
  18. })
  19. },