Skip to content

Commit

Permalink
Merge pull request #100 from jujijigo/main
Browse files Browse the repository at this point in the history
curd组件合计行增加在指定列显示静态文字支持
  • Loading branch information
zds-s authored Jan 28, 2024
2 parents b6def85 + 896aff1 commit 2b54d00
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions src/components/ma-crud/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -705,23 +705,29 @@ const __summary = ({ data }) => {
let summarySuffixText = {}
let length = data.length || 0
summary.map( item => {
summaryData[item.dataIndex] = 0
summaryPrefixText[item.dataIndex] = item?.prefixText ?? ''
summarySuffixText[item.dataIndex] = item?.suffixText ?? ''
data.map(record => {
if (record[item.dataIndex]) {
if (item.action && item.action === 'sum') {
summaryData[item.dataIndex] += parseFloat(record[item.dataIndex])
}
if (item.action && item.action === 'avg') {
summaryData[item.dataIndex] += parseFloat(record[item.dataIndex]) / length
if (item.action && item.action === 'text') {
summaryData[item.dataIndex] = item.content
} else {
summaryData[item.dataIndex] = 0
summaryPrefixText[item.dataIndex] = item?.prefixText ?? ''
summarySuffixText[item.dataIndex] = item?.suffixText ?? ''
data.map(record => {
if (record[item.dataIndex]) {
if (item.action && item.action === 'sum') {
summaryData[item.dataIndex] += parseFloat(record[item.dataIndex])
}
if (item.action && item.action === 'avg') {
summaryData[item.dataIndex] += parseFloat(record[item.dataIndex]) / length
}
}
}
})
})
}
})

for (let i in summaryData) {
summaryData[i] = summaryPrefixText[i] + tool.groupSeparator(summaryData[i].toFixed(2)) + summarySuffixText[i]
if (/^\d+(\.\d+)?$/.test(summaryData[i])) {
summaryData[i] = summaryPrefixText[i] + tool.groupSeparator(summaryData[i].toFixed(2)) + summarySuffixText[i]
}
}

return [ summaryData ]
Expand Down

0 comments on commit 2b54d00

Please sign in to comment.