UNPKG

tav-ui

Version:
75 lines (70 loc) 2.23 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); require('../../../../utils/index2.js'); var formatNumber = require('../../../../utils/formatNumber2.js'); var dateUtil = require('../../../../utils/dateUtil2.js'); var geo$1 = require('../../../../utils/geo2.js'); var is = require('../../../../utils/is2.js'); function number({ cellValue }, format = "auto") { return formatNumber.formatNumber(cellValue, format); } function date({ cellValue }, format = "YYYY-MM-DD") { return dateUtil.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 && geo$1.ProvinceCityRecord[province] && res.push(geo$1.ProvinceCityRecord[province]); if (city && !hideCity) { geo$1.ProvinceCityRecord[city] && res.push(geo$1.ProvinceCityRecord[city]); } if (district) { const districtLabel = geo$1.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 (is.isFunction(formatter)) { return formatter({ cellValue: row[column.field], ...params }); } let formatFn = void 0; let formatterArgs = []; if (is.isString(formatter)) { formatFn = formats[formatter]; } else if (is.isArray(formatter)) { const [name, ...args] = formatter; formatFn = formats[name]; formatterArgs = args; } return formatFn?.({ cellValue: row[column.field], ...params }, ...formatterArgs); } } exports.formats = formats; exports.useFormats = useFormats; //# sourceMappingURL=formats2.js.map