From 41d01112600075db5f4451fa188a4bdfc1e6354a Mon Sep 17 00:00:00 2001 From: shuzhenyang Date: Thu, 31 Oct 2024 15:24:40 +0800 Subject: [PATCH] =?UTF-8?q?fix(access-log)=EF=BC=9A=E6=B5=81=E6=B0=B4?= =?UTF-8?q?=E6=97=A5=E5=BF=97=E4=BD=93=E9=AA=8C=E9=97=AE=E9=A2=98=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=20optimize=20code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit optimize code --- .../src/components/ag-icon.vue | 25 +++++ src/dashboard-front/src/language/lang.ts | 1 + .../views/operate-data/access-log/index.vue | 102 +++++++++++++++--- 3 files changed, 115 insertions(+), 13 deletions(-) create mode 100644 src/dashboard-front/src/components/ag-icon.vue diff --git a/src/dashboard-front/src/components/ag-icon.vue b/src/dashboard-front/src/components/ag-icon.vue new file mode 100644 index 000000000..2aa680e09 --- /dev/null +++ b/src/dashboard-front/src/components/ag-icon.vue @@ -0,0 +1,25 @@ + + + diff --git a/src/dashboard-front/src/language/lang.ts b/src/dashboard-front/src/language/lang.ts index 0af70afef..f368f1ffd 100644 --- a/src/dashboard-front/src/language/lang.ts +++ b/src/dashboard-front/src/language/lang.ts @@ -1515,6 +1515,7 @@ const lang: ILANG = { '关键字搜索': ['Keyword search'], '引用条件': ['Reference condition'], '如何使用': ['How to use'], + '检索出的日志条数为 0,不需要下载': ['The number of retrieved logs is 0, do not need to download'], '新建后端服务': ['Create backend service'], '于': ['at'], '超时时间不能为空': ['Timeout cannot be empty'], diff --git a/src/dashboard-front/src/views/operate-data/access-log/index.vue b/src/dashboard-front/src/views/operate-data/access-log/index.vue index 96b0f102f..85e6c03ce 100644 --- a/src/dashboard-front/src/views/operate-data/access-log/index.vue +++ b/src/dashboard-front/src/views/operate-data/access-log/index.vue @@ -58,7 +58,7 @@ {{ t('检索项:') }} - {{ item }} + + {{ t('清除') }} @@ -113,12 +114,14 @@ {{ t('日志详情') }} {{ t('共') }} - {{ table?.list?.length }} + {{ pageCount }} {{ t('条') }} - - - + + {{ t('下载日志') }}
- + {{ t('状态码为 200 时不记录响应正文') }} {{ formatValue(row[field], field) }} - + - - +
@@ -249,6 +254,7 @@ import { } from 'bkui-vue/lib/icon'; import { Message } from 'bkui-vue'; import { useStorage } from '@vueuse/core'; +import AgIcon from '@/components/ag-icon.vue'; const { t } = i18n.global; const { getChartIntervalOption } = userChartIntervalOption(); @@ -310,6 +316,10 @@ const searchConditions = computed(() => { return res; }); +const pageCount = computed(() => { + return pagination.value.count; +}); + // const searchUsage = ref({ // showed: false, // }); @@ -434,6 +444,10 @@ const renderChart = (data: Record) => { feature: { dataZoom: { show: true, + yAxisIndex: 'none', + iconStyle: { + opacity: 0, + }, }, }, }, @@ -441,6 +455,11 @@ const renderChart = (data: Record) => { const timeDuration = timeline[timeline.length - 1] - timeline[0]; const intervalOption = getChartIntervalOption(timeDuration, 'time', 'xAxis'); chartInstance.value.setOption(merge(options, intervalOption)); + chartInstance.value?.dispatchAction({ + type: 'takeGlobalCursor', + key: 'dataZoomSelect', + dataZoomSelectActive: true, + }); chartResize(); }; @@ -644,6 +663,16 @@ const handleTagClose = (item: string) => { getSearchData(); }; +const generateTagContent = (item: string) => { + if (!item) { + return; + } + if (item.indexOf('!=') !== -1) { + return item.replace('!=', '!='); + } + return item.replace('=', '='); +}; + const handleClearSearch = () => { includeObj.value = []; excludeObj.value = []; @@ -651,6 +680,9 @@ const handleClearSearch = () => { }; const handleDownload = async (e: Event) => { + if (pagination.value.count === 0) { + return; + } e.stopPropagation(); try { const { params, path } = getPayload(); @@ -794,6 +826,31 @@ const initData = async () => { const initChart = async () => { chartInstance.value = markRaw(echarts.init(chartContainer.value)); window.addEventListener('resize', chartResize); + + chartInstance.value.on('datazoom', (event: {batch: {startValue: number, endValue: number}[]}) => { + const { startValue, endValue } = event.batch[0]; + + // 获取x轴缩放后的数据范围 + const zoomedXAxisData = chartInstance.value.getOption().xAxis[0].data.slice(startValue, endValue + 1); + const startTime = zoomedXAxisData[0]; + const endTime = zoomedXAxisData[zoomedXAxisData.length - 1]; + + if (startTime === endTime) { + dateTimeRange.value = []; + shortcutSelectedIndex.value = 1; + [datePickerRef.value.shortcut] = [AccessLogStore.datepickerShortcuts[1]]; + + chartInstance.value.dispatchAction({ + type: 'restore', + }); + } else { + shortcutSelectedIndex.value = -1; + dateTimeRange.value = [new Date(startTime), new Date(endTime)]; + } + + dateKey.value = String(+new Date()); + handlePickerChange(); + }); }; onMounted(() => { @@ -842,6 +899,10 @@ onBeforeUnmount(() => { font-size: 16px; margin-right: -4px; } + &.disabled-logs { + color: #c4c6cc; + cursor: not-allowed; + } } .panel-title-icon { transition: .2s; @@ -1003,12 +1064,15 @@ onBeforeUnmount(() => { } .opt-btns { - color: #1768EF; - font-size: 18px; + color: #979BA5; + font-size: 16px; padding-top: 3px; margin-left: 10px; + &:hover { + color: #1768EF; + } .opt-copy { - font-size: 16px; + font-size: 14px; } span { cursor: pointer; @@ -1138,4 +1202,16 @@ onBeforeUnmount(() => { .access-log-popover { top: 10px !important; } +.include-equal, +.exclude-equal { + font-weight: bold; + font-size: 16px; + vertical-align: bottom; +} +.exclude-equal { + color: #EA3636; +} +.include-equal { + color: #2DCB56; +}