修复员工颜色设置
This commit is contained in:
+5
@@ -49,6 +49,11 @@ public class NailArtistInfoDTO {
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* 预约展示颜色
|
||||
*/
|
||||
private String color;
|
||||
|
||||
/**
|
||||
* Field `participateProduction` (Integer): data variable carried by this DTO/VO/entity. Check controller/service usage to see when it is filled.
|
||||
*/
|
||||
|
||||
+5
@@ -47,6 +47,11 @@ public class NailArtistInfoDO extends BaseEntity {
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* 预约展示颜色
|
||||
*/
|
||||
private String color;
|
||||
|
||||
@TableField("participate_production")
|
||||
/**
|
||||
* Field `participateProduction` (Integer): data variable carried by this DTO/VO/entity. Check controller/service usage to see when it is filled.
|
||||
|
||||
+8
-1
@@ -314,7 +314,7 @@ public class PlanningServiceImpl implements PlanningService {
|
||||
vo.setShortName(PlanningCalendarSupport.shortName(vo.getName()));
|
||||
vo.setPhone(firstNonBlank(user.getContactPhone(), user.getPhone(), ""));
|
||||
vo.setAvatar(user.getAvatar());
|
||||
vo.setColor(colorForArtist(user.getId(), i));
|
||||
vo.setColor(resolveArtistColor(info, user.getId(), i));
|
||||
vo.setStatus(info == null || info.getStatus() == null ? user.getStatus() : info.getStatus());
|
||||
vo.setStatusText(Integer.valueOf(0).equals(vo.getStatus()) ? "休息" : "可预约");
|
||||
vo.setWorkStartTime(info == null || info.getWorkStartTime() == null ? null : info.getWorkStartTime().toString());
|
||||
@@ -846,6 +846,13 @@ public class PlanningServiceImpl implements PlanningService {
|
||||
.collect(Collectors.toMap(UserDO::getId, Function.identity(), (a, b) -> a));
|
||||
}
|
||||
|
||||
private String resolveArtistColor(NailArtistInfoDO info, Long artistId, int index) {
|
||||
if (info != null && hasText(info.getColor()) && info.getColor().trim().matches("^#[0-9a-fA-F]{6}$")) {
|
||||
return info.getColor().trim().toUpperCase();
|
||||
}
|
||||
return colorForArtist(artistId, index);
|
||||
}
|
||||
|
||||
private String colorForArtist(Long artistId, int index) {
|
||||
if (artistId == null) {
|
||||
return ARTIST_COLORS.get(index % ARTIST_COLORS.size());
|
||||
|
||||
@@ -1,47 +1,172 @@
|
||||
<template>
|
||||
<MobileShell title="颜色设置">
|
||||
<section class="color-grid">
|
||||
<button v-for="color in presets" :key="color" class="color-swatch" :class="{ active: selected === color }" :style="{ backgroundColor: color }" type="button" @click="selectColor(color)"></button>
|
||||
<LoadingState v-if="loading" text="正在加载颜色" />
|
||||
<template v-else-if="employee">
|
||||
<section class="card color-preview">
|
||||
<span class="preview-dot" :style="{ backgroundColor: selected }"></span>
|
||||
<div>
|
||||
<h2>{{ employeeName }}</h2>
|
||||
<p>{{ selected }}</p>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="color-grid section">
|
||||
<button v-for="color in presets" :key="color" class="color-swatch" :class="{ active: selected === color }" :style="{ backgroundColor: color }" type="button" @click="selectColor(color)"></button>
|
||||
</section>
|
||||
|
||||
<section class="card form-card section">
|
||||
<div class="field color-picker-field">
|
||||
<label>色盘选择</label>
|
||||
<input class="native-color" type="color" :value="selected" @input="onPickerInput" />
|
||||
</div>
|
||||
<div class="field"><label>自定义色值</label><input v-model.trim="customColor" placeholder="#6F8F83" @blur="applyCustom" /></div>
|
||||
</section>
|
||||
|
||||
<button class="primary-btn section" type="button" :disabled="saving" @click="save">{{ saving ? '保存中...' : '保存颜色' }}</button>
|
||||
</template>
|
||||
<section v-else class="card empty-card">
|
||||
<strong>员工不存在</strong>
|
||||
<p>请返回员工列表重新选择</p>
|
||||
</section>
|
||||
<section class="card form-card section">
|
||||
<div class="field"><label>自定义色值</label><input v-model.trim="customColor" placeholder="#6F8F83" /></div>
|
||||
</section>
|
||||
<button class="primary-btn section" type="button" @click="applyCustom">应用自定义颜色</button>
|
||||
<button class="secondary-btn section" type="button" @click="save">保存</button>
|
||||
</MobileShell>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref } from 'vue'
|
||||
import { computed, onMounted, ref } from 'vue'
|
||||
import { useRoute } from 'vue-router'
|
||||
import LoadingState from '@/components/LoadingState.vue'
|
||||
import MobileShell from '@/components/MobileShell.vue'
|
||||
import { managerEmployeesApi } from '@/api/managerEmployees'
|
||||
import { useToastStore } from '@/stores/toast'
|
||||
import type { Artist } from '@/types/manager'
|
||||
|
||||
const route = useRoute()
|
||||
const toast = useToastStore()
|
||||
const presets = ['#6F8F83', '#C58C6D', '#8B6F8F', '#6F7F8F', '#B86B6B', '#B8A36B', '#7A9D96', '#9D7A7A']
|
||||
const defaultColor = presets[0] as string
|
||||
const selected = ref(defaultColor)
|
||||
const customColor = ref(defaultColor)
|
||||
const loading = ref(false)
|
||||
const saving = ref(false)
|
||||
const employee = ref<Artist | null>(null)
|
||||
const employeeId = computed(() => String(route.params.id))
|
||||
const employeeName = computed(() => employee.value?.name || employee.value?.nickname || '未命名员工')
|
||||
|
||||
const selectColor = (color: string): void => {
|
||||
const normalizeColor = (value: string | undefined): string | null => {
|
||||
if (!value) {
|
||||
return null
|
||||
}
|
||||
const color = value.trim().toUpperCase()
|
||||
return /^#[0-9A-F]{6}$/.test(color) ? color : null
|
||||
}
|
||||
|
||||
const syncColor = (color: string): void => {
|
||||
selected.value = color
|
||||
customColor.value = color
|
||||
}
|
||||
|
||||
const applyCustom = (): void => {
|
||||
if (!/^#[0-9a-fA-F]{6}$/.test(customColor.value)) {
|
||||
toast.error('请输入6位色值')
|
||||
return
|
||||
}
|
||||
selected.value = customColor.value.toUpperCase()
|
||||
customColor.value = selected.value
|
||||
const errorMessage = (error: { message?: string } | null, fallback: string): string => {
|
||||
return error?.message ? error.message : fallback
|
||||
}
|
||||
|
||||
const save = (): void => {
|
||||
toast.success('已保存到本地')
|
||||
const selectColor = (color: string): void => {
|
||||
const normalizedColor = normalizeColor(color)
|
||||
if (normalizedColor) {
|
||||
syncColor(normalizedColor)
|
||||
}
|
||||
}
|
||||
|
||||
const onPickerInput = (event: Event): void => {
|
||||
const input = event.target as HTMLInputElement
|
||||
const normalizedColor = normalizeColor(input.value)
|
||||
if (normalizedColor) {
|
||||
syncColor(normalizedColor)
|
||||
}
|
||||
}
|
||||
|
||||
const applyCustom = (): boolean => {
|
||||
const normalizedColor = normalizeColor(customColor.value)
|
||||
if (!normalizedColor) {
|
||||
toast.error('请输入#开头的6位色值')
|
||||
return false
|
||||
}
|
||||
syncColor(normalizedColor)
|
||||
return true
|
||||
}
|
||||
|
||||
const loadEmployee = async (): Promise<void> => {
|
||||
loading.value = true
|
||||
try {
|
||||
const detail = await managerEmployeesApi.detail(employeeId.value)
|
||||
if (!detail) {
|
||||
employee.value = null
|
||||
toast.error('员工不存在')
|
||||
return
|
||||
}
|
||||
employee.value = detail
|
||||
syncColor(normalizeColor(detail.color) || defaultColor)
|
||||
} catch (error) {
|
||||
toast.error(errorMessage(error as { message?: string } | null, '颜色加载失败,请稍后重试'))
|
||||
employee.value = null
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const save = async (): Promise<void> => {
|
||||
if (!employee.value || !applyCustom()) {
|
||||
return
|
||||
}
|
||||
saving.value = true
|
||||
try {
|
||||
const color = selected.value
|
||||
const saved = await managerEmployeesApi.save({
|
||||
...employee.value,
|
||||
userId: employee.value.userId || employeeId.value,
|
||||
color
|
||||
})
|
||||
employee.value = { ...employee.value, ...saved, color: normalizeColor(saved.color) || color }
|
||||
syncColor(color)
|
||||
toast.success('颜色已保存')
|
||||
} catch (error) {
|
||||
toast.error(errorMessage(error as { message?: string } | null, '颜色保存失败,请稍后重试'))
|
||||
} finally {
|
||||
saving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
void loadEmployee()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.color-preview {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 14px;
|
||||
padding: 18px;
|
||||
}
|
||||
|
||||
.preview-dot {
|
||||
width: 58px;
|
||||
height: 58px;
|
||||
border: 4px solid var(--card-bg);
|
||||
border-radius: 20px;
|
||||
box-shadow: var(--shadow);
|
||||
}
|
||||
|
||||
.color-preview h2,
|
||||
.color-preview p {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.color-preview p {
|
||||
margin-top: 4px;
|
||||
color: var(--muted);
|
||||
font-weight: 800;
|
||||
}
|
||||
|
||||
.color-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(4, 1fr);
|
||||
@@ -59,4 +184,42 @@ const save = (): void => {
|
||||
border-color: var(--card-bg);
|
||||
outline: 3px solid var(--accent);
|
||||
}
|
||||
|
||||
.color-picker-field {
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.field .native-color {
|
||||
flex: 0 0 54px;
|
||||
width: 54px;
|
||||
height: 36px;
|
||||
padding: 0;
|
||||
overflow: hidden;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 12px;
|
||||
background: var(--card-bg);
|
||||
}
|
||||
|
||||
.native-color::-webkit-color-swatch-wrapper {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.native-color::-webkit-color-swatch {
|
||||
border: 0;
|
||||
border-radius: 10px;
|
||||
}
|
||||
|
||||
.primary-btn:disabled {
|
||||
opacity: 0.65;
|
||||
}
|
||||
|
||||
.empty-card {
|
||||
padding: 24px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.empty-card p {
|
||||
margin: 8px 0 0;
|
||||
color: var(--muted);
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
CREATE DATABASE IF NOT EXISTS jayu_cloud DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
use jayu_cloud;
|
||||
|
||||
DROP PROCEDURE IF EXISTS sp_jy_add_column_if_not_exists;
|
||||
DELIMITER $$
|
||||
CREATE PROCEDURE sp_jy_add_column_if_not_exists(
|
||||
IN p_table_name varchar(128),
|
||||
IN p_column_name varchar(128),
|
||||
IN p_column_sql varchar(1000)
|
||||
)
|
||||
BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM information_schema.columns
|
||||
WHERE table_schema = DATABASE()
|
||||
AND table_name = p_table_name
|
||||
AND column_name = p_column_name
|
||||
) THEN
|
||||
SET @jy_sql = CONCAT('ALTER TABLE ', p_table_name, ' ADD COLUMN ', p_column_sql);
|
||||
PREPARE jy_stmt FROM @jy_sql;
|
||||
EXECUTE jy_stmt;
|
||||
DEALLOCATE PREPARE jy_stmt;
|
||||
END IF;
|
||||
END$$
|
||||
DELIMITER ;
|
||||
|
||||
CALL sp_jy_add_column_if_not_exists('t_nail_artist_info', 'color', '`color` varchar(20) NULL COMMENT ''员工预约展示颜色''');
|
||||
|
||||
DROP PROCEDURE IF EXISTS sp_jy_add_column_if_not_exists;
|
||||
Reference in New Issue
Block a user