Browse Source

数据权限功能提交

master
parent
commit
3f0717c654
  1. 9
      src/api/dhc/productLineArea.js
  2. 44
      src/api/system/auth.js
  3. 8
      src/api/system/user.js
  4. 14
      src/router/index.js
  5. 288
      src/views/system/authData/index.vue
  6. 336
      src/views/system/user/authData.vue
  7. 10
      src/views/system/user/index.vue

9
src/api/dhc/productLineArea.js

@ -51,3 +51,12 @@ export function queryList(data) { @@ -51,3 +51,12 @@ export function queryList(data) {
data: data
})
}
// 查询产品线-区域类型-区域层级关系列表
export function queryAreaMaplist(data) {
return request({
url: '/dhc/area/queryAreaMaplist',
method: 'get',
data: data
})
}

44
src/api/system/auth.js

@ -0,0 +1,44 @@ @@ -0,0 +1,44 @@
import request from '@/utils/request'
// 查询数据权限列表
export function listAuth(query) {
return request({
url: '/dhc/authData/list',
method: 'get',
params: query
})
}
// 查询数据权限详细
export function getAuth(dataAuthId) {
return request({
url: '/dhc/authData/' + dataAuthId,
method: 'get'
})
}
// 新增数据权限
export function addAuth(data) {
return request({
url: '/dhc/authData',
method: 'post',
data: data
})
}
// 修改数据权限
export function updateAuth(data) {
return request({
url: '/dhc/authData',
method: 'put',
data: data
})
}
// 删除数据权限
export function delAuth(dataAuthId) {
return request({
url: '/dhc/authData/' + dataAuthId,
method: 'delete'
})
}

8
src/api/system/user.js

@ -134,3 +134,11 @@ export function deptTreeSelect() { @@ -134,3 +134,11 @@ export function deptTreeSelect() {
method: 'get'
})
}
// 查询数据权限列表
export function getAuthData(userId) {
return request({
url: '/system/user/authData/' + userId,
method: 'get'
})
}

14
src/router/index.js

@ -161,6 +161,20 @@ export const dynamicRoutes = [ @@ -161,6 +161,20 @@ export const dynamicRoutes = [
meta: { title: '修改生成配置', activeMenu: '/tool/gen' }
}
]
},
{
path: '/system/user-auth',
component: Layout,
hidden: true,
permissions: ['system:user:edit'],
children: [
{
path: 'authData/:userId(\\d+)',
component: () => import('@/views/system/user/authData'),
name: 'authData',
meta: { title: '分配数据权限', activeMenu: '/system/user/authData' }
}
]
}
]

288
src/views/system/authData/index.vue

