block.vue
1.6 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
<template>
<div class="block">
<h5 class="title">{{ title }}</h5>
<div v-for="option in options" :key="option.name" class="switch-wrapper">
<span>{{ $t(option.name) }}</span>
<form-wrapper
:type="option.type || 'switch'"
:name="option.key"
:default-value="option.defaultVal"
@input-change="handleChange"
/>
</div>
</div>
</template>
<script lang="ts" setup>
import { PropType } from 'vue'
import { useAppStore } from '@/store'
import FormWrapper from './form-wrapper.vue'
interface OptionsProps {
name: string
key: string
type?: string
defaultVal?: boolean | string | number
}
defineProps({
title: {
type: String,
default: '',
},
options: {
type: Array as PropType<OptionsProps[]>,
default() {
return []
},
},
})
const appStore = useAppStore()
const handleChange = async ({
key,
value,
}: {
key: string
value: unknown
}) => {
if (key === 'colorWeak') {
document.body.style.filter = value ? 'invert(80%)' : 'none'
}
if (key === 'menuFromServer' && value) {
await appStore.fetchFatherMenuConfig()
}
if (key === 'topMenu') {
appStore.updateSettings({
menuCollapse: false,
})
}
appStore.updateSettings({ [key]: value })
}
</script>
<style scoped lang="less">
.block {
margin-bottom: 24px;
}
.title {
margin: 10px 0;
padding: 0;
font-size: 14px;
}
.switch-wrapper {
display: flex;
align-items: center;
justify-content: space-between;
height: 32px;
}
</style>