Blame view

ant-design-vue-jeecg/src/views/system/modules/DeptUserInfo.vue 11.3 KB
1
2
3
4
5
6
7
8
9
<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <!-- 搜索区域 -->
      <a-form layout="inline">
        <a-row :gutter="10">
          <a-col :md="10" :sm="12">
            <a-form-item label="用户账号" style="margin-left:8px">
10
              <a-input placeholder="请输入账号" v-model="queryParam.username"></a-input>
11
12
13
14
15
16
17
18
19
20
21
22
            </a-form-item>
          </a-col>
          <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
            <a-col :md="6" :sm="24">
             <a-button type="primary" @click="searchQuery" icon="search" style="margin-left: 18px">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
            </a-col>
          </span>
        </a-row>
      </a-form>
    </div>
    <!-- 操作按钮区域 -->
23
    <div class="table-operator" :md="24" :sm="24" style="margin-top: -15px">
24
25
      <!--<a-button @click="handleEdit" type="primary" icon="edit" style="margin-top: 16px">用户编辑</a-button>-->
      <a-button @click="handleAddUserDepart" type="primary" icon="plus">添加已有用户</a-button>
26
      <a-button @click="handleAdd" type="primary" icon="plus" style="margin-top: 16px">新建用户</a-button>
27
28
29
30
31

      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel">
            <a-icon type="delete"/>
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
          </a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作
          <a-icon type="down"/>
        </a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{
        selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        @change="handleTableChange">



        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>

          <a-divider type="vertical"/>

          <a-dropdown>
            <a class="ant-dropdown-link">
              更多 <a-icon type="down"/>
            </a>
            <a-menu slot="overlay">
73
                <a-menu-item>
74
                <a href="javascript:;" @click="handleDeptRole(record)">部门角色</a>
75
76
              </a-menu-item>
77
              <a-menu-item>
78
                <a href="javascript:;" @click="handleDetail(record)">用户详情</a>
79
80
81
              </a-menu-item>

              <a-menu-item>
82
83
                <a-popconfirm title="确定取消与选中部门关联吗?" @confirm="() => handleDelete(record.id)">
                  <a>取消关联</a>
84
85
86
87
88
89
90
91
92
93
94
95
96
97
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>


      </a-table>
    </div>
    <!-- table区域-end -->

    <!-- 表单区域 -->
    <user-modal ref="modalForm" @ok="modalFormOk"></user-modal>
    <Select-User-Modal ref="selectUserModal" @selectFinished="selectOK"></Select-User-Modal>
98
    <dept-role-user-modal ref="deptRoleUser"></dept-role-user-modal>
99
100
101
102
103
104
105
106
  </a-card>
</template>

<script>
  import {JeecgListMixin} from '@/mixins/JeecgListMixin'
  import {getAction, postAction, deleteAction} from '@/api/manage'
  import SelectUserModal from './SelectUserModal'
  import UserModal from './UserModal'
107
  import DeptRoleUserModal from './DeptRoleUserModal'
108
109
110
111
112

  export default {
    name: "DeptUserInfo",
    mixins: [JeecgListMixin],
    components: {
113
      DeptRoleUserModal,
114
115
116
117
118
119
120
      SelectUserModal,
      UserModal
    },
    data() {
      return {
        description: '用户信息',
        currentDeptId: '',
121
        currentDept: {},
122
123
        // 表头
        columns: [{
124
125
126
127
            title: '用户账号',
            align: "center",
            dataIndex: 'username'
          },
128
129
130
131
132
133
          {
            title: '用户名称',
            align: "center",
            dataIndex: 'realname'
          },
          {
134
135
136
137
138
            title: '部门',
            align: "center",
            dataIndex: 'orgCode'
          },
          {
139
140
141
142
143
144
145
146
147
148
            title: '性别',
            align: "center",
            dataIndex: 'sex_dictText'
          },
          {
            title: '电话',
            align: "center",
            dataIndex: 'phone'
          },
          {
149
150
151
152
            title: '操作',
            dataIndex: 'action',
            scopedSlots: {customRender: 'action'},
            align: "center",
153
            width: 150
154
155
156
157
158
159
160
161
162
163
164
165
166
          }],
        url: {
          list: "/sys/user/departUserList",
          edit: "/sys/user/editSysDepartWithUser",
          delete: "/sys/user/deleteUserInDepart",
          deleteBatch: "/sys/user/deleteUserInDepartBatch",
        }
      }
    },
    created() {
    },

    methods: {
167
168
169
170
      searchReset() {
        this.queryParam = {}
        this.loadData(1);
      },
171
172
173
174
175
176
177
178
179
      loadData(arg) {
        if (!this.url.list) {
          this.$message.error("请设置url.list属性!")
          return
        }
        //加载数据 若传入参数1则加载第一页的内容
        if (arg === 1) {
          this.ipagination.current = 1;
        }
180
181
        //if (this.currentDeptId === '') return;
        let params = this.getQueryParams();//查询条件
182
183
        params.depId = this.currentDeptId;
        getAction(this.url.list, params).then((res) => {
184
          if (res.success && res.result) {
185
186
187
188
189
190
191
192
193
194
195
            this.dataSource = res.result.records;
            this.ipagination.total = res.result.total;
          }
        })
      },
      batchDel: function () {

        if (!this.url.deleteBatch) {
          this.$message.error("请设置url.deleteBatch属性!")
          return
        }
196
197
198
199
200
        if (!this.currentDeptId) {
          this.$message.error("未选中任何部门,无法取消部门与用户的关联!")
          return
        }
201
202
203
204
205
206
207
208
209
210
211
        if (this.selectedRowKeys.length <= 0) {
          this.$message.warning('请选择一条记录!');
          return;
        } else {
          var ids = "";
          for (var a = 0; a < this.selectedRowKeys.length; a++) {
            ids += this.selectedRowKeys[a] + ",";
          }
          var that = this;
          console.log(this.currentDeptId);
          this.$confirm({
212
213
            title: "确认取消",
            content: "是否取消用户与选中部门的关联?",
214
215
216
            onOk: function () {
              deleteAction(that.url.deleteBatch, {depId: that.currentDeptId, userIds: ids}).then((res) => {
                if (res.success) {
217
                  that.$message.success("删除用户与选中部门关系成功!");
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
                  that.loadData();
                  that.onClearSelected();
                } else {
                  that.$message.warning(res.message);
                }
              });
            }
          });
        }
      },
      handleDelete: function (id) {
        if (!this.url.delete) {
          this.$message.error("请设置url.delete属性!")
          return
        }
233
234
235
236
237
        if (!this.currentDeptId) {
          this.$message.error("未选中任何部门,无法取消部门与用户的关联!")
          return
        }
238
239
240
        var that = this;
        deleteAction(that.url.delete, {depId: this.currentDeptId, userId: id}).then((res) => {
          if (res.success) {
241
            that.$message.success("删除用户与选中部门关系成功!");
zhangdaihao authored
242
243
244
245
246
247
248
249
            if (this.selectedRowKeys.length>0){
               for(let i =0; i<this.selectedRowKeys.length;i++){
                   if (this.selectedRowKeys[i] == id){
                     this.selectedRowKeys.splice(i,1);
                     break;
                   }
               }
            }
250
251
252
253
254
255
256
257
258
            that.loadData();
          } else {
            that.$message.warning(res.message);
          }
        });
      },
      open(record) {
        //console.log(record);
        this.currentDeptId = record.id;
259
        this.currentDept = record;
260
261
262
263
264
265
266
        this.loadData(1);
      },
      clearList() {
        this.currentDeptId = '';
        this.dataSource = [];
      },
      hasSelectDept() {
267
        if (this.currentDeptId == '') {
268
269
270
271
272
273
          this.$message.error("请选择一个部门!")
          return false;
        }
        return true;
      },
      handleAddUserDepart() {
274
        if (this.currentDeptId == '' ) {
275
276
277
278
279
          this.$message.error("请选择一个部门!")
        } else {
          this.$refs.selectUserModal.visible = true;
        }
      },
280
281
282
283
      handleEdit: function (record) {
        this.$refs.modalForm.title = "编辑";
        this.$refs.modalForm.departDisabled = true;
        this.$refs.modalForm.disableSubmit = false;
284
285
286
287
        //update-begin---author:wangshuai ---date:20220315  for:[issues/3472]给新建用户赋予角色的逻辑漏洞------------
        //部门中角色信息隐藏掉
        this.$refs.modalForm.roleDisabled = true
        //update-end---author:wangshuai ---date:20220315  for:[issues/3472]给新建用户赋予角色的逻辑漏洞------------
288
289
        this.$refs.modalForm.edit(record);
      },
290
291
292
293
294
      handleAdd: function () {
        if (this.currentDeptId == '') {
          this.$message.error("请选择一个部门!")
        } else {
          this.$refs.modalForm.departDisabled = true;
295
296
297
298
          //update-begin---author:wangshuai ---date:20220315  for:[issues/3472]给新建用户赋予角色的逻辑漏洞------------
          //部门中角色信息隐藏掉
          this.$refs.modalForm.roleDisabled = true
          //update-end---author:wangshuai ---date:20220315  for:[issues/3472]给新建用户赋予角色的逻辑漏洞------------
299
          //初始化负责部门
300
          this.$refs.modalForm.nextDepartOptions=[{value:this.currentDept.key,label:this.currentDept.title}]
301
          this.$refs.modalForm.title = "新增";
302
          this.$refs.modalForm.edit({activitiSync:'1',userIdentity:1,selecteddeparts:this.currentDeptId})
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
        }
      },
      selectOK(data) {
        let params = {};
        params.depId = this.currentDeptId;
        params.userIdList = [];
        for (var a = 0; a < data.length; a++) {
          params.userIdList.push(data[a]);
        }
        console.log(params);
        postAction(this.url.edit, params).then((res) => {
          if (res.success) {
            this.$message.success(res.message);
            this.loadData();
          } else {
            this.$message.warning(res.message);
          }
        })
321
322
      },
      handleDeptRole(record){
323
324
325
326
327
328
        if(this.currentDeptId != ''){
          this.$refs.deptRoleUser.add(record,this.currentDeptId);
          this.$refs.deptRoleUser.title = "部门角色分配";
        }else{
          this.$message.warning("请先选择一个部门!");
        }
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
      }
    }
  }
</script>
<style scoped>
  /** Button按钮间距 */
  .ant-btn {
    margin-left: 3px
  }

  .ant-card {
    margin-left: -30px;
    margin-right: -30px;
  }

  .table-page-search-wrapper {
    margin-top: -16px;
    margin-bottom: 16px;
  }
</style>