index.vue
1.99 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
80
81
82
83
84
85
86
87
88
89
90
91
92
<template>
<div class="flex link">
<el-menu :default-active="activeMenu" class="!w-[160px] min-h-[350px] link-menu" @select="handleSelect">
<el-menu-item v-for="(item, index) in menus" :index="item.type" :key="index">
<span>{{ item.name }}</span>
</el-menu-item>
</el-menu>
<div class="flex-1 pl-4">
<shop-pages v-model="activeLink" v-if="LinkTypeEnum.SHOP_PAGES == activeMenu" />
<custom-link v-model="activeLink" v-if="LinkTypeEnum.CUSTOM_LINK == activeMenu" />
</div>
</div>
</template>
<script lang="ts" setup>
import type { PropType } from 'vue';
import { LinkTypeEnum, type Link } from '.';
import ShopPages from './shop-pages.vue';
import CustomLink from './custom-link.vue';
const props = defineProps({
modelValue: {
type: Object as PropType<Link>,
required: true,
},
});
const emit = defineEmits<{
(event: 'update:modelValue', value: any): void;
}>();
const menus = ref([
{
name: '商城页面',
type: LinkTypeEnum.SHOP_PAGES,
link: {},
},
{
name: '自定义链接',
type: LinkTypeEnum.CUSTOM_LINK,
link: {},
},
]);
const activeLink = computed({
get() {
return menus.value.find((item) => item.type == activeMenu.value)?.link as Link;
},
set(value) {
menus.value.forEach((item) => {
if (item.type == activeMenu.value) {
item.link = value;
}
});
},
});
const activeMenu = ref<string>(LinkTypeEnum.SHOP_PAGES);
const handleSelect = (index: string) => {
activeMenu.value = index;
};
watch(activeLink, (value) => {
if (!value?.type) return;
emit('update:modelValue', value);
});
watch(
() => props.modelValue,
(value) => {
activeMenu.value = value.type;
activeLink.value = value;
},
{
immediate: true,
}
);
</script>
<style lang="scss" scoped>
.link-menu {
--el-menu-item-height: 40px;
:deep(.el-menu-item) {
border-color: transparent !important;
&.is-active {
border-right-width: 2px !important;
border-color: var(--el-color-primary) !important;
background-color: var(--el-color-primary-light-9) !important;
}
}
}
</style>