fix config

This commit is contained in:
Qiuxia Fan 2022-03-30 15:21:39 +08:00
parent 7ddd719205
commit 9f64086d51
3 changed files with 28 additions and 18 deletions

View File

@ -13,10 +13,23 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. --> limitations under the License. -->
<template> <template>
<div ref="chartRef" :style="`height:${height};width:${width};`"></div> <div
v-if="isRight"
ref="chartRef"
:style="`height:${height};width:${width};`"
></div>
<div v-else>No Data</div>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { watch, ref, Ref, onMounted, onBeforeUnmount, unref } from "vue"; import {
watch,
ref,
Ref,
onMounted,
onBeforeUnmount,
unref,
computed,
} from "vue";
import type { PropType } from "vue"; import type { PropType } from "vue";
import { useECharts } from "@/hooks/useEcharts"; import { useECharts } from "@/hooks/useEcharts";
import { addResizeListener, removeResizeListener } from "@/utils/event"; import { addResizeListener, removeResizeListener } from "@/utils/event";
@ -31,12 +44,16 @@ const props = defineProps({
height: { type: String, default: "100%" }, height: { type: String, default: "100%" },
width: { type: String, default: "100%" }, width: { type: String, default: "100%" },
option: { option: {
type: Object as PropType<{ [key: string]: unknown }>, type: Object as PropType<{ [key: string]: any }>,
default: () => ({}), default: () => ({}),
}, },
}); });
const isRight = computed(
() =>
props.option.series && props.option.series[0] && props.option.series[0].data
);
onMounted(async () => { onMounted(async () => {
console.log(props.option);
await setOptions(props.option); await setOptions(props.option);
chartRef.value && addResizeListener(unref(chartRef), resize); chartRef.value && addResizeListener(unref(chartRef), resize);
setTimeout(() => { setTimeout(() => {

View File

@ -103,13 +103,10 @@ const currentMetric = ref<MetricConfigOpt>({
...props.currentMetricConfig, ...props.currentMetricConfig,
topN: props.currentMetricConfig.topN || 10, topN: props.currentMetricConfig.topN || 10,
}); });
const metricType = ref<string>( const metricTypes = dashboardStore.selectedGrid.metricTypes || [];
dashboardStore.selectedGrid.metricTypes[props.index] const metricType = ref<string>(metricTypes[props.index]);
);
const isTopn = computed(() => const isTopn = computed(() =>
["sortMetrics", "readSampledRecords"].includes( ["sortMetrics", "readSampledRecords"].includes(metricTypes[props.index])
dashboardStore.selectedGrid.metricTypes[props.index]
)
); );
function changeConfigs( function changeConfigs(
index: number, index: number,

View File

@ -15,21 +15,17 @@ limitations under the License. -->
<template> <template>
<div <div
v-if="!isNaN(singleVal)"
class="chart-card" class="chart-card"
:class="{ center: config.textAlign === 'center' }" :class="{ center: config.textAlign === 'center' }"
:style="{ fontSize: `${config.fontSize}px`, textAlign: config.textAlign }" :style="{ fontSize: `${config.fontSize}px`, textAlign: config.textAlign }"
> >
{{ {{ singleVal.toFixed(2) }}
typeof singleVal === "string"
? singleVal
: isNaN(singleVal)
? null
: singleVal.toFixed(2)
}}
<span v-show="config.showUnit"> <span v-show="config.showUnit">
{{ metricConfig[0]?.unit }} {{ metricConfig[0]?.unit }}
</span> </span>
</div> </div>
<div class="center chart-card" v-else>No Data</div>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { computed, PropType } from "vue"; import { computed, PropType } from "vue";
@ -53,7 +49,7 @@ const props = defineProps({
}); });
const metricConfig = computed(() => props.config.metricConfig || []); const metricConfig = computed(() => props.config.metricConfig || []);
const key = computed(() => Object.keys(props.data)[0]); const key = computed(() => Object.keys(props.data)[0]);
const singleVal = computed(() => props.data[key.value]); const singleVal = computed(() => Number(props.data[key.value]));
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.chart-card { .chart-card {