test.vue 3.59 KB
<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>