Commit 1fc81fb9 by limin

1.新增从远程config获取追加路由功能 2.支持路由外部跳转 部分功能优化

1 parent 83d24569
{ {
"name": "dj-car-life-system", "name": "AIot",
"version": "0.1.0", "version": "0.1.0",
"scripts": { "scripts": {
"serve": "vue-cli-service serve --open", "serve": "vue-cli-service serve --open",
...@@ -12,30 +12,19 @@ ...@@ -12,30 +12,19 @@
"test:unit": "vue-cli-service test:unit" "test:unit": "vue-cli-service test:unit"
}, },
"dependencies": { "dependencies": {
"axios": "^0.18.0",
"better-scroll": "^1.15.2", "better-scroll": "^1.15.2",
"dayjs": "^1.8.12", "dayjs": "^1.8.12",
"default-passive-events": "^2.0.0", "default-passive-events": "^2.0.0",
"echarts": "^5.0.0",
"element-ui": "^2.14.1",
"file-saver": "^2.0.2", "file-saver": "^2.0.2",
"flex.css": "^1.1.7", "flex.css": "^1.1.7",
"fuse.js": "^3.4.4", "fuse.js": "^3.4.4",
"hotkeys-js": "^3.6.2", "hotkeys-js": "^3.6.2",
"js-cookie": "^2.2.0",
"js-md5": "^0.7.3", "js-md5": "^0.7.3",
"lodash": "^4.17.11",
"lowdb": "^1.0.0", "lowdb": "^1.0.0",
"moment": "^2.29.1", "moment": "^2.29.1",
"nprogress": "^0.2.0",
"qs": "^6.8.0",
"screenfull": "^4.2.0", "screenfull": "^4.2.0",
"sha1": "^1.1.1", "sha1": "^1.1.1",
"ua-parser-js": "^0.7.19",
"vue": "^2.6.10",
"vue-i18n": "^8.14.0", "vue-i18n": "^8.14.0",
"vue-router": "^3.0.3",
"vuex": "^3.0.1",
"xlsx": "^0.16.8" "xlsx": "^0.16.8"
}, },
"devDependencies": { "devDependencies": {
......
import request from './request' import request from './request'
import axios from 'axios' // import axios from 'axios'
import { import {
baseConfig baseConfig
} from '@/main' } from '@/main'
......
import util from '@/libs/util.js' /*
* @Descripttion:
* @version:
* @Author: limin
* @Date: 2020-12-23 17:06:59
* @LastEditors: limin
* @LastEditTime: 2020-12-24 10:07:54
*/
export default { export default {
methods: { methods: {
handleMenuSelect(index, indexPath) { handleMenuSelect(index, indexPath) {
if (/^d2-menu-empty-\d+$/.test(index) || index === undefined) { if (/^d2-menu-empty-\d+$/.test(index) || index === undefined) {
this.$message.warning('临时菜单') this.$message.warning('临时菜单')
} else if (/^https:\/\/|http:\/\//.test(index)) { } else if (/^https:\/\/|http:\/\//.test(index)) {
util.open(index) this.$open(index)
} else { } else {
this.$router.push({ this.$router.push({
path: index path: index
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
v-for="page in opened" v-for="page in opened"
:key="page.fullPath" :key="page.fullPath"
:name="page.fullPath"> :name="page.fullPath">
<span slot="label"><d2-el-icon :name="page.meta.icon"/> <span v-text="(page.meta && page.meta.title) || '未命名'"></span></span> <span slot="label"><d2-el-icon :name="page.meta.icon"/>&nbsp;<span v-text="(page.meta && page.meta.title) || '未命名'"></span></span>
</el-tab-pane> </el-tab-pane>
</el-tabs> </el-tabs>
</div> </div>
......
...@@ -4,13 +4,26 @@ ...@@ -4,13 +4,26 @@
* @Last Modified by: chenwq * @Last Modified by: chenwq
* @Last Modified time: 2020-12-14 11:01:26 * @Last Modified time: 2020-12-14 11:01:26
*/ */
import { baseConfig } from '@/main'
const permision = {} const permision = {}
/** /**
* 追加config配置的路由信息
* @param {*} res
*/
permision.addRoutesInConfig= function(res){
const { routes } = baseConfig
if(routes){
return {...res,...routes}
}
return res
}
/**
* 打包如有与按钮 * 打包如有与按钮
* resources 所有资源集合 * resources 所有资源集合
* idsInPermision 返回的权限id集合 * idsInPermision 返回的权限id集合
*/ */
permision.packRoutesBtns = function(resources, idsInPermision) { permision.packRoutesBtns = function(resources, idsInPermision) {
resources = permision.addRoutesInConfig(resources)
if (!resources || !idsInPermision || !idsInPermision.length) { if (!resources || !idsInPermision || !idsInPermision.length) {
throw new Error('参数错误') throw new Error('参数错误')
} }
...@@ -31,8 +44,6 @@ permision.packRoutesBtns = function(resources, idsInPermision) { ...@@ -31,8 +44,6 @@ permision.packRoutesBtns = function(resources, idsInPermision) {
} else { } else {
__oBtnInPermision[obj.parentId] = [__obj] __oBtnInPermision[obj.parentId] = [__obj]
} }
// __oBtnInPermision[obj.parentId] = __objResource.auth
// __aBtnIdAll = __aBtnIdAll.concat([...__objResource.auth.action.map(o=>o.authId),...__objResource.auth.operation.map(o=>o.authId)])
} }
} }
}) })
...@@ -48,6 +59,7 @@ permision.packRoutesBtns = function(resources, idsInPermision) { ...@@ -48,6 +59,7 @@ permision.packRoutesBtns = function(resources, idsInPermision) {
* idsInPermision 返回的权限id集合 * idsInPermision 返回的权限id集合
*/ */
permision.packAsideMenus = function(resources, idsInPermision) { permision.packAsideMenus = function(resources, idsInPermision) {
resources = permision.addRoutesInConfig(resources)
if (!resources || !idsInPermision || !idsInPermision.length) { if (!resources || !idsInPermision || !idsInPermision.length) {
throw new Error('参数错误') throw new Error('参数错误')
} }
...@@ -60,6 +72,7 @@ permision.packAsideMenus = function(resources, idsInPermision) { ...@@ -60,6 +72,7 @@ permision.packAsideMenus = function(resources, idsInPermision) {
* idsInPermision 返回的权限id集合 * idsInPermision 返回的权限id集合
*/ */
permision.packMenusBtns = function(resources) { permision.packMenusBtns = function(resources) {
resources = permision.addRoutesInConfig(resources)
if (!resources) { if (!resources) {
throw new Error('参数错误') throw new Error('参数错误')
} }
...@@ -85,8 +98,8 @@ const _loop = function(res, fnGetMenu) { ...@@ -85,8 +98,8 @@ const _loop = function(res, fnGetMenu) {
} }
}) })
/** /**
* 第二次循环所有子菜单 ,然后挂载到对应的一级菜单 * 第二次循环所有子菜单 ,然后挂载到对应的一级菜单
*/ */
let __parent = null let __parent = null
__aSub.forEach(obj => { __aSub.forEach(obj => {
__parent = __aParent.find(menu => +(menu.authId) === +(obj.parentId)) __parent = __aParent.find(menu => +(menu.authId) === +(obj.parentId))
......
/*
* @Descripttion:
* @version:
* @Author: limin
* @Date: 2020-12-23 17:06:59
* @LastEditors: limin
* @LastEditTime: 2020-12-24 18:15:13
*/
// Vue // Vue
import Vue from 'vue' // import Vue from 'vue'
import axios from 'axios' // import axios from 'axios'
// import i18n from './i18n' // import i18n from './i18n'
import App from './App' import App from './App'
// 核心插件 // 核心插件
...@@ -32,16 +40,14 @@ axios({ ...@@ -32,16 +40,14 @@ axios({
// baseURL: process.env.VUE_APP_REPO + '/dj-car-life-system-config-test', // baseURL: process.env.VUE_APP_REPO + '/dj-car-life-system-config-test',
baseURL: process.env.VUE_APP_REPO + '/develop-platform-config', baseURL: process.env.VUE_APP_REPO + '/develop-platform-config',
method: 'get' method: 'get'
}).then(({ }).then(({ data: config }) => {
data baseConfig = config
}) => {
baseConfig = data
new Vue({ new Vue({
router, router,
store, store,
// i18n, // i18n,
render: h => { render: h => {
Vue.prototype.baseConfig = data Vue.prototype.baseConfig = config
return h(App) return h(App)
}, },
// created () { // created () {
...@@ -62,7 +68,7 @@ axios({ ...@@ -62,7 +68,7 @@ axios({
// 用户登录后从数据库加载一系列的设置 // 用户登录后从数据库加载一系列的设置
this.$store.dispatch('d2admin/account/load') this.$store.dispatch('d2admin/account/load')
// 获取并记录用户 UA // 获取并记录用户 UA
this.$store.commit('d2admin/ua/get') // this.$store.commit('d2admin/ua/get')
// 初始化全屏监听 // 初始化全屏监听
this.$store.dispatch('d2admin/fullscreen/listen') this.$store.dispatch('d2admin/fullscreen/listen')
}, },
...@@ -70,6 +76,4 @@ axios({ ...@@ -70,6 +76,4 @@ axios({
}).$mount('#app') }).$mount('#app')
}) })
export { export { baseConfig }
baseConfig
}
import store from '@/store' import store from '@/store'
import axios from 'axios' // import axios from 'axios'
import { import {
Message Message
} from 'element-ui' } from 'element-ui'
...@@ -58,7 +58,6 @@ service.interceptors.request.use( ...@@ -58,7 +58,6 @@ service.interceptors.request.use(
config => { config => {
return new Promise(async resolve => { return new Promise(async resolve => {
await store.commit('d2admin/loading/set', true) await store.commit('d2admin/loading/set', true)
console.log(config)
resolve(config) resolve(config)
}) })
}, },
......
import Vue from 'vue' /*
import VueRouter from 'vue-router' * @Descripttion:
* @version:
* @Author: limin
* @Date: 2020-12-23 17:06:59
* @LastEditors: limin
* @LastEditTime: 2020-12-23 19:17:35
*/
// import Vue from 'vue'
// import VueRouter from 'vue-router'
// 进度条 // 进度条
import NProgress from 'nprogress' // import NProgress from 'nprogress'
import 'nprogress/nprogress.css' // import 'nprogress/nprogress.css'
import store from '@/store/index' import store from '@/store/index'
import util from '@/libs/util.js' import util from '@/libs/util.js'
// 路由数据 // 路由数据
import routes from './routes' import routes from './routes'
......
import layoutHeaderAside from '@/layout/header-aside' import layoutHeaderAside from '@/layout/header-aside'
// 由于懒加载页面太多的话会造成webpack热更新太慢,所以开发环境不使用懒加载,只有生产环境使用懒加载 // 由于懒加载页面太多的话会造成webpack热更新太慢,所以开发环境不使用懒加载,只有生产环境使用懒加载
const _import = require('@/libs/util.import.' + process.env.NODE_ENV) const _import = require('@/libs/util.import.' + process.env.NODE_ENV)
......
/*
* @Descripttion:
* @version:
* @Author: limin
* @Date: 2020-12-23 17:06:59
* @LastEditors: limin
* @LastEditTime: 2020-12-23 18:33:09
*/
export default { export default {
// 快捷键 // 快捷键
// 支持快捷键 例如 ctrl+shift+s // 支持快捷键 例如 ctrl+shift+s
...@@ -56,33 +64,6 @@ export default { ...@@ -56,33 +64,6 @@ export default {
backgroundImage: 'image/theme/plane/bg.jpg', backgroundImage: 'image/theme/plane/bg.jpg',
preview: 'image/theme/plane/preview@2x.png' preview: 'image/theme/plane/preview@2x.png'
} }
// {
// title: 'd2admin 经典',
// name: 'd2',
// preview: 'image/theme/d2/preview@2x.png'
// },
// {
// title: '紫罗兰',
// name: 'violet',
// preview: 'image/theme/violet/preview@2x.png'
// },
// {
// title: '简约线条',
// name: 'line',
// backgroundImage: 'image/theme/line/bg.jpg',
// preview: 'image/theme/line/preview@2x.png'
// },
// {
// title: '流星',
// name: 'star',
// backgroundImage: 'image/theme/star/bg.jpg',
// preview: 'image/theme/star/preview@2x.png'
// },
// {
// title: 'Tomorrow Night Blue (vsCode)',
// name: 'tomorrow-night-blue',
// preview: 'image/theme/tomorrow-night-blue/preview@2x.png'
// }
] ]
}, },
// 是否默认开启页面切换动画 // 是否默认开启页面切换动画
......
import Vue from 'vue' /*
import Vuex from 'vuex' * @Descripttion:
* @version:
* @Author: limin
* @Date: 2020-12-23 17:06:59
* @LastEditors: limin
* @LastEditTime: 2020-12-24 18:15:51
*/
// import Vue from 'vue'
// import Vuex from 'vuex'
import d2admin, { storeResets } from './modules/d2admin' import d2admin, { storeResets } from './modules/d2admin'
Vue.prototype.$StoreReset = function() { Vue.prototype.$StoreReset = function() {
......
/*
* @Descripttion:
* @version:
* @Author: limin
* @Date: 2020-12-23 17:06:59
* @LastEditors: limin
* @LastEditTime: 2020-12-23 19:30:09
*/
/** /**
* The file enables `@/store/index.js` to import all vuex modules * The file enables `@/store/index.js` to import all vuex modules
* in a one-shot manner. There should not be any reason to edit this file. * in a one-shot manner. There should not be any reason to edit this file.
......
...@@ -37,11 +37,7 @@ export default { ...@@ -37,11 +37,7 @@ export default {
// token 代表用户当前登录状态 建议在网络请求中携带 token // token 代表用户当前登录状态 建议在网络请求中携带 token
// 如有必要 token 需要定时更新,默认保存一天 // 如有必要 token 需要定时更新,默认保存一天
util.cookies.set('uuid', data.loginName) util.cookies.set('uuid', data.loginName)
data.roleType = baseConfig.hasAuth ? data.roleType : SUPPER_ADMIN let authes = _getAuthes(data)
const authes = (+data.roleType === SUPPER_ADMIN)
? util.permision.flatten(Object.values(localRoutes))
.map(obj => ({ authId: obj.authId, parentId: obj.parentId }))
: _.cloneDeep(data.authes)
await dispatch('d2admin/auth/set', authes, { root: true }) await dispatch('d2admin/auth/set', authes, { root: true })
// // 设置 vuex 用户信息 // // 设置 vuex 用户信息
delete data.authes delete data.authes
...@@ -129,3 +125,19 @@ export default { ...@@ -129,3 +125,19 @@ export default {
} }
} }
} }
function _getAuthes(data) {
let authes
data.roleType = baseConfig.hasAuth ? data.roleType : SUPPER_ADMIN
if (+data.roleType === SUPPER_ADMIN) {
authes = util.permision.flatten(Object.values(localRoutes)).map(obj => ({ authId: obj.authId, parentId: obj.parentId }))
} else {
authes = _.cloneDeep(data.authes)
}
const { routes } = baseConfig
if (routes) {
let configIds = util.permision.flatten(Object.values(routes)).map(obj => ({ authId: obj.authId, parentId: obj.parentId }))
authes.push(...configIds)
}
return authes
}
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
import util from '@/libs/util.js' import util from '@/libs/util.js'
import router, { ResetRouter } from '@/router' import router, { ResetRouter } from '@/router'
import { localRoutes, frameInRoutes, sys } from '@/router/routes' import { localRoutes, frameInRoutes, sys } from '@/router/routes'
export default { export default {
namespaced: true, namespaced: true,
state: { state: {
......
...@@ -5,7 +5,7 @@ const INDEX_PATH = '/index' ...@@ -5,7 +5,7 @@ const INDEX_PATH = '/index'
home.fullPath = INDEX_PATH home.fullPath = INDEX_PATH
// 判定是否需要缓存 // 判定是否需要缓存
const isKeepAlive = data => _.get(data, 'meta.cache', false) const isKeepAlive = data => _.get(data, 'meta.cache', false)
const setIcon = meta => (meta.icon = localRoutes[meta.authId].icon) const setIcon = meta => (meta.icon = localRoutes[meta.authId]?localRoutes[meta.authId].icon:'')
export default { export default {
namespaced: true, namespaced: true,
......
/*
* @Descripttion:
* @version:
* @Author: limin
* @Date: 2020-12-23 17:06:59
* @LastEditors: limin
* @LastEditTime: 2020-12-23 19:21:49
*/
import util from '@/libs/util.js' import util from '@/libs/util.js'
export default { export default {
...@@ -9,7 +17,7 @@ export default { ...@@ -9,7 +17,7 @@ export default {
*/ */
versionShow() { versionShow() {
util.log.capsule(process.env.VUE_APP_TITLE, `v${process.env.VUE_APP_VERSION}`) util.log.capsule(process.env.VUE_APP_TITLE, `v${process.env.VUE_APP_VERSION}`)
console.log('广联赛讯 http://www.glsx.com.cn') console.log('AIot http://www.xxxx.cn')
} }
} }
} }
import UAParser from 'ua-parser-js' /*
* @Descripttion:
* @version:
* @Author: limin
* @Date: 2020-12-23 17:06:59
* @LastEditors: limin
* @LastEditTime: 2020-12-23 19:16:57
*/
// import UAParser from 'ua-parser-js'
export default { export default {
namespaced: true, namespaced: true,
state: { state: {
......
...@@ -113,7 +113,6 @@ export default { ...@@ -113,7 +113,6 @@ export default {
methods: { methods: {
beforeSearchFn() { beforeSearchFn() {
return new Promise(resolve => { return new Promise(resolve => {
console.log(this.registerTime)
if (this.registerTime && this.registerTime.length) { if (this.registerTime && this.registerTime.length) {
this.searchForm.registerStartTime = new Date(this.registerTime[0]).toLocaleDateString().replace(/\//g, '-') + ' 00:00:00' this.searchForm.registerStartTime = new Date(this.registerTime[0]).toLocaleDateString().replace(/\//g, '-') + ' 00:00:00'
this.searchForm.registerEndTime = new Date(this.registerTime[1]).toLocaleDateString().replace(/\//g, '-') + ' 23:59:59' this.searchForm.registerEndTime = new Date(this.registerTime[1]).toLocaleDateString().replace(/\//g, '-') + ' 23:59:59'
......
<!--
* @Descripttion:
* @version:
* @Author: limin
* @Date: 2020-12-23 17:06:59
* @LastEditors: limin
* @LastEditTime: 2020-12-23 19:26:29
-->
# Vue Filename Injector # Vue Filename Injector
Inject the file path of the `.vue` on `this.$options.__source`. Inject the file path of the `.vue` on `this.$options.__source`.
......
...@@ -30,7 +30,7 @@ const cdn = { ...@@ -30,7 +30,7 @@ const cdn = {
`${CDN_DOMAIN}/qs/6.8.0/qs.min.js`, `${CDN_DOMAIN}/qs/6.8.0/qs.min.js`,
// `${CDN_DOMAIN}/core-js/2.6.9/core.min.js`, // `${CDN_DOMAIN}/core-js/2.6.9/core.min.js`,
// `${CDN_DOMAIN}/vue-i18n/8.14.0/vue-i18n.esm.js`, // `${CDN_DOMAIN}/vue-i18n/8.14.0/vue-i18n.esm.js`,
`${CDN_DOMAIN}/UAParser.js/0.7.20/ua-parser.min.js`, // `${CDN_DOMAIN}/UAParser.js/0.7.20/ua-parser.min.js`,
'https://unpkg.com/better-scroll@1.15.2/dist/bscroll.min.js' 'https://unpkg.com/better-scroll@1.15.2/dist/bscroll.min.js'
] ]
} }
...@@ -60,7 +60,7 @@ module.exports = { ...@@ -60,7 +60,7 @@ module.exports = {
'echarts': 'echarts', 'echarts': 'echarts',
'lodash': '_', 'lodash': '_',
// 'vue-i18n':'vue-i18n', // 'vue-i18n':'vue-i18n',
'ua-parser-js': 'UAParser', // 'ua-parser-js': 'UAParser',
'better-scroll': 'BScroll', 'better-scroll': 'BScroll',
'qs': 'Qs' 'qs': 'Qs'
// 'core-js': 'core-js' // 'core-js': 'core-js'
...@@ -106,7 +106,7 @@ module.exports = { ...@@ -106,7 +106,7 @@ module.exports = {
matchColors: [ matchColors: [
...forElementUI.getElementUISeries(process.env.VUE_APP_ELEMENT_COLOR) // Element-ui主色系列 ...forElementUI.getElementUISeries(process.env.VUE_APP_ELEMENT_COLOR) // Element-ui主色系列
], ],
externalCssFiles: [ './node_modules/element-ui/lib/theme-chalk/index.css' ], // optional, String or string array. Set external css files (such as cdn css) to extract colors. // externalCssFiles: [ './node_modules/element-ui/lib/theme-chalk/index.css' ], // optional, String or string array. Set external css files (such as cdn css) to extract colors.
changeSelector: forElementUI.changeSelector changeSelector: forElementUI.changeSelector
}]) }])
config config
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!