1
This commit is contained in:
61
miniprogram/pages/profile/index.js
Normal file
61
miniprogram/pages/profile/index.js
Normal file
@@ -0,0 +1,61 @@
|
||||
const { request } = require('../../utils/request')
|
||||
|
||||
Page({
|
||||
data: {
|
||||
loading: false,
|
||||
form: {
|
||||
nickname: '',
|
||||
company: '',
|
||||
title: '',
|
||||
phone: '',
|
||||
password: ''
|
||||
}
|
||||
},
|
||||
|
||||
onShow() {
|
||||
this.loadProfile()
|
||||
},
|
||||
|
||||
async loadProfile() {
|
||||
const profile = await request({ url: '/user/profile' })
|
||||
this.setData({
|
||||
form: {
|
||||
nickname: profile.nickname || '',
|
||||
company: profile.company || '',
|
||||
title: profile.title || '',
|
||||
phone: profile.phone || '',
|
||||
password: ''
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
onInput(e) {
|
||||
const field = e.currentTarget.dataset.field
|
||||
this.setData({ [`form.${field}`]: (e.detail.value || '').trim() })
|
||||
},
|
||||
|
||||
async save() {
|
||||
if (this.data.loading) return
|
||||
this.setData({ loading: true })
|
||||
|
||||
const payload = { ...this.data.form }
|
||||
if (!payload.password) {
|
||||
delete payload.password
|
||||
}
|
||||
|
||||
try {
|
||||
const user = await request({
|
||||
url: '/user/profile',
|
||||
method: 'PUT',
|
||||
data: payload
|
||||
})
|
||||
const app = getApp()
|
||||
app.globalData.user = user
|
||||
wx.setStorageSync('user', user)
|
||||
wx.showToast({ title: '保存成功', icon: 'success' })
|
||||
this.setData({ 'form.password': '' })
|
||||
} finally {
|
||||
this.setData({ loading: false })
|
||||
}
|
||||
}
|
||||
})
|
||||
3
miniprogram/pages/profile/index.json
Normal file
3
miniprogram/pages/profile/index.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"navigationBarTitleText": "个人中心"
|
||||
}
|
||||
39
miniprogram/pages/profile/index.wxml
Normal file
39
miniprogram/pages/profile/index.wxml
Normal file
@@ -0,0 +1,39 @@
|
||||
<view class="container">
|
||||
<view class="hero fade-up">
|
||||
<view class="hero-badge">PROFILE</view>
|
||||
<view class="hero-title">个人资料设置</view>
|
||||
<view class="hero-sub">完善你的身份信息,便于审计追踪和团队协同。</view>
|
||||
</view>
|
||||
|
||||
<view class="card fade-up fade-up-delay-1">
|
||||
<view class="card-title">账号资料</view>
|
||||
|
||||
<view class="field">
|
||||
<text class="field-label">昵称</text>
|
||||
<input class="input" placeholder="请输入昵称" value="{{form.nickname}}" data-field="nickname" bindinput="onInput" />
|
||||
</view>
|
||||
|
||||
<view class="field">
|
||||
<text class="field-label">公司</text>
|
||||
<input class="input" placeholder="请输入公司名称" value="{{form.company}}" data-field="company" bindinput="onInput" />
|
||||
</view>
|
||||
|
||||
<view class="field">
|
||||
<text class="field-label">岗位</text>
|
||||
<input class="input" placeholder="请输入岗位" value="{{form.title}}" data-field="title" bindinput="onInput" />
|
||||
</view>
|
||||
|
||||
<view class="field">
|
||||
<text class="field-label">手机号</text>
|
||||
<input class="input" placeholder="请输入手机号" value="{{form.phone}}" data-field="phone" bindinput="onInput" />
|
||||
</view>
|
||||
|
||||
<view class="field">
|
||||
<text class="field-label">新密码</text>
|
||||
<input class="input" placeholder="留空表示不修改" password value="{{form.password}}" data-field="password" bindinput="onInput" />
|
||||
<view class="field-help">密码长度需不少于 6 位。</view>
|
||||
</view>
|
||||
|
||||
<button class="btn btn-primary" loading="{{loading}}" bindtap="save">保存资料</button>
|
||||
</view>
|
||||
</view>
|
||||
1
miniprogram/pages/profile/index.wxss
Normal file
1
miniprogram/pages/profile/index.wxss
Normal file
@@ -0,0 +1 @@
|
||||
/* profile styles use global theme */
|
||||
Reference in New Issue
Block a user