|
@@ -1,56 +0,0 @@
|
|
|
-import { isNullES } from 'js-fast-way'
|
|
|
-import { delMessage } from 'hc-vue3-ui'
|
|
|
-
|
|
|
-//删除指令
|
|
|
-const delComDom = []
|
|
|
-const delComClickFun = []
|
|
|
-const delComClickItem = []
|
|
|
-const delComOnClick = (el) => {
|
|
|
- let index = getDomindex(el.target)
|
|
|
- if (index === -1) return
|
|
|
- if (delComClickFun.length <= 0) return
|
|
|
- if (isNullES(delComClickFun[index])) return
|
|
|
- const fun = delComClickFun[index]
|
|
|
- if (typeof fun !== 'function') return
|
|
|
- delMessage(() => {
|
|
|
- if (delComClickItem.length <= 0 || isNullES(delComClickItem[index])) {
|
|
|
- fun(el)
|
|
|
- } else {
|
|
|
- fun(delComClickItem[index], el)
|
|
|
- }
|
|
|
- })
|
|
|
-}
|
|
|
-
|
|
|
-//获取当前点击的dom索引
|
|
|
-const getDomindex = (el, times = 0) => {
|
|
|
- let index = delComDom.indexOf(el)
|
|
|
- if (index !== -1) {
|
|
|
- return index
|
|
|
- }
|
|
|
- if (times > 10) return -1
|
|
|
- //如果没有找到,就找父级
|
|
|
- const parentNode = el?.target?.parentNode ?? el?.parentNode
|
|
|
- if (isNullES(parentNode)) return -1
|
|
|
- return getDomindex(parentNode, times + 1)
|
|
|
-}
|
|
|
-
|
|
|
-//注册全局删除指令
|
|
|
-export const vDelCom = {
|
|
|
- mounted(el, { arg, value }) {
|
|
|
- //判断是否为函数
|
|
|
- if (typeof arg !== 'function') return
|
|
|
- delComDom.push(el)
|
|
|
- el.addEventListener('click', delComOnClick)
|
|
|
- delComClickFun.push(arg ?? null)
|
|
|
- delComClickItem.push(value ?? '')
|
|
|
- },
|
|
|
- unmounted(el) {
|
|
|
- const index = delComDom.indexOf(el)
|
|
|
- if (index > -1) {
|
|
|
- delComDom.splice(index, 1)
|
|
|
- delComClickFun.splice(index, 1)
|
|
|
- delComClickItem.splice(index, 1)
|
|
|
- }
|
|
|
- el.removeEventListener('click', delComOnClick)
|
|
|
- },
|
|
|
-}
|