UNPKG

@tplc/business

Version:

98 lines (91 loc) 2.53 kB
export const transformValueUnit = (value?: number | string, uni = 'rpx') => { return typeof value === 'number' ? value + uni : typeof value === 'string' ? value : '0rpx' } /** 获取json字符串第一个url */ export const getJsonStrFirstUrl = (jsonStr = '[]') => { const json = JSON.parse(jsonStr) return json[0] } /** 获取json字符串列表 */ export const getJsonStrList = (jsonStr = '[]') => { return JSON.parse(jsonStr) } /** 删除其他外部字段 */ export const cleanOutSizeKeys = ( obj: Record<string, any>, /** 保留字段 */ keys: string[] = [], ) => { return Object.keys(obj).reduce((acc, key) => { if ([...keys, ...['endDate', 'startDate', 'keywords']].includes(key)) { acc[key] = obj[key] } return acc }, {}) } export const getSliderTitle = ( translate: (v: string) => string, value?: number[], max = 0, min = 0, ) => { if (value) { const [start, end] = value if (start === min && end === max) { return translate('不限') } else if (end === max || end === undefined) { return ${start}` + translate('以上') } else if (start === min) { return ${end}` + translate('以下') } else { return ${start}-${end}` } } else { return '' } } export const getFlexStyle = (align?: string) => { const style: Record<string, string> = {} if (align) { style.display = 'flex' switch (align) { case 'top-left': style.justifyContent = 'flex-start' style.alignItems = 'flex-start' break case 'top-center': style.justifyContent = 'center' style.alignItems = 'flex-start' break case 'top-right': style.justifyContent = 'flex-end' style.alignItems = 'flex-start' break case 'center-left': style.justifyContent = 'flex-start' style.alignItems = 'center' break case 'center-center': style.justifyContent = 'center' style.alignItems = 'center' break case 'center-right': style.justifyContent = 'flex-end' style.alignItems = 'center' break case 'bottom-left': style.justifyContent = 'flex-start' style.alignItems = 'flex-end' break case 'bottom-center': style.justifyContent = 'center' style.alignItems = 'flex-end' break case 'bottom-right': style.justifyContent = 'flex-end' style.alignItems = 'flex-end' break } } return style }