hookehuyr

feat(路由): 为checkin页面添加路由名称和组件名称

添加路由名称和组件名称以支持keep-alive缓存功能
在map.vue中实现activated和deactivated生命周期钩子
1 /* 1 /*
2 * @Date: 2023-05-29 11:10:19 2 * @Date: 2023-05-29 11:10:19
3 * @LastEditors: hookehuyr hookehuyr@gmail.com 3 * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2025-08-26 15:46:05 4 + * @LastEditTime: 2025-09-18 10:25:55
5 * @FilePath: /map-demo/src/route.js 5 * @FilePath: /map-demo/src/route.js
6 * @Description: 文件描述 6 * @Description: 文件描述
7 */ 7 */
...@@ -114,6 +114,7 @@ export default [ ...@@ -114,6 +114,7 @@ export default [
114 }, 114 },
115 { 115 {
116 path: '/checkin', 116 path: '/checkin',
117 + name: 'CheckinMap',
117 component: () => import('@/views/checkin/map.vue'), 118 component: () => import('@/views/checkin/map.vue'),
118 meta: { 119 meta: {
119 title: '地图', 120 title: '地图',
...@@ -121,6 +122,7 @@ export default [ ...@@ -121,6 +122,7 @@ export default [
121 }, 122 },
122 { 123 {
123 path: '/checkin/info', 124 path: '/checkin/info',
125 + name: 'CheckinInfo',
124 component: () => import('@/views/checkin/info.vue'), 126 component: () => import('@/views/checkin/info.vue'),
125 meta: { 127 meta: {
126 title: '详情页', 128 title: '详情页',
......
1 <!-- 1 <!--
2 * @Date: 2024-09-15 22:08:49 2 * @Date: 2024-09-15 22:08:49
3 * @LastEditors: hookehuyr hookehuyr@gmail.com 3 * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2025-09-17 19:50:14 4 + * @LastEditTime: 2025-09-18 10:31:19
5 * @FilePath: /map-demo/src/views/checkin/info.vue 5 * @FilePath: /map-demo/src/views/checkin/info.vue
6 * @Description: 文件描述 6 * @Description: 文件描述
7 --> 7 -->
...@@ -87,7 +87,7 @@ ...@@ -87,7 +87,7 @@
87 </div> 87 </div>
88 </template> 88 </template>
89 89
90 -<script setup> 90 +<script setup name="CheckinInfo">
91 import { ref, watch, watchEffect } from 'vue' 91 import { ref, watch, watchEffect } from 'vue'
92 import { useRoute, useRouter } from 'vue-router' 92 import { useRoute, useRouter } from 'vue-router'
93 import { showImagePreview, showDialog } from 'vant'; 93 import { showImagePreview, showDialog } from 'vant';
......
1 <!-- 1 <!--
2 * @Date: 2023-05-19 14:54:27 2 * @Date: 2023-05-19 14:54:27
3 * @LastEditors: hookehuyr hookehuyr@gmail.com 3 * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2025-09-18 10:10:09 4 + * @LastEditTime: 2025-09-18 10:31:06
5 * @FilePath: /map-demo/src/views/checkin/map.vue 5 * @FilePath: /map-demo/src/views/checkin/map.vue
6 * @Description: 公众地图主体页面 6 * @Description: 公众地图主体页面
7 --> 7 -->
...@@ -173,6 +173,7 @@ window._AMapSecurityConfig = { ...@@ -173,6 +173,7 @@ window._AMapSecurityConfig = {
173 } 173 }
174 174
175 export default { 175 export default {
176 + name: 'CheckinMap',
176 components: { pageInfo, audioBackground1, BottomNav }, 177 components: { pageInfo, audioBackground1, BottomNav },
177 computed: { 178 computed: {
178 ...mapState(mainStore, ['audio_entity', 'audio_src', 'audio_status']), 179 ...mapState(mainStore, ['audio_entity', 'audio_src', 'audio_status']),
...@@ -322,6 +323,12 @@ export default { ...@@ -322,6 +323,12 @@ export default {
322 // 设置默认标题,避免显示undefined 323 // 设置默认标题,避免显示undefined
323 document.title = '地图加载中...'; 324 document.title = '地图加载中...';
324 325
326 + // 将当前页面添加到缓存列表
327 + const store = mainStore();
328 + if (!store.keepPages.includes('CheckinMap')) {
329 + store.keepPages.push('CheckinMap');
330 + }
331 +
325 const AMap = await AMapLoader.load({ 332 const AMap = await AMapLoader.load({
326 key: '17b8fc386104b89db88b60b049a6dbce', // 控制台获取 333 key: '17b8fc386104b89db88b60b049a6dbce', // 控制台获取
327 version: '2.0', // 指定API版本 334 version: '2.0', // 指定API版本
...@@ -409,6 +416,37 @@ export default { ...@@ -409,6 +416,37 @@ export default {
409 autoFitView: true, // 是否自动调整地图视野到显示的路线 416 autoFitView: true, // 是否自动调整地图视野到显示的路线
410 }); 417 });
411 }, 418 },
419 + // keep-alive 组件激活时调用
420 + activated() {
421 + // 组件被激活时,不需要重新初始化地图,保持之前的状态
422 + console.log('地图组件已激活,保持之前状态');
423 + // 确保当前页面在缓存列表中
424 + const store = mainStore();
425 + if (!store.keepPages.includes('CheckinMap')) {
426 + store.keepPages.push('CheckinMap');
427 + }
428 + // 重置page-info组件状态,关闭浮动面板
429 + this.info_height = 0;
430 + this.itemInfo = {};
431 + // 重置浮动面板样式
432 + this.$nextTick(() => {
433 + $('.van-floating-panel__content').css('borderRadius', '1.25rem');
434 + $('.van-floating-panel').css('boxShadow', 'none');
435 + // 还原标记点样式
436 + this.resetMarkStyle();
437 + });
438 + // 如果地图已经初始化,重新设置地图大小以适应容器
439 + if (this.map) {
440 + this.$nextTick(() => {
441 + this.map.getSize();
442 + });
443 + }
444 + },
445 + // keep-alive 组件停用时调用
446 + deactivated() {
447 + // 组件被停用时,保存当前状态
448 + console.log('地图组件已停用,状态已保存');
449 + },
412 watch: { 450 watch: {
413 // // 监听 $route 对象的 query 属性 451 // // 监听 $route 对象的 query 属性
414 // '$route.query': { 452 // '$route.query': {
......