56 lines
1.6 KiB
Vue
56 lines
1.6 KiB
Vue
<template>
|
||
<template v-if="!config || config.type === 'default'">
|
||
<slot />
|
||
</template>
|
||
<template v-else-if="config.type === 'tag'">
|
||
<el-tag size="small" :type="resolvedTagType">
|
||
{{ displayValue }}
|
||
</el-tag>
|
||
</template>
|
||
<template v-else>
|
||
<span>{{ displayValue }}</span>
|
||
</template>
|
||
</template>
|
||
|
||
<script setup lang="ts">
|
||
import { computed } from 'vue'
|
||
import type { ColumnSlotConfig } from '../config/waveorder-config'
|
||
import { TAG_RESOLVERS, translate, formatTime } from '../config/waveorder-config'
|
||
|
||
defineOptions({ name: 'ColumnCellRenderer' })
|
||
|
||
const props = defineProps<{
|
||
/** 列插槽渲染配置 */
|
||
config: ColumnSlotConfig | undefined
|
||
/** 单元格值 */
|
||
value: any
|
||
}>()
|
||
|
||
/** 显示文本:translateField 翻译 > format 格式化 > 原始值 */
|
||
const displayValue = computed(() => {
|
||
const v = props.value
|
||
if (props.config?.translateField) {
|
||
return translate(props.config.translateField, v)
|
||
}
|
||
if (props.config?.format === 'datetime') {
|
||
return formatTime(v)
|
||
}
|
||
return v
|
||
})
|
||
|
||
const resolvedTagType = computed(() => {
|
||
if (!props.config || props.config.type !== 'tag') return ''
|
||
const { tagType, tagResolver } = props.config
|
||
// 优先使用 tagResolver(函数名映射)
|
||
if (tagResolver && TAG_RESOLVERS[tagResolver]) {
|
||
return TAG_RESOLVERS[tagResolver](props.value)
|
||
}
|
||
// 其次使用 tagType 映射表(用翻译后的值查找)
|
||
if (tagType && typeof tagType === 'object') {
|
||
return tagType[String(props.value)] ?? 'info'
|
||
}
|
||
// 最后使用固定值
|
||
return (typeof tagType === 'string' ? tagType : 'info')
|
||
})
|
||
</script>
|