diff --git a/src/hooks/useProcessor.ts b/src/hooks/useProcessor.ts index c885373b..8dad9179 100644 --- a/src/hooks/useProcessor.ts +++ b/src/hooks/useProcessor.ts @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { RespFields, MetricQueryTypes, CalculationType } from "./data"; +import { RespFields, MetricQueryTypes } from "./data"; import { ElMessage } from "element-plus"; import { useDashboardStore } from "@/store/modules/dashboard"; import { useSelectorStore } from "@/store/modules/selectors"; @@ -186,28 +186,6 @@ export function useSourceProcessor( return source; } -function aggregation(json: { - data: number; - type: string; - aggregationNum: number; -}) { - if (isNaN(json.aggregationNum)) { - return json.data; - } - if (json.type === CalculationType.Plus) { - return json.data + json.aggregationNum; - } - if (json.type === CalculationType.Minus) { - return json.data - json.aggregationNum; - } - if (json.type === CalculationType.Multiplication) { - return json.data * json.aggregationNum; - } - if (json.type === CalculationType.Division) { - return json.data / json.aggregationNum; - } - return json.data; -} export function useQueryPodsMetrics( pods: Array, @@ -258,10 +236,14 @@ export function usePodsSource( const data = pods.map((d: Instance | any, idx: number) => { config.metrics.map((name: string, index: number) => { const key = name + idx + index; - - d[name] = resp.data[key].values.values.map( - (d: { value: number }) => d.value - ); + if (config.metricTypes[index] === MetricQueryTypes.ReadMetricsValue) { + d[name] = resp.data[key]; + } + if (config.metricTypes[index] === MetricQueryTypes.ReadMetricsValues) { + d[name] = resp.data[key].values.values.map( + (d: { value: number }) => d.value + ); + } }); return d; diff --git a/src/store/modules/dashboard.ts b/src/store/modules/dashboard.ts index aad67347..47fc4a71 100644 --- a/src/store/modules/dashboard.ts +++ b/src/store/modules/dashboard.ts @@ -57,6 +57,8 @@ export const dashboardStore = defineStore({ ...NewControl, i: String(this.layout.length), type, + metricTypes: [""], + metrics: [""], }; if (type === "Tab") { newWidget.h = 24; diff --git a/src/store/modules/selectors.ts b/src/store/modules/selectors.ts index 7b1314a2..fe8aa820 100644 --- a/src/store/modules/selectors.ts +++ b/src/store/modules/selectors.ts @@ -62,7 +62,6 @@ export const selectorStore = defineStore({ if (!res.data.errors) { this.services = res.data.data.services || []; - this.currentService = this.services.length ? this.services[0] : null; } return res.data; }, @@ -79,7 +78,6 @@ export const selectorStore = defineStore({ }); if (!res.data.errors) { this.pods = res.data.data.pods || []; - this.currentPod = this.pods.length ? this.pods[0] : null; } return res.data; }, @@ -104,7 +102,6 @@ export const selectorStore = defineStore({ }); if (!res.data.errors) { this.pods = res.data.data.pods || []; - this.currentPod = this.pods.length ? this.pods[0] : null; } return res.data; }, diff --git a/src/types/dashboard.ts b/src/types/dashboard.ts index 2735b9e3..e8b27db9 100644 --- a/src/types/dashboard.ts +++ b/src/types/dashboard.ts @@ -77,7 +77,8 @@ export interface AreaConfig { export interface CardConfig { type?: string; fontSize?: number; - showUint: boolean; + showUint?: boolean; + textAlign?: "center" | "right" | "left"; } export interface TableConfig { diff --git a/src/views/dashboard/configuration/ConfigEdit.vue b/src/views/dashboard/configuration/ConfigEdit.vue index 0ae6fdea..5c5e5f63 100644 --- a/src/views/dashboard/configuration/ConfigEdit.vue +++ b/src/views/dashboard/configuration/ConfigEdit.vue @@ -28,7 +28,12 @@ limitations under the License. --> :is="dashboardStore.selectedGrid.graph.type" :intervalTime="appStoreWithOut.intervalTime" :data="states.source" - :config="dashboardStore.selectedGrid.graph" + :config="{ + ...dashboardStore.selectedGrid.graph, + i: dashboardStore.selectedGrid.i, + metrics: dashboardStore.selectedGrid.metrics, + metricTypes: dashboardStore.selectedGrid.metricTypes, + }" />
{{ t("noData") }} @@ -114,7 +119,6 @@ export default defineComponent({ function applyConfig() { dashboardStore.setConfigs(dashboardStore.selectedGrid); dashboardStore.setConfigPanel(false); - dashboardStore.selectWidget(null); } return { diff --git a/src/views/dashboard/configuration/MetricOptions.vue b/src/views/dashboard/configuration/MetricOptions.vue index 7473fc4d..15ce0d57 100644 --- a/src/views/dashboard/configuration/MetricOptions.vue +++ b/src/views/dashboard/configuration/MetricOptions.vue @@ -155,7 +155,7 @@ async function setMetricType(catalog?: string) { function setVisTypes() { let graphs = []; if (dashboardStore.entity === EntityType[0].value) { - graphs = ChartTypes.filter((d: Option) => d.value !== ChartTypes[8].value); + graphs = ChartTypes.filter((d: Option) => d.value !== ChartTypes[7].value); } else if (dashboardStore.entity === EntityType[1].value) { graphs = ChartTypes.filter( (d: Option) => !PodsChartTypes.includes(d.value) @@ -188,7 +188,7 @@ function changeChartType(item: Option) { EndpointList: EntityType[2].value, ServiceList: EntityType[0].value, }; - if (catalog[graph.type] || dashboardStore.entity) { + if (catalog[graph.type]) { setMetricType(catalog[graph.type]); } } @@ -212,6 +212,9 @@ function changeMetrics(index: number, arr: (Option & { type: string })[]) { ...dashboardStore.selectedGrid, ...{ metricTypes: states.metricTypes, metrics: states.metrics }, }); + if (states.isTable) { + return; + } queryMetrics(); } @@ -238,6 +241,9 @@ function changeMetricType(index: number, opt: Option[]) { ...dashboardStore.selectedGrid, ...{ metricTypes: states.metricTypes }, }); + if (states.isTable) { + return; + } queryMetrics(); } async function queryMetrics() { diff --git a/src/views/dashboard/controls/Image.vue b/src/views/dashboard/controls/Image.vue deleted file mode 100644 index 777e8284..00000000 --- a/src/views/dashboard/controls/Image.vue +++ /dev/null @@ -1,35 +0,0 @@ - - - diff --git a/src/views/dashboard/controls/Widget.vue b/src/views/dashboard/controls/Widget.vue index 5858e042..9599e42b 100644 --- a/src/views/dashboard/controls/Widget.vue +++ b/src/views/dashboard/controls/Widget.vue @@ -51,6 +51,7 @@ limitations under the License. --> ...data.graph, metrics: data.metrics, metricTypes: data.metricTypes, + i: data.i, }" :standard="data.standard" /> @@ -69,6 +70,7 @@ import { useSelectorStore } from "@/store/modules/selectors"; import graphs from "../graphs"; import { useI18n } from "vue-i18n"; import { useQueryProcessor, useSourceProcessor } from "@/hooks/useProcessor"; +import { TableChartTypes } from "../data"; const props = { data: { @@ -83,7 +85,6 @@ export default defineComponent({ props, setup(props) { const { t } = useI18n(); - const params = useRoute().params; const loading = ref(false); const state = reactive<{ source: { [key: string]: unknown } }>({ source: {}, @@ -93,10 +94,6 @@ export default defineComponent({ const dashboardStore = useDashboardStore(); const selectorStore = useSelectorStore(); - if (params.serviceId) { - queryMetrics(); - } - async function queryMetrics() { const params = await useQueryProcessor(props.data); if (!params) { @@ -127,27 +124,18 @@ export default defineComponent({ watch( () => [props.data.metricTypes, props.data.metrics], () => { - queryMetrics(); - } - ); - watch( - () => selectorStore.currentService, - () => { - if (dashboardStore.entity !== "Service") { + if (props.data.i !== dashboardStore.selectedGrid.i) { + return; + } + if (TableChartTypes.includes(dashboardStore.selectedGrid.graph.type)) { return; } queryMetrics(); } ); watch( - () => selectorStore.currentPod, + () => [selectorStore.currentService, selectorStore.currentPod], () => { - if ( - dashboardStore.entity === "All" || - dashboardStore.entity === "Service" - ) { - return; - } queryMetrics(); } ); diff --git a/src/views/dashboard/data.ts b/src/views/dashboard/data.ts index d739217b..42b16fae 100644 --- a/src/views/dashboard/data.ts +++ b/src/views/dashboard/data.ts @@ -23,11 +23,11 @@ export const ChartTypes = [ { label: "Bar", value: "Bar" }, { label: "Line", value: "Line" }, { label: "Area", value: "Area" }, - { label: "Heatmap", value: "Heatmap" }, - { label: "Pie", value: "Pie" }, + // { label: "Pie", value: "Pie" }, { label: "Card", value: "Card" }, { label: "Top List", value: "TopList" }, { label: "Table", value: "Table" }, + { label: "Heatmap", value: "Heatmap" }, { label: "Service List", value: "ServiceList" }, { label: "Endpoint List", value: "EndpointList" }, { label: "Instance List", value: "InstanceList" }, @@ -66,6 +66,7 @@ export const DefaultGraphConfig: { [key: string]: any } = { Card: { type: "Card", fontSize: 14, + textAlign: "center", showUint: true, }, Table: { diff --git a/src/views/dashboard/graphs/Card.vue b/src/views/dashboard/graphs/Card.vue index af08c4fd..1b1fc377 100644 --- a/src/views/dashboard/graphs/Card.vue +++ b/src/views/dashboard/graphs/Card.vue @@ -14,7 +14,10 @@ See the License for the specific language governing permissions and limitations under the License. -->