browse.vue 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <template>
  2. <view class="">
  3. <uni-nav-bar
  4. fixed="true"
  5. statusBar="true"
  6. left-icon="back"
  7. title="预览"
  8. @clickLeft="back"
  9. >
  10. </uni-nav-bar>
  11. <web-view
  12. :src="fileUrl"
  13. class="webview"
  14. allow
  15. :fullscreen="false"
  16. :webview-styles="webviewStyles"
  17. style="width: 100%; height: calc(100vh - 100px)"
  18. :frameborder="0"
  19. ></web-view>
  20. </view>
  21. </template>
  22. <script>
  23. // import { getFileType } from './util.js';
  24. export default {
  25. data() {
  26. return {
  27. fileUrl: "",
  28. showEditFlag: false,
  29. webviewStyles: {
  30. width: "100%",
  31. height: "100%",
  32. bottom: "56px",
  33. },
  34. };
  35. },
  36. onReady() {
  37. // #ifdef APP-PLUS
  38. var currentWebview = this.$scope.$getAppWebview(); //获取当前页面的webview对象
  39. setTimeout(function () {
  40. let wv = currentWebview.children()[0];
  41. console.log(currentWebview.children()[0],'currentWebview')
  42. console.log(wv,'wv')
  43. wv.setStyle({ scalable: true });
  44. }, 1000); //如果是页面初始化调用时,需要延时一下
  45. // #endif
  46. },
  47. onLoad({ url }) {
  48. uni.getSystemInfo({
  49. success: (res) => {
  50. this.webviewStyles.height =
  51. res.screenHeight -
  52. res.statusBarHeight -
  53. res.safeAreaInsets?.bottom -
  54. 100 +
  55. "px";
  56. this.webviewStyles.bottom = res.safeAreaInsets?.bottom + 56 + "px";
  57. },
  58. });
  59. this.fileUrl = url;
  60. console.log(url);
  61. },
  62. methods: {
  63. // open(row) {
  64. // this.showEditFlag = true
  65. // this.setFileUrl(row)
  66. // },
  67. setFileUrl(row) {
  68. let file = row.storagePath[0];
  69. let fileNames = file.storePath.split("/");
  70. let url =
  71. window.location.origin +
  72. "/api/main/file/getFile?objectName=" +
  73. file.storePath +
  74. "&fullfilename=" +
  75. fileNames[fileNames.length - 1];
  76. this.fileUrl = "/kkfile/onlinePreview?url=" + btoa(url);
  77. },
  78. },
  79. };
  80. </script>
  81. <style scoped lang="scss"></style>