Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello uni-app x
提交
7e06885a
H
hello uni-app x
项目概览
DCloud
/
hello uni-app x
通知
6372
Star
108
Fork
184
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
24
列表
看板
标记
里程碑
合并请求
2
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
hello uni-app x
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
24
Issue
24
列表
看板
标记
里程碑
合并请求
2
合并请求
2
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
7e06885a
编写于
4月 21, 2025
作者:
DCloud-yinjiacheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
更新web-view示例和自动化测试用例
# Conflicts: # pages/component/web-view/web-view.uvue
上级
887c1863
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
43 addition
and
3 deletion
+43
-3
pages/component/web-view/web-view.test.js
pages/component/web-view/web-view.test.js
+13
-0
pages/component/web-view/web-view.uvue
pages/component/web-view/web-view.uvue
+30
-3
未找到文件。
pages/component/web-view/web-view.test.js
浏览文件 @
7e06885a
...
@@ -121,6 +121,19 @@ describe('component-native-web-view', () => {
...
@@ -121,6 +121,19 @@ describe('component-native-web-view', () => {
type
:
'
load
'
,
type
:
'
load
'
,
src
:
'
https://www.dcloud.io/
'
src
:
'
https://www.dcloud.io/
'
});
});
});
it
(
'
test event contentheightchange
'
,
async
()
=>
{
expect
(
await
page
.
callMethod
(
'
getContentHeight
'
)).
toBeGreaterThan
(
0
);
start
=
Date
.
now
();
await
page
.
waitFor
(
async
()
=>
{
return
(
await
page
.
data
(
'
eventContentHeightChange
'
))
||
(
Date
.
now
()
-
start
>
500
);
});
expect
(
await
page
.
data
(
'
eventContentHeightChange
'
)).
toEqual
({
tagName
:
'
WEB-VIEW
'
,
type
:
'
contentheightchange
'
,
isValidHeight
:
true
});
});
});
it
(
'
test event error
'
,
async
()
=>
{
it
(
'
test event error
'
,
async
()
=>
{
...
...
pages/component/web-view/web-view.uvue
浏览文件 @
7e06885a
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
<view class="uni-flex-item">
<view class="uni-flex-item">
<web-view id="web-view" class="uni-flex-item" :style="{ 'pointer-events': pointerEvents }" :src="src"
<web-view id="web-view" class="uni-flex-item" :style="{ 'pointer-events': pointerEvents }" :src="src"
:webview-styles="webview_styles" :horizontalScrollBarAccess="horizontalScrollBarAccess" :verticalScrollBarAccess="verticalScrollBarAccess" :bounces="bounces" @message="message" @error="error" @loading="loading"
:webview-styles="webview_styles" :horizontalScrollBarAccess="horizontalScrollBarAccess" :verticalScrollBarAccess="verticalScrollBarAccess" :bounces="bounces" @message="message" @error="error" @loading="loading"
@load="load" @download="download" @touchstart="touchstart" @tap="tap">
@load="load" @download="download" @
contentheightchange="contentheightchange" @
touchstart="touchstart" @tap="tap">
</web-view>
</web-view>
<!-- #ifdef APP -->
<!-- #ifdef APP -->
<view class="uni-padding-wrap uni-common-mt">
<view class="uni-padding-wrap uni-common-mt">
...
@@ -20,8 +20,11 @@
...
@@ -20,8 +20,11 @@
</view>
</view>
<!-- #ifndef APP-HARMONY -->
<!-- #ifndef APP-HARMONY -->
<!-- TODO harmony 执行 alert 无反应 -->
<!-- TODO harmony 执行 alert 无反应 -->
<view class="uni-btn-v">
<view class="uni-row uni-btn-v">
<button type="primary" @click="nativeToWeb">原生和Web通信</button>
<button class="uni-flex-item" type="primary" @click="nativeToWeb">原生和Web通信</button>
<!-- #ifdef APP-ANDROID || APP-IOS -->
<button class="margin-left-5 uni-flex-item" type="primary" @click="getContentHeight">获取内容高度</button>
<!-- #endif -->
</view>
</view>
<!-- #endif -->
<!-- #endif -->
<view class="uni-btn-v">
<view class="uni-btn-v">
...
@@ -88,6 +91,7 @@
...
@@ -88,6 +91,7 @@
eventLoading: null as UTSJSONObject | null,
eventLoading: null as UTSJSONObject | null,
eventLoad: null as UTSJSONObject | null,
eventLoad: null as UTSJSONObject | null,
eventError: null as UTSJSONObject | null,
eventError: null as UTSJSONObject | null,
eventContentHeightChange: null as UTSJSONObject | null,
pointerEvents: 'auto',
pointerEvents: 'auto',
isTouchEnable: false
isTouchEnable: false
}
}
...
@@ -134,6 +138,19 @@
...
@@ -134,6 +138,19 @@
nativeToWeb() {
nativeToWeb() {
webviewElement?.evalJS("alert('hello uni-app x')");
webviewElement?.evalJS("alert('hello uni-app x')");
},
},
// #ifdef APP-ANDROID || APP-IOS
getContentHeight() : number {
const height = webviewElement?.getContentHeight() ?? 0;
console.log('contentHeight', height);
if (!this.autoTest) {
uni.showModal({
content: ' 当前内容高度: ' + height,
showCancel: false
});
}
return height;
},
// #endif
message(event : UniWebViewMessageEvent) {
message(event : UniWebViewMessageEvent) {
console.log(JSON.stringify(event.detail));
console.log(JSON.stringify(event.detail));
},
},
...
@@ -183,6 +200,16 @@
...
@@ -183,6 +200,16 @@
showCancel: false
showCancel: false
});
});
},
},
contentheightchange(event : UniWebViewContentHeightChangeEvent) {
console.log(JSON.stringify(event.detail));
if (this.autoTest) {
this.eventContentHeightChange = {
"tagName": event.target?.tagName,
"type": event.type,
"isValidHeight": event.detail.height > 0
};
}
},
confirm(event : UniInputConfirmEvent) {
confirm(event : UniInputConfirmEvent) {
let url = event.detail.value;
let url = event.detail.value;
if (!url.startsWith('https://') && !url.startsWith('http://')) {
if (!url.startsWith('https://') && !url.startsWith('http://')) {
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录