Blame view

HHECS.Web/src/views/systemPermission/components/bus_user.vue 12.9 KB
1
2
3
4
5
6
7
8
<template>
  <div class="sys-container">
    <form ref="form" label-width="80px">
      <el-row :gutter="10">
        <el-col :span="3.5">
          <div class="sys-form-item bg-purple">
            <div class="sys-form-item-text">用户编码:</div>
            <div class="sys-form-item-input">
9
              <el-input v-model="paramsQuery.queryConfig.UserCode" placeholder="请输入用户编码" />
10
11
12
13
14
15
16
            </div>
          </div>
        </el-col>
        <el-col :span="3.5">
          <div class="sys-form-item bg-purple">
            <div class="sys-form-item-text">用户名称:</div>
            <div class="sys-form-item-input">
17
              <el-input v-model="paramsQuery.queryConfig.UserName" placeholder="请输入用户名称" />
18
19
20
21
22
23
            </div>
          </div>
        </el-col>

        <el-col :span="4">
          <div class="sys-form-item bg-purple">
24
25
            <el-button icon="el-icon-search" @click="btnAction(1)" type="primary">查询</el-button>
            <el-button icon="el-icon-refresh-right" @click="btnAction(0)">重置</el-button>
26
27
28
          </div>
        </el-col>
      </el-row>
29
      <div class="sys-pb-5">
30
        <el-button type="primary" size="small" icon="el-icon-plus" @click="userEditOrAddOpen(null, 'add')">
31
32
33
          新增
        </el-button>
      </div>
34
    </form>
35
36
37
    <!-- table -->
    <div class="sys-table-border">
38
39
40
41
      <el-table :data="tableData" ref="multipleTable" border :header-cell-style="{ color: '#000000' }"
        highlight-current-row style="width: 100%" height="520">
        <el-table-column label="序号" width="60" type="index" :index="(index) =>
          (paramsQuery.PageNumber - 1) * paramsQuery.PerPageCount + index + 1" />
42
43
44
        <el-table-column prop="id" label="id" v-if="false"></el-table-column>
        <el-table-column prop="userCode" label="用户编码"> </el-table-column>
        <el-table-column prop="userName" label="用户名称"> </el-table-column>
45
46
47
48
        <el-table-column prop="department" label="部门" width="150"> </el-table-column>
        <el-table-column prop="phone" label="电话" width="150"> </el-table-column>
        <el-table-column prop="disable" label="是否启用"  :formatter="(row) => row.disable ? '是' : '否'" width="90"> </el-table-column>
        <el-table-column prop="address" label="地址" width="200"> </el-table-column>
49
50
        <el-table-column prop="remark" label="备注"> </el-table-column>
陈嘉新 authored
51
52
        <el-table-column prop="created" label="创建时间" width="180">
        </el-table-column>
53
        <el-table-column prop="createdBy" label="创建人"> </el-table-column>
54
55
        <el-table-column label="操作" width="120">
          <template slot-scope="scope">
56
57
            <el-button type="text" @click="userEditOrAddOpen(scope.row, 'edit')">编辑</el-button>
            <el-button style="color: red" type="text" @click="userDelete(scope.row, 'edit')">删除</el-button>
58
59
          </template>
        </el-table-column>
60
61
62
      </el-table>

      <div class="sys-pagination-container">
63
64
65
        <el-pagination @current-change="handleCurrentChange" @size-change="handleSizeChange"
          :current-page="paramsQuery.PageNumber" :page-size="paramsQuery.PerPageCount" :page-sizes="[20, 50, 100]"
          layout="total, sizes, prev, pager, next, jumper" :total="paramsQuery.PageTotal" />
66
67
      </div>
    </div>
68
69
    <!-- dialog 用户新增和编辑 -->
70
    <el-dialog :title="userDialog.title" :close-on-click-modal="false" :visible.sync="userDialog.visible" width="60%">
71
72
73
74
      <el-form :model="userDialog.form" label-width="80px">
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="编码">
75
76
              <el-input v-model="userDialog.form.userCode" ref="userCode" maxlength="20" show-word-limit
                autocomplete="off"></el-input>
77
78
79
80
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="名称">
81
82
              <el-input v-model="userDialog.form.userName" ref="userName" maxlength="20" show-word-limit
                autocomplete="off"></el-input>
83
84
85
86
87
88
89
            </el-form-item>
          </el-col>
        </el-row>
        <!-- 第二行:密码 + 部门 -->
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="密码">
90
91
              <el-input v-model="userDialog.form.password" type="password" maxlength="20" ref="password"
                autocomplete="off"></el-input>
92
93
94
95
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="部门">
96
97
              <el-input v-model="userDialog.form.department" maxlength="20" show-word-limit
                autocomplete="off"></el-input>