@ -0,0 +1,288 @@ @@ -0,0 +1,288 @@
<template>
<div class="app-container">
<el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
<el-form-item label="部门ID" prop="deptId">
<el-input
v-model="queryParams.deptId"
placeholder="请输入部门ID"
clearable
@keyup.enter.native="handleQuery"
/>
</el-form-item>
<el-form-item label="权限控制点" prop="authNode">
<el-input
v-model="queryParams.authNode"
placeholder="请输入权限控制点"
clearable
@keyup.enter.native="handleQuery"
/>
</el-form-item>
<el-form-item label="产品线编码" prop="productLineCode">
<el-input
v-model="queryParams.productLineCode"
placeholder="请输入产品线编码"
clearable
@keyup.enter.native="handleQuery"
/>
</el-form-item>
<el-form-item>
<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
</el-form-item>
</el-form>
<el-row :gutter="10" class="mb8">
<el-col :span="1.5">
<el-button
type="primary"
plain
icon="el-icon-plus"
size="mini"
@click="handleAdd"
v-hasPermi="['dhc:auth:add']"
>新增</el-button>
</el-col>
<el-col :span="1.5">
<el-button
type="success"
plain
icon="el-icon-edit"
size="mini"
:disabled="single"
@click="handleUpdate"
v-hasPermi="['dhc:auth:edit']"
>修改</el-button>
</el-col>
<el-col :span="1.5">
<el-button
type="danger"
plain
icon="el-icon-delete"
size="mini"
:disabled="multiple"
@click="handleDelete"
v-hasPermi="['dhc:auth:remove']"
>删除</el-button>
</el-col>
<el-col :span="1.5">
<el-button
type="warning"
plain
icon="el-icon-download"
size="mini"
@click="handleExport"
v-hasPermi="['dhc:auth:export']"
>导出</el-button>
</el-col>
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
</el-row>
<el-table v-loading="loading" :data="authList" @selection-change="handleSelectionChange">
<el-table-column type="selection" width="55" align="center" />
<el-table-column label="数据权限ID" align="center" prop="dataAuthId" />
<el-table-column label="部门ID" align="center" prop="deptId" />
<el-table-column label="权限控制点" align="center" prop="authNode" />
<el-table-column label="产品线编码" align="center" prop="productLineCode" />
<el-table-column label="区域类型" align="center" prop="areaType" />
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
<template slot-scope="scope">
<el-button
size="mini"
type="text"
icon="el-icon-edit"
@click="handleUpdate(scope.row)"
v-hasPermi="['dhc:auth:edit']"
>修改</el-button>
<el-button
size="mini"
type="text"
icon="el-icon-delete"
@click="handleDelete(scope.row)"
v-hasPermi="['dhc:auth:remove']"
>删除</el-button>
</template>
</el-table-column>
</el-table>
<pagination
v-show="total>0"
:total="total"
:page.sync="queryParams.pageNum"
:limit.sync="queryParams.pageSize"
@pagination="getList"
/>
<!-- 添加或修改数据权限对话框 -->
<el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
<el-form ref="form" :model="form" :rules="rules" label-width="80px">
<el-form-item label="部门ID" prop="deptId">
<el-input v-model="form.deptId" placeholder="请输入部门ID" />
</el-form-item>
<el-form-item label="权限控制点" prop="authNode">
<el-input v-model="form.authNode" placeholder="请输入权限控制点" />
</el-form-item>
<el-form-item label="产品线编码" prop="productLineCode">
<el-input v-model="form.productLineCode" placeholder="请输入产品线编码" />
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button type="primary" @click="submitForm"> </el-button>
<el-button @click="cancel"> </el-button>
</div>
</el-dialog>
</div>
</template>
<script>
import { listAuth, getAuth, delAuth, addAuth, updateAuth } from "@/api/system/auth";
export default {
name: "Auth",
data() {
return {
//
loading: true,
//
ids: [],
//
single: true,
//
multiple: true,
//
showSearch: true,
//
total: 0,
//
authList: [],
//
title: "",
//
open: false,
//
queryParams: {
pageNum: 1,
pageSize: 10,
deptId: null,
authNode: null,
productLineCode: null,
areaType: null
},
//
form: {},
//
rules: {
deptId: [
{ required: true, message: "部门ID不能为空", trigger: "blur" }
],
authNode: [
{ required: true, message: "权限控制点不能为空", trigger: "blur" }
],
productLineCode: [
{ required: true, message: "产品线编码不能为空", trigger: "blur" }
],
areaType: [
{ required: true, message: "区域类型不能为空", trigger: "change" }
]
}
};
},
created() {
this.getList();
},
methods: {
/** 查询数据权限列表 */
getList() {
this.loading = true;
listAuth(this.queryParams).then(response => {
this.authList = response.rows;
this.total = response.total;
this.loading = false;
});
},
//
cancel() {
this.open = false;
this.reset();
},
//
reset() {
this.form = {
dataAuthId: null,
deptId: null,
authNode: null,
productLineCode: null,
areaType: null
};
this.resetForm("form");
},
/** 搜索按钮操作 */
handleQuery() {
this.queryParams.pageNum = 1;
this.getList();
},
/** 重置按钮操作 */
resetQuery() {
this.resetForm("queryForm");
this.handleQuery();
},
//
handleSelectionChange(selection) {
this.ids = selection.map(item => item.dataAuthId)
this.single = selection.length!==1
this.multiple = !selection.length
},
/** 新增按钮操作 */
handleAdd() {
this.reset();
this.open = true;
this.title = "添加数据权限";
},
/** 修改按钮操作 */
handleUpdate(row) {
this.reset();
const dataAuthId = row.dataAuthId || this.ids
getAuth(dataAuthId).then(response => {
this.form = response.data;
this.open = true;
this.title = "修改数据权限";
});
},
/** 提交按钮 */
submitForm() {
this.$refs["form"].validate(valid => {
if (valid) {
if (this.form.dataAuthId != null) {
updateAuth(this.form).then(response => {
this.$modal.msgSuccess("修改成功");
this.open = false;
this.getList();
});
} else {
addAuth(this.form).then(response => {
this.$modal.msgSuccess("新增成功");
this.open = false;
this.getList();
});
}
}
});
},
/** 删除按钮操作 */
handleDelete(row) {
const dataAuthIds = row.dataAuthId || this.ids;
this.$modal.confirm('是否确认删除数据权限编号为"' + dataAuthIds + '"的数据项?').then(function() {
return delAuth(dataAuthIds);
}).then(() => {
this.getList();
this.$modal.msgSuccess("删除成功");
}).catch(() => {});
},
/** 导出按钮操作 */
handleExport() {
this.download('dhc/auth/export', {
...this.queryParams
}, `auth_${new Date().getTime()}.xlsx`)
}
}
};
</script>

