This commit is contained in:
Qiuxia Fan 2022-07-26 18:01:57 +08:00
parent 19b85285ba
commit 4dd198b9a6
4 changed files with 58 additions and 104 deletions

View File

@ -15,6 +15,8 @@
* limitations under the License. * limitations under the License.
*/ */
import { useDashboardStore } from "@/store/modules/dashboard"; import { useDashboardStore } from "@/store/modules/dashboard";
import { LayoutConfig } from "@/types/dashboard";
export default function getDashboard(param: { export default function getDashboard(param: {
name: string; name: string;
layer: string; layer: string;
@ -29,7 +31,7 @@ export default function getDashboard(param: {
d.layer === param.layer d.layer === param.layer
); );
const all = dashboardStore.layout; const all = dashboardStore.layout;
const widgets = []; const widgets: LayoutConfig[] = [];
for (const item of all) { for (const item of all) {
if (item.type === "Tab") { if (item.type === "Tab") {
if (item.children && item.children.length) { if (item.children && item.children.length) {
@ -43,5 +45,31 @@ export default function getDashboard(param: {
widgets.push(item); widgets.push(item);
} }
} }
return { dashboard, widgets }; function associationWidget(sourceId: string, filters: unknown, type: string) {
const widget = widgets.filter((d: { type: string }) => d.type === type)[0];
if (!widget) {
return;
}
const item = {
...widget,
filters,
};
dashboardStore.setWidget(item);
const targetTabIndex = (widget.id || "").split("-");
const sourceTabindex = (sourceId || "").split("-") || [];
let container: Nullable<Element>;
if (targetTabIndex[1] === undefined) {
container = document.querySelector(".ds-main");
} else {
container = document.querySelector(".tab-layout");
}
if (targetTabIndex[1] && targetTabIndex[1] !== sourceTabindex[1]) {
dashboardStore.setActiveTabIndex(Number(targetTabIndex[1]));
}
if (container && widget) {
container.scrollTop = widget.y * 10;
}
}
return { dashboard, widgets, associationWidget };
} }

View File

@ -168,7 +168,7 @@ export default defineComponent({
for (const item of associate) { for (const item of associate) {
const widget = widgets.find( const widget = widgets.find(
(d: { id: string }) => d.id === item.widgetId (d: LayoutConfig) => d.id === item.widgetId
); );
if (widget) { if (widget) {
widget.filters = { widget.filters = {

View File

@ -121,7 +121,7 @@ limitations under the License. -->
</template> </template>
<script lang="ts"> <script lang="ts">
import dayjs from "dayjs"; import dayjs from "dayjs";
import { ref, defineComponent, computed, inject } from "vue"; import { ref, defineComponent, inject } from "vue";
import { useI18n } from "vue-i18n"; import { useI18n } from "vue-i18n";
import { useTraceStore } from "@/store/modules/trace"; import { useTraceStore } from "@/store/modules/trace";
import { Option } from "@/types/app"; import { Option } from "@/types/app";
@ -140,21 +140,14 @@ export default defineComponent({
LogTable, LogTable,
}, },
setup() { setup() {
/*global Nullable, Recordable */ /*global Recordable */
const options: Recordable<LayoutConfig> = inject("options") || {}; const options: Recordable<LayoutConfig> = inject("options") || {};
const { t } = useI18n(); const { t } = useI18n();
const traceStore = useTraceStore(); const traceStore = useTraceStore();
const loading = ref<boolean>(false); const loading = ref<boolean>(false);
const traceId = ref<string>(""); const traceId = ref<string>("");
const displayMode = ref<string>("List"); const displayMode = ref<string>("List");
const pageNum = ref<number>(1);
const pageSize = 10;
const dashboardStore = useDashboardStore(); const dashboardStore = useDashboardStore();
const total = computed(() =>
traceStore.traceList.length === pageSize
? pageSize * pageNum.value + 1
: pageSize * pageNum.value
);
const dateFormat = (date: number, pattern = "YYYY-MM-DD HH:mm:ss") => const dateFormat = (date: number, pattern = "YYYY-MM-DD HH:mm:ss") =>
dayjs(date).format(pattern); dayjs(date).format(pattern);
@ -173,41 +166,17 @@ export default defineComponent({
} }
async function searchTraceLogs() { async function searchTraceLogs() {
const { widgets } = getDashboard(dashboardStore.currentDashboard); const { associationWidget } = getDashboard(
const widget = widgets.filter( dashboardStore.currentDashboard
(d: { type: string }) => d.type === "Log" );
)[0]; associationWidget(
if (!widget) { (options.id as any) || "",
return; {
}
const item = {
...widget,
filters: {
sourceId: options?.id || "", sourceId: options?.id || "",
traceId: traceId.value || traceStore.currentTrace.traceIds[0].value, traceId: traceId.value || traceStore.currentTrace.traceIds[0].value,
}, },
}; "Log"
dashboardStore.setWidget(item); );
const logTabIndex = widget.id.split("-");
const traceTabindex = (options.id as any).split("-") || [];
let container: Nullable<Element>;
if (logTabIndex[1] === undefined) {
container = document.querySelector(".ds-main");
} else {
container = document.querySelector(".tab-layout");
}
if (logTabIndex[1] && logTabIndex[1] !== traceTabindex[1]) {
dashboardStore.setActiveTabIndex(Number(logTabIndex[1]));
}
if (container && widget) {
container.scrollTop = widget.y * 10;
}
}
function turnLogsPage(page: number) {
pageNum.value = page;
searchTraceLogs();
} }
return { return {
traceStore, traceStore,
@ -217,11 +186,7 @@ export default defineComponent({
handleClick, handleClick,
t, t,
searchTraceLogs, searchTraceLogs,
turnLogsPage,
pageSize,
pageNum,
loading, loading,
total,
traceId, traceId,
}; };
}, },

View File

@ -81,77 +81,38 @@ limitations under the License. -->
{{ t("relatedTraceLogs") }} {{ t("relatedTraceLogs") }}
</el-button> </el-button>
</div> </div>
<el-dialog
v-model="showRelatedLogs"
:destroy-on-close="true"
fullscreen
@closed="showRelatedLogs = false"
>
<el-pagination
v-model:currentPage="pageNum"
v-model:page-size="pageSize"
:small="true"
layout="prev, pager, next"
:pager-count="5"
:total="total"
@current-change="turnPage"
/>
<LogTable
:tableData="traceStore.traceSpanLogs || []"
:type="`service`"
:noLink="true"
>
<div class="log-tips" v-if="!traceStore.traceSpanLogs.length">
{{ t("noData") }}
</div>
</LogTable>
</el-dialog>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { ref, computed } from "vue"; import { ref, inject } from "vue";
import { useI18n } from "vue-i18n"; import { useI18n } from "vue-i18n";
import type { PropType } from "vue"; import type { PropType } from "vue";
import dayjs from "dayjs"; import dayjs from "dayjs";
import { useTraceStore } from "@/store/modules/trace";
import copy from "@/utils/copy"; import copy from "@/utils/copy";
import { ElMessage } from "element-plus"; import getDashboard from "@/hooks/useDashboardsSession";
import LogTable from "@/views/dashboard/related/components/LogTable/Index.vue"; import { useDashboardStore } from "@/store/modules/dashboard";
import { LayoutConfig } from "@/types/dashboard";
/* global defineProps */ /*global defineProps, Recordable */
const options: Recordable<LayoutConfig> = inject("options") || {};
const props = defineProps({ const props = defineProps({
currentSpan: { type: Object as PropType<any>, default: () => ({}) }, currentSpan: { type: Object as PropType<any>, default: () => ({}) },
}); });
const dashboardStore = useDashboardStore();
const { t } = useI18n(); const { t } = useI18n();
const traceStore = useTraceStore();
const pageNum = ref<number>(1);
const showRelatedLogs = ref<boolean>(false);
const pageSize = 10;
const total = computed(() =>
traceStore.traceList.length === pageSize
? pageSize * pageNum.value + 1
: pageSize * pageNum.value
);
const dateFormat = (date: number, pattern = "YYYY-MM-DD HH:mm:ss") => const dateFormat = (date: number, pattern = "YYYY-MM-DD HH:mm:ss") =>
dayjs(date).format(pattern); dayjs(date).format(pattern);
async function getTaceLogs() { async function getTaceLogs() {
showRelatedLogs.value = true; const { associationWidget } = getDashboard(dashboardStore.currentDashboard);
const res = await traceStore.getSpanLogs({ associationWidget(
condition: { (options.id as any) || "",
relatedTrace: { {
sourceId: options?.id || "",
traceId: props.currentSpan.traceId, traceId: props.currentSpan.traceId,
segmentId: props.currentSpan.segmentId, segmentId: props.currentSpan.segmentId,
spanId: props.currentSpan.spanId, spanId: props.currentSpan.spanId,
}, },
paging: { pageNum: pageNum.value, pageSize }, "Log"
}, );
});
if (res.errors) {
ElMessage.error(res.errors);
}
}
function turnPage(p: number) {
pageNum.value = p;
getTaceLogs();
} }
function showCurrentSpanDetail(text: string) { function showCurrentSpanDetail(text: string) {
copy(text); copy(text);