98
99
100
101
102
103
104
            </el-form-item>
          </el-col>
        </el-row>
        <!-- 第三行:电话 + 地址 -->
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="电话">
105
              <el-input v-model="userDialog.form.phone" maxlength="20" show-word-limit autocomplete="off"></el-input>
106
107
108
109
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="地址">
110
              <el-input v-model="userDialog.form.address" maxlength="40" show-word-limit autocomplete="off"></el-input>
111
112
113
114
115
116
117
            </el-form-item>
          </el-col>
        </el-row>

        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="权限">
118
119
              <el-select v-model="roleSelectOpt.selectVal" multiple placeholder="请选择权限">
                <el-option v-for="item in roleSelectOpt.data" :key="item.value" :label="item.label" :value="item.value">
120
121
122
123
124
125
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="禁用">
126
127
              <el-switch v-model="userDialog.form.disable" active-color="#ff4949" inactive-color="#13ce66"
                active-text="(绿色启用/红色禁用)">
128
129
130
131
132
133
134
135
136
              </el-switch>
            </el-form-item>
          </el-col>
        </el-row>

        <!-- 单列:备注 -->
        <el-row>
          <el-col :span="24">
            <el-form-item label="备注">
137
              <el-input v-model="userDialog.form.remark" type="textarea" :rows="2" autocomplete="off">
138
139
140
141
142
143
144
145
146
147
              </el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="userAddOrEditSave">确 定</el-button>
        <el-button @click="userDialog.visible = false">取 消</el-button>
      </span>
    </el-dialog>
148
149
150
  </div>
