mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-22 07:03:53 +08:00
fix: 修复 mobile 短信验证码错误重复提示、智能体插件保存异常问题
This commit is contained in:
@@ -587,15 +587,6 @@ function handleTools() {
|
||||
})
|
||||
}
|
||||
|
||||
// 监听插件配置更新
|
||||
function watchPluginUpdates() {
|
||||
// 监听store中的插件配置变化
|
||||
watch(() => pluginStore.currentFunctions, (newFunctions) => {
|
||||
console.log('插件配置已更新:', newFunctions)
|
||||
formData.value.functions = newFunctions
|
||||
}, { deep: true })
|
||||
}
|
||||
|
||||
// 获取智能体标签
|
||||
async function loadAgentTags() {
|
||||
try {
|
||||
@@ -611,9 +602,12 @@ async function handleUpdateAgentTags() {
|
||||
await updateAgentTags(agentId.value, { tagNames })
|
||||
}
|
||||
|
||||
// 监听store中的插件配置变化
|
||||
watch(() => pluginStore.currentFunctions, (newFunctions) => {
|
||||
formData.value.functions = newFunctions
|
||||
}, { deep: true })
|
||||
|
||||
onMounted(async () => {
|
||||
// 初始化插件配置监听
|
||||
watchPluginUpdates()
|
||||
loadAgentTags()
|
||||
|
||||
// 先加载模型选项和角色模板
|
||||
|
||||
@@ -11,8 +11,8 @@
|
||||
<script lang="ts" setup>
|
||||
import { useMessage } from 'wot-design-uni'
|
||||
import { getMcpAddress, getMcpTools } from '@/api/agent/agent'
|
||||
import { usePluginStore } from '@/store'
|
||||
import { t } from '@/i18n'
|
||||
import { usePluginStore } from '@/store'
|
||||
|
||||
const message = useMessage()
|
||||
const pluginStore = usePluginStore()
|
||||
@@ -30,8 +30,8 @@ const mcpAddress = ref('')
|
||||
const mcpTools = ref<string[]>([])
|
||||
|
||||
// 初始化时从本地存储加载MCP地址
|
||||
if (uni.getStorageSync('cachedMcpAddress_' + agentId.value)) {
|
||||
mcpAddress.value = uni.getStorageSync('cachedMcpAddress_' + agentId.value)
|
||||
if (uni.getStorageSync(`cachedMcpAddress_${agentId.value}`)) {
|
||||
mcpAddress.value = uni.getStorageSync(`cachedMcpAddress_${agentId.value}`)
|
||||
}
|
||||
|
||||
// 参数编辑相关
|
||||
@@ -67,16 +67,18 @@ async function mergeFunctions() {
|
||||
const address = await getMcpAddress(agentId.value)
|
||||
mcpAddress.value = address
|
||||
// 缓存到本地存储,下次打开页面可以立即显示
|
||||
uni.setStorageSync('cachedMcpAddress_' + agentId.value, address)
|
||||
} catch (error) {
|
||||
uni.setStorageSync(`cachedMcpAddress_${agentId.value}`, address)
|
||||
}
|
||||
catch (error) {
|
||||
console.error('获取MCP地址失败:', error)
|
||||
}
|
||||
|
||||
|
||||
// 异步获取MCP工具列表,不阻塞UI显示
|
||||
try {
|
||||
const tools = await getMcpTools(agentId.value)
|
||||
mcpTools.value = tools || []
|
||||
} catch (error) {
|
||||
}
|
||||
catch (error) {
|
||||
console.error('获取MCP工具列表失败:', error)
|
||||
}
|
||||
}
|
||||
@@ -85,12 +87,12 @@ async function mergeFunctions() {
|
||||
// 添加插件到已选
|
||||
function selectFunction(func: any) {
|
||||
// 添加到已选列表
|
||||
selectedList.value.push({
|
||||
selectedList.value = [...selectedList.value, {
|
||||
id: func.id,
|
||||
name: func.name,
|
||||
params: { ...func.params },
|
||||
fieldsMeta: func.fieldsMeta,
|
||||
})
|
||||
}]
|
||||
|
||||
// 从未选列表中移除
|
||||
notSelectedList.value = notSelectedList.value.filter(
|
||||
@@ -206,15 +208,6 @@ function closeParamEdit() {
|
||||
|
||||
// 返回上一页并更新配置
|
||||
function goBack() {
|
||||
const finalFunctions = selectedList.value.map(f => ({
|
||||
pluginId: f.id,
|
||||
paramInfo: f.params,
|
||||
}))
|
||||
|
||||
// 更新到store中
|
||||
pluginStore.updateFunctions(finalFunctions)
|
||||
|
||||
// 直接返回
|
||||
uni.navigateBack()
|
||||
}
|
||||
|
||||
@@ -229,11 +222,11 @@ function copyMcpAddress() {
|
||||
data: mcpAddress.value,
|
||||
showToast: false,
|
||||
success: () => {
|
||||
message.alert(t('agent.tools.mcpAddressCopied'))
|
||||
},
|
||||
message.alert(t('agent.tools.mcpAddressCopied'))
|
||||
},
|
||||
fail: () => {
|
||||
message.alert(t('agent.tools.copyFailed'))
|
||||
},
|
||||
message.alert(t('agent.tools.copyFailed'))
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
@@ -254,6 +247,15 @@ function getFieldRemark(field: any) {
|
||||
return description
|
||||
}
|
||||
|
||||
// 监听已选列表变化,实时更新插件配置,避免用户不点击返回按钮导致配置丢失
|
||||
watch(() => selectedList.value, (newSelectedList) => {
|
||||
const finalFunctions = newSelectedList.map(f => ({
|
||||
pluginId: f.id,
|
||||
paramInfo: f.params,
|
||||
}))
|
||||
pluginStore.updateFunctions(finalFunctions)
|
||||
})
|
||||
|
||||
onMounted(async () => {
|
||||
// 直接从store获取数据并合并
|
||||
await mergeFunctions()
|
||||
@@ -407,11 +409,11 @@ onMounted(async () => {
|
||||
class="flex-1 rounded-[10rpx] bg-[#f5f7fb] p-[20rpx]"
|
||||
>
|
||||
<view
|
||||
class="ml-[20rpx] h-[70rpx] flex items-center justify-center rounded-[10rpx] bg-[#1677ff] px-[20rpx] text-[24rpx] text-white"
|
||||
@click="copyMcpAddress"
|
||||
>
|
||||
{{ t('agent.tools.copy') }}
|
||||
</view>
|
||||
class="ml-[20rpx] h-[70rpx] flex items-center justify-center rounded-[10rpx] bg-[#1677ff] px-[20rpx] text-[24rpx] text-white"
|
||||
@click="copyMcpAddress"
|
||||
>
|
||||
{{ t('agent.tools.copy') }}
|
||||
</view>
|
||||
</view>
|
||||
<!-- 工具列表 -->
|
||||
<view class="mt-[20rpx] flex-1 overflow-hidden">
|
||||
|
||||
@@ -240,14 +240,6 @@ async function handleLogin() {
|
||||
catch (error: any) {
|
||||
// 登录失败重新获取验证码
|
||||
refreshCaptcha()
|
||||
// 处理验证码错误 - 从error.message中解析错误码
|
||||
if (error.message.includes('请求错误[10067]')) {
|
||||
toast.warning(t('login.captchaError'))
|
||||
}
|
||||
// 处理账号或密码错误
|
||||
else if (error.message.includes('请求错误[10004]')) {
|
||||
toast.warning(t('message.passwordError'))
|
||||
}
|
||||
}
|
||||
finally {
|
||||
loading.value = false
|
||||
|
||||
Reference in New Issue
Block a user