feat:完善合同起草页面点击高亮以及页面跳转问题

This commit is contained in:
PingChuan
2025-12-08 17:08:56 +08:00
parent 88e3d57351
commit e9c89d6d00
5 changed files with 155 additions and 63 deletions
@@ -304,3 +304,66 @@ export async function replaceTextInPage(
function delay(ms: number): Promise<void> {
return new Promise((resolve) => setTimeout(resolve, ms));
}
/**
* 高亮文本(使用 UNO 命令)
* 流程:先搜索选中所有匹配项,再设置背景色
*
* @param iframeWindow - iframe 的 contentWindow
* @param text - 要高亮的文本
* @param color - 高亮颜色,默认 16776960 = 黄色
*/
export function unoHighlightText(
iframeWindow: Window,
text: string,
color: number = 16776960
): void {
// 1. 查找所有匹配项(FindAll
sendUnoCommand(iframeWindow, '.uno:ExecuteSearch', {
'SearchItem.SearchString': { type: 'string', value: text },
'SearchItem.Command': { type: 'long', value: 1 }, // 1 = FindAll / Search Next
'SearchItem.SearchFlags': { type: 'long', value: 0 },
'SearchItem.AlgorithmType': { type: 'short', value: 0 },
'SearchItem.Backward': { type: 'boolean', value: false },
'SearchItem.SearchCaseSensitive': { type: 'boolean', value: false },
'Quiet': { type: 'boolean', value: true },
});
// 2. 设置背景色高亮
sendUnoCommand(iframeWindow, '.uno:BackColor', {
BackColor: { type: 'long', value: color },
});
console.log('[SearchReplace] 高亮文本:', text, '颜色:', color);
}
/**
* 清除高亮(使用 UNO 命令)
* 通过设置背景色为透明来清除高亮
*
* @param iframeWindow - iframe 的 contentWindow
* @param text - 要清除高亮的文本(可选,不传则清除当前选中)
*/
export function unoClearHighlight(
iframeWindow: Window,
text?: string
): void {
if (text) {
// 先搜索选中文本
sendUnoCommand(iframeWindow, '.uno:ExecuteSearch', {
'SearchItem.SearchString': { type: 'string', value: text },
'SearchItem.Command': { type: 'long', value: 1 },
'SearchItem.SearchFlags': { type: 'long', value: 0 },
'SearchItem.AlgorithmType': { type: 'short', value: 0 },
'SearchItem.Backward': { type: 'boolean', value: false },
'Quiet': { type: 'boolean', value: true },
});
}
// 设置背景色为透明(-1 表示无背景色)
sendUnoCommand(iframeWindow, '.uno:BackColor', {
BackColor: { type: 'long', value: -1 },
});
console.log('[SearchReplace] 清除高亮:', text || '当前选中');
}