新增美甲师页颜色选择抽屉与注册流程按钮样式同步设计稿
This commit is contained in:
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user