schangxiang@126.com
2025-09-19 9be9c3784b2881a3fa25e93ae2033dc2803c0ed0
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
<template>
  <el-dialog v-dialogDrag :visible.sync="currentDialogVisible" title="数据权限设置" class="dialog-container" width="980px" @open="onOpen">
    <el-table ref="table" :data="tableData" style="width: 100%">
      <el-table-column label="模块" width="180">
        <template slot-scope="{row}">
          <el-checkbox v-model="row.allChecked" @change="(val)=>{selectAll(val, row)}"></el-checkbox>
          <span style="margin-left: 10px">{{ row.moduleName }}</span>
        </template>
      </el-table-column>
      <el-table-column label="权限点">
        <template slot-scope="{row}">
          <div class="padding-bottom-10">
            <el-checkbox v-model="row.isAll">全部</el-checkbox>
          </div>
          <el-checkbox v-for="(item, index) in row.authNodeList" :key="index" :disabled="row.isAll" v-model="item.isCheck">{{ item.nodeName }}</el-checkbox>
        </template>
      </el-table-column>
    </el-table>
 
    <span slot="footer" class="dialog-footer">
      <el-button @click="currentDialogVisible = false">取 消</el-button>
      <el-button :loading="isSave" type="primary" icon="el-icon-yrt-baocun2" @click="save">保存</el-button>
    </span>
  </el-dialog>
</template>
 
<script>
export default {
  props: {
    visible: {
      type: Boolean,
      default: false
    },
    label: {
      type: String,
      default: null
    },
    userId: {
      type: Number,
      required: true
    }
  },
  data() {
    return {
      isSave: false,
      tableData: []
    };
  },
  computed: {
    // 显示窗口
    currentDialogVisible: {
      get: function() {
        return this.visible;
      },
      set: function(val) {
        this.$emit("update:visible", val);
      }
    }
  },
  watch: {},
  created() {},
  methods: {
    // 初始化数据
    init() {
      const url = "/api/auth/getDataAuth";
      const params = {
        openNodeApi: true,
        id: this.userId
      };
      this.common.ajax(
        url,
        params,
        res => {
          this.common.showMsg(res);
          if (res.result) {
            this.tableData = res.data;
            this.tableData.forEach(item => {
              var allChecked = true;
              item.authNodeList.forEach(node => {
                if (!node.isCheck) {
                  allChecked = false;
                }
              });
              item.allChecked = allChecked;
              // 是否全部
              const allNode = item.authNodeList.find(node => node.node_Id === 0);
              this.$set(item, "isAll", allNode ? allNode.isCheck : false);
 
              // 排除掉0
              item.authNodeList = item.authNodeList.filter(node => node.node_Id !== 0);
            });
          }
        },
        this.$refs.table
      );
    },
    // 对话框打开事件
    onOpen() {
      this.init();
    },
    // 全选
    selectAll(val, row) {
      row.authNodeList.forEach(item => {
        item.isCheck = val;
      });
    },
    save() {
      const _tableData = JSON.parse(JSON.stringify(this.tableData));
 
      _tableData.forEach(item => {
        item.user_Id = this.userId;
        item.authNodeList.forEach(node => {
          delete node.nodeName;
        });
        item.authNodeList = item.authNodeList.filter(node => node.isCheck);
        const allNode = item.authNodeList.find(node => node.node_Id === 0);
        if (!allNode) {
          item.authNodeList.push({
            node_Id: 0,
            isCheck: item.isAll
          });
        } else {
          allNode.isCheck = item.isAll;
        }
      });
      const url = "/api/auth/saveUserDataAuth";
      const params = {
        code: JSON.stringify(_tableData)
      };
      this.common.ajax(
        url,
        params,
        res => {
          this.common.showMsg(res);
          this.currentDialogVisible = false;
        },
        this.$refs.table
      );
    }
  }
};
</script>
 
<style lang="scss" scoped>
.dialog-container {
  /deep/ .el-upload-list {
    margin-right: 20px;
  }
  /deep/ .scrollbar-wrap {
    max-height: 400px;
    overflow-x: hidden;
    padding: 0px;
  }
  .msg-container {
    margin: 0;
    padding: 0;
    .msg-item {
      margin: 0;
      padding: 5px 0;
      word-wrap: break-word;
    }
  }
}
</style>