adtec-core-package 2.7.2 → 2.7.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "adtec-core-package",
3
- "version": "2.7.2",
3
+ "version": "2.7.3",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "scripts": {
@@ -95,43 +95,62 @@ const blurEvent = (event: FocusEvent) => {
95
95
 
96
96
  const keyUpEvent = (event: KeyboardEvent) => {
97
97
  if (event.key === 'Enter') {
98
- const applicationModule = moduleName.value || sessionStorage.getItem('applicationModule')
99
- //首先判断当前页面有没有抽屉
100
- const docTemp = event.currentTarget as any
101
- const doc =
102
- applicationModule === 'system'
103
- ? (docTemp as Document)
104
- : (docTemp && docTemp[applicationModule ?? 'default'] && docTemp[applicationModule ?? 'default'].document) || undefined
105
- if (!doc) return
106
- if (!doc) return
107
- const loginButton = doc.body.querySelector('.login_button')
108
- if (loginButton) {
109
- event.stopPropagation()
110
- ;(loginButton as HTMLElement).click()
111
- return
98
+ const applicationModule = moduleName.value || sessionStorage.getItem('applicationModule');
99
+ // 首先判断当前页面有没有抽屉
100
+ const docTemp = event.currentTarget as any;
101
+ const doc = applicationModule === 'system'
102
+ ? (docTemp as Document)
103
+ : (docTemp && docTemp[applicationModule ?? 'default'] && docTemp[applicationModule ?? 'default'].document) || undefined;
104
+
105
+ if (!doc) return;
106
+
107
+ // 工具函数:判断元素是否可见(未隐藏、display不为none、visibility不为hidden)
108
+ const isElementVisible = (el: HTMLElement | null): boolean => {
109
+ if (!el) return false;
110
+ // 1. 元素本身隐藏(v-if=false 会导致 el 为 null,已在入参过滤)
111
+ // 2. display: none
112
+ if (el.style.display === 'none' || getComputedStyle(el).display === 'none') return false;
113
+ // 3. visibility: hidden
114
+ if (el.style.visibility === 'hidden' || getComputedStyle(el).visibility === 'hidden') return false;
115
+ // 4. 父元素隐藏导致该元素不可见
116
+ let parent = el.parentElement;
117
+ while (parent) {
118
+ if (parent.style.display === 'none' || getComputedStyle(parent).display === 'none') return false;
119
+ parent = parent.parentElement;
120
+ }
121
+ return true;
122
+ };
123
+
124
+ // 1. 优先查找登录按钮(可见时才点击)
125
+ const loginButton = doc.body.querySelector('.login_button') as HTMLElement;
126
+ if (loginButton && isElementVisible(loginButton)) {
127
+ event.stopPropagation();
128
+ event.preventDefault(); // 新增:阻止表单默认提交(避免页面刷新)
129
+ loginButton.click();
130
+ return;
112
131
  }
113
- if (
114
- doc.body.className === 'el-popup-parent--hidden' ||
115
- doc.body.querySelector('.el-drawer .open')
116
- ) {
117
- const drawer = doc.body.querySelector('.el-drawer__body')
132
+
133
+ // 2. 判断是否有打开的抽屉
134
+ const hasDrawer = doc.body.className === 'el-popup-parent--hidden' || doc.body.querySelector('.el-drawer .open');
135
+ let target: HTMLElement | null = null;
136
+ const routeCode = sessionStorage.getItem('activationRouteCode') as string;
137
+
138
+ if (hasDrawer) {
139
+ const drawer = doc.body.querySelector('.el-drawer__body');
118
140
  if (drawer) {
119
- const target = drawer.querySelector(
120
- '.' + (sessionStorage.getItem('activationRouteCode') as string) + '_search',
121
- )
122
- if (target) {
123
- event.stopPropagation()
124
- ;(target as HTMLElement).click()
125
- }
141
+ // 抽屉内的搜索按钮(需可见)
142
+ target = drawer.querySelector(`.${routeCode}_search`) as HTMLElement;
126
143
  }
127
144
  } else {
128
- const target = doc.body.querySelector(
129
- '.' + (sessionStorage.getItem('activationRouteCode') as string) + '_search',
130
- )
131
- if (target) {
132
- event.stopPropagation()
133
- ;(target as HTMLElement).click()
134
- }
145
+ // 页面内的搜索按钮(需可见)
146
+ target = doc.body.querySelector(`.${routeCode}_search`) as HTMLElement;
147
+ }
148
+
149
+ // 3. 目标元素存在且可见时,才执行点击
150
+ if (target && isElementVisible(target)) {
151
+ event.stopPropagation();
152
+ event.preventDefault(); // 新增:阻止表单默认提交(避免页面刷新)
153
+ target.click();
135
154
  }
136
155
  }
137
- }
156
+ };