9 changed files with 266 additions and 123 deletions
@ -1,66 +1,135 @@ |
|||
// pages/user/myInfo/index.js
|
|||
import { store } from '../../../utils/store.js' |
|||
import { config } from '../../../config.js' |
|||
import { UserModel } from '../../../models/user.js' |
|||
let userModel = new UserModel() |
|||
Page({ |
|||
|
|||
/** |
|||
* 页面的初始数据 |
|||
*/ |
|||
data: { |
|||
|
|||
avatarUrl:String, |
|||
nikeName: String, |
|||
phone: String, |
|||
company: String, |
|||
position: String, |
|||
}, |
|||
|
|||
/** |
|||
* 生命周期函数--监听页面加载 |
|||
*/ |
|||
onLoad: function (options) { |
|||
|
|||
console.log(options) |
|||
this.setData({ |
|||
avatarUrl: options.userIcon, |
|||
nikeName: options.userName, |
|||
phone: options.userPhone || '', |
|||
company: options.company || '', |
|||
position: options.position || '', |
|||
}) |
|||
}, |
|||
|
|||
/** |
|||
* 生命周期函数--监听页面初次渲染完成 |
|||
*/ |
|||
onReady: function () { |
|||
|
|||
onTapItem(e) { |
|||
const { type } = e.currentTarget.dataset |
|||
console.log(type) |
|||
if(type === 'userIcon'){ |
|||
this.upload() |
|||
} |
|||
}, |
|||
|
|||
/** |
|||
* 生命周期函数--监听页面显示 |
|||
*/ |
|||
onShow: function () { |
|||
|
|||
upload(){ |
|||
let that = this |
|||
|
|||
wx.chooseImage({ |
|||
success(res) { |
|||
wx.showLoading() |
|||
const tempFilePaths = res.tempFilePaths |
|||
console.log(res) |
|||
const token = store.readToken() |
|||
wx.uploadFile({ |
|||
url: config.api_url + "/api/common/upload", |
|||
filePath: tempFilePaths[0], |
|||
header: { |
|||
'token': token, |
|||
'content-type': 'application/json', |
|||
}, |
|||
name: 'files', |
|||
success(res) { |
|||
console.log(res); |
|||
const data = JSON.parse(res.data) |
|||
const image = { |
|||
url: config.api_url + '/' + data.result.imgUrl, |
|||
} |
|||
that.setData({ |
|||
avatarUrl: image.url |
|||
},()=>{ |
|||
wx.hideLoading() |
|||
}) |
|||
} |
|||
}) |
|||
} |
|||
}) |
|||
}, |
|||
|
|||
/** |
|||
* 生命周期函数--监听页面隐藏 |
|||
*/ |
|||
onHide: function () { |
|||
|
|||
getUserInfo(){ |
|||
userModel.getUserInfo(res => { |
|||
let nickName = res.result.nickName |
|||
let avatarUrl = res.result.avatarUrl |
|||
this.setData({ |
|||
avatarUrl: res.result.avatarUrl, |
|||
nikeName: res.result.nickName, |
|||
phone: res.result.phone || '', |
|||
company: res.result.company || '', |
|||
position: res.result.position || '', |
|||
}) |
|||
store.saveUserInfo({ |
|||
nickName: res.result.nickName, |
|||
avatarUrl: res.result.avatarUrl, |
|||
phone: res.result.phone || '' |
|||
}) |
|||
}) |
|||
}, |
|||
|
|||
/** |
|||
* 生命周期函数--监听页面卸载 |
|||
*/ |
|||
onUnload: function () { |
|||
|
|||
bindNikeNameInput(e){ |
|||
this.setData({ |
|||
nikeName:e.detail.value |
|||
}) |
|||
}, |
|||
|
|||
/** |
|||
* 页面相关事件处理函数--监听用户下拉动作 |
|||
*/ |
|||
onPullDownRefresh: function () { |
|||
|
|||
bindPhoneInput(e) { |
|||
this.setData({ |
|||
phone: e.detail.value |
|||
}) |
|||
}, |
|||
|
|||
/** |
|||
* 页面上拉触底事件的处理函数 |
|||
*/ |
|||
onReachBottom: function () { |
|||
|
|||
bindCompanyInput(e) { |
|||
this.setData({ |
|||
company: e.detail.value |
|||
}) |
|||
}, |
|||
|
|||
/** |
|||
* 用户点击右上角分享 |
|||
*/ |
|||
onShareAppMessage: function () { |
|||
|
|||
bindPositionInput(e) { |
|||
this.setData({ |
|||
position: e.detail.value |
|||
}) |
|||
}, |
|||
submit(){ |
|||
let avatarUrl = this.data.avatarUrl |
|||
let nikeName = this.data.nikeName |
|||
let phone = this.data.phone |
|||
let company = this.data.company |
|||
let position = this.data.position |
|||
|
|||
userModel.updateUserInfo(avatarUrl, nikeName, phone, company, position, res => { |
|||
// that.getUserInfo()
|
|||
if(res.code === 200){ |
|||
wx.showToast({ |
|||
title: '修改成功', |
|||
icon: 'none', |
|||
duration: 2000, |
|||
success(res) { |
|||
setTimeout(function () { |
|||
wx.navigateBack({ |
|||
delta: 1 |
|||
}) |
|||
}, 2000) |
|||
} |
|||
}) |
|||
} |
|||
}) |
|||
} |
|||
}) |
@ -1,4 +1,8 @@ |
|||
{ |
|||
"navigationBarTitleText": "个人资料", |
|||
"usingComponents": {} |
|||
"usingComponents": { |
|||
"e-ibutton": "/components/image-button/index", |
|||
"mp-cells": "/components/weui/cells/cells", |
|||
"mp-cell": "/components/weui/cell/cell" |
|||
} |
|||
} |
@ -1,2 +1,38 @@ |
|||
<!--pages/user/myInfo/index.wxml--> |
|||
<text>pages/user/myInfo/index.wxml</text> |
|||
<view class="container"> |
|||
<mp-cells ext-class="page_bd"> |
|||
<mp-cell |
|||
bindtap="onTapItem" data-type="userIcon" |
|||
title="头像" |
|||
ext-class="cell-item"> |
|||
<image slot="footer" class="user_logo" src="{{avatarUrl}}" /> |
|||
</mp-cell> |
|||
<mp-cell |
|||
bindtap="onTapItem" data-type="userName" |
|||
title="名字" |
|||
ext-class="cell-item"> |
|||
<input slot="footer" class="msg_footer" bindinput="bindNikeNameInput" value="{{nikeName}}"></input> |
|||
</mp-cell> |
|||
<mp-cell |
|||
bindtap="onTapItem" data-type="userPhone" |
|||
title="手机号" |
|||
ext-class="cell-item"> |
|||
<input slot="footer" class="msg_footer" bindinput="bindPhoneInput" value="{{phone}}"></input> |
|||
</mp-cell> |
|||
<mp-cell |
|||
bindtap="onTapItem" data-type="workUnit" |
|||
title="工作单位" |
|||
ext-class="cell-item"> |
|||
<input slot="footer" class="msg_footer" bindinput="bindCompanyInput" value="{{company}}"></input> |
|||
</mp-cell> |
|||
<mp-cell |
|||
bindtap="onTapItem" data-type="position" |
|||
title="职务" |
|||
ext-class="cell-item"> |
|||
<input slot="footer" class="msg_footer" bindinput="bindPositionInput" value="{{position}}"></input> |
|||
</mp-cell> |
|||
<view class="btnView"> |
|||
<e-ibutton title="提交" bind:onTap="submit"/> |
|||
</view> |
|||
</mp-cells> |
|||
</view> |
|||
|
@ -1 +1,74 @@ |
|||
/* pages/user/myInfo/index.wxss */ |
|||
/* pages/user/myInfo/index.wxss */ |
|||
.container { |
|||
background-color: #FAFAFA; |
|||
height: 100vh; |
|||
} |
|||
.page_hd { |
|||
border-bottom: 7px solid #f7f7f7; |
|||
} |
|||
.page_hd .weui-cells:before { |
|||
border-top: 0px solid white; |
|||
} |
|||
.page_hd .weui-cells:after { |
|||
border-bottom: 0px solid white; |
|||
} |
|||
.user_hd { |
|||
display: flex; |
|||
flex-direction: row; |
|||
align-items: center; |
|||
overflow: hidden; |
|||
} |
|||
.user_auth_hd { |
|||
display: flex; |
|||
flex-direction: row; |
|||
align-items: center; |
|||
overflow: hidden; |
|||
justify-content: space-between; |
|||
} |
|||
.user_logo { |
|||
width: 60px; |
|||
height: 60px; |
|||
border-radius: 5px; |
|||
} |
|||
.user_name { |
|||
width: 400rpx; |
|||
color: #292E3E; |
|||
padding-left: 10px; |
|||
white-space: nowrap; |
|||
text-overflow: ellipsis; |
|||
overflow: hidden; |
|||
} |
|||
/* 页面body */ |
|||
.page_bd .weui-cell{ |
|||
padding: 10px 16px 10px 16px; |
|||
} |
|||
.weui-cell_wxss{ |
|||
|
|||
} |
|||
.weui-cell__ft{ |
|||
width: 70%; |
|||
} |
|||
.page_bd .weui-cell__hd { |
|||
display: flex; |
|||
align-items: center; |
|||
font-size: 14px; |
|||
} |
|||
.page_bd .weui-cell__icon { |
|||
width: 19px; |
|||
height: 16px; |
|||
padding: 0 10px 0 0; |
|||
} |
|||
.msg_footer{ |
|||
font-size: 14px; |
|||
border: 1px solid #AAAAAA; |
|||
border-radius: 4px; |
|||
height: 30px; |
|||
text-align: left; |
|||
} |
|||
.btnView{ |
|||
position: fixed; |
|||
padding: 10px 20px 20px 20px; |
|||
bottom: 0; |
|||
left: 0; |
|||
right: 0; |
|||
} |
Loading…
Reference in new issue