wujingjing
2024-12-31 3cb993333cbb2f80d5a31b48027766262af92a75
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<template>
    <yw-dialog v-model="isShow" :showFooter="false" width="500" :title="title">
        <div v-if="item.alias && Object.keys(item.alias).length > 0">
            <div v-for="key in Object.keys(item.alias)" :key="key">
                <span>{{ key }}:</span>
                <span>{{ item.alias[key].join(',') }}</span>
            </div>
        </div>
    </yw-dialog>
</template>
 
<script setup lang="ts" name="AliasDisplayDlg">
import _ from 'lodash';
import { computed, ref, watch } from 'vue';
import * as metricApi from '/@/api/metrics';
import ywDialog from '/@/components/dialog/yw-dialog.vue';
 
const props = defineProps(['item']);
const isShow = defineModel({
    type: Boolean,
});
 
const tableData = ref([]);
const title = computed(() => props.item?.title + '——别名');
 
// 需要合并单元格的 prop
const GROUP_PROP = ['title', 'full_name', 'metrics_define', 'calcu_method'];
const objectSpanMethod = ({ row, column, rowIndex, columnIndex }) => {
    if (GROUP_PROP.includes(column.property)) {
        return {
            rowspan: row.rowspan,
            colspan: 1,
        };
    }
};
 
const parseData = (data: any[]) => {
    const finalData = (data ?? []).reduce((pre, cur) => {
        const dimensions = cur.dimensions;
        pre.push(
            ...dimensions.map((item, index) => ({
                ..._.omit(cur, 'dimensions'),
                id: cur.id + '_dimension_' + item.id,
                dimension: item,
                rowspan: index === 0 ? dimensions.length : undefined,
            }))
        );
        return pre;
    }, []);
    return finalData;
};
 
watch(
    () => isShow.value,
    async (val) => {
        if (!val) return;
 
        const res = await metricApi.getMetricNameListByPost({
            agent_id: props.item.id,
        });
        tableData.value = parseData(res?.values);
    }
);
</script>
<style scoped lang="scss">
:deep(.el-card__body) {
    position: relative;
}
</style>