持续集成分支

This commit is contained in:
aixianling
2024-10-10 16:04:11 +08:00
parent f35c272a19
commit 00b2dbb4a4
38 changed files with 2222 additions and 111 deletions

107
src/utils/autoRoutes.js Normal file
View File

@@ -0,0 +1,107 @@
import {waiting} from "./index";
import router from "./router";
import store from "./store";
import {Message} from "element-ui";
import Vue from "vue";
import extra from "../config.json"
let {state: {user}, commit, dispatch} = store
const signOut = () => commit("signOut"),
getUserInfo = () => dispatch("getUserInfo"),
existRoute = route => {
return router.getRoutes()?.find(e => e.name == route?.name || e.path == route?.path)
},
goto = (route, next) => {
const exist = !!existRoute(route)
return exist ? route.name ? next() : router.replace(route) :
!route.name && route.path == "/" ? router.replace({name: "Home"}).catch(() => 0) :
Message.error("无法找到路由,请联系系统管理员!")
}
const loadApps = () => {
//新App的自动化格式
waiting.init({innerHTML: '应用加载中..'})
let apps = require.context('../../apps', true, /\.(\/.+)\/App[A-Z][^\/]+\.vue$/, "lazy")
return Promise.all(apps.keys().map(path => apps(path).then(file => {
if (file.default) {
let {name} = file.default
waiting.setContent(`加载${name}...`)
Vue.component(name, file.default)
} else return 0
}))).then(() => {
waiting.setContent(`正在进入系统...`)
setTimeout(() => waiting.close(), 1000)
})
}
const addHome = homePage => {
const component = extra?.homePage || homePage.path
if (extra?.homePage && Vue.component(component)) {
homePage = {...homePage, path: component, component: () => import('../views/mainEntry'), meta: component}
}
router.addRoute('Home', homePage)
router.options.routes[2].children.unshift(homePage)
commit("setHomePage", {
...homePage,
label: homePage.name,
id: `/v/${component}`,
isMenu: 1,
route: homePage.name,
component,
path: component,
})
}
const generateRoutes = (to, from, next) => {
if (router.options.routes[2].children.length > 0) {
goto(to, next)
} else {
Promise.all([getUserInfo(), loadApps()]).then(() => {
//初始化默认工作台
let homePage = {name: "工作台", path: "console", style: "iconfont iconNav_Dashborad", component: () => import('../views/console')}
addHome(homePage)
const mods = user.info.menuSet?.filter(e => !!e.component)?.map(e => ({route: e.id, ...e}))
mods?.map(({route: name, path, component}) => {
if (!!Vue.component(component) && path && !existRoute({name})) {
let search = path.split("?")
path = search?.[0] || path
const route = {name, path, component: () => import('../views/mainEntry'), meta: component}
router.addRoute('Home', route)
router.options.routes[2].children.push(route)
}
})
to.name == "Home" ? next({name: homePage.name, replace: true}) : next({...to, replace: true})
}).then(() => commit("setRoutes", router.options.routes[2].children))
}
}
export const routes = [
{path: "/login", name: "登录", component: () => import('../views/sign')},
{path: '/dv', name: '数据大屏入口', component: () => import('../views/dvIndex')},
{path: '/v', name: 'Home', component: () => import('../views/home'), children: []},
{path: '/', name: "init"},
]
export default {
init: () => {
router.beforeEach((to, from, next) => {
console.log('%s=>%s', from.name, to.name)
if (to.hash == "#pddv") {
const {query} = to
dispatch("getToken", {
username: "18971406276",
password: "admin321!"
}).then(() => next({name: "数据大屏入口", query, hash: "#dv"}))
} else if (["数据大屏入口", "登录"].includes(to.name)) {
next()
} else if (to.hash == "#dv") {
//数据大屏进行的独立页面跳转
let {query, hash} = to
next({name: "数据大屏入口", query, hash})
} else if (user.token) {
to.name == "init" ? next({name: "Home"}) : generateRoutes(to, from, next)
} else {
signOut()
}
})
router.onError(err => {
console.error(err)
})
return Promise.resolve()
}
}

26
src/utils/axios.js Normal file
View File

