TransitionPage.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <template>
  2. <div class="page">
  3. <transition name="fade">
  4. <CesiumTransition
  5. v-if="isTransitioning && isDataReady"
  6. :province="province"
  7. :poi="poi"
  8. :district-center="districtCenter"
  9. :roads="roads"
  10. :satellite-image="satelliteImage"
  11. :boundary-url="boundaryUrl"
  12. :micro-view-range="microViewRange"
  13. @complete="onTransitionComplete"
  14. />
  15. </transition>
  16. </div>
  17. </template>
  18. <script>
  19. import CesiumTransition from '@/components/CesiumTransition.vue';
  20. export default {
  21. name: "TransitionPage",
  22. components: { CesiumTransition },
  23. data() {
  24. return {
  25. isTransitioning: true,
  26. isDataReady: false, // 控制加载时机
  27. // ====== 以下数据将在 initCityData 中被动态替换,这里填入默认兜底值 ======
  28. province: '北京市',
  29. districtCenter: [116.70, 39.80],
  30. microViewRange: 80000,
  31. // 中国边界 GeoJSON
  32. boundaryUrl: './china.json',
  33. // 微观标记点(可根据城市动态配置,暂设为null)
  34. poi: null,
  35. // 路网数据和卫星底图(因为不同城市的数据不同,如果是动态全国切换,建议默认清空)
  36. // 如果你需要保留北京的默认路网,可以在 if(targetCity === '北京市') 里面再单独赋回来
  37. roads: [],
  38. satelliteImage: null
  39. };
  40. },
  41. created() {
  42. // 组件创建时,立即去获取城市数据
  43. this.initCityData();
  44. },
  45. methods: {
  46. async initCityData() {
  47. // 1. 获取登录页通过路由传过来的城市名称,默认走北京
  48. // 例如:this.$router.push({ path: '/transition', query: { city: '成都市' } })
  49. const targetCity = this.$route.query.city || '北京市';
  50. try {
  51. // 2. 动态请求 public 目录下的全量城市配置文件
  52. // 请确保通过上一步的脚本生成的 cities.json 已经放置在 public 目录下
  53. const response = await fetch('./cities.json');
  54. if (!response.ok) {
  55. throw new Error(`HTTP error! status: ${response.status}`);
  56. }
  57. const allCitiesConfig = await response.json();
  58. // 3. 查找当前匹配城市的配置
  59. const config = allCitiesConfig[targetCity];
  60. if (config) {
  61. this.province = config.province; // 用于宏观视角高亮对应省份边界
  62. this.districtCenter = config.districtCenter; // 用于微观俯冲视角的中心点
  63. this.microViewRange = config.microViewRange; // 用于微观视角的相机高度
  64. // 动态提取卫星图:如果有配置则加载,没有则设为 null(避免显示错位)
  65. this.satelliteImage = config.satellite || null;
  66. // 如果不是北京,建议清空路网,或者根据需要加载该城市的路网
  67. this.roads = (targetCity === '北京市') ? this.defaultBeijingRoads : [];
  68. } else {
  69. console.warn(`⚠️ 未在 cities.json 中匹配到【${targetCity}】的配置,将使用默认北京视角`);
  70. }
  71. } catch (error) {
  72. console.error("加载城市配置 cities.json 失败,请检查文件是否在 public 目录下!", error);
  73. } finally {
  74. // 4. 无论成功还是失败(走兜底),都开放渲染条件,开始地球动画
  75. this.isDataReady = true;
  76. }
  77. },
  78. onTransitionComplete() {
  79. this.isTransitioning = false;
  80. console.log("地球过渡动画结束,正式进入系统首页!");
  81. this.$router.replace("/main");
  82. }
  83. }
  84. }
  85. </script>
  86. <style scoped>
  87. .page {
  88. width: 100vw;
  89. height: 100vh;
  90. overflow: hidden;
  91. background-color: #000;
  92. }
  93. .fade-enter-active, .fade-leave-active {
  94. transition: opacity 1.5s ease;
  95. }
  96. .fade-enter, .fade-leave-to {
  97. opacity: 0;
  98. }
  99. </style>