webview-screenshot-comparison.uvue 2.0 KB
Newer Older
1
<template>
2
  <view v-if="!isCustomNavigationBar" class="top-placehoder"></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
        isCustomNavigationBar: false,
DCloud-WZF's avatar
DCloud-WZF 已提交
20
        devicePixelRatio: state.devicePixelRatio,
21 22 23
        webviewStyles: {
          progress: false
        }
24 25 26
      }
    },
    onReady() {
27
      this.webviewContext = uni.createWebviewContext('webview-screenshot-comparison', this)
28 29
    },
    methods: {
DCloud-WZF's avatar
DCloud-WZF 已提交
30
      customNavigationBarPageAppendWebHeadPlaceholder() {
雪洛's avatar
雪洛 已提交
31
        if (this.src.indexOf('pages/template/navbar-lite/navbar-lite') > -1) {
DCloud-WZF's avatar
DCloud-WZF 已提交
32
          this.webviewContext?.evalJS(`
DCloud-WZF's avatar
DCloud-WZF 已提交
33
            const uniNavbar = document.querySelector('.uni-navbar');
34
            uniNavbar.style.paddingTop = '${state.statusBarHeight}px';
DCloud-WZF's avatar
DCloud-WZF 已提交
35
          `)
雪洛's avatar
雪洛 已提交
36
        } else if (this.src.indexOf('pages/template/scroll-fold-nav/scroll-fold-nav') > -1) {
DCloud-WZF's avatar
DCloud-WZF 已提交
37
          this.webviewContext?.evalJS(`
DCloud-WZF's avatar
DCloud-WZF 已提交
38 39 40 41 42 43
        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 已提交
44
        }
45 46 47
      },
      loaded() {
        this.isLoaded = true
DCloud-WZF's avatar
DCloud-WZF 已提交
48
        this.customNavigationBarPageAppendWebHeadPlaceholder();
49 50 51 52 53 54 55
      },
      error(event : WebViewErrorEvent) {
        console.log('webview load error', JSON.stringify(event.detail));
      }
    }
  }
</script>
56 57 58 59 60
<style>
  .top-placehoder{
    height: var(--status-bar-height);
    background-color: #007aff;
  }
61
  .webview-screenshot-comparison {
62 63 64
    flex: 1;
  }
</style>