webviewPage.vue 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <template>
  2. <view>
  3. <view ref='file' v-if="word"></view>
  4. <web-view v-else :webview-styles="webviewStyles" :src="url"></web-view>
  5. </view>
  6. </template>
  7. <script>
  8. const docx = require('docx-preview');
  9. window.JSZip = require('jszip')
  10. export default {
  11. data() {
  12. return {
  13. url: "",
  14. webviewStyles: {
  15. progress: {
  16. color: '#F07423'
  17. }
  18. },
  19. type: "",
  20. word: false,
  21. };
  22. },
  23. onLoad(param) {
  24. this.type = param.type;
  25. let title = ""
  26. if (this.type == 1) {
  27. title = "用户使用协议"
  28. } else if (this.type == 2) {
  29. title = "隐私协议"
  30. } else if (this.type == 3) {
  31. title = "入驻协议"
  32. }
  33. uni.setNavigationBarTitle({
  34. title: title
  35. })
  36. this.webviewStyles.progress.color = getApp().globalData.color1;
  37. this.queryProtocolConfigView();
  38. },
  39. methods: {
  40. async queryProtocolConfigView() {
  41. let res = await this.$myRequest({
  42. url: "/project/queryProtocolConfigView",
  43. data: {},
  44. })
  45. if (res.data.success) {
  46. const curryUrl = this.curry("/hybrid/html/web/viewer.html?file=")
  47. if (this.type == '1') { //使用协议
  48. this.isWord(res.data.single.userUseProtocol);
  49. this.url = curryUrl(res.data.single.userUseProtocol);
  50. } else if (this.type == '2') { //隐私协议
  51. this.isWord(res.data.single.userPrivacyProtocol);
  52. this.url = curryUrl(res.data.single.userPrivacyProtocol);
  53. } else if (this.type == '3') { //业主注册协议
  54. this.isWord(res.data.single.ownerRegistProtocol);
  55. this.url = curryUrl(res.data.single.ownerRegistProtocol);
  56. }
  57. }
  58. },
  59. curry(baseUrl) {
  60. return function(url) {
  61. let index = url.lastIndexOf('.');
  62. if (url.substring(index + 1).indexOf('pdf') > -1) {
  63. return baseUrl + url;
  64. } else {
  65. return url;
  66. }
  67. }
  68. },
  69. isWord(url) {
  70. let index = url.lastIndexOf('.');
  71. if (url.substring(index + 1).indexOf('docx') > -1) {
  72. this.word = true;
  73. docx.renderAsync(new Blob([url]),this.$refs.file) // 渲染到页面预览
  74. } else {
  75. this.word = false;
  76. }
  77. }
  78. }
  79. }
  80. </script>
  81. <style lang="scss">
  82. </style>