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