Skip to content

Commit 0fa18f2

Browse files
author
张柯雨
committed
[feature] 优化传参,增加readme
1 parent 4b3f412 commit 0fa18f2

File tree

10 files changed

+872
-261
lines changed

10 files changed

+872
-261
lines changed

.editorconfig

Lines changed: 0 additions & 9 deletions
This file was deleted.

README.md

Lines changed: 102 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,107 @@
22

33
> Automatically generate routes and menu by given privilege
44
5+
## Usage
6+
7+
#### PrivilegeMenu Attribute
8+
9+
参数 | 说明 | 类型 | 可选值 | 默认值
10+
-----|-----|-----|------|------
11+
routerMap|必传,根据此参数生成router,详细使用见下方示例|array|-|-
12+
role|当前用户角色,配合routerMap使用|string|-|-
13+
mode|模式|string|horizontal / vertical|vertical
14+
collapse|是否水平折叠收起菜单(仅在 mode 为 vertical 时可用)|boolean|-|false
15+
background-color|菜单的背景色(仅支持 hex 格式)|string|—|#ffffff
16+
text-color|菜单的文字颜色(仅支持 hex 格式)|string|—|#303133
17+
active-text-color|当前激活菜单的文字颜色(仅支持 hex 格式)|string|—|#409EFF
18+
default-active|当前激活菜单的|index|string|—|—
19+
default-openeds|当前打开的 sub-menu 的 index 的数组|Array|—|—
20+
unique-opened|是否只保持一个子菜单的展开|boolean|—|false
21+
menu-trigger|子菜单打开的触发方式(只在 mode 为 horizontal 时有效)|string|hover / click|hover
22+
router|是否使用 vue-router 的模式,启用该模式会在激活导航时以 index 作为 path 进行路由跳转|boolean|—|false
23+
collapse-transition|是否开启折叠动画|boolean|—|true
24+
25+
26+
#### PrivilegeMenu Events
27+
28+
事件名称|说明|回调参数
29+
-----|-----|------
30+
select|菜单激活回调|index: 选中菜单项的 index, indexPath: 选中菜单项的 index path
31+
open|sub-menu 展开的回调|index: 打开的 sub-menu 的 index, indexPath: 打开的 sub-menu 的 index path
32+
close|sub-menu 收起的回调|index: 收起的 sub-menu 的 index, indexPath: 收起的 sub-menu 的 index path
33+
34+
#### RouterMap Example
35+
36+
``` js
37+
[
38+
{
39+
path: '/requestquery', //第一层级路径
40+
display: '请求查询', //名称
41+
icon: 'el-icon-s-management', //图标(当前节点为最外层menu时渲染)
42+
children: [
43+
{
44+
path: '/logidsearch', //第二层级路径,此页面路径为/requestquery/logidsearch
45+
display: 'Logid查询',
46+
component: a, //页面组件
47+
},
48+
{
49+
path: '/conditionsearch',
50+
display: '条件查询',
51+
component: b,
52+
privilege: ['user_admin', 'user_re'], //拥有查看该页面权限的角色,由role参数传入,有权限的角色可看到并访问此menu项(只在叶节点起作用)
53+
},
54+
{
55+
path: '/c',
56+
display: 'c',
57+
component: c,
58+
notShow: true, //有权限角色可以访问该页面,但menu中不展示
59+
privilege: ['user_admin', 'user_re'],
60+
}
61+
],
62+
},
63+
{
64+
path: '/dataSearch',
65+
display: '数据查询',
66+
icon: 'el-icon-document',
67+
children: [
68+
{
69+
path: '/narwalSearch',
70+
display: 'Narwal查询',
71+
component: c,
72+
icon: 'el-icon-document',
73+
privilege: ['user_admin', 'user_re'],
74+
},
75+
],
76+
},
77+
{
78+
path: '/utils',
79+
display: '通用工具',
80+
icon: 'el-icon-s-tools',
81+
children: [
82+
{
83+
path: '/jsonformatter',
84+
display: 'JSON格式化',
85+
component: a,
86+
privilege: ['user_admin', 'user_re'],
87+
},
88+
{
89+
path: '/transform',
90+
display: 'Pin/PinId查询',
91+
component: b,
92+
privilege: ['user_admin', 'user_re'],
93+
},
94+
{
95+
path: '/jsonquery',
96+
display: '数据请求',
97+
component: c,
98+
icon: 'el-icon-s-tools',
99+
privilege: ['user_admin', 'user_re', 'user_pm'],
100+
},
101+
],
102+
}
103+
]
104+
```
105+
5106
## Build Setup
6107

