webview.nvue 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <template>
  2. <view class="webview-page">
  3. <view class="status-bar" :style="{height: statusBarHeight + 'px'}"></view>
  4. <view class="custom-head">
  5. <text class="back-btn" @click="goBack">← 返回</text>
  6. <text class="head-title">{{ title }}</text>
  7. <view class="placeholder"></view>
  8. </view>
  9. <web-view :src="url" class="web-content"></web-view>
  10. </view>
  11. </template>
  12. <script>
  13. export default {
  14. data() {
  15. return {
  16. id: '',
  17. title: '',
  18. url: '',
  19. statusBarHeight: 44
  20. }
  21. },
  22. created() {
  23. const sysInfo = uni.getSystemInfoSync()
  24. this.statusBarHeight = sysInfo.statusBarHeight || 44
  25. },
  26. onLoad(options) {
  27. this.id = options.id || ''
  28. // 支持直接传入 url 和 title 参数(如文章阅读页)
  29. if (options.url) {
  30. console.log(options.url)
  31. this.url = decodeURIComponent(options.url)
  32. console.log(this.url)
  33. this.title = options.title ? decodeURIComponent(options.title) : '详情'
  34. } else if (this.id === '1') {
  35. this.title = '用户协议'
  36. this.url = 'http://8.155.56.12:8081/profile/upload/userAgreement.html'
  37. } else if (this.id === '2') {
  38. this.title = '隐私政策'
  39. this.url = 'http://8.155.56.12:8081/profile/upload/privatery.html'
  40. }
  41. },
  42. methods: {
  43. goBack() {
  44. uni.navigateBack()
  45. }
  46. }
  47. }
  48. </script>
  49. <style>
  50. .webview-page {
  51. flex: 1;
  52. background-color: #ffffff;
  53. }
  54. .status-bar {
  55. background-color: #ffffff;
  56. }
  57. .custom-head {
  58. flex-direction: row;
  59. align-items: center;
  60. justify-content: space-between;
  61. height: 100rpx;
  62. padding-left: 30rpx;
  63. padding-right: 30rpx;
  64. background-color: #ffffff;
  65. border-bottom-width: 1px;
  66. border-bottom-color: #eeeeee;
  67. border-bottom-style: solid;
  68. }
  69. .back-btn {
  70. font-size: 34rpx;
  71. color: #333333;
  72. }
  73. .head-title {
  74. font-size: 36rpx;
  75. font-weight: bold;
  76. color: #333333;
  77. }
  78. .placeholder {
  79. width: 80rpx;
  80. }
  81. .web-content {
  82. flex: 1;
  83. }
  84. </style>