Browse Source

fix:修改权限管理按钮在不同账号展示问题

confidence
杜贤金 3 years ago
parent
commit
4a019640df
  1. 673
      src/views/authority/role.vue
  2. 53
      src/views/iot/components/ProductDetail/Server.vue

673
src/views/authority/role.vue

@ -1,380 +1,407 @@
<template> <template>
<basic-container> <basic-container>
<avue-crud :option="option" <avue-crud
:table-loading="loading" :option="option"
:data="data" :table-loading="loading"
ref="crud" :data="data"
v-model="form" ref="crud"
:permission="permissionList" v-model="form"
:before-open="beforeOpen" :permission="permissionList"
@row-del="rowDel" :before-open="beforeOpen"
@row-update="rowUpdate" @row-del="rowDel"
@row-save="rowSave" @row-update="rowUpdate"
@search-change="searchChange" @row-save="rowSave"
@search-reset="searchReset" @search-change="searchChange"
@selection-change="selectionChange" @search-reset="searchReset"
@current-change="currentChange" @selection-change="selectionChange"
@size-change="sizeChange" @current-change="currentChange"
@refresh-change="refreshChange" @size-change="sizeChange"
@on-load="onLoad"> @refresh-change="refreshChange"
@on-load="onLoad"
>
<template slot="menuLeft"> <template slot="menuLeft">
<el-button type="danger" <el-button
size="small" type="danger"
icon="el-icon-delete" size="small"
v-if="permission.role_delete" icon="el-icon-delete"
plain v-if="permission.role_delete"
@click="handleDelete"> plain
@click="handleDelete"
>
</el-button> </el-button>
<el-button size="small" <!-- v-if="userInfo.role_name.includes('admin')" -->
icon="el-icon-setting" <el-button size="small" icon="el-icon-setting" @click="handleRole" plain
@click="handleRole" >权限设置
v-if="userInfo.role_name.includes('admin')"
plain>权限设置
</el-button> </el-button>
</template> </template>
</avue-crud> </avue-crud>
<el-dialog title="角色权限配置" <el-dialog
append-to-body title="角色权限配置"
:visible.sync="box" append-to-body
width="345px"> :visible.sync="box"
width="345px"
>
<el-tabs type="border-card"> <el-tabs type="border-card">
<el-tab-pane label="菜单权限"> <el-tab-pane label="菜单权限">
<el-tree :data="menuGrantList" <el-tree
show-checkbox :data="menuGrantList"
node-key="id" show-checkbox
ref="treeMenu" node-key="id"
:default-checked-keys="menuTreeObj" ref="treeMenu"
:props="props"> :default-checked-keys="menuTreeObj"
:props="props"
>
</el-tree> </el-tree>
</el-tab-pane> </el-tab-pane>
<el-tab-pane label="数据权限"> <el-tab-pane label="数据权限">
<el-tree :data="dataScopeGrantList" <el-tree
show-checkbox :data="dataScopeGrantList"
node-key="id" show-checkbox
ref="treeDataScope" node-key="id"
:default-checked-keys="dataScopeTreeObj" ref="treeDataScope"
:props="props"> :default-checked-keys="dataScopeTreeObj"
:props="props"
>
</el-tree> </el-tree>
</el-tab-pane> </el-tab-pane>
<el-tab-pane label="接口权限"> <el-tab-pane label="接口权限">
<el-tree :data="apiScopeGrantList" <el-tree
show-checkbox :data="apiScopeGrantList"
node-key="id" show-checkbox
ref="treeApiScope" node-key="id"
:default-checked-keys="apiScopeTreeObj" ref="treeApiScope"
:props="props"> :default-checked-keys="apiScopeTreeObj"
:props="props"
>
</el-tree> </el-tree>
</el-tab-pane> </el-tab-pane>
</el-tabs> </el-tabs>
<span slot="footer" <span slot="footer" class="dialog-footer">
class="dialog-footer">
<el-button @click="box = false"> </el-button> <el-button @click="box = false"> </el-button>
<el-button type="primary" <el-button type="primary" @click="submit"> </el-button>
@click="submit"> </el-button>
</span> </span>
</el-dialog> </el-dialog>
</basic-container> </basic-container>
</template> </template>
<script> <script>
import {add, getList, getRole, getRoleTreeById, grant, grantTree, remove, update} from "@/api/system/role"; import {
import {mapGetters} from "vuex"; add,
import website from '@/config/website'; getList,
getRole,
getRoleTreeById,
grant,
grantTree,
remove,
update,
} from "@/api/system/role";
import { mapGetters } from "vuex";
import website from "@/config/website";
export default { export default {
data() { data() {
return { return {
form: {}, form: {},
box: false, box: false,
props: { props: {
label: "title", label: "title",
value: "key" value: "key",
}, },
menuGrantList: [], menuGrantList: [],
dataScopeGrantList: [], dataScopeGrantList: [],
apiScopeGrantList: [], apiScopeGrantList: [],
apiGrantList: [], apiGrantList: [],
menuTreeObj: [], menuTreeObj: [],
dataScopeTreeObj: [], dataScopeTreeObj: [],
apiScopeTreeObj: [], apiScopeTreeObj: [],
selectionList: [], selectionList: [],
query: {}, query: {},
loading: true, loading: true,
page: { page: {
pageSize: 10, pageSize: 10,
currentPage: 1, currentPage: 1,
total: 0 total: 0,
}, },
option: { option: {
tip: false, tip: false,
simplePage: true, simplePage: true,
searchShow: true, searchShow: true,
searchMenuSpan: 6, searchMenuSpan: 6,
tree: true, tree: true,
border: true, border: true,
index: true, index: true,
selection: true, selection: true,
viewBtn: true, viewBtn: true,
dialogWidth: 900, dialogWidth: 900,
dialogClickModal: false, dialogClickModal: false,
column: [ column: [
{ {
label: "角色名称", label: "角色名称",
prop: "roleName", prop: "roleName",
search: true, search: true,
span: 24, span: 24,
rules: [ rules: [
{ {
required: true, required: true,
message: "请输入角色名称", message: "请输入角色名称",
trigger: "blur" trigger: "blur",
}
]
},
{
label: "所属租户",
prop: "tenantId",
type: "tree",
dicUrl: "/api/iot-system/tenant/select",
addDisplay: false,
editDisplay: false,
viewDisplay: website.tenantMode,
span: 24,
props: {
label: "tenantName",
value: "tenantId"
}, },
hide: !website.tenantMode, ],
search: website.tenantMode, },
rules: [{ {
label: "所属租户",
prop: "tenantId",
type: "tree",
dicUrl: "/api/iot-system/tenant/select",
addDisplay: false,
editDisplay: false,
viewDisplay: website.tenantMode,
span: 24,
props: {
label: "tenantName",
value: "tenantId",
},
hide: !website.tenantMode,
search: website.tenantMode,
rules: [
{
required: true, required: true,
message: "请输入所属租户", message: "请输入所属租户",
trigger: "click" trigger: "click",
}] },
}, ],
{ },
label: "角色别名", {
prop: "roleAlias", label: "角色别名",
search: true, prop: "roleAlias",
span: 24, search: true,
rules: [ span: 24,
{ rules: [
required: true, {
message: "请输入角色别名", required: true,
trigger: "blur" message: "请输入角色别名",
} trigger: "blur",
]
},
{
label: "上级角色",
prop: "parentId",
dicData: [],
type: "tree",
hide: true,
span: 24,
props: {
label: "title"
}, },
rules: [ ],
{ },
required: false, {
message: "请选择上级角色", label: "上级角色",
trigger: "click" prop: "parentId",
} dicData: [],
] type: "tree",
hide: true,
span: 24,
props: {
label: "title",
}, },
{ rules: [
label: "角色排序", {
prop: "sort", required: false,
type: "number", message: "请选择上级角色",
span: 24, trigger: "click",
rules: [ },
{ ],
required: true, },
message: "请输入角色排序", {
trigger: "blur" label: "角色排序",
} prop: "sort",
] type: "number",
} span: 24,
] rules: [
}, {
data: [] required: true,
message: "请输入角色排序",
trigger: "blur",
},
],
},
],
},
data: [],
};
},
computed: {
...mapGetters(["userInfo", "permission"]),
permissionList() {
return {
addBtn: this.vaildData(this.permission.role_add, false),
viewBtn: this.vaildData(this.permission.role_view, false),
delBtn: this.vaildData(this.permission.role_delete, false),
editBtn: this.vaildData(this.permission.role_edit, false),
}; };
}, },
computed: { ids() {
...mapGetters(["userInfo", "permission"]), let ids = [];
permissionList() { this.selectionList.forEach((ele) => {
return { ids.push(ele.id);
addBtn: this.vaildData(this.permission.role_add, false), });
viewBtn: this.vaildData(this.permission.role_view, false), return ids.join(",");
delBtn: this.vaildData(this.permission.role_delete, false),
editBtn: this.vaildData(this.permission.role_edit, false)
};
},
ids() {
let ids = [];
this.selectionList.forEach(ele => {
ids.push(ele.id);
});
return ids.join(",");
},
idsArray() {
let ids = [];
this.selectionList.forEach(ele => {
ids.push(ele.id);
});
return ids;
}
}, },
methods: { idsArray() {
initData(roleId){ let ids = [];
getRoleTreeById(roleId).then(res => { this.selectionList.forEach((ele) => {
const column = this.findObject(this.option.column, "parentId"); ids.push(ele.id);
column.dicData = res.data.data; });
}); return ids;
}, },
submit() { },
const menuList = this.$refs.treeMenu.getCheckedKeys(); methods: {
const dataScopeList = this.$refs.treeDataScope.getCheckedKeys(); initData(roleId) {
const apiScopeList = this.$refs.treeApiScope.getCheckedKeys(); getRoleTreeById(roleId).then((res) => {
grant(this.idsArray, menuList, dataScopeList, apiScopeList).then(() => { const column = this.findObject(this.option.column, "parentId");
this.box = false; column.dicData = res.data.data;
this.$message({ });
type: "success", },
message: "操作成功!" submit() {
}); const menuList = this.$refs.treeMenu.getCheckedKeys();
this.onLoad(this.page); const dataScopeList = this.$refs.treeDataScope.getCheckedKeys();
const apiScopeList = this.$refs.treeApiScope.getCheckedKeys();
grant(this.idsArray, menuList, dataScopeList, apiScopeList).then(() => {
this.box = false;
this.$message({
type: "success",
message: "操作成功!",
}); });
}, this.onLoad(this.page);
rowSave(row, done, loading) { });
add(row).then(() => { },
rowSave(row, done, loading) {
add(row).then(
() => {
this.onLoad(this.page); this.onLoad(this.page);
this.$message({ this.$message({
type: "success", type: "success",
message: "操作成功!" message: "操作成功!",
}); });
done(); done();
}, error => { },
(error) => {
window.console.log(error); window.console.log(error);
loading(); loading();
}); }
}, );
rowUpdate(row, index, done, loading) { },
update(row).then(() => { rowUpdate(row, index, done, loading) {
update(row).then(
() => {
this.onLoad(this.page); this.onLoad(this.page);
this.$message({ this.$message({
type: "success", type: "success",
message: "操作成功!" message: "操作成功!",
}); });
done(); done();
}, error => { },
(error) => {
window.console.log(error); window.console.log(error);
loading(); loading();
}); }
}, );
rowDel(row) { },
this.$confirm("确定将选择数据删除?", { rowDel(row) {
confirmButtonText: "确定", this.$confirm("确定将选择数据删除?", {
cancelButtonText: "取消", confirmButtonText: "确定",
type: "warning" cancelButtonText: "取消",
type: "warning",
})
.then(() => {
return remove(row.id);
}) })
.then(() => { .then(() => {
return remove(row.id); this.onLoad(this.page);
}) this.$message({
.then(() => { type: "success",
this.onLoad(this.page); message: "操作成功!",
this.$message({
type: "success",
message: "操作成功!"
});
}); });
}, });
},
searchReset() { searchReset() {
this.query = {}; this.query = {};
this.onLoad(this.page); this.onLoad(this.page);
}, },
searchChange(params, done) { searchChange(params, done) {
this.query = params; this.query = params;
this.page.currentPage = 1; this.page.currentPage = 1;
this.onLoad(this.page, params); this.onLoad(this.page, params);
done(); done();
}, },
selectionChange(list) { selectionChange(list) {
this.selectionList = list; this.selectionList = list;
}, },
selectionClear() { selectionClear() {
this.selectionList = []; this.selectionList = [];
this.$refs.crud.toggleSelection(); this.$refs.crud.toggleSelection();
}, },
beforeOpen(done, type) { beforeOpen(done, type) {
if (["add", "edit"].includes(type)) { if (["add", "edit"].includes(type)) {
this.initData(this.form.id); this.initData(this.form.id);
} }
done(); done();
}, },
handleRole() { handleRole() {
if (this.selectionList.length !== 1) { if (this.selectionList.length !== 1) {
this.$message.warning("只能选择一条数据"); this.$message.warning("只能选择一条数据");
return; return;
} }
this.menuTreeObj = []; this.menuTreeObj = [];
this.dataScopeTreeObj = []; this.dataScopeTreeObj = [];
this.apiScopeTreeObj = []; this.apiScopeTreeObj = [];
grantTree() grantTree().then((res) => {
.then(res => { this.menuGrantList = res.data.data.menu;
this.menuGrantList = res.data.data.menu; this.dataScopeGrantList = res.data.data.dataScope;
this.dataScopeGrantList = res.data.data.dataScope; this.apiScopeGrantList = res.data.data.apiScope;
this.apiScopeGrantList = res.data.data.apiScope; getRole(this.ids).then((res) => {
getRole(this.ids).then(res => { this.menuTreeObj = res.data.data.menu;
this.menuTreeObj = res.data.data.menu; this.dataScopeTreeObj = res.data.data.dataScope;
this.dataScopeTreeObj = res.data.data.dataScope; this.apiScopeTreeObj = res.data.data.apiScope;
this.apiScopeTreeObj = res.data.data.apiScope; this.box = true;
this.box = true; });
}); });
}); },
}, handleDelete() {
handleDelete() { if (this.selectionList.length === 0) {
if (this.selectionList.length === 0) { this.$message.warning("请选择至少一条数据");
this.$message.warning("请选择至少一条数据"); return;
return; }
} this.$confirm("确定将选择数据删除?", {
this.$confirm("确定将选择数据删除?", { confirmButtonText: "确定",
confirmButtonText: "确定", cancelButtonText: "取消",
cancelButtonText: "取消", type: "warning",
type: "warning" })
.then(() => {
return remove(this.ids);
}) })
.then(() => { .then(() => {
return remove(this.ids); this.onLoad(this.page);
}) this.$message({
.then(() => { type: "success",
this.onLoad(this.page); message: "操作成功!",
this.$message({
type: "success",
message: "操作成功!"
});
this.$refs.crud.toggleSelection();
}); });
}, this.$refs.crud.toggleSelection();
currentChange(currentPage) {
this.page.currentPage = currentPage;
},
sizeChange(pageSize) {
this.page.pageSize = pageSize;
},
refreshChange() {
this.onLoad(this.page, this.query);
},
onLoad(page, params = {}) {
this.loading = true;
getList(page.currentPage, page.pageSize, Object.assign(params, this.query)).then(res => {
this.data = res.data.data;
this.loading = false;
this.selectionClear();
}); });
} },
} currentChange(currentPage) {
}; this.page.currentPage = currentPage;
},
sizeChange(pageSize) {
this.page.pageSize = pageSize;
},
refreshChange() {
this.onLoad(this.page, this.query);
},
onLoad(page, params = {}) {
this.loading = true;
getList(
page.currentPage,
page.pageSize,
Object.assign(params, this.query)
).then((res) => {
this.data = res.data.data;
this.loading = false;
this.selectionClear();
});
},
},
};
</script> </script>

