From 611b1e3c972cec56f4e5aa375c85fd9101dcb5e2 Mon Sep 17 00:00:00 2001 From: q4speed Date: Thu, 24 Dec 2020 11:45:15 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E6=8E=A5=E5=8F=A3=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E5=8C=96):=20=E4=BF=AE=E6=94=B9=E9=A1=B5=E9=9D=A2=E5=B8=83?= =?UTF-8?q?=E5=B1=80=E5=92=8CFAB=E6=8C=89=E9=92=AE=E4=BD=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../automation/scenario/EditApiScenario.vue | 1574 +++++++++-------- frontend/src/common/js/outside-click.js | 31 + 2 files changed, 837 insertions(+), 768 deletions(-) create mode 100644 frontend/src/common/js/outside-click.js diff --git a/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue b/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue index c9bb269508..18d04c2c67 100644 --- a/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue +++ b/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue @@ -1,41 +1,42 @@ diff --git a/frontend/src/common/js/outside-click.js b/frontend/src/common/js/outside-click.js new file mode 100644 index 0000000000..7431be960d --- /dev/null +++ b/frontend/src/common/js/outside-click.js @@ -0,0 +1,31 @@ +const OutsideClick = { + // 初始化指令 + bind(el, binding, vnode) { + function documentHandler(e) { + // 这里判断点击的元素是否是本身,是本身,则返回 + if (el.contains(e.target)) { + return false; + } + // 判断指令中是否绑定了函数 + if (binding.expression) { + // 如果绑定了函数 则调用那个函数,此处binding.value就是handleClose方法 + binding.value(e); + } + } + + // 给当前元素绑定个私有变量,方便在unbind中可以解除事件监听 + el.__vueClickOutside__ = documentHandler; + document.addEventListener('click', documentHandler); + }, + update() { + }, + unbind(el, binding) { + // 解除事件监听 + document.removeEventListener('click', el.__vueClickOutside__); + delete el.__vueClickOutside__; + }, +}; + +export default OutsideClick; + +