resolver-egretimp-plus 0.0.164 → 0.0.166
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script setup>
|
|
2
|
-
import { commonPropsType, formatDate, formatAmount, getConfigOptions, hasOwn } from '../../utils/index.js'
|
|
2
|
+
import { commonPropsType, formatDate, formatAmount, getConfigOptions, hasOwn, isPlainObject } from '../../utils/index.js'
|
|
3
3
|
import { computed, inject, onMounted, reactive, ref, useAttrs, watch } from 'vue'
|
|
4
4
|
|
|
5
5
|
const attrs = useAttrs()
|
|
@@ -151,6 +151,80 @@ const tableKey = computed(() => {
|
|
|
151
151
|
return `${tableProps.value.card}${tableProps.value.display}${!tableProps.value.card ? page.pageNum : 0}`
|
|
152
152
|
})
|
|
153
153
|
|
|
154
|
+
// 统计行定义 ====start======
|
|
155
|
+
const totalMetaCodes = computed(() => {
|
|
156
|
+
return props.config?.totalMetaCodes || []
|
|
157
|
+
})
|
|
158
|
+
const normalTotalCodes = computed(() => {
|
|
159
|
+
return totalMetaCodes.value.map(code => {
|
|
160
|
+
if (typeof code === 'string') {
|
|
161
|
+
return {
|
|
162
|
+
code,
|
|
163
|
+
totalFn: defaultTotalFn,
|
|
164
|
+
totalFormatter: defaultTotalFormatter
|
|
165
|
+
}
|
|
166
|
+
} else {
|
|
167
|
+
if (isPlainObject(code) && hasOwn(code, 'code')) {
|
|
168
|
+
code.totalFn = typeof code.totalFn === 'function' ? code.totalFn : defaultTotalFn
|
|
169
|
+
code.totalFormatter = typeof code.totalFormatter === 'function' ? code.totalFormatter : defaultTotalFormatter
|
|
170
|
+
return code
|
|
171
|
+
}
|
|
172
|
+
return null
|
|
173
|
+
}
|
|
174
|
+
}).filter(codeInfo => !!codeInfo)
|
|
175
|
+
})
|
|
176
|
+
const totalCodeFormatters = (row) => {
|
|
177
|
+
if (!row?.length) {
|
|
178
|
+
return []
|
|
179
|
+
}
|
|
180
|
+
const totalObj = {
|
|
181
|
+
[pmPageMetaList.value?.[0]?.metaCode]: lang.value.indexOf('zh') > -1 ? '总计' : 'Total',
|
|
182
|
+
...row[0]
|
|
183
|
+
}
|
|
184
|
+
normalTotalCodes.value.map((codeInfo) => {
|
|
185
|
+
const { code, totalFormatter } = codeInfo
|
|
186
|
+
if (totalFormatter && typeof totalFormatter === 'function') {
|
|
187
|
+
totalObj[code] = totalFormatter(totalObj[code], totalObj, code)
|
|
188
|
+
}
|
|
189
|
+
})
|
|
190
|
+
return [totalObj]
|
|
191
|
+
}
|
|
192
|
+
const defaultTotalFormatter = (val, total, code) => {
|
|
193
|
+
let codeConfig = pmPageMetaList.value?.find(item => item.metaCode == code)
|
|
194
|
+
if (codeConfig) {
|
|
195
|
+
normalResult(total, codeConfig)
|
|
196
|
+
return total[code]
|
|
197
|
+
}
|
|
198
|
+
return val
|
|
199
|
+
}
|
|
200
|
+
const defaultTotalFn = (total, val, row) => {
|
|
201
|
+
if (val === undefined || val === null) {
|
|
202
|
+
val = !isNaN(Number(val)) ? 0 : ''
|
|
203
|
+
} else {
|
|
204
|
+
val = val.toString().replace(/[^\d\.\-]/g, '')
|
|
205
|
+
}
|
|
206
|
+
const numFlag = !isNaN(Number(val))
|
|
207
|
+
if (total === null || total === undefined) {
|
|
208
|
+
total = numFlag ? 0 : ''
|
|
209
|
+
}
|
|
210
|
+
return total + (numFlag ? Number(val) : val)
|
|
211
|
+
}
|
|
212
|
+
const totalRow = computed(() => {
|
|
213
|
+
if (!normalTableData.value?.length || !totalMetaCodes.value.length || !normalTotalCodes.value.length) {
|
|
214
|
+
return []
|
|
215
|
+
}
|
|
216
|
+
// 进行统计的计算
|
|
217
|
+
const row = (normalTableData.value || []).reduce((total, row) => {
|
|
218
|
+
normalTotalCodes.value.forEach(codeInfo => {
|
|
219
|
+
const { code, totalFn } = codeInfo
|
|
220
|
+
total[code] = totalFn(total[code], row[code], row)
|
|
221
|
+
})
|
|
222
|
+
return total
|
|
223
|
+
}, { totalFlag: true })
|
|
224
|
+
return [row]
|
|
225
|
+
})
|
|
226
|
+
// 统计行定义 ====end======
|
|
227
|
+
|
|
154
228
|
onMounted(() => {
|
|
155
229
|
watch(() => {
|
|
156
230
|
return {
|
|
@@ -166,7 +240,7 @@ onMounted(() => {
|
|
|
166
240
|
setTimeout(() => {
|
|
167
241
|
try {
|
|
168
242
|
// 这边有的时候会报错
|
|
169
|
-
tableRef.value?.setTableData(val)
|
|
243
|
+
tableRef.value?.setTableData([...val,...totalCodeFormatters(totalRow.value)])
|
|
170
244
|
} catch (error) {
|
|
171
245
|
}
|
|
172
246
|
}, 100);
|
|
@@ -197,22 +271,25 @@ function normalVal(val, options) {
|
|
|
197
271
|
return val
|
|
198
272
|
}
|
|
199
273
|
|
|
274
|
+
function normalResult(ret, config) {
|
|
275
|
+
ret[config.metaCode] = normalVal(ret[config.metaCode], getOptions(config))
|
|
276
|
+
if (config?.dateFormat) {
|
|
277
|
+
ret[config.metaCode] = formatDate(ret[config.metaCode], config.dateFormat)
|
|
278
|
+
}
|
|
279
|
+
if (config?.amountFormat) {
|
|
280
|
+
ret[config.metaCode] = formatAmount(ret[config.metaCode], config.amountFormat)
|
|
281
|
+
}
|
|
282
|
+
if (typeof config?.formatter === "function") {
|
|
283
|
+
ret[config.metaCode] = config.formatter(ret[config.metaCode], config, props)
|
|
284
|
+
}
|
|
285
|
+
}
|
|
200
286
|
|
|
201
287
|
function normalTableRowValue(row) {
|
|
202
288
|
const ret = {
|
|
203
289
|
...row
|
|
204
290
|
}
|
|
205
291
|
pmPageMetaList.value.forEach(config => {
|
|
206
|
-
|
|
207
|
-
if (config?.dateFormat) {
|
|
208
|
-
ret[config.metaCode] = formatDate(ret[config.metaCode], config.dateFormat)
|
|
209
|
-
}
|
|
210
|
-
if (config?.amountFormat) {
|
|
211
|
-
ret[config.metaCode] = formatAmount(ret[config.metaCode], config.amountFormat)
|
|
212
|
-
}
|
|
213
|
-
if (typeof config?.formatter === "function") {
|
|
214
|
-
ret[config.metaCode] = config.formatter(ret[config.metaCode], config, props)
|
|
215
|
-
}
|
|
292
|
+
normalResult(ret, config)
|
|
216
293
|
})
|
|
217
294
|
return ret
|
|
218
295
|
}
|
|
@@ -75,9 +75,15 @@ const allInitEvents = {
|
|
|
75
75
|
const targetConfig = dynamicMapComp?.[matchs[1]]
|
|
76
76
|
val = targetConfig?.bindValue || ''
|
|
77
77
|
} else {
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
|
|
78
|
+
const _assginKey = /^_assgin:(.+)$/
|
|
79
|
+
const matchs = val.match(_assginKey)
|
|
80
|
+
if (matchs?.[1]) {
|
|
81
|
+
val = matchs?.[1]
|
|
82
|
+
} else {
|
|
83
|
+
const curVal = getConfigValue.call(this, targetObj, true)
|
|
84
|
+
if (curVal || curVal == '0') {
|
|
85
|
+
val = curVal
|
|
86
|
+
}
|
|
81
87
|
}
|
|
82
88
|
}
|
|
83
89
|
}
|