12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- 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: any, ...props: any[]) {
- 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: HTMLElement,
- target: Node,
- isIncludeSelf = false
- ) => {
- const pos = {
- x: 0,
- y: 0,
- width: origin.offsetWidth,
- height: origin.offsetHeight,
- }
- let temporary: HTMLElement = 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 as HTMLElement
- }
- if (isIncludeSelf) {
- pos.x += pos.width
- pos.y += pos.height
- }
- return pos
- }
|