Files
orion-visor/orion-ops-ui/src/components/global-setting/block.vue

85 lines
1.8 KiB
Vue
Raw Normal View History

2023-07-24 10:05:07 +08:00
<template>
<div class="block">
<h5 class="title">{{ title }}</h5>
2023-09-26 01:11:57 +08:00
<div v-for="option in options" :key="option.name" class="option-wrapper">
<!-- 偏好项 -->
2023-09-25 22:05:48 +08:00
<span>{{ option.name }}</span>
2023-09-26 01:11:57 +08:00
<!-- input -->
<form-wrapper :name="option.key"
:type="option.type"
:default-value="option.defaultVal"
:options="option.options"
@input-change="handleChange" />
2023-07-24 10:05:07 +08:00
</div>
</div>
</template>
<script lang="ts" setup>
import { PropType } from 'vue';
import { useAppStore } from '@/store';
import FormWrapper from './form-wrapper.vue';
2023-09-26 01:11:57 +08:00
import { RadioOption } from '@arco-design/web-vue/es/radio/interface';
2023-07-24 10:05:07 +08:00
interface OptionsProps {
name: string;
key: string;
type?: string;
defaultVal?: boolean | string | number;
2023-09-26 01:11:57 +08:00
options?: Array<RadioOption>;
2023-07-24 10:05:07 +08:00
}
2023-07-27 18:48:15 +08:00
2023-07-24 10:05:07 +08:00
defineProps({
2023-09-26 01:11:57 +08:00
title: String,
2023-07-24 10:05:07 +08:00
options: {
type: Array as PropType<OptionsProps[]>,
default() {
return [];
},
},
});
const appStore = useAppStore();
2023-07-27 18:48:15 +08:00
/**
* 修改配置
*/
const handleChange = async ({ key, value, }: {
2023-07-24 10:05:07 +08:00
key: string;
value: unknown;
}) => {
2023-07-27 18:48:15 +08:00
// 色弱模式
2023-07-24 10:05:07 +08:00
if (key === 'colorWeak') {
document.body.style.filter = value ? 'invert(80%)' : 'none';
}
2023-07-27 18:48:15 +08:00
// 顶部菜单
2023-07-24 10:05:07 +08:00
if (key === 'topMenu') {
appStore.updateSettings({
menuCollapse: false,
});
}
2023-09-26 01:11:57 +08:00
// 修改配置
2023-07-24 10:05:07 +08:00
appStore.updateSettings({ [key]: value });
2023-09-26 01:11:57 +08:00
// TODO 同步偏好
2023-07-24 10:05:07 +08:00
};
</script>
<style scoped lang="less">
.block {
margin-bottom: 24px;
2023-09-26 01:11:57 +08:00
user-select: none;
2023-07-24 10:05:07 +08:00
}
.title {
margin: 10px 0;
padding: 0;
font-size: 14px;
}
2023-09-26 01:11:57 +08:00
.option-wrapper {
2023-07-24 10:05:07 +08:00
display: flex;
align-items: center;
justify-content: space-between;
height: 32px;
}
</style>