xiangpei
2025-04-18 7feee0463330ee014b0ac1a6f8e31118bb699f12
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<template>
  <el-dialog
      title="分配权限"
      :visible.sync="dialogTreeVisible"
      width="400px"
      :append-to-body="true"
      :close-on-click-modal="false"
      :destroy-on-close="true"
   >
    <el-tree
        style="width: 100%; height: 400px; overflow: auto; margin-bottom: 30px"
        :data="treeData"
        ref="tree"
        node-key="id"
        show-checkbox
        :check-strictly="true"
        :default-expand-all="false"
        :highlight-current="true"
        :default-checked-keys="rolePermissions.menuIds"
        @check-change="selectedNodes"
        :props="defaultProps">
    </el-tree>
    <div slot="footer" class="dialog-footer">
      <el-button @click="dialogTreeVisible = false" size="small">取 消</el-button>
      <el-button type="primary" @click="addPermission" size="small">确 定</el-button>
    </div>
  </el-dialog>
</template>
 
<script>
import {addPermission} from "@/api/role";
export default {
  name: "PermissionDialog",
  data() {
    return {
      defaultProps: {
        children: 'children',
        label: 'menuName'
      }
    }
  },
  computed: {
    dialogTreeVisible: {
      get() {
        return this.$store.state.role.dialogTreeVisible;
      },
      set(value) {
        this.$store.state.role.dialogTreeVisible = value;
      }
    },
    treeData: {
      get() {
        return this.$store.state.role.treeData;
      },
      set(value) {
        this.$store.state.role.treeData =value;
      }
    },
    rolePermissions: {
      get() {
        return this.$store.state.role.rolePermissions;
      },
      set(value) {
        this.$store.state.role.rolePermissions =value;
      }
    }
    ,
    assignPermission: {
      get() {
        return this.$store.state.role.assignPermission;
      },
      set(value) {
        this.$store.state.role.assignPermission =value;
      }
    }
  },
  methods: {
    selectedNodes() {
      this.assignPermission = this.$refs.tree.getCheckedNodes().map((item) => {return item.id});
    },
    addPermission() {
      // if (this.$store.state.role.rolePermissions) {
      //
      // }
      var params = {
        roleId: this.$store.state.role.roleId,
        id: this.$store.state.role.rolePermissions === null ? null : this.$store.state.role.rolePermissions.id ,
        menuIds: this.assignPermission
      }
      addPermission(params).then((res) => {
        this.$message.success(res.data.msg);
        this.dialogTreeVisible = false;
      })
    }
  }
}
</script>
 
<style scoped>
 
</style>