Icon字段类型直接显示图标

This commit is contained in:
jingrow 2025-11-01 19:30:48 +08:00
parent cb9543448f
commit 1fe27e25ca
2 changed files with 84 additions and 5 deletions

View File

@ -1,11 +1,17 @@
<script setup lang="ts"> <script setup lang="ts">
import { computed } from 'vue' import { computed } from 'vue'
import { NInput } from 'naive-ui' import { NInput } from 'naive-ui'
import { Icon } from '@iconify/vue'
const props = defineProps<{ df: any; record: Record<string, any>; canEdit: boolean; ctx: any }>() const props = defineProps<{ df: any; record: Record<string, any>; canEdit: boolean; ctx: any }>()
// Label(vertical) (horizontal) // Label(vertical) (horizontal)
const labelLayout = computed(() => props.df.label_layout || 'vertical') const labelLayout = computed(() => props.df.label_layout || 'vertical')
//
const iconValue = computed(() => {
return props.record[props.df.fieldname] || ''
})
</script> </script>
<template> <template>
@ -14,11 +20,27 @@ const labelLayout = computed(() => props.df.label_layout || 'vertical')
{{ ctx.t(df.label || df.fieldname) }} {{ ctx.t(df.label || df.fieldname) }}
<span v-if="df.reqd" class="required">*</span> <span v-if="df.reqd" class="required">*</span>
</label> </label>
<n-input <!-- Icon 字段特殊布局左边显示图标右边显示字段值 -->
v-model:value="record[df.fieldname]" <div class="icon-field-content">
:placeholder="ctx.t(df.fieldname)" <!-- 左侧图标 -->
:disabled="!canEdit" <div class="icon-display">
/> <Icon v-if="iconValue" :icon="iconValue" :width="24" :height="24" class="icon-gray" />
<span v-else class="icon-placeholder"></span>
</div>
<!-- 右侧字段值 -->
<div class="icon-value-display">
<!-- 只读模式显示文本值 -->
<span v-if="!canEdit" class="field-value-text">
{{ iconValue || '—' }}
</span>
<!-- 编辑模式显示输入框 -->
<n-input
v-else
v-model:value="record[df.fieldname]"
:placeholder="ctx.t(df.fieldname)"
/>
</div>
</div>
</div> </div>
</template> </template>
@ -26,6 +48,45 @@ const labelLayout = computed(() => props.df.label_layout || 'vertical')
.field-wrapper :deep(.n-input) { .field-wrapper :deep(.n-input) {
flex: 1; flex: 1;
} }
.icon-field-content {
display: flex;
align-items: center;
gap: 12px;
flex: 1;
}
.icon-display {
display: flex;
align-items: center;
justify-content: center;
min-width: 32px;
width: 32px;
height: 32px;
flex-shrink: 0;
}
.icon-gray {
color: #9ca3af;
}
.icon-placeholder {
color: #9ca3af;
font-size: 14px;
}
.icon-value-display {
flex: 1;
min-width: 0;
}
.field-value-text {
color: #111827;
font-size: 14px;
min-height: 32px;
display: flex;
align-items: center;
}
</style> </style>

View File

@ -154,6 +154,9 @@
<span v-if="row[f.key] === 1 || row[f.key] === true" class="boolean-true"></span> <span v-if="row[f.key] === 1 || row[f.key] === true" class="boolean-true"></span>
<span v-else class="boolean-false"></span> <span v-else class="boolean-false"></span>
</template> </template>
<template v-else-if="isIconField(f.key) && row[f.key]">
<Icon :icon="row[f.key]" :width="20" :height="20" class="icon-gray" />
</template>
<template v-else>{{ formatDisplayValue(row[f.key], f.key) }}</template> <template v-else>{{ formatDisplayValue(row[f.key], f.key) }}</template>
</span> </span>
</template> </template>
@ -241,6 +244,9 @@
<span v-if="row[col.key] === 1 || row[col.key] === true" class="boolean-true"></span> <span v-if="row[col.key] === 1 || row[col.key] === true" class="boolean-true"></span>
<span v-else class="boolean-false"></span> <span v-else class="boolean-false"></span>
</template> </template>
<template v-else-if="isIconField(col.key) && row[col.key]">
<Icon :icon="row[col.key]" :width="20" :height="20" class="icon-gray" />
</template>
<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"
@ -298,6 +304,7 @@
import { onMounted, ref, computed, watch, shallowRef, markRaw } from 'vue' import { onMounted, ref, computed, watch, shallowRef, markRaw } from 'vue'
import { useRoute, useRouter } from 'vue-router' import { useRoute, useRouter } from 'vue-router'
import { NInput, NPagination, useMessage } from 'naive-ui' import { NInput, NPagination, useMessage } from 'naive-ui'
import { Icon } from '@iconify/vue'
import axios from 'axios' import axios from 'axios'
import { t } from '@/shared/i18n' import { t } from '@/shared/i18n'
import { get_session_api_headers } from '@/shared/api/auth' import { get_session_api_headers } from '@/shared/api/auth'
@ -1070,6 +1077,12 @@ function isSelectField(fieldName: string) {
return fieldMeta?.fieldtype === 'Select' return fieldMeta?.fieldtype === 'Select'
} }
// Icon
function isIconField(fieldName: string) {
const fieldMeta = metaFields.value.find(f => f.fieldname === fieldName)
return fieldMeta?.fieldtype === 'Icon'
}
// Select // Select
// { fieldName: { value: color } } { 'global': { value: color } } Select // { fieldName: { value: color } } { 'global': { value: color } } Select
// 使'#e0f2fe''#dcfce7'绿 // 使'#e0f2fe''#dcfce7'绿
@ -1738,6 +1751,11 @@ function formatDisplayValue(value: any, fieldName: string) {
font-size: 16px; font-size: 16px;
} }
/* Icon 字段图标样式 - 灰色系 */
.icon-gray {
color: #9ca3af;
}
/* 列表列通用样式 - 确保垂直居中 */ /* 列表列通用样式 - 确保垂直居中 */
.list-header > div:not(.col-checkbox), .list-header > div:not(.col-checkbox),
.list-item > div:not(.col-checkbox):not(.col-actions) { .list-item > div:not(.col-checkbox):not(.col-actions) {