UNPKG

tav-ui

Version:
70 lines (67 loc) 2.11 kB
import '../../../../utils/index2.mjs'; import { formatNumber } from '../../../../utils/formatNumber2.mjs'; import { formatToDate } from '../../../../utils/dateUtil2.mjs'; import { ProvinceCityRecord } from '../../../../utils/geo2.mjs'; import { isFunction, isString, isArray } from '../../../../utils/is2.mjs'; function number({ cellValue }, format = "auto") { return formatNumber(cellValue, format); } function date({ cellValue }, format = "YYYY-MM-DD") { return formatToDate(cellValue, format); } function geo({ cellValue, row }, { hideProvince, hideCity, hideDistrict, hideTwoLevelDistrict } = { hideProvince: false, hideCity: false, hideDistrict: true, hideTwoLevelDistrict: false }, joinChar = "-") { const res = []; if (!row) return ""; const { province = cellValue, city, district } = row; const IS_TWO_LEVEL = province == city; if (!province) { return ""; } !hideProvince && !IS_TWO_LEVEL && ProvinceCityRecord[province] && res.push(ProvinceCityRecord[province]); if (city && !hideCity) { ProvinceCityRecord[city] && res.push(ProvinceCityRecord[city]); } if (district) { const districtLabel = ProvinceCityRecord[district]; if (districtLabel) { if (IS_TWO_LEVEL) { hideTwoLevelDistrict || res.push(districtLabel); } else { hideDistrict || res.push(districtLabel); } } } return res.join(joinChar); } const formats = { number, date, geo }; function useFormats(params) { const { row, column } = params; const formatter = column.params?.formatter; if (formatter) { if (isFunction(formatter)) { return formatter({ cellValue: row[column.field], ...params }); } let formatFn = void 0; let formatterArgs = []; if (isString(formatter)) { formatFn = formats[formatter]; } else if (isArray(formatter)) { const [name, ...args] = formatter; formatFn = formats[name]; formatterArgs = args; } return formatFn?.({ cellValue: row[column.field], ...params }, ...formatterArgs); } } export { formats, useFormats }; //# sourceMappingURL=formats2.mjs.map