mirror of
https://github.com/element-plus/element-plus.git
synced 2026-03-13 07:51:17 +08:00
* chore(components): cascader-panel Update types.ts export types * chore(components): cascader-panel/node.ts export types from types.ts * chore(components): cascader-panel/types export * chore: cascader-panel import types form types.ts * chore: cascader-panel test types --------- Co-authored-by: 一只前端汪 <985313519@qq.com>
42 lines
919 B
TypeScript
42 lines
919 B
TypeScript
import { isLeaf } from '@element-plus/utils'
|
|
|
|
import type { CascaderNode } from './types'
|
|
|
|
export const getMenuIndex = (el: HTMLElement) => {
|
|
if (!el) return 0
|
|
const pieces = el.id.split('-')
|
|
return Number(pieces[pieces.length - 2])
|
|
}
|
|
|
|
export const checkNode = (el: HTMLElement) => {
|
|
if (!el) return
|
|
|
|
const input = el.querySelector('input')
|
|
if (input) {
|
|
input.click()
|
|
} else if (isLeaf(el)) {
|
|
el.click()
|
|
}
|
|
}
|
|
|
|
export const sortByOriginalOrder = (
|
|
oldNodes: CascaderNode[],
|
|
newNodes: CascaderNode[]
|
|
) => {
|
|
const newNodesCopy = newNodes.slice(0)
|
|
const newIds = newNodesCopy.map((node) => node.uid)
|
|
const res = oldNodes.reduce((acc, item) => {
|
|
const index = newIds.indexOf(item.uid)
|
|
if (index > -1) {
|
|
acc.push(item)
|
|
newNodesCopy.splice(index, 1)
|
|
newIds.splice(index, 1)
|
|
}
|
|
return acc
|
|
}, [] as CascaderNode[])
|
|
|
|
res.push(...newNodesCopy)
|
|
|
|
return res
|
|
}
|