1234567891011121314151617181920212223242526272829303132333435363738394041 |
- export const randomId = (e = 6): string => {
- const t = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678'
- const a = t.length
- let n = ''
- for (let i = 0; i < e; i++) {
- n += t.charAt(Math.floor(Math.random() * a))
- }
- return n
- }
- export function omit(obj, ...props) {
- const result = { ...obj }
- props.forEach(prop => {
- delete result[prop]
- })
- return result
- }
- /**
- * 获取制定dom在相对于目标中的位置
- * @param {*} origin 或获取的DOM
- * @param {*} target 目标DOM
- * @param {*} isIncludeSelf 是否要包含自身宽高
- * @returns 位置信息 {x, y}
- */
- export const getPostionByTarget = (origin, target, isIncludeSelf = false) => {
- const pos = { x: 0, y: 0, width: origin.offsetWidth, height: origin.offsetHeight }
- let temporary = origin
- while (temporary && temporary !== target && temporary !== document.documentElement && target.contains(temporary)) {
- pos.x += temporary.offsetLeft + temporary.clientLeft
- pos.y += temporary.offsetTop + temporary.clientTop
- temporary = temporary.offsetParent
- }
- if (isIncludeSelf) {
- pos.x += pos.width
- pos.y += pos.height
- }
- return pos
- }
|