Files
JayuCloud/FM-Front/src/views/ColorSettingView.vue
T

63 lines
1.8 KiB
Vue

<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>
</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 MobileShell from '@/components/MobileShell.vue'
import { useToastStore } from '@/stores/toast'
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 selectColor = (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 save = (): void => {
toast.success('已保存到本地')
}
</script>
<style scoped>
.color-grid {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 12px;
}
.color-swatch {
aspect-ratio: 1;
border: 4px solid transparent;
border-radius: 18px;
box-shadow: var(--shadow);
}
.color-swatch.active {
border-color: var(--card-bg);
outline: 3px solid var(--accent);
}
</style>