sunshine1130 4 vuotta sitten
vanhempi
commit
33d84af728

+ 0 - 1
api/upload.js

@@ -41,7 +41,6 @@ class uploadImg extends request {
             mask: true
         });
         const res = await request.upload(`${this.BASE_URL}Common/upload`, 'image', tempFilePaths)
-        console.log(res)
         wx.hideLoading()
         return res.data.url
     }

+ 2 - 2
api/user.js

@@ -10,8 +10,8 @@ class store extends request{
         const res = await this.postRequest(`${this.BASE_URL}User/save`, data)
         return res.data;
     }
-    static async updateUserInfo(name,birthday,avatar){
-        const res = await this.getRequest(`${this.BASE_URL}User/editUser?name=${name}&birthday=${brithday}&avatar=${avatar}`)
+    static async updateUserInfo(name,birthday,avatar,sex){
+        const res = await this.getRequest(`${this.BASE_URL}User/editUser?name=${name}&birthday=${birthday}&avatar=${avatar}&sex=${sex}`)
     }
     static async getUserById(userId){
         const res = await this.getRequest(`${this.BASE_URL}User/read?id=${userId}`)

BIN
images/icons/left.png


+ 13 - 1
pages/person/person.js

@@ -15,6 +15,7 @@ Page({
    */
   onLoad: async function (options) {
     let userInfo = await app.getWxUserInfo()
+    console.log(2222222222222)
     console.log(userInfo);
     if (userInfo) {
       this.setData({
@@ -34,7 +35,18 @@ Page({
   /**
    * 生命周期函数--监听页面显示
    */
-  onShow: async function () {},
+  onShow: async function () {
+    let userInfo = await app.getWxUserInfo()
+    console.log(2222222222222)
+    console.log(userInfo);
+    if (userInfo) {
+      this.setData({
+        userInfo: userInfo,
+        hasUserInfo: true,
+        hasMobile: userInfo.mobile ? true : false
+      })
+    }
+  },
 
   /**
    * 生命周期函数--监听页面隐藏

+ 45 - 10
pages/personinfo/personinfo.js

@@ -1,5 +1,6 @@
 // pages/personinfo/personinfo.js
 import userApi from '../../api/user'
+import uploadApi from '../../api/upload'
 const app = getApp();
 
 Page({
@@ -9,7 +10,7 @@ Page({
    */
   data: {
     endDate: "",
-    birth: "1993-12-12",
+    birth: "",
     sex: 0,
     array: ["未知", "男", "女"],
     userName: "",
@@ -21,6 +22,18 @@ Page({
    * 生命周期函数--监听页面加载
    */
   onLoad: async function (options) {
+    //设置标题栏的高度
+    var that = this
+    wx.getSystemInfo({
+      success: function (res) {
+        console.log(res)
+        console.log(res.statusBarHeight)
+        that.setData({
+          statusBarHeight: res.statusBarHeight
+        })
+      },
+    })
+    //设置结束日期为今日
     var d = new Date();
     var endDate = d.getFullYear() + '-' + (d.getMonth() + 1) + '-' + d.getDate()
     this.setData({
@@ -29,11 +42,14 @@ Page({
     let userInfo = await app.getWxUserInfo();
     let userId = userInfo.userId;
     let user = await userApi.getUserById(userId);
+    let birth = user.info.birthday;
+    birth == "" ? '1970-01-01' : birth;
     console.log(user)
     this.setData({
       sex: userInfo.gender,
       imgUrl: user.info.avatar,
       userName: user.info.name,
+      birth: birth
     })
 
   },
@@ -54,7 +70,7 @@ Page({
       sex: e.detail.value
     })
   },
-  upload: function () {
+  upload: async function () {
     var _this = this;
     wx.chooseImage({
       count: 1, // 默认9      
@@ -62,15 +78,35 @@ Page({
       // 指定是原图还是压缩图,默认两个都有      
       sourceType: ['album', 'camera'],
       // 指定来源是相册还是相机,默认两个都有    
-      success: function (res) {
-        // 返回选定照片的本地文件路径tempFilePath可以作为img标签的src属性显示图片        
+      success: async function (res) {
+        // 返回选定照片的本地文件路径tempFilePath可以作为img标签的src属性显示图片 
+        var imgUrl = await uploadApi.uploadAvatar(res.tempFilePaths[0]);
         _this.setData({
-          imgUrl: res.tempFilePaths
+          imgUrl: imgUrl
         })
       }
     })
   },
-  updatePersonInfo: async function () {},
+  updateUser: async function () {
+    var name = this.data.userName;
+    var birthDay = this.data.birth;
+    var avatar = this.data.imgUrl;
+    var sex = this.data.sex;
+    var userInfo = await app.getWxUserInfo();
+    userInfo.name = name;
+    userInfo.birthday = birthDay;
+    userInfo.avatar = avatar;
+    userInfo.sex = sex;
+    wx.setStorage({
+      data: userInfo,
+      key: 'userInfo',
+    })
+    await userApi.updateUserInfo(name, birthDay, avatar, sex);
+    wx.switchTab({
+
+      url: '/pages/person/person',
+    })
+  },
   /**
    * 生命周期函数--监听页面初次渲染完成
    */
@@ -89,15 +125,14 @@ Page({
    * 生命周期函数--监听页面隐藏
    */
   onHide: function () {
-    
+
   },
 
   /**
    * 生命周期函数--监听页面卸载
    */
-  onUnload: function () {
-    console.log('隐藏啦')
-    console.log(this.data)
+  onUnload: async function () {
+
   },
 
   /**

+ 1 - 0
pages/personinfo/personinfo.json

@@ -1,5 +1,6 @@
 {
   "disableScroll": true,
+  "navigationStyle": "custom",
   "usingComponents": {
     "mp-icon": "weui-miniprogram/icon/icon"
    

+ 21 - 0
pages/personinfo/personinfo.scss

@@ -1,3 +1,24 @@
+.top-bar{
+    background-color: #343434;
+    .bar-text{
+        text-align: center;
+        color: #fff;
+        position: relative;
+        padding-bottom: 15rpx;
+        font-size: 25rpx;
+        .left{
+            position: absolute;
+            left: 30rpx;
+            top: 6rpx;
+            >.left-img{
+                width: 38rpx;
+                height: 38rpx;
+            }
+        }
+    }
+}
+
+
 .container {
     background-color: #F7F7F7;
     min-height: 1200rpx;

+ 16 - 4
pages/personinfo/personinfo.wxml

@@ -1,4 +1,16 @@
 <!--pages/personinfo/personinfo.wxml-->
+<!-- 标题栏 -->
+<view class="top-bar">
+    <!-- 沉浸栏 -->
+    <view style="width:100%;height:{{statusBarHeight}}px"></view>
+    <!-- 标题栏 这里就可以自定义写标题 -->
+    <view class="bar-text">
+        <view class="left" bindtap = "updateUser">
+            <image class="left-img" src="../../images/icons/left.png"></image>
+        </view>
+        <text>个人</text>
+    </view>
+</view>
 <view class="container">
     <view class="head-img card">
         <view class="title">头像</view>
@@ -10,10 +22,10 @@
     </view>
     <view class="user-name">
         <view class="title">昵称</view>
-        <view class="info" >
-            <input type="text" value="{{userName}}" name="user" bindblur = "changeUserName"/>
+        <view class="info">
+            <input type="text" value="{{userName}}" name="user" bindblur="changeUserName" />
         </view>
-        <image class="icon" src="../../images/icons/next-gray.png" >
+        <image class="icon" src="../../images/icons/next-gray.png">
 
         </image>
     </view>
@@ -32,7 +44,7 @@
         <view class="title">生日</view>
         <view class="info">
             <picker mode="date" value="{{date}}" start="1970-01-01" end="{{endDate}}" bindchange="changeBirth">
-                {{userInfo.birthday?userInfo.birthday:'1970-01-01'}}
+                {{birth}}
             </picker>
         </view>
         <image class="icon" src="../../images/icons/next-gray.png">

+ 23 - 0
pages/personinfo/personinfo.wxss

@@ -1,3 +1,26 @@
+.top-bar {
+  background-color: #343434;
+}
+
+.top-bar .bar-text {
+  text-align: center;
+  color: #fff;
+  position: relative;
+  padding-bottom: 15rpx;
+  font-size: 25rpx;
+}
+
+.top-bar .bar-text .left {
+  position: absolute;
+  left: 30rpx;
+  top: 6rpx;
+}
+
+.top-bar .bar-text .left > .left-img {
+  width: 38rpx;
+  height: 38rpx;
+}
+
 .container {
   background-color: #F7F7F7;
   min-height: 1200rpx;