四零语境前端代码仓库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

204 lines
3.8 KiB

1 month ago
  1. <template>
  2. <view v-if="showSplash" class="splash-screen">
  3. <!-- 富文本內容 -->
  4. <view class="splash-content">
  5. <image
  6. :src="splashContent"
  7. mode="scaleToFill"
  8. class="splash-image"
  9. />
  10. </view>
  11. <!-- 跳過按鈕 -->
  12. <view class="skip-button" >
  13. <text class="skip-text">跳過 ({{ countdown }}s)</text>
  14. </view>
  15. <!-- 定位英語文字和中文文字到左下角 -->
  16. <view class="text-container">
  17. <text class="english-text">
  18. {{ configParamContent('creen_en') }}
  19. </text>
  20. <text class="chinese-text">
  21. {{ configParamContent('creen_zh') }}
  22. </text>
  23. </view>
  24. </view>
  25. </template>
  26. <script>
  27. // import config from '../../mixins/config.js'
  28. export default {
  29. name: 'SplashScreen',
  30. // mixins: [config],
  31. props: {
  32. // 顯示時長(秒)
  33. duration: {
  34. type: Number,
  35. default: 5
  36. }
  37. },
  38. data() {
  39. return {
  40. showSplash: false,
  41. countdown: 5,
  42. timer: null,
  43. splashContent: ''
  44. }
  45. },
  46. computed: {
  47. image() {
  48. return this.configParamContent('creen_image') || uni.getStorageSync('screen_image')
  49. }
  50. },
  51. mounted() {
  52. this.initSplash()
  53. uni.hideTabBar()
  54. },
  55. beforeDestroy() {
  56. this.clearTimer()
  57. },
  58. methods: {
  59. // 初始化開動頁面
  60. async initSplash() {
  61. try {
  62. // 獲取富文本內容
  63. this.splashContent = this.image
  64. // 如果有內容才顯示
  65. if (this.splashContent) {
  66. this.countdown = this.duration
  67. this.showSplash = true
  68. this.startCountdown()
  69. }
  70. } catch (error) {
  71. console.error('獲取開動頁面內容失敗:', error)
  72. }
  73. },
  74. // 開始倒計時
  75. startCountdown() {
  76. this.timer = setInterval(() => {
  77. this.countdown--
  78. if (this.countdown <= 0) {
  79. this.closeSplash()
  80. }
  81. }, 1000)
  82. },
  83. // 關閉開動頁面
  84. closeSplash() {
  85. this.showSplash = false
  86. uni.showTabBar({
  87. animation: true
  88. })
  89. this.clearTimer()
  90. this.$emit('close')
  91. },
  92. // 清除計時器
  93. clearTimer() {
  94. if (this.timer) {
  95. clearInterval(this.timer)
  96. this.timer = null
  97. }
  98. }
  99. }
  100. }
  101. </script>
  102. <style lang="scss" scoped>
  103. .splash-screen {
  104. position: fixed;
  105. top: 0;
  106. left: 0;
  107. width: 100vw;
  108. height: 100vh;
  109. background-color: #fff;
  110. z-index: 9999;
  111. display: flex;
  112. flex-direction: column;
  113. .splash-image{
  114. width: 100%;
  115. height: 100%;
  116. }
  117. }
  118. .splash-content {
  119. flex: 1;
  120. width: 100%;
  121. height: 100%;
  122. overflow: hidden;
  123. // 富文本樣式
  124. :deep(rich-text) {
  125. width: 100%;
  126. height: 100%;
  127. display: block;
  128. img{
  129. width: 100%;
  130. height: 100%;
  131. }
  132. }
  133. }
  134. .skip-button {
  135. position: absolute;
  136. top: 100rpx;
  137. left: 40rpx;
  138. background-color: #0000004D;
  139. border-radius: 100rpx;
  140. width: 148rpx ;
  141. height: 60rpx;
  142. text-align: center;
  143. z-index: 10000;
  144. .skip-text {
  145. font-size: 24rpx;
  146. line-height: 60rpx;
  147. color: #fff;
  148. }
  149. }
  150. // 文字容器定位到左下角
  151. .text-container {
  152. position: absolute;
  153. bottom: 80rpx;
  154. left: 40rpx;
  155. z-index: 10001;
  156. display: flex;
  157. flex-direction: column;
  158. gap: 8rpx;
  159. }
  160. // 英文文字样式
  161. .english-text {
  162. font-family: PingFang SC;
  163. font-weight: 600;
  164. font-size: 32rpx; // 16px转换为rpx
  165. line-height: 48rpx; // 24px转换为rpx
  166. letter-spacing: 0;
  167. color: #FFFFFF;
  168. background: transparent;
  169. }
  170. // 中文文字样式
  171. .chinese-text {
  172. font-family: PingFang SC;
  173. // font-weight: 600;
  174. font-size: 32rpx; // 16px转换为rpx
  175. line-height: 48rpx; // 24px转换为rpx
  176. letter-spacing: 0;
  177. color: #FFFFFF;
  178. background: transparent;
  179. }
  180. // 確保覆蓋 tabbar
  181. .splash-screen {
  182. // 覆蓋所有內容,包括 tabbar
  183. position: fixed !important;
  184. z-index: 9999 !important;
  185. }
  186. </style>