Commit c98f8614 authored by smallwei's avatar smallwei

sys cli2

parent 50b98c63
This diff is collapsed.
This diff is collapsed.
......@@ -29,7 +29,7 @@
<script src="<%= BASE_URL %>util/pad-zeropadding.js" charset="utf-8"></script>
<script src="<%= BASE_URL %>cdn/vue/2.5.2/vue.min.js" charset="utf-8"></script>
<script src="<%= BASE_URL %>cdn/vuex/2.4.1/vuex.min.js" charset="utf-8"></script>
<script src="<%= BASE_URL %>cdn/vue-router/3.0.1/vue-router.js" charset="utf-8"></script>
<script src="<%= BASE_URL %>cdn/vue-router/3.0.1/vue-router.min.js" charset="utf-8"></script>
<script src="<%= BASE_URL %>cdn/axios/1.0.0/axios.min.js" charset="utf-8"></script>
<script src="<%= BASE_URL %>cdn/element-ui/2.4.6/index.js" charset="utf-8"></script>
</body>
......
export default {
title: "Avue",
logo: "A",
title: "PigX",
logo: "P",
indexTitle: 'avue-cli By smallwei',
whiteList: ["/login", "/404", "/401", "/lock"], //配置无权限可以访问的页面
whiteTagList: ["/login", "/404", "/401", "/lock", ], //配置不添加tags页面 ('/advanced-router/mutative-detail/*'——*为通配符)
......
......@@ -31,8 +31,8 @@ export default {
created () {
this.$store.dispatch("GetMenu").then(data => {
if (data.length === 0) return
this.$router.addRoutes(this.$router.$avueRouter.formatRoutes(data, true))
});
this.$router.$avueRouter.formatRoutes(data, true);
})
},
computed: {
...mapGetters(['website', 'menu', 'tag', 'keyCollapse', 'screen']),
......@@ -44,4 +44,3 @@ export default {
</script>
<style lang="scss" scoped>
</style>
\ No newline at end of file
<template>
<div class="menu-wrapper">
<template v-for="(item,index) in menu">
<el-menu-item v-if="validatenull(item[childrenKey])"
:index="filterPath(item[pathKey],index)"
<template v-for="item in menu">
<el-menu-item v-if="validatenull(item[childrenKey]) && vaildRoles(item)"
:index="item[pathKey]"
@click="open(item)"
:key="item[labelKey]">
:key="item[labelKey]"
:class="{'is-active':nowTagValue===item[pathKey]}">
<i :class="item[iconKey]"></i>
<span slot="title">{{item[labelKey]}}</span>
</el-menu-item>
<el-submenu v-else
:index="filterPath(item[labelKey],index)"
<el-submenu v-else-if="!validatenull(item[childrenKey])&&vaildRoles(item)"
:index="item[pathKey]"
:key="item[labelKey]">
<template slot="title">
<i :class="item[iconKey]"></i>
......@@ -17,16 +18,16 @@
:class="{'el-menu--display':collapse}">{{item[labelKey]}}</span>
</template>
<template v-for="(child,cindex) in item[childrenKey]">
<el-menu-item :class="{'siderbar-active':nowTagValue==child[pathKey]}"
:index="filterPath(child[pathKey],cindex)"
<el-menu-item :index="child[pathKey],cindex"
@click="open(child)"
:class="{'is-active':nowTagValue===child[pathKey]}"
v-if="validatenull(child[childrenKey])"
:key="child[labelKey]">
<i :class="child[iconKey]"></i>
<span slot="title">{{child[labelKey]}}</span>
</el-menu-item>
<sidebar-item v-else
:menu="[child]"
:menu="child[childrenKey]"
:key="cindex"
:props="props"
:screen="screen"
......@@ -37,6 +38,7 @@
</div>
</template>
<script>
import { mapGetters } from 'vuex'
import { validatenull } from '@/util/validate';
import config from './config.js'
export default {
......@@ -65,6 +67,7 @@ export default {
},
mounted () { },
computed: {
...mapGetters(['roles']),
labelKey () { return this.props.label || this.config.propsDefault.label },
pathKey () { return this.props.path || this.config.propsDefault.path },
iconKey () { return this.props.icon || this.config.propsDefault.icon },
......@@ -72,12 +75,13 @@ export default {
nowTagValue () { return this.$router.$avueRouter.getValue(this.$route) }
},
methods: {
vaildRoles (item) {
item.meta = item.meta || {};
return item.meta.roles ? item.meta.roles.includes(this.roles) : true
},
validatenull (val) {
return validatenull(val);
},
filterPath (path, index) {
return path == null ? index + '' : path
},
open (item) {
if (this.screen <= 1) this.$store.commit("SET_COLLAPSE");
this.$router.push({
......@@ -91,13 +95,3 @@ export default {
}
}
</script>
<style lang="scss" scoped>
//刷新激活状态
.siderbar-active {
i,
span {
color: #409eff;
}
}
</style>
......@@ -33,7 +33,6 @@
<script>
import { mapGetters, mapState } from 'vuex'
import { isObjectValueEqual } from '@/util/util';
export default {
name: 'tags',
data () {
......@@ -89,9 +88,6 @@ export default {
query: tag.query
})
},
isObjectValueEqual (a, b) {
return isObjectValueEqual(a, b)
},
closeOthersTags () {
this.$store.commit('DEL_TAG_OTHER')
},
......@@ -118,4 +114,3 @@ export default {
}
</script>
......@@ -2,15 +2,19 @@
<div class="login-container pull-height"
@keyup.enter.native="handleLogin">
<div class="login-logo animated fadeIn">
<el-dropdown @command="handleCommand">
<span class="el-dropdown-link">
默认租户<i class="el-icon-arrow-down el-icon--right"></i>
</span>
<el-dropdown-menu slot="dropdown">
<el-dropdown-item command="1">租户1</el-dropdown-item>
<el-dropdown-item command="2">租户2</el-dropdown-item>
</el-dropdown-menu>
</el-dropdown>
<el-select v-model="active"
placeholder="请选择租户,不选为默认"
size="mini">
<el-option label="默认租户"
value="">
</el-option>
<el-option label="租户1"
value="1">
</el-option>
<el-option label="租户2"
value="2">
</el-option>
</el-select>
</div>
<div class="login-weaper">
<div class="login-left animated fadeInLeft">
......@@ -30,7 +34,8 @@
</div>
<div class="login-border animated fadeInRight">
<div class="login-main">
<h4 class="login-title">登录 {{website.title}}</h4>
<h4 class="login-title">登录 {{website.title}}
</h4>
<userLogin v-if="activeName==='user'"></userLogin>
<codeLogin v-else-if="activeName==='code'"></codeLogin>
<thirdLogin v-else-if="activeName==='third'"></thirdLogin>
......@@ -53,6 +58,7 @@ import codeLogin from "./codelogin";
import thirdLogin from "./thirdlogin";
import topColor from "../index/top/top-color";
import color from "@/mixins/color";
import { setStore } from '@/util/store'
import { mapGetters } from "vuex";
import { validatenull } from '@/util/validate'
export default {
......@@ -66,6 +72,7 @@ export default {
},
data () {
return {
active: '',
activeName: "user"
};
},
......@@ -95,8 +102,8 @@ export default {
},
props: [],
methods: {
handleCommand(command) {
sessionStorage.setItem('tenantId',command)
handleCommand (command) {
setStore({ name: 'tenantId', content: command, type: 'session' })
}
}
};
......@@ -114,7 +121,7 @@ export default {
left: 0;
width: 100%;
height: 500px;
margin-top: -200px;
margin-top: -220px;
}
.login-container::before {
z-index: -1024;
......@@ -134,8 +141,8 @@ export default {
}
.login-logo {
position: absolute;
top: 0;
right: 0;
top: 10px;
right: 30px;
font-size: 24px;
color: #333;
}
......@@ -161,6 +168,9 @@ export default {
width: 50%;
box-sizing: border-box;
}
.login-select {
display: inline-block;
}
.login-main > h3 {
margin-bottom: 20px;
}
......
import router from './router/router'
import store from './store'
import { getToken } from '@/util/auth'
import NProgress from 'nprogress' // progress bar
import 'nprogress/nprogress.css' // progress bar style
import { asyncRouterMap } from '@/router/router'
NProgress.configure({ showSpinner: false });
const lockPage = store.getters.website.lockPage; //锁屏页
const whiteList = store.getters.website.whiteList; //不鉴权白名单
const whiteTagList = store.getters.website.whiteTagList; //不加tags白名单
router.addRoutes(asyncRouterMap);
router.beforeEach((to, from, next) => {
NProgress.start()
if (store.getters.access_token) {
const meta = to.meta || {};
if (getToken()) {
if (store.getters.isLock && to.path != lockPage) {
next({ path: lockPage })
} else if (to.path === '/login') {
......@@ -27,8 +23,8 @@ router.beforeEach((to, from, next) => {
})
})
} else {
if (!router.$avueRouter.vaildPath(whiteTagList, to.path)) {
const value = to.query.src ? to.query.src : to.path;
if (meta.isTab !== false) {
const value = to.query.src ? to.query.src : to.fullPath;
const label = to.query.name ? to.query.name : to.name;
store.commit('ADD_TAG', {
label: label,
......@@ -41,7 +37,7 @@ router.beforeEach((to, from, next) => {
}
}
} else {
if (router.$avueRouter.vaildPath(whiteList, to.path)) {
if (meta.isAuth === false) {
next()
} else {
next('/login')
......@@ -54,4 +50,3 @@ router.afterEach(() => {
const title = store.getters.tag.label;
router.$avueRouter.setTitle(title);
});
\ No newline at end of file
//正则验证路由
\ No newline at end of file
......@@ -16,9 +16,10 @@ RouterPlugin.install = function(router, store) {
this.$router.$avueRouter = {
//全局配置
$website: this.$store.getters.website,
safe: this,
// 设置标题
setTitle: function(title) {
title = title ? `${title}——Avue 通用管理 系统快速开发框架` : 'Avue 通用管理 系统快速开发框架';
title = title ? `${title}——PigX Pro 快速开发框架` : 'PigX Pro 快速开发框架';
document.title = title;
},
closeTag: (value) => {
......@@ -57,7 +58,6 @@ RouterPlugin.install = function(router, store) {
},
//动态路由
formatRoutes: function(aMenu, first) {
if (!aMenu) return;
const aRouter = []
const propsConfig = this.$website.menu.props;
const propsDefault = {
......@@ -66,6 +66,7 @@ RouterPlugin.install = function(router, store) {
icon: propsConfig.icon || 'icon',
children: propsConfig.children || 'children'
}
if (!aMenu) return;
aMenu.forEach(oMenu => {
const path = oMenu[propsDefault.path],
component = oMenu.component,
......@@ -113,10 +114,14 @@ RouterPlugin.install = function(router, store) {
})()
}
aRouter.push(oRouter)
})
if (first) {
this.safe.$router.addRoutes(aRouter)
} else {
return aRouter
}
}
}
}
export default RouterPlugin;
\ No newline at end of file
......@@ -5,63 +5,60 @@
*/
// 引入axios以及element ui中的loading和message组件
import axios from 'axios'
import router from '../router/router'
import { serialize } from '@/util/util'
import store from '../store'
import {
getToken
} from '@/util/auth'
import { getStore } from '../util/store'
import { getToken } from '@/util/auth'
import NProgress from 'nprogress' // progress bar
import errorCode from '@/const/errorCode'
import {
Message
} from 'element-ui'
import { Message } from 'element-ui'
import 'nprogress/nprogress.css' // progress bar style
axios.defaults.timeout = 30000;
//返回其他状态吗
// axios.defaults.validateStatus = function(status) {
// return status >= 200 && status < 500; // 默认的
// };
axios.defaults.validateStatus = function(status) {
return status >= 200 && status <= 500; // 默认的
};
//跨域请求,允许保存cookie
axios.defaults.withCredentials = true;
// NProgress Configuration
NProgress.configure({
showSpinner: false
}) // NProgress Configuration
});
//HTTPrequest拦截
axios.interceptors.request.use(config => {
NProgress.start() // start progress bar
if (store.getters.access_token) {
config.headers['Authorization'] = 'Bearer ' + getToken() // 让每个请求携带token--['X-Token']为自定义key 请根据实际情况自行修改
}
if (sessionStorage.getItem('tenantId')) {
config.headers['TENANT_ID'] = sessionStorage.getItem('tenantId') // 租户ID
const TENANT_ID = getStore({ name: 'tenantId' });
if (TENANT_ID) {
config.headers['TENANT_ID'] = TENANT_ID // 租户ID
}
//headers中配置serialize为true开启序列化
if (config.methods === 'post' && config.headers.serialize) {
config.data = serialize(config.data);
delete config.data.serialize;
}
return config
}, error => {
console.log('err' + error) // for debug
return Promise.reject(error)
})
});
//HTTPresponse拦截
axios.interceptors.response.use(res => {
NProgress.done();
return res
}, error => {
NProgress.done()
let errMsg = error.toString()
let code = errMsg.substr(errMsg.indexOf('code') + 5)
const status = Number(res.status);
const message = res.data.message || errorCode[status] || errorCode['default'];
if (status !== 200) {
Message({
message: errorCode[code] || errorCode['default'],
message: message,
type: 'error'
})
if (parseInt(code) === 401 || parseInt(code) === 403) {
store.dispatch('FedLogOut').then(() => {
router.push({
path: '/login'
});
})
return Promise.reject(new Error(message))
}
return res;
}, error => {
NProgress.done()
return Promise.reject(new Error(error))
})
export default axios
\ No newline at end of file
import Layout from '@/page/index/'
export default [{
path: '*',
redirect: '/404',
hidden: true
}, {
path: '/login',
name: '登录页',
component: () =>
import ( /* webpackChunkName: "page" */ '@/page/login/index'),
meta: {
keepAlive: true,
isTab: false,
isAuth: false
}
},
{
path: '/authredirect',
name: '授权页',
component: () =>
import ( /* webpackChunkName: "page" */ '@/page/login/authredirect')
},
{
path: '/lock',
name: '锁屏页',
component: () =>
import ( /* webpackChunkName: "page" */ '@/page/lock/index'),
meta: {
keepAlive: true,
isTab: false,
isAuth: false
}
},
{
path: '/404',
component: () =>
import ( /* webpackChunkName: "page" */ '@/components/error-page/404'),
name: '404'
name: '404',
meta: {
keepAlive: true,
isTab: false,
isAuth: false
}
},
{
path: '/403',
component: () =>
import ( /* webpackChunkName: "page" */ '@/components/error-page/403'),
name: '403'
name: '403',
meta: {
keepAlive: true,
isTab: false,
isAuth: false
}
},
{
path: '/500',
component: () =>
import ( /* webpackChunkName: "page" */ '@/components/error-page/500'),
name: '500'
name: '500',
meta: {
keepAlive: true,
isTab: false,
isAuth: false
}
},
{
path: '/',
name: '主页',
redirect: '/wel'
},
{
path: '/wel',
component: Layout,
redirect: '/wel/index',
children: [{
path: 'index',
name: '首页',
component: () =>
import ( /* webpackChunkName: "page" */ '@/page/wel'),
}]
},
{
path: '/myiframe',
component: Layout,
......
......@@ -20,6 +20,6 @@ let Router = new VueRouter({
routes: [].concat([])
});
AvueRouter.install(Router, Store);
Router.addRoutes(Router.$avueRouter.formatRoutes(Store.state.user.menu, true));
Router.$avueRouter.formatRoutes(Store.state.user.menu, true);
Router.addRoutes([...PageRouter, ...ViewsRouter]);
export default Router;
\ No newline at end of file
export const asyncRouterMap = [].concat(PageRouter, ViewsRouter)
\ No newline at end of file
import Layout from '@/page/index/'
export default [{
path: '/info',
path: '/wel',
component: Layout,
redirect: '/info/index',
redirect: '/wel/index',
children: [{
path: 'index',
name: '首页',
component: () =>
import ( /* webpackChunkName: "views" */ '@/views/admin/user/info')
import ( /* webpackChunkName: "views" */ '@/page/wel')
}]
}, {
path: '/crud',
......
import { setStore, getStore } from '@/util/store'
import { isObjectValueEqual } from '@/util/util'
import { diff } from '@/util/util'
const tagObj = {
label: '', //标题名称
value: '', //标题的路径
......@@ -38,22 +38,14 @@ const navs = {
ADD_TAG: (state, action) => {
state.tag = action;
setStore({ name: 'tag', content: state.tag, type: 'session' })
if (state.tagList.some(ele => isObjectValueEqual(ele, action))) return
if (state.tagList.some(ele => diff(ele, action))) return
state.tagList.push(action)
setFistTag(state.tagList);
setStore({ name: 'tagList', content: state.tagList, type: 'session' })
},
DEL_TAG: (state, action) => {
state.tagList = state.tagList.filter(item => {
if (typeof(action) === 'object') {
let a = Object.assign({}, item);
let b = Object.assign({}, action);
delete a.close;
delete b.__ob__;
return !isObjectValueEqual(a, b)
} else {
return item.value !== action
}
return !diff(item, action);
})
setFistTag(state.tagList);
setStore({ name: 'tagList', content: state.tagList, type: 'session' })
......
import {
validatenull
} from './validate'
import { validatenull } from './validate'
//表单序列化
export const serialize = data => {
let list = [];
Object.keys(data).forEach(ele => {
list.push(`${ele}=${data[ele]}`)
})
return list.join('&');
};
/**
* 判断路由是否相等
*/
export const diff = (obj1, obj2) => {
delete obj1.close;
var o1 = obj1 instanceof Object;
var o2 = obj2 instanceof Object;
if (!o1 || !o2) { /* 判断不是对象 */
return obj1 === obj2;
}
if (Object.keys(obj1).length !== Object.keys(obj2).length) {
return false;
//Object.keys() 返回一个由对象的自身可枚举属性(key值)组成的数组,例如:数组返回下表:let arr = ["a", "b", "c"];console.log(Object.keys(arr))->0,1,2;
}
for (var attr in obj1) {
var t1 = obj1[attr] instanceof Object;
var t2 = obj2[attr] instanceof Object;
if (t1 && t2) {
return diff(obj1[attr], obj2[attr]);
} else if (obj1[attr] !== obj2[attr]) {
return false;
}
}
return true;
}
/**
* 设置灰度模式
*/
export const toggleGrayMode = (status) => {
......
......@@ -22,9 +22,8 @@
ref="crud"
v-model="form"
:page="page"
@on-load="getList"
:table-loading="listLoading"
@current-change="handleCurrentChange"
@size-change="handleSizeChange"
@search-change="handleFilter"
@refresh-change="handleRefreshChange"
@row-update="update"
......@@ -118,14 +117,11 @@ export default {
page: {
total: 0, // 总页数
currentPage: 1, // 当前页数
pageSize: 20 // 每页显示多少条
pageSize: 20, // 每页显示多少条,
isAsc: false//是否倒序
},
list: [],
listLoading: true,
listQuery: {
page: 1,
limit: 20
},
role: [],
form: {},
rolesOptions: [],
......@@ -150,16 +146,17 @@ export default {
}
},
created () {
this.getList();
this.sys_user_add = this.permissions["sys_user_add"];
this.sys_user_edit = this.permissions["sys_user_edit"];
this.sys_user_del = this.permissions["sys_user_del"];
},
methods: {
getList () {
getList (page, params) {
this.listLoading = true;
this.listQuery.isAsc = false;
fetchList(this.listQuery).then(response => {
fetchList(Object.assign({
page: page.currentPage,
limit: page.pageSize
}, params)).then(response => {
this.list = response.data.records;
this.page.total = response.data.total
this.listLoading = false;
......@@ -176,20 +173,11 @@ export default {
});
},
handleFilter (param) {
this.listQuery = Object.assign(this.listQuery, param)
this.listQuery.page = 1;
this.getList();
},
handleSizeChange (val) {
this.listQuery.limit = val;
this.getList();
this.page.page = 1;
this.getList(this.page, param);
},
handleRefreshChange () {
this.getList()
},
handleCurrentChange (val) {
this.listQuery.page = val;
this.getList();
this.getList(this.page)
},
handleCreate () {
this.$refs.crud.rowAdd();
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment