test.vue
3.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
<template>
<view class="test-container">
<view class="test-header">
<text class="test-title">WebView页面测试</text>
</view>
<view class="test-content">
<view class="test-section">
<text class="section-title">测试链接:</text>
<nut-button
type="primary"
size="small"
@click="testWebView('https://www.baidu.com', '百度搜索')"
class="test-btn"
>
测试百度
</nut-button>
<nut-button
type="success"
size="small"
@click="testWebView('https://m.taobao.com', '淘宝网')"
class="test-btn"
>
测试淘宝
</nut-button>
<nut-button
type="warning"
size="small"
@click="testWebView('https://github.com', 'GitHub')"
class="test-btn"
>
测试GitHub
</nut-button>
</view>
<view class="test-section">
<text class="section-title">自定义URL测试:</text>
<nut-input
v-model="customUrl"
placeholder="请输入要测试的URL"
class="url-input"
/>
<nut-input
v-model="customTitle"
placeholder="请输入页面标题"
class="title-input"
/>
<nut-button
type="primary"
@click="testCustomUrl"
class="test-btn"
>
测试自定义URL
</nut-button>
</view>
</view>
</view>
</template>
<script setup>
import { ref } from 'vue'
import Taro from '@tarojs/taro'
/**
* WebView测试页面
*/
const customUrl = ref('')
const customTitle = ref('')
/**
* 测试WebView页面
* @param {string} url - 要测试的URL
* @param {string} title - 页面标题
*/
const testWebView = (url, title) => {
Taro.navigateTo({
url: `/pages/webview/index?url=${encodeURIComponent(url)}&title=${encodeURIComponent(title)}`
})
}
/**
* 测试自定义URL
*/
const testCustomUrl = () => {
if (!customUrl.value) {
Taro.showToast({
title: '请输入URL',
icon: 'none'
})
return
}
const url = customUrl.value.startsWith('http') ? customUrl.value : `https://${customUrl.value}`
const title = customTitle.value || '自定义页面'
testWebView(url, title)
}
</script>
<script>
export default {
name: 'WebViewTest'
}
</script>
<style lang="less">
.test-container {
padding: 32rpx;
background-color: #f5f5f5;
min-height: 100vh;
}
.test-header {
text-align: center;
margin-bottom: 48rpx;
}
.test-title {
font-size: 36rpx;
font-weight: 600;
color: #333;
}
.test-content {
background-color: #fff;
border-radius: 16rpx;
padding: 32rpx;
}
.test-section {
margin-bottom: 48rpx;
&:last-child {
margin-bottom: 0;
}
}
.section-title {
display: block;
font-size: 28rpx;
font-weight: 600;
color: #333;
margin-bottom: 24rpx;
}
.test-btn {
margin-right: 16rpx;
margin-bottom: 16rpx;
}
.url-input,
.title-input {
margin-bottom: 16rpx;
}
</style>