diff --git a/src/components/Graph.vue b/src/components/Graph.vue index bdc0dfb7..e70b7a1d 100644 --- a/src/components/Graph.vue +++ b/src/components/Graph.vue @@ -38,7 +38,7 @@ const props = defineProps({ onMounted(async () => { await setOptions(props.option); - addResizeListener(unref(chartRef), resize); + chartRef.value && addResizeListener(unref(chartRef), resize); setTimeout(() => { const instance = getInstance(); diff --git a/src/components/Selector.vue b/src/components/Selector.vue index b6dd34c7..908b2f65 100644 --- a/src/components/Selector.vue +++ b/src/components/Selector.vue @@ -22,6 +22,7 @@ limitations under the License. --> :multiple="multiple" :disabled="disabled" :style="{ borderRadius }" + :clearable="clearable" > (props.value); diff --git a/src/hooks/useEcharts.ts b/src/hooks/useEcharts.ts index 16b505b2..63cea634 100644 --- a/src/hooks/useEcharts.ts +++ b/src/hooks/useEcharts.ts @@ -96,6 +96,7 @@ export function useECharts( } function setOptions(options: ECOption, clear = true) { + console.log(options); cacheOptions.value = options; if (unref(elRef)?.offsetHeight === 0) { useTimeoutFn(() => { diff --git a/src/views/dashboard/configuration/Widget.vue b/src/views/dashboard/configuration/Widget.vue index e3f45822..70ccd038 100644 --- a/src/views/dashboard/configuration/Widget.vue +++ b/src/views/dashboard/configuration/Widget.vue @@ -37,8 +37,9 @@ limitations under the License. --> metrics: dashboardStore.selectedGrid.metrics, metricTypes: dashboardStore.selectedGrid.metricTypes, standard: dashboardStore.selectedGrid.standard, - isEdit: true, }" + :isEdit="isEdit" + @changeOpt="setStatus" />
{{ t("noData") }} @@ -51,7 +52,11 @@ limitations under the License. --> :style="{ '--el-collapse-header-font-size': '15px' }" > - + @@ -85,6 +90,7 @@ import configs from "./widget/graph-styles"; import WidgetOptions from "./widget/WidgetOptions.vue"; import StandardOptions from "./widget/StandardOptions.vue"; import MetricOptions from "./widget/MetricOptions.vue"; +import { ListChartTypes } from "../data"; export default defineComponent({ name: "ConfigEdit", @@ -101,6 +107,7 @@ export default defineComponent({ const dashboardStore = useDashboardStore(); const appStoreWithOut = useAppStoreWithOut(); const loading = ref(false); + const isEdit = ref(false); const states = reactive<{ activeNames: string; source: unknown; @@ -123,8 +130,13 @@ export default defineComponent({ } function applyConfig() { - dashboardStore.setConfigs(dashboardStore.selectedGrid); dashboardStore.setConfigPanel(false); + setStatus(true); + dashboardStore.setConfigs(dashboardStore.selectedGrid); + } + + function setStatus(p: boolean) { + isEdit.value = p; } function cancelConfig() { @@ -143,6 +155,8 @@ export default defineComponent({ cancelConfig, getSource, setLoading, + setStatus, + isEdit, }; }, }); diff --git a/src/views/dashboard/configuration/widget/MetricOptions.vue b/src/views/dashboard/configuration/widget/MetricOptions.vue index 8df2ae8d..9def5744 100644 --- a/src/views/dashboard/configuration/widget/MetricOptions.vue +++ b/src/views/dashboard/configuration/widget/MetricOptions.vue @@ -22,6 +22,7 @@ limitations under the License. --> placeholder="Please select a dashboard name" @change="changeDashboard" class="selectors" + :clearable="true" />
{{ t("metrics") }}
@@ -63,7 +64,6 @@ limitations under the License. --> /> ({ metrics: metrics && metrics.length ? metrics : [""], metricTypes: metricTypes && metricTypes.length ? metricTypes : [""], @@ -125,11 +125,11 @@ const states = reactive<{ isList: false, metricList: [], dashboardName: graph.dashboardName, - dashboardList: [], + dashboardList: [{ label: "", value: "" }], }); states.isList = ListChartTypes.includes(graph.type); -const defaultLen = ref(states.isList ? 5 : 10); +const defaultLen = ref(states.isList ? 5 : 20); states.visTypes = setVisTypes(); setDashboards(); @@ -197,7 +197,7 @@ async function setMetricType() { function setDashboards() { const { graph } = dashboardStore.selectedGrid; const list = JSON.parse(sessionStorage.getItem("dashboards") || "[]"); - states.dashboardList = list.reduce( + const arr = list.reduce( ( prev: (DashboardItem & { label: string; value: string })[], d: DashboardItem @@ -219,6 +219,8 @@ function setDashboards() { }, [] ); + + states.dashboardList = arr.length ? arr : [{ label: "", value: "" }]; } function setVisTypes() { @@ -281,6 +283,7 @@ function changeMetrics( ...{ metricTypes: states.metricTypes, metrics: states.metrics }, }); if (states.isList) { + emit("changeOpt", true); return; } queryMetrics(); @@ -311,6 +314,7 @@ function changeMetricType(index: number, opt: Option[] | any) { ...{ metricTypes: states.metricTypes }, }); if (states.isList) { + emit("changeOpt", true); return; } queryMetrics(); @@ -338,7 +342,11 @@ async function queryMetrics() { } function changeDashboard(opt: any) { - states.dashboardName = opt[0].value; + if (!opt[0]) { + states.dashboardName = ""; + } else { + states.dashboardName = opt[0].value; + } const graph = { ...dashboardStore.selectedGrid.graph, dashboardName: states.dashboardName, @@ -358,6 +366,11 @@ function addMetric() { states.metricTypes.push(""); } function deleteMetric(index: number) { + if (states.metrics.length === 1) { + states.metrics = [""]; + states.metricTypes = [""]; + return; + } states.metrics.splice(index, 1); states.metricTypes.splice(index, 1); } diff --git a/src/views/dashboard/graphs/EndpointList.vue b/src/views/dashboard/graphs/EndpointList.vue index 53893da4..d1ac24be 100644 --- a/src/views/dashboard/graphs/EndpointList.vue +++ b/src/views/dashboard/graphs/EndpointList.vue @@ -93,7 +93,7 @@ import { EntityType } from "../data"; import router from "@/router"; import getDashboard from "@/hooks/useDashboardsSession"; -/*global defineProps */ +/*global defineProps, defineEmits */ const props = defineProps({ data: { type: Object, @@ -104,14 +104,14 @@ const props = defineProps({ i: string; metrics: string[]; metricTypes: string[]; - isEdit: boolean; } >, default: () => ({ dashboardName: "", fontSize: 12, i: "" }), }, intervalTime: { type: Array as PropType, default: () => [] }, - needQuery: { type: Boolean, default: false }, + isEdit: { type: Boolean, default: false }, }); +const emit = defineEmits(["changeOpt"]); const selectorStore = useSelectorStore(); const dashboardStore = useDashboardStore(); const chartLoading = ref(false); @@ -135,12 +135,12 @@ async function queryEndpoints(limit?: number) { return; } endpoints.value = selectorStore.pods.splice(0, pageSize); - if (!endpoints.value.length || props.config.isEdit) { - return; - } await queryEndpointMetrics(endpoints.value); } async function queryEndpointMetrics(currentPods: Endpoint[]) { + if (!currentPods.length) { + return; + } const metrics = props.config.metrics.filter((d: string) => d); if (metrics.length && metrics[0]) { @@ -186,11 +186,9 @@ async function searchList() { } watch( () => [props.config.metricTypes, props.config.metrics], - () => { - if (!endpoints.value.length) { - return; - } - queryEndpointMetrics(endpoints.value); + async () => { + await queryEndpointMetrics(endpoints.value); + emit("changeOpt", false); } ); watch( diff --git a/src/views/dashboard/graphs/InstanceList.vue b/src/views/dashboard/graphs/InstanceList.vue index d2466882..c6bf8366 100644 --- a/src/views/dashboard/graphs/InstanceList.vue +++ b/src/views/dashboard/graphs/InstanceList.vue @@ -158,6 +158,9 @@ async function queryInstance() { } async function queryInstanceMetrics(currentInstances: Instance[]) { + if (!instances.value.length) { + return; + } const { metrics } = props.config; if (metrics.length && metrics[0]) { @@ -209,9 +212,6 @@ function searchList() { watch( () => [props.config.metricTypes, props.config.metrics], () => { - if (!instances.value.length) { - return; - } queryInstanceMetrics(instances.value); } );