336
src/views/system/user/authData.vue

@ -0,0 +1,336 @@ @@ -0,0 +1,336 @@
<template>
<div class="app-container">
<h4 class="form-header h4">基本信息</h4>
<el-form ref="form" :model="form" label-width="80px">
<el-row>
<el-col :span="8" :offset="2">
<el-form-item label="用户昵称" prop="nickName">
<el-input v-model="form.nickName" disabled />
</el-form-item>
</el-col>
<el-col :span="8" :offset="2">
<el-form-item label="登录账号" prop="userName">
<el-input v-model="form.userName" disabled />
</el-form-item>
</el-col>
</el-row>
</el-form>
<h4 class="form-header h4">数据权限信息</h4>
<el-row :gutter="10" class="mb8">
<el-col :span="1.5">
<el-button
type="primary"
plain
icon="el-icon-plus"
size="mini"
@click="handleAdd"
>新增</el-button>
</el-col>
</el-row>
<el-table v-loading="loading" :row-key="getRowKey" ref="table" :data="authData">
<el-table-column label="序号" width="60" type="index" />
<el-table-column label="组织" align="center" prop="deptIds">
<template slot-scope="scope">
<span v-if="scope.row.editFlag" >
<el-cascader v-model="scope.row.deptIds" :options="deptData" @change="setDeptName" placeholder="组织"></el-cascader>
</span>
<span v-else>{{scope.row.deptAllName}}</span>
</template>
</el-table-column>
<el-table-column label="权限控制节点" align="center" prop="authNode" >
<template slot-scope="scope">
<span v-if="scope.row.editFlag" >
<el-select v-model="scope.row.authNode" placeholder="权限控制节点">
<el-option
v-for="line in dict.type.auth_node"
:key="line.value"
:label="line.label"
:value="line.value"
/>
</el-select>
</span>
<span v-else>
<dict-tag :options="dict.type.auth_node" :value="scope.row.authNode"/>
</span>
</template>
</el-table-column>
<el-table-column label="产品线" align="center" prop="productLineCode">
<template slot-scope="scope">
<span v-if="scope.row.editFlag" >
<el-select v-model="scope.row.productLineCode" placeholder="产品线"
@change="setAreaType">
<el-option
v-for="line in dict.type.product_line"
:key="line.value"
:label="line.label"
:value="line.value"
/>
</el-select>
</span>
<span v-else>
<dict-tag :options="dict.type.product_line" :value="scope.row.productLineCode"/>
</span>
</template>
</el-table-column>
<el-table-column label="区域类型" align="center" prop="areaType">
<template slot-scope="scope">
<span v-if="scope.row.editFlag" >
<el-select v-model="scope.row.areaType" placeholder="区域类型" @change="setArea">
<el-option
v-for="type in areaTypeList"
:key="type.value"
:label="type.label"
:value="type.value"
/>
</el-select>
</span>
<span v-else>
<dict-tag :options="dict.type.area_type" :value="scope.row.areaType"/>
</span>
</template>
</el-table-column>
<el-table-column label="区域" align="center" prop="detailCodes">
<template slot-scope="scope">
<span v-if="scope.row.editFlag" >
<el-select v-model="scope.row.detailCodes" multiple placeholder="区域类型" @change="setAreaNames">
<el-option
v-for="type in areaList"
:key="type.value"
:label="type.label"
:value="type.value"
/>
</el-select>
</span>
<span v-else>{{scope.row.detailNames}}</span>
</template>
</el-table-column>
<el-table-column
label="操作"
align="center"
width="160"
class-name="small-padding fixed-width"
>
<template slot-scope="scope">
<el-button
size="mini"
type="text"
icon="el-icon-delete"
v-if="scope.row.editFlag"
@click="handleSave(scope.row)"
v-hasPermi="['system:user:remove']"
>保存</el-button>
<el-button
size="mini"
type="text"
icon="el-icon-delete"
v-else-if="!scope.row.editFlag"
@click="handleEdit(scope.row)"
>编辑</el-button>
<el-button
size="mini"
type="text"
icon="el-icon-delete"
@click="handleDelete(scope.$index, scope.row)"
v-hasPermi="['system:user:remove']"
>删除</el-button>
</template>
</el-table-column>
</el-table>
<el-form label-width="100px">
<el-form-item style="text-align: center;margin-left:-120px;margin-top:30px;">
<el-button @click="close()">返回</el-button>
</el-form-item>
</el-form>
</div>
</template>
<script>
import { addAuth, delAuth } from "@/api/system/auth";
import {getAuthData, deptTreeSelect } from "@/api/system/user";
import {queryList, queryAreaMaplist} from "@/api/dhc/productLineArea";
export default {
name: "AuthData",
dicts: ['product_line', 'area_type', 'auth_node'],
data() {
return {
//
loading: true,
authData: [],
//
form: {},
areaTypeList: [],
areaList: [],
deptData: [],
};
},
created() {
const userId = this.$route.params && this.$route.params.userId;
if (userId) {
this.loading = true;
getAuthData(userId).then((response) => {
this.form = response.user;
this.authData = response.authData;
this.total = this.authData.length;
this.$nextTick(() => {
this.authData.forEach((row) => {
if (row.flag) {
this.$refs.table.toggleRowSelection(row);
}
});
});
this.loading = false;
});
};
this.getDeptTree();
},
methods: {
handleEdit(row) {
this.authData.forEach((a) => {
a.editFlag = false;
});
row.editFlag = true;
},
handleSave(row) {
row.editFlag = false;
addAuth(row).then(response => {
this.$modal.msgSuccess("新增成功");
});
},
handleDelete(index, row) {
if (row.dataAuthId != null) {
let dataAuthIds = [];
dataAuthIds.push(row.dataAuthId);
this.$modal.confirm('是否确认删除的数据项?').then(function() {
return delAuth(dataAuthIds);
}).then(() => {
this.authData.splice(index,1)
this.$modal.msgSuccess("删除成功");
}).catch(() => {});
} else {
this.authData.splice(index,1)
}
},
//
handleSelectionChange(selection) {
this.roleIds = selection.map((item) => item.roleId);
},
//
getRowKey(row) {
return row.roleId;
},
/** 关闭按钮 */
close() {
const obj = { path: "/system/user" };
this.$tab.closeOpenPage(obj);
},
/** 添加按钮 */
handleAdd() {
this.authData.forEach((a) => {
a.editFlag = false;
});
this.authData.push({
editFlag:true,
dataAuthId:null,
userId:this.form.userId,
deptId:0,
deptAllId:'',
deptAllName:'',
authNode:'',
productLineCode:'',
areaType:'',
deptIds:[],
detailCodes:[],
detailNames:'',
detailList:{}
});
},
//
setAreaType(row) {
let queryParams = {productLineCode:row.productLineCode, areaType:'', type:'areaType'}
this.areaTypeList = [];
this.areaList = [];
queryList(queryParams).then(response => {
this.areaTypeList = response;
});
},
//
setArea(row) {
let queryParams = {productLineCode:row.productLineCode, areaType:row.areaType}
this.areaList = [];
queryAreaMaplist(queryParams).then(response => {
this.areaList = response;
});
},
setAreaNames(values) {
this.$nextTick(() => {
const labels = this.getSelectLabels(this.areaList, values);
let ids = values.join('|');
for (let i=0;i<this.authData.length;i++) {
let detailCodes = this.authData[i].detailCodes.join('|');
if (detailCodes == ids) {
this.authData[i].detailNames = labels.join('/');
}
this.authData[i].detailList = [];
for (let j=0;j<values.length;j++) {
let data = {detailType:'0', detailCode:values[j], detailName:labels[j]}
this.authData[i].detailList.push(data);
}
}
});
},
/** 查询部门下拉树结构 */
getDeptTree() {
deptTreeSelect().then(response => {
this.deptData = response.data;
});
},
setDeptName(values){
this.$nextTick(() => {
const labels = this.getCascaderLabels(this.deptData, values);
let ids = values.join('/');
for (let i=0;i<this.authData.length;i++) {
let deptIds = this.authData[i].deptIds.join('/');
if (deptIds == ids) {
this.authData[i].deptId = values[values.length-1];
this.authData[i].deptAllId = deptIds;
this.authData[i].deptAllName = labels.join('/');
}
}
});
},
getCascaderLabels(nodes, value) {
let labels = [];
for (let node of nodes) {
if (node.value === value[0]) {
labels.push(node.label);
if (node.children && value.length > 1) {
const childLabels = this.getCascaderLabels(node.children, value.slice(1));
if (childLabels) {
labels = labels.concat(childLabels);
}
}
break;
} else if (node.children) {
const foundLabels = this.getCascaderLabels(node.children, value);
if (foundLabels) {
labels = labels.concat(foundLabels);
}
}
}
return labels;
},
getSelectLabels(nodes, values) {
let labels = [];
for (let node of nodes) {
for (let value of values) {
if (node.value === value) {
labels.push(node.label);
}
}
}
return labels;
}
},
};
</script>

