pdfPreView.vue 3.1 KB
<template>
  <view class="material-detail">
    <view class="nav-bar">
      <view class="back" @click.stop="back">
        <uni-icons type="left" :size="20" color="#000"></uni-icons>
      </view>
      {{ title }}
    </view>
    <web-view v-if="fileUrltype === 'html'" :src="url"></web-view>
    <view v-else-if="fileUrltype !== 'pdf'">
      <lk-preview-office :url="url" :fileType="fileType"></lk-preview-office>
    </view>
    <view v-else>
      <lk-preview-office :url="url" fileType="pdf"></lk-preview-office>
    </view>
  </view>
</template>

<script type="text/ecmascript-6">
import { report } from '@/mixin/index.js'
export default {
  name: '',
  mixins: [report],
  data () {
    return {
      url: '',
      title: '',
      fileType: 'pdf',
      Signature: true,
      fileUrltype:'pdf'
    }
  },
  onLoad (options) {
console.log(options)
this.fileUrltype = options.fileUrltype || 'pdf'
this.fileType = options.fileType || 'pdf'
this.Signature = options.Signature === 'false' ? false : (options.Signature || true);
if(this.fileType === 'docx') {
 this.url = options.fileUrl
}else if(!this.Signature) {
this.url = options.fileUrl
}else {
 this.url = options.fileUrl + '&OSSAccessKeyId='+ options.OSSAccessKeyId + '&Signature=' + options.Signature
}

 this.title = options.fileName
 console.log(this.url)
    // else this.setWv()
  },
  mounted () {
  },
  methods: {
    back () {
      uni.navigateBack({
        delta: 1,
        animationType: 'pop-out',
        animationDuration: 100
      })
    },
    setWebviewStyle () {
      const setWebviewStyleWithRetry = () => {
        const currentWebview = this.$scope.$getAppWebview()
        let [wv] = currentWebview.children(),
          wvFlag = false
        if (wv) {
          wv.setStyle({
            left: '71.9%',
            top: '17.18%',
            height: '82.82%',
            width: '28.3%'
          })
          wvFlag = true;
        }
        return wvFlag
      }
      const retrySetWebviewStyle = () => {
        if (!setWebviewStyleWithRetry()) {
          // 如果未成功,继续重试
          setTimeout(retrySetWebviewStyle, 50);
        } else {
          // 成功设置样式,结束循环
          console.log('Webview样式设置成功');
        }
      };

      setTimeout(retrySetWebviewStyle, 100);
    }
  }
}
</script>

<style scoped lang="scss">
.nav-bar {
  position: fixed;
  width: 100%;
  height: toRpx(96);
  left: 0;
  top: toRpx(48);
  z-index: 9;
  text-align: center;
  font-weight: 700;
  font-size: toRpx(32);
  color: #1a1a1a;
  line-height: toRpx(96);
  .back {
    position: absolute;
    left: 0;
    top: 0;
    height: 100%;
    aspect-ratio: 1/1;
    display: flex;
    align-items: center;
    justify-content: center;
  }
}
.file-box {
  position: fixed;
  top: 5.2vh;
  height: 94.8vh;
  left: 0;
  width: 100vw;
}
.has-ai {
  width: 71.36vw;
}
.AI-window {
  width: 28.3vw;
  height: 90.63vh;
  position: fixed;
  top: 9.37vh;
  right: 0;
  background: #f5f9ff;
  .AI-title {
    height: 5.73vh;
    padding-top: 2.08vh;
    font-size: toRpx(34);
    font-weight: 500;
    justify-content: center;
    color: #333333;
  }
}
</style>