-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
132 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,4 +36,9 @@ img { | |
margin-top: 2px; | ||
} | ||
/* 文本不可选中 */ | ||
.no-select { | ||
user-select: none; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
<template> | ||
<el-tooltip popper-class="no-select" :content="content" :disabled="!(isShow && isShowTooltip)" :show-after="delay" placement="top"> | ||
<div ref="tooltipContent" class="tooltip-content"> | ||
<slot name="content"></slot> | ||
</div> | ||
</el-tooltip> | ||
</template> | ||
|
||
<script> | ||
import { ref, onMounted, onBeforeUnmount } from 'vue'; | ||
export default { | ||
name: 'ToolTip', | ||
props: { | ||
content: { | ||
type:String, | ||
required:true, | ||
default:'', | ||
}, | ||
delay: { | ||
type:Number, | ||
required:false, | ||
default:200, | ||
}, | ||
isShow: { | ||
type:Boolean, | ||
required:false, | ||
default:true, | ||
} | ||
}, | ||
setup() { | ||
const tooltipContent = ref(null); | ||
const isShowTooltip = ref(false); | ||
// 检查内容是否溢出 | ||
const checkOverflow = () => { | ||
setTimeout(() => { | ||
if(tooltipContent.value && tooltipContent.value.firstElementChild) { | ||
isShowTooltip.value = tooltipContent.value.firstElementChild.scrollWidth > tooltipContent.value.firstElementChild.offsetWidth; | ||
} | ||
else isShowTooltip.value = false; | ||
},1); | ||
}; | ||
// 使用MutationObserver监听DOM变化 | ||
let mutationObserver = null; | ||
const observeTextChanges = () => { | ||
if(tooltipContent.value) { | ||
mutationObserver = new MutationObserver(() => { | ||
checkOverflow(); | ||
}); | ||
mutationObserver.observe(tooltipContent.value, { | ||
childList: true, // 监听子节点的变化 | ||
subtree: true, // 监听所有后代节点的变化 | ||
characterData: true, // 监听文本节点的变化 | ||
}); | ||
} | ||
}; | ||
onMounted(() => { | ||
checkOverflow(); | ||
observeTextChanges(); | ||
}); | ||
onBeforeUnmount(() => { | ||
if(mutationObserver) mutationObserver.disconnect(); | ||
}); | ||
return { | ||
tooltipContent, | ||
isShowTooltip, | ||
checkOverflow, | ||
}; | ||
}, | ||
}; | ||
</script> | ||
|
||
<style scoped> | ||
.tooltip-content { | ||
display: inline-block; | ||
white-space: nowrap; | ||
overflow: hidden; | ||
text-overflow: ellipsis; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
// 上线环境 | ||
let http_protocol = window.location.protocol; | ||
let ws_protocol = ''; | ||
if(http_protocol == 'https:') ws_protocol = 'wss://'; | ||
else ws_protocol = 'ws://'; | ||
export const ws_base_url = ws_protocol + window.location.host + '/socket/ssh/'; | ||
export const http_base_url = http_protocol + '//' + window.location.host + '/api'; | ||
// let http_protocol = window.location.protocol; | ||
// let ws_protocol = ''; | ||
// if(http_protocol == 'https:') ws_protocol = 'wss://'; | ||
// else ws_protocol = 'ws://'; | ||
// export const ws_base_url = ws_protocol + window.location.host + '/socket/ssh/'; | ||
// export const http_base_url = http_protocol + '//' + window.location.host + '/api'; | ||
|
||
// 本地开发环境 | ||
// export const ws_base_url = 'ws://localhost:3000/socket/ssh/'; | ||
// export const http_base_url = 'http://localhost:3000/api'; | ||
|
||
// 在线环境 | ||
// export const ws_base_url = 'wss://ssh.kkbpro.com/socket/ssh/'; | ||
// export const http_base_url = 'https://ssh.kkbpro.com/api'; | ||
export const ws_base_url = 'wss://ssh.kkbpro.com/socket/ssh/'; | ||
export const http_base_url = 'https://ssh.kkbpro.com/api'; |