File size: 4,802 Bytes
89ce340 |
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 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 |
<template>
<div class="templates">
<div class="catalogs">
<div class="catalog"
:class="{ 'active': activeCatalog === item.id }"
v-for="item in templates"
:key="item.id"
@click="changeCatalog(item.id)"
>{{ item.name }}</div>
</div>
<div class="content">
<div class="header">
<div class="types">
<div class="type"
:class="{ 'active': activeType === item.value }"
v-for="item in types"
:key="item.value"
@click="activeType = item.value"
>{{ item.label }}</div>
</div>
<div class="insert-all" @click="insertTemplates(slides)">插入全部</div>
</div>
<div class="list" ref="listRef">
<template v-for="slide in slides" :key="slide.id">
<div
class="slide-item"
v-if="slide.type === activeType || activeType === 'all'"
>
<ThumbnailSlide class="thumbnail" :slide="slide" :size="180" />
<div class="btns">
<Button class="btn" type="primary" size="small" @click="insertTemplate(slide)">插入模板</Button>
</div>
</div>
</template>
</div>
</div>
</div>
</template>
<script lang="ts" setup>
import { ref, onMounted } from 'vue'
import { storeToRefs } from 'pinia'
import { useSlidesStore } from '@/store'
import type { Slide } from '@/types/slides'
import api from '@/services'
import ThumbnailSlide from '@/views/components/ThumbnailSlide/index.vue'
import Button from '@/components/Button.vue'
const emit = defineEmits<{
(event: 'select', payload: Slide): void
(event: 'selectAll', payload: Slide[]): void
}>()
const slidesStore = useSlidesStore()
const { templates } = storeToRefs(slidesStore)
const slides = ref<Slide[]>([])
const listRef = ref<HTMLElement>()
const types = ref<{
label: string
value: string
}[]>([
{ label: '全部', value: 'all' },
{ label: '封面', value: 'cover' },
{ label: '目录', value: 'contents' },
{ label: '过渡', value: 'transition' },
{ label: '内容', value: 'content' },
{ label: '结束', value: 'end' },
])
const activeType = ref('all')
const activeCatalog = ref('')
const insertTemplate = (slide: Slide) => {
emit('select', slide)
}
const insertTemplates = (slides: Slide[]) => {
emit('selectAll', slides)
}
const changeCatalog = (id: string) => {
activeCatalog.value = id
api.getFileData(activeCatalog.value).then(ret => {
slides.value = ret.slides
if (listRef.value) listRef.value.scrollTo(0, 0)
})
}
onMounted(() => {
changeCatalog(templates.value[0].id)
})
</script>
<style lang="scss" scoped>
.templates {
width: 500px;
height: 500px;
display: flex;
user-select: none;
}
.catalogs {
width: 108px;
margin-right: 10px;
padding-right: 10px;
border-right: 1px solid $borderColor;
overflow: auto;
.catalog {
padding: 7px 8px;
border-radius: $borderRadius;
cursor: pointer;
&:hover {
background-color: #f5f5f5;
}
&.active {
color: $themeColor;
background-color: rgba($color: $themeColor, $alpha: .05);
border-right: 2px solid $themeColor;
font-weight: 700;
}
& + .catalog {
margin-top: 3px;
}
}
}
.content {
display: flex;
flex-direction: column;
}
.header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 10px;
padding-right: 4px;
&:hover .insert-all {
opacity: 1;
transition: opacity $transitionDelay;
}
}
.types {
display: flex;
.type {
border-radius: $borderRadius;
padding: 3px 8px;
font-size: 12px;
cursor: pointer;
& +.type {
margin-left: 4px;
}
&.active {
color: $themeColor;
background-color: rgba($color: $themeColor, $alpha:.05);
font-weight: 700;
}
&:hover {
background-color: #f5f5f5;
}
}
}
.insert-all {
opacity: 0;
font-size: 12px;
color: $themeColor;
text-decoration: underline;
cursor: pointer;
}
.list {
width: 392px;
padding: 2px;
margin-right: -10px;
padding-right: 10px;
overflow: auto;
@include flex-grid-layout();
}
.slide-item {
position: relative;
@include flex-grid-layout-children(2, 48%);
&:hover .btns {
opacity: 1;
}
&:hover .thumbnail {
outline-color: $themeColor;
}
.btns {
@include absolute-0();
flex-direction: column;
justify-content: center;
align-items: center;
display: flex;
background-color: rgba($color: #000, $alpha: .25);
opacity: 0;
transition: opacity $transitionDelay;
}
.thumbnail {
outline: 2px solid $borderColor;
transition: outline $transitionDelay;
border-radius: $borderRadius;
cursor: pointer;
}
}
</style> |