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

wip(uts): automator element.scrollTo

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