update:完成在web端,修改提示词功能

This commit is contained in:
hrz
2025-02-15 19:38:32 +08:00
parent aa71968a91
commit 2baba43946
6 changed files with 82 additions and 18 deletions
+8 -3
View File
@@ -1,5 +1,7 @@
import logging
from aiohttp import web
from config.settings import update_config
from ruamel.yaml.scalarstring import PreservedScalarString
from manager.api.auth import verify_token
from manager.api.response import response_unauthorized, response_success, response_error
@@ -28,10 +30,13 @@ class PromptApi:
if 'prompt' not in data:
return response_success()
self.config['prompt'] = data['prompt']
# TODO 保存到配置文件
return response_success()
# 使用PreservedScalarString保留多行文本格式
self.config['prompt'] = PreservedScalarString(data['prompt'])
# 保存到配置文件
update_config(self.config)
return response_success()
except Exception as e:
logger.error(f"Failed to update prompt: {e}")
return response_error(str(e))
+26 -3
View File
@@ -60,7 +60,30 @@ body {
}
@keyframes gradient {
0% { background-position: 0% 50% }
50% { background-position: 100% 50% }
100% { background-position: 0% 50% }
0% {
background-position: 0% 50%
}
50% {
background-position: 100% 50%
}
100% {
background-position: 0% 50%
}
}
.user-menu {
position: fixed;
top: 23px;
right: 32px;
z-index: 1000;
cursor: pointer;
}
.user-info {
align-items: center;
}
.user-name {
font-size: 14px;
color: #606266;
}
+27 -6
View File
@@ -51,15 +51,26 @@
<div class="animated-bg"></div>
<app-header>xiaozhi-esp32-server</app-header>
<div class="content-container">
<div class="role-title">配置角色:</div>
<div class="role-id">cc:ba:97:11:a6:ac</div>
<div class="user-menu">
<el-dropdown @command="handleCommand">
<div class="user-info">
<el-avatar :size="32" src="https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png"/>
<span class="user-name">管理员</span>
</div>
<template #dropdown>
<el-dropdown-menu>
<el-dropdown-item command="logout">退出</el-dropdown-item>
</el-dropdown-menu>
</template>
</el-dropdown>
</div>
<div class="content-container">
<div class="role-description">角色介绍</div>
<el-input
type="textarea"
v-model="form.prompt"
:rows="6"
:rows="10"
resize="vertical"
@input="updateCharCount"
></el-input>
@@ -67,7 +78,7 @@
<div class="button-group">
<el-button type="primary" @click="savePrompt">保存配置</el-button>
<el-button @click="resetPrompt">重置</el-button>
<el-button @click="loadPrompt">重置</el-button>
</div>
<div class="note">注意:保存配置后,需要重启设备,新的配置才会生效。</div>
@@ -121,7 +132,17 @@
});
}
});
}
},
// 新增退出处理方法
handleCommand(command) {
if (command === 'logout') {
this.handleLogout();
}
},
handleLogout() {
localStorage.removeItem('token');
location.href = 'login.html';
},
},
mounted() {
this.loadPrompt();