VisualConfiguration.vue
2.44 KB
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
70
71
72
73
74
75
76
77
78
79
<script lang="ts" setup>
import { Tabs, List } from 'ant-design-vue';
import VisualWidgetSelect from './VisualWidgetSelect.vue';
import { getComponentDefaultConfig } from '../../components/help';
import { frontComponentMap } from '../../components/help';
import { computed } from 'vue';
import {
FrontComponent,
FrontComponentCategory,
FrontComponentCategoryName,
} from '../../const/const';
interface DataSource {
category: string;
categoryName: string;
list: Recordable[];
}
const props = defineProps<{
value: string;
}>();
const emit = defineEmits(['update:value', 'change']);
const grid = { gutter: 10, column: 1, xs: 1, sm: 2, md: 2, lg: 3, xl: 3, xxl: 4 };
const getDataSource = computed(() => {
const _dataSource = Array.from(frontComponentMap.values());
const category = new Map<FrontComponentCategory, DataSource>();
for (const item of _dataSource) {
if (category.has(item.ComponentCategory)) {
const value = category.get(item.ComponentCategory)!;
value.list.push(item);
continue;
}
category.set(item.ComponentCategory, {
category: item.ComponentCategory,
categoryName: FrontComponentCategoryName[item.ComponentCategory],
list: [item],
});
}
return Array.from(category.values());
});
const handleCheck = (checked: FrontComponent) => {
const defaultConfig = getComponentDefaultConfig(checked);
emit('update:value', checked);
emit('change', defaultConfig);
};
</script>
<template>
<section>
<Tabs>
<Tabs.TabPane
v-for="category in getDataSource"
:key="category.category"
:tab="category.categoryName"
>
<List :grid="grid" :data-source="category.list">
<template #renderItem="{ item }">
<List.Item class="!flex !justify-center">
<VisualWidgetSelect
:checked-id="props.value"
:control-id="item.ComponentKey"
@change="handleCheck"
>
<template #default>
<component :is="item.Component" :random="true" :layout="item.ComponentConfig" />
</template>
<template #description>
{{ item.ComponentName || '选择' }}
</template>
</VisualWidgetSelect>
</List.Item>
</template>
</List>
</Tabs.TabPane>
</Tabs>
</section>
</template>