| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284 |
- <template>
- <basic-container>
- <avue-crud :option="option"
- :data="data"
- ref="crud"
- v-model="form"
- :permission="permissionList"
- @row-del="rowDel"
- @row-update="rowUpdate"
- @row-save="rowSave"
- @search-change="searchChange"
- @search-reset="searchReset"
- @selection-change="selectionChange"
- @on-load="onLoad">
- <template slot="menuLeft">
- <el-button type="danger"
- size="small"
- icon="el-icon-delete"
- plain
- @click="handleDelete">删 除
- </el-button>
- <el-button size="small"
- icon="el-icon-delete"
- @click="handleRole"
- plain>权限设置
- </el-button>
- </template>
- <template slot-scope="{row}"
- slot="roleId">
- <el-tag>{{row.roleName}}</el-tag>
- </template>
- <template slot-scope="{row}"
- slot="deptId">
- <el-tag>{{row.deptName}}</el-tag>
- </template>
- </avue-crud>
- <el-dialog title="提示"
- :visible.sync="box"
- width="40%">
- <el-tree :data="list"
- show-checkbox
- node-key="id"
- ref="tree"
- :default-checked-keys="defaultObj"
- :props="props">
- </el-tree>
- <span slot="footer"
- class="dialog-footer">
- <el-button @click="box = false">取 消</el-button>
- <el-button type="primary"
- @click="submit">确 定</el-button>
- </span>
- </el-dialog>
- </basic-container>
- </template>
- <script>
- import {
- getList,
- remove,
- update,
- add,
- grant,
- grantTree,
- getRole,
- getRoleTree
- } from "@/api/system/role";
- import { mapGetters } from "vuex";
- export default {
- data() {
- return {
- form: {},
- box: false,
- props: {
- label: "title",
- valie: "key"
- },
- list: [],
- defaultObj: [],
- selectionList: [],
- page: {
- pageSize: 10,
- currentPage: 1,
- total: 0
- },
- option: {
- tip: false,
- tree: true,
- border: true,
- index: true,
- selection: true,
- viewBtn: true,
- column: [
- {
- label: "角色名称",
- prop: "roleName",
- search: true,
- rules: [
- {
- required: true,
- message: "请输入角色名称",
- trigger: "blur"
- }
- ]
- },
- {
- label: "角色别名",
- prop: "roleAlias",
- search: true,
- rules: [
- {
- required: true,
- message: "请输入角色别名",
- trigger: "blur"
- }
- ]
- },
- {
- label: "上级角色",
- prop: "parentId",
- dicData: [],
- type: "tree",
- hide: true,
- props: {
- label: "title"
- },
- rules: [
- {
- required: false,
- message: "请选择上级角色",
- trigger: "blur"
- }
- ]
- },
- {
- label: "角色排序",
- prop: "sort",
- type: "number",
- rules: [
- {
- required: true,
- message: "请输入角色排序",
- trigger: "blur"
- }
- ]
- }
- ]
- },
- data: []
- };
- },
- computed: {
- ...mapGetters(["permission"]),
- permissionList() {
- return {
- addBtn: this.permission.role_add,
- viewBtn: this.permission.role_view,
- delBtn: this.permission.role_delete,
- editBtn: this.permission.role_edit
- };
- },
- ids() {
- let ids = [];
- this.selectionList.forEach(ele => {
- ids.push(ele.id);
- });
- return ids.join(",");
- }
- },
- methods: {
- submit() {
- const menuLIst = this.$refs.tree.getCheckedKeys().join(",");
- grant(this.ids[0], menuLIst).then(() => {
- this.box = false;
- this.$message({
- type: "success",
- message: "操作成功!"
- });
- this.onLoad(this.page);
- });
- },
- rowSave(row, loading) {
- add(row).then(() => {
- loading();
- this.onLoad(this.page);
- this.$message({
- type: "success",
- message: "操作成功!"
- });
- });
- },
- rowUpdate(row, index, loading) {
- update(row).then(() => {
- this.onLoad(this.page);
- loading();
- this.$message({
- type: "success",
- message: "操作成功!"
- });
- });
- },
- rowDel(row) {
- this.$confirm("确定将选择数据删除?", {
- confirmButtonText: "确定",
- cancelButtonText: "取消",
- type: "warning"
- })
- .then(() => {
- return remove(row.id);
- })
- .then(() => {
- this.onLoad(this.page);
- this.$message({
- type: "success",
- message: "操作成功!"
- });
- });
- },
- searchReset() {
- this.onLoad(this.page);
- },
- searchChange(params) {
- this.onLoad(this.page, params);
- },
- selectionChange(list) {
- this.selectionList = list;
- },
- handleRole() {
- if (this.selectionList.length !== 1) {
- this.$message.warning("请选择至少一条数据");
- return;
- }
- this.defaultObj = [];
- grantTree()
- .then(res => {
- this.list = res.data.data;
- return getRole(this.ids[0]);
- })
- .then(res => {
- this.defaultObj = res.data.data;
- this.box = true;
- });
- },
- handleDelete() {
- if (this.selectionList.length === 0) {
- this.$message.warning("请选择至少一条数据");
- return;
- }
- this.$confirm("确定将选择数据删除?", {
- confirmButtonText: "确定",
- cancelButtonText: "取消",
- type: "warning"
- })
- .then(() => {
- return remove(this.ids);
- })
- .then(() => {
- this.onLoad(this.page);
- this.$message({
- type: "success",
- message: "操作成功!"
- });
- this.$refs.crud.toggleSelection();
- });
- },
- onLoad(page, params = {}) {
- getList(page.currentPage, page.pageSize, params).then(res => {
- const data = res.data.data;
- this.data = data;
- getRoleTree().then(res => {
- const data = res.data.data;
- const index = this.$refs.crud.findColumnIndex("parentId");
- this.option.column[index].dicData = data;
- });
- });
- }
- }
- };
- </script>
- <style>
- </style>
|