WEB/src/views/storage/stockcheck/components/ColumnCellRenderer.vue
liufumingren 4dc90ac539 1
2026-10-01 09:07:35 +08:00

75 lines
2.5 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!--
ColumnCellRenderer — 通用表格列渲染器
根据传入的 ColumnSlotConfig 决定如何渲染单元格:
- type='tag' → 状态文字颜色(ut-status-text,替代 el-tag;支持 tagResolver / tagType 颜色映射)
- type='text' → 纯文本(支持 datetime 格式化)
- type='default' → 默认插槽渲染
- type='operation' → 操作列(由 OperationCellRenderer 处理)
-->
<template>
<template v-if="!config || config.type === 'default'">
<slot />
</template>
<template v-else-if="config.type === 'tag'">
<span :class="getStatusTextClass(resolvedTagType)">
{{ displayValue }}
</span>
</template>
<template v-else>
<span>{{ displayValue }}</span>
</template>
</template>
<script setup lang="ts">
import { computed } from 'vue'
import type { ColumnSlotConfig } from '../config/template-config'
import { TAG_RESOLVERS, translate, formatTime, formatDate } from '../config/template-config'
import { getStatusTextClass } from '@/views/order/orderManagement/config/order-common-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)
}
if (props.config?.format === 'date') {
return formatDate(v)
}
return v === undefined || v === null || v === '' ? '—' : 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>
<style lang="scss" scoped>
/* ut-status-text 系列状态文字颜色类定义在 order-sub.scss 里(scoped 样式需要本组件自行引入) */
@use "../../../order/orderManagement/styles/order-sub.scss";
</style>