@@ -0,0 +1,26 @@
import instance from 'dui/lib/js/request'
import {Message} from 'element-ui'
import extra from "../config.json";
import store from "./store"
let baseURLs = {
production: extra.base || "/",
development: extra.baseURL || '/lan',
}
instance.defaults.baseURL = baseURLs[process.env.NODE_ENV]
instance.interceptors.request.use(config => {
config.timeout = 300000
if (extra?.isSingleService) {
config.url = config.url.replace(/(app|auth|admin)\//, "api/")
}
if (config.url.startsWith("/node")) {
config.baseURL = "/ns"
}
return config
}, error => Message.error(error))
instance.interceptors.response.use(res => res, err => {
if (err?.code == 401) {
store.commit('signOut', 1)
}
})
export default instance

100
src/utils/index.js Normal file
View File

@@ -0,0 +1,100 @@
import {MessageBox} from 'element-ui'
import tools from 'dui/lib/js/utils'
import store from "./store";
let {state: {user}} = store
const addChildParty = (parent, pending) => {
let doBeforeCount = pending.length
parent["children"] = parent["children"] || []
pending.map((e, index, arr) => {
if (e.partyOrgParentId == parent.partyOrgId) {
parent.children.push(e)
arr.splice(index, 1)
addChildParty(parent, arr)
}
})
if (parent.children.length == 0) {
delete parent.children
}
if (pending.length > 0 && doBeforeCount > pending.length) {
parent.children.map(c => addChildParty(c, pending))
}
}
/**
* 封装提示框
*/
const $confirm = (content, options) => {
return MessageBox.confirm(content, {
type: "warning",
confirmButtonText: "确认",
center: true,
title: "提示",
dangerouslyUseHTMLString: true,
...options
})
}
/**
* 封装权限判断方法
*/
const $permissions = flag => {
const buttons = user?.info?.buttons
if (buttons) return buttons.some(b => b.id == flag || b.permission == flag)
else return false
}
const $decimalCalc = (...arr) => {
//确认提升精度
let decimalLengthes = arr.map(e => {
let index = ("" + e).indexOf(".")
return ("" + e).length - index
})
let maxDecimal = Math.max(...decimalLengthes), precision = Math.pow(10, maxDecimal)
//计算
let intArr = arr.map(e => (Number(e) || 0) * precision)
//返回计算值
return intArr.reduce((t, a) => t + a) / precision
}
export const waiting = {
init(ops, count) {
if (document.body) {
let div = document.createElement('div')
div.id = "ai-waiting"
div.innerHTML = "信息正在加载中..."
div.className = "el-loading-mask is-fullscreen"
div.style.zIndex = '202204271710'
div.style.textAlign = 'center'
div.style.lineHeight = '100vh'
div.style.background = 'rgba(255,255,255,.8)'
div.style.backdropFilter = 'blur(6px)'
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,
$waiting: waiting
}

19
src/utils/router.js Normal file
View File

@@ -0,0 +1,19 @@
import Vue from 'vue'
import VueRouter from 'vue-router'
import {routes} from "./autoRoutes"
import config from "../config.json"
Vue.use(VueRouter)
export default new VueRouter({
base: config.base || '/',
mode: 'history',
hashbang: false,
routes,
scrollBehavior(to) {
if (to.hash) {
return {
selector: to.hash
}
}
}
})

44
src/utils/store.js Normal file
View File

@@ -0,0 +1,44 @@
import Vue from 'vue'
import Vuex from 'vuex'
import preState from 'vuex-persistedstate'
import * as modules from "dui/lib/js/modules"
import axios from "./axios";
import extra from "../config.json"
Vue.use(Vuex)
export default new Vuex.Store({
state: {
homePage: {}
},
mutations: {
setHomePage(state, home) {
state.homePage = home
},
signOut(state, flag) {
const base = extra.base || ""
if (flag) {
state.user.token = null;
state.user.info = {}
sessionStorage.clear();
location.href = base + '/login' + location.hash;
} else {
axios.delete('/auth/token/logout').then(() => {
state.user.token = null;
sessionStorage.clear();
state.user.info = {}
location.href = base + '/login';
});
}
},
},
getters: {
//后台数据库中的应用集合,在本工程中不一定存在
mods: state => [
state.homePage,
state.user.info?.menuSet?.map(e => ({route: e.id, ...e, label: e.name}))
].flat().filter(Boolean)
},
modules,
plugins: [preState()]
})