爱简收旧衣按件回收前端代码仓库
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.

301 lines
6.5 KiB

10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
9 months ago
9 months ago
9 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
  1. <template>
  2. <view v-if="!globalDataLoaded" class="global-loading">
  3. <view class="loading-container">
  4. <view class="loading-logo">
  5. <image src="/static/回收/衣物.png" mode="aspectFit" class="logo-img" />
  6. </view>
  7. <view class="loading-spinner">
  8. <view class="spinner"></view>
  9. </view>
  10. <text class="loading-text">正在加载...</text>
  11. <view class="loading-progress">
  12. <view class="progress-bar" :style="{width: loadingProgress + '%'}"></view>
  13. </view>
  14. </view>
  15. </view>
  16. </template>
  17. <script>
  18. import routerInterception from '@/utils/router-interception.js'
  19. import config from '/config.js'
  20. export default {
  21. data() {
  22. return {
  23. globalDataLoaded: false,
  24. loadingProgress: 0,
  25. loadedCount: 0,
  26. totalRequests: 3 // 总共需要加载的请求数量
  27. }
  28. },
  29. globalData: {
  30. flag: 1,
  31. login_status: true,
  32. phone: null,
  33. bannerList: [],
  34. pricePreviewList: [],
  35. configData: [],
  36. qr_path: '',
  37. isAppDataReady: false // 新增标志位
  38. },
  39. onLaunch: function() {
  40. routerInterception()
  41. this.initializeAppData()
  42. console.log('App Launch')
  43. },
  44. onLoad: function() {
  45. console.log('App Show')
  46. },
  47. onHide: function() {
  48. console.log('App Hide')
  49. },
  50. methods: {
  51. // 初始化应用数据
  52. async initializeAppData() {
  53. try {
  54. // 设置初始进度
  55. this.loadingProgress = 0
  56. this.loadedCount = 0
  57. // 并发加载所有数据
  58. const promises = [
  59. this.getBannerList(),
  60. this.getPricePreviewList(),
  61. this.getConfigData(),
  62. ]
  63. // this.getQrCode()
  64. await Promise.all(promises)
  65. // 确保进度达到100%
  66. this.loadingProgress = 100
  67. // 所有数据加载完成
  68. this.globalDataLoaded = true
  69. getApp().globalData.isAppDataReady = true
  70. // 延迟一点时间让用户看到加载完成的状态
  71. setTimeout(() => {
  72. uni.$emit('appDataReady')
  73. }, 500)
  74. } catch (error) {
  75. console.error('App data loading failed:', error)
  76. // 即使失败也要让应用继续运行
  77. this.loadingProgress = 100
  78. this.globalDataLoaded = true
  79. getApp().globalData.isAppDataReady = true
  80. setTimeout(() => {
  81. uni.$emit('appDataReady')
  82. }, 500)
  83. }
  84. },
  85. // 更新加载进度
  86. updateProgress() {
  87. this.loadedCount++
  88. this.loadingProgress = Math.round((this.loadedCount / this.totalRequests) * 100)
  89. },
  90. getBannerList() {
  91. return new Promise((resolve) => {
  92. if (!this.$api) {
  93. this.updateProgress()
  94. resolve()
  95. return
  96. }
  97. this.$api('getBanner', {}, res => {
  98. if (res && res.code === 200 && Array.isArray(res.result)) {
  99. getApp().globalData.bannerList = res.result
  100. console.log(getApp().globalData.bannerList, 'bannerList')
  101. uni.$emit('bannerListUpdated')
  102. }
  103. this.updateProgress()
  104. resolve()
  105. })
  106. })
  107. },
  108. getPricePreviewList() {
  109. return new Promise((resolve) => {
  110. if (!this.$api) {
  111. this.updateProgress()
  112. resolve()
  113. return
  114. }
  115. this.$api('getPricePreviewClassList', {}, res => {
  116. if (res && res.success && Array.isArray(res.result)) {
  117. getApp().globalData.pricePreviewList = res.result
  118. uni.$emit('pricePreviewListUpdated')
  119. }
  120. this.updateProgress()
  121. resolve()
  122. })
  123. })
  124. },
  125. getConfigData() {
  126. return new Promise((resolve) => {
  127. if (!this.$api) {
  128. this.updateProgress()
  129. resolve()
  130. return
  131. }
  132. this.$api('getConfig', {}, res => {
  133. console.log('Config data response:', JSON.parse(JSON.stringify(res)))
  134. if (res && res.success && Array.isArray(res.result)) {
  135. getApp().globalData.configData = res.result
  136. uni.$emit('configDataUpdated')
  137. }
  138. this.updateProgress()
  139. resolve()
  140. })
  141. })
  142. },
  143. getQrCode() {
  144. return new Promise((resolve) => {
  145. if (!uni.getStorageSync('token')) {
  146. this.updateProgress()
  147. resolve()
  148. return
  149. }
  150. uni.getImageInfo({
  151. src: `${config.baseUrl}/recycle-admin/applet/promotion/getInviteCode?token=${uni.getStorageSync('token')}`,
  152. success: res => {
  153. getApp().globalData.qr_path = res.path
  154. console.log(getApp().globalData.qr_path, 'qr_path')
  155. this.updateProgress()
  156. resolve()
  157. },
  158. fail: err => {
  159. console.log('QR code load failed:', err)
  160. this.updateProgress()
  161. resolve()
  162. }
  163. })
  164. })
  165. }
  166. }
  167. }
  168. </script>
  169. <style>
  170. /* 全局loading样式 */
  171. .global-loading {
  172. position: fixed;
  173. top: 0;
  174. left: 0;
  175. right: 0;
  176. bottom: 0;
  177. background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  178. display: flex;
  179. align-items: center;
  180. justify-content: center;
  181. z-index: 99999;
  182. }
  183. .loading-container {
  184. display: flex;
  185. flex-direction: column;
  186. align-items: center;
  187. justify-content: center;
  188. }
  189. .loading-logo {
  190. margin-bottom: 60rpx;
  191. }
  192. .logo-img {
  193. width: 160rpx;
  194. height: 160rpx;
  195. border-radius: 32rpx;
  196. box-shadow: 0 8rpx 32rpx rgba(0, 0, 0, 0.2);
  197. }
  198. .loading-spinner {
  199. margin-bottom: 40rpx;
  200. }
  201. .spinner {
  202. width: 60rpx;
  203. height: 60rpx;
  204. border: 4rpx solid rgba(255, 255, 255, 0.3);
  205. border-top-color: #fff;
  206. border-radius: 50%;
  207. animation: spin 1s linear infinite;
  208. }
  209. .loading-text {
  210. color: #fff;
  211. font-size: 32rpx;
  212. font-weight: 500;
  213. margin-bottom: 40rpx;
  214. opacity: 0.9;
  215. }
  216. .loading-progress {
  217. width: 400rpx;
  218. height: 6rpx;
  219. background: rgba(255, 255, 255, 0.2);
  220. border-radius: 3rpx;
  221. overflow: hidden;
  222. }
  223. .progress-bar {
  224. height: 100%;
  225. background: linear-gradient(90deg, #fff 0%, #f0f8ff 100%);
  226. border-radius: 3rpx;
  227. transition: width 0.3s ease;
  228. box-shadow: 0 0 10rpx rgba(255, 255, 255, 0.3);
  229. }
  230. @keyframes spin {
  231. from { transform: rotate(0deg); }
  232. to { transform: rotate(360deg); }
  233. }
  234. /* 原有样式 */
  235. /*每个页面公共css */
  236. .uni-tabbar-bottom {
  237. display: none;
  238. }
  239. .icon {
  240. width: 50rpx;
  241. height: 50rpx;
  242. }
  243. .nav-bar {
  244. /* margin-top: calc(70rpx + env(safe-area-inset-top)); */
  245. height: 30%;
  246. display: flex;
  247. justify-content: center;
  248. }
  249. /* 每个页面公共css */
  250. /* 解决小程序和app滚动条的问题 */
  251. ::-webkit-scrollbar {
  252. display: none;
  253. width: 0 !important;
  254. height: 0 !important;
  255. -webkit-appearance: none;
  256. background: transparent;
  257. color: transparent;
  258. }
  259. /* 解决H5的问题 */
  260. uni-scroll-view .uni-scroll-view::-webkit-scrollbar {
  261. display: none;
  262. width: 0 !important;
  263. height: 0 !important;
  264. -webkit-appearance: none;
  265. background: transparent;
  266. color: transparent;
  267. }
  268. </style>