增加指令配置
This commit is contained in:
parent
7923a945cd
commit
d431076623
49
content.js
49
content.js
@ -46,7 +46,7 @@ function expandParentMenu(span) {
|
||||
if (subMenu) {
|
||||
const title = subMenu.querySelector(".el-sub-menu__title");
|
||||
if (title && !subMenu.classList.contains("is-opened")) {
|
||||
title.click(); // 展开父菜单
|
||||
title.click();
|
||||
console.log("📂 已展开父菜单");
|
||||
}
|
||||
}
|
||||
@ -54,39 +54,40 @@ function expandParentMenu(span) {
|
||||
|
||||
// ========= 4. 路由跳转函数 =========
|
||||
function goToRoute(route) {
|
||||
// 直接修改 hash
|
||||
window.location.hash = route;
|
||||
console.log("✅ 已跳转到路由:", route);
|
||||
}
|
||||
|
||||
// ========= 5. 指令解析(文字/语音共用) =========
|
||||
// ========= 5. 指令配置 =========
|
||||
const COMMANDS = [
|
||||
{ key: "首页", menu: "首页", route: "/首页" },
|
||||
{ key: "添加设备", menu: "添加设备", route: "/添加设备/添加设备" },
|
||||
{ key: "监控中心", menu: "监控中心", route: "/监控中心/监控中心" },
|
||||
];
|
||||
|
||||
// ========= 6. 指令解析(文字 & 语音共用) =========
|
||||
function handleCommand(text) {
|
||||
console.log("📥 收到指令:", text);
|
||||
|
||||
// 找菜单 DOM
|
||||
const span = [...document.querySelectorAll("span")]
|
||||
.find(el => el.innerText.trim() === text);
|
||||
|
||||
if (text.includes("添加设备")) {
|
||||
// 展开父菜单(如果存在)
|
||||
span && expandParentMenu(span);
|
||||
// 路由跳转
|
||||
goToRoute("/添加设备/添加设备");
|
||||
return;
|
||||
}
|
||||
|
||||
if (text.includes("设备")) {
|
||||
span && expandParentMenu(span);
|
||||
goToRoute("/设备管理");
|
||||
return;
|
||||
}
|
||||
const command = COMMANDS.find(c => text.includes(c.key));
|
||||
|
||||
if (!command) {
|
||||
alert("未识别指令:" + text);
|
||||
return;
|
||||
}
|
||||
|
||||
// ========= 6. 文字输入支持 =========
|
||||
const input = panel.querySelector("#voiceTextInput");
|
||||
// 找菜单 DOM 并展开父菜单
|
||||
const span = [...document.querySelectorAll("span")]
|
||||
.find(el => el.innerText.trim() === command.menu);
|
||||
|
||||
span && expandParentMenu(span);
|
||||
|
||||
// 路由跳转
|
||||
goToRoute(command.route);
|
||||
}
|
||||
|
||||
// ========= 7. 文字输入支持 =========
|
||||
const input = panel.querySelector("#voiceTextInput");
|
||||
input.addEventListener("keydown", (e) => {
|
||||
if (e.key === "Enter") {
|
||||
const value = input.value.trim();
|
||||
@ -97,7 +98,7 @@ input.addEventListener("keydown", (e) => {
|
||||
}
|
||||
});
|
||||
|
||||
// ========= 7. 语音识别支持 =========
|
||||
// ========= 8. 语音识别支持 =========
|
||||
let recognition;
|
||||
if (supportSpeech) {
|
||||
recognition = new SpeechRecognition();
|
||||
@ -122,7 +123,7 @@ if (supportSpeech) {
|
||||
panel.querySelector("#voiceBtn").innerText = "❌";
|
||||
}
|
||||
|
||||
// ========= 8. 快捷键 Alt+V 支持语音 =========
|
||||
// ========= 9. 快捷键 Alt+V 支持语音 =========
|
||||
document.addEventListener("keydown", (e) => {
|
||||
if (e.altKey && e.key.toLowerCase() === "v") {
|
||||
if (supportSpeech && recognition) recognition.start();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user