web端产品库 vite版本
This commit is contained in:
		| @@ -1,61 +1,42 @@ | ||||
| import store from "../store"; | ||||
| import appEntry from "../views/appEntry"; | ||||
| import {waiting} from "../utils"; | ||||
|  | ||||
| export default { | ||||
|   routes: () => store.state.apps.map(e => { | ||||
|     return { | ||||
|       ...e, | ||||
|       component: () => import(`../views/apps/${e.entry}`) | ||||
|     } | ||||
|   }), | ||||
|   routes: [], | ||||
|   init() { | ||||
|     //约束正则式 | ||||
|     store.commit("cleanApps") | ||||
|     this.routes = [] | ||||
|     // 自动化本工程应用 | ||||
|     this.loadApps() | ||||
|     return this.loadApps() | ||||
|   }, | ||||
|   loadApps() { | ||||
|     //锁屏loading | ||||
|     waiting.init({innerHTML: '应用加载中..'}) | ||||
|     //新App的自动化格式 | ||||
|     let files = require.context('../../packages', true, /\.(\/.+)\/App[A-Z][^\/]+\.vue$/) | ||||
|     files.keys().map(path => { | ||||
|       if (files(path).default) { | ||||
|         let {name, label} = files(path).default, | ||||
|             addApp = { | ||||
|               name, label: label || name, | ||||
|               path: path.replace(/\.(\/.+\/App.+)\.vue$/, '/packages$1'), | ||||
|               entry: 'appEntry', | ||||
|               module: files(path).default | ||||
|             } | ||||
|         //命名规范入口文件必须以App开头 | ||||
|         store.commit("addApp", addApp) | ||||
|     let files = import.meta.glob('../../packages/**/App*.vue') | ||||
|     let cores = import.meta.glob('../../core/**/App*.vue') | ||||
|     let projects = import.meta.glob('../../project/**/App*.vue') | ||||
|     files = {...files, ...cores, ...projects} | ||||
|     return Promise.all(Object.keys(files).map(path => { | ||||
|       if (/App[A-Z]\w+\.vue/.test(path)) { | ||||
|         return files?.[path]()?.then(file => { | ||||
|           let {name, label} = file.default, | ||||
|               addApp = { | ||||
|                 name: [path.replace(/[.\/]+(project)?[\/]([a-z]+).+/, '$2'), name].join("_"), label: label || name, | ||||
|                 path: path.replace(/[.\/]+([a-zA-Z].+\/App[A-Z]\w+)\.vue$/, '/$1'), | ||||
|                 component: appEntry, | ||||
|                 module: file.default | ||||
|               } | ||||
|           //命名规范入口文件必须以App开头 | ||||
|           waiting.setContent(`加载${name}...`) | ||||
|           this.routes.push(addApp) | ||||
|           return store.commit("addApp", addApp) | ||||
|         }) | ||||
|       } else { | ||||
|         return Promise.resolve() | ||||
|       } | ||||
|     }) | ||||
|     let cores = require.context('../../core', true, /\.(\/.+)\/App[^\/]+\.vue$/) | ||||
|     cores.keys().map(path => { | ||||
|       if (cores(path).default) { | ||||
|         let {name, label} = cores(path).default, | ||||
|             addApp = { | ||||
|               name, label: label || name, | ||||
|               path: path.replace(/\.(\/.+\/App.+)\.vue$/, '/core$1'), | ||||
|               entry: 'appEntry', | ||||
|               module: cores(path).default | ||||
|             } | ||||
|         //命名规范入口文件必须以App开头 | ||||
|         store.commit("addApp", addApp) | ||||
|       } | ||||
|     }) | ||||
|     let project = require.context('../../project', true, /\.(\/.+)\/App[^\/]+\.vue$/) | ||||
|     project.keys().map(path => { | ||||
|       if (project(path).default) { | ||||
|         let {name, label} = project(path).default, | ||||
|             addApp = { | ||||
|               name: [path.replace(/\.\/([^\/]+)\/.*/, '$1'), name].join("_"), label: label || name, | ||||
|               path: path.replace(/\.(\/.+\/App.+)\.vue$/, '/project$1'), | ||||
|               entry: 'appEntry', | ||||
|               module: project(path).default | ||||
|             } | ||||
|         //命名规范入口文件必须以App开头 | ||||
|         store.commit("addApp", addApp) | ||||
|       } | ||||
|     }) | ||||
|     })).then(() => waiting.close()) | ||||
|   } | ||||
| } | ||||
|   | ||||
| @@ -3,16 +3,20 @@ import VueRouter from 'vue-router' | ||||
| import autoRoutes from './autoRoutes' | ||||
|  | ||||
| Vue.use(VueRouter) | ||||
| autoRoutes.init() | ||||
| export default new VueRouter({ | ||||
|  | ||||
| export default autoRoutes.init().then(() => new VueRouter({ | ||||
|   mode: 'history', | ||||
|   hashbang: false, | ||||
|   routes: autoRoutes.routes(), | ||||
|   routes: [ | ||||
|     {path: "/", name: "产品库"}, | ||||
|     ...autoRoutes.routes | ||||
|   ], | ||||
|   scrollBehavior(to) { | ||||
|     console.log(to) | ||||
|     if (to.hash) { | ||||
|       return { | ||||
|         selector: to.hash | ||||
|       } | ||||
|     } | ||||
|   } | ||||
| }) | ||||
| })) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user