quiz.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <template>
  2. <view class="quiz-page">
  3. <view class="nav-bar" :style="navBarStyle">
  4. <view class="nav-left" @tap="handleBack">
  5. <text class="back-icon">‹</text>
  6. </view>
  7. <text class="nav-title">在线测评</text>
  8. <view class="nav-right"></view>
  9. </view>
  10. <view class="webview-container" :style="contentStyle">
  11. <web-view v-if="url" :src="url"></web-view>
  12. </view>
  13. </view>
  14. </template>
  15. <script setup>
  16. import { ref } from 'vue'
  17. import { onLoad, onBackPress } from '@dcloudio/uni-app'
  18. const url = ref('')
  19. const assessmentId = ref('')
  20. const source = ref('')
  21. const statusBarHeight = uni.getSystemInfoSync().statusBarHeight || 20
  22. const navBarHeight = 44
  23. const navBarStyle = `padding-top:${statusBarHeight}px;height:${navBarHeight}px;`
  24. const contentStyle = `margin-top:${statusBarHeight + navBarHeight}px;`
  25. const handleBack = () => {
  26. if (source.value === 'kaoshixing' && assessmentId.value) {
  27. uni.redirectTo({
  28. url: `/pages/common/webview?mode=kaoshixing&assessmentId=${encodeURIComponent(assessmentId.value)}`
  29. })
  30. return true
  31. }
  32. uni.navigateBack()
  33. return true
  34. }
  35. onBackPress((options) => {
  36. return handleBack()
  37. })
  38. onLoad((options) => {
  39. assessmentId.value = options.assessmentId || ''
  40. source.value = options.from || ''
  41. if (options.from === 'report') {
  42. const cachedUrl = uni.getStorageSync('temp_report_url')
  43. if (cachedUrl) {
  44. url.value = cachedUrl
  45. uni.removeStorageSync('temp_report_url')
  46. return
  47. }
  48. }
  49. if (options.from === 'kaoshixing') {
  50. const cachedUrl = uni.getStorageSync('temp_exam_url')
  51. if (cachedUrl) {
  52. url.value = cachedUrl
  53. uni.removeStorageSync('temp_exam_url')
  54. return
  55. }
  56. }
  57. if (options.url) {
  58. url.value = decodeURIComponent(options.url)
  59. console.log('Quiz WebView Loading URL:', url.value)
  60. }
  61. })
  62. </script>
  63. <style scoped>
  64. .quiz-page {
  65. min-height: 100vh;
  66. background: #fff;
  67. }
  68. .nav-bar {
  69. position: fixed;
  70. top: 0;
  71. left: 0;
  72. right: 0;
  73. z-index: 999;
  74. display: flex;
  75. align-items: center;
  76. justify-content: space-between;
  77. background: #fff;
  78. }
  79. .nav-left,
  80. .nav-right {
  81. width: 88rpx;
  82. height: 44px;
  83. display: flex;
  84. align-items: center;
  85. justify-content: center;
  86. flex-shrink: 0;
  87. }
  88. .back-icon {
  89. font-size: 52rpx;
  90. color: #111;
  91. line-height: 1;
  92. }
  93. .nav-title {
  94. flex: 1;
  95. text-align: center;
  96. font-size: 32rpx;
  97. color: #111;
  98. font-weight: 500;
  99. }
  100. .webview-container {
  101. height: calc(100vh - 44px);
  102. }
  103. </style>