magiccube-vue3
Version:
vue3-js版组件库
75 lines (62 loc) • 1.95 kB
JavaScript
/* 多级表头时 颜色区分 */
export const getGroupClassName = (number) => number%2 === 0? 'mc-table__th--even' : 'mc-table__th--odd'
export const getAllColumnWidthSum = (arr = []) => {
const _a = arr.map((n) => n.cellWidth) || []
return sum(_a)
}
export const sum = (arr = []) => arr?.length ? arr.reduce((a, b) => a + b) : 0
export const DEFAULT_SCOPE_DATA = {
rowIndex: null,
columnIndex: null,
data: {}
}
export const formatterProps = (props) => {
for(const key in props){
const humpKey = translateKeyNameFormat(key, 'hump')
props[humpKey] = props[key]
}
return props
}
// 字符串下划线转驼峰
const formatToHump = (value) => value.replace(/\_|-(\w)/g, (_, letter) => letter.toUpperCase())
// 字符串驼峰转下划线
const formatToLine = (value) => value.replace(/([A-Z])/g, '_$1').toLowerCase()
export const formatHumpLineTransfer = (
data,
type = 'hump'
) => type === 'hump' ? formatToHump(data) : formatToLine(data)
export const translateKeyNameFormat = (
keyName,
type,
) => formatHumpLineTransfer(keyName, type)
export const isFixedColumn = (props, site) => {
if(!site) return false
const propKeys = Object.keys(props)
if(site === 'left'){
return propKeys.includes('fixed-left' || 'fixedLeft')
} else if(site === 'right') {
return propKeys.includes('fixed-right' || 'fixedRight')
} else {
return false
}
}
export const getColFixedLeftPosition = (idx, list = []) => {
let i = 0
let res = 0
while(i <= idx){
res += list[i]
i++
}
return res + 'px'
}
export const getColFixedRightPosition = (idx, list = []) => {
const len = list.length
let i = idx + 2
let res = 0
while(i < len){
res += list[i]
i++
}
return res + 'px'
}
export const formatSizeValueToNumber = (value) => value? Number(value.toString().replace(/[a-zA-Z]/g, '')) : 0