<template>
    <view class="container">
        <web-view
            :src="url"
            @message="handleMessage"
            @error="onWebviewError"
        ></web-view>

    </view>
</template>

<script>
import {signApi} from "@/api/sign";

export default {
    data() {
        return {
            url: '',
            loading: true
        }
    },
    onLoad(options) {

        if (options.url) {
            this.url = decodeURIComponent(options.url)
            console.log('this.url',this.url)
            this.loading = false
        } else {
            uni.showToast({ title: '协议或报告链接错误', icon: 'none' })
            uni.navigateBack()
        }
    },
    methods: {
        // 接收H5页面消息
        async handleMessage(e) {
            const [message] = e.detail.data

            console.log('收到H5消息:', JSON.parse(JSON.stringify(message)))


        },

        // 处理加载失败
        onWebviewError() {
            this.loading = false
            uni.showModal({
                title: '提示',
                content: '协议或报告加载失败，请检查网络后重试',
                showCancel: false,
                success: () => {
                    uni.navigateBack()
                }
            })
        }
    }
}
</script>

<style scoped>
.loading-mask {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255,255,255,0.9);
    display: flex;
    justify-content: center;
    align-items: center;
}
</style>