53
src/views/iot/components/ProductDetail/Server.vue

@ -1,26 +1,30 @@
<template> <template>
<div> <div>
<avue-crud <avue-
:option='option' :option="option"
:data='data' :data="data"
:table-loading='loading' :table-loading="loading"
@on-load='onLoad' @on-load="onLoad"
> >
<template #menuLeft> <template #menuLeft>
<el-button type='primary' size='small' @click='$router.push("/iot/server/subscribe")'> <el-button
type="primary"
size="small"
@click="$router.push('/iot/server/subscribe')"
>
管理订阅 管理订阅
</el-button> </el-button>
</template> </template>
</avue-crud> </avue->
</div> </div>
</template> </template>
<script> <script>
import { getServerSubscribeList } from '@/api/iot/device/product'; import { getServerSubscribeList } from "@/api/iot/device/product";
import {isEmptyObject} from '@/util/util'; import { isEmptyObject } from "@/util/util";
export default { export default {
name: 'Server', name: "Server",
props: { props: {
detail: { detail: {
type: Object, type: Object,
@ -37,26 +41,27 @@ export default {
border: true, border: true,
columnBtn: false, columnBtn: false,
refreshBtn: false, refreshBtn: false,
size: 'small', size: "small",
column: [ column: [
{ {
label: '订阅类型', label: "订阅类型",
prop: 'type', prop: "type",
}, },
{ {
label: '订阅消息', label: "订阅消息",
dicUrl: '/api/iot-system/dict/dictionary?code=subscribe_message_type', dicUrl:
"/api/iot-system/dict/dictionary?code=subscribe_message_type",
props: { props: {
label: 'dictValue', label: "dictValue",
value: 'dictKey' value: "dictKey",
}, },
prop: 'messageType', prop: "messageType",
dataType: 'number', dataType: "number",
type: 'tree', type: "tree",
}, },
{ {
label: '创建时间', label: "创建时间",
prop: 'createTime', prop: "createTime",
}, },
], ],
}, },
@ -68,7 +73,9 @@ export default {
this.loading = true; this.loading = true;
getServerSubscribeList(this.detail.id).then((res) => { getServerSubscribeList(this.detail.id).then((res) => {
// type // type
this.data = !isEmptyObject(res.data.data) ? [{...res.data.data, type: 'mqtt'}] : []; this.data = !isEmptyObject(res.data.data)
? [{ ...res.data.data, type: "mqtt" }]
: [];
this.loading = false; this.loading = false;
}); });
}, },

Loading…
Cancel
Save