1
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user