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

wip(uts): automator

上级 44ae5f89
...@@ -3,7 +3,7 @@ import { JSONObject } from 'com.alibaba.fastjson' ...@@ -3,7 +3,7 @@ import { JSONObject } from 'com.alibaba.fastjson'
import { getChildrenText, toCamelCase } from './util.uts' import { getChildrenText, toCamelCase } from './util.uts'
export type GetElementParams = { export type GetElementParams = {
pageId: number pageId: string
nodeId?: number | null nodeId?: number | null
elementId?: string | null elementId?: string | null
selector: string selector: string
...@@ -43,7 +43,7 @@ export const getElements = (params: GetElementParams): void => { ...@@ -43,7 +43,7 @@ export const getElements = (params: GetElementParams): void => {
} }
export type GetDOMPropertiesParams = { export type GetDOMPropertiesParams = {
pageId: number pageId: string
elementId?: string | null elementId?: string | null
nodeId?: number | null nodeId?: number | null
names: string[] names: string[]
...@@ -77,7 +77,7 @@ export const getDOMProperties = (params: GetDOMPropertiesParams): void => { ...@@ -77,7 +77,7 @@ export const getDOMProperties = (params: GetDOMPropertiesParams): void => {
} }
export type GetPropertiesParams = { export type GetPropertiesParams = {
pageId: number pageId: string
elementId?: string | null elementId?: string | null
nodeId?: number | null nodeId?: number | null
names: string[] names: string[]
...@@ -100,7 +100,7 @@ export const getProperties = (params: GetPropertiesParams): void => { ...@@ -100,7 +100,7 @@ export const getProperties = (params: GetPropertiesParams): void => {
} }
export type GetAttributesParams = { export type GetAttributesParams = {
pageId: number pageId: string
elementId?: string | null elementId?: string | null
nodeId?: number | null nodeId?: number | null
names: string[] names: string[]
...@@ -121,7 +121,7 @@ export const getAttributes = (params: GetAttributesParams): void => { ...@@ -121,7 +121,7 @@ export const getAttributes = (params: GetAttributesParams): void => {
} }
export type CallFunctionParams = { export type CallFunctionParams = {
pageId: number pageId: string
elementId: string elementId: string
functionName: string functionName: string
args: any[] args: any[]
...@@ -141,7 +141,7 @@ export const callFunction = (params: CallFunctionParams): void => { ...@@ -141,7 +141,7 @@ export const callFunction = (params: CallFunctionParams): void => {
} }
export type TapParams = { export type TapParams = {
pageId: number pageId: string
elementId?: string | null elementId?: string | null
nodeId?: number | null nodeId?: number | null
callback: (result: any | null, error: any | null) => void callback: (result: any | null, error: any | null) => void
...@@ -158,7 +158,7 @@ export const tap = (params: TapParams): void => { ...@@ -158,7 +158,7 @@ export const tap = (params: TapParams): void => {
} }
export type CallMethodParams = { export type CallMethodParams = {
pageId: number pageId: string
nodeId: number nodeId: number
method: string method: string
args: any[] args: any[]
...@@ -174,7 +174,7 @@ export const callMethod = (params: CallMethodParams): void => { ...@@ -174,7 +174,7 @@ export const callMethod = (params: CallMethodParams): void => {
} }
export type GetDataParams = { export type GetDataParams = {
pageId: number pageId: string
nodeId: number nodeId: number
path: string path: string
callback: (result: any | null, error: any | null) => void callback: (result: any | null, error: any | null) => void
...@@ -188,7 +188,7 @@ export const getData = (params: GetDataParams): void => { ...@@ -188,7 +188,7 @@ export const getData = (params: GetDataParams): void => {
} }
export type SetDataParams = { export type SetDataParams = {
pageId: number pageId: string
nodeId: number nodeId: number
data: UTSJSONObject data: UTSJSONObject
callback: (result: any | null, error: any | null) => void callback: (result: any | null, error: any | null) => void
...@@ -202,7 +202,7 @@ export const setData = (params: SetDataParams): void => { ...@@ -202,7 +202,7 @@ export const setData = (params: SetDataParams): void => {
} }
export type GetOffsetParams = { export type GetOffsetParams = {
pageId: number pageId: string
elementId?: string | null elementId?: string | null
nodeId?: number | null nodeId?: number | null
callback: (result: any | null, error: any | null) => void callback: (result: any | null, error: any | null) => void
...@@ -216,7 +216,7 @@ export const getOffset = (params: GetOffsetParams): void => { ...@@ -216,7 +216,7 @@ export const getOffset = (params: GetOffsetParams): void => {
} }
export type LongpressParams = { export type LongpressParams = {
pageId: number pageId: string
elementId?: string | null elementId?: string | null
nodeId?: number | null nodeId?: number | null
callback: (result: any | null, error: any | null) => void callback: (result: any | null, error: any | null) => void
...@@ -233,7 +233,7 @@ export const longpress = (params: LongpressParams): void => { ...@@ -233,7 +233,7 @@ export const longpress = (params: LongpressParams): void => {
} }
export type HandleTouchEventParams = { export type HandleTouchEventParams = {
pageId: number pageId: string
elementId?: string | null elementId?: string | null
nodeId?: number | null nodeId?: number | null
eventName: string eventName: string
...@@ -264,7 +264,7 @@ function getTouches(touches: any[]): Touch[] { ...@@ -264,7 +264,7 @@ function getTouches(touches: any[]): Touch[] {
} }
export type GetStylesParams = { export type GetStylesParams = {
pageId: number pageId: string
elementId?: string | null elementId?: string | null
nodeId?: number | null nodeId?: number | null
names: string[] names: string[]
......
import { pageGetData, pageSetData, getPageVm, getValidComponentsOrNodes } from './util.uts' import { pageGetData, pageSetData, getPageVm, getValidComponentsOrNodes } from './util.uts'
export type GetDataParams = { export type GetDataParams = {
pageId: number pageId: string
path: string path: string
callback: (result: any | null, error: any | null) => void callback: (result: any | null, error: any | null) => void
} }
...@@ -17,7 +17,7 @@ export const getData = (params: GetDataParams): void => { ...@@ -17,7 +17,7 @@ export const getData = (params: GetDataParams): void => {
} }
export type SetDataParams = { export type SetDataParams = {
pageId: number pageId: string
data: UTSJSONObject data: UTSJSONObject
callback: (result: any | null, error: any | null) => void callback: (result: any | null, error: any | null) => void
} }
...@@ -33,7 +33,7 @@ export const setData = (params: SetDataParams): void => { ...@@ -33,7 +33,7 @@ export const setData = (params: SetDataParams): void => {
} }
} }
export type CallMethodParams = { export type CallMethodParams = {
pageId: number pageId: string
method: string method: string
args: any[] args: any[]
callback: (result: any | null, error: any | null) => void callback: (result: any | null, error: any | null) => void
...@@ -52,7 +52,7 @@ export const callMethod = (params: CallMethodParams): void => { ...@@ -52,7 +52,7 @@ export const callMethod = (params: CallMethodParams): void => {
} }
export type GetElementParams = { export type GetElementParams = {
pageId: number pageId: string
selector: string selector: string
callback: (result: any | null, error: any | null) => void callback: (result: any | null, error: any | null) => void
} }
...@@ -91,7 +91,7 @@ export const getElements = (params: GetElementParams): void => { ...@@ -91,7 +91,7 @@ export const getElements = (params: GetElementParams): void => {
} }
export type GetWindowPropertiesParams = { export type GetWindowPropertiesParams = {
pageId: number, pageId: string,
names: string[], names: string[],
callback: (result: any | null, error: any | null) => void callback: (result: any | null, error: any | null) => void
} }
......
function getPageId(page: BasePage): number { function getPageId(page: BasePage): string {
return page.$.uid return page.$appPage!.pageId
} }
function getPagePath(page: BasePage): string { function getPagePath(page: BasePage): string {
...@@ -10,7 +10,7 @@ function getPageQuery(page: BasePage): Map<string, string | null> { ...@@ -10,7 +10,7 @@ function getPageQuery(page: BasePage): Map<string, string | null> {
return page.options return page.options
} }
function getPageById(id: number): BasePage | null { function getPageById(id: string): BasePage | null {
const pages = getCurrentPages() const pages = getCurrentPages()
let result: BasePage | null = null let result: BasePage | null = null
pages.forEach((page: BasePage) => { pages.forEach((page: BasePage) => {
...@@ -21,7 +21,7 @@ function getPageById(id: number): BasePage | null { ...@@ -21,7 +21,7 @@ function getPageById(id: number): BasePage | null {
return result return result
} }
export function getPageVm(id: number): BasePage | null { export function getPageVm(id: string): BasePage | null {
return getPageById(id) return getPageById(id)
} }
...@@ -54,7 +54,7 @@ export function parsePage(page: BasePage): UTSJSONObject { ...@@ -54,7 +54,7 @@ export function parsePage(page: BasePage): UTSJSONObject {
} as UTSJSONObject } as UTSJSONObject
} }
export function getComponentVmBySelector(pageId: number, selector: string, callback: (result: any | null, error: any | null) => void): ComponentPublicInstance | null { export function getComponentVmBySelector(pageId: string, selector: string, callback: (result: any | null, error: any | null) => void): ComponentPublicInstance | null {
const page = getPageVm(pageId) const page = getPageVm(pageId)
if (page == null) { if (page == null) {
callback(null, { errMsg: `Page[${pageId}] not exists` }) callback(null, { errMsg: `Page[${pageId}] not exists` })
...@@ -68,7 +68,7 @@ export function getComponentVmBySelector(pageId: number, selector: string, callb ...@@ -68,7 +68,7 @@ export function getComponentVmBySelector(pageId: number, selector: string, callb
return component return component
} }
export function getComponentVmByNodeId(pageId: number, nodeId: number, callback: (result: any | null, error: any | null) => void): ComponentPublicInstance | null { export function getComponentVmByNodeId(pageId: string, nodeId: number, callback: (result: any | null, error: any | null) => void): ComponentPublicInstance | null {
const page = getPageVm(pageId) const page = getPageVm(pageId)
if (page == null) { if (page == null) {
callback(null, { errMsg: `Page[${pageId}] not exists` }) callback(null, { errMsg: `Page[${pageId}] not exists` })
...@@ -76,7 +76,7 @@ export function getComponentVmByNodeId(pageId: number, nodeId: number, callback: ...@@ -76,7 +76,7 @@ export function getComponentVmByNodeId(pageId: number, nodeId: number, callback:
} }
let component: ComponentPublicInstance | null = null let component: ComponentPublicInstance | null = null
function getComponentChild(parent: ComponentPublicInstance) { function getComponentChild(parent: ComponentPublicInstance) {
if (parent.$.uid == nodeId) { if (parent.$.uid.toInt() == nodeId) {
component = parent component = parent
return return
} }
...@@ -92,7 +92,7 @@ export function getComponentVmByNodeId(pageId: number, nodeId: number, callback: ...@@ -92,7 +92,7 @@ export function getComponentVmByNodeId(pageId: number, nodeId: number, callback:
return component return component
} }
export function getElementByIdOrNodeId(pageId: number, elementId: string | null, nodeId: number | null, callback: (result: any | null, error: any | null) => void): INode | null { export function getElementByIdOrNodeId(pageId: string, elementId: string | null, nodeId: number | null, callback: (result: any | null, error: any | null) => void): INode | null {
if (nodeId != null) { if (nodeId != null) {
return getComponentDomByNodeId(pageId, nodeId, callback) return getComponentDomByNodeId(pageId, nodeId, callback)
} else if (elementId != null) { } else if (elementId != null) {
...@@ -101,7 +101,7 @@ export function getElementByIdOrNodeId(pageId: number, elementId: string | null, ...@@ -101,7 +101,7 @@ export function getElementByIdOrNodeId(pageId: number, elementId: string | null,
return null return null
} }
export function getComponentDomByNodeId(pageId: number, nodeId: number, callback: (result: any | null, error: any | null) => void): INode | null { export function getComponentDomByNodeId(pageId: string, nodeId: number, callback: (result: any | null, error: any | null) => void): INode | null {
const component = getComponentVmByNodeId(pageId, nodeId, callback) const component = getComponentVmByNodeId(pageId, nodeId, callback)
if (component == null) { if (component == null) {
return null return null
...@@ -109,7 +109,7 @@ export function getComponentDomByNodeId(pageId: number, nodeId: number, callback ...@@ -109,7 +109,7 @@ export function getComponentDomByNodeId(pageId: number, nodeId: number, callback
return component.$el return component.$el
} }
export function getElementByNodeIdOrElementId(pageId: number, nodeId: number | null, elementId: string | null, callback: (result: any | null, error: any | null) => void): INode | null { export function getElementByNodeIdOrElementId(pageId: string, nodeId: number | null, elementId: string | null, callback: (result: any | null, error: any | null) => void): INode | null {
const page = getPageVm(pageId) const page = getPageVm(pageId)
if (page == null) { if (page == null) {
callback(null, { errMsg: `Page[${pageId}] not exists` }) callback(null, { errMsg: `Page[${pageId}] not exists` })
...@@ -123,7 +123,7 @@ export function getElementByNodeIdOrElementId(pageId: number, nodeId: number | n ...@@ -123,7 +123,7 @@ export function getElementByNodeIdOrElementId(pageId: number, nodeId: number | n
return null return null
} }
export function getElementById(pageId: number, elementId: string, callback: (result: any | null, error: any | null) => void): INode | null { export function getElementById(pageId: string, elementId: string, callback: (result: any | null, error: any | null) => void): INode | null {
const page = getPageVm(pageId) const page = getPageVm(pageId)
if (page == null) { if (page == null) {
callback(null, { errMsg: `Page[${pageId}] not exists` }) callback(null, { errMsg: `Page[${pageId}] not exists` })
......
...@@ -104,7 +104,7 @@ export function onMessage(msg: string) { ...@@ -104,7 +104,7 @@ export function onMessage(msg: string) {
break break
} }
} else if (method.startsWith('Page.')) { } else if (method.startsWith('Page.')) {
const pageId = params['pageId'] as number const pageId = params['pageId'] as string
switch (method) { switch (method) {
case 'Page.getData': case 'Page.getData':
const path = params['path'] != null ? (params['path'] as string) : '' const path = params['path'] != null ? (params['path'] as string) : ''
...@@ -136,7 +136,7 @@ export function onMessage(msg: string) { ...@@ -136,7 +136,7 @@ export function onMessage(msg: string) {
break break
} }
} else if (method.startsWith('Element.')) { } else if (method.startsWith('Element.')) {
const pageId = params['pageId'] as number const pageId = params['pageId'] as string
switch (method) { switch (method) {
case 'Element.getElement': case 'Element.getElement':
const getElementElementId = params['elementId'] != null ? params['elementId'] as string : null const getElementElementId = params['elementId'] != null ? params['elementId'] as string : null
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册