个人中心更新 user

This commit is contained in:
2025-02-12 02:40:45 +08:00
parent 2ab1b6df53
commit df410f1142
11 changed files with 127 additions and 13 deletions

View File

@ -1,5 +1,12 @@
import request from './request'
let app = getApp();
let token;
wx.getStorage({
key:'accessToken',
success:(res)=>{
token = res.data;
}
})
export default {
community:{
@ -30,5 +37,20 @@ export default {
},
station:{
list:(community_id)=>request.get('/api/station',{community_id})
},
uploadImg(file){
// const formData = new formData();
// return request.post('/api/upload/image',{file:file});
wx.uploadFile({
filePath: file.tempFilePath,
name: 'name',
header:{
Authorization: `Bearer ${token}`
},
formData:{
file:file
},
url: request.baseUrl+'/api/upload/image',
})
}
}

View File

@ -8,6 +8,7 @@ wx.getStorage({
})
const sendRequest = (options)=>{
console.log(options.data?options.data.file:1,12121212);
return new Promise((rs,rj)=>{
wx.request({
url: `${baseUrl}${options.url}`,
@ -18,11 +19,12 @@ const sendRequest = (options)=>{
rj(result.data)
}
},
method:options.method,
data:options.data,
params:options.params,
header:{
Authorization: `Bearer ${token}`
Authorization: `Bearer ${token}`,
"content-type":options.data&&options.data.file?'application/x-www-form-urlencoded':'application/json'
},
fail:rj
})
@ -30,6 +32,7 @@ const sendRequest = (options)=>{
}
export default {
baseUrl:baseUrl,
get(url,data){
return sendRequest({url,method:'get',data});
},

View File

@ -39,6 +39,7 @@ export default {
friend:{
list:()=>request.get('/api/user/referrals')
},
updateUser:(data)=>request.put('/api/user/update',data),
createPayment(order_id,order_type){
return request.post('/api/wechat/create-payment',{order_id,order_type});
}

4
app.js
View File

@ -17,6 +17,10 @@ App({
url: '/pages/login/login',
})
},
forceGetUserInfo(){
this.globalData.userInfoGetTime = null;
return this.getUserInfo();
},
async getUserInfo(){
if(this.globalData.userInfoGetTime&&
this.globalData.userInfo&&

View File

@ -42,7 +42,11 @@ Page({
* 生命周期函数--监听页面显示
*/
onShow() {
app.getUserInfo().then((data)=>{
this.setData({
userInfo:data
});
})
},
/**

View File

@ -24,8 +24,9 @@
<view class="cell-hd">
<image class="icon" src="/assets/icon/my/share@2x.png"></image>
</view>
<view class="cell-bd">
<view class="cell-bd invite-cell">
<view>邀请邻友</view>
<view class="spec">邻友下单赠送 1 张跑腿卷</view>
</view>
<view class="cell-ft"></view>
</navigator>

View File

@ -14,6 +14,8 @@
}
.user-info .content .avatar{
width:112rpx;height:112rpx;
border: 2px solid #FFFFFF;
border-radius: 50%;
}
.user-info .content .name{
font-size: 36rpx;
@ -54,3 +56,21 @@
.property .item .value{
font-size:56rpx;
}
.invite-cell{
display:flex;
justify-content: space-between;
}
.invite-cell .spec{
font-size: 26rpx;
position: relative;
color:var(--main-color);
}
.invite-cell .spec::before{
content:'';
position: absolute;
bottom: -16rpx;
background: rgba(153, 153, 153, 0.2);
width:100%;
height: 8rpx;
}

View File

@ -1,20 +1,52 @@
// pages/my/setting/index.js
const app = getApp();
import userApi from '../../../api/user';
import commonApi from '../../../api/common';
Page({
/**
* 页面的初始数据
*/
data: {
isShowPopup:false,
name:app.globalData.userInfo.nickname,
inputName:app.globalData.userInfo.nickname
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
},
saveName(){
userApi.updateUser({
nickname:this.data.inputName
}).then((data)=>{
this.setData({
name:data.nickname
});
wx.showToast({
title: '更新成功',
});
wx.navigateBack();
app.forceGetUserInfo();
})
},
chooseImage(){
wx.chooseMedia({
count:1,
mediaType:'image',
success:(res)=>{
console.log(res);
commonApi.uploadImg(res.tempFiles[0]);
}
});
},
modifyName(){
this.setData({
isShowPopup:true
});
},
/**
* 生命周期函数--监听页面初次渲染完成
*/

View File

@ -1,3 +1,4 @@
{
"usingComponents": {}
"usingComponents": {},
"navigationBarTitleText": "设置"
}

View File

@ -1,13 +1,13 @@
<view class="cells">
<view class="cell">
<view class="cell" bind:tap="chooseImage">
<view class="cell-bd">修改头像</view>
<view class="cell-ft">
<image src="/assets/imgs/for_test/avatar.png" class="avatar"/>
</view>
</view>
<view class="cell">
<view class="cell" bind:tap="modifyName">
<view class="cell-bd">修改昵称</view>
<view class="cell-ft">西瓜</view>
<view class="cell-ft">{{name}}</view>
</view>
</view>
@ -21,3 +21,13 @@
<view class="cell-ft"></view>
</view>
</view>
<page-container show="{{isShowPopup}}" close-on-slide-down>
<view class="content">
<view class="input-area">
<input class="input" model:value="{{inputName}}"/>
<button type="primary" size="mini" class="button"
disabled="{{name==inputName}}" bind:tap="saveName">保存</button>
</view>
</view>
</page-container>

View File

@ -1,3 +1,19 @@
.cell .avatar{
width:80rpx;height:80rpx;
}
.content{
height:100vh;
overflow: hidden;
}
.input-area{
background-color: #fff;
margin-top:20rpx;
display: flex;
align-items: center;
padding:0 20rpx;
}
.input-area .input{
height:88rpx;
line-height: 88rpx;
flex: 1;
}