list.vue
4.88 KB
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
<template>
<div class="article-list">
<zp-page-list>
<template v-slot:header>
<span>管理员列表</span>
</template>
<!-- filter start -->
<div slot="filter">
<el-form
ref="searchForm"
class="zp-search-form"
:inline="true"
:model="searchForm"
>
<el-form-item label="关键词:" prop="keyword">
<el-input
placeholder="请输入用户名"
v-model="searchForm.keyword"
@keydown.enter.native="getUserList"
></el-input>
</el-form-item>
<el-button type="primary" @click="getUserList"> 查询 </el-button>
</el-form>
</div>
<!-- filter end -->
<!-- list start -->
<div slot="list">
<zp-table-list
:loading="listLoading"
:source="userList"
:count="userTotal"
:columns="columns"
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
>
<template slot="_id" slot-scope="scope">
<el-button
icon="el-icon-document-copy"
type="primary"
size="mini"
class="clipboardBtn"
:data-clipboard-text="scope.row._id"
@click="handleCopyId"
>复制
</el-button>
</template>
<template slot="roles" slot-scope="scope">
<el-tag
class="tag"
type="primary"
close-transition
v-for="(tag, index) in scope.row.roles"
:key="index"
>{{ tag }}</el-tag
>
</template>
<template slot="operate" slot-scope="scope">
<el-button size="mini" type="primary" @click="handleEdit(scope.row)"
>编辑</el-button
>
<el-button
size="mini"
type="danger"
@click="handleDelete(scope.row)"
>删除</el-button
>
</template>
</zp-table-list>
</div>
<!-- list end -->
</zp-page-list>
<editDialog
v-if="editShow"
:info="userInfo"
@close="handleClose"
></editDialog>
</div>
</template>
<script>
import Clipboard from "clipboard";
import editDialog from "./components/editDialog";
import { mapGetters } from "vuex";
export default {
components: {
editDialog,
},
computed: {
...mapGetters(["userList", "userTotal"]),
},
data() {
return {
listLoading: false,
editShow: false,
searchForm: {
keyword: "",
},
userInfo: {},
columns: [
{
label: "_id",
prop: "_id",
slot: "_id",
},
{
label: "用户名",
prop: "username",
},
{
label: "权限",
prop: "roles",
slot: "roles",
},
{
label: "操作",
slot: "operate",
width: "150",
},
],
};
},
mounted() {
this.requestPageData = this.getUserList;
this.getUserList();
},
methods: {
async getUserList() {
this.listLoading = true;
try {
await this.$store.dispatch("getUserList", {
keyword: this.searchForm.keyword,
pageindex: this.pageInfo.pageNum,
pagesize: this.pageInfo.pageSize,
});
this.listLoading = false;
} catch (e) {
this.listLoading = false;
}
},
handleCopyId() {
let clipboard = new Clipboard(".clipboardBtn");
clipboard.on("success", (e) => {
this.$message.success("复制成功");
clipboard.destroy();
});
clipboard.on("error", (e) => {
this.$message.error("该浏览器不支持自动复制");
clipboard.destroy();
});
},
handleClose() {
this.editShow = false;
},
handleDelete(row) {
this.$confirm("此操作将永久删除该数据, 是否继续?", "提示", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning",
})
.then(async () => {
try {
await this.$store.dispatch("delUser", row._id);
this.$message.success("删除成功");
this.getUserList();
} catch (e) {
this.$message.error("删除失败");
console.log(e);
}
})
.catch(() => {
this.$message.info("已取消删除");
});
},
handleEdit(row) {
this.editShow = true;
row.releaseTime = new Date(row.releaseTime);
this.userInfo = row;
},
},
};
</script>
<style lang="less" scoped>
.tag {
margin: 0 10px;
}
</style>