temp:备份代码
This commit is contained in:
@@ -19,7 +19,6 @@ export function sendUnoCommand(
|
||||
): void {
|
||||
const message = {
|
||||
MessageId: 'Send_UNO_Command',
|
||||
SendTime: Date.now(),
|
||||
Values: {
|
||||
Command: command,
|
||||
Args: args,
|
||||
@@ -130,10 +129,25 @@ export function unoEscape(iframeWindow: Window): void {
|
||||
}
|
||||
|
||||
/**
|
||||
* 滚动到文档开头
|
||||
* 滚动到文档开头 (带焦点请求)
|
||||
* @param iframeWindow - iframe 的 contentWindow
|
||||
*/
|
||||
export function unoScrollToTop(iframeWindow: Window): void {
|
||||
export async function unoScrollToTop(iframeWindow: Window): Promise<void> {
|
||||
// 1. 先请求 iframe 获取焦点
|
||||
const focusMessage = {
|
||||
MessageId: 'custompostMessage',
|
||||
Values: {
|
||||
Command: 'REQUEST_FOCUS',
|
||||
Args: {},
|
||||
},
|
||||
};
|
||||
console.log('[custompostMessage] 请求焦点 (滚动到顶部)');
|
||||
iframeWindow.postMessage(JSON.stringify(focusMessage), '*');
|
||||
|
||||
// 2. 等待焦点激活
|
||||
await new Promise((resolve) => setTimeout(resolve, 100));
|
||||
|
||||
// 3. 发送滚动命令
|
||||
sendUnoCommand(iframeWindow, '.uno:GoToStartOfDoc', {});
|
||||
}
|
||||
|
||||
@@ -166,3 +180,64 @@ export function unoGetState(iframeWindow: Window): void {
|
||||
console.log('[UNO] 发送 Get_State (.uno:ModifiedStatus) - 等待命令队列执行完成');
|
||||
iframeWindow.postMessage(JSON.stringify(message), '*');
|
||||
}
|
||||
|
||||
/**
|
||||
* 放大文档(固定步长)
|
||||
* @param iframeWindow - iframe 的 contentWindow
|
||||
*/
|
||||
export function unoZoomPlus(iframeWindow: Window): void {
|
||||
sendUnoCommand(iframeWindow, '.uno:ZoomPlus', {});
|
||||
}
|
||||
|
||||
/**
|
||||
* 缩小文档(固定步长)
|
||||
* @param iframeWindow - iframe 的 contentWindow
|
||||
*/
|
||||
export function unoZoomMinus(iframeWindow: Window): void {
|
||||
sendUnoCommand(iframeWindow, '.uno:ZoomMinus', {});
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置文档缩放比例
|
||||
* @param iframeWindow - iframe 的 contentWindow
|
||||
* @param percentage - 缩放百分比(例如:100 表示 100%)
|
||||
*/
|
||||
export function unoSetZoom(iframeWindow: Window, percentage: number): void {
|
||||
sendUnoCommand(iframeWindow, '.uno:Zoom', {
|
||||
Zoom: {
|
||||
type: 'short',
|
||||
value: percentage,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 跳转到指定页面
|
||||
* @param iframeWindow - iframe 的 contentWindow
|
||||
* @param pageNumber - 页码(从1开始)
|
||||
*/
|
||||
export function unoGotoPage(iframeWindow: Window, pageNumber: number): void {
|
||||
sendUnoCommand(iframeWindow, '.uno:GotoPage', {
|
||||
Page: {
|
||||
type: 'long',
|
||||
value: pageNumber,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 跳转到第一页
|
||||
* @param iframeWindow - iframe 的 contentWindow
|
||||
*/
|
||||
export function unoFirstPage(iframeWindow: Window): void {
|
||||
sendUnoCommand(iframeWindow, '.uno:FirstPage', {});
|
||||
}
|
||||
|
||||
/**
|
||||
* 跳转到最后一页
|
||||
* @param iframeWindow - iframe 的 contentWindow
|
||||
*/
|
||||
export function unoLastPage(iframeWindow: Window): void {
|
||||
sendUnoCommand(iframeWindow, '.uno:LastPage', {});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user