Skip to content

Commit

Permalink
✨ dict module
Browse files Browse the repository at this point in the history
  • Loading branch information
tookbra committed Jul 2, 2019
1 parent 9ea0b23 commit 6b67295
Show file tree
Hide file tree
Showing 15 changed files with 189 additions and 90 deletions.
7 changes: 2 additions & 5 deletions src/api/permission/permission.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ import { fetch } from "@/libs/fetch";

export function getPermission() {
return fetch({
url: "/permissions/router",
method: "get",
headers: {
"Content-Type": "application/json;charset=UTF-8"
}
url: "/system/menus/user",
method: "get"
});
}
10 changes: 2 additions & 8 deletions src/api/system/dict.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { fetch } from "@/libs/fetch";
import { serialize } from "@/libs/util";

export function dictTree() {
return fetch({
Expand All @@ -23,14 +22,9 @@ export function getDict(id) {
});
}

export function getDictByCode(code) {
let data = { code: code };
return getDictByParam(data);
}

export function getDictByParam(parameter) {
export function getDictByType(parameter) {
return fetch({
url: "/system/dicts?" + serialize(parameter),
url: "/system/dicts/type/" + parameter,
method: "get"
});
}
Expand Down
5 changes: 5 additions & 0 deletions src/const/dict.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default {
tenantType: "tenant_type",
componentType: "vue_component",
permissionType: "permission_type"
};
35 changes: 35 additions & 0 deletions src/core/directives/action.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import Vue from "vue";
import store from "@/store";

/**
* Action 权限指令
* 指令用法:
* - 在需要控制 action 级别权限的组件上使用 v-action:[method] , 如下:
* <i-button v-action:add >添加用户</a-button>
* <a-button v-action:delete>删除用户</a-button>
* <a v-action:edit @click="edit(record)">修改</a>
*
* - 当前用户没有权限时,组件上使用了该指令则会被隐藏
* - 当后台权限跟 pro 提供的模式不同时,只需要针对这里的权限过滤进行修改即可
*
* @see https://github.com/sendya/ant-design-pro-vue/pull/53
*/
const action = Vue.directive("action", {
inserted: function(el, binding, vnode) {
const actionName = binding.arg;
const roles = store.getters.roles;
const elVal = vnode.context.$route.meta.permission;
const permissionId = (elVal instanceof String && [elVal]) || elVal;
roles.permissions.forEach(p => {
if (!permissionId.includes(p.permissionId)) {
return;
}
if (p.actionList && !p.actionList.includes(actionName)) {
(el.parentNode && el.parentNode.removeChild(el)) ||
(el.style.display = "none");
}
});
}
});

export default action;
4 changes: 4 additions & 0 deletions src/core/use.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@ import "ant-design-vue/dist/antd.css";
import "../styles/index.less";
import Loading from "../components/loading";

import action from "./directives/action";

Vue.use(Antd);

Vue.use(action);

Vue.use(VueStorage, config.localStorageOptions);
Vue.use(VueSessionStorage, config.sessionStorageOptions);
Vue.use(VueCropper);
Expand Down
8 changes: 5 additions & 3 deletions src/libs/fetch.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import axios from "axios";
import store from "@/store";
import Vue from "vue";
import { ACCESS_TOKEN } from "@/store/mutation-types";

import notification from "ant-design-vue/es/notification";

Expand All @@ -15,8 +16,9 @@ export const fetch = axios.create({
});

fetch.interceptors.request.use(config => {
if (store.state.account.token) {
config.headers.Authorization = "Bearer " + store.state.account.token;
const token = Vue.ls.get(ACCESS_TOKEN);
if (token) {
config.headers.Authorization = "Bearer " + token;
}
return config;
}, err);
Expand Down
2 changes: 1 addition & 1 deletion src/libs/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ Vue.filter("statusFilter", function(status) {
});

Vue.filter("typeFilter", function(type, typeMap) {
return typeMap[type];
return typeMap.get(type + "");
});
2 changes: 1 addition & 1 deletion src/mock/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ if (
// 使用同步加载依赖
// 防止 vuex 中的 GetInfo 早于 mock 运行,导致无法 mock 请求返回结果
// require("./services/login");
require("./services/resource");
// require("./services/resource");
// require("./services/system/tenant");
// require("./services/system/menu");
// require("./services/system/dict");
Expand Down
33 changes: 0 additions & 33 deletions src/permission/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,36 +70,3 @@ router.beforeEach((to, from, next) => {
router.afterEach(() => {
NProgress.done(); // finish progress bar
});

/**
* Action 权限指令
* 指令用法:
* - 在需要控制 action 级别权限的组件上使用 v-action:[method] , 如下:
* <i-button v-action:add >添加用户</a-button>
* <a-button v-action:delete>删除用户</a-button>
* <a v-action:edit @click="edit(record)">修改</a>
*
* - 当前用户没有权限时,组件上使用了该指令则会被隐藏
* - 当后台权限跟 pro 提供的模式不同时,只需要针对这里的权限过滤进行修改即可
*
* @see https://github.com/sendya/ant-design-pro-vue/pull/53
*/
const action = Vue.directive("action", {
bind: function(el, binding, vnode) {
const actionName = binding.arg;
const roles = store.getters.roles;
const elVal = vnode.context.$route.meta.permission;
const permissionId = (elVal instanceof String && [elVal]) || elVal;
roles.permissions.forEach(p => {
if (!permissionId.includes(p.permissionId)) {
return;
}
if (p.actionList && !p.actionList.includes(actionName)) {
(el.parentNode && el.parentNode.removeChild(el)) ||
(el.style.display = "none");
}
});
}
});

export { action };
10 changes: 5 additions & 5 deletions src/router/dynamic-router.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,24 +50,24 @@ export const generator = (routerMap, parent) => {
return routerMap.map(item => {
const currentRouter = {
// 路由地址 动态拼接生成如 /dashboard/workplace
path: `${(parent && parent.path) || ""}/${item.key}`,
path: `${(parent && parent.path) || ""}/${item.path}`,
// 路由名称,建议唯一
name: item.name || item.key || "",
// 该路由对应页面的 组件
component: item.component
? constantRouterComponents[item.component || item.key]
? constantRouterComponents[item.component || item.path]
: function(resolve) {
require([
`../views` +
`${(parent && parent.path) || ""}/${item.key}` +
`${(parent && parent.path) || ""}/${item.path}` +
`.vue`
], resolve);
},
// meta: 页面标题, 菜单图标, 页面权限(供指令权限用,可去掉)
meta: {
title: item.title,
title: item.name,
icon: item.icon || undefined,
permission: (item.key && [item.key]) || null,
permission: (item.path && [item.path]) || null,
closeable: true
}
};
Expand Down
12 changes: 6 additions & 6 deletions src/store/modules/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ export default {
getAccountInfo()
.then(response => {
const result = response.data;
if (result.role && result.permissions.length > 0) {
const role = result.role;
role.permissions = result.role.permissions;
if (result.roles && result.permissions.length > 0) {
const role = result.roles;
role.permissions = result.permissions;
role.permissions.map(per => {
if (per.actions != null && per.actions.length > 0) {
const action = per.actions.map(action => {
Expand All @@ -56,13 +56,13 @@ export default {
role.permissionList = role.permissions.map(permission => {
return permission.permissionId;
});
commit("SET_ROLES", result.role);
commit("SET_ROLES", result.roles);
commit("SET_INFO", result);
} else {
reject(new Error("getInfo: roles must be a non-null array !"));
}
commit("SET_NAME", { name: result.name });
commit("SET_AVATAR", result.avatar);
// commit("SET_NAME", { name: result.name });
// commit("SET_AVATAR", result.avatar);

resolve(response);
})
Expand Down
27 changes: 19 additions & 8 deletions src/views/system/dict.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<basicContainer>
<a-row :gutter="24">
<a-col :md="24" :lg="7">
<a-col :md="24" :lg="5">
<a-card :bordered="false">
<div class="table-operator">
<a-button class="btn" type="primary" @click="showAdd" icon="plus"
Expand Down Expand Up @@ -38,17 +38,17 @@
</template>
</a-card>
</a-col>
<a-col :md="24" :lg="17">
<a-col :md="24" :lg="19">
<a-card :bordered="false">
<div class="search-wrapper" v-if="showSearch">
<a-form layout="inline">
<a-row :gutter="16">
<a-col :md="5" :sm="24">
<a-col :md="8" :sm="24">
<a-form-item label="字典名称">
<a-input v-model="queryParam.name" placeholder="字典名称" />
</a-form-item>
</a-col>
<a-col :md="5" :sm="24">
<a-col :md="8" :sm="24">
<a-form-item label="状态">
<a-select
v-model="queryParam.status"
Expand All @@ -60,7 +60,7 @@
</a-select>
</a-form-item>
</a-col>
<a-col :md="5" :sm="24">
<a-col :md="8" :sm="24">
<span class="table-page-search-submitButtons">
<a-button
type="primary"
Expand Down Expand Up @@ -140,7 +140,7 @@
{
rules: [
{ required: true, message: '请输入字典名称' },
{ min: 2, max: 10, message: '字典名称长度为[2,10]' }
{ min: 2, max: 15, message: '字典名称长度为[2,15]' }
]
}
]"
Expand All @@ -158,7 +158,7 @@
{
rules: [
{ required: true, message: '请输入字典编码' },
{ min: 2, max: 10, message: '字典编码长度为[2,10]' }
{ min: 2, max: 15, message: '字典编码长度为[2,15]' }
]
}
]"
Expand Down Expand Up @@ -209,7 +209,7 @@
{
rules: [
{ required: true, message: '请输入字典名称' },
{ min: 2, max: 10, message: '字典名称长度为[2,10]' }
{ min: 1, max: 15, message: '字典名称长度为[1,15]' }
]
}
]"
Expand Down Expand Up @@ -244,6 +244,17 @@
:max="100"
/>
</a-form-item>
<a-form-item
label="备注"
:label-col="{ span: 5 }"
:wrapper-col="{ span: 14 }"
>
<a-textarea
placeholder="请输入备注"
:autosize="{ minRows: 4, maxRows: 6 }"
v-decorator="['remark']"
></a-textarea>
</a-form-item>
<a-form-item
label="状态"
:label-col="{ span: 5 }"
Expand Down
Loading

0 comments on commit 6b67295

Please sign in to comment.