webviewPage.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <template>
  2. <view>
  3. <web-view :webview-styles="webviewStyles" :src="url" v-if="iOS"></web-view>
  4. </view>
  5. </template>
  6. <script>
  7. export default {
  8. data() {
  9. return {
  10. url: "",
  11. webviewStyles: {
  12. progress: {
  13. color: '#F07423'
  14. }
  15. },
  16. type: "",
  17. iOS: true
  18. };
  19. },
  20. onLoad(param) {
  21. this.type = param.type;
  22. let title = ""
  23. if (this.type == 1) {
  24. title = "用户使用协议"
  25. } else if (this.type == 2) {
  26. title = "隐私协议"
  27. } else if (this.type == 3) {
  28. title = "入驻协议"
  29. }
  30. uni.setNavigationBarTitle({
  31. title: title
  32. })
  33. this.webviewStyles.progress.color = getApp().globalData.color1;
  34. this.queryProtocolConfigView();
  35. },
  36. methods: {
  37. async queryProtocolConfigView() {
  38. let res = await this.$myRequest({
  39. url: "/project/queryProtocolConfigView",
  40. data: {},
  41. })
  42. if (res.data.success) {
  43. if (this.type = '1') { //使用协议
  44. this.url = res.data.single.userUseProtocol;
  45. } else if (this.type = '2') { //隐私协议
  46. this.url = res.data.single.userPrivacyProtocol;
  47. } else if (this.type = '3') { //业主注册协议
  48. this.url = res.data.single.ownerRegistProtocol;
  49. }
  50. let index = this.url.lastIndexOf('.');
  51. let ah = this.url.substring(index+1);
  52. if(ah.indexOf('pdf')>-1){ //是pdf
  53. this.loadpdf();
  54. }
  55. }
  56. },
  57. loadpdf() {
  58. uni.getSystemInfo({
  59. success: (res) => {
  60. console.log(res)
  61. if (res.system.includes('iOS')) {
  62. this.iOS = true;
  63. } else {
  64. this.iOS = false;
  65. // Android 需要下载后再打开
  66. uni.downloadFile({
  67. url: this.url,
  68. success: (res) => {
  69. const path = res.tempFilePath;
  70. uni.openDocument({
  71. filePath: path,
  72. fileType: 'pdf',
  73. success: (res) => {
  74. uni.navigateBack({
  75. delta: 1
  76. });
  77. },
  78. fail: (err) => {
  79. uni.showToast({
  80. title: '打开文件失败',
  81. icon: 'none',
  82. duration: 2000
  83. });
  84. }
  85. });
  86. },
  87. fail: (err) => {
  88. console.log(err);
  89. uni.showToast({
  90. title: '下载文件失败',
  91. icon: 'none',
  92. duration: 2000
  93. });
  94. }
  95. });
  96. }
  97. }
  98. });
  99. }
  100. }
  101. }
  102. </script>
  103. <style lang="scss">
  104. </style>