he wei
2023-12-23 fc842d9e22aef1946df050257be41b4bfbd838a9
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
<template>
  <div class="p-container">
    <panel class="panel p-content">
      <div class="panel-content flex-c">
        <div class="btn-grp">
          <el-button
            type="primary"
            icon="el-icon-plus"
            round
            size="mini"
            @click="addUser"
            >添加</el-button
          >
          <el-button
            type="primary"
            round
            size="mini"
            @click="getList"
            icon="el-icon-search"
            >查询</el-button
          >
        </div>
 
        <!-- 用户列表 -->
        <div class="table-wrap">
          <el-table
            class="table-dark"
            stripe
            height="100%"
            size="small"
            :data="tableData"
            style="width: 100%"
          >
            <el-table-column
              type="index"
              label="序号"
              width="80"
            ></el-table-column>
            <el-table-column
              v-for="header in headers"
              :key="header.prop"
              :prop="header.prop"
              :label="header.label"
              :min-width="header.width"
              align="center"
            ></el-table-column>
            <el-table-column label="操作" width="360" align="center">
              <template slot-scope="scope">
                <el-button
                  type="primary"
                  size="mini"
                  :disabled="scope.row.uid == uid"
                  @click="edit(scope.row)"
                  >编辑</el-button
                >
                <el-button
                  type="primary"
                  size="mini"
                  :disabled="scope.row.uid == uid"
                  @click="resetSnId(scope.row)"
                  >重置密码</el-button
                >
                <el-button
                  type="danger"
                  size="mini"
                  :disabled="scope.row.uid == uid"
                  @click="confirmRemove(scope.row)"
                  >删除</el-button
                >
                <el-button
                  type="success"
                  v-if="scope.row.uid > 1000"
                  size="mini"
                  @click="improveRole(scope.row)"
                  >加入管理员组</el-button
                >
                <el-button
                  type="danger"
                  v-else
                  :disabled="scope.row.uid == uid"
                  size="mini"
                  @click="dropRole(scope.row)"
                  >移出管理员组</el-button
                >
              </template>
            </el-table-column>
          </el-table>
        </div>
        <!-- 底部 -->
        <!-- 底部分页 -->
        <el-pagination
          class="pages center dark"
          :current-page="pageCurr"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :page-sizes="[10, 20, 30, 50, 100]"
          :page-size="pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
        ></el-pagination>
      </div>
    </panel>
    <!-- 弹窗 -->
    <el-dialog
      :title="dialogTitle"
      :visible.sync="addEditVisible"
      top="0"
      :close-on-click-modal="false"
      class="dialog-center"
      width="700px"
      center
    >
      <add-edit
        v-if="addEditVisible"
        @success="onOk"
        :info="userInfo"
        @cancel="onCanel"
      ></add-edit>
    </el-dialog>
  </div>
</template>
 
<script>
import Panel from "@/components/panel.vue";
import gradientBtn from "@/components/gradientBtn.vue";
 
import {
  getAllUser,
  deleteUser,
  dropRole,
  improveRole,
  resetSnId,
} from "./api";
import AddEdit from "./addEdit";
import { mapGetters } from "vuex";
export default {
  name: "",
 
  data() {
    return {
      pageCurr: 1,
      pageSize: 10,
      total: 0,
      tableData: [],
      addEditVisible: false,
      dialogTitle: "",
      userInfo: {},
      headers: [
        {
          prop: "uname",
          label: "姓名",
          width: "",
        },
        {
          prop: "canDownload",
          label: "控制权限",
          width: "",
        },
      ],
    };
  },
  components: { AddEdit, Panel, gradientBtn },
  computed: {
    ...mapGetters(["uid"]),
  },
  methods: {
    getList() {
      let { pageCurr, pageSize } = this;
      let loading = this.$layer.loading();
      getAllUser(pageCurr, pageSize)
        .then((res) => {
          let { code, data, data2 } = res.data;
          let list = [];
          let total = 0;
          if (code && data) {
            // console.log(data);
            list = data2.list.map((v) => {
              v.canDownload = v.udownloadRole ? "有" : "无";
              return v;
            });
            total = data2.total;
          }
          this.$layer.close(loading);
          this.tableData = list;
          this.total = total;
        })
        .catch((err) => {
          console.log(err);
          this.$layer.close(loading);
        });
    },
    // 展示数据数量
    handleSizeChange(val) {
      this.pageSize = val;
      this.getList();
    },
    // 翻页
    handleCurrentChange(val) {
      this.pageCurr = val;
      this.getList();
    },
    addUser() {
      this.dialogTitle = "添加用户";
      this.userInfo = undefined;
      this.addEditVisible = true;
    },
    edit(record) {
      this.dialogTitle = "编辑用户";
      this.addEditVisible = true;
      this.userInfo = record;
    },
    confirmRemove(record) {
      this.$confirm("确认删除该用户吗", "系统提示", {
        type: "warning",
      })
        .then(() => {
          this.remove(record.uid);
        })
        .catch(() => {});
    },
    remove(uid) {
      let loading = this.$layer.loading();
      deleteUser(uid)
        .then((res) => {
          let { code, data } = res.data;
          if (code && data) {
            this.$message.success("操作成功");
            this.handleCurrentChange(1);
          } else {
            this.$message.success("操作失败");
          }
          this.$layer.close(loading);
        })
        .catch((err) => {
          this.$layer.close(loading);
          console.log(err);
        });
    },
    onOk() {
      this.addEditVisible = false;
      this.handleCurrentChange(1);
    },
    onCanel() {
      this.addEditVisible = false;
    },
    improveRole(record) {
      let loading = this.$layer.loading();
      improveRole(record.uid)
        .then((res) => {
          let { code, data, msg } = res.data;
          if (code && data) {
            this.$message.success(msg);
            this.getList();
          } else {
            this.$message.error(msg);
          }
          this.$layer.close(loading);
        })
        .catch((err) => {
          console.log(err);
          this.$layer.close(loading);
        });
    },
    dropRole(record) {
      let loading = this.$layer.loading();
      dropRole(record.uid)
        .then((res) => {
          let { code, data, msg } = res.data;
          if (code && data) {
            this.$message.success(msg);
            this.getList();
          } else {
            this.$message.error(msg);
          }
          this.$layer.close(loading);
        })
        .catch((err) => {
          this.$layer.close(loading);
          console.log(err);
        });
    },
    resetSnId(record) {
      this.$confirm("确认重置该用户密码吗", "系统提示", {
        type: "warning",
      })
        .then(() => {
          let loading = this.$layer.loading();
          resetSnId(record.uid)
            .then((res) => {
              let { code, data, msg } = res.data;
              if (code && data) {
                this.$message.success(msg);
              } else {
                this.$message.error(msg);
              }
              this.$layer.close(loading);
            })
            .catch((err) => {
              this.$layer.close(loading);
              console.log(err);
            });
        })
        .catch(() => {});
    },
  },
 
  mounted() {
    this.getList();
  },
};
</script>
 
<style scoped lang="less">
.p-container {
  height: 100%;
  display: flex;
  flex-direction: column;
 
  .p-content {
    flex: 1;
    margin-top: 4px;
    :deep(.content) {
      background: #011f39;
    }
    .panel-content {
      height: 100%;
      padding: 10px;
      .table-wrap {
        flex: 1;
        margin-top: 6px;
        margin-bottom: 6px;
      }
    }
  }
}
.btn-grp {
  padding: 0.6em;
}
</style>