fix: calculate widget index and init metrics config (#41)

This commit is contained in:
Fine0830 2022-03-27 23:45:28 +08:00 committed by GitHub
parent d733594804
commit 2167b4afd5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 16 additions and 14 deletions

View File

@ -76,9 +76,10 @@ export const dashboardStore = defineStore({
this.currentDashboard = item; this.currentDashboard = item;
}, },
addControl(type: string) { addControl(type: string) {
const arr = this.layout.map((d: any) => Number(d.i));
const newItem: LayoutConfig = { const newItem: LayoutConfig = {
...NewControl, ...NewControl,
i: String(this.layout.length), i: String(Math.max(...arr) + 1),
type, type,
metricTypes: [""], metricTypes: [""],
metrics: [""], metrics: [""],
@ -146,9 +147,10 @@ export const dashboardStore = defineStore({
} }
const tabIndex = this.layout[idx].activedTabIndex || 0; const tabIndex = this.layout[idx].activedTabIndex || 0;
const { children } = this.layout[idx].children[tabIndex]; const { children } = this.layout[idx].children[tabIndex];
const arr = children.map((d: any) => Number(d.i));
const newItem: LayoutConfig = { const newItem: LayoutConfig = {
...NewControl, ...NewControl,
i: String(children.length), i: String(Math.max(...arr) + 1),
type, type,
metricTypes: [""], metricTypes: [""],
metrics: [""], metrics: [""],

View File

@ -17,9 +17,6 @@ limitations under the License. -->
<div class="graph" v-loading="loading"> <div class="graph" v-loading="loading">
<div class="header"> <div class="header">
<span>{{ dashboardStore.selectedGrid.widget.title }}</span> <span>{{ dashboardStore.selectedGrid.widget.title }}</span>
<span v-show="dashboardStore.selectedGrid.standard.unit" class="unit">
({{ dashboardStore.selectedGrid.standard.unit }})
</span>
<div class="tips" v-show="dashboardStore.selectedGrid.widget.tips"> <div class="tips" v-show="dashboardStore.selectedGrid.widget.tips">
<el-tooltip :content="dashboardStore.selectedGrid.widget.tips"> <el-tooltip :content="dashboardStore.selectedGrid.widget.tips">
<Icon iconName="info_outline" size="sm" /> <Icon iconName="info_outline" size="sm" />

View File

@ -159,8 +159,8 @@ states.visTypes = setVisTypes();
setDashboards(); setDashboards();
setMetricType(); setMetricType();
async function setMetricType() { async function setMetricType(chart?: any) {
const { graph } = dashboardStore.selectedGrid; const graph = chart || dashboardStore.selectedGrid.graph;
const json = await dashboardStore.fetchMetricList(); const json = await dashboardStore.fetchMetricList();
if (json.errors) { if (json.errors) {
ElMessage.error(json.errors); ElMessage.error(json.errors);
@ -203,6 +203,7 @@ async function setMetricType() {
...dashboardStore.selectedGrid, ...dashboardStore.selectedGrid,
metrics: states.metrics, metrics: states.metrics,
metricTypes: states.metricTypes, metricTypes: states.metricTypes,
graph,
}); });
states.metricTypeList = []; states.metricTypeList = [];
for (const metric of metrics) { for (const metric of metrics) {
@ -266,7 +267,6 @@ function setVisTypes() {
function changeChartType(item: Option) { function changeChartType(item: Option) {
const graph = DefaultGraphConfig[item.value]; const graph = DefaultGraphConfig[item.value];
dashboardStore.selectWidget({ ...dashboardStore.selectedGrid, graph });
states.isList = ListChartTypes.includes(graph.type); states.isList = ListChartTypes.includes(graph.type);
if (states.isList) { if (states.isList) {
dashboardStore.selectWidget({ dashboardStore.selectWidget({
@ -278,7 +278,7 @@ function changeChartType(item: Option) {
states.metricTypes = [""]; states.metricTypes = [""];
defaultLen.value = 5; defaultLen.value = 5;
} }
setMetricType(); setMetricType(graph);
setDashboards(); setDashboards();
states.dashboardName = ""; states.dashboardName = "";
defaultLen.value = 10; defaultLen.value = 10;

View File

@ -71,7 +71,7 @@ limitations under the License. -->
</div> </div>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { ref } from "vue"; import { ref, watch } from "vue";
import type { PropType } from "vue"; import type { PropType } from "vue";
import { useI18n } from "vue-i18n"; import { useI18n } from "vue-i18n";
import { SortOrder, CalculationOpts } from "../../../data"; import { SortOrder, CalculationOpts } from "../../../data";
@ -104,6 +104,12 @@ function changeConfigs(index: number, param: { [key: string]: string }) {
}); });
emit("update"); emit("update");
} }
watch(
() => props.currentMetricConfig,
() => {
currentMetric.value = props.currentMetricConfig;
}
);
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.config-panel { .config-panel {

View File

@ -19,9 +19,6 @@ limitations under the License. -->
<span> <span>
{{ data.widget?.title || "" }} {{ data.widget?.title || "" }}
</span> </span>
<span class="unit" v-show="data.standard?.unit">
({{ data.standard?.unit }})
</span>
</div> </div>
<div> <div>
<el-tooltip :content="data.widget?.tips"> <el-tooltip :content="data.widget?.tips">

View File

@ -67,7 +67,7 @@ export const DefaultGraphConfig: { [key: string]: any } = {
type: "Card", type: "Card",
fontSize: 14, fontSize: 14,
textAlign: "center", textAlign: "center",
showUint: true, showUnit: true,
}, },
Table: { Table: {
type: "Table", type: "Table",