Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-app
提交
f737694f
U
uni-app
项目概览
DCloud
/
uni-app
6 个月 前同步成功
通知
751
Star
38709
Fork
3642
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
8
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
8
Issue
8
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
f737694f
编写于
6月 27, 2023
作者:
DCloud-WZF
💬
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
wip(uts): automator element.attribute
上级
8e0c1c35
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
30 addition
and
1 deletion
+30
-1
packages/uni-app-uts/lib/automator/apis/Element.uts
packages/uni-app-uts/lib/automator/apis/Element.uts
+23
-0
packages/uni-app-uts/lib/automator/index.uts
packages/uni-app-uts/lib/automator/index.uts
+7
-0
packages/uni-automator/dist/index.js
packages/uni-automator/dist/index.js
+0
-1
未找到文件。
packages/uni-app-uts/lib/automator/apis/Element.uts
浏览文件 @
f737694f
...
...
@@ -265,3 +265,26 @@ function getTouches(touches: any[]): Touch[] {
return result
})
}
export type GetAttributesParams = {
pageId: number
elementId?: string | null
nodeId?: number | null
names: string[]
callback: (res?: any | null) => void
}
export const getAttributes = (params: GetAttributesParams): void => {
let dom: INode | null = null
if (params.elementId !== null) {
dom = getElementById(params.pageId, params.elementId!, params.callback)
} else if (params.nodeId !== null) {
dom = getComponentDomByNodeId(params.pageId, params.nodeId!, params.callback)
}
if (dom !== null) {
const attributes = params.names.map((name: string): any | null => {
return dom.getAttribute(name)
})
params.callback({ attributes })
}
}
packages/uni-app-uts/lib/automator/index.uts
浏览文件 @
f737694f
...
...
@@ -46,6 +46,8 @@ import {
longpress,
HandleTouchEventParams,
handleTouchEvent,
GetAttributesParams,
getAttributes,
} from './apis/Element.uts'
let socketTask: SocketTask | null = null
...
...
@@ -200,6 +202,11 @@ export function onMessage(msg: string) {
const touchstartChangedTouches = ((params['changedTouches'] as UTSJSONObject).toJSONObject() as JSONArray).toUTSArray()
handleTouchEvent({ pageId, elementId: touchstartElementId, nodeId: touchstartNodeId, eventName, touches: touchstartTouches, changedTouches: touchstartChangedTouches, callback } as HandleTouchEventParams)
break
case 'Element.getAttributes':
const getAttributesElementId = params['elementId'] !== null ? params['elementId'] as string : null
const getAttributesNodeId = params['nodeId'] !== null ? params['nodeId'] as number : null
const getAttributesNames = ((params['names'] as UTSJSONObject).toJSONObject() as JSONArray).toUTSArray() as string[]
getAttributes({ pageId, elementId: getAttributesElementId, nodeId: getAttributesNodeId, names: getAttributesNames, callback } as GetAttributesParams)
}
}
} catch (error) {
...
...
packages/uni-automator/dist/index.js
浏览文件 @
f737694f
process
.
env
.
DEBUG
=
"
automator:*
"
"
use strict
"
;
Object
.
defineProperty
(
exports
,
"
__esModule
"
,
{
value
:
!
0
});
var
t
=
require
(
"
fs
"
),
e
=
require
(
"
path
"
),
n
=
require
(
"
debug
"
),
s
=
require
(
"
merge
"
),
o
=
require
(
"
jsonc-parser
"
),
i
=
require
(
"
licia/isRelative
"
),
r
=
require
(
"
ws
"
),
a
=
require
(
"
events
"
),
c
=
require
(
"
licia/uuid
"
),
l
=
require
(
"
licia/stringify
"
),
p
=
require
(
"
licia/dateFormat
"
),
u
=
require
(
"
licia/waitUntil
"
),
h
=
require
(
"
licia/fs
"
),
d
=
require
(
"
licia/isFn
"
),
m
=
require
(
"
licia/trim
"
),
g
=
require
(
"
licia/isStr
"
),
y
=
require
(
"
licia/startWith
"
),
v
=
require
(
"
licia/isNum
"
),
f
=
require
(
"
licia/sleep
"
),
w
=
require
(
"
licia/isUndef
"
),
P
=
require
(
"
address
"
),
M
=
require
(
"
default-gateway
"
),
k
=
require
(
"
licia/getPort
"
),
E
=
require
(
"
qrcode-terminal
"
),
I
=
require
(
"
child_process
"
),
b
=
require
(
"
licia/toStr
"
);
function
C
(
t
)
{
return
t
&&
"
object
"
==
typeof
t
&&
"
default
"
in
t
?
t
:
{
default
:
t
}
}
var
T
=
C
(
t
),
A
=
C
(
e
),
N
=
C
(
n
),
S
=
C
(
i
),
U
=
C
(
r
),
D
=
C
(
c
),
j
=
C
(
l
),
R
=
C
(
p
),
_
=
C
(
u
),
x
=
C
(
h
),
O
=
C
(
d
),
q
=
C
(
m
),
$
=
C
(
g
),
F
=
C
(
y
),
L
=
C
(
v
),
H
=
C
(
f
),
W
=
C
(
w
),
B
=
C
(
P
),
J
=
C
(
M
),
X
=
C
(
k
),
V
=
C
(
E
),
G
=
C
(
b
);
class
z
extends
a
.
EventEmitter
{
constructor
(
t
)
{
super
(),
this
.
ws
=
t
,
this
.
ws
.
addEventListener
(
"
message
"
,
(
t
=>
{
this
.
emit
(
"
message
"
,
t
.
data
)
})),
this
.
ws
.
addEventListener
(
"
close
"
,
(()
=>
{
this
.
emit
(
"
close
"
)
}))
}
send
(
t
)
{
this
.
ws
.
send
(
t
)
}
close
()
{
this
.
ws
.
close
()
}
}
const
K
=
new
Map
,
Y
=
[
"
onCompassChange
"
,
"
onThemeChange
"
,
"
onUserCaptureScreen
"
,
"
onWindowResize
"
,
"
onMemoryWarning
"
,
"
onAccelerometerChange
"
,
"
onKeyboardHeightChange
"
,
"
onNetworkStatusChange
"
,
"
onPushMessage
"
,
"
onLocationChange
"
,
"
onGetWifiList
"
,
"
onWifiConnected
"
,
"
onWifiConnectedWithPartialInfo
"
];
const
Q
=
new
Map
;
function
Z
(
t
,
e
)
{
(
null
==
t
?
void
0
:
t
.
success
)
&&
"
function
"
==
typeof
(
null
==
t
?
void
0
:
t
.
success
)
&&
(
e
?
t
.
success
(
e
)
:
t
.
success
()),
(
null
==
t
?
void
0
:
t
.
complete
)
&&
"
function
"
==
typeof
(
null
==
t
?
void
0
:
t
.
complete
)
&&
(
e
?
t
.
complete
(
e
)
:
t
.
complete
())
}
function
tt
(
t
,
e
)
{
(
null
==
t
?
void
0
:
t
.
fail
)
&&
"
function
"
==
typeof
(
null
==
t
?
void
0
:
t
.
fail
)
&&
(
e
?
t
.
fail
(
e
)
:
t
.
fail
()),
(
null
==
t
?
void
0
:
t
.
complete
)
&&
"
function
"
==
typeof
(
null
==
t
?
void
0
:
t
.
complete
)
&&
(
e
?
t
.
complete
(
e
)
:
t
.
complete
())
}
const
et
=
"
Connection closed
"
;
class
nt
extends
a
.
EventEmitter
{
constructor
(
t
,
e
,
n
)
{
super
(),
this
.
puppet
=
e
,
this
.
namespace
=
n
,
this
.
callbacks
=
new
Map
,
this
.
transport
=
t
,
this
.
debug
=
N
.
default
(
"
automator:protocol:
"
+
this
.
namespace
),
this
.
onMessage
=
t
=>
{
var
e
,
n
;
this
.
debug
(
`
${
R
.
default
(
"
yyyy-mm-dd HH:MM:ss:l
"
)}
◀ RECV
${
t
}
`
);
const
{
id
:
s
,
method
:
o
,
error
:
i
,
result
:
r
,
params
:
a
}
=
JSON
.
parse
(
t
);
if
(
null
===
(
e
=
null
==
r
?
void
0
:
r
.
method
)
||
void
0
===
e
?
void
0
:
e
.
startsWith
(
"
on
"
))
return
void
((
t
,
e
,
n
)
=>
{
const
s
=
K
.
get
(
t
);
(
null
==
s
?
void
0
:
s
.
has
(
e
))
&&
s
.
get
(
e
)(
n
)
})(
r
.
method
,
s
,
r
);
if
(
null
===
(
n
=
null
==
r
?
void
0
:
r
.
method
)
||
void
0
===
n
?
void
0
:
n
.
startsWith
(
"
Socket.
"
))
{
return
void
((
t
,
e
,
n
)
=>
{
const
s
=
Q
.
get
(
e
);
(
null
==
s
?
void
0
:
s
.
has
(
t
))
&&
s
.
get
(
t
)(
n
)
})(
r
.
method
.
replace
(
"
Socket.
"
,
""
),
r
.
id
,
r
.
data
)
}
if
(
!
s
)
return
this
.
puppet
.
emit
(
o
,
a
);
const
{
callbacks
:
c
}
=
this
;
if
(
s
&&
c
.
has
(
s
))
{
const
t
=
c
.
get
(
s
);
c
.
delete
(
s
),
i
?
t
.
reject
(
Error
(
i
.
message
||
i
.
detailMessage
))
:
t
.
resolve
(
r
)
}
},
this
.
onClose
=
()
=>
{
this
.
callbacks
.
forEach
((
t
=>
{
t
.
reject
(
Error
(
et
))
}))
},
this
.
transport
.
on
(
"
message
"
,
this
.
onMessage
),
this
.
transport
.
on
(
"
close
"
,
this
.
onClose
)
}
send
(
t
,
e
=
{},
n
=
!
0
)
{
if
(
n
&&
this
.
puppet
.
adapter
.
has
(
t
))
return
this
.
puppet
.
adapter
.
send
(
this
,
t
,
e
);
const
s
=
D
.
default
(),
o
=
j
.
default
({
id
:
s
,
method
:
t
,
params
:
e
});
return
this
.
debug
(
`
${
R
.
default
(
"
yyyy-mm-dd HH:MM:ss:l
"
)}
SEND ►
${
o
}
`
),
new
Promise
(((
t
,
e
)
=>
{
try
{
this
.
transport
.
send
(
o
)
}
catch
(
t
)
{
e
(
Error
(
et
))
}
this
.
callbacks
.
set
(
s
,
{
resolve
:
t
,
reject
:
e
})
}))
}
dispose
()
{
this
.
transport
.
close
()
}
static
createDevtoolConnection
(
t
,
e
)
{
return
new
Promise
(((
n
,
s
)
=>
{
const
o
=
new
U
.
default
(
t
);
o
.
addEventListener
(
"
open
"
,
(()
=>
{
n
(
new
nt
(
new
z
(
o
),
e
,
"
devtool
"
))
})),
o
.
addEventListener
(
"
error
"
,
s
)
}))
}
static
createRuntimeConnection
(
t
,
e
,
n
)
{
return
new
Promise
(((
s
,
o
)
=>
{
N
.
default
(
"
automator:runtime
"
)(
`
${
R
.
default
(
"
yyyy-mm-dd HH:MM:ss:l
"
)}
port=
${
t
}
`
);
const
i
=
new
U
.
default
.
Server
({
port
:
t
});
_
.
default
((
async
()
=>
{
if
(
e
.
runtimeConnection
)
return
!
0
}),
n
,
1
e3
).
catch
((()
=>
{
i
.
close
(),
o
(
"
Failed to connect to runtime, please make sure the project is running
"
)
})),
i
.
on
(
"
connection
"
,
(
function
(
t
)
{
N
.
default
(
"
automator:runtime
"
)(
`
${
R
.
default
(
"
yyyy-mm-dd HH:MM:ss:l
"
)}
connected`
);
const
n
=
new
nt
(
new
z
(
t
),
e
,
"
runtime
"
);
e
.
setRuntimeConnection
(
n
),
s
(
n
)
})),
e
.
setRuntimeServer
(
i
)
}))
}
}
async
function
st
(
t
,
e
)
{
const
[
n
,
s
]
=
function
(
t
)
{
return
$
.
default
(
t
)
?
[
!
0
,
[
t
]]
:
[
!
1
,
t
]
}(
e
),
o
=
await
t
(
s
);
return
n
?
o
[
0
]
:
o
}
function
ot
(
t
)
{
try
{
return
require
(
t
)
}
catch
(
e
)
{
return
require
(
require
.
resolve
(
t
,
{
paths
:
[
process
.
cwd
()]
}))
}
}
/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录