美化pagetype列表页badge配色

This commit is contained in:
jingrow 2025-11-01 17:34:49 +08:00
parent a2e4a0e074
commit 962d147fad

View File

@ -144,21 +144,27 @@
<div class="title">{{ row[primaryLabel] || row.name }}</div> <div class="title">{{ row[primaryLabel] || row.name }}</div>
<div class="desc">{{ row.name }}</div> <div class="desc">{{ row.name }}</div>
<div class="meta"> <div class="meta">
<span v-for="f in cardBadges" :key="f.key" class="badge"> <template v-for="f in cardBadges" :key="f.key">
<template v-if="isBooleanField(f.key) && (row[f.key] === 1 || row[f.key] === 0 || typeof row[f.key] === 'boolean')"> <!-- Select字段使用独立的span不包裹在.badge中 -->
<span v-if="row[f.key] === 1 || row[f.key] === true" class="boolean-true"></span> <span
<span v-else class="boolean-false"></span> v-if="isSelectField(f.key) && row[f.key]"
</template> class="select-badge"
<template v-else-if="isSelectField(f.key) && row[f.key]"> :style="{
<span backgroundColor: getSelectBadgeColor(f.key, row[f.key]),
class="select-badge" color: getSelectBadgeTextColor(f.key, row[f.key])
:style="{ backgroundColor: getSelectBadgeColor(f.key, row[f.key]) }" }"
> >
{{ formatDisplayValue(row[f.key], f.key) }} {{ formatDisplayValue(row[f.key], f.key) }}
</span> </span>
</template> <!-- 其他字段使用.badge包裹 -->
<template v-else>{{ formatDisplayValue(row[f.key], f.key) }}</template> <span v-else class="badge">
</span> <template v-if="isBooleanField(f.key) && (row[f.key] === 1 || row[f.key] === 0 || typeof row[f.key] === 'boolean')">
<span v-if="row[f.key] === 1 || row[f.key] === true" class="boolean-true"></span>
<span v-else class="boolean-false"></span>
</template>
<template v-else>{{ formatDisplayValue(row[f.key], f.key) }}</template>
</span>
</template>
</div> </div>
</div> </div>
</div> </div>
@ -246,7 +252,10 @@
<template v-else-if="isSelectField(col.key) && row[col.key]"> <template v-else-if="isSelectField(col.key) && row[col.key]">
<span <span
class="select-badge" class="select-badge"
:style="{ backgroundColor: getSelectBadgeColor(col.key, row[col.key]) }" :style="{
backgroundColor: getSelectBadgeColor(col.key, row[col.key]),
color: getSelectBadgeTextColor(col.key, row[col.key])
}"
> >
{{ formatDisplayValue(row[col.key], col.key) }} {{ formatDisplayValue(row[col.key], col.key) }}
</span> </span>
@ -1010,16 +1019,22 @@ function isSelectField(fieldName: string) {
return fieldMeta?.fieldtype === 'Select' return fieldMeta?.fieldtype === 'Select'
} }
// Select // Select
// { fieldName: { value: color } } { 'global': { value: color } } Select // { fieldName: { value: color } } { 'global': { value: color } } Select
// 'blue', 'green', 'red' '#3b82f6' // 使'#e0f2fe''#dcfce7'绿
const selectFieldColors = ref<Record<string, Record<string, string>>>({ const selectFieldColors = ref<Record<string, Record<string, string>>>({
// Select // Select
'global': { 'global': {
// // 使
} }
}) })
// Select
// selectFieldColors
const selectFieldTextColors = ref<Record<string, Record<string, string>>>({
'global': {}
})
// Select // Select
function getSelectBadgeColor(fieldName: string, value: any): string { function getSelectBadgeColor(fieldName: string, value: any): string {
if (!value || value === '') return '' if (!value || value === '') return ''
@ -1041,20 +1056,21 @@ function getSelectBadgeColor(fieldName: string, value: any): string {
} }
// 使 // 使
// 使
function getDefaultColorForValue(value: string): string { function getDefaultColorForValue(value: string): string {
// // +
const colors = [ const colors = [
'#3b82f6', // blue { bg: '#e6f8f0', text: '#0d684b' }, // 绿
'#10b981', // green { bg: '#dcfce7', text: '#166534' }, // 绿
'#f59e0b', // amber { bg: '#e0f2fe', text: '#0369a1' }, //
'#ef4444', // red { bg: '#fef9c3', text: '#713f12' }, //
'#8b5cf6', // violet { bg: '#fee2e2', text: '#991b1b' }, //
'#ec4899', // pink { bg: '#fdf2f8', text: '#9d174d' }, //
'#06b6d4', // cyan { bg: '#f5f3ff', text: '#6d28d9' }, //
'#84cc16', // lime { bg: '#fff7ed', text: '#9a3412' }, //
'#f97316', // orange { bg: '#f0fdfa', text: '#115e59' }, // 绿
'#6366f1', // indigo { bg: '#f1f5f9', text: '#0f172a' }, //
] ];
// //
let hash = 0 let hash = 0
@ -1063,7 +1079,40 @@ function getDefaultColorForValue(value: string): string {
hash = hash & hash // 32 hash = hash & hash // 32
} }
return colors[Math.abs(hash) % colors.length] const colorConfig = colors[Math.abs(hash) % colors.length]
//
return colorConfig.bg
}
// Select
function getSelectBadgeTextColor(fieldName: string, value: any): string {
if (!value || value === '') return '#374151'
const valueStr = String(value)
// 1.
if (selectFieldTextColors.value[fieldName] && selectFieldTextColors.value[fieldName][valueStr]) {
return selectFieldTextColors.value[fieldName][valueStr]
}
// 2.
if (selectFieldTextColors.value['global'] && selectFieldTextColors.value['global'][valueStr]) {
return selectFieldTextColors.value['global'][valueStr]
}
// 3. 使
const textColors = [
'#0369a1', '#166534', '#92400e', '#991b1b', '#6b21a8',
'#9f1239', '#0e7490', '#15803d', '#9a3412', '#4338ca'
]
let hash = 0
for (let i = 0; i < valueStr.length; i++) {
hash = ((hash << 5) - hash) + valueStr.charCodeAt(i)
hash = hash & hash
}
return textColors[Math.abs(hash) % textColors.length]
} }
function formatDisplayValue(value: any, fieldName: string) { function formatDisplayValue(value: any, fieldName: string) {
@ -1276,21 +1325,23 @@ function formatDisplayValue(value: any, fieldName: string) {
min-width: 0; min-width: 0;
} }
/* Select字段Badge样式 */ /* Select字段Badge样式 - 柔和现代风格 */
.select-badge { .select-badge {
display: inline-block; display: inline-block;
padding: 4px 10px; padding: 4px 12px;
border-radius: 12px; border-radius: 16px;
font-size: 12px; font-size: 12px;
font-weight: 500; font-weight: 500;
color: white;
white-space: nowrap; white-space: nowrap;
line-height: 1.4; line-height: 1.5;
transition: opacity 0.2s ease; transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
border: 1px solid rgba(0, 0, 0, 0.06);
backdrop-filter: blur(4px);
} }
.select-badge:hover { .select-badge:hover {
opacity: 0.9; transform: translateY(-1px);
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
} }
.card-actions { .card-actions {