|
96 | 96 | </div> |
97 | 97 | ` |
98 | 98 | } |
| 99 | + |
| 100 | + function getHighestZIndexValue() { |
| 101 | + try { |
| 102 | + let maxZIndex = -Infinity |
| 103 | + let foundAny = false |
| 104 | + |
| 105 | + const allElements = document.all || document.querySelectorAll('*') |
| 106 | + |
| 107 | + for (let i = 0; i < allElements.length; i++) { |
| 108 | + const element = allElements[i] |
| 109 | + |
| 110 | + if (!element || element.nodeType !== 1) continue |
| 111 | + |
| 112 | + const styles = window.getComputedStyle(element) |
| 113 | + |
| 114 | + const position = styles.position |
| 115 | + if (position === 'static') continue |
| 116 | + |
| 117 | + const zIndex = styles.zIndex |
| 118 | + let zIndexValue |
| 119 | + |
| 120 | + if (zIndex === 'auto') { |
| 121 | + zIndexValue = 0 |
| 122 | + } else { |
| 123 | + zIndexValue = parseInt(zIndex, 10) |
| 124 | + if (isNaN(zIndexValue)) continue |
| 125 | + } |
| 126 | + |
| 127 | + foundAny = true |
| 128 | + |
| 129 | + // 快速返回:如果找到很大的z-index,很可能就是最大值 |
| 130 | + /* if (zIndexValue > 10000) { |
| 131 | + return zIndexValue; |
| 132 | + } */ |
| 133 | + |
| 134 | + if (zIndexValue > maxZIndex) { |
| 135 | + maxZIndex = zIndexValue |
| 136 | + } |
| 137 | + } |
| 138 | + return foundAny ? maxZIndex : 0 |
| 139 | + } catch (error) { |
| 140 | + console.warn('获取最高z-index时出错,返回默认值0:', error) |
| 141 | + return 0 |
| 142 | + } |
| 143 | + } |
| 144 | + |
99 | 145 | /** |
100 | 146 | * 初始化引导 |
101 | 147 | * @param {*} root |
|
256 | 302 |
|
257 | 303 | // 初始化全局样式 |
258 | 304 | function initsqlbot_assistantStyle(root, sqlbot_assistantId, data) { |
| 305 | + const maxZIndex = getHighestZIndexValue() |
| 306 | + const zIndex = Math.max((maxZIndex || 0) + 1, 10000) |
| 307 | + const maskZIndex = zIndex + 1 |
259 | 308 | style = document.createElement('style') |
260 | 309 | style.type = 'text/css' |
261 | 310 | style.innerText = ` |
|
279 | 328 |
|
280 | 329 | #sqlbot-assistant .sqlbot-assistant-mask { |
281 | 330 | position: fixed; |
282 | | - z-index: 10001; |
| 331 | + z-index: ${maskZIndex}; |
283 | 332 | background-color: transparent; |
284 | 333 | height: 100%; |
285 | 334 | width: 100%; |
|
293 | 342 | position: absolute; |
294 | 343 | ${data.x_type}: ${data.x_val}px; |
295 | 344 | ${data.y_type}: ${data.y_val}px; |
296 | | - z-index: 10001; |
| 345 | + z-index: ${maskZIndex}; |
297 | 346 | } |
298 | 347 | #sqlbot-assistant .sqlbot-assistant-tips { |
299 | 348 | position: fixed; |
|
304 | 353 | color: #ffffff; |
305 | 354 | font-size: 14px; |
306 | 355 | background: #3370FF; |
307 | | - z-index: 10001; |
| 356 | + z-index: ${maskZIndex}; |
308 | 357 | } |
309 | 358 | #sqlbot-assistant .sqlbot-assistant-tips .sqlbot-assistant-arrow { |
310 | 359 | position: absolute; |
|
366 | 415 | ${data.x_type}: ${data.x_val}px; |
367 | 416 | ${data.y_type}: ${data.y_val}px; |
368 | 417 | cursor: pointer; |
369 | | - z-index:10000; |
| 418 | + z-index: ${zIndex}; |
370 | 419 | } |
371 | 420 | #sqlbot-assistant #sqlbot-assistant-chat-container{ |
372 | | - z-index:10000;position: relative; |
| 421 | + z-index: ${zIndex}; |
| 422 | + position: relative; |
373 | 423 | border-radius: 8px; |
374 | 424 | //border: 1px solid #ffffff; |
375 | 425 | background: linear-gradient(188deg, rgba(235, 241, 255, 0.20) 39.6%, rgba(231, 249, 255, 0.20) 94.3%), #EFF0F1; |
|
0 commit comments