splash.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. <template>
  2. <view class="splash-container">
  3. <!-- 背景装饰 -->
  4. <view class="splash-bg-1"></view>
  5. <view class="splash-bg-2"></view>
  6. <!-- Logo 区域 -->
  7. <view class="logo-section">
  8. <view class="logo-wrapper">
  9. <view class="logo-glow"></view>
  10. <image class="logo-icon" src="/static/image/public/logo.png" mode="aspectFit"></image>
  11. </view>
  12. <text class="app-name">{{appName}}</text>
  13. <text class="app-slogan">您的客户关系管理助手</text>
  14. </view>
  15. <!-- 加载动画 -->
  16. <view class="loading-section">
  17. <text class="loading-text">
  18. 正在加载
  19. <view class="loading-dots">
  20. <view class="dot dot1"></view>
  21. <view class="dot dot2"></view>
  22. <view class="dot dot3"></view>
  23. </view>
  24. </text>
  25. </view>
  26. <!-- 版本信息 -->
  27. <view class="version-info">
  28. <text class="version-text">{{version}}</text>
  29. <view class="version-text">
  30. 浙江舒博特网络科技有限公司提供技术支持
  31. </view>
  32. </view>
  33. </view>
  34. </template>
  35. <script setup>
  36. import {
  37. ref,
  38. onMounted
  39. } from 'vue'
  40. import {
  41. isLogin,
  42. getToken,
  43. saveUserInfo,
  44. clearUserInfo
  45. } from '@/utils/userCache.js'
  46. import {
  47. getUserInfo as fetchUserInfo
  48. } from '@/api/login.js'
  49. import {
  50. getCurrentConfig
  51. } from '@/config/index.js'
  52. const loadingText = ref('正在加载...')
  53. let appName = ref('')
  54. let version = ref('')
  55. // 页面加载
  56. onMounted(async () => {
  57. const config = await getCurrentConfig()
  58. console.log(config,"configconfigconfigconfig");
  59. appName.value = config.appName
  60. version.value = config.appVersion
  61. initApp()
  62. })
  63. /**
  64. * 初始化应用
  65. */
  66. const initApp = async () => {
  67. try {
  68. // 模拟加载延迟(提升用户体验)
  69. await sleep(500)
  70. loadingText.value = '检查登录状态...'
  71. // 获取本地 token
  72. const token = getToken()
  73. // 如果没有 token,直接跳转登录页
  74. if (!token) {
  75. console.log('未登录,token 不存在')
  76. await sleep(800)
  77. uni.reLaunch({
  78. url: '/pages/index/index'
  79. })
  80. return
  81. }
  82. // 调用 getUserInfo 接口验证 token
  83. const res = await fetchUserInfo({})
  84. if (res.code === 200) {
  85. // token 有效,更新用户信息
  86. const userInfo = res.data || res
  87. saveUserInfo(userInfo, token)
  88. console.log('登录态有效,用户信息已更新')
  89. // 延迟跳转,让动画更流畅
  90. await sleep(500)
  91. // 已登录,跳转首页
  92. uni.reLaunch({
  93. url: '/pages/index/index'
  94. })
  95. } else {
  96. // token 失效,清除本地存储
  97. console.log('登录凭证失效,需要重新登录')
  98. clearUserInfo()
  99. await sleep(800)
  100. // 跳转登录页
  101. uni.reLaunch({
  102. url: '/pages/login/login'
  103. })
  104. }
  105. } catch (error) {
  106. console.error('验证登录态失败:', error)
  107. // 接口调用失败,也视为 token 失效
  108. clearUserInfo()
  109. // 出错时跳转到登录页
  110. uni.reLaunch({
  111. url: '/pages/login/login'
  112. })
  113. }
  114. }
  115. /**
  116. * 延时函数
  117. * @param {number} ms - 毫秒数
  118. */
  119. const sleep = (ms) => {
  120. return new Promise(resolve => setTimeout(resolve, ms))
  121. }
  122. </script>
  123. <style lang="scss" scoped>
  124. .splash-container {
  125. min-height: 100vh;
  126. background: linear-gradient(135deg, #4A90E2 0%, #6FB3F2 50%, #87CEEB 100%);
  127. position: relative;
  128. overflow: hidden;
  129. display: flex;
  130. flex-direction: column;
  131. align-items: center;
  132. justify-content: center;
  133. padding: 0 40rpx;
  134. .splash-bg-1 {
  135. position: absolute;
  136. top: -20%;
  137. left: -10%;
  138. width: 60%;
  139. height: 60%;
  140. background: radial-gradient(circle, rgba(255,255,255,0.15) 0%, transparent 70%);
  141. border-radius: 50%;
  142. animation: floatBg1 8s ease-in-out infinite;
  143. }
  144. .splash-bg-2 {
  145. position: absolute;
  146. bottom: -20%;
  147. right: -10%;
  148. width: 70%;
  149. height: 70%;
  150. background: radial-gradient(circle, rgba(255,255,255,0.12) 0%, transparent 70%);
  151. border-radius: 50%;
  152. animation: floatBg2 10s ease-in-out infinite;
  153. }
  154. }
  155. // Logo 区域
  156. .logo-section {
  157. display: flex;
  158. flex-direction: column;
  159. align-items: center;
  160. margin-bottom: 120rpx;
  161. position: relative;
  162. z-index: 10;
  163. .logo-wrapper {
  164. position: relative;
  165. width: 240rpx;
  166. height: 240rpx;
  167. display: flex;
  168. align-items: center;
  169. justify-content: center;
  170. .logo-glow {
  171. position: absolute;
  172. top: 50%;
  173. left: 50%;
  174. transform: translate(-50%, -50%);
  175. width: 280rpx;
  176. height: 280rpx;
  177. background: radial-gradient(circle, rgba(255,255,255,0.3) 0%, transparent 70%);
  178. border-radius: 50%;
  179. animation: logoGlow 3s ease-in-out infinite;
  180. }
  181. .logo-icon {
  182. width: 200rpx;
  183. height: 200rpx;
  184. border-radius: 44rpx;
  185. background: rgba(255, 255, 255, 0.95);
  186. box-shadow: 0 20rpx 60rpx rgba(0, 0, 0, 0.15),
  187. 0 0 40rpx rgba(255, 255, 255, 0.3);
  188. display: flex;
  189. align-items: center;
  190. justify-content: center;
  191. animation: logoFloat 3s ease-in-out infinite;
  192. position: relative;
  193. z-index: 2;
  194. }
  195. }
  196. .app-name {
  197. font-size: 48rpx;
  198. font-weight: 600;
  199. color: #ffffff;
  200. margin-top: 48rpx;
  201. letter-spacing: 3rpx;
  202. text-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.15);
  203. }
  204. .app-slogan {
  205. font-size: 26rpx;
  206. color: rgba(255, 255, 255, 0.85);
  207. margin-top: 20rpx;
  208. letter-spacing: 1rpx;
  209. text-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.1);
  210. }
  211. }
  212. // 加载动画
  213. .loading-section {
  214. display: flex;
  215. flex-direction: column;
  216. align-items: center;
  217. position: relative;
  218. z-index: 10;
  219. .loading-text {
  220. font-size: 28rpx;
  221. color: rgba(255, 255, 255, 0.95);
  222. letter-spacing: 2rpx;
  223. text-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.1);
  224. display: flex;
  225. align-items: center;
  226. justify-content: center;
  227. background: rgba(255, 255, 255, 0.15);
  228. padding: 20rpx 40rpx;
  229. border-radius: 40rpx;
  230. backdrop-filter: blur(10rpx);
  231. box-shadow: 0 8rpx 32rpx rgba(0, 0, 0, 0.1);
  232. .loading-dots {
  233. display: flex;
  234. justify-content: center;
  235. align-items: center;
  236. margin-left: 8rpx;
  237. height: 20rpx;
  238. .dot {
  239. width: 12rpx;
  240. height: 12rpx;
  241. border-radius: 50%;
  242. background-color: #ffffff;
  243. margin: 0 4rpx;
  244. opacity: 0.4;
  245. box-shadow: 0 0 15rpx rgba(255, 255, 255, 0.5);
  246. }
  247. .dot1 {
  248. animation: loadingDot 1.4s ease-in-out infinite;
  249. }
  250. .dot2 {
  251. animation: loadingDot 1.4s ease-in-out 0.2s infinite;
  252. }
  253. .dot3 {
  254. animation: loadingDot 1.4s ease-in-out 0.4s infinite;
  255. }
  256. }
  257. }
  258. }
  259. // 版本信息
  260. .version-info {
  261. position: absolute;
  262. bottom: 80rpx;
  263. display: flex;
  264. flex-direction: column;
  265. align-items: center;
  266. justify-content: center;
  267. z-index: 10;
  268. background: rgba(255, 255, 255, 0.1);
  269. padding: 20rpx 40rpx;
  270. border-radius: 32rpx;
  271. backdrop-filter: blur(10rpx);
  272. box-shadow: 0 8rpx 32rpx rgba(0, 0, 0, 0.1);
  273. border: 1rpx solid rgba(255, 255, 255, 0.2);
  274. .version-text {
  275. font-size: 22rpx;
  276. color: rgba(255, 255, 255, 0.7);
  277. text-align: center;
  278. line-height: 1.6;
  279. text-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.1);
  280. }
  281. }
  282. // 动画
  283. @keyframes logoFloat {
  284. 0%, 100% {
  285. transform: translateY(0) scale(1);
  286. }
  287. 50% {
  288. transform: translateY(-15rpx) scale(1.02);
  289. }
  290. }
  291. @keyframes logoGlow {
  292. 0%, 100% {
  293. opacity: 0.5;
  294. transform: translate(-50%, -50%) scale(1);
  295. }
  296. 50% {
  297. opacity: 0.8;
  298. transform: translate(-50%, -50%) scale(1.1);
  299. }
  300. }
  301. @keyframes loadingDot {
  302. 0%, 80%, 100% {
  303. transform: scale(0.8);
  304. opacity: 0.4;
  305. }
  306. 40% {
  307. transform: scale(1.2);
  308. opacity: 1;
  309. }
  310. }
  311. @keyframes floatBg1 {
  312. 0%, 100% {
  313. transform: translate(0, 0) scale(1);
  314. }
  315. 50% {
  316. transform: translate(30rpx, -30rpx) scale(1.05);
  317. }
  318. }
  319. @keyframes floatBg2 {
  320. 0%, 100% {
  321. transform: translate(0, 0) scale(1);
  322. }
  323. 50% {
  324. transform: translate(-30rpx, 30rpx) scale(1.08);
  325. }
  326. }
  327. </style>