index.vue
1.47 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 name="SearchBar">
const props = defineProps({
fold: {
type: Boolean,
default: true,
},
showToggle: {
type: Boolean,
default: true,
},
background: {
type: Boolean,
default: false,
},
})
const emit = defineEmits<{
(event: 'update:fold', value: boolean): void
(event: 'toggle', value: boolean): void
}>()
const isFold = ref(props.fold)
watch(() => props.fold, (value) => {
isFold.value = value
emit('update:fold', value)
})
function toggle() {
isFold.value = !isFold.value
emit('toggle', isFold.value)
}
</script>
<template>
<div class="search-container" :class="{ 'has-bg': background }">
<slot :fold="isFold" />
<div v-if="showToggle" class="toggle">
<el-button text size="small" @click="toggle" v-preReClick>
<template #icon>
<el-icon>
<svg-icon :name="isFold ? 'ep:caret-bottom' : 'ep:caret-top' " />
</el-icon>
</template>
{{ isFold ? '展开' : '收起' }}
</el-button>
</div>
</div>
</template>
<style lang="scss" scoped>
.search-container {
position: relative;
&.has-bg {
padding: 20px;
background-color: var(--el-fill-color-lighter);
transition: background-color 0.3s;
}
:deep(.el-form) {
margin-bottom: -10px;
.el-select {
width: 100%;
}
.el-date-editor {
width: 100%;
}
}
.toggle {
position: relative;
text-align: center;
margin-bottom: -10px;
}
}
</style>