Skip to content

Commit

Permalink
style: overflow text tooltip
Browse files Browse the repository at this point in the history
  • Loading branch information
zyyzyykk committed Dec 9, 2024
1 parent e3cc4ad commit 0b276e0
Show file tree
Hide file tree
Showing 6 changed files with 132 additions and 14 deletions.
5 changes: 5 additions & 0 deletions front/terminal/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,9 @@ img {
margin-top: 2px;
}
/* 文本不可选中 */
.no-select {
user-select: none;
}
</style>
8 changes: 7 additions & 1 deletion front/terminal/src/components/ConnectSetting.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@
<div>
<div class="item-class" style="margin-bottom: 15px;">
<div class="no-select form-width nowrap">{{ $t('配\u00A0\u00A0\u00A0置') }}:</div>
<div class="ellipsis" style="user-select: none;" :class="!(setInfo.option && setInfo.option.length > 0) ? 'new-option': 'old-option'" >{{ !(setInfo.option && setInfo.option.length > 0) ? $t('新建配置') : setInfo.option }}</div>
<ToolTip :content="!(setInfo.option && setInfo.option.length > 0) ? $t('新建配置') : setInfo.option" >
<template #content>
<div class="ellipsis" style="user-select: none;" :class="!(setInfo.option && setInfo.option.length > 0) ? 'new-option': 'old-option'" >{{ !(setInfo.option && setInfo.option.length > 0) ? $t('新建配置') : setInfo.option }}</div>
</template>
</ToolTip>
<div style="flex: 1;"></div>
<div><el-button size="small" type="primary" @click="showOption(0)" style="margin-left: 10px;" ><el-icon class="el-icon--left"><Switch /></el-icon>{{ $t('切换') }}</el-button></div>
<div><el-button v-if="isForbidInput == false" size="small" type="primary" @click="showOption(1)" style="margin-left: 10px;" ><el-icon class="el-icon--left"><Finished /></el-icon>{{ $t('保存') }}</el-button></div>
Expand Down Expand Up @@ -86,12 +90,14 @@ import { ref } from 'vue';
import useClipboard from "vue-clipboard3";
import { ElMessage } from 'element-plus';
import OptionBlock from './OptionBlock';
import ToolTip from './ToolTip.vue';
import { HomeFilled, Paperclip, User, Lock, DocumentCopy, View, Hide, Edit, Finished, Switch } from '@element-plus/icons-vue';
import i18n from "@/locales/i18n";
export default {
name:'ConnectSetting',
components: {
ToolTip,
OptionBlock,
HomeFilled,
Paperclip,
Expand Down
12 changes: 9 additions & 3 deletions front/terminal/src/components/FileAttr.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,13 @@
<div class="kk-border" ></div>
<div class="kk-flex nowrap">
<div class="form-width" >{{ $t('位置') }}:</div>
<div class="ellipsis">
{{ fileDir + fileInfo.name }}
</div>
<ToolTip :content="fileDir + fileInfo.name" >
<template #content>
<div class="ellipsis">
{{ fileDir + fileInfo.name }}
</div>
</template>
</ToolTip>
<div style="cursor: pointer; margin-left: 5px;" @click="doCopy(fileDir + fileInfo.name)">
<el-icon size="18"><DocumentCopy /></el-icon>
</div>
Expand Down Expand Up @@ -98,6 +102,7 @@ import useClipboard from "vue-clipboard3";
import { DocumentCopy, Refresh } from '@element-plus/icons-vue';
import { calcSize } from '@/utils/CalcSize';
import { escapeItem, escapePath } from '@/utils/StringUtil';
import ToolTip from './ToolTip.vue';
import i18n from "@/locales/i18n";
// 引入文件图标组件
Expand All @@ -106,6 +111,7 @@ import FileIcons from 'file-icons-vue';
export default {
name: 'FileAttr',
components: {
ToolTip,
FileIcons,
DocumentCopy,
Refresh,
Expand Down
18 changes: 16 additions & 2 deletions front/terminal/src/components/FileBlock.vue
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,13 @@
<div style="margin: 0 10px;" v-if="isShowRenameInput == true && renameFile && item.id == renameFile.id" >
<el-input id="rename" v-model="renameFile.name" placeholder="" size="small" @keydown.enter="isShowRenameInput = false;" @blur="isShowRenameInput = false;" @mousedown.stop @dblclick.stop @change="handleRename(item)" />
</div>
<div v-else class="ellipsis" style="margin: 0 10px;">{{ item.name }}</div>
<ToolTip :isShow="!isShowMenu" :content="item.name" :delay="1000" >
<template #content>
<div v-if="!(isShowRenameInput == true && renameFile && item.id == renameFile.id)" class="ellipsis" style="margin: 0 10px;">
{{ item.name }}
</div>
</template>
</ToolTip>
</div>
</template>
<template v-else>
Expand All @@ -76,7 +82,13 @@
<div style="margin: 0 10px;" v-if="isShowRenameInput == true && renameFile && item.id == renameFile.id" >
<el-input id="rename" v-model="renameFile.name" placeholder="" size="small" @keydown.enter="isShowRenameInput = false;" @blur="isShowRenameInput = false;" @mousedown.stop @dblclick.stop @change="handleRename(item)" />
</div>
<div v-else class="ellipsis" style="margin: 0 10px;">{{ item.name }}</div>
<ToolTip :isShow="!isShowMenu" :content="item.name" :delay="1000" >
<template #content>
<div v-if="!(isShowRenameInput == true && renameFile && item.id == renameFile.id)" class="ellipsis" style="margin: 0 10px;">
{{ item.name }}
</div>
</template>
</ToolTip>
</div>
</template>
</div>
Expand Down Expand Up @@ -148,6 +160,7 @@ import { http_base_url } from '@/utils/BaseUrl';
import { Refresh, Fold, Download, Upload, DocumentAdd, FolderAdd, Link } from '@element-plus/icons-vue';
import { escapeItem, escapePath } from '@/utils/StringUtil';
import { isZipFile } from '@/utils/FileSuffix';
import ToolTip from './ToolTip.vue';
import NoData from '@/components/NoData';
import TxtPreview from './preview/TxtPreview';
Expand All @@ -163,6 +176,7 @@ import FileIcons from 'file-icons-vue';
export default {
name:'FileBlock',
components: {
ToolTip,
NoData,
FileIcons,
TxtPreview,
Expand Down
87 changes: 87 additions & 0 deletions front/terminal/src/components/ToolTip.vue
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>
16 changes: 8 additions & 8 deletions front/terminal/src/utils/BaseUrl.js
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';

0 comments on commit 0b276e0

Please sign in to comment.