(newOrder: Command[])
| 1568 | |
| 1569 | // 更新固定列表顺序 |
| 1570 | async function updatePinnedOrder(newOrder: Command[]): Promise<void> { |
| 1571 | // 乐观更新:立即更新本地状态,避免等待后端导致的延迟和闪动 |
| 1572 | pinnedCommands.value = newOrder |
| 1573 | |
| 1574 | // 标记这是本地触发的更新 |
| 1575 | isLocalPinnedUpdate = true |
| 1576 | |
| 1577 | // 异步保存到后端,不等待完成 |
| 1578 | // 将 Vue 响应式对象数组转换为纯对象数组,避免 IPC 传递时的克隆错误 |
| 1579 | const plainOrder = JSON.parse(JSON.stringify(newOrder)) |
| 1580 | window.ztools.updatePinnedOrder(plainOrder).catch((error) => { |
| 1581 | console.error('保存固定列表顺序失败:', error) |
| 1582 | // 如果保存失败,重置标志并重新从后端加载数据 |
| 1583 | isLocalPinnedUpdate = false |
| 1584 | loadPinnedData() |
| 1585 | }) |
| 1586 | // 注意:不需要等待 pinned-changed 事件,因为本地已经更新了 |
| 1587 | } |
| 1588 | |
| 1589 | // 清空固定列表 |
| 1590 | async function clearPinned(): Promise<void> { |
nothing calls this directly
no test coverage detected