diff --git a/packages/uni-app-uts/lib/automator/apis/Element.uts b/packages/uni-app-uts/lib/automator/apis/Element.uts index 66fd12d46378b0b37708d5d85ef0deaaf26c503b..02ff424b1e90d24310359db6565d6a2b15154f82 100644 --- a/packages/uni-app-uts/lib/automator/apis/Element.uts +++ b/packages/uni-app-uts/lib/automator/apis/Element.uts @@ -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(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` }) } } diff --git a/packages/uni-app-uts/lib/automator/apis/Page.uts b/packages/uni-app-uts/lib/automator/apis/Page.uts index 62177f7875258b63b9e3a9b3eab775738f368afd..fd3c19de6a344a51b9c29a34621550130f8255e9 100644 --- a/packages/uni-app-uts/lib/automator/apis/Page.uts +++ b/packages/uni-app-uts/lib/automator/apis/Page.uts @@ -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 })