10
src/views/system/user/index.vue

@ -186,6 +186,8 @@ @@ -186,6 +186,8 @@
v-hasPermi="['system:user:resetPwd']">重置密码</el-dropdown-item>
<el-dropdown-item command="handleAuthRole" icon="el-icon-circle-check"
v-hasPermi="['system:user:edit']">分配角色</el-dropdown-item>
<el-dropdown-item command="handleAuthData" icon="el-icon-circle-plus-outline"
v-hasPermi="['system:user:edit']">分配数据权限</el-dropdown-item>
</el-dropdown-menu>
</el-dropdown>
</template>
@ -555,6 +557,9 @@ export default { @@ -555,6 +557,9 @@ export default {
case "handleAuthRole":
this.handleAuthRole(row);
break;
case "handleAuthData":
this.handleAuthData(row);
break;
default:
break;
}
@ -609,6 +614,11 @@ export default { @@ -609,6 +614,11 @@ export default {
const userId = row.userId;
this.$router.push("/system/user-auth/role/" + userId);
},
/** 分配数据权限操作 */
handleAuthData: function(row) {
const userId = row.userId;
this.$router.push("/system/user-auth/authData/" + userId);
},
/** 提交按钮 */
submitForm: function() {
this.$refs["form"].validate(valid => {

Loading…
Cancel
Save