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
6 changed files with 16 additions and 14 deletions

View File

@@ -17,9 +17,6 @@ limitations under the License. -->
<div class="graph" v-loading="loading">
<div class="header">
<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">
<el-tooltip :content="dashboardStore.selectedGrid.widget.tips">
<Icon iconName="info_outline" size="sm" />

View File

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

View File

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

View File

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

View File

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