169 lines
4.4 KiB
Vue
169 lines
4.4 KiB
Vue
<template>
|
|
<div class="wave-order2-detail">
|
|
<div v-if="!row" class="empty-tip">请从上方列表中选择一项查看明细</div>
|
|
<template v-else>
|
|
<div
|
|
v-for="(section, si) in detailConfig"
|
|
:key="si"
|
|
class="section"
|
|
>
|
|
<div class="section-title">{{ section.title }}</div>
|
|
<el-descriptions
|
|
:column="section.columnCount"
|
|
border
|
|
size="small"
|
|
class="detail-descriptions"
|
|
>
|
|
<el-descriptions-item
|
|
v-for="(field, fi) in section.fields"
|
|
:key="fi"
|
|
:label="field.label"
|
|
:span="field.span ?? 1"
|
|
>
|
|
<!-- tag 渲染 -->
|
|
<template v-if="field.renderType === 'tag'">
|
|
<el-tag size="small" :type="resolveTagType(field, getRowData()?.[field.key])">
|
|
{{ resolveDisplayValue(field, getRowData()?.[field.key]) }}
|
|
</el-tag>
|
|
</template>
|
|
<!-- pre 渲染 -->
|
|
<template v-else-if="field.renderType === 'pre'">
|
|
<pre class="order-list-pre">{{ getRowData()?.[field.key] ?? '—' }}</pre>
|
|
</template>
|
|
<!-- 默认文本渲染 -->
|
|
<template v-else>
|
|
{{ resolveDisplayValue(field, getRowData()?.[field.key]) }}
|
|
</template>
|
|
</el-descriptions-item>
|
|
</el-descriptions>
|
|
</div>
|
|
</template>
|
|
</div>
|
|
</template>
|
|
|
|
<script setup lang="ts">
|
|
import { ref, watch } from 'vue'
|
|
import { TAG_RESOLVERS, translate, formatTime } from '../../config/waveorder-config'
|
|
import type { DetailSectionConfig, DetailFieldConfig } from '../../config/waveorder-config'
|
|
|
|
defineOptions({ name: 'WaveOrder2DetailPanel' })
|
|
|
|
const props = defineProps<{
|
|
row: Record<string, any> | null
|
|
/** 明细区域配置(由各页面在 waveorder-config.ts 中配置) */
|
|
detailConfig: DetailSectionConfig[]
|
|
/** 可选的 detail API 方法,传入后自动调用获取完整明细数据 */
|
|
apiMethod?: (...args: any[]) => Promise<any>
|
|
}>()
|
|
|
|
/** 通过 API 获取的增强数据(与 row 合并) */
|
|
const enrichedData = ref<Record<string, any> | null>(null)
|
|
|
|
watch(() => props.row, async (newRow) => {
|
|
if (newRow && props.apiMethod) {
|
|
try {
|
|
const res = await props.apiMethod({
|
|
wave_id: newRow.wave_id ?? newRow.id,
|
|
wave_no: newRow.wave_no
|
|
})
|
|
if (res && (res.code === 1 || res.code === 200)) {
|
|
enrichedData.value = res.data ?? res
|
|
} else {
|
|
enrichedData.value = null
|
|
}
|
|
} catch {
|
|
enrichedData.value = null
|
|
}
|
|
} else {
|
|
enrichedData.value = null
|
|
}
|
|
}, { immediate: true })
|
|
|
|
/** 合并 row + API 增强数据 */
|
|
function getRowData(): Record<string, any> | null {
|
|
if (!props.row) return null
|
|
if (enrichedData.value) {
|
|
return { ...props.row, ...enrichedData.value }
|
|
}
|
|
return props.row
|
|
}
|
|
|
|
/** 解析显示值:优先使用 translateField 翻译,然后 format 格式化,否则显示原始值 */
|
|
function resolveDisplayValue(field: DetailFieldConfig, value: any): string {
|
|
if (field.translateField) {
|
|
return translate(field.translateField, value)
|
|
}
|
|
if (field.format === 'datetime') {
|
|
return formatTime(value)
|
|
}
|
|
return value ?? '—'
|
|
}
|
|
|
|
/** 解析 tag 颜色 */
|
|
function resolveTagType(field: DetailFieldConfig, value: any): string {
|
|
if (field.tagResolver) {
|
|
const resolver = TAG_RESOLVERS[field.tagResolver]
|
|
if (resolver) return resolver(value)
|
|
}
|
|
if (field.tagType) {
|
|
if (typeof field.tagType === 'object') {
|
|
return field.tagType[String(value)] ?? 'info'
|
|
}
|
|
return field.tagType
|
|
}
|
|
return 'info'
|
|
}
|
|
</script>
|
|
|
|
<style lang="scss" scoped>
|
|
.wave-order2-detail {
|
|
height: 100%;
|
|
overflow-y: auto;
|
|
padding: 16px;
|
|
}
|
|
|
|
.empty-tip {
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
height: 100%;
|
|
font-size: 14px;
|
|
color: #909399;
|
|
}
|
|
|
|
.section {
|
|
margin-bottom: 16px;
|
|
|
|
&:last-child {
|
|
margin-bottom: 0;
|
|
}
|
|
|
|
.section-title {
|
|
font-size: 14px;
|
|
font-weight: 600;
|
|
color: #303133;
|
|
margin-bottom: 10px;
|
|
padding-left: 8px;
|
|
border-left: 3px solid #409eff;
|
|
line-height: 1.4;
|
|
}
|
|
}
|
|
|
|
.detail-descriptions {
|
|
:deep(.el-descriptions__label) {
|
|
width: 120px;
|
|
background: #fafbfc;
|
|
font-weight: 500;
|
|
}
|
|
}
|
|
|
|
.order-list-pre {
|
|
margin: 0;
|
|
font-family: inherit;
|
|
font-size: 13px;
|
|
line-height: 1.8;
|
|
white-space: pre-wrap;
|
|
color: #606266;
|
|
}
|
|
</style>
|