feat: add widget and standard config

This commit is contained in:
Qiuxia Fan
2022-01-12 15:15:16 +08:00
parent 16085bb56f
commit 8e0bf6357e
6 changed files with 99 additions and 31 deletions

View File

@@ -15,7 +15,14 @@ limitations under the License. -->
<template>
<div class="widget-config flex-v">
<div class="graph">
<div class="header">{{ states.widget.title }}</div>
<div class="header">
<span>{{ states.widget.title }}</span>
<div class="tips">
<el-tooltip :content="states.widget.tips">
<Icon iconName="info_outline" size="sm" />
</el-tooltip>
</div>
</div>
<div class="render-chart">
<component
:is="states.chartType"
@@ -80,7 +87,10 @@ limitations under the License. -->
/>
</el-collapse-item>
<el-collapse-item :title="t('standardOptions')" name="5">
<StandardOptions />
<StandardOptions
:config="states.standard"
@update="updateStandardOptions"
/>
</el-collapse-item>
</el-collapse>
</div>
@@ -107,7 +117,7 @@ import {
DefaultGraphConfig,
} from "../data";
import { Option } from "@/types/app";
import { WidgetConfig, GraphConfig } from "@/types/dashboard";
import { WidgetConfig, GraphConfig, StandardConfig } from "@/types/dashboard";
import graphs from "../graphs";
import configs from "./graph-styles";
import WidgetOptions from "./WidgetOptions.vue";
@@ -138,6 +148,7 @@ export default defineComponent({
index: string;
graph: GraphConfig;
widget: WidgetConfig | any;
standard: StandardConfig;
}>({
metrics: selectedGrid.metrics || [],
valueTypes: [],
@@ -148,10 +159,8 @@ export default defineComponent({
source: {},
index: selectedGrid.i,
graph: {},
widget: {
tips: selectedGrid.widget.tips,
title: selectedGrid.widget.title,
},
widget: selectedGrid.widget,
standard: selectedGrid.standard,
});
if (states.metrics[0]) {
queryMetricType(states.metrics[0]);
@@ -210,21 +219,27 @@ export default defineComponent({
];
const configHeight = document.documentElement.clientHeight - 520;
function updateWidgetOptions(param: { label: string; value: string }) {
if (states.widget[param.label] === undefined) {
return;
}
states.widget[param.label] = param.value;
function updateWidgetOptions(param: { [key: string]: unknown }) {
states.widget = {
...states.widget,
...param,
};
}
function updateGraphOptions(param: { label: string; value: unknown }) {
console.log(param);
function updateGraphOptions(param: { [key: string]: unknown }) {
states.graph = {
...states.graph,
...param,
};
}
function updateStandardOptions(param: { [key: string]: unknown }) {
states.standard = {
...states.standard,
...param,
};
}
async function queryMetrics() {
const json = await dashboardStore.fetchMetricValue(
dashboardStore.selectedGrid
@@ -284,6 +299,7 @@ export default defineComponent({
updateWidgetOptions,
configHeight,
updateGraphOptions,
updateStandardOptions,
applyConfig,
loading,
};
@@ -311,6 +327,13 @@ export default defineComponent({
text-align: center;
background-color: aliceblue;
font-size: 12px;
position: relative;
}
.tips {
position: absolute;
right: 5px;
top: 0;
}
.render-chart {

View File

@@ -20,6 +20,7 @@ limitations under the License. -->
v-model="state.unit"
size="mini"
placeholder="Please input Unit"
@change="changeStandardOpt({ unit: state.unit })"
/>
</div>
<div class="item">
@@ -30,6 +31,7 @@ limitations under the License. -->
size="mini"
placeholder="Select a sort order"
class="selector"
@change="changeStandardOpt({ sortOrder: state.sortOrder })"
/>
</div>
<div class="item">
@@ -39,6 +41,7 @@ limitations under the License. -->
v-model="state.max"
size="mini"
placeholder="auto"
@change="changeStandardOpt({ max: state.max })"
/>
</div>
<div class="item">
@@ -48,6 +51,7 @@ limitations under the License. -->
v-model="state.min"
size="mini"
placeholder="auto"
@change="changeStandardOpt({ min: state.min })"
/>
</div>
<div class="item">
@@ -57,6 +61,7 @@ limitations under the License. -->
v-model="state.plus"
size="mini"
placeholder="none"
@change="changeStandardOpt({ plus: state.plus })"
/>
</div>
<div class="item">
@@ -66,6 +71,7 @@ limitations under the License. -->
v-model="state.minus"
size="mini"
placeholder="none"
@change="changeStandardOpt({ minus: state.minus })"
/>
</div>
<div class="item">
@@ -75,6 +81,7 @@ limitations under the License. -->
v-model="state.multiply"
size="mini"
placeholder="none"
@change="changeStandardOpt({ multiply: state.multiply })"
/>
</div>
<div class="item">
@@ -84,6 +91,7 @@ limitations under the License. -->
v-model="state.divide"
size="mini"
placeholder="none"
@change="changeStandardOpt({ divide: state.divide })"
/>
</div>
<div class="item">
@@ -93,6 +101,7 @@ limitations under the License. -->
v-model="state.milliseconds"
size="mini"
placeholder="none"
@change="changeStandardOpt({ milliseconds: state.milliseconds })"
/>
</div>
<div class="item">
@@ -102,17 +111,27 @@ limitations under the License. -->
v-model="state.seconds"
size="mini"
placeholder="none"
@change="changeStandardOpt({ seconds: state.seconds })"
/>
</div>
</template>
<script lang="ts" setup>
import { reactive } from "vue";
import { reactive, defineProps, defineEmits } from "vue";
import { useI18n } from "vue-i18n";
import { SortOrder } from "../data";
import { StandardConfig } from "@/types/dashboard";
import type { PropType } from "vue";
const props = defineProps({
config: {
type: Object as PropType<StandardConfig>,
default: () => ({ unit: "", sortOrder: "DES" }),
},
});
const emits = defineEmits(["update"]);
const { t } = useI18n();
const state = reactive({
unit: "",
unit: props.config.unit,
max: "",
min: "",
plus: "",
@@ -121,8 +140,12 @@ const state = reactive({
divide: "",
milliseconds: "",
seconds: "",
sortOrder: "DES",
sortOrder: props.config.sortOrder,
});
function changeStandardOpt(param: { [key: string]: unknown }) {
emits("update", param);
}
</script>
<style lang="scss" scoped>
.label {

View File

@@ -20,40 +20,39 @@ limitations under the License. -->
v-model="title"
size="mini"
placeholder="Please input title"
@change="updateTitle"
@change="updateWidgetConfig({ title })"
/>
</div>
<div class="item">
<span class="label">{{ t("tooltipsContent") }}</span>
<el-input
class="input"
v-model="tooltip"
v-model="tips"
size="mini"
placeholder="Please input tips"
@change="updateTips"
@change="updateWidgetConfig({ tips })"
/>
</div>
</template>
<script lang="ts" setup>
import { ref, defineEmits, defineProps } from "vue";
import { useI18n } from "vue-i18n";
import { WidgetConfig } from "@/types/dashboard";
import type { PropType } from "vue";
defineProps({
const props = defineProps({
config: {
type: Object,
type: Object as PropType<WidgetConfig>,
default: () => ({ title: "", tooltips: "" }),
},
});
const emits = defineEmits(["update"]);
const { t } = useI18n();
const title = ref<string>("");
const tooltip = ref<string>("");
const title = ref<string>(props.config.title);
const tips = ref<string>(props.config.tips);
function updateTitle(value: string) {
emits("update", { value, label: "title" });
}
function updateTips(value: string) {
emits("update", { value, label: "tips" });
function updateWidgetConfig(param: { [key: string]: unknown }) {
emits("update", param);
}
</script>
<style lang="scss" scoped>

View File

@@ -25,7 +25,6 @@ export const ChartTypes = [
{ label: "Table", value: "Table" },
{ label: "Endpoint List", value: "EndpointList" },
{ label: "Instance List", value: "InstanceList" },
// { label: "Image", value: "Image" },
];
export const DefaultGraphConfig: { [key: string]: any } = {
Bar: {