launch.loader.ts 958 B

123456789101112131415161718192021222324252627282930
  1. import router from '@/router';
  2. import pinia, { useFlowStore } from '@/stores';
  3. const components = import.meta.glob('@/pages/**/*.vue');
  4. export default function launchLoader(container = '#app'): DEV.Loader {
  5. return async function (app, config) {
  6. let currentRoute = router.currentRoute.value.fullPath;
  7. if (currentRoute === '/') currentRoute = '/screen';
  8. if (config.image.com) {
  9. const component = components[`/src/pages/${config.image.com}.vue`];
  10. if (!component) throw { message: `配置 ${config.image.com} 组件未找到` };
  11. const path = '/screen';
  12. router.addRoute({
  13. name: 'screen',
  14. path,
  15. component,
  16. meta: { scan: true },
  17. });
  18. if (currentRoute === path) await router.replace(path);
  19. }
  20. if (config.image.page && config.image.page !== currentRoute) await router.replace(config.image.page);
  21. useFlowStore().$init(config.flowConfig)
  22. app.mount(container);
  23. };
  24. }