webview-screenshot-comparison.uvue 2.1 KB
Newer Older
1
<template>
DCloud-WZF's avatar
DCloud-WZF 已提交
2
  <view v-if="!isCustomNavigationBar" :style="placeholderStyle"></view>
3 4
  <web-view id="webview-screenshot-comparison" class="webview-screenshot-comparison" :webview-styles="webviewStyles"
    :src="src" @loaded="loaded" @error="error">
5 6 7 8
  </web-view>
</template>

<script>
DCloud-WZF's avatar
DCloud-WZF 已提交
9 10
  import { state } from '@/store/index.uts'

11 12 13 14 15 16 17
  export default {
    data() {
      return {
        baseSrc: '',
        src: '',
        webviewContext: null as WebviewContext | null,
        isLoaded: false,
18
        statusBarHeight: state.statusBarHeight,
DCloud-WZF's avatar
DCloud-WZF 已提交
19 20 21
        isCustomNavigationBar: false,
        placeholderStyle: {
          display: 'block',
22
          height: `${state.statusBarHeight}px`,
DCloud-WZF's avatar
DCloud-WZF 已提交
23 24
          backgroundColor: '#007aff'
        },
DCloud-WZF's avatar
DCloud-WZF 已提交
25
        devicePixelRatio: state.devicePixelRatio,
26 27 28
        webviewStyles: {
          progress: false
        }
29 30 31
      }
    },
    onReady() {
32
      this.webviewContext = uni.createWebviewContext('webview-screenshot-comparison', this)
33 34
    },
    methods: {
DCloud-WZF's avatar
DCloud-WZF 已提交
35
      customNavigationBarPageAppendWebHeadPlaceholder() {
雪洛's avatar
雪洛 已提交
36
        if (this.src.indexOf('pages/template/navbar-lite/navbar-lite') > -1) {
DCloud-WZF's avatar
DCloud-WZF 已提交
37
          this.webviewContext?.evalJS(`
DCloud-WZF's avatar
DCloud-WZF 已提交
38
            const uniNavbar = document.querySelector('.uni-navbar');
39
            uniNavbar.style.paddingTop = '${state.statusBarHeight}px';
DCloud-WZF's avatar
DCloud-WZF 已提交
40
          `)
雪洛's avatar
雪洛 已提交
41
        } else if (this.src.indexOf('pages/template/scroll-fold-nav/scroll-fold-nav') > -1) {
DCloud-WZF's avatar
DCloud-WZF 已提交
42
          this.webviewContext?.evalJS(`
DCloud-WZF's avatar
DCloud-WZF 已提交
43 44 45 46 47 48
        const heightSeat = document.querySelector('.height-seat');
        heightSeat.style.height = '125px';
        heightSeat.style.backgroundColor = '#f0f8ff';
        const topBox = document.querySelector('.top-box');
        topBox.style.top = '35px';
      `)
DCloud-WZF's avatar
DCloud-WZF 已提交
49
        }
50 51 52
      },
      loaded() {
        this.isLoaded = true
DCloud-WZF's avatar
DCloud-WZF 已提交
53
        this.customNavigationBarPageAppendWebHeadPlaceholder();
54 55 56 57 58 59 60 61
      },
      error(event : WebViewErrorEvent) {
        console.log('webview load error', JSON.stringify(event.detail));
      }
    }
  }
</script>
<style>
62
  .webview-screenshot-comparison {
63 64 65
    flex: 1;
  }
</style>