gin-vue-admin/web/src/directive/clickOutSide.js

44 lines
1.4 KiB
JavaScript
Raw Normal View History

public:发布2.8.6版本 (#2126) * feat(mcp): 新增gva_review工具并优化字典和代码生成逻辑 * fix: 调整mcp整体逻辑 * chore: 更新.gitignore,添加对本地配置文件的忽略 * feat(logo): 新增Logo组件并在多个页面中替换原有logo实现 * fix: 修复菜单 Logo 部分删除文本后显示异常的问题 * fix:添加字典列表搜索,支持中英文搜索.添加字典详情搜索 * style: 优化部分视觉样式 * feat: 增强错误预览组件的暗黑模式支持 * feat: 优化请求错误消息获取逻辑,增加状态文本优先级 * feat: 添加前端登录验证码静态验证逻辑 * feat: 添加开发环境启动脚本 * feat: 更新 SvgIcon 组件,支持本地图标和 Iconify 图标、移除未使用的 unocss 依赖 * fix:字典支持 tree 结构 * feat: 优化动态路由注册方式 * feat: 添加配置控制标签页keep-alive功能 * feat: 添加全局错误处理机制,捕获 Vue 和 JS 错误 * refactor: 移除API和菜单创建结果中的权限分配提醒,优化输出信息 * feat: 更新 reset.scss,优化全局样式重置,增强兼容性和可读性 * refactor(字典详情): 优化字典详情查询逻辑,移除预加载改为按需加载 * refactor(路由管理): 优化路由添加逻辑,增强路径处理和顶级路由注册 * refactor(系统配置): 将auto-migrate修改为disable-auto-migrate,保证用户升级的兼容性 * feat(utils): 优化字典数据递归查找功能并替换select为tree-select * fix(deps): 修复在字段类型为file生成搜索条件无法运行的bug * fix: 修复header的tools中icon不展示的问题 --------- Co-authored-by: piexlMax(奇淼 <qimiaojiangjizhao@gmail.com> Co-authored-by: Azir-11 <2075125282@qq.com> Co-authored-by: bypanghu <bypanghu@163.com> Co-authored-by: feitianbubu <feitianbubu@qq.com> Co-authored-by: 青菜白玉汤 <79054161+Azir-11@users.noreply.github.com> Co-authored-by: krank <emosick@qq.com>
2025-10-19 05:27:48 +00:00
export default {
install: (app) => {
app.directive('click-outside', {
mounted(el, binding) {
const handler = (e) => {
// 如果绑定的元素包含事件目标,或元素已经被移除,则不触发
if (!el || el.contains(e.target) || e.target === el) return
// 支持函数或对象 { handler: fn, exclude: [el1, el2], capture: true }
const value = binding.value
if (value && typeof value === 'object') {
if (
value.exclude &&
value.exclude.some(
(ex) => ex && ex.contains && ex.contains(e.target)
)
)
return
if (typeof value.handler === 'function') value.handler(e)
} else if (typeof value === 'function') {
value(e)
}
}
// 存到 el 上,便于解绑
el.__clickOutsideHandler__ = handler
// 延迟注册,避免 mounted 时触发(比如当点击就是触发绑定动作时)
setTimeout(() => {
document.addEventListener('mousedown', handler)
document.addEventListener('touchstart', handler)
}, 0)
},
unmounted(el) {
const h = el.__clickOutsideHandler__
if (h) {
document.removeEventListener('mousedown', h)
document.removeEventListener('touchstart', h)
delete el.__clickOutsideHandler__
}
}
})
}
}