-
Notifications
You must be signed in to change notification settings - Fork 3k
feat: Enhance log container with copy mode and improved UI layout #11905
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
HynoR
wants to merge
2
commits into
1Panel-dev:dev-v2
Choose a base branch
from
HynoR:feat/dk4
base: dev-v2
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+534
−174
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,44 +1,67 @@ | ||
| <template> | ||
| <div v-if="showControl"> | ||
| <el-select @change="searchLogs" class="fetchClass" v-model="logSearch.mode"> | ||
| <template #prefix>{{ $t('container.fetch') }}</template> | ||
| <el-option v-for="item in timeOptions" :key="item.label" :value="item.value" :label="item.label" /> | ||
| </el-select> | ||
| <el-select @change="searchLogs" class="tailClass" v-model.number="logSearch.tail"> | ||
| <template #prefix>{{ $t('container.lines') }}</template> | ||
| <el-option :value="0" :label="$t('commons.table.all')" /> | ||
| <el-option :value="100" :label="100" /> | ||
| <el-option :value="200" :label="200" /> | ||
| <el-option :value="500" :label="500" /> | ||
| <el-option :value="1000" :label="1000" /> | ||
| </el-select> | ||
| <div class="margin-button float-left"> | ||
| <el-checkbox border @change="searchLogs" v-model="logSearch.isWatch"> | ||
| {{ $t('commons.button.watch') }} | ||
| </el-checkbox> | ||
| <div v-if="showControl" class="toolbar-container"> | ||
| <div class="filter-row"> | ||
| <div class="select-group"> | ||
| <el-select @change="searchLogs" class="fetchClass" v-model="logSearch.mode" :disabled="isCopyMode"> | ||
| <template #prefix>{{ $t('container.fetch') }}</template> | ||
| <el-option v-for="item in timeOptions" :key="item.label" :value="item.value" :label="item.label" /> | ||
| </el-select> | ||
| <el-select | ||
| @change="searchLogs" | ||
| class="tailClass" | ||
| v-model.number="logSearch.tail" | ||
| :disabled="isCopyMode" | ||
| > | ||
| <template #prefix>{{ $t('container.lines') }}</template> | ||
| <el-option :value="0" :label="$t('commons.table.all')" /> | ||
| <el-option :value="100" :label="100" /> | ||
| <el-option :value="200" :label="200" /> | ||
| <el-option :value="500" :label="500" /> | ||
| <el-option :value="1000" :label="1000" /> | ||
| </el-select> | ||
| </div> | ||
| <div class="checkbox-group"> | ||
| <el-checkbox border @change="searchLogs" v-model="logSearch.isWatch" :disabled="isCopyMode"> | ||
| {{ $t('commons.button.watch') }} | ||
| </el-checkbox> | ||
| <el-checkbox border @change="searchLogs" v-model="logSearch.isShowTimestamp" :disabled="isCopyMode"> | ||
| {{ $t('commons.table.date') }} | ||
| </el-checkbox> | ||
| </div> | ||
| </div> | ||
| <div class="margin-button float-left"> | ||
| <el-checkbox border @change="searchLogs" v-model="logSearch.isShowTimestamp"> | ||
| {{ $t('commons.table.date') }} | ||
| </el-checkbox> | ||
| <div class="button-row"> | ||
| <el-button | ||
| @click="toggleCopyMode" | ||
| :type="isCopyMode ? 'primary' : 'default'" | ||
| :icon="isCopyMode ? 'Close' : 'CopyDocument'" | ||
| > | ||
| {{ isCopyMode ? $t('commons.button.close') : $t('commons.button.copy') }} | ||
| </el-button> | ||
| <el-button @click="onDownload" icon="Download" :disabled="isCopyMode"> | ||
| {{ $t('commons.button.download') }} | ||
| </el-button> | ||
| <el-button @click="onClean" icon="Delete" :disabled="isCopyMode"> | ||
| {{ $t('commons.button.clean') }} | ||
| </el-button> | ||
| </div> | ||
| <el-button class="margin-button" @click="onDownload" icon="Download"> | ||
| {{ $t('commons.button.download') }} | ||
| </el-button> | ||
| <el-button class="margin-button" @click="onClean" icon="Delete"> | ||
| {{ $t('commons.button.clean') }} | ||
| </el-button> | ||
| </div> | ||
| <div class="log-container" :style="styleVars" ref="logContainer"> | ||
| <div class="log-spacer" :style="{ height: `${totalHeight}px` }"></div> | ||
| <div | ||
| v-for="(log, index) in visibleLogs" | ||
| :key="startIndex + index" | ||
| class="log-item" | ||
| :style="{ top: `${(startIndex + index) * logHeight}px` }" | ||
| > | ||
| <hightlight :log="log" type="container" :container="container"></hightlight> | ||
| </div> | ||
| <template v-if="isCopyMode"> | ||
| <div v-for="(log, index) in logs" :key="`copy-${index}`" class="log-copy-item"> | ||
| <span class="whitespace-pre">{{ log }}</span> | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 日志内容很多的时候,点击复制按钮全部渲染会比较卡,是否可以加一个 loading 之类的效果 |
||
| </div> | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 也可以支持一波全选操作,如果日志内容太多的话,滚轮复制也不是一个好办法 |
||
| </template> | ||
| <template v-else> | ||
| <div class="log-spacer" :style="{ height: `${totalHeight}px` }"></div> | ||
| <div | ||
| v-for="(log, index) in visibleLogs" | ||
| :key="startIndex + index" | ||
| class="log-item" | ||
| :style="{ top: `${(startIndex + index) * logHeight}px` }" | ||
| > | ||
| <hightlight :log="log" type="container" :container="container"></hightlight> | ||
| </div> | ||
| </template> | ||
| </div> | ||
| </template> | ||
|
|
||
|
|
@@ -97,6 +120,8 @@ const styleVars = computed(() => ({ | |
| const logVisible = ref(false); | ||
| const logContainer = ref<HTMLElement | null>(null); | ||
| const logs = ref<string[]>([]); | ||
| const isCopyMode = ref(false); | ||
| const copyPendingLogs = ref<string[]>([]); | ||
| let eventSource: EventSource | null = null; | ||
| const logSearch = reactive({ | ||
| isWatch: props.defaultFollow ? true : true, | ||
|
|
@@ -148,16 +173,42 @@ const stopListening = () => { | |
|
|
||
| const handleClose = async () => { | ||
| stopListening(); | ||
| isCopyMode.value = false; | ||
| copyPendingLogs.value = []; | ||
| logVisible.value = false; | ||
| }; | ||
|
|
||
| const flushCopyPendingLogs = () => { | ||
| if (copyPendingLogs.value.length === 0) { | ||
| return; | ||
| } | ||
| logs.value.push(...copyPendingLogs.value); | ||
| copyPendingLogs.value = []; | ||
| }; | ||
|
|
||
| const toggleCopyMode = () => { | ||
| if (isCopyMode.value) { | ||
| isCopyMode.value = false; | ||
| flushCopyPendingLogs(); | ||
| nextTick(() => { | ||
| if (logContainer.value) { | ||
| logContainer.value.scrollTop = logContainer.value.scrollHeight; | ||
| } | ||
| }); | ||
| return; | ||
| } | ||
| isCopyMode.value = true; | ||
| }; | ||
|
|
||
| const searchLogs = async () => { | ||
| if (Number(logSearch.tail) < 0) { | ||
| MsgError(i18n.global.t('container.linesHelper')); | ||
| return; | ||
| } | ||
| stopListening(); | ||
| isCopyMode.value = false; | ||
| logs.value = []; | ||
| copyPendingLogs.value = []; | ||
| let currentNode = globalStore.currentNode; | ||
| if (props.node && props.node !== '') { | ||
| currentNode = props.node; | ||
|
|
@@ -169,6 +220,10 @@ const searchLogs = async () => { | |
| eventSource = new EventSource(url); | ||
| eventSource.onmessage = (event: MessageEvent) => { | ||
| const data = event.data; | ||
| if (isCopyMode.value) { | ||
| copyPendingLogs.value.push(data); | ||
| return; | ||
| } | ||
| logs.value.push(data); | ||
| nextTick(() => { | ||
| if (logContainer.value) { | ||
|
|
@@ -290,20 +345,50 @@ onMounted(() => { | |
| </script> | ||
|
|
||
| <style scoped lang="scss"> | ||
| .margin-button { | ||
| margin-left: 20px; | ||
| .toolbar-container { | ||
| display: flex; | ||
| flex-direction: column; | ||
| gap: 10px; | ||
| } | ||
|
|
||
| .filter-row { | ||
| display: flex; | ||
| align-items: center; | ||
| justify-content: space-between; | ||
| flex-wrap: wrap; | ||
| gap: 10px 12px; | ||
| } | ||
| .fullScreen { | ||
| border: none; | ||
|
|
||
| .button-row { | ||
| display: flex; | ||
| align-items: center; | ||
| gap: 12px; | ||
| flex-wrap: wrap; | ||
| } | ||
| .tailClass { | ||
| width: 20%; | ||
| float: left; | ||
| margin-left: 20px; | ||
|
|
||
| .select-group { | ||
| display: flex; | ||
| align-items: center; | ||
| flex-wrap: wrap; | ||
| gap: 12px; | ||
| } | ||
|
|
||
| .checkbox-group { | ||
| display: flex; | ||
| align-items: center; | ||
| gap: 12px; | ||
| flex-wrap: wrap; | ||
| margin-left: auto; | ||
| } | ||
|
|
||
| .fetchClass { | ||
| width: 30%; | ||
| float: left; | ||
| width: 320px; | ||
| max-width: 100%; | ||
| } | ||
|
|
||
| .tailClass { | ||
| width: 220px; | ||
| max-width: 100%; | ||
| } | ||
|
|
||
| .log-container { | ||
|
|
@@ -323,4 +408,12 @@ onMounted(() => { | |
| box-sizing: border-box; | ||
| white-space: nowrap; | ||
| } | ||
|
|
||
| .log-copy-item { | ||
| width: 100%; | ||
| padding: 2px; | ||
| color: #f5f5f5; | ||
| box-sizing: border-box; | ||
| white-space: nowrap; | ||
| } | ||
| </style> | ||
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
复制模式下,字体样式最好和原来的保持一致