webview.nvue 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. this.url = decodeURIComponent(options.url)
  31. this.title = options.title ? decodeURIComponent(options.title) : '详情'
  32. } else if (this.id === '1') {
  33. this.title = '用户协议'
  34. this.url = 'http://8.155.56.12:8081/profile/upload/userAgreement.html'
  35. } else if (this.id === '2') {
  36. this.title = '隐私政策'
  37. this.url = 'http://8.155.56.12:8081/profile/upload/privatery.html'
  38. }
  39. },
  40. methods: {
  41. goBack() {
  42. uni.navigateBack()
  43. }
  44. }
  45. }
  46. </script>
  47. <style>
  48. .webview-page {
  49. flex: 1;
  50. background-color: #ffffff;
  51. }
  52. .status-bar {
  53. background-color: #ffffff;
  54. }
  55. .custom-head {
  56. flex-direction: row;
  57. align-items: center;
  58. justify-content: space-between;
  59. height: 100rpx;
  60. padding-left: 30rpx;
  61. padding-right: 30rpx;
  62. background-color: #ffffff;
  63. border-bottom-width: 1px;
  64. border-bottom-color: #eeeeee;
  65. border-bottom-style: solid;
  66. }
  67. .back-btn {
  68. font-size: 34rpx;
  69. color: #333333;
  70. }
  71. .head-title {
  72. font-size: 36rpx;
  73. font-weight: bold;
  74. color: #333333;
  75. }
  76. .placeholder {
  77. width: 80rpx;
  78. }
  79. .web-content {
  80. flex: 1;
  81. }
  82. </style>