初始化代码

This commit is contained in:
2025-12-22 17:13:05 +08:00
parent ed0de08e3a
commit 1f7e9d401b
2947 changed files with 526137 additions and 0 deletions

View File

@@ -0,0 +1,43 @@
import Vue from 'vue'
import Vuex from 'vuex'
import routes from './modules/routes'
import operate from './modules/operate'
Vue.use(Vuex)
const store = new Vuex.Store({
modules: {
routes,
operate
},
state: {
adSwitch: false,
sideBarSwitch: false,
uploadStatus: false
},
getters: {
adSwitch: state => {
return state.adSwitch
},
sideBarSwitch: state => {
return state.sideBarSwitch
},
uploadStatus: state => {
return state.uploadStatus
}
},
mutations: {
handleAdSwitch (state, value) {
state.adSwitch = value
},
handleSideBarSwitch (state, value) {
state.sideBarSwitch = value
},
handleUploadStatus (state, value) {
state.uploadStatus = value
}
},
actions: {}
})
export default store

View File

@@ -0,0 +1,19 @@
const state = {
currentIndex: 0
}
const getters = {
currentIndex: state => {
return state.currentIndex
}
}
const mutations = {
setCurrentIndex (state, index = 0) {
state.currentIndex = index
}
}
export default {
state,
getters,
mutations
}

View File

@@ -0,0 +1,185 @@
import {
api
} from '@/api'
import router from '@/router'
import Layout from '@/components/layout'
const _import = require('../../router/_import_' + process.env.NODE_ENV)
const state = {
promptData: '',
isFirst: true,
isAuth: false,
isW7: false,
isShowPrompt: false, // 是否显示到期提醒
systemCopyInfo: '', // 获取微擎系统版本信息
routes: [],
notice_num: 0
}
const getters = {
isAuth: state => {
return state.isAuth
},
isW7: state => {
return state.isW7
},
routes: state => {
return state.routes
}
}
const mutations = {
changeRoutesItem (state, item) {
console.log('changeItem ==>', item)
let { key, val } = item
state[key] = val
},
saveRoutes (state, item = []) {
state.routes = item
state.isAuth = true
}
}
const actions = {
isWeiVersion ({ commit }, obj) {
let data = { key: 'isW7', val: obj }
commit('changeRoutesItem', data)
},
getUserPromission ({
commit
}, obj) {
api.account.adminNodeInfo().then(res => {
if (res.code === 200) {
let { is_admin: isAdmin, node } = res.data
let routes = JSON.parse(JSON.stringify(obj.routes))
commit('changeRoutesItem', { key: 'allRoutes', val: routes })
let allRoutes = []
if (isAdmin === 0) {
let arr = node.map(item => { return item.node })
let isHavePayment = arr.includes('SystemPaymentWechat') && arr.includes('SystemPaymentAlipay') ? 1 : arr.includes('SystemPaymentWechat') || arr.includes('SystemPaymentAlipay') ? arr.includes('SystemPaymentWechat') ? 2 : 3 : 0
let paymentUrl = isHavePayment && isHavePayment === 3 ? '/sys/payment' : '/sys/alipay'
let isHaveNotice = arr.includes('SystemClientNotice') && arr.includes('SystemRadarNotice') ? 1 : arr.includes('SystemClientNotice') || arr.includes('SystemRadarNotice') ? arr.includes('SystemClientNotice') ? 2 : 3 : 0
let noticeUrl = isHaveNotice && isHaveNotice === 3 ? '/sys/radarNotice' : '/sys/clientNotice'
let newRoutes = []
routes.map(item => {
if (item.hidden) return
let children = []
item.children.map(aitem => {
if (arr.includes(aitem.name)) {
let ind = node.findIndex(bitem => {
return bitem.node === aitem.name
})
aitem.meta.pagePermission[0].auth = node[ind].auth
if ((isHavePayment && isHavePayment === 2 && aitem.name === 'SystemPaymentWechat') || (isHaveNotice && isHaveNotice === 2 && aitem.name === 'SystemClientNotice')) {
aitem.meta.pagePermission.splice(1, 1)
}
if ((isHavePayment && isHavePayment === 3 && aitem.name === 'SystemPaymentAlipay') || (isHaveNotice && isHaveNotice === 3 && aitem.name === 'SystemRadarNotice')) {
aitem.meta.pagePermission.splice(0, 1)
}
children.push(aitem)
}
})
let hidden = item.children.filter(item => {
return item.hidden
})
if (children.length > 0) {
let arr = children.map(item => {
return item.name
})
children = [...children, ...hidden]
item.children = children
if (item.meta.subNavName && item.meta.subNavName.length > 0) {
let subNavName = []
item.meta.subNavName.map(aitem => {
let url = aitem.url.filter(bitem => {
return arr.includes(bitem.name)
})
if (aitem.name === 'SystemSetting') {
if (isHavePayment && paymentUrl) {
url.push({name: 'SystemPayment', url: paymentUrl})
}
if (isHaveNotice && noticeUrl) {
url.push({name: 'SystemNotice', url: noticeUrl})
}
}
if (url.length > 0) {
subNavName.push({name: aitem.name, url})
}
})
if (subNavName.length > 0) {
item.redirect = subNavName[0].url[0].url
item.meta.subNavName = subNavName
}
}
newRoutes.push(item)
}
})
allRoutes = [...newRoutes, {
path: '*',
redirect: '/404',
hidden: true
}]
} else {
allRoutes = routes
}
commit('saveRoutes', allRoutes)
obj.routes = allRoutes
let { path = '' } = obj.to
let arr = []
allRoutes.map(item => {
if (item.children && item.children.length) {
item.children.map(aitem => {
arr.push(`${item.path}/${aitem.path}`)
})
}
})
if (!path || (path && !arr.includes(path))) {
obj.to = allRoutes[0]
}
routerGo(allRoutes, obj)
}
})
}
}
export default {
state,
getters,
mutations,
actions
}
function routerGo (routes, obj) {
let getRouter = filterAsyncRouter(routes) // 过滤路由
router.options.routes.push(...getRouter)
router.addRoutes(getRouter) // 动态添加路由
// localStorage.setItem('routes', JSON.stringify(getRouter))
obj.next({
...obj.to,
replace: true
})
}
function filterAsyncRouter (asyncRouterMap) { // 遍历后台传来的路由字符串,转换为组件对象
const accessedRouters = asyncRouterMap.filter(route => {
if (route.component) {
if (route.component === 'Layout') { // Layout组件特殊处理
route.component = Layout
} else {
route.component = _import(route.component)
}
}
if (route.children && route.children.length) {
route.children = filterAsyncRouter(route.children)
}
return true
})
return accessedRouters
}
// function getRouteChildre (routes, name) {
// let routeObj = ''
// for (let i = 0, len = routes.length; i < len; i++) {
// if (routes[i].path === name) {
// routeObj = routes[i]
// break
// }
// }
// return routeObj
// }