提交 26fe5da5 编写于 作者: DCloud-WZF's avatar DCloud-WZF 💬

wip(uts): automator element.scrollTo

上级 576a0725
......@@ -193,14 +193,18 @@ export type CallFunctionParams = {
functionName: string
args: any[]
}
type Coordinate = {
x: number
y: number
}
export const callFunction = (
params: CallFunctionParams,
callback: Callback
): void => {
const element = getElementById(params.pageId, params.elementId, callback)
if (element != null) {
switch (params.functionName) {
const functionName = params.functionName
switch (functionName) {
case 'input.input':
element.dispatchEvent(
'input',
......@@ -208,8 +212,31 @@ export const callFunction = (
InputEvent('input', InputEventDetail(params.args[0] as string, 0, 0))
)
break
case 'scroll-view.scrollTo':
if (element.tagName == 'SCROLL-VIEW') {
// @ts-ignore
const arg = JSON.parse<Coordinate>(JSON.stringify(params.args[0]))!
element.setAttribute('scrollLeft', arg.x)
element.setAttribute('scrollTop', arg.y)
callback({ result: `${functionName} success` }, null)
} else {
callback({ result: `${functionName} fail, element is not scroll-view` }, null)
}
break
case 'swiper.swipeTo':
if (element.tagName == 'SWIPER') {
callback(null, { errMsg: `${functionName} not support` })
} else {
callback({ result: `${functionName} fail, element is not swiper` }, null)
return
}
break
default:
callback(null, { errMsg: `${functionName} not support` })
break
}
callback({ result: `Element.callFunction success` }, null)
} else {
callback(null, { errMsg: `Element not exists` })
}
}
......
......@@ -100,18 +100,19 @@ export type GetWindowPropertiesParams = {
export const getWindowProperties = (params: GetWindowPropertiesParams, callback: Callback): void => {
const page = getPageVm(params.pageId)
if (page == null) {
callback(null, { errMsg: 'Page.getData:fail, Page not found.' })
callback(null, { errMsg: 'Page.getWindowProperties:fail, Page not found.' })
return
}
// TODO: 待客户端支持
// const document = page.$appPage!.document
const properties = params.names.map((name): any | null => {
switch (name) {
case 'document.documentElement.scrollTop':
const document = page.$appPage!.document
// TODO: 确认根节点
const scrollViews = document.getElementsByTagName('SCROLL-VIEW')
const scrollView = scrollViews.size > 0 ? scrollViews[0] : null
const scrollTop: any | null = scrollView != null ? scrollView.getAttribute('scrollTop') : 0
return scrollTop == null ? 0 : scrollTop
case 'document.documentElement.scrollWidth':
// return document.scrollWidth
return 0
case 'document.documentElement.scrollHeight':
// return document.scrollHeight
return 0
}
return null
})
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册