二维表头
This commit is contained in:
@@ -135,6 +135,7 @@ const amountObj=ref<any>({})
|
||||
const crudRef = ref()
|
||||
const dimensionFields=ref<any>({})
|
||||
const exportLoading = ref(false)
|
||||
const fieldList = ref<any[]>([]) // 添加fieldList引用
|
||||
const permissions =
|
||||
wsCache.get(CACHE_KEY.USER).lideeYunjipermissions?.[route.meta.menuDataId as string] || false
|
||||
const selectIds = computed(() => {
|
||||
@@ -167,7 +168,11 @@ const summaryMethod1=({columns,data})=>{
|
||||
const initTable = async () => {
|
||||
isInit.value = false
|
||||
loading.value = true
|
||||
const { fieldList, reportVo } = await ReportApi.getWebConfig(props.reportCode)
|
||||
const { fieldList: apiFieldList, reportVo } = await ReportApi.getWebConfig(props.reportCode)
|
||||
|
||||
// 存储字段列表到响应式引用
|
||||
fieldList.value = apiFieldList
|
||||
|
||||
const isHeight = reportVo.tableConfig?.includes('height')
|
||||
const isPage = reportVo.dataConfig?.includes('page')
|
||||
const isPermi = reportVo.dataConfig?.includes('authTrue')
|
||||
@@ -188,12 +193,37 @@ const initTable = async () => {
|
||||
column: {}
|
||||
}
|
||||
//国际化处理
|
||||
const fieldLengObj = assembleLengObj(fieldList, 'labelI18n', 'fieldCode', 'fieldName')
|
||||
const fieldLengObj = assembleLengObj(apiFieldList, 'labelI18n', 'fieldCode', 'fieldName')
|
||||
for (const key in fieldLengObj) {
|
||||
mergeLocaleMessage(key, { [props.reportCode]: fieldLengObj[key] })
|
||||
}
|
||||
//字段处理
|
||||
fieldList.forEach((item,index) => {
|
||||
|
||||
// 根据parentFieldCode判断表头结构
|
||||
const hasSubFields = Array.isArray(apiFieldList) && apiFieldList.some(field => field.parentFieldCode && field.parentFieldCode !== '')
|
||||
|
||||
// 构建父子关系映射
|
||||
const parentChildMap = new Map()
|
||||
const childParentMap = new Map()
|
||||
|
||||
// 建立映射关系
|
||||
apiFieldList.forEach(field => {
|
||||
if (field.parentFieldCode && field.parentFieldCode !== '') {
|
||||
// 这是子字段
|
||||
childParentMap.set(field.fieldCode, field.parentFieldCode)
|
||||
if (!parentChildMap.has(field.parentFieldCode)) {
|
||||
parentChildMap.set(field.parentFieldCode, [])
|
||||
}
|
||||
parentChildMap.get(field.parentFieldCode).push(field.fieldCode)
|
||||
}
|
||||
})
|
||||
|
||||
//字段处理 - 构建正确的表头结构
|
||||
apiFieldList.forEach((item, index) => {
|
||||
// 跳过子字段,子字段会在父字段中处理
|
||||
if (item.parentFieldCode && item.parentFieldCode !== '') {
|
||||
return
|
||||
}
|
||||
|
||||
const config: any = {
|
||||
prop: item.fieldCode,
|
||||
label: t(`${props.reportCode}.${item.fieldCode}`),
|
||||
@@ -203,6 +233,24 @@ const initTable = async () => {
|
||||
sortable: item.isShowSort == 'Y' ? 'custom' : false,
|
||||
search: item.queryIsWeb == 'Y',
|
||||
}
|
||||
|
||||
// 如果该字段有子字段,添加子列配置
|
||||
if (parentChildMap.has(item.fieldCode)) {
|
||||
const childFields = parentChildMap.get(item.fieldCode)
|
||||
config.children = childFields.map(childFieldCode => {
|
||||
const childField = apiFieldList.find(f => f.fieldCode === childFieldCode)
|
||||
return {
|
||||
prop: childField.fieldCode,
|
||||
label: t(`${props.reportCode}.${childField.fieldCode}`),
|
||||
type: 'input',
|
||||
overHidden: true,
|
||||
isExport: childField.isExport == 'Y',
|
||||
sortable: childField.isShowSort == 'Y' ? 'custom' : false,
|
||||
search: childField.queryIsWeb == 'Y'
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
if(!!item.isAmount){
|
||||
index==0?amountFieds.value.fistField=config.prop:''
|
||||
amountFieds.value[item.isAmount]=config
|
||||
@@ -320,7 +368,31 @@ const getTableData = async (isLoading = true) => {
|
||||
try {
|
||||
const data = await ReportApi.getTableList(props.reportCode, searchObj)
|
||||
if (tablePage.value) tablePage.value['total'] = data.total
|
||||
tableData.value = data.records
|
||||
|
||||
// 处理包含子字段的数据
|
||||
let processedData = data.records
|
||||
// 根据字段配置判断是否需要处理子字段
|
||||
const hasSubFields = Array.isArray(fieldList.value) && fieldList.value.length > 0 &&
|
||||
fieldList.value.some(field => field.parentFieldCode && field.parentFieldCode !== '')
|
||||
|
||||
if (hasSubFields) {
|
||||
processedData = data.records.map(record => {
|
||||
const flatRecord = { ...record }
|
||||
// 处理子字段数据
|
||||
fieldList.value.forEach(field => {
|
||||
if (field.parentFieldCode && field.parentFieldCode !== '') {
|
||||
// 这是子字段,从父字段中提取数据
|
||||
const parentData = record[field.parentFieldCode]
|
||||
if (parentData && typeof parentData === 'object') {
|
||||
flatRecord[field.fieldCode] = parentData[field.fieldCode]
|
||||
}
|
||||
}
|
||||
})
|
||||
return flatRecord
|
||||
})
|
||||
}
|
||||
|
||||
tableData.value = processedData
|
||||
// amountFieds.value={
|
||||
// 'thissaqty_s':{
|
||||
// prop:'thissaqty',
|
||||
|
||||
Reference in New Issue
Block a user