Files
hospital-rescue-app-v2/uni_modules/x-screenshot-s/utssdk/app-harmony/index.uts
T
2026-09-24 16:25:22 +08:00

64 lines
1.9 KiB
Plaintext

import { x_getElementShotImage,x_getRootShotImage } from "x_screenshot_s";
/**
* 获取窗口截图
*/
export function getRootShotImage(callback : (str : string) => void) {
x_getRootShotImage(UTSHarmony.getCurrentWindow()!.getUIContext(),callback)
}
/**
* 获取指定元素截图
*/
export function getElementShotImage(ele:UniElement|null, callback : (str : string) => void) {
x_getElementShotImage(UTSHarmony.getCurrentWindow()!.getUIContext(),ele?.getAttribute("id"),callback)
}
/**
* 递归查询
*/
function iterateElement(homeElement : UniElement) : UniNativeViewElement | null {
if ("NATIVE-VIEW" == homeElement.nodeName) {
return homeElement as UniNativeViewElement
}
for (const perChildEle of homeElement.children) {
let findEle = iterateElement(perChildEle)
if (findEle != null) {
return findEle
}
}
return null
}
function getPageRootView(id : string, ins : ComponentPublicInstance | null = null) : FrameNode | null {
if (ins == null) {
const pages = getCurrentPages()
if (pages.length > 0) {
const page = pages[pages.length - 1]
const rootViewElement = page.getElementById(id)
if (rootViewElement != null) {
/**
* 找到了root节点,递归检索目标 native-view
*/
const nativeViewElement = iterateElement(rootViewElement)
if (nativeViewElement != null) {
return nativeViewElement.getHarmonyFrameNode()
}
}
}
} else {
/**
* 尝试迭代遍历
*/
if (ins.$el != null) {
const nativeViewElement = iterateElement(ins.$el as UniElement)
if (nativeViewElement != null) {
return nativeViewElement.getHarmonyFrameNode()
}
}
}
return null
}