新增美甲师页颜色选择抽屉与注册流程按钮样式同步设计稿

This commit is contained in:
2026-11-07 00:31:33 +08:00
parent 54215ffd50
commit a5f050286b
6 changed files with 393 additions and 46 deletions
+136 -2
View File
@@ -3,6 +3,63 @@ const { chooseImageFilePath, uploadObjectFile } = require('../../utils/upload')
const { showErrorToast, toUserMessage } = require('../../utils/toast')
const EMPLOYEE_COLORS = ['#7BA7C7', '#8FB89A', '#A894C7', '#D7A86E', '#D98DA5', '#79A6A3', '#B9A16B', '#9BA9C8']
const COLOR_WHEEL_RADIUS = 110
function clamp(value, min, max) {
return Math.min(max, Math.max(min, value))
}
function normalizeHex(value) {
const raw = String(value || '').trim().replace('#', '')
if (/^[0-9a-fA-F]{3}$/.test(raw)) {
return ('#' + raw.split('').map(char => char + char).join('')).toUpperCase()
}
if (/^[0-9a-fA-F]{6}$/.test(raw)) return ('#' + raw).toUpperCase()
return ''
}
function rgbToHex(red, green, blue) {
return ('#' + [red, green, blue]
.map(value => Math.round(clamp(value, 0, 255)).toString(16).padStart(2, '0'))
.join('')).toUpperCase()
}
function hsvToHex(hue, saturation) {
const normalizedHue = ((Number(hue) % 360) + 360) % 360
const s = clamp(Number(saturation) || 0, 0, 1)
const chroma = s
const x = chroma * (1 - Math.abs(((normalizedHue / 60) % 2) - 1))
const offset = 1 - chroma
let red = 0
let green = 0
let blue = 0
if (normalizedHue < 60) { red = chroma; green = x }
else if (normalizedHue < 120) { red = x; green = chroma }
else if (normalizedHue < 180) { green = chroma; blue = x }
else if (normalizedHue < 240) { green = x; blue = chroma }
else if (normalizedHue < 300) { red = x; blue = chroma }
else { red = chroma; blue = x }
return rgbToHex((red + offset) * 255, (green + offset) * 255, (blue + offset) * 255)
}
function hexToHsv(value) {
const hex = normalizeHex(value) || '#8FB89A'
const red = parseInt(hex.slice(1, 3), 16) / 255
const green = parseInt(hex.slice(3, 5), 16) / 255
const blue = parseInt(hex.slice(5, 7), 16) / 255
const max = Math.max(red, green, blue)
const min = Math.min(red, green, blue)
const delta = max - min
let hue = 0
if (delta === 0) hue = 0
else if (max === red) hue = 60 * (((green - blue) / delta) % 6)
else if (max === green) hue = 60 * ((blue - red) / delta + 2)
else hue = 60 * ((red - green) / delta + 4)
return {
hue: ((hue % 360) + 360) % 360,
saturation: max === 0 ? 0 : delta / max
}
}
Page({
data: {
@@ -10,6 +67,11 @@ Page({
appointmentContext: { date: '', time: '', durationMinutes: '' },
applicationId: '',
employeeColors: EMPLOYEE_COLORS,
colorSheetVisible: false,
colorDraft: '#8FB89A',
colorHexInput: '#8FB89A',
wheelDotX: COLOR_WHEEL_RADIUS,
wheelDotY: 0,
onboardingVisible: false,
createdEmployee: null,
userPickerVisible: false,
@@ -56,8 +118,80 @@ Page({
this.setData({ [`form.${field}`]: value })
},
selectColor(event) {
this.setData({ 'form.color': event.currentTarget.dataset.color })
openColorSheet() {
const color = normalizeHex(this.data.form.color) || '#8FB89A'
this.setData({ colorSheetVisible: true, colorDraft: color, colorHexInput: color })
this.applyDraftColor(color)
if (typeof wx.nextTick === 'function') {
wx.nextTick(() => {
wx.createSelectorQuery().in(this).select('.color-wheel').boundingClientRect(rect => {
this._wheelRect = rect
}).exec()
})
}
},
closeColorSheet() {
this.setData({ colorSheetVisible: false })
},
stopColorSheetTap() {},
pickDraftColor(event) {
const color = normalizeHex(event.currentTarget.dataset.color)
if (color) this.applyDraftColor(color)
},
onColorHexInput(event) {
this.setData({ colorHexInput: event.detail.value })
},
applyColorHex() {
const color = normalizeHex(this.data.colorHexInput)
if (!color) {
wx.showToast({ title: '请输入有效的十六进制色值', icon: 'none' })
return
}
this.applyDraftColor(color)
},
applyDraftColor(color) {
const { hue, saturation } = hexToHsv(color)
const angle = (hue - 90) * Math.PI / 180
const distance = saturation * COLOR_WHEEL_RADIUS
this.setData({
colorDraft: color,
colorHexInput: color,
wheelDotX: Math.round(COLOR_WHEEL_RADIUS + Math.cos(angle) * distance),
wheelDotY: Math.round(COLOR_WHEEL_RADIUS + Math.sin(angle) * distance)
})
},
applyWheelPoint(clientX, clientY) {
const rect = this._wheelRect
if (!rect || !rect.width) return
const centerX = rect.left + rect.width / 2
const centerY = rect.top + rect.height / 2
const radius = rect.width / 2
const offsetX = clientX - centerX
const offsetY = clientY - centerY
const distance = Math.min(radius, Math.sqrt(offsetX * offsetX + offsetY * offsetY))
const hue = ((Math.atan2(offsetY, offsetX) * 180 / Math.PI + 90) % 360 + 360) % 360
this.applyDraftColor(hsvToHex(hue, radius ? distance / radius : 0))
},
onWheelTap(event) {
const touch = event.touches && event.touches[0]
if (touch) this.applyWheelPoint(touch.clientX, touch.clientY)
},
onWheelTouch(event) {
const touch = event.touches && event.touches[0]
if (touch) this.applyWheelPoint(touch.clientX, touch.clientY)
},
saveColorSheet() {
this.setData({ 'form.color': this.data.colorDraft, colorSheetVisible: false })
},
async openUserPicker() {
@@ -35,8 +35,10 @@
</view>
<view class="field color-field">
<text class="field-label required">日程中排班展示颜色</text>
<view class="color-options">
<view wx:for="{{employeeColors}}" wx:key="*this" class="color-option {{form.color === item ? 'selected' : ''}}" style="background: {{item}};" data-color="{{item}}" bindtap="selectColor"></view>
<view class="color-current">
<view class="color-current-chip" style="background: {{form.color}};"></view>
<text class="color-current-value">{{form.color}}</text>
<view class="color-select-btn" bindtap="openColorSheet">选择颜色<text class="color-select-arrow">›</text></view>
</view>
</view>
</view>
@@ -62,6 +64,27 @@
</block>
</view>
</view>
<view wx:if="{{colorSheetVisible}}" class="color-sheet-mask" catchtouchmove="stopTouchMove" catchtap="closeColorSheet">
<view class="color-sheet" catchtap="stopColorSheetTap">
<view class="color-sheet-handle"></view>
<text class="color-sheet-title">选择颜色</text>
<view class="color-preview" style="background: {{colorDraft}};"></view>
<text class="color-section-title">推荐色</text>
<view class="color-grid">
<view wx:for="{{employeeColors}}" wx:key="*this" class="color-grid-item {{colorDraft === item ? 'selected' : ''}}" style="background: {{item}};" data-color="{{item}}" bindtap="pickDraftColor"></view>
</view>
<text class="color-section-title">色轮</text>
<view class="color-wheel" bindtap="onWheelTap" catchtouchmove="onWheelTouch">
<view class="color-wheel-dot" style="left: {{wheelDotX}}rpx; top: {{wheelDotY}}rpx; background: {{colorDraft}};"></view>
</view>
<text class="color-section-title">自定义色值</text>
<view class="color-hex-row">
<input class="color-hex-input" value="{{colorHexInput}}" bindinput="onColorHexInput" maxlength="7" placeholder="#8FB89A" />
<button class="color-apply-btn" bindtap="applyColorHex">应用</button>
</view>
<button class="primary-btn color-save-btn" bindtap="saveColorSheet">保存颜色</button>
</view>
</view>
<entity-selector-sheet visible="{{userPickerVisible}}" title="选择微信用户" keyword="{{userKeyword}}" placeholder="搜索昵称或手机号" items="{{userItems}}" selected-id="{{selectedWechatUserId}}" loading="{{userLoading}}" empty-text="暂无未关联的微信用户" action-text="暂不关联" bind:search="onUserSearch" bind:select="selectWechatUser" bind:action="closeUserPicker" bind:close="closeUserPicker" />
<entity-selector-sheet visible="{{associationSheetVisible}}" title="关联待审核申请" keyword="{{associationKeyword}}" placeholder="搜索申请昵称、手机号或编号" items="{{associationItems}}" selected-id="{{associationSelectedId}}" loading="{{associationLoading}}" empty-text="暂无可关联申请" action-text="暂不关联,继续" bind:search="onAssociationSearch" bind:select="selectAssociation" bind:action="skipAssociation" bind:close="skipAssociation" />
</view>
+154 -11
View File
@@ -95,23 +95,166 @@
width: 176rpx;
}
.color-options {
.color-current {
display: flex;
flex-wrap: wrap;
gap: 18rpx;
padding: 10rpx 0;
flex: 1;
min-width: 0;
align-items: center;
gap: 16rpx;
}
.color-option {
width: 44rpx;
height: 44rpx;
border: 4rpx solid #fff;
border-radius: 50%;
.color-current-chip {
width: 56rpx;
height: 56rpx;
flex: none;
border-radius: 14rpx;
box-shadow: 0 0 0 1rpx #d9e3dd;
}
.color-option.selected {
box-shadow: 0 0 0 4rpx #287a62;
.color-current-value {
color: #71807a;
font-size: 24rpx;
}
.color-select-btn {
display: flex;
flex: none;
align-items: center;
gap: 6rpx;
height: 56rpx;
margin-left: auto;
padding: 0 20rpx;
border: 1rpx solid #e7ece9;
border-radius: 999rpx;
background: #f1f3f2;
color: #71807a;
font-size: 23rpx;
font-weight: 700;
}
.color-select-arrow {
font-size: 24rpx;
line-height: 1;
}
.color-sheet-mask {
position: fixed;
z-index: 60;
inset: 0;
display: flex;
align-items: flex-end;
background: rgba(23, 33, 31, 0.45);
}
.color-sheet {
box-sizing: border-box;
width: 100%;
padding: 12rpx 28rpx calc(28rpx + env(safe-area-inset-bottom));
border-radius: 40rpx 40rpx 0 0;
background: #ffffff;
}
.color-sheet-handle {
width: 72rpx;
height: 8rpx;
margin: 0 auto 18rpx;
border-radius: 999rpx;
background: #dfe5e2;
}
.color-sheet-title {
display: block;
color: #17211f;
font-size: 30rpx;
font-weight: 800;
text-align: center;
}
.color-preview {
height: 110rpx;
margin-top: 18rpx;
border-radius: 16rpx;
box-shadow: 0 0 0 1rpx #e7ece9 inset;
}
.color-section-title {
display: block;
margin-top: 20rpx;
color: #71807a;
font-size: 22rpx;
}
.color-grid {
display: grid;
grid-template-columns: repeat(8, 1fr);
gap: 14rpx;
margin-top: 12rpx;
}
.color-grid-item {
height: 56rpx;
border-radius: 12rpx;
box-shadow: 0 0 0 1rpx #e7ece9;
}
.color-grid-item.selected {
box-shadow: 0 0 0 4rpx #247b63;
}
.color-wheel {
position: relative;
width: 220rpx;
height: 220rpx;
margin: 18rpx auto 0;
border-radius: 50%;
background: radial-gradient(circle, #ffffff 0%, rgba(255, 255, 255, 0) 72%), conic-gradient(#ff0000, #ffff00, #00ff00, #00ffff, #0000ff, #ff00ff, #ff0000);
}
.color-wheel-dot {
position: absolute;
width: 26rpx;
height: 26rpx;
border: 3rpx solid #ffffff;
border-radius: 50%;
box-shadow: 0 0 0 1rpx rgba(0, 0, 0, 0.25);
transform: translate(-50%, -50%);
}
.color-hex-row {
display: flex;
align-items: center;
gap: 16rpx;
margin-top: 12rpx;
}
.color-hex-input {
flex: 1;
min-width: 0;
height: 80rpx;
padding: 0 24rpx;
border: 1rpx solid #e7ece9;
border-radius: 12rpx;
background: #f7faf8;
font-size: 26rpx;
}
.color-apply-btn {
display: flex;
flex: none;
align-items: center;
height: 80rpx;
margin: 0;
padding: 0 28rpx;
border-radius: 12rpx;
background: #e5f4ed;
color: #247b63;
font-size: 24rpx;
font-weight: 700;
line-height: 80rpx;
}
.color-save-btn {
margin-top: 24rpx;
}
.onboarding-mask {