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

256 lines
5.5 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. <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. @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. // 獲取圖片URL,優先使用配置,然後使用本地存儲
  82. let imageUrl = ''
  83. // 嘗試從配置獲取
  84. if (this.$store.state.configList && this.$store.state.configList['creen_image']) {
  85. imageUrl = this.configParamContent('creen_image')
  86. }
  87. // 如果配置中沒有,嘗試從本地存儲獲取
  88. if (!imageUrl) {
  89. imageUrl = uni.getStorageSync('screen_image')
  90. }
  91. console.log('開屏圖片URL:', imageUrl)
  92. // 如果有圖片URL才顯示開屏
  93. if (imageUrl && imageUrl !== 'undefined' && imageUrl !== '') {
  94. this.splashContent = imageUrl
  95. this.countdown = this.duration
  96. this.showSplash = true
  97. this.startCountdown()
  98. } else {
  99. console.log('沒有開屏圖片,跳過開屏動畫')
  100. this.$emit('close')
  101. }
  102. } catch (error) {
  103. console.error('獲取開動頁面內容失敗:', error)
  104. // 發生錯誤時直接關閉開屏
  105. this.$emit('close')
  106. }
  107. },
  108. // 開始倒計時
  109. startCountdown() {
  110. this.timer = setInterval(() => {
  111. this.countdown--
  112. if (this.countdown <= 0) {
  113. this.closeSplash()
  114. }
  115. }, 1000)
  116. },
  117. // 關閉開動頁面
  118. closeSplash() {
  119. this.showSplash = false
  120. uni.showTabBar({
  121. animation: true
  122. })
  123. this.clearTimer()
  124. this.$emit('close')
  125. },
  126. // 清除計時器
  127. clearTimer() {
  128. if (this.timer) {
  129. clearInterval(this.timer)
  130. this.timer = null
  131. }
  132. },
  133. // 圖片加載成功
  134. onImageLoad() {
  135. console.log('開屏圖片加載成功')
  136. },
  137. // 圖片加載失敗
  138. onImageError(e) {
  139. console.error('開屏圖片加載失敗:', e)
  140. // 圖片加載失敗時直接關閉開屏
  141. this.closeSplash()
  142. }
  143. }
  144. }
  145. </script>
  146. <style lang="scss" scoped>
  147. .splash-screen {
  148. position: fixed;
  149. top: 0;
  150. left: 0;
  151. width: 100vw;
  152. height: 100vh;
  153. background-color: #fff;
  154. z-index: 9999;
  155. display: flex;
  156. flex-direction: column;
  157. .splash-image{
  158. width: 100%;
  159. height: 100%;
  160. }
  161. }
  162. .splash-content {
  163. flex: 1;
  164. width: 100%;
  165. height: 100%;
  166. overflow: hidden;
  167. // 富文本樣式
  168. :deep(rich-text) {
  169. width: 100%;
  170. height: 100%;
  171. display: block;
  172. img{
  173. width: 100%;
  174. height: 100%;
  175. }
  176. }
  177. }
  178. .skip-button {
  179. position: absolute;
  180. top: 100rpx;
  181. left: 40rpx;
  182. background-color: #0000004D;
  183. border-radius: 100rpx;
  184. width: 148rpx ;
  185. height: 60rpx;
  186. text-align: center;
  187. z-index: 10000;
  188. .skip-text {
  189. font-size: 24rpx;
  190. line-height: 60rpx;
  191. color: #fff;
  192. }
  193. }
  194. // 文字容器定位到左下角
  195. .text-container {
  196. position: absolute;
  197. bottom: 80rpx;
  198. left: 40rpx;
  199. z-index: 10001;
  200. display: flex;
  201. flex-direction: column;
  202. gap: 8rpx;
  203. }
  204. // 英文文字样式
  205. .english-text {
  206. font-family: PingFang SC;
  207. font-weight: 600;
  208. font-size: 32rpx; // 16px转换为rpx
  209. line-height: 48rpx; // 24px转换为rpx
  210. letter-spacing: 0;
  211. color: #FFFFFF;
  212. background: transparent;
  213. }
  214. // 中文文字样式
  215. .chinese-text {
  216. font-family: PingFang SC;
  217. // font-weight: 600;
  218. font-size: 32rpx; // 16px转换为rpx
  219. line-height: 48rpx; // 24px转换为rpx
  220. letter-spacing: 0;
  221. color: #FFFFFF;
  222. background: transparent;
  223. }
  224. // 確保覆蓋 tabbar
  225. .splash-screen {
  226. // 覆蓋所有內容,包括 tabbar
  227. position: fixed !important;
  228. z-index: 9999 !important;
  229. }
  230. </style>