提交 7e06885a 编写于 作者: DCloud-yinjiacheng's avatar DCloud-yinjiacheng

更新web-view示例和自动化测试用例

# Conflicts:
#	pages/component/web-view/web-view.uvue
上级 887c1863
...@@ -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 () => {
......
...@@ -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.
先完成此消息的编辑!
想要评论请 注册