|
@@ -1,5 +1,5 @@
|
|
<template>
|
|
<template>
|
|
- <div class="metrics-cards">
|
|
|
|
|
|
+ <div class="metrics-cards" v-loading="loading">
|
|
<MCard
|
|
<MCard
|
|
v-model="info.metric"
|
|
v-model="info.metric"
|
|
:metric-items="allMetricItems"
|
|
:metric-items="allMetricItems"
|
|
@@ -11,45 +11,59 @@
|
|
</template>
|
|
</template>
|
|
|
|
|
|
<script lang="ts" setup>
|
|
<script lang="ts" setup>
|
|
-import { ref, withDefaults, Ref, onBeforeMount, watch, computed,ComputedRef } from 'vue'
|
|
|
|
|
|
+import { ref, Ref, onBeforeMount, watch, onMounted, computed } from 'vue'
|
|
import MCard from './mCard.vue'
|
|
import MCard from './mCard.vue'
|
|
|
|
+import XEUtils from 'xe-utils';
|
|
|
|
|
|
-interface ModelData {
|
|
|
|
- metric: string,
|
|
|
|
- color: string
|
|
|
|
-}
|
|
|
|
interface Props {
|
|
interface Props {
|
|
- modelValue: ModelData[],
|
|
|
|
|
|
+ modelValue: ShowMetric[],
|
|
metricItems: MetricData[],
|
|
metricItems: MetricData[],
|
|
- colors?: string[]
|
|
|
|
}
|
|
}
|
|
const colorsMap: { [key: string]: boolean } = {}
|
|
const colorsMap: { [key: string]: boolean } = {}
|
|
-const props = withDefaults(defineProps<Props>(), { colors: () => ["aqua", "orange", "blue"] })
|
|
|
|
|
|
+const props = defineProps<Props>()
|
|
const emits = defineEmits(['change', 'update:modelValue'])
|
|
const emits = defineEmits(['change', 'update:modelValue'])
|
|
const allMetricItems = ref(props.metricItems)
|
|
const allMetricItems = ref(props.metricItems)
|
|
const selectedMetric = ref(props.modelValue)
|
|
const selectedMetric = ref(props.modelValue)
|
|
const displayMetrics: Ref<{metric:string, color?: string}[]> = ref([])
|
|
const displayMetrics: Ref<{metric:string, color?: string}[]> = ref([])
|
|
|
|
|
|
-onBeforeMount(()=> {
|
|
|
|
- for (const color of props.colors) {
|
|
|
|
- colorsMap[color] = false
|
|
|
|
|
|
+const metricMap = computed(():{[key: string]: string} => {
|
|
|
|
+ const tmp:{[key: string]: string} = {}
|
|
|
|
+ for (const info of allMetricItems.value) {
|
|
|
|
+ tmp[info.value] = info.label
|
|
}
|
|
}
|
|
- const tmp:{[key: string]: boolean} = {}
|
|
|
|
|
|
+ return tmp
|
|
|
|
+})
|
|
|
|
+const loading = computed(() => {
|
|
|
|
+ return displayMetrics.value.length !== 6
|
|
|
|
+})
|
|
|
|
+onBeforeMount(()=> {
|
|
|
|
+ const dup:{[key: string]: boolean} = {}
|
|
for (const info of selectedMetric.value) {
|
|
for (const info of selectedMetric.value) {
|
|
displayMetrics.value.push({ metric: info.metric, color: info.color })
|
|
displayMetrics.value.push({ metric: info.metric, color: info.color })
|
|
- tmp[info.metric] = true
|
|
|
|
|
|
+ dup[info.metric] = true
|
|
|
|
+ if (info.color) {
|
|
|
|
+ colorsMap[info.color] = true
|
|
|
|
+ }
|
|
}
|
|
}
|
|
for (const info of allMetricItems.value) {
|
|
for (const info of allMetricItems.value) {
|
|
- if (info.disabled && !tmp[info.value]) { displayMetrics.value.push({ metric: info.value }) }
|
|
|
|
|
|
+ if (info.disabled && !dup[info.value]) { displayMetrics.value.push({ metric: info.value }) }
|
|
}
|
|
}
|
|
})
|
|
})
|
|
|
|
|
|
const getColor = () => {
|
|
const getColor = () => {
|
|
for (const [k,v] of Object.entries(colorsMap)) {
|
|
for (const [k,v] of Object.entries(colorsMap)) {
|
|
- if (!v) return k
|
|
|
|
|
|
+ if (!v) {
|
|
|
|
+ colorsMap[k] = true
|
|
|
|
+ return k
|
|
|
|
+ }
|
|
}
|
|
}
|
|
return ""
|
|
return ""
|
|
}
|
|
}
|
|
|
|
+const unsetColor = (color: string ) => {
|
|
|
|
+ if (XEUtils.has(colorsMap, color)) {
|
|
|
|
+ colorsMap[color] = false
|
|
|
|
+ }
|
|
|
|
+}
|
|
const changedMetric = (oldVal: string, newVal: string) => {
|
|
const changedMetric = (oldVal: string, newVal: string) => {
|
|
for (const info of allMetricItems.value) {
|
|
for (const info of allMetricItems.value) {
|
|
if (info.value === newVal) {
|
|
if (info.value === newVal) {
|
|
@@ -61,6 +75,7 @@ const changedMetric = (oldVal: string, newVal: string) => {
|
|
const index = selectedMetric.value.findIndex( info => info.metric === oldVal)
|
|
const index = selectedMetric.value.findIndex( info => info.metric === oldVal)
|
|
if (index > -1) {
|
|
if (index > -1) {
|
|
selectedMetric.value[index].metric = newVal
|
|
selectedMetric.value[index].metric = newVal
|
|
|
|
+ selectedMetric.value[index].label = metricMap.value[newVal]
|
|
emits('update:modelValue', selectedMetric.value)
|
|
emits('update:modelValue', selectedMetric.value)
|
|
emits('change', selectedMetric.value)
|
|
emits('change', selectedMetric.value)
|
|
}
|
|
}
|
|
@@ -71,16 +86,16 @@ const clickCard = (metric: string) => {
|
|
if (selectedMetric.value.length <= 1 ) return
|
|
if (selectedMetric.value.length <= 1 ) return
|
|
const tmp = selectedMetric.value[index]
|
|
const tmp = selectedMetric.value[index]
|
|
selectedMetric.value.splice(index, 1)
|
|
selectedMetric.value.splice(index, 1)
|
|
- colorsMap[tmp.color] = false
|
|
|
|
|
|
+ unsetColor(tmp.color)
|
|
emits('update:modelValue', selectedMetric.value)
|
|
emits('update:modelValue', selectedMetric.value)
|
|
emits('change', selectedMetric.value)
|
|
emits('change', selectedMetric.value)
|
|
} else { // 不存在则添加
|
|
} else { // 不存在则添加
|
|
if (selectedMetric.value.length === 3) {
|
|
if (selectedMetric.value.length === 3) {
|
|
selectedMetric.value[2].metric = metric
|
|
selectedMetric.value[2].metric = metric
|
|
|
|
+ selectedMetric.value[2].label = metricMap.value[metric]
|
|
} else {
|
|
} else {
|
|
const color = getColor()
|
|
const color = getColor()
|
|
- colorsMap[color] = true
|
|
|
|
- selectedMetric.value.push({ metric: metric, color: color})
|
|
|
|
|
|
+ selectedMetric.value.push({ metric: metric, color: color, label: metricMap.value[metric]})
|
|
}
|
|
}
|
|
emits('update:modelValue', selectedMetric.value)
|
|
emits('update:modelValue', selectedMetric.value)
|
|
emits('change', selectedMetric.value)
|
|
emits('change', selectedMetric.value)
|
|
@@ -101,6 +116,19 @@ watch(selectedMetric.value, () => {
|
|
}
|
|
}
|
|
})
|
|
})
|
|
|
|
|
|
|
|
+watch(
|
|
|
|
+ allMetricItems.value,
|
|
|
|
+ () => {
|
|
|
|
+ const tmp:{[key: string]: boolean} = {}
|
|
|
|
+ for (const info of displayMetrics.value) {
|
|
|
|
+ tmp[info.metric] = true
|
|
|
|
+ }
|
|
|
|
+ for (const info of allMetricItems.value) {
|
|
|
|
+ if (info.disabled && !tmp[info.value]) { displayMetrics.value.push({ metric: info.value }) }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+)
|
|
|
|
+
|
|
</script>
|
|
</script>
|
|
|
|
|
|
<style scoped>
|
|
<style scoped>
|