@liujitcn/kratos-admin-bi 0.0.0-stage → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +43 -2
- package/dist/package/declarations/index.d.ts +1 -0
- package/dist/package/declarations/src/api/bi/admin/v1/bi_card.d.ts +18 -0
- package/dist/package/declarations/src/api/bi/admin/v1/bi_card.js +46 -0
- package/dist/package/declarations/src/api/bi/admin/v1/bi_dashboard.d.ts +17 -0
- package/dist/package/declarations/src/api/bi/admin/v1/bi_dashboard.js +30 -0
- package/dist/package/declarations/src/api/bi/admin/v1/bi_query.d.ts +11 -0
- package/dist/package/declarations/src/api/bi/admin/v1/bi_query.js +41 -0
- package/dist/package/declarations/src/api/bi/admin/v1/bi_query_record.d.ts +10 -0
- package/dist/package/declarations/src/api/bi/admin/v1/bi_query_record.js +14 -0
- package/dist/package/declarations/src/api/bi/admin/v1/bi_source.d.ts +26 -0
- package/dist/package/declarations/src/api/bi/admin/v1/bi_source.js +46 -0
- package/dist/package/declarations/src/bi-core.d.ts +17 -0
- package/dist/package/declarations/src/bi-core.js +22 -0
- package/dist/package/declarations/src/bi-dashboard-schema.d.ts +31 -0
- package/dist/package/declarations/src/bi-dashboard-schema.js +39 -0
- package/dist/package/declarations/src/bi-messages.d.ts +247 -0
- package/dist/package/declarations/src/bi-messages.js +247 -0
- package/dist/package/declarations/src/bi-response.d.ts +10 -0
- package/dist/package/declarations/src/bi-response.js +33 -0
- package/dist/package/declarations/src/bi-vue.d.ts +10 -0
- package/dist/package/declarations/src/bi-vue.js +10 -0
- package/dist/package/declarations/src/card-schema.d.ts +30 -0
- package/dist/package/declarations/src/card-schema.js +87 -0
- package/dist/package/declarations/src/components/BiCardChartEditor.vue.d.ts +17 -0
- package/dist/package/declarations/src/components/BiCardChartEditor.vue.js +527 -0
- package/dist/package/declarations/src/components/BiCardFormDialog.vue.d.ts +20 -0
- package/dist/package/declarations/src/components/BiCardFormDialog.vue.js +495 -0
- package/dist/package/declarations/src/components/BiCardLibrary.vue.d.ts +3 -0
- package/dist/package/declarations/src/components/BiCardLibrary.vue.js +807 -0
- package/dist/package/declarations/src/components/BiCardVisualization.vue.d.ts +10 -0
- package/dist/package/declarations/src/components/BiCardVisualization.vue.js +97 -0
- package/dist/package/declarations/src/components/BiChart.vue.d.ts +20 -0
- package/dist/package/declarations/src/components/BiChart.vue.js +112 -0
- package/dist/package/declarations/src/components/BiDashboard.vue.d.ts +9 -0
- package/dist/package/declarations/src/components/BiDashboard.vue.js +81 -0
- package/dist/package/declarations/src/components/BiDashboardMenuDialog.vue.d.ts +12 -0
- package/dist/package/declarations/src/components/BiDashboardMenuDialog.vue.js +252 -0
- package/dist/package/declarations/src/components/BiDataCard.vue.d.ts +36 -0
- package/dist/package/declarations/src/components/BiDataCard.vue.js +372 -0
- package/dist/package/declarations/src/components/BiDesigner.vue.d.ts +17 -0
- package/dist/package/declarations/src/components/BiDesigner.vue.js +666 -0
- package/dist/package/declarations/src/components/BiSourceModelDialog.vue.d.ts +17 -0
- package/dist/package/declarations/src/components/BiSourceModelDialog.vue.js +2118 -0
- package/dist/package/declarations/src/components/BiWorkbenchPreview.vue.d.ts +7 -0
- package/dist/package/declarations/src/components/BiWorkbenchPreview.vue.js +176 -0
- package/dist/package/declarations/src/components/source-model-layout.d.ts +3 -0
- package/dist/package/declarations/src/components/source-model-layout.js +66 -0
- package/dist/package/declarations/src/dataset/index.d.ts +7 -0
- package/dist/package/declarations/src/dataset/index.js +25 -0
- package/dist/package/declarations/src/dataset/labels.d.ts +2 -0
- package/dist/package/declarations/src/dataset/labels.js +21 -0
- package/dist/package/declarations/src/dataset/transform.d.ts +20 -0
- package/dist/package/declarations/src/dataset/transform.js +173 -0
- package/dist/package/declarations/src/engine/chart-types.d.ts +14 -0
- package/dist/package/declarations/src/engine/chart-types.js +37 -0
- package/dist/package/declarations/src/engine/echarts.d.ts +16 -0
- package/dist/package/declarations/src/engine/echarts.js +491 -0
- package/dist/package/declarations/src/engine/types.d.ts +36 -0
- package/dist/package/declarations/src/engine/types.js +20 -0
- package/dist/package/declarations/src/env.d.ts +17 -0
- package/dist/package/declarations/src/env.js +67 -0
- package/dist/package/declarations/src/index.d.ts +1 -0
- package/dist/package/declarations/src/index.js +1 -0
- package/dist/package/declarations/src/locales/en-US.json +254 -0
- package/dist/package/declarations/src/locales/generated.d.ts +1021 -0
- package/dist/package/declarations/src/locales/generated.js +13 -0
- package/dist/package/declarations/src/locales/ja-JP.json +254 -0
- package/dist/package/declarations/src/locales/zh-CN.json +254 -0
- package/dist/package/declarations/src/locales/zh-TW.json +254 -0
- package/dist/package/declarations/src/module.d.ts +2 -0
- package/dist/package/declarations/src/module.js +9 -0
- package/dist/package/declarations/src/rpc/bi/admin/v1/bi_card.d.ts +145 -0
- package/dist/package/declarations/src/rpc/bi/admin/v1/bi_card.js +6 -0
- package/dist/package/declarations/src/rpc/bi/admin/v1/bi_dashboard.d.ts +107 -0
- package/dist/package/declarations/src/rpc/bi/admin/v1/bi_dashboard.js +6 -0
- package/dist/package/declarations/src/rpc/bi/admin/v1/bi_query.d.ts +157 -0
- package/dist/package/declarations/src/rpc/bi/admin/v1/bi_query.js +6 -0
- package/dist/package/declarations/src/rpc/bi/admin/v1/bi_query_record.d.ts +83 -0
- package/dist/package/declarations/src/rpc/bi/admin/v1/bi_query_record.js +15 -0
- package/dist/package/declarations/src/rpc/bi/admin/v1/bi_source.d.ts +301 -0
- package/dist/package/declarations/src/rpc/bi/admin/v1/bi_source.js +6 -0
- package/dist/package/declarations/src/rpc/common/v1/types.d.ts +60 -0
- package/dist/package/declarations/src/rpc/common/v1/types.js +6 -0
- package/dist/package/declarations/src/schema/layout.d.ts +7 -0
- package/dist/package/declarations/src/schema/layout.js +52 -0
- package/dist/package/declarations/src/schema/types.d.ts +83 -0
- package/dist/package/declarations/src/schema/types.js +1 -0
- package/dist/package/declarations/src/theme/index.d.ts +29 -0
- package/dist/package/declarations/src/theme/index.js +83 -0
- package/dist/package/declarations/src/theme/palettes.d.ts +7 -0
- package/dist/package/declarations/src/theme/palettes.js +28 -0
- package/dist/package/declarations/src/theme/presets.d.ts +73 -0
- package/dist/package/declarations/src/theme/presets.js +235 -0
- package/dist/package/declarations/src/views/card/index.vue.d.ts +3 -0
- package/dist/package/declarations/src/views/card/index.vue.js +18 -0
- package/dist/package/declarations/src/views/dashboard/index.vue.d.ts +3 -0
- package/dist/package/declarations/src/views/dashboard/index.vue.js +107 -0
- package/dist/package/declarations/src/views/designer/index.vue.d.ts +3 -0
- package/dist/package/declarations/src/views/designer/index.vue.js +332 -0
- package/dist/package/declarations/src/views/manage/index.vue.d.ts +3 -0
- package/dist/package/declarations/src/views/manage/index.vue.js +325 -0
- package/dist/package/declarations/src/views/query/index.vue.d.ts +3 -0
- package/dist/package/declarations/src/views/query/index.vue.js +876 -0
- package/dist/package/declarations/src/views/source/index.vue.d.ts +3 -0
- package/dist/package/declarations/src/views/source/index.vue.js +343 -0
- package/dist/package/declarations/src/views/workbench/index.vue.d.ts +3 -0
- package/dist/package/declarations/src/views/workbench/index.vue.js +362 -0
- package/dist/package/src/api/bi/admin/v1/bi_card.ts +67 -0
- package/dist/package/src/api/bi/admin/v1/bi_dashboard.ts +51 -0
- package/dist/package/src/api/bi/admin/v1/bi_query.ts +55 -0
- package/dist/package/src/api/bi/admin/v1/bi_query_record.ts +25 -0
- package/dist/package/src/api/bi/admin/v1/bi_source.ts +80 -0
- package/dist/package/src/bi-core.ts +43 -0
- package/dist/package/src/bi-dashboard-schema.ts +69 -0
- package/dist/package/src/bi-messages.ts +249 -0
- package/dist/package/src/bi-response.ts +39 -0
- package/dist/package/src/bi-vue.ts +13 -0
- package/dist/package/src/card-schema.ts +111 -0
- package/dist/package/src/components/BiCardChartEditor.vue +139 -0
- package/dist/package/src/components/BiCardFormDialog.vue +289 -0
- package/dist/package/src/components/BiCardLibrary.vue +310 -0
- package/dist/package/src/components/BiCardVisualization.vue +95 -0
- package/dist/package/src/components/BiChart.vue +134 -0
- package/dist/package/src/components/BiDashboard.vue +53 -0
- package/dist/package/src/components/BiDashboardMenuDialog.vue +177 -0
- package/dist/package/src/components/BiDataCard.vue +231 -0
- package/dist/package/src/components/BiDesigner.vue +287 -0
- package/dist/package/src/components/BiSourceModelDialog.vue +846 -0
- package/dist/package/src/components/BiWorkbenchPreview.vue +131 -0
- package/dist/package/src/components/source-model-layout.ts +62 -0
- package/dist/package/src/dataset/index.ts +28 -0
- package/dist/package/src/dataset/labels.ts +19 -0
- package/dist/package/src/dataset/transform.ts +189 -0
- package/dist/package/src/engine/chart-types.ts +44 -0
- package/dist/package/src/engine/echarts.ts +568 -0
- package/dist/package/src/engine/types.ts +60 -0
- package/dist/package/src/env.ts +82 -0
- package/dist/package/src/index.ts +1 -0
- package/dist/package/src/locales/en-US.json +254 -0
- package/dist/package/src/locales/generated.ts +16 -0
- package/dist/package/src/locales/ja-JP.json +254 -0
- package/dist/package/src/locales/zh-CN.json +254 -0
- package/dist/package/src/locales/zh-TW.json +254 -0
- package/dist/package/src/module.ts +12 -0
- package/dist/package/src/rpc/bi/admin/v1/bi_card.ts +169 -0
- package/dist/package/src/rpc/bi/admin/v1/bi_dashboard.ts +126 -0
- package/dist/package/src/rpc/bi/admin/v1/bi_query.ts +187 -0
- package/dist/package/src/rpc/bi/admin/v1/bi_query_record.ts +98 -0
- package/dist/package/src/rpc/bi/admin/v1/bi_source.ts +338 -0
- package/dist/package/src/rpc/common/v1/types.ts +77 -0
- package/dist/package/src/schema/layout.ts +54 -0
- package/dist/package/src/schema/types.ts +103 -0
- package/dist/package/src/styles.scss +1 -0
- package/dist/package/src/theme/index.ts +108 -0
- package/dist/package/src/theme/palettes.ts +34 -0
- package/dist/package/src/theme/presets.ts +278 -0
- package/dist/package/src/views/card/index.vue +5 -0
- package/dist/package/src/views/dashboard/index.vue +58 -0
- package/dist/package/src/views/designer/index.vue +164 -0
- package/dist/package/src/views/manage/index.vue +276 -0
- package/dist/package/src/views/query/index.vue +593 -0
- package/dist/package/src/views/source/index.vue +214 -0
- package/dist/package/src/views/workbench/index.vue +208 -0
- package/package.json +67 -3
- package/tsconfig.json +12 -0
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="bi-chart">
|
|
3
|
+
<div ref="hostRef" class="bi-chart__host" :style="{ visibility: ready ? 'visible' : 'hidden' }" />
|
|
4
|
+
<div v-if="error" class="bi-chart__error" :title="error">!</div>
|
|
5
|
+
<div v-else-if="!rows.length" class="bi-chart__empty">{{ emptyText }}</div>
|
|
6
|
+
</div>
|
|
7
|
+
</template>
|
|
8
|
+
|
|
9
|
+
<script setup lang="ts">
|
|
10
|
+
/**
|
|
11
|
+
* 单图表渲染:引擎挂载 + 行数据/主题变化重编译 + ResizeObserver 跟随。
|
|
12
|
+
* 空数据不挂引擎,只显示占位文案。
|
|
13
|
+
*/
|
|
14
|
+
import { onBeforeUnmount, onMounted, ref, watch } from "vue";
|
|
15
|
+
import { getEngine, transformRows } from "../bi-core";
|
|
16
|
+
import type { BiChartEvent, BiChartSchema, BiResolvedTheme, ChartHandle } from "../bi-core";
|
|
17
|
+
|
|
18
|
+
const props = withDefaults(
|
|
19
|
+
defineProps<{
|
|
20
|
+
chart: BiChartSchema;
|
|
21
|
+
rows: any[];
|
|
22
|
+
theme: BiResolvedTheme;
|
|
23
|
+
loading?: boolean;
|
|
24
|
+
error?: string | null;
|
|
25
|
+
emptyText?: string;
|
|
26
|
+
}>(),
|
|
27
|
+
{ loading: false, error: null, emptyText: "" }
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
const emit = defineEmits<{
|
|
31
|
+
"chart-click": [event: BiChartEvent];
|
|
32
|
+
}>();
|
|
33
|
+
|
|
34
|
+
const hostRef = ref<HTMLElement | null>(null);
|
|
35
|
+
const ready = ref(false);
|
|
36
|
+
let handle: ChartHandle | null = null;
|
|
37
|
+
let observer: ResizeObserver | null = null;
|
|
38
|
+
let frame = 0;
|
|
39
|
+
|
|
40
|
+
/** 释放图表及尚未执行的尺寸更新。 */
|
|
41
|
+
function teardown() {
|
|
42
|
+
cancelAnimationFrame(frame);
|
|
43
|
+
observer?.disconnect();
|
|
44
|
+
observer = null;
|
|
45
|
+
handle?.dispose();
|
|
46
|
+
handle = null;
|
|
47
|
+
ready.value = false;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function compileAndApply() {
|
|
51
|
+
if (!handle) return;
|
|
52
|
+
const engine = getEngine(props.chart.engine);
|
|
53
|
+
handle.update(engine.compile(props.chart, transformRows(props.chart, props.rows), props.theme));
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** 等弹窗或折叠区域实际显示后再挂载图表,避免以零尺寸初始化。 */
|
|
57
|
+
function setup() {
|
|
58
|
+
teardown();
|
|
59
|
+
if (!hostRef.value || !props.rows.length) return;
|
|
60
|
+
observer = new ResizeObserver(() => {
|
|
61
|
+
cancelAnimationFrame(frame);
|
|
62
|
+
frame = requestAnimationFrame(() => {
|
|
63
|
+
const host = hostRef.value;
|
|
64
|
+
if (!host?.clientWidth || !host.clientHeight) return;
|
|
65
|
+
if (handle) {
|
|
66
|
+
handle.resize();
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
const engine = getEngine(props.chart.engine);
|
|
70
|
+
handle = engine.mount(host, engine.compile(props.chart, transformRows(props.chart, props.rows), props.theme));
|
|
71
|
+
engine.bindEvents(handle, (e) => emit("chart-click", { ...e, chartId: props.chart.id }));
|
|
72
|
+
ready.value = true;
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
observer.observe(hostRef.value);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
onMounted(setup);
|
|
79
|
+
|
|
80
|
+
watch(
|
|
81
|
+
() => [props.rows, props.theme, props.chart] as const,
|
|
82
|
+
() => {
|
|
83
|
+
// 数据从空到有 / 引擎未挂时重建;否则原地重编译
|
|
84
|
+
if (!handle || !props.rows.length) {
|
|
85
|
+
setup();
|
|
86
|
+
} else {
|
|
87
|
+
compileAndApply();
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
{ deep: true }
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
onBeforeUnmount(teardown);
|
|
94
|
+
</script>
|
|
95
|
+
|
|
96
|
+
<style scoped>
|
|
97
|
+
.bi-chart {
|
|
98
|
+
position: relative;
|
|
99
|
+
width: 100%;
|
|
100
|
+
height: 100%;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
.bi-chart__host {
|
|
104
|
+
width: 100%;
|
|
105
|
+
height: 100%;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
.bi-chart__empty {
|
|
109
|
+
position: absolute;
|
|
110
|
+
inset: 0;
|
|
111
|
+
display: flex;
|
|
112
|
+
align-items: center;
|
|
113
|
+
justify-content: center;
|
|
114
|
+
color: var(--el-text-color-secondary, #909399);
|
|
115
|
+
font-size: 13px;
|
|
116
|
+
user-select: none;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
.bi-chart__error {
|
|
120
|
+
position: absolute;
|
|
121
|
+
top: 6px;
|
|
122
|
+
right: 6px;
|
|
123
|
+
width: 16px;
|
|
124
|
+
height: 16px;
|
|
125
|
+
display: flex;
|
|
126
|
+
align-items: center;
|
|
127
|
+
justify-content: center;
|
|
128
|
+
border-radius: 50%;
|
|
129
|
+
background: var(--el-color-danger, #f56c6c);
|
|
130
|
+
color: #fff;
|
|
131
|
+
font-size: 11px;
|
|
132
|
+
cursor: help;
|
|
133
|
+
}
|
|
134
|
+
</style>
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="bi-dashboard-grid">
|
|
3
|
+
<div
|
|
4
|
+
v-for="item in schema.cards"
|
|
5
|
+
:key="item.id"
|
|
6
|
+
class="bi-dashboard-grid__item"
|
|
7
|
+
:style="{ gridColumn: `${(item.x || 0) + 1} / span ${item.w}`, gridRow: `${(item.y || 0) + 1} / span ${item.h}` }"
|
|
8
|
+
>
|
|
9
|
+
<BiDataCard v-if="results.get(item.id)" :card="dashboardSnapshotCard(item)" :preview-result="results.get(item.id)" :show-category="false" />
|
|
10
|
+
<el-empty v-else :description="t('common.message.no_data')" />
|
|
11
|
+
</div>
|
|
12
|
+
<el-empty v-if="!schema.cards.length" :description="t('bi.dashboard.empty')" />
|
|
13
|
+
</div>
|
|
14
|
+
</template>
|
|
15
|
+
<script setup lang="ts">
|
|
16
|
+
import { t } from "@liujitcn/kratos-admin-core";
|
|
17
|
+
import type { BiQueryResult } from "../rpc/bi/admin/v1/bi_query";
|
|
18
|
+
import { dashboardSnapshotCard } from "../bi-dashboard-schema";
|
|
19
|
+
import type { DashboardLayout } from "../bi-dashboard-schema";
|
|
20
|
+
import BiDataCard from "./BiDataCard.vue";
|
|
21
|
+
defineProps<{ schema: DashboardLayout; results: Map<string, BiQueryResult | undefined> }>();
|
|
22
|
+
</script>
|
|
23
|
+
<style scoped>
|
|
24
|
+
.bi-dashboard-grid {
|
|
25
|
+
display: grid;
|
|
26
|
+
grid-template-columns: repeat(12, minmax(0, 1fr));
|
|
27
|
+
grid-auto-rows: 80px;
|
|
28
|
+
gap: 12px;
|
|
29
|
+
}
|
|
30
|
+
.bi-dashboard-grid__item {
|
|
31
|
+
min-width: 0;
|
|
32
|
+
min-height: 0;
|
|
33
|
+
}
|
|
34
|
+
.bi-dashboard-grid__item :deep(.bi-data-card) {
|
|
35
|
+
height: 100%;
|
|
36
|
+
}
|
|
37
|
+
.bi-dashboard-grid__item :deep(.bi-data-card__chart) {
|
|
38
|
+
flex: 1;
|
|
39
|
+
min-height: 80px;
|
|
40
|
+
height: auto;
|
|
41
|
+
}
|
|
42
|
+
@media (max-width: 700px) {
|
|
43
|
+
.bi-dashboard-grid {
|
|
44
|
+
grid-template-columns: 1fr;
|
|
45
|
+
grid-auto-rows: auto;
|
|
46
|
+
}
|
|
47
|
+
.bi-dashboard-grid__item {
|
|
48
|
+
grid-column: 1 !important;
|
|
49
|
+
grid-row: auto !important;
|
|
50
|
+
min-height: 360px;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
</style>
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<FormDialog
|
|
3
|
+
ref="dialog"
|
|
4
|
+
:model-value="modelValue"
|
|
5
|
+
:title="t('bi.dashboard.configure_menu')"
|
|
6
|
+
:model="form"
|
|
7
|
+
:fields="fields"
|
|
8
|
+
:rules="rules"
|
|
9
|
+
:confirm-loading="saving"
|
|
10
|
+
:form-props="{ disabled: loading || saving }"
|
|
11
|
+
:close-on-click-modal="!saving"
|
|
12
|
+
@update:model-value="emit('update:modelValue', $event)"
|
|
13
|
+
@confirm="submit"
|
|
14
|
+
@closed="reset"
|
|
15
|
+
>
|
|
16
|
+
<template #i18ns>
|
|
17
|
+
<DynamicI18nEditor v-model="i18nValues" :source="form.title" :maxlength="100" :disabled="loading || saving" />
|
|
18
|
+
</template>
|
|
19
|
+
<template #icon>
|
|
20
|
+
<SelectIcon v-model:icon-value="form.icon" :placeholder="t('system.base.menu.placeholder.icon')" />
|
|
21
|
+
</template>
|
|
22
|
+
</FormDialog>
|
|
23
|
+
</template>
|
|
24
|
+
|
|
25
|
+
<script setup lang="ts">
|
|
26
|
+
import { computed, reactive, ref, watch } from "vue";
|
|
27
|
+
import { t } from "@liujitcn/kratos-admin-core";
|
|
28
|
+
import FormDialog from "@liujitcn/kratos-admin-core/components/Dialog/FormDialog.vue";
|
|
29
|
+
import SelectIcon from "@liujitcn/kratos-admin-core/components/SelectIcon/index.vue";
|
|
30
|
+
import type { ProFormField, ProFormOption } from "@liujitcn/kratos-admin-core/components/ProForm/interface";
|
|
31
|
+
import { defBaseMenuService } from "@liujitcn/kratos-admin-system/api/system/admin/v1/base_menu";
|
|
32
|
+
import { loadEnabledBaseLanguages } from "@liujitcn/kratos-admin-system/api/system/admin/v1/base_language";
|
|
33
|
+
import DynamicI18nEditor from "@liujitcn/kratos-admin-system/components/i18n/DynamicI18nEditor.vue";
|
|
34
|
+
import {
|
|
35
|
+
normalizeDynamicI18ns,
|
|
36
|
+
serializeDynamicI18ns,
|
|
37
|
+
type DynamicI18nRecord,
|
|
38
|
+
type DynamicI18nValue
|
|
39
|
+
} from "@liujitcn/kratos-admin-system/components/i18n/dynamicI18n";
|
|
40
|
+
import type { BaseMenu, BaseMenuForm } from "@liujitcn/kratos-admin-system/rpc/system/admin/v1/base_menu";
|
|
41
|
+
import { BaseMenuType } from "@liujitcn/kratos-admin-system/rpc/system/admin/v1/common";
|
|
42
|
+
import { Status } from "@liujitcn/kratos-admin-system/rpc/common/v1/enum";
|
|
43
|
+
import type { BiDashboard } from "../rpc/bi/admin/v1/bi_dashboard";
|
|
44
|
+
|
|
45
|
+
const props = defineProps<{ modelValue: boolean; dashboard?: BiDashboard }>();
|
|
46
|
+
const emit = defineEmits<{ "update:modelValue": [value: boolean] }>();
|
|
47
|
+
const dialog = ref<InstanceType<typeof FormDialog>>();
|
|
48
|
+
const form = reactive({ title: "", icon: "DataAnalysis", parent_id: undefined as number | undefined });
|
|
49
|
+
const options = ref<ProFormOption[]>([]);
|
|
50
|
+
const existing = ref<BaseMenuForm>();
|
|
51
|
+
const i18nValues = ref<DynamicI18nValue[]>([]);
|
|
52
|
+
const loading = ref(false),
|
|
53
|
+
saving = ref(false);
|
|
54
|
+
let request = 0;
|
|
55
|
+
const fields = computed<ProFormField[]>(() => [
|
|
56
|
+
{
|
|
57
|
+
prop: "title",
|
|
58
|
+
label: t("system.base.menu.field.title"),
|
|
59
|
+
component: "input",
|
|
60
|
+
suffixSlotName: "i18ns",
|
|
61
|
+
props: { maxlength: 100 }
|
|
62
|
+
},
|
|
63
|
+
{ prop: "icon", label: t("system.base.menu.field.icon"), component: "slot", slotName: "icon" },
|
|
64
|
+
{
|
|
65
|
+
prop: "parent_id",
|
|
66
|
+
label: t("bi.dashboard.menu_position"),
|
|
67
|
+
component: "tree-select",
|
|
68
|
+
options: options.value,
|
|
69
|
+
props: { nodeKey: "value", props: { label: "label", children: "children" }, checkStrictly: true, filterable: true }
|
|
70
|
+
}
|
|
71
|
+
]);
|
|
72
|
+
const rules = computed(() => ({
|
|
73
|
+
title: [{ required: true, whitespace: true, message: t("system.base.menu.placeholder.title"), trigger: "blur" }],
|
|
74
|
+
icon: [{ required: true, message: t("system.base.menu.placeholder.icon"), trigger: "change" }],
|
|
75
|
+
parent_id: [{ required: true, message: t("system.base.menu.placeholder.parent"), trigger: "change" }]
|
|
76
|
+
}));
|
|
77
|
+
|
|
78
|
+
/** 加载可放置的管理端目录,并回填当前仪表盘已存在的菜单。 */
|
|
79
|
+
async function load() {
|
|
80
|
+
const current = ++request;
|
|
81
|
+
loading.value = true;
|
|
82
|
+
existing.value = undefined;
|
|
83
|
+
i18nValues.value = [];
|
|
84
|
+
Object.assign(form, { title: props.dashboard?.name || "", icon: "DataAnalysis", parent_id: undefined });
|
|
85
|
+
try {
|
|
86
|
+
await loadEnabledBaseLanguages();
|
|
87
|
+
if (current !== request) return;
|
|
88
|
+
i18nValues.value = normalizeDynamicI18ns(undefined);
|
|
89
|
+
const data = await defBaseMenuService.TreeBaseMenu({ lazy: false });
|
|
90
|
+
if (current !== request) return;
|
|
91
|
+
options.value = folderOptions(data.base_menus || []);
|
|
92
|
+
const queue = [...(data.base_menus || [])];
|
|
93
|
+
for (const item of queue) {
|
|
94
|
+
queue.push(...(item.children || []));
|
|
95
|
+
if (item.name !== `BiDashboard${props.dashboard?.id}` || item.component !== "bi/dashboard/index") continue;
|
|
96
|
+
const value = await defBaseMenuService.GetBaseMenu({ id: item.id });
|
|
97
|
+
if (current !== request) return;
|
|
98
|
+
existing.value = value;
|
|
99
|
+
i18nValues.value = normalizeDynamicI18ns(value.i18ns as DynamicI18nRecord[] | undefined);
|
|
100
|
+
Object.assign(form, {
|
|
101
|
+
title: value.meta?.title || props.dashboard?.name || "",
|
|
102
|
+
icon: value.meta?.icon || "DataAnalysis",
|
|
103
|
+
parent_id: value.parent_id
|
|
104
|
+
});
|
|
105
|
+
break;
|
|
106
|
+
}
|
|
107
|
+
} catch (cause) {
|
|
108
|
+
ElMessage.error(cause instanceof Error ? cause.message : t("bi.query.error"));
|
|
109
|
+
} finally {
|
|
110
|
+
if (current === request) loading.value = false;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** 目录作为唯一可选父级,排除移动端分支和页面、按钮节点。 */
|
|
115
|
+
function folderOptions(items: BaseMenu[]): ProFormOption[] {
|
|
116
|
+
return items
|
|
117
|
+
.filter(item => item.type === BaseMenuType.BASE_MENU_TYPE_FOLDER && item.id !== 99000000)
|
|
118
|
+
.map(item => ({ label: item.meta?.title || item.name, value: item.id, children: folderOptions(item.children || []) }));
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/** 固定仪表盘路由与权限,保存菜单标题、译文、图标和父目录。 */
|
|
122
|
+
async function submit() {
|
|
123
|
+
if (!props.dashboard || loading.value || saving.value || !(await dialog.value?.validate())) return;
|
|
124
|
+
saving.value = true;
|
|
125
|
+
try {
|
|
126
|
+
const payload: BaseMenuForm = {
|
|
127
|
+
id: existing.value?.id || 0,
|
|
128
|
+
parent_id: form.parent_id,
|
|
129
|
+
type: BaseMenuType.BASE_MENU_TYPE_MENU,
|
|
130
|
+
path: `/reports/dashboard/${props.dashboard.id}`,
|
|
131
|
+
name: `BiDashboard${props.dashboard.id}`,
|
|
132
|
+
component: "bi/dashboard/index",
|
|
133
|
+
redirect: "",
|
|
134
|
+
meta: {
|
|
135
|
+
title: form.title,
|
|
136
|
+
icon: form.icon,
|
|
137
|
+
hidden: false,
|
|
138
|
+
always_show: false,
|
|
139
|
+
keep_alive: false,
|
|
140
|
+
full: false,
|
|
141
|
+
affix: false,
|
|
142
|
+
params: [],
|
|
143
|
+
app: undefined
|
|
144
|
+
},
|
|
145
|
+
api: ["/bi.admin.v1.BiDashboardService/GetBiDashboardData"],
|
|
146
|
+
i18ns: serializeDynamicI18ns(i18nValues.value, "base_menu.meta.title", existing.value?.id || 0, form.title),
|
|
147
|
+
sort: existing.value?.sort || 1,
|
|
148
|
+
status: Status.STATUS_ENABLE
|
|
149
|
+
};
|
|
150
|
+
if (payload.id) await defBaseMenuService.UpdateBaseMenu({ base_menu: payload });
|
|
151
|
+
else await defBaseMenuService.CreateBaseMenu({ base_menu: payload });
|
|
152
|
+
ElMessage.success(t("bi.dashboard.menu_saved"));
|
|
153
|
+
emit("update:modelValue", false);
|
|
154
|
+
} catch (cause) {
|
|
155
|
+
ElMessage.error(cause instanceof Error ? cause.message : t("bi.query.error"));
|
|
156
|
+
} finally {
|
|
157
|
+
saving.value = false;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/** 关闭时清空草稿与校验,并丢弃迟到的目录请求。 */
|
|
162
|
+
function reset() {
|
|
163
|
+
request++;
|
|
164
|
+
loading.value = false;
|
|
165
|
+
existing.value = undefined;
|
|
166
|
+
i18nValues.value = [];
|
|
167
|
+
options.value = [];
|
|
168
|
+
Object.assign(form, { title: "", icon: "DataAnalysis", parent_id: undefined });
|
|
169
|
+
dialog.value?.clearValidate();
|
|
170
|
+
}
|
|
171
|
+
watch(
|
|
172
|
+
() => [props.modelValue, props.dashboard?.id],
|
|
173
|
+
() => {
|
|
174
|
+
if (props.modelValue && props.dashboard) void load();
|
|
175
|
+
}
|
|
176
|
+
);
|
|
177
|
+
</script>
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<article class="bi-data-card">
|
|
3
|
+
<header class="bi-data-card__header">
|
|
4
|
+
<div class="bi-data-card__heading">
|
|
5
|
+
<h3 class="bi-data-card__title">
|
|
6
|
+
<el-icon class="bi-data-card__icon"><component :is="icon" /></el-icon>{{ card.name }}
|
|
7
|
+
</h3>
|
|
8
|
+
<div class="bi-data-card__meta">
|
|
9
|
+
<el-tag v-if="showCategory" size="small" effect="plain" type="info">{{ t(`bi.card.category.${card.category || "mine"}`) }}</el-tag>
|
|
10
|
+
<el-select
|
|
11
|
+
v-if="showPeriodFilter"
|
|
12
|
+
:model-value="effectiveRangeDays"
|
|
13
|
+
class="bi-data-card__period"
|
|
14
|
+
size="small"
|
|
15
|
+
:aria-label="t('bi.card.period', { name: card.name })"
|
|
16
|
+
@update:model-value="emit('update:rangeDays', $event)"
|
|
17
|
+
>
|
|
18
|
+
<el-option :value="0" :label="t('bi.card.period.default')" />
|
|
19
|
+
<el-option v-for="days in [7, 30]" :key="days" :value="days" :label="t('bi.card.period.recent_days', { days })" />
|
|
20
|
+
</el-select>
|
|
21
|
+
<span v-if="periodLabel">{{ periodLabel }}</span>
|
|
22
|
+
<el-tag v-if="data?.truncated" size="small" type="warning">{{ t("bi.query.truncated") }}</el-tag>
|
|
23
|
+
</div>
|
|
24
|
+
</div>
|
|
25
|
+
<slot name="actions" />
|
|
26
|
+
</header>
|
|
27
|
+
<div v-loading="loading" class="bi-data-card__chart" :aria-busy="loading">
|
|
28
|
+
<div v-if="error" class="bi-data-card__error" role="alert">
|
|
29
|
+
<span>{{ error }}</span>
|
|
30
|
+
<el-button link type="primary" @click="loadData">{{ t("bi.card.retry") }}</el-button>
|
|
31
|
+
</div>
|
|
32
|
+
<BiCardVisualization v-else-if="data" :card="card" :result="data" />
|
|
33
|
+
<el-empty v-else-if="!loading" :image-size="48" :description="t('common.message.no_data')" />
|
|
34
|
+
</div>
|
|
35
|
+
<div v-if="sourceName" class="bi-data-card__source">
|
|
36
|
+
<el-icon><component :is="sourceIcon" /></el-icon>{{ sourceName }}
|
|
37
|
+
</div>
|
|
38
|
+
<footer v-if="$slots.footer" class="bi-data-card__footer"><slot name="footer" /></footer>
|
|
39
|
+
</article>
|
|
40
|
+
</template>
|
|
41
|
+
|
|
42
|
+
<script setup lang="ts">
|
|
43
|
+
import { computed, onActivated, onBeforeUnmount, onDeactivated, onMounted, ref, watch } from "vue";
|
|
44
|
+
import { t } from "@liujitcn/kratos-admin-core";
|
|
45
|
+
import BiCardVisualization from "./BiCardVisualization.vue";
|
|
46
|
+
import { cardRefreshDelay } from "../card-schema";
|
|
47
|
+
import { defBiCardService } from "../api/bi/admin/v1/bi_card";
|
|
48
|
+
import type { BiCard } from "../rpc/bi/admin/v1/bi_card";
|
|
49
|
+
import type { BiQueryResult } from "../rpc/bi/admin/v1/bi_query";
|
|
50
|
+
|
|
51
|
+
const icon = DataAnalysis;
|
|
52
|
+
const sourceIcon = Coin;
|
|
53
|
+
const props = withDefaults(
|
|
54
|
+
defineProps<{
|
|
55
|
+
card: BiCard;
|
|
56
|
+
sourceName?: string;
|
|
57
|
+
previewResult?: BiQueryResult;
|
|
58
|
+
refreshKey?: number;
|
|
59
|
+
rangeDays?: number;
|
|
60
|
+
showPeriodFilter?: boolean;
|
|
61
|
+
showCategory?: boolean;
|
|
62
|
+
}>(),
|
|
63
|
+
{ sourceName: "", refreshKey: 0, rangeDays: 0, showPeriodFilter: false, showCategory: true }
|
|
64
|
+
);
|
|
65
|
+
const emit = defineEmits<{ "update:rangeDays": [value: number] }>();
|
|
66
|
+
const effectiveRangeDays = computed(() => (props.showPeriodFilter ? props.rangeDays : 0));
|
|
67
|
+
const periodLabel = computed(() => {
|
|
68
|
+
const range = props.card.query?.time_range;
|
|
69
|
+
return !effectiveRangeDays.value && range ? `${range.start.slice(0, 10)} — ${range.end.slice(0, 10)}` : "";
|
|
70
|
+
});
|
|
71
|
+
const result = ref<BiQueryResult>();
|
|
72
|
+
const loading = ref(false);
|
|
73
|
+
const error = ref("");
|
|
74
|
+
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
75
|
+
let active = true;
|
|
76
|
+
let requestID = 0;
|
|
77
|
+
const data = computed(() => props.previewResult ?? result.value);
|
|
78
|
+
|
|
79
|
+
/** 按当前卡片周期加载数据,关闭或切换卡片后丢弃迟到响应。 */
|
|
80
|
+
async function loadData() {
|
|
81
|
+
clearTimeout(timer);
|
|
82
|
+
if (!active || props.card.id === 0 || props.previewResult) return;
|
|
83
|
+
const current = ++requestID;
|
|
84
|
+
loading.value = true;
|
|
85
|
+
error.value = "";
|
|
86
|
+
try {
|
|
87
|
+
const loadedResult = await defBiCardService.GetBiCardData({ id: props.card.id, range_days: effectiveRangeDays.value });
|
|
88
|
+
if (current === requestID) result.value = loadedResult;
|
|
89
|
+
} catch (cause) {
|
|
90
|
+
if (current === requestID) {
|
|
91
|
+
error.value = cause instanceof Error ? cause.message : t("bi.query.error");
|
|
92
|
+
result.value = undefined;
|
|
93
|
+
}
|
|
94
|
+
} finally {
|
|
95
|
+
if (current === requestID) {
|
|
96
|
+
loading.value = false;
|
|
97
|
+
scheduleRefresh();
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** 隐藏标签页时延后自动取数,避免后台持续查询。 */
|
|
103
|
+
function scheduleRefresh() {
|
|
104
|
+
clearTimeout(timer);
|
|
105
|
+
if (active && props.card.refresh_seconds > 0)
|
|
106
|
+
timer = setTimeout(() => {
|
|
107
|
+
if (document.hidden) scheduleRefresh();
|
|
108
|
+
else void loadData();
|
|
109
|
+
}, cardRefreshDelay(props.card.refresh_seconds));
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** 标签页重新可见后补一次刷新,避免错过每日刷新时间。 */
|
|
113
|
+
function handleVisibility() {
|
|
114
|
+
if (active && !document.hidden && props.card.refresh_seconds > 0 && !loading.value) void loadData();
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** 停止非活动页面的定时器与响应回填。 */
|
|
118
|
+
function stop() {
|
|
119
|
+
active = false;
|
|
120
|
+
requestID++;
|
|
121
|
+
loading.value = false;
|
|
122
|
+
clearTimeout(timer);
|
|
123
|
+
}
|
|
124
|
+
watch(
|
|
125
|
+
() => [props.card.id, props.card.updated_at, props.refreshKey, effectiveRangeDays.value],
|
|
126
|
+
() => {
|
|
127
|
+
result.value = undefined;
|
|
128
|
+
void loadData();
|
|
129
|
+
},
|
|
130
|
+
{ immediate: true }
|
|
131
|
+
);
|
|
132
|
+
onActivated(() => {
|
|
133
|
+
if (!active) {
|
|
134
|
+
active = true;
|
|
135
|
+
void loadData();
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
onDeactivated(stop);
|
|
139
|
+
onMounted(() => document.addEventListener("visibilitychange", handleVisibility));
|
|
140
|
+
onBeforeUnmount(() => {
|
|
141
|
+
stop();
|
|
142
|
+
document.removeEventListener("visibilitychange", handleVisibility);
|
|
143
|
+
});
|
|
144
|
+
</script>
|
|
145
|
+
|
|
146
|
+
<style scoped>
|
|
147
|
+
.bi-data-card {
|
|
148
|
+
display: flex;
|
|
149
|
+
min-width: 0;
|
|
150
|
+
flex-direction: column;
|
|
151
|
+
border: 1px solid var(--el-border-color-light);
|
|
152
|
+
border-radius: var(--admin-page-radius);
|
|
153
|
+
background: var(--el-bg-color);
|
|
154
|
+
}
|
|
155
|
+
.bi-data-card__header {
|
|
156
|
+
display: flex;
|
|
157
|
+
align-items: flex-start;
|
|
158
|
+
justify-content: space-between;
|
|
159
|
+
gap: 8px;
|
|
160
|
+
padding: 16px 16px 0;
|
|
161
|
+
}
|
|
162
|
+
.bi-data-card__heading {
|
|
163
|
+
min-width: 0;
|
|
164
|
+
}
|
|
165
|
+
.bi-data-card__title {
|
|
166
|
+
display: flex;
|
|
167
|
+
align-items: center;
|
|
168
|
+
gap: 8px;
|
|
169
|
+
margin: 0;
|
|
170
|
+
color: var(--el-text-color-primary);
|
|
171
|
+
overflow-wrap: anywhere;
|
|
172
|
+
font: inherit;
|
|
173
|
+
font-size: 14px;
|
|
174
|
+
font-weight: 500;
|
|
175
|
+
}
|
|
176
|
+
.bi-data-card__meta {
|
|
177
|
+
display: flex;
|
|
178
|
+
flex-wrap: wrap;
|
|
179
|
+
align-items: center;
|
|
180
|
+
gap: 8px;
|
|
181
|
+
margin-top: 8px;
|
|
182
|
+
color: var(--el-text-color-secondary);
|
|
183
|
+
font-size: 12px;
|
|
184
|
+
}
|
|
185
|
+
.bi-data-card__chart {
|
|
186
|
+
box-sizing: border-box;
|
|
187
|
+
height: 280px;
|
|
188
|
+
padding: 12px 16px;
|
|
189
|
+
}
|
|
190
|
+
.bi-data-card__period {
|
|
191
|
+
width: 130px;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
.bi-data-card__error {
|
|
195
|
+
display: flex;
|
|
196
|
+
height: 100%;
|
|
197
|
+
flex-direction: column;
|
|
198
|
+
align-items: center;
|
|
199
|
+
justify-content: center;
|
|
200
|
+
gap: 8px;
|
|
201
|
+
color: var(--el-text-color-secondary);
|
|
202
|
+
font-size: 12px;
|
|
203
|
+
overflow-wrap: anywhere;
|
|
204
|
+
}
|
|
205
|
+
.bi-data-card__footer {
|
|
206
|
+
display: flex;
|
|
207
|
+
align-items: center;
|
|
208
|
+
justify-content: space-between;
|
|
209
|
+
flex-wrap: wrap;
|
|
210
|
+
gap: 8px;
|
|
211
|
+
padding: 12px 16px;
|
|
212
|
+
border-top: 1px solid var(--el-border-color-lighter);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
.bi-data-card__source {
|
|
216
|
+
display: flex;
|
|
217
|
+
align-items: center;
|
|
218
|
+
gap: 5px;
|
|
219
|
+
padding: 0 16px 12px;
|
|
220
|
+
color: var(--el-text-color-secondary);
|
|
221
|
+
font-size: 11px;
|
|
222
|
+
}
|
|
223
|
+
.bi-data-card__icon {
|
|
224
|
+
flex: none;
|
|
225
|
+
width: 27px;
|
|
226
|
+
height: 27px;
|
|
227
|
+
color: var(--el-color-primary);
|
|
228
|
+
background: var(--el-color-primary-light-9);
|
|
229
|
+
border-radius: var(--admin-page-radius);
|
|
230
|
+
}
|
|
231
|
+
</style>
|