<template>
    <web-view :src="webSrc"/>
</template>

<script setup>
import {ref, onMounted, getCurrentInstance} from "vue";
import {onLoad} from '@dcloudio/uni-app'

//初始变量
let wv;
const instance = getCurrentInstance().proxy
const webSrc = ref('');

onLoad((option) => {
    if (option.url) {
        webSrc.value = '/hybrid/html/pdf/web/viewer.html?file= ' + decodeURIComponent(option.url);
    }
})

//渲染完成
onMounted(() => {
    // #ifdef APP-PLUS
    let currentWebview = instance.$scope.$getAppWebview()
    //如果是页面初始化调用时，需要延时一下
    setTimeout(function() {
        wv = currentWebview.children()[0]
        wv.setStyle({scalable:true})
        // #ifdef APP-PLUS
        //ios 禁用缓存，测试生效！！
        let cache1 = plus.ios.newObject('NSURLCache');
        let cache = plus.ios.invoke(cache1, 'sharedURLCache');
        plus.ios.invoke(cache, 'removeAllCachedResponses');
        plus.ios.invoke(cache, 'setDiskCapacity:', 0);
        plus.ios.invoke(cache, 'setMemoryCapacity:', 0);

        //安卓端缓存清理。
        plus.cache.clear();
        // #endif
    }, 1000);
    // #endif
})
</script>

<style lang="scss">
page {
    height: auto;
}
</style>
