fix(webui): 菜单锚点用 anchorElement;开发环境 mock 匹配去掉 shell 引号

- md-menu 的 anchor 是 idref 字符串,元素引用必须走 anchorElement,
  且需在打开前设置,否则菜单无锚点无法定位(表现为点不开)
- callJSON 会给参数加单引号,devMock 直接匹配命令串失效,
  导致普通浏览器里退化成真实执行并报 'ksu is not defined'
This commit is contained in:
YuleBest committed 2026-09-10 10:01:26 +08:00
1 parent 7200793d17
commit a7bb624eec
2 files changed
+19 -17

No files matched your search

+11 -9
View File
@@ -63,17 +63,19 @@ const ok = (obj) => ({ ok: true, errno: 0, stdout: JSON.stringify(obj), stderr:
/** 依据命令内容返回模拟响应;无法识别时返回 null */
export function devMock(command) {
if (command.includes(' config read')) return ok(mockConfig())
if (command.includes(' config patch') || command.includes(' config set')) return ok({ ok: true })
if (command.includes(' status')) return ok(mockStatus(!command.includes('--no-display')))
if (command.includes(' oplock')) return ok({ locked: false, seconds: 0 })
if (command.includes(' focus')) return ok({ focus: 'com.example.video/.MainActivity' })
if (command.includes(' brightness set')) return ok({ ok: true, value: 2000 })
if (command.includes(' log tail')) {
// 参数经 shellQuote 包装过,比较前先去掉单引号
const plain = command.replace(/'/g, '')
if (plain.includes(' config read')) return ok(mockConfig())
if (plain.includes(' config patch') || plain.includes(' config set')) return ok({ ok: true })
if (plain.includes(' status')) return ok(mockStatus(!plain.includes('--no-display')))
if (plain.includes(' oplock')) return ok({ locked: false, seconds: 0 })
if (plain.includes(' focus')) return ok({ focus: 'com.example.video/.MainActivity' })
if (plain.includes(' brightness set')) return ok({ ok: true, value: 2000 })
if (plain.includes(' log tail')) {
return ok({ entries: mockLogEntries, sizeKB: 12, total: mockLogEntries.length })
}
if (command.includes(' log clear') || command.includes(' log export')) return ok({ ok: true })
if (command.includes('boost') || command.includes('restart') || command.includes('action.sh')) {
if (plain.includes(' log clear') || plain.includes(' log export')) return ok({ ok: true })
if (plain.includes('boost') || plain.includes('restart') || plain.includes('action.sh')) {
return { ok: true, errno: 0, stdout: 'LuminPro: 服务已启用', stderr: '' }
}
return null
+8 -8
View File
@@ -1,8 +1,8 @@
<script setup>
import { ref, watch, nextTick } from 'vue'
import { ref } from 'vue'
import { MoreVertical } from 'lucide-vue-next'
const props = defineProps({
defineProps({
items: { type: Array, default: () => [] }, // [{ key, label }]
title: { type: String, default: '更多' },
disabled: { type: Boolean, default: false },
@@ -13,13 +13,13 @@ const open = ref(false)
const anchorEl = ref(null)
const menuEl = ref(null)
async function toggle() {
function toggle() {
const menu = menuEl.value
if (!menu) return
// 注意:md-menu 的 anchor 是 idref 字符串,元素引用必须用 anchorElement;
// 且必须在打开前设置——菜单打开时会立刻按锚点定位
if (anchorEl.value) menu.anchorElement = anchorEl.value
open.value = !open.value
if (open.value) {
await nextTick()
// MWC 菜单需要通过属性接收锚点元素(不能用 attribute 绑定)
if (menuEl.value && anchorEl.value) menuEl.value.anchor = anchorEl.value
}
}
function pick(item) {