7108
``` bash
@@ -13,6 +114,4 @@ npm run dev
13114

14115
# build for production with minification
15116
npm run build
16-
```
17-
18-
For detailed explanation on how things work, consult the [docs for vue-loader](http://vuejs.github.io/vue-loader).
117+
```

build/webpack.config.js

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
module.exports = function(env, argv){
2+
// entry: './lib/index.js',
3+
return {
4+
// entry: './example/main.js',
5+
// output: {
6+
// path: path.resolve(__dirname, './dist'),
7+
// publicPath: './dist/',
8+
// filename: 'vue-privilege-menu.js',
9+
// library: 'vuePrivilegeMenu',
10+
// libraryTarget: 'umd',
11+
// umdNamedDefine: true,
12+
// },
13+
module: {
14+
rules: [
15+
{
16+
test: /\.css$/,
17+
use: [
18+
'vue-style-loader',
19+
'css-loader'
20+
],
21+
},
22+
{
23+
test: /\.vue$/,
24+
loader: 'vue-loader',
25+
},
26+
{
27+
test: /\.js$/,
28+
loader: 'babel-loader',
29+
exclude: /node_modules/
30+
},
31+
{
32+
test: /\.(woff|woff2|ttf|eot|png|jpg|gif|svg)$/,
33+
loader: 'url-loader',
34+
options: {
35+
name: "[name]-[hash:5].[ext]",
36+
}
37+
}
38+
]
39+
},
40+
resolve: {
41+
alias: {
42+
'vue$': 'vue/dist/vue.esm.js'
43+
},
44+
extensions: ['*', '.js', '.vue', '.json']
45+
},
46+
// devServer: {
47+
// openPage: './example/index.html',
48+
// historyApiFallback: true,
49+
// noInfo: true,
50+
// overlay: true
51+
// },
52+
performance: {
53+
hints: false
54+
},
55+
// devtool: '#source-map',
56+
}
57+
58+
// if (process.env.NODE_ENV === 'production') {
59+
// module.exports.devtool = '#source-map'
60+
// // http://vue-loader.vuejs.org/en/workflow/production.html
61+
// module.exports.plugins = (module.exports.plugins || []).concat([
62+
// new webpack.DefinePlugin({
63+
// 'process.env': {
64+
// NODE_ENV: '"production"'
65+
// }
66+
// }),
67+
// new webpack.optimize.UglifyJsPlugin({
68+
// sourceMap: true,
69+
// compress: {
70+
// warnings: false
71+
// }
72+
// }),
73+
// new webpack.LoaderOptionsPlugin({
74+
// minimize: true
75+
// })
76+
// ])
77+
}

build/webpack.dev.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
const baseConfig = require('./webpack.config.js')
2+
const htmlWebpackPlugin = require('html-webpack-plugin')
3+
const merge = require('webpack-merge')
4+
const path = require('path')
5+
6+
module.exports = function(env, argv) {
7+
const base = baseConfig(env, argv)
8+
return merge(base, {
9+
entry: './example/main.js',
10+
devServer: {
11+
openPage: 'index.html',
12+
historyApiFallback: true,
13+
noInfo: true,
14+
overlay: true
15+
},
16+
plugins:[
17+
new htmlWebpackPlugin({
18+
template: './example/index.html',
19+
filename: 'index.html',
20+
title: 'vue-privilege-menu',
21+
inject: true,
22+
cache: true,
23+
})
24+
],
25+
devtool: '#source-map',
26+
})
27+
}

build/webpack.prod.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
const baseConfig = require('./webpack.config.js')
2+
const webpack = require('webpack')
3+
const path = require('path')
4+
const merge = require('webpack-merge')
5+
6+
module.exports = function(env, argv) {
7+
const base = baseConfig(env, argv)
8+
return merge(base, {
9+
entry: './lib/index.js',
10+
output: {
11+
path: path.resolve(__dirname, '../dist'),
12+
publicPath: '../dist/',
13+
filename: 'vue-privilege-menu.js',
14+
library: 'vuePrivilegeMenu',
15+
libraryTarget: 'umd',
16+
umdNamedDefine: true,
17+
},
18+
plugins: [
19+
new webpack.DefinePlugin({
20+
'process.env': {
21+
NODE_ENV: '"production"'
22+
}
23+
}),
24+
new webpack.optimize.UglifyJsPlugin({
25+
sourceMap: true,
26+
compress: {
27+
warnings: false
28+
}
29+
}),
30+
new webpack.LoaderOptionsPlugin({
31+
minimize: true
32+
})
33+
]
34+
})
35+
}

example/index.html

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,5 @@
66
</head>
77
<body>
88
<div id="app"></div>
9-
<!-- <script src="./main.js"></script> -->
10-
<script src="../dist/vue-privilege-menu.js"></script>
119
</body>
1210
</html>

0 commit comments

Comments
 (0)