You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Protocol.vue 2.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <template>
  2. <view class="view-container">
  3. <scroll-view :scroll-y="true" style="height: 100%;" >
  4. <view ref="container" class='docx-content'></view>
  5. </scroll-view>
  6. </view>
  7. </template>
  8. <script setup>
  9. import {
  10. ref,
  11. onMounted
  12. } from "vue";
  13. import {
  14. renderAsync
  15. } from "docx-preview"; // 引入异步渲染方法
  16. onMounted(() => {
  17. getFile('/sett-minio/template/ETC用户协议(阳光行A).docx')
  18. })
  19. let container = ref(null);
  20. let renderContext = ref(null);
  21. function getFile(url) {
  22. uni.showLoading({
  23. title: "加载中",
  24. mask: true
  25. })
  26. let x = new XMLHttpRequest()
  27. x.open('GET', url, true)
  28. x.responseType = 'blob'
  29. x.onload = function() {
  30. //self.exportLoading = false;
  31. const blob = new Blob([x.response]);
  32. filechange(blob)
  33. }
  34. x.send()
  35. }
  36. function filechange(blob) {
  37. console.log(blob, container.value.$el);
  38. renderAsync(blob, container.value.$el, null, {
  39. className: "docx", // 默认和文档样式类的类名/前缀
  40. inWrapper: true, // 启用围绕文档内容渲染包装器
  41. ignoreWidth: false, // 禁止页面渲染宽度
  42. ignoreHeight: false, // 禁止页面渲染高度
  43. ignoreFonts: false, // 禁止字体渲染
  44. breakPages: true, // 在分页符上启用分页
  45. ignoreLastRenderedPageBreak: true, //禁用lastRenderedPageBreak元素的分页
  46. experimental: false, //启用实验性功能(制表符停止计算)
  47. trimXmlDeclaration: true, //如果为真,xml声明将在解析之前从xml文档中删除
  48. breakPages: true, // 在分页符上启用分页
  49. debug: false, // 启用额外的日志记录
  50. }).then((res) => {
  51. let timer = setTimeout(() => {
  52. const $slides = document.querySelector(".docx");
  53. uni.hideLoading()
  54. if ($slides.children.length) {
  55. const slidesWidth = Math.max(
  56. ...Array.from($slides.children).map((s) => s.offsetWidth)
  57. );
  58. const $wrapper = document.querySelector(".docx-wrapper");
  59. const wrapperWidth = $wrapper.offsetWidth;
  60. console.log(wrapperWidth);
  61. $wrapper.style.transform = `scale(${wrapperWidth / slidesWidth})`
  62. $wrapper.style.transformOrigin = "top center"
  63. // $wrapper.style.height = wrapperHeight * (1 / (wrapperWidth / slidesWidth)) + "px"
  64. clearInterval(timer);
  65. }
  66. }, 100)
  67. })
  68. }
  69. </script>
  70. <style>
  71. .docx-content {
  72. width: 100%;
  73. height: 100%;
  74. }
  75. .view-container {
  76. width: 100%;
  77. height: 100%;
  78. padding: 0 16rpx;
  79. overflow: auto;
  80. }
  81. /deep/.docx-wrapper {
  82. padding: 0 !important;
  83. width: 100%;
  84. }
  85. /deep/.docx {
  86. width: 100% !important;
  87. display: table !important;
  88. padding: 2em 1em 0 !important;
  89. }
  90. </style>