</template>
<script>
151
import * as userApi from "@/api/systemPermission/userPermission";
152
153
export default {
  data() {
154
    const defaultData = {
155
      PageNumber: 1,
156
      PerPageCount: 20,
157
158
159
160
161
162
      queryConfig: {
        UserCode: "",
        UserName: "",
      },
      PageTotal: 0,
    };
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
    const userData = {
      userCode: "",
      userName: "",
      password: "",
      department: null,
      phone: null,
      remark: null,
      address: "",
      disable: false,

      //权限数据
      Roles: [],

      Created: null,
      CreatedBy: null,
      Updated: null,
      UpdatedBy: null,
陈嘉新 authored
180
      Id: 0,
181
    };
182
183
    return {
      tableData: [],
184
185
186
187
188
189
190
191
192
193
194
195
      paramsQuery: { ...defaultData },
      defaultData: JSON.parse(JSON.stringify(defaultData)),

      userDialog: {
        visible: false,
        flag: "add",
        title: "新增",
        form: { ...userData },
        formDefaultData: JSON.parse(JSON.stringify(userData)),
      },
      //临时存储的数据
      roleSelectOpt: {
陈嘉新 authored
196
        data: [], // 处理后的数据(展示用)
197
198
        originData: [], // 原始数据
        selectVal: null,
陈嘉新 authored
199
      },
200
201
202
    };
  },
  methods: {
203
204
205
    /**
     * 查询或者搜索
     */
206
207
    btnAction(flag) {
      if (flag == 0) {
208
        this.paramsQuery = JSON.parse(JSON.stringify(this.defaultData));
209
210
211
      }
      this.getData();
    },
212
213
    getData() {
陈嘉新 authored
214
      userApi.getUserData(this.paramsQuery).then((response) => {
215
        this.paramsQuery.PageTotal = response.data.totalCount;
216
217
218
219
        this.tableData = response.data.data;
      });
    },
220
221
222
223
    /**
     * 获取用户权限数据
     */
    getUserRoleList() {
陈嘉新 authored
224
225
      userApi.getUserRole().then((res) => {
        if (res.code !== "Success") return;
226
227
        this.roleSelectOpt.data = this.getUserRoleDataHandle(res.data);
        this.roleSelectOpt.originData = res.data;
陈嘉新 authored
228
      });
229
230
231
232
233
234
    },
    /**
     * 用户选项数据转换给组件格式数据
     */
    getUserRoleDataHandle(data) {
      var roleOptions = [];
陈嘉新 authored
235
      data.forEach((element) => {
236
237
        roleOptions.push({
          value: element.id,
陈嘉新 authored
238
239
          label: element.roleName,
        });
240
      });
陈嘉新 authored
241
      return roleOptions;
242
243
244
245
246
247
    },

    /**
     * 新增或者编辑弹出框
     */
    async userEditOrAddOpen(row, flag) {
陈嘉新 authored
248
      debugger;
249
      if (this.roleSelectOpt.data.length == 0) {
陈嘉新 authored
250
251
252
        this.$message.error(
          "权限数据加载中...请稍后在操作,反复出现请联系管理员!"
        );
253
254
255
256
257
        return;
      }
      this.roleSelectOpt.selectVal = [];
      this.userDialog.flag = flag;
      if (flag == "add") {
陈嘉新 authored
258
259
260
261
        this.userDialog.form = JSON.parse(
          JSON.stringify(this.userDialog.formDefaultData)
        );
        this.userDialog.title = "新增";
262
      } else {
陈嘉新 authored
263
264
265
        this.userDialog.title = `编辑,用户名【${row.userName}】`;
        var result = await userApi.getUserWithRoles({ UserCode: row.userCode });
        const keys = result.data.roles.map((x) => x.id);
266
267
268
269
        this.roleSelectOpt.selectVal = keys;
        this.userDialog.form = row;
      }
      this.userDialog.visible = true;
270
    },
271
272
273
274
275

    /**
     * 用户新增或者编辑 保存操作
     */
    userAddOrEditSave() {
陈嘉新 authored
276
277
278
279
280
      debugger;
      if (
        this.userDialog.form.userCode == "" ||
        this.userDialog.form.userCode == null
      ) {
281
282
283
284
        this.$message.error("用户编码不能为!");
        this.$refs.userCode.focus();
        return;
      }
陈嘉新 authored
285
286
287
288
      if (
        this.userDialog.form.userName == "" ||
        this.userDialog.form.userName == null
      ) {
289
290
291
292
        this.$message.error("用户名称不能为!");
        this.$refs.userName.focus();
        return;
      }
陈嘉新 authored
293
294
295
296
      if (
        this.userDialog.form.password == "" ||
        this.userDialog.form.password == null
      ) {
297
298
299
300
301
302
303
304
        this.$message.error("用户密码不能为!");
        this.$refs.password.focus();
        return;
      }
      var roleData = this.getSelectRoleVal();
      if (roleData.length == 0) return;
      this.userDialog.form.Roles = roleData;
      if (this.userDialog.flag == "edit") {
陈嘉新 authored
305
306
307
308
309
310
311
312
313
        userApi.editUser(this.userDialog.form).then((res) => {
          userApi.ajaxSuccessBefore(
            res,
            (res) => {
              this.userDialog.visible = false;
              this.getData();
            },
            this
          );
314
        });
陈嘉新 authored
315
        return;
316
      }
陈嘉新 authored
317
318
319
320
321
322
323
324
325
      userApi.addUser(this.userDialog.form).then((res) => {
        userApi.ajaxSuccessBefore(
          res,
          (res) => {
            this.userDialog.visible = false;
            this.getData();
          },
          this
        );
326
327
328
329
330
331
      });
    },

    //用户删除
    userDelete(row) {
      var title = `此操作将永久删除该数据,用户名【${row.userName}】,是否继续?`;
陈嘉新 authored
332
      this.$confirm(title, "提示", { type: "warning" })
赖素文 authored
333
        .then(() => {
陈嘉新 authored
334
335
336
337
338
339
340
341
342
          userApi.deleteUser(row).then((res) => {
            userApi.ajaxSuccessBefore(
              res,
              (res) => {
                this.userDialog.visible = false;
                this.getData();
              },
              this
            );
343
          });
陈嘉新 authored
344
345
        })
        .catch();
346
347
348
349
350
351
352
353
354
355
356
357
358
    },

    setCurrent(row) {
      this.$refs.multipleTable.setCurrentRow(row);
    },

    //获取选中的权限,处理好符合后台提交数据格式
    getSelectRoleVal() {
      if (this.roleSelectOpt.selectVal.length == 0) {
        this.$message.error("请选择权限数据!");
        return [];
      }
      var result = [];
陈嘉新 authored
359
360
361
      this.roleSelectOpt.selectVal.forEach((x) => {
        var tempVal = this.roleSelectOpt.originData.find((y) => y.id == x);
        result.push(tempVal);
362
363
364
365
      });
      return result;
    },
    //下一页
366
    handleCurrentChange(page) {
陈嘉新 authored
367
      debugger;
368
369
370
371
372
373
      this.paramsQuery.PageNumber = page;
      this.getData();
    },
    handleSizeChange(val) {
      this.paramsQuery.PerPageCount = val;
      this.paramsQuery.PageNumber = 1;
374
375
376
377
      this.getData();
    },
  },
  mounted() {
378
    this.getUserRoleList();
379
380
381
382
383
384
385
386
387
    this.getData();
  },
};
</script>
<style scoped lang="scss">
.sys-container {
  width: 100%;
}
388
389
.sys-pb-5 {
  padding-bottom: 5px !important;
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
}

.sys-form-item {
  display: flex;
  border-radius: 4px;
  min-height: 46px;
  margin-bottom: 10px;
  align-items: center;
}

.sys-table-border {
  border: 1px solid #e5e9f2;
}

.sys-pagination-container {
  text-align: center;
406
407
408
409
}

.current-row {
  background-color: #ecf5ff;
410
411
}
</style>