四零语境前端代码仓库
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.

275 lines
6.1 KiB

1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
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="aspectFit"
  8. class="splash-image"
  9. @error="onImageError"
  10. @load="onImageLoad"
  11. />
  12. </view>
  13. <!-- 跳過按鈕 -->
  14. <view class="skip-button" >
  15. <text class="skip-text">跳过 ({{ countdown }}s)</text>
  16. </view>
  17. <!-- 定位英語文字和中文文字到左下角 -->
  18. <view class="text-container">
  19. <text class="english-text">
  20. {{ configParamContent('creen_en') }}
  21. </text>
  22. <text class="chinese-text">
  23. {{ configParamContent('creen_zh') }}
  24. </text>
  25. </view>
  26. </view>
  27. </template>
  28. <script>
  29. // import config from '../../mixins/config.js'
  30. export default {
  31. name: 'SplashScreen',
  32. // mixins: [config],
  33. props: {
  34. // 顯示時長(秒)
  35. duration: {
  36. type: Number,
  37. default: 5
  38. }
  39. },
  40. data() {
  41. return {
  42. showSplash: false,
  43. countdown: 5,
  44. timer: null,
  45. splashContent: ''
  46. }
  47. },
  48. computed: {
  49. image() {
  50. try {
  51. // 優先從配置獲取
  52. const configImage = this.configParamContent && this.configParamContent('creen_image')
  53. if (configImage && configImage !== 'undefined' && configImage !== '') {
  54. return configImage
  55. }
  56. // 備用方案:從本地存儲獲取
  57. const storageImage = uni.getStorageSync('screen_image')
  58. if (storageImage && storageImage !== 'undefined' && storageImage !== '') {
  59. return storageImage
  60. }
  61. return ''
  62. } catch (error) {
  63. console.error('獲取開屏圖片失敗:', error)
  64. return ''
  65. }
  66. }
  67. },
  68. mounted() {
  69. this.initSplash()
  70. uni.hideTabBar()
  71. },
  72. beforeDestroy() {
  73. this.clearTimer()
  74. },
  75. methods: {
  76. // 初始化開動頁面
  77. async initSplash() {
  78. try {
  79. // 等待一小段時間確保 store 數據加載完成
  80. await this.$nextTick()
  81. // #ifdef H5
  82. // H5环境下检查sessionStorage,判断是否在当前会话中已经显示过开屏动画
  83. const hasShownSplash = sessionStorage.getItem('splash_shown')
  84. if (hasShownSplash) {
  85. console.log('当前会话已显示过开屏动画,跳过')
  86. this.$emit('close')
  87. return
  88. }
  89. // #endif
  90. // 獲取圖片URL,優先使用配置,然後使用本地存儲
  91. let imageUrl = ''
  92. // 嘗試從配置獲取
  93. if (this.$store.state.configList && this.$store.state.configList['creen_image']) {
  94. imageUrl = this.configParamContent('creen_image')
  95. }
  96. // 如果配置中沒有,嘗試從本地存儲獲取
  97. if (!imageUrl) {
  98. imageUrl = uni.getStorageSync('screen_image')
  99. }
  100. console.log('開屏圖片URL:', imageUrl)
  101. // 如果有圖片URL才顯示開屏
  102. if (imageUrl && imageUrl !== 'undefined' && imageUrl !== '') {
  103. this.splashContent = imageUrl
  104. this.countdown = this.duration
  105. this.showSplash = true
  106. // #ifdef H5
  107. // H5环境下设置sessionStorage标记,表示当前会话已显示过开屏动画
  108. sessionStorage.setItem('splash_shown', 'true')
  109. // #endif
  110. this.startCountdown()
  111. } else {
  112. console.log('沒有開屏圖片,跳過開屏動畫')
  113. this.$emit('close')
  114. }
  115. } catch (error) {
  116. console.error('獲取開動頁面內容失敗:', error)
  117. // 發生錯誤時直接關閉開屏
  118. this.$emit('close')
  119. }
  120. },
  121. // 開始倒計時
  122. startCountdown() {
  123. this.timer = setInterval(() => {
  124. this.countdown--
  125. if (this.countdown <= 0) {
  126. this.closeSplash()
  127. }
  128. }, 1000)
  129. },
  130. // 關閉開動頁面
  131. closeSplash() {
  132. this.showSplash = false
  133. uni.showTabBar({
  134. animation: true
  135. })
  136. this.clearTimer()
  137. this.$emit('close')
  138. },
  139. // 清除計時器
  140. clearTimer() {
  141. if (this.timer) {
  142. clearInterval(this.timer)
  143. this.timer = null
  144. }
  145. },
  146. // 圖片加載成功
  147. onImageLoad() {
  148. console.log('開屏圖片加載成功')
  149. },
  150. // 圖片加載失敗
  151. onImageError(e) {
  152. console.error('開屏圖片加載失敗:', e)
  153. // 圖片加載失敗時直接關閉開屏
  154. this.closeSplash()
  155. }
  156. }
  157. }
  158. </script>
  159. <style lang="scss" scoped>
  160. .splash-screen {
  161. position: fixed;
  162. top: 0;
  163. left: 0;
  164. width: 100vw;
  165. height: 100vh;
  166. background-color: #fff;
  167. z-index: 9999;
  168. display: flex;
  169. flex-direction: column;
  170. .splash-image{
  171. width: 100%;
  172. height: 100%;
  173. }
  174. }
  175. .splash-content {
  176. flex: 1;
  177. width: 100%;
  178. height: 80%;
  179. overflow: hidden;
  180. // 富文本樣式
  181. :deep(rich-text) {
  182. width: 100%;
  183. height: 100%;
  184. display: block;
  185. img{
  186. width: 100%;
  187. height: 100%;
  188. }
  189. }
  190. }
  191. .skip-button {
  192. position: absolute;
  193. top: 40rpx;
  194. left: 40rpx;
  195. background-color: #0000004D;
  196. border-radius: 100rpx;
  197. width: 148rpx ;
  198. height: 60rpx;
  199. text-align: center;
  200. z-index: 10000;
  201. .skip-text {
  202. font-size: 24rpx;
  203. line-height: 60rpx;
  204. color: #fff;
  205. }
  206. }
  207. // 文字容器定位到左下角
  208. .text-container {
  209. // position: absolute;
  210. // bottom: 80rpx;
  211. // left: 40rpx;
  212. // z-index: 10001;
  213. height: 20%;
  214. width: 100%;
  215. padding: 20rpx;
  216. display: flex;
  217. flex-direction: column;
  218. gap: 30rpx;
  219. }
  220. // 英文文字样式
  221. .english-text {
  222. font-family: PingFang SC;
  223. font-weight: 600;
  224. font-size: 32rpx; // 16px转换为rpx
  225. line-height: 48rpx; // 24px转换为rpx
  226. letter-spacing: 0;
  227. color: black;
  228. background: transparent;
  229. }
  230. // 中文文字样式
  231. .chinese-text {
  232. font-family: PingFang SC;
  233. // font-weight: 600;
  234. font-size: 32rpx; // 16px转换为rpx
  235. line-height: 48rpx; // 24px转换为rpx
  236. letter-spacing: 0;
  237. color: black;
  238. background: transparent;
  239. }
  240. // 確保覆蓋 tabbar
  241. .splash-screen {
  242. // 覆蓋所有內容,包括 tabbar
  243. position: fixed !important;
  244. z-index: 9999 !important;
  245. }
  246. </style>