<!--
 * @Author: qfkong kongqf@yusys.com.cn
 * @Date: 2024-03-26 15:54:56
 * @LastEditors: qfkong kongqf@yusys.com.cn
 * @LastEditTime: 2024-04-13 23:19:43
 * @FilePath: \oca-web\src\App.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <div id="app" class="yu-frame-root">
    <transition>
      <router-view />
    </transition>
    <chatDragIcon v-if="false"></chatDragIcon>
    <chatDialog :keepCenter="true">
      <chat />
    </chatDialog>
  </div>
</template>

<script>
import chatDragIcon from '@xdjf/idd/components/XiaoyuChat/components/chatDragIcon.vue';
import chatDialog from '@xdjf/idd/components/XiaoyuChat/components/chatDialog.vue';
import chat from '@xdjf/idd/components/XiaoyuChat/components/chat.vue';

export default {
  name: 'App',
  components: {
    chatDragIcon,
    chatDialog,
    chat,
  },
  computed: {
    shouldShow() {
      const { path } = this.$route;
      const excludedPaths = ['/login', '/401', '/404'];
      if (excludedPaths.includes(path)) {
        return false;
      }
      const includePatterns = [/^\/@xdjf\/intelligent-due-diligence\/views(\/.*)?$/, /^.*$/];
      return includePatterns.some((pattern) => pattern.test(path));
    },
  },
  mounted() {
    this.hotUpdateVite(); // 用于在keepalive场景下，vite 更新代码页面没有重新加载的问题
  },
  methods: {
    hotUpdateVite() {
      // 判断是否开启热更新
      if (import.meta.hot) {
        // 监听vite更新
        import.meta.hot.on('vite:beforeUpdate', (updatesObj) => {
          updatesObj.updates.forEach((element) => {
            this.$route.matched.forEach((matched) => {
              // 目前路由的文件路径
              const filePath = matched.components.default.__file;
              // vite 热更新的文件路径
              const upPath = element.path.split('?')[0];
              // 判断是否是当前页面
              if (filePath.indexOf(upPath) !== -1) location.reload(); // 强制页面重新加载
            });
          });
        });
      }
    },
  },
};
</script>
