实现预约草稿和资料头像编辑
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
const employeesApi = require('../../api/employees')
|
||||
const { chooseImageFilePath, uploadObjectFile } = require('../../utils/upload')
|
||||
|
||||
const EMPLOYEE_COLORS = ['#7AA9C2', '#8EB99B', '#BDA7D8', '#D7B17D', '#D98D8D']
|
||||
const DEFAULT_EMPLOYEE_PASSWORD = 'Fingertip@123'
|
||||
@@ -20,8 +21,11 @@ Page({
|
||||
phone: '',
|
||||
account: '',
|
||||
password: DEFAULT_EMPLOYEE_PASSWORD,
|
||||
wechatId: ''
|
||||
}
|
||||
wechatId: '',
|
||||
avatar: '',
|
||||
avatarUrl: ''
|
||||
},
|
||||
avatarUploading: false
|
||||
},
|
||||
|
||||
onLoad() {
|
||||
@@ -90,11 +94,43 @@ Page({
|
||||
phone: '',
|
||||
account: '',
|
||||
password: DEFAULT_EMPLOYEE_PASSWORD,
|
||||
wechatId: ''
|
||||
wechatId: '',
|
||||
avatar: '',
|
||||
avatarUrl: ''
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
async chooseEmployeeAvatar() {
|
||||
if (this.data.avatarUploading || this.data.creating) {
|
||||
return
|
||||
}
|
||||
try {
|
||||
const filePath = await chooseImageFilePath()
|
||||
if (!filePath) {
|
||||
return
|
||||
}
|
||||
this.setData({ avatarUploading: true })
|
||||
const uploadResult = await uploadObjectFile(filePath)
|
||||
const avatarUrl = uploadResult.fileUrl || uploadResult.primaryUrl || filePath
|
||||
this.setData({
|
||||
'createForm.avatar': avatarUrl,
|
||||
'createForm.avatarUrl': avatarUrl
|
||||
})
|
||||
} catch (error) {
|
||||
wx.showToast({ title: error.message || '头像上传失败', icon: 'none' })
|
||||
} finally {
|
||||
this.setData({ avatarUploading: false })
|
||||
}
|
||||
},
|
||||
|
||||
removeEmployeeAvatar() {
|
||||
this.setData({
|
||||
'createForm.avatar': '',
|
||||
'createForm.avatarUrl': ''
|
||||
})
|
||||
},
|
||||
|
||||
async submitEmployee() {
|
||||
const form = this.data.createForm
|
||||
const nickname = String(form.nickname || '').trim()
|
||||
@@ -115,6 +151,7 @@ Page({
|
||||
account,
|
||||
password,
|
||||
wechatId,
|
||||
avatar: form.avatar || undefined,
|
||||
type: 3
|
||||
})
|
||||
wx.showToast({ title: '美甲师已新增', icon: 'success' })
|
||||
|
||||
@@ -34,6 +34,14 @@
|
||||
</view>
|
||||
<view class="modal-close" bindtap="closeCreateModal">×</view>
|
||||
</view>
|
||||
<view class="avatar-upload">
|
||||
<view wx:if="{{createForm.avatarUrl}}" class="avatar-preview image-avatar">
|
||||
<image src="{{createForm.avatarUrl}}" mode="aspectFill"></image>
|
||||
</view>
|
||||
<view wx:else class="avatar-preview">头像</view>
|
||||
<button class="secondary-btn avatar-btn" loading="{{avatarUploading}}" bindtap="chooseEmployeeAvatar">上传头像</button>
|
||||
<button wx:if="{{createForm.avatarUrl}}" class="text-btn avatar-remove" bindtap="removeEmployeeAvatar">移除</button>
|
||||
</view>
|
||||
<view class="form-grid">
|
||||
<view class="modal-field">
|
||||
<text class="required-label">姓名</text>
|
||||
|
||||
@@ -169,6 +169,46 @@
|
||||
transform: rotate(-45deg);
|
||||
}
|
||||
|
||||
.avatar-upload {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 16rpx;
|
||||
margin-bottom: 18rpx;
|
||||
padding: 18rpx;
|
||||
border-radius: 18rpx;
|
||||
background: #f7efe7;
|
||||
}
|
||||
|
||||
.avatar-preview {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
flex: 0 0 auto;
|
||||
width: 92rpx;
|
||||
height: 92rpx;
|
||||
overflow: hidden;
|
||||
border-radius: 50%;
|
||||
background: #6f8f83;
|
||||
color: #fff;
|
||||
font-size: 24rpx;
|
||||
font-weight: 900;
|
||||
}
|
||||
|
||||
.avatar-preview image {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.avatar-btn {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
max-width: none;
|
||||
}
|
||||
|
||||
.avatar-remove {
|
||||
flex: 0 0 auto;
|
||||
}
|
||||
|
||||
.form-grid {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr;
|
||||
|
||||
Reference in New Issue
Block a user