web端产品库 vite版本

This commit is contained in:
aixianling
2022-04-27 18:18:57 +08:00
parent ee93320cad
commit 4f0178c627
172 changed files with 4520 additions and 16858 deletions

View File

@@ -44,7 +44,7 @@ export default {
return (this.apps || []).filter(e => !this.search || reg.test(e.name) || reg.test(e.label))
},
selectedApp() {
return this.$route.matched.length > 0
return this.$route.name != "产品库"
},
login() {
let url = '/auth/oauth/token';

View File

@@ -1,25 +0,0 @@
import Vue from 'vue';
import App from './App.vue';
import ui from 'element-ui';
import router from './router/router';
import axios from './router/axios';
import utils from './utils';
import vcUI from 'dvcp-ui';
import 'dvcp-ui/lib/styles/common.scss';
import 'dvcp-ui/lib/dvcp-ui.css';
import store from './store';
import dataV from '@jiaminghi/data-view';
Vue.use(dataV);
Vue.use(ui);
Vue.use(vcUI);
//富文本编辑器配置
Vue.config.productionTip = false;
Vue.prototype.$axios = axios;
Vue.prototype.formatContent = (val) => val.replace(/(\r\n)|(\n)/g, '<br>');
Object.keys(utils).map((e) => (Vue.prototype[e] = utils[e]));
new Vue({
router,
store,
render: (h) => h(App)
}).$mount('#app');

View File

@@ -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())
}
}

View File

@@ -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
}
}
}
})
}))

View File

@@ -66,14 +66,40 @@ const $decimalCalc = (...arr) => {
* @param { boolean } immediate true 表立即执行false 表非立即执行
*/
export const waiting = {
init(ops, count) {
if (document.body) {
let div = document.createElement('div')
div.id = "ai-waiting"
div.className = "el-loading-mask is-fullscreen"
div.style.zIndex = '202204271710'
div.style.textAlign = 'center'
div.style.lineHeight = '100vh'
document.body.appendChild(div)
} else if (count < 10) {
setTimeout(() => this.init(ops, ++count), 500)
}
},
getDom() {
return document.querySelector('#ai-waiting')
},
setContent(html) {
let div = this.getDom()
div.innerHTML = html
},
close() {
let div = this.getDom()
div.parentElement.removeChild(div)
}
}
export default {
...tools,
addChildParty,
$confirm,
$permissions,
$decimalCalc
$decimalCalc,
$waiting: waiting
}