ForcePilot/web/src/views/SettingView.vue

349 lines
10 KiB
Vue
Raw Normal View History

<template>
2025-05-05 19:48:55 +08:00
<!-- TODO 优化样式表格优化添加一个 utils 的函数用来把时间戳转换为东 8 区的时间并格式化显示出来 -->
2024-09-14 02:46:44 +08:00
<div class="">
<HeaderComponent title="设置" class="setting-header">
2025-05-02 23:56:59 +08:00
2024-09-14 02:46:44 +08:00
<template #actions>
2025-03-14 03:29:08 +08:00
<a-button :type="isNeedRestart ? 'primary' : 'default'" @click="sendRestart" :icon="h(ReloadOutlined)">
2025-04-09 12:05:05 +08:00
{{ isNeedRestart ? '需要刷新' : '重新加载' }}
2024-09-14 02:46:44 +08:00
</a-button>
</template>
</HeaderComponent>
<div class="setting-container layout-container">
2025-02-27 01:37:42 +08:00
<div class="sider" v-if="state.windowWidth > 520">
2024-09-28 00:41:18 +08:00
<a-button type="text" :class="{ activesec: state.section === 'base'}" @click="state.section='base'" :icon="h(SettingOutlined)"> 基本设置 </a-button>
<a-button type="text" :class="{ activesec: state.section === 'model'}" @click="state.section='model'" :icon="h(CodeOutlined)"> 模型配置 </a-button>
<a-button type="text" :class="{ activesec: state.section === 'path'}" @click="state.section='path'" :icon="h(FolderOutlined)"> 路径配置 </a-button>
2025-05-02 23:56:59 +08:00
<a-button type="text" :class="{ activesec: state.section === 'user'}" @click="state.section='user'" :icon="h(UserOutlined)" v-if="userStore.isAdmin"> 用户管理 </a-button>
2024-09-28 00:41:18 +08:00
</div>
2025-02-27 01:37:42 +08:00
<div class="setting" v-if="state.windowWidth <= 520 || state.section === 'base'">
<h3>检索配置</h3>
2024-09-14 02:46:44 +08:00
<div class="section">
<div class="card card-select">
<span class="label">对话模型</span>
<ModelSelectorComponent @select-model="handleChatModelSelect" />
</div>
2025-02-27 01:37:42 +08:00
<div class="card card-select">
2024-09-28 00:41:18 +08:00
<span class="label">{{ items?.embed_model.des }}</span>
2025-02-23 16:39:52 +08:00
<a-select style="width: 300px"
2024-09-14 02:46:44 +08:00
:value="configStore.config?.embed_model"
@change="handleChange('embed_model', $event)"
>
<a-select-option
v-for="(name, idx) in items?.embed_model.choices" :key="idx"
:value="name">{{ name }}
</a-select-option>
</a-select>
</div>
2025-02-27 01:37:42 +08:00
<div class="card card-select">
2024-09-28 00:41:18 +08:00
<span class="label">{{ items?.reranker.des }}</span>
2025-02-23 16:39:52 +08:00
<a-select style="width: 300px"
2024-09-14 02:46:44 +08:00
:value="configStore.config?.reranker"
@change="handleChange('reranker', $event)"
:disabled="!configStore.config.enable_reranker"
>
<a-select-option
v-for="(name, idx) in items?.reranker.choices" :key="idx"
:value="name">{{ name }}
</a-select-option>
</a-select>
</div>
<div class="card">
2024-09-28 00:41:18 +08:00
<span class="label">{{ items?.enable_reranker.des }}</span>
2024-09-14 02:46:44 +08:00
<a-switch
:checked="configStore.config.enable_reranker"
@change="handleChange('enable_reranker', !configStore.config.enable_reranker)"
/>
</div>
2025-02-27 01:37:42 +08:00
<div class="card card-select">
<span class="label">{{ items?.use_rewrite_query.des }}</span>
<a-select style="width: 200px"
:value="configStore.config?.use_rewrite_query"
@change="handleChange('use_rewrite_query', $event)"
>
<a-select-option
v-for="(name, idx) in items?.use_rewrite_query.choices" :key="idx"
:value="name">{{ name }}
</a-select-option>
</a-select>
</div>
</div>
<h3>功能配置</h3>
<div class="section">
<div class="card">
<span class="label">{{ items?.enable_knowledge_base.des }}</span>
<a-switch
:checked="configStore.config.enable_knowledge_base"
@change="handleChange('enable_knowledge_base', !configStore.config.enable_knowledge_base)"
/>
</div>
<div class="card">
<span class="label">{{ items?.enable_knowledge_graph.des }}</span>
<a-switch
:checked="configStore.config.enable_knowledge_graph"
@change="handleChange('enable_knowledge_graph', !configStore.config.enable_knowledge_graph)"
/>
</div>
</div>
</div>
2025-02-27 01:37:42 +08:00
<div class="setting" v-if="state.windowWidth <= 520 || state.section === 'model'">
2024-09-28 00:41:18 +08:00
<h3>模型配置</h3>
<p>请在 <code>src/.env</code> 文件中配置对应的 APIKEY并重新启动服务</p>
2025-05-18 17:18:29 +08:00
<ModelProvidersComponent />
2024-09-28 00:41:18 +08:00
</div>
2025-02-27 01:37:42 +08:00
<div class="setting" v-if="state.windowWidth <= 520 || state.section ==='path'">
<h3>本地模型配置</h3>
2025-03-08 20:26:00 +08:00
<p>如果是 Docker 启动务必确保在 docker-compose.dev.yaml 中添加了 volumes 映射</p>
<TableConfigComponent
:config="configStore.config?.model_local_paths"
@update:config="handleModelLocalPathsUpdate"
/>
2024-11-14 20:07:49 +08:00
</div>
2025-05-05 19:48:55 +08:00
<!-- TODO 用户管理优化添加姓名默认使用用户名配置项 -->
2025-05-02 23:56:59 +08:00
<div class="setting" v-if="state.section === 'user'">
2025-05-18 17:18:29 +08:00
<UserManagementComponent />
2025-05-02 23:56:59 +08:00
</div>
</div>
</div>
</template>
<script setup>
import { message } from 'ant-design-vue';
2025-02-27 01:37:42 +08:00
import { computed, reactive, ref, h, watch, onMounted, onUnmounted } from 'vue'
2024-07-27 14:32:57 +08:00
import { useConfigStore } from '@/stores/config';
2025-05-02 23:56:59 +08:00
import { useUserStore } from '@/stores/user'
2024-09-28 00:41:18 +08:00
import {
ReloadOutlined,
SettingOutlined,
CodeOutlined,
FolderOutlined,
2025-05-18 17:18:29 +08:00
UserOutlined
2024-09-28 00:41:18 +08:00
} from '@ant-design/icons-vue';
2024-09-14 02:46:44 +08:00
import HeaderComponent from '@/components/HeaderComponent.vue';
import TableConfigComponent from '@/components/TableConfigComponent.vue';
2025-05-18 17:18:29 +08:00
import ModelProvidersComponent from '@/components/ModelProvidersComponent.vue';
import UserManagementComponent from '@/components/UserManagementComponent.vue';
2024-10-08 22:16:17 +08:00
import { notification, Button } from 'ant-design-vue';
2025-05-04 21:04:01 +08:00
import { systemConfigApi } from '@/apis/admin_api'
import ModelSelectorComponent from '@/components/ModelSelectorComponent.vue';
const configStore = useConfigStore()
2025-05-02 23:56:59 +08:00
const userStore = useUserStore()
const items = computed(() => configStore.config._config_items)
2024-09-28 00:41:18 +08:00
const isNeedRestart = ref(false)
const state = reactive({
loading: false,
2025-02-27 01:37:42 +08:00
section: 'base',
windowWidth: window?.innerWidth || 0
2024-09-28 00:41:18 +08:00
})
const handleModelLocalPathsUpdate = (config) => {
handleChange('model_local_paths', config)
}
2025-05-05 19:40:23 +08:00
const preHandleChange = (key, e) => {
2024-09-03 16:37:59 +08:00
if (key == 'enable_knowledge_graph' && e && !configStore.config.enable_knowledge_base) {
2024-09-06 12:54:17 +08:00
message.error('启动知识图谱必须请先启用知识库功能')
2024-09-03 16:37:59 +08:00
return
}
2024-09-06 12:54:17 +08:00
if (key == 'enable_knowledge_base' && !e && configStore.config.enable_knowledge_graph) {
message.error('关闭知识库功能必须请先关闭知识图谱功能')
return
}
2024-09-28 00:41:18 +08:00
if (key == 'enable_reranker'
2025-05-05 19:40:23 +08:00
|| key == 'enable_knowledge_graph'
|| key == 'enable_knowledge_base'
|| key == 'embed_model'
|| key == 'reranker'
|| key == 'model_local_paths') {
isNeedRestart.value = true
notification.info({
message: '需要重新加载模型',
description: '请点击右下角按钮重新加载模型',
placement: 'topLeft',
duration: 0,
btn: h(Button, { type: 'primary', onClick: sendRestart }, '立即重新加载')
})
2024-09-28 00:41:18 +08:00
}
2025-05-05 19:40:23 +08:00
return true
}
2024-09-28 00:41:18 +08:00
2025-05-05 19:40:23 +08:00
const handleChange = (key, e) => {
if (!preHandleChange(key, e)) {
return
}
configStore.setConfigValue(key, e)
}
2024-10-08 22:16:17 +08:00
2025-05-05 19:40:23 +08:00
const handleChanges = (items) => {
for (const key in items) {
if (!preHandleChange(key, items[key])) {
return
}
}
configStore.setConfigValues(items)
}
2025-02-27 01:37:42 +08:00
const updateWindowWidth = () => {
state.windowWidth = window?.innerWidth || 0
}
const handleChatModelSelect = ({ provider, name }) => {
configStore.setConfigValues({
model_provider: provider,
model_name: name,
})
}
2025-02-27 01:37:42 +08:00
onMounted(() => {
updateWindowWidth()
window.addEventListener('resize', updateWindowWidth)
})
onUnmounted(() => {
window.removeEventListener('resize', updateWindowWidth)
})
const sendRestart = () => {
console.log('Restarting...')
2024-07-27 14:32:57 +08:00
message.loading({ content: '重新加载模型中', key: "restart", duration: 0 });
2025-05-05 19:40:23 +08:00
2025-05-04 21:04:01 +08:00
systemConfigApi.restartServer()
.then(() => {
console.log('Restarted')
message.success({ content: '重新加载完成!', key: "restart", duration: 2 });
setTimeout(() => {
window.location.reload()
}, 200)
})
.catch(error => {
console.error('重启服务失败:', error)
message.error({ content: `重启失败: ${error.message}`, key: "restart", duration: 2 });
});
}
</script>
<style lang="less" scoped>
2025-05-06 10:37:39 +08:00
.setting-container {
--setting-header-height: 65px;
}
2024-09-28 00:41:18 +08:00
.setting-header {
height: var(--setting-header-height);
2024-09-28 00:41:18 +08:00
}
2024-09-14 02:46:44 +08:00
.setting-header p {
margin: 8px 0 0;
}
.setting-container {
padding: 0;
box-sizing: border-box;
display: flex;
2024-09-28 00:41:18 +08:00
position: relative;
min-height: calc(100vh - var(--setting-header-height));
2024-09-28 00:41:18 +08:00
}
.sider {
width: 200px;
height: 100%;
padding: 0 20px;
position: sticky;
2025-05-06 10:37:39 +08:00
top: var(--setting-header-height);
2024-09-28 00:41:18 +08:00
display: flex;
flex-direction: column;
align-items: center;
border-right: 1px solid var(--main-light-3);
gap: 8px;
padding-top: 20px;
& > * {
width: 100%;
height: auto;
padding: 6px 16px;
cursor: pointer;
transition: all 0.1s;
text-align: left;
font-size: 15px;
border-radius: 8px;
color: var(--gray-700);
&:hover {
background: var(--gray-100);
}
&.activesec {
background: var(--gray-200);
color: var(--gray-900);
}
}
2024-09-14 02:46:44 +08:00
}
.setting {
2024-09-14 02:46:44 +08:00
width: 100%;
2024-09-28 00:41:18 +08:00
flex: 1;
margin: 0 auto;
2024-09-14 02:46:44 +08:00
height: 100%;
2024-09-28 00:41:18 +08:00
padding: 0 20px;
margin-bottom: 40px;
h3 {
margin-top: 20px;
}
.section {
margin-top: 20px;
2024-09-28 00:41:18 +08:00
background-color: var(--gray-10);
padding: 20px;
border-radius: 8px;
display: flex;
flex-direction: column;
gap: 16px;
// box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
2024-09-28 00:41:18 +08:00
border: 1px solid var(--gray-300);
}
.card {
display: flex;
align-items: center;
justify-content: space-between;
.label {
margin-right: 20px;
2024-09-06 21:30:49 +08:00
button {
margin-left: 10px;
height: 24px;
padding: 0 8px;
font-size: smaller;
}
}
}
2025-02-27 01:37:42 +08:00
}
2024-09-28 00:41:18 +08:00
2025-02-27 01:37:42 +08:00
@media (max-width: 520px) {
.setting-container {
flex-direction: column;
}
.card.card-select {
gap: 0.75rem;
align-items: flex-start;
flex-direction: column;
}
}
2024-10-24 13:09:59 +08:00
</style>
<style lang="less">
2025-05-18 17:18:29 +08:00
// 添加全局样式以确保滚动功能在dropdown内正常工作
.ant-dropdown-menu {
&.scrollable-menu {
max-height: 300px;
overflow-y: auto;
}
}
</style>