优化:个人信息改为独立页面
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
const { BRAND_CONFIG } = require('../../utils/config')
|
||||
const userApi = require('../../api/user')
|
||||
const auth = require('../../utils/auth')
|
||||
const { chooseImageFilePath, uploadProfileImage } = require('../../utils/upload')
|
||||
const planningApi = require('../../api/planning')
|
||||
const employeesApi = require('../../api/employees')
|
||||
const shopApi = require('../../api/shop')
|
||||
@@ -19,18 +18,7 @@ function resolveRoleText(type) {
|
||||
Page({
|
||||
data: {
|
||||
roleText: '管理端',
|
||||
userInfo: {},
|
||||
profileCard: buildProfileCard({}, BRAND_CONFIG.defaultShopName),
|
||||
editModalVisible: false,
|
||||
profileSaving: false,
|
||||
avatarUploading: false,
|
||||
profileForm: {
|
||||
nickname: '',
|
||||
avatar: '',
|
||||
contactPhone: '',
|
||||
wechatId: '',
|
||||
signature: ''
|
||||
},
|
||||
overviewLoading: false,
|
||||
overview: {
|
||||
date: '',
|
||||
@@ -43,7 +31,7 @@ Page({
|
||||
shopStatus: '营业中'
|
||||
},
|
||||
menus: [
|
||||
{ title: '个人信息', action: 'editProfile' },
|
||||
{ title: '个人信息', url: '/pages/profile-edit/index' },
|
||||
{ title: '账号设置', url: '/pages/account-settings/index' },
|
||||
{ title: '店铺设置', url: '/pages/shop-settings/index' },
|
||||
{ title: '数据导出', url: '/pages/export/index' },
|
||||
@@ -112,17 +100,11 @@ Page({
|
||||
const fallbackShopName = app.globalData.shopName || BRAND_CONFIG.defaultShopName
|
||||
this.setData({
|
||||
roleText: resolveRoleText(userInfo.type),
|
||||
userInfo,
|
||||
profileCard: buildProfileCard(userInfo, fallbackShopName)
|
||||
})
|
||||
},
|
||||
|
||||
go(event) {
|
||||
const action = event.currentTarget.dataset.action
|
||||
if (action === 'editProfile') {
|
||||
this.openEditProfile()
|
||||
return
|
||||
}
|
||||
wx.navigateTo({ url: event.currentTarget.dataset.url })
|
||||
},
|
||||
|
||||
@@ -161,95 +143,8 @@ Page({
|
||||
userInfo: nextUserInfo
|
||||
})
|
||||
this.setData({
|
||||
userInfo: nextUserInfo,
|
||||
roleText: resolveRoleText(nextUserInfo.type),
|
||||
profileCard: buildProfileCard(nextUserInfo, BRAND_CONFIG.defaultShopName)
|
||||
})
|
||||
},
|
||||
|
||||
openEditProfile() {
|
||||
const userInfo = this.data.userInfo || {}
|
||||
this.setData({
|
||||
editModalVisible: true,
|
||||
profileForm: {
|
||||
nickname: userInfo.nickname || '',
|
||||
avatar: userInfo.avatar || '',
|
||||
contactPhone: userInfo.contactPhone || '',
|
||||
wechatId: userInfo.wechatId || '',
|
||||
signature: userInfo.signature || ''
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
closeEditProfile() {
|
||||
if (this.data.profileSaving || this.data.avatarUploading) {
|
||||
return
|
||||
}
|
||||
this.setData({ editModalVisible: false })
|
||||
},
|
||||
|
||||
stopTap() {
|
||||
},
|
||||
|
||||
onProfileInput(event) {
|
||||
const field = event.currentTarget.dataset.field
|
||||
this.setData({
|
||||
[`profileForm.${field}`]: event.detail.value
|
||||
})
|
||||
},
|
||||
|
||||
async chooseProfileAvatar() {
|
||||
if (this.data.avatarUploading || this.data.profileSaving) {
|
||||
return
|
||||
}
|
||||
try {
|
||||
const filePath = await chooseImageFilePath()
|
||||
if (!filePath) {
|
||||
return
|
||||
}
|
||||
this.setData({ avatarUploading: true })
|
||||
const avatar = await uploadProfileImage(filePath)
|
||||
this.setData({ 'profileForm.avatar': avatar })
|
||||
} catch (error) {
|
||||
wx.showToast({ title: error.message || '头像上传失败', icon: 'none' })
|
||||
} finally {
|
||||
this.setData({ avatarUploading: false })
|
||||
}
|
||||
},
|
||||
|
||||
removeProfileAvatar() {
|
||||
this.setData({ 'profileForm.avatar': '' })
|
||||
},
|
||||
|
||||
async saveProfile() {
|
||||
const form = this.data.profileForm
|
||||
const nickname = String(form.nickname || '').trim()
|
||||
const contactPhone = String(form.contactPhone || '').trim()
|
||||
if (contactPhone && !/^1[3-9]\d{9}$/.test(contactPhone)) {
|
||||
wx.showToast({ title: '请输入正确联系电话', icon: 'none' })
|
||||
return
|
||||
}
|
||||
if (!nickname) {
|
||||
wx.showToast({ title: '请填写昵称', icon: 'none' })
|
||||
return
|
||||
}
|
||||
this.setData({ profileSaving: true })
|
||||
try {
|
||||
await userApi.updateInfo({
|
||||
nickname,
|
||||
avatar: form.avatar || '',
|
||||
contactPhone,
|
||||
wechatId: String(form.wechatId || '').trim(),
|
||||
signature: String(form.signature || '').trim()
|
||||
})
|
||||
const profile = await userApi.info()
|
||||
this.syncProfileToSession(profile)
|
||||
this.setData({ editModalVisible: false })
|
||||
wx.showToast({ title: '已保存', icon: 'success' })
|
||||
} catch (error) {
|
||||
wx.showToast({ title: error.message || '保存失败', icon: 'none' })
|
||||
} finally {
|
||||
this.setData({ profileSaving: false })
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user