mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-28 19:43:53 +08:00
不开启通讯录功能时不显示相关工具
关闭通讯录功能清除相关状态
This commit is contained in:
@@ -146,6 +146,11 @@ public interface Constant {
|
|||||||
*/
|
*/
|
||||||
String SERVER_AUTH_ENABLED = "server.auth.enabled";
|
String SERVER_AUTH_ENABLED = "server.auth.enabled";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 系统功能菜单配置
|
||||||
|
*/
|
||||||
|
String SYSTEM_WEB_MENU = "system-web.menu";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 无记忆
|
* 无记忆
|
||||||
*/
|
*/
|
||||||
|
|||||||
+9
-2
@@ -14,7 +14,7 @@ public interface AgentPluginMappingService extends IService<AgentPluginMapping>
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据智能体id获取插件参数
|
* 根据智能体id获取插件参数
|
||||||
*
|
*
|
||||||
* @param agentId
|
* @param agentId
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@@ -22,8 +22,15 @@ public interface AgentPluginMappingService extends IService<AgentPluginMapping>
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据智能体id删除插件参数
|
* 根据智能体id删除插件参数
|
||||||
*
|
*
|
||||||
* @param agentId
|
* @param agentId
|
||||||
*/
|
*/
|
||||||
void deleteByAgentId(String agentId);
|
void deleteByAgentId(String agentId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据插件ID删除所有智能体的插件映射
|
||||||
|
*
|
||||||
|
* @param pluginId 插件ID
|
||||||
|
*/
|
||||||
|
void deleteByPluginId(String pluginId);
|
||||||
}
|
}
|
||||||
|
|||||||
+7
@@ -104,4 +104,11 @@ public class AgentPluginMappingServiceImpl extends ServiceImpl<AgentPluginMappin
|
|||||||
agentPluginMappingMapper.delete(updateWrapper);
|
agentPluginMappingMapper.delete(updateWrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deleteByPluginId(String pluginId) {
|
||||||
|
UpdateWrapper<AgentPluginMapping> updateWrapper = new UpdateWrapper<>();
|
||||||
|
updateWrapper.eq("plugin_id", pluginId);
|
||||||
|
agentPluginMappingMapper.delete(updateWrapper);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-1
@@ -114,7 +114,12 @@ public class SysParamsController {
|
|||||||
// 校验mqtt密钥长度
|
// 校验mqtt密钥长度
|
||||||
validateMqttSecretLength(dto.getParamCode(), dto.getParamValue());
|
validateMqttSecretLength(dto.getParamCode(), dto.getParamValue());
|
||||||
|
|
||||||
sysParamsService.update(dto);
|
// 如果是系统功能菜单配置,使用特殊处理
|
||||||
|
if (Constant.SYSTEM_WEB_MENU.equals(dto.getParamCode())) {
|
||||||
|
sysParamsService.updateSystemWebMenu(dto.getParamValue());
|
||||||
|
} else {
|
||||||
|
sysParamsService.update(dto);
|
||||||
|
}
|
||||||
configService.getConfig(false);
|
configService.getConfig(false);
|
||||||
return new Result<Void>();
|
return new Result<Void>();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,4 +53,19 @@ public interface SysParamsService extends BaseService<SysParamsEntity> {
|
|||||||
* 初始化服务器密钥
|
* 初始化服务器密钥
|
||||||
*/
|
*/
|
||||||
void initServerSecret();
|
void initServerSecret();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取系统功能菜单配置
|
||||||
|
*
|
||||||
|
* @param fromCache 是否从缓存获取
|
||||||
|
* @return 系统功能菜单配置JSON字符串
|
||||||
|
*/
|
||||||
|
String getSystemWebMenu(boolean fromCache);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新系统功能菜单配置(自动处理功能相关的插件清理)
|
||||||
|
*
|
||||||
|
* @param configJson 新的系统功能菜单配置JSON
|
||||||
|
*/
|
||||||
|
void updateSystemWebMenu(String configJson);
|
||||||
}
|
}
|
||||||
|
|||||||
+61
-1
@@ -22,6 +22,7 @@ import xiaozhi.common.service.impl.BaseServiceImpl;
|
|||||||
import xiaozhi.common.utils.ConvertUtils;
|
import xiaozhi.common.utils.ConvertUtils;
|
||||||
import xiaozhi.common.utils.JsonUtils;
|
import xiaozhi.common.utils.JsonUtils;
|
||||||
import xiaozhi.common.utils.SM2Utils;
|
import xiaozhi.common.utils.SM2Utils;
|
||||||
|
import xiaozhi.modules.agent.service.AgentPluginMappingService;
|
||||||
import xiaozhi.modules.sys.dao.SysParamsDao;
|
import xiaozhi.modules.sys.dao.SysParamsDao;
|
||||||
import xiaozhi.modules.sys.dto.SysParamsDTO;
|
import xiaozhi.modules.sys.dto.SysParamsDTO;
|
||||||
import xiaozhi.modules.sys.entity.SysParamsEntity;
|
import xiaozhi.modules.sys.entity.SysParamsEntity;
|
||||||
@@ -35,6 +36,7 @@ import xiaozhi.modules.sys.service.SysParamsService;
|
|||||||
@Service
|
@Service
|
||||||
public class SysParamsServiceImpl extends BaseServiceImpl<SysParamsDao, SysParamsEntity> implements SysParamsService {
|
public class SysParamsServiceImpl extends BaseServiceImpl<SysParamsDao, SysParamsEntity> implements SysParamsService {
|
||||||
private final SysParamsRedis sysParamsRedis;
|
private final SysParamsRedis sysParamsRedis;
|
||||||
|
private final AgentPluginMappingService agentPluginMappingService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PageData<SysParamsDTO> page(Map<String, Object> params) {
|
public PageData<SysParamsDTO> page(Map<String, Object> params) {
|
||||||
@@ -270,4 +272,62 @@ public class SysParamsServiceImpl extends BaseServiceImpl<SysParamsDao, SysParam
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
@Override
|
||||||
|
public String getSystemWebMenu(boolean fromCache) {
|
||||||
|
return getValue(Constant.SYSTEM_WEB_MENU, fromCache);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public void updateSystemWebMenu(String configJson) {
|
||||||
|
// 获取当前配置
|
||||||
|
String currentConfig = getSystemWebMenu(false);
|
||||||
|
Map<String, Object> currentMap = null;
|
||||||
|
Map<String, Object> newMap = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (StringUtils.isNotBlank(currentConfig)) {
|
||||||
|
currentMap = JsonUtils.parseObject(currentConfig, Map.class);
|
||||||
|
}
|
||||||
|
if (StringUtils.isNotBlank(configJson)) {
|
||||||
|
newMap = JsonUtils.parseObject(configJson, Map.class);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RenException(ErrorCode.PARAM_JSON_INVALID);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查addressBook功能是否被关闭
|
||||||
|
if (currentMap != null && newMap != null) {
|
||||||
|
Map<String, Object> currentFeatures = (Map<String, Object>) currentMap.get("features");
|
||||||
|
Map<String, Object> newFeatures = (Map<String, Object>) newMap.get("features");
|
||||||
|
|
||||||
|
if (currentFeatures != null && newFeatures != null) {
|
||||||
|
Object currentAddressBookObj = currentFeatures.get("addressBook");
|
||||||
|
Object newAddressBookObj = newFeatures.get("addressBook");
|
||||||
|
|
||||||
|
Boolean currentEnabled = false;
|
||||||
|
Boolean newEnabled = false;
|
||||||
|
|
||||||
|
if (currentAddressBookObj instanceof Map) {
|
||||||
|
Map<String, Object> currentAddressBook = (Map<String, Object>) currentAddressBookObj;
|
||||||
|
currentEnabled = currentAddressBook.get("enabled") != null
|
||||||
|
? (Boolean) currentAddressBook.get("enabled") : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (newAddressBookObj instanceof Map) {
|
||||||
|
Map<String, Object> newAddressBook = (Map<String, Object>) newAddressBookObj;
|
||||||
|
newEnabled = newAddressBook.get("enabled") != null
|
||||||
|
? (Boolean) newAddressBook.get("enabled") : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 如果之前是启用状态,现在被禁用,删除所有call_device插件
|
||||||
|
if (Boolean.TRUE.equals(currentEnabled) && !Boolean.TRUE.equals(newEnabled)) {
|
||||||
|
agentPluginMappingService.deleteByPluginId("SYSTEM_PLUGIN_CALL_DEVICE");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 更新配置
|
||||||
|
updateValueByCode(Constant.SYSTEM_WEB_MENU, configJson);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -209,16 +209,27 @@ export default {
|
|||||||
|
|
||||||
// 功能状态
|
// 功能状态
|
||||||
featureStatus: {
|
featureStatus: {
|
||||||
mcpAccessPoint: false
|
mcpAccessPoint: false,
|
||||||
|
addressBook: false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
selectedList() {
|
selectedList() {
|
||||||
return this.allFunctions.filter(f => this.selectedNames.includes(f.name));
|
const list = this.allFunctions.filter(f => this.selectedNames.includes(f.name));
|
||||||
|
// 如果通讯录功能未启用,过滤掉设备呼叫设备插件
|
||||||
|
if (!this.featureStatus.addressBook) {
|
||||||
|
return list.filter(f => f.providerCode !== 'call_device');
|
||||||
|
}
|
||||||
|
return list;
|
||||||
},
|
},
|
||||||
unselected() {
|
unselected() {
|
||||||
return this.allFunctions.filter(f => !this.selectedNames.includes(f.name));
|
const list = this.allFunctions.filter(f => !this.selectedNames.includes(f.name));
|
||||||
|
// 如果通讯录功能未启用,过滤掉设备呼叫设备插件
|
||||||
|
if (!this.featureStatus.addressBook) {
|
||||||
|
return list.filter(f => f.providerCode !== 'call_device');
|
||||||
|
}
|
||||||
|
return list;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
@@ -239,11 +250,23 @@ export default {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
value(v) {
|
async value(v) {
|
||||||
this.dialogVisible = v;
|
this.dialogVisible = v;
|
||||||
if (v) {
|
if (v) {
|
||||||
|
// 加载功能状态(需要在初始化选中态之前)
|
||||||
|
await this.loadFeatureStatus();
|
||||||
|
|
||||||
// 对话框打开时,初始化选中态
|
// 对话框打开时,初始化选中态
|
||||||
this.selectedNames = this.functions.map(f => f.name);
|
this.selectedNames = this.functions.map(f => f.name);
|
||||||
|
|
||||||
|
// 如果通讯录功能未启用,从已选列表中移除设备呼叫设备插件
|
||||||
|
if (!this.featureStatus.addressBook) {
|
||||||
|
this.selectedNames = this.selectedNames.filter(name => {
|
||||||
|
const func = this.allFunctions.find(f => f.name === name);
|
||||||
|
return func && func.providerCode !== 'call_device';
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// 把后端传来的 this.functions(带 params)merge 到 allFunctions 上
|
// 把后端传来的 this.functions(带 params)merge 到 allFunctions 上
|
||||||
this.functions.forEach(saved => {
|
this.functions.forEach(saved => {
|
||||||
const idx = this.allFunctions.findIndex(f => f.name === saved.name);
|
const idx = this.allFunctions.findIndex(f => f.name === saved.name);
|
||||||
@@ -255,9 +278,6 @@ export default {
|
|||||||
// 右侧默认指向第一个
|
// 右侧默认指向第一个
|
||||||
this.currentFunction = this.selectedList[0] || null;
|
this.currentFunction = this.selectedList[0] || null;
|
||||||
|
|
||||||
// 加载功能状态
|
|
||||||
this.loadFeatureStatus();
|
|
||||||
|
|
||||||
// 加载MCP数据
|
// 加载MCP数据
|
||||||
this.loadMcpAddress();
|
this.loadMcpAddress();
|
||||||
this.loadMcpTools();
|
this.loadMcpTools();
|
||||||
@@ -274,10 +294,11 @@ export default {
|
|||||||
async loadFeatureStatus() {
|
async loadFeatureStatus() {
|
||||||
// 确保featureManager已初始化完成
|
// 确保featureManager已初始化完成
|
||||||
await featureManager.waitForInitialization();
|
await featureManager.waitForInitialization();
|
||||||
|
|
||||||
const config = featureManager.getConfig();
|
const config = featureManager.getConfig();
|
||||||
this.featureStatus = {
|
this.featureStatus = {
|
||||||
mcpAccessPoint: config.mcpAccessPoint || false
|
mcpAccessPoint: config.mcpAccessPoint || false,
|
||||||
|
addressBook: config.addressBook || false
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -413,7 +434,7 @@ export default {
|
|||||||
this.tempFunctions = {};
|
this.tempFunctions = {};
|
||||||
this.hasSaved = true;
|
this.hasSaved = true;
|
||||||
|
|
||||||
const selected = this.selectedList.map(f => {
|
let selected = this.selectedList.map(f => {
|
||||||
const modified = this.modifiedFunctions[f.name];
|
const modified = this.modifiedFunctions[f.name];
|
||||||
return {
|
return {
|
||||||
id: f.id,
|
id: f.id,
|
||||||
@@ -424,6 +445,11 @@ export default {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 如果通讯录功能未启用,自动取消已选的设备呼叫设备插件
|
||||||
|
if (!this.featureStatus.addressBook) {
|
||||||
|
selected = selected.filter(f => f.providerCode !== 'call_device');
|
||||||
|
}
|
||||||
|
|
||||||
this.$emit('update-functions', selected);
|
this.$emit('update-functions', selected);
|
||||||
this.dialogVisible = false;
|
this.dialogVisible = false;
|
||||||
// 通知父组件对话框已关闭且已保存
|
// 通知父组件对话框已关闭且已保存
|
||||||
|
|||||||
Reference in New Issue
Block a user