update list

This commit is contained in:
Qiuxia Fan 2022-03-25 21:29:30 +08:00
parent 9c34ac0c3b
commit b84b5f9338
7 changed files with 28 additions and 14 deletions

View File

@ -257,7 +257,11 @@ export function useQueryPodsMetrics(
export function usePodsSource( export function usePodsSource(
pods: Array<Instance | Endpoint>, pods: Array<Instance | Endpoint>,
resp: { errors: string; data: { [key: string]: any } }, resp: { errors: string; data: { [key: string]: any } },
config: { metrics: string[]; metricTypes: string[] } config: {
metrics: string[];
metricTypes: string[];
metricConfig: MetricConfigOpt[];
}
): any { ): any {
if (resp.errors) { if (resp.errors) {
ElMessage.error(resp.errors); ElMessage.error(resp.errors);
@ -265,13 +269,14 @@ export function usePodsSource(
} }
const data = pods.map((d: Instance | any, idx: number) => { const data = pods.map((d: Instance | any, idx: number) => {
config.metrics.map((name: string, index: number) => { config.metrics.map((name: string, index: number) => {
const c = (config.metricConfig && config.metricConfig[index]) || {};
const key = name + idx + index; const key = name + idx + index;
if (config.metricTypes[index] === MetricQueryTypes.ReadMetricsValue) { if (config.metricTypes[index] === MetricQueryTypes.ReadMetricsValue) {
d[name] = resp.data[key]; d[name] = aggregation(resp.data[key], c);
} }
if (config.metricTypes[index] === MetricQueryTypes.ReadMetricsValues) { if (config.metricTypes[index] === MetricQueryTypes.ReadMetricsValues) {
d[name] = resp.data[key].values.values.map( d[name] = resp.data[key].values.values.map((d: { value: number }) =>
(d: { value: number }) => d.value aggregation(d.value, c)
); );
} }
}); });
@ -307,7 +312,7 @@ export function useQueryTopologyMetrics(metrics: string[], ids: string[]) {
} }
function aggregation(val: number, config: any): number | string { function aggregation(val: number, config: any): number | string {
let data: number | string = val; let data: number | string = Number(val);
switch (config.calculation) { switch (config.calculation) {
case Calculations.Percentage: case Calculations.Percentage:
@ -329,5 +334,7 @@ function aggregation(val: number, config: any): number | string {
data; data;
break; break;
} }
console.log(data);
return data; return data;
} }

View File

@ -85,7 +85,7 @@ import { Option } from "@/types/app";
import graphs from "../graphs"; import graphs from "../graphs";
import configs from "./widget/graph-styles"; import configs from "./widget/graph-styles";
import WidgetOptions from "./widget/WidgetOptions.vue"; import WidgetOptions from "./widget/WidgetOptions.vue";
import MetricOptions from "./widget/metric/MetricOptions.vue"; import MetricOptions from "./widget/metric/Options.vue";
export default defineComponent({ export default defineComponent({
name: "WidgetEdit", name: "WidgetEdit",

View File

@ -55,7 +55,7 @@ limitations under the License. -->
<Icon class="cp mr-5" iconName="mode_edit" size="middle" /> <Icon class="cp mr-5" iconName="mode_edit" size="middle" />
</span> </span>
</template> </template>
<StandardOptions @update="queryMetrics" @close="showConfig = false" /> <Standard @update="queryMetrics" @close="showConfig = false" />
</el-popover> </el-popover>
<span <span
v-show="states.isList || states.metricTypes[0] === 'readMetricsValues'" v-show="states.isList || states.metricTypes[0] === 'readMetricsValues'"
@ -110,7 +110,7 @@ import Icon from "@/components/Icon.vue";
import { useQueryProcessor, useSourceProcessor } from "@/hooks/useProcessor"; import { useQueryProcessor, useSourceProcessor } from "@/hooks/useProcessor";
import { useI18n } from "vue-i18n"; import { useI18n } from "vue-i18n";
import { DashboardItem, MetricConfigOpt } from "@/types/dashboard"; import { DashboardItem, MetricConfigOpt } from "@/types/dashboard";
import StandardOptions from "./StandardOptions.vue"; import Standard from "./Standard.vue";
/*global defineEmits */ /*global defineEmits */
const { t } = useI18n(); const { t } = useI18n();

View File

@ -105,7 +105,6 @@ function changeConfigs(index: number, param: { [key: string]: string }) {
...dashboardStore.selectedGrid, ...dashboardStore.selectedGrid,
metricConfig, metricConfig,
}); });
console.log(dashboardStore.selectedGrid);
emit("update"); emit("update");
} }

View File

@ -65,7 +65,7 @@ limitations under the License. -->
metricTypes: data.metricTypes, metricTypes: data.metricTypes,
i: data.i, i: data.i,
}" }"
:standard="data.standard" :standard="data.metricConfig"
:needQuery="needQuery" :needQuery="needQuery"
/> />
</div> </div>

View File

@ -31,7 +31,7 @@ limitations under the License. -->
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { computed, PropType } from "vue"; import { computed, PropType } from "vue";
import { CardConfig, StandardConfig } from "@/types/dashboard"; import { CardConfig, MetricConfigOpt } from "@/types/dashboard";
/*global defineProps */ /*global defineProps */
const props = defineProps({ const props = defineProps({
@ -44,7 +44,7 @@ const props = defineProps({
default: () => ({ fontSize: 12, showUint: true, textAlign: "center" }), default: () => ({ fontSize: 12, showUint: true, textAlign: "center" }),
}, },
standard: { standard: {
type: Object as PropType<StandardConfig>, type: Object as PropType<MetricConfigOpt>,
default: () => ({ unit: "" }), default: () => ({ unit: "" }),
}, },
}); });

View File

@ -104,6 +104,7 @@ import { useQueryPodsMetrics, usePodsSource } from "@/hooks/useProcessor";
import { EntityType } from "../data"; import { EntityType } from "../data";
import router from "@/router"; import router from "@/router";
import getDashboard from "@/hooks/useDashboardsSession"; import getDashboard from "@/hooks/useDashboardsSession";
import { MetricConfigOpt } from "@/types/dashboard";
/*global defineProps */ /*global defineProps */
const props = defineProps({ const props = defineProps({
@ -123,6 +124,10 @@ const props = defineProps({
}, },
intervalTime: { type: Array as PropType<string[]>, default: () => [] }, intervalTime: { type: Array as PropType<string[]>, default: () => [] },
isEdit: { type: Boolean, default: false }, isEdit: { type: Boolean, default: false },
standard: {
type: Object as PropType<MetricConfigOpt[]>,
default: () => ({ unit: "" }),
},
}); });
const selectorStore = useSelectorStore(); const selectorStore = useSelectorStore();
const dashboardStore = useDashboardStore(); const dashboardStore = useDashboardStore();
@ -201,7 +206,7 @@ async function queryServiceMetrics(currentServices: Service[]) {
return; return;
} }
const { metrics } = props.config; const { metrics } = props.config;
console.log(props.config);
if (metrics.length && metrics[0]) { if (metrics.length && metrics[0]) {
const params = await useQueryPodsMetrics( const params = await useQueryPodsMetrics(
currentServices, currentServices,
@ -214,7 +219,10 @@ async function queryServiceMetrics(currentServices: Service[]) {
ElMessage.error(json.errors); ElMessage.error(json.errors);
return; return;
} }
services.value = usePodsSource(currentServices, json, props.config); services.value = usePodsSource(currentServices, json, {
...props.config,
metricConfig: props.standard || [],
});
return; return;
} }
services.value = currentServices; services.value = currentServices;