提交 | 用户 | age
|
36b711
|
1 |
<template> |
L |
2 |
<div class="app-container"> |
7f89d0
|
3 |
<!-- 返回按钮和标题 --> |
C |
4 |
<!-- <el-page-header class="mb20" content="xx" @back="$router.go(-1)" /> --> |
|
5 |
|
36b711
|
6 |
<!-- 搜索区 ↓↓↓↓↓↓↓↓↓↓ --> |
L |
7 |
<el-form v-show="showSearch" ref="searchForm" :inline="true"> |
|
8 |
<el-form-item label="角色名称"> |
|
9 |
<el-input |
|
10 |
v-model="keyWord" |
|
11 |
placeholder="请输入角色名称" |
|
12 |
clearable |
|
13 |
size="small" |
|
14 |
style="width: 240px" |
|
15 |
maxlength="50" |
|
16 |
@keyup.enter.native="reGetList" |
|
17 |
/> |
|
18 |
</el-form-item> |
|
19 |
<el-form-item> |
|
20 |
<el-button type="cyan" icon="el-icon-search" size="mini" @click="reGetList">搜索</el-button> |
|
21 |
<el-button icon="el-icon-refresh" size="mini" @click="resetHandle">重置</el-button> |
|
22 |
</el-form-item> |
|
23 |
</el-form> |
|
24 |
<!-- 搜索区 ↑↑↑↑↑↑↑↑↑↑ --> |
|
25 |
|
|
26 |
<!-- 操作区 ↓↓↓↓↓↓↓↓↓↓ --> |
|
27 |
<el-row :gutter="10" class="mb8"> |
7f89d0
|
28 |
<!-- 权限判断 v-if="getAuthValueFN('xxx_add')" --> |
36b711
|
29 |
<el-col :span="1.5"> |
L |
30 |
<el-button |
|
31 |
type="primary" |
|
32 |
icon="el-icon-plus" |
|
33 |
size="mini" |
|
34 |
@click="showAddDialog" |
|
35 |
>新增</el-button> |
|
36 |
</el-col> |
|
37 |
<right-toolbar :show-search.sync="showSearch" @queryTable="getList" /> |
|
38 |
</el-row> |
|
39 |
<!-- 操作区 ↑↑↑↑↑↑↑↑↑↑ --> |
|
40 |
|
|
41 |
<el-table :data="list" max-height="500px" stripe> |
|
42 |
<el-table-column type="index" label="序号" align="center" width="60" /> |
|
43 |
<el-table-column label="角色名称" prop="name" align="center" min-width="120" /> |
|
44 |
<el-table-column label="角色名称" prop="name" align="center" min-width="120" /> |
|
45 |
<el-table-column label="角色名称" prop="name" align="center" min-width="120" /> |
|
46 |
<el-table-column label="角色名称" prop="name" align="center" min-width="120" /> |
|
47 |
<el-table-column label="角色名称" prop="name" align="center" min-width="120" /> |
|
48 |
<el-table-column label="角色名称" prop="name" align="center" min-width="120" /> |
|
49 |
<el-table-column label="角色名称" prop="name" align="center" min-width="120" /> |
|
50 |
<el-table-column label="角色名称" prop="name" align="center" min-width="120" /> |
|
51 |
<el-table-column label="角色名称" prop="name" align="center" min-width="120" /> |
|
52 |
<el-table-column label="角色名称" prop="name" align="center" min-width="120" /> |
|
53 |
<el-table-column label="是否上架" prop="isUp" align="center" min-width="100"> |
|
54 |
<template slot-scope="scope"> |
7f89d0
|
55 |
<!-- 权限判断 v-if="getAuthValueFN('xxx_edit')" --> |
36b711
|
56 |
<el-switch |
L |
57 |
v-model="scope.row.isUp" |
|
58 |
:active-value="1" |
|
59 |
:inactive-value="0" |
|
60 |
@change="handleUpChange(scope.row)" |
|
61 |
/> |
|
62 |
</template> |
|
63 |
</el-table-column> |
|
64 |
<el-table-column label="创建时间" prop="createTime" align="center" min-width="160" /> |
|
65 |
<el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="120" fixed="right"> |
|
66 |
<template slot-scope="scope"> |
7f89d0
|
67 |
<!-- 权限判断 v-if="getAuthValueFN('xxx_edit')" --> |
36b711
|
68 |
<el-button |
L |
69 |
size="mini" |
|
70 |
type="text" |
|
71 |
icon="el-icon-edit" |
|
72 |
@click="showEditDialog(scope.row)" |
|
73 |
>编辑</el-button> |
7f89d0
|
74 |
<!-- 权限判断 v-if="getAuthValueFN('xxx_del')" --> |
36b711
|
75 |
<el-button |
L |
76 |
size="mini" |
|
77 |
type="text warn" |
|
78 |
icon="el-icon-delete" |
|
79 |
@click="handleDelete(scope.row)" |
|
80 |
>删除</el-button> |
|
81 |
</template> |
|
82 |
</el-table-column> |
|
83 |
</el-table> |
|
84 |
|
|
85 |
<!-- 新增&编辑 --> |
7f89d0
|
86 |
<el-dialog v-el-drag-dialog :title="(dialogData.type=='add'?'新增':'编辑') + objectName" width="500px" :visible.sync="dialogVisible" append-to-body :before-close="hideDialog" :close-on-click-modal="false"> |
36b711
|
87 |
<el-form ref="refDialog" :model="dialogData" label-width="110px" :rules="rules" size="small"> |
L |
88 |
<el-form-item label="名称" prop="name"> |
|
89 |
<el-input v-model="dialogData.name" placeholder="请输入名称" maxlength="50" /> |
|
90 |
</el-form-item> |
|
91 |
<el-form-item label="是否上架" prop="isUp"> |
|
92 |
<el-switch |
|
93 |
v-model="dialogData.isUp" |
|
94 |
:active-value="1" |
|
95 |
:inactive-value="0" |
|
96 |
/> |
|
97 |
</el-form-item> |
|
98 |
</el-form> |
|
99 |
<div slot="footer" class="dialog-footer"> |
|
100 |
<el-button @click="hideDialog">取消</el-button> |
|
101 |
<el-button type="primary" @click="submitHandle">确定</el-button> |
|
102 |
</div> |
|
103 |
</el-dialog> |
|
104 |
|
|
105 |
<pagination |
|
106 |
v-show="total>0" |
|
107 |
:total="total" |
|
108 |
:page.sync="pageNum" |
|
109 |
:limit.sync="pageSize" |
|
110 |
@pagination="getList" |
|
111 |
/> |
|
112 |
</div> |
|
113 |
</template> |
|
114 |
|
|
115 |
<script> |
|
116 |
|
|
117 |
export default { |
|
118 |
name: 'Demo', |
|
119 |
data() { |
|
120 |
return { |
|
121 |
showSearch: true, // 是否显示搜索区 |
7f89d0
|
122 |
keyWord: '', // 搜索区字段,可自行扩展其余字段 |
36b711
|
123 |
|
7f89d0
|
124 |
// TODO |
C |
125 |
objectName: 'xx', // 对象名称,用于删除提示、启用提示、弹窗标题等 |
|
126 |
|
|
127 |
// 数据列表 |
36b711
|
128 |
list: [], |
L |
129 |
|
|
130 |
// 弹窗数据 |
|
131 |
dialogVisible: false, |
|
132 |
dialogData: {}, |
7f89d0
|
133 |
|
C |
134 |
// 富文本编辑器 |
|
135 |
// rangenum: null, |
36b711
|
136 |
|
L |
137 |
// 分页 ↓↓↓↓↓↓↓↓↓↓ |
|
138 |
total: 0, |
|
139 |
pageNum: 1, |
|
140 |
pageSize: 20, |
|
141 |
// 分页 ↑↑↑↑↑↑↑↑↑↑ |
|
142 |
|
|
143 |
// 表单校验 |
|
144 |
rules: { |
|
145 |
name: [ |
|
146 |
{ required: true, message: '名称不能为空', trigger: 'change' } |
|
147 |
], |
|
148 |
isUp: [ |
|
149 |
{ required: true, message: '是否上架不能为空', trigger: 'change' } |
|
150 |
] |
|
151 |
} |
|
152 |
} |
|
153 |
}, |
|
154 |
mounted() { |
|
155 |
this.init() |
|
156 |
}, |
|
157 |
methods: { |
|
158 |
// 初始化 |
|
159 |
init() { |
|
160 |
this.getList() |
|
161 |
}, |
|
162 |
|
7f89d0
|
163 |
// ========== 富文本相关 |
C |
164 |
// 富文本编辑器的内容赋值 |
|
165 |
// catchData(content) { |
|
166 |
// if (content === '<p><br></p>') content = '' |
|
167 |
// try { |
|
168 |
// const currentRange = window.getSelection().getRangeAt(0) |
|
169 |
// this.rangenum = currentRange |
|
170 |
// } catch (e) { |
|
171 |
// |
|
172 |
// } |
|
173 |
// this.$set(this.dialogData, 'content', content) |
|
174 |
// this.$refs[this.formName].validateField('content') |
|
175 |
// }, |
|
176 |
// ========== 富文本相关 |
|
177 |
|
36b711
|
178 |
// 获取列表 |
L |
179 |
getList() { |
|
180 |
var { pageNum, pageSize, keyWord } = this |
|
181 |
this.postFN({ |
7f89d0
|
182 |
// TODO url |
36b711
|
183 |
url: 'xxx', |
L |
184 |
params: { |
|
185 |
pageNum: pageNum, |
|
186 |
pageSize: pageSize, |
|
187 |
keyWord: keyWord |
|
188 |
}, |
|
189 |
mockData: { |
|
190 |
code: 100, |
|
191 |
msg: '', |
|
192 |
data: { |
|
193 |
list: [{ |
|
194 |
id: 'xxx', |
|
195 |
index: 1, |
|
196 |
name: '超级管理员', |
|
197 |
createTime: '2020-08-09 10:10:10' |
|
198 |
}], |
|
199 |
total: 100 |
|
200 |
} |
|
201 |
} |
|
202 |
}, (inf) => { |
7f89d0
|
203 |
// 测试用 |
36b711
|
204 |
for (var i = 0; i < 19; i++) { |
L |
205 |
inf.list.push({ |
|
206 |
id: 'xxx', |
|
207 |
index: 1, |
|
208 |
name: '超级管理员', |
|
209 |
createTime: '2020-08-09 10:10:10' |
|
210 |
}) |
|
211 |
} |
|
212 |
this.list = inf.list || [] |
|
213 |
this.total = inf.total |
|
214 |
}) |
|
215 |
}, |
|
216 |
// 重新获取列表 |
|
217 |
reGetList() { |
|
218 |
this.pageNum = 1 |
|
219 |
this.getList() |
|
220 |
}, |
|
221 |
// 重置 |
|
222 |
resetHandle() { |
|
223 |
this.keyWord = '' |
|
224 |
this.reGetList() |
|
225 |
}, |
|
226 |
// 删除 |
|
227 |
handleDelete(item) { |
|
228 |
// 打开二次确认弹窗 |
|
229 |
this.$confirm('是否确认删除该角色?', '提示', { |
|
230 |
confirmButtonText: '确定', |
|
231 |
cancelButtonText: '取消', |
|
232 |
type: 'warning' |
|
233 |
}).then(() => { |
|
234 |
// 确定回调 |
7f89d0
|
235 |
// TODO url |
36b711
|
236 |
this.postFN({ |
L |
237 |
url: 'xxx', |
|
238 |
params: { |
|
239 |
id: item.id |
|
240 |
}, |
|
241 |
mockData: { |
|
242 |
code: 100, |
|
243 |
msg: '', |
|
244 |
data: {} |
|
245 |
} |
|
246 |
}, () => { |
|
247 |
this.getList() |
|
248 |
this.$messageSuc('删除成功') |
|
249 |
}) |
|
250 |
}).catch(() => {}) |
|
251 |
}, |
|
252 |
// 修改是否上架 todo |
|
253 |
handleUpChange(item) { |
|
254 |
const text = item.isUp === 1 ? '上架' : '下架' |
|
255 |
this.$confirm('确认要' + text + '该角色吗?', '提示', { |
|
256 |
confirmButtonText: '确定', |
|
257 |
cancelButtonText: '取消', |
|
258 |
type: 'warning' |
|
259 |
}).then(() => { |
|
260 |
this.postFN({ |
|
261 |
url: 'xxx', |
7f89d0
|
262 |
// TODO url |
36b711
|
263 |
params: { |
L |
264 |
id: item.id |
|
265 |
}, |
|
266 |
mockData: { |
|
267 |
code: 100, |
|
268 |
msg: '', |
|
269 |
data: {} |
|
270 |
} |
|
271 |
}, () => { |
|
272 |
this.$messageSuc(text + '成功') |
4dde14
|
273 |
}, (res) => { |
L |
274 |
item.isUp = item.isUp === 1 ? 0 : 1 |
|
275 |
this.$messageError(res.msg) |
36b711
|
276 |
}) |
L |
277 |
}).catch(() => { |
|
278 |
item.isUp = item.isUp === 1 ? 0 : 1 |
|
279 |
}) |
|
280 |
}, |
|
281 |
|
|
282 |
// 打开新增弹窗 |
|
283 |
showAddDialog() { |
|
284 |
var dialogData = { |
|
285 |
type: 'add', |
|
286 |
isUp: 1 |
|
287 |
} |
|
288 |
this.dialogVisible = true |
|
289 |
this.$nextTick(() => { |
|
290 |
this.dialogData = dialogData |
|
291 |
this.$refs['refDialog'].resetFields() |
|
292 |
}) |
|
293 |
}, |
|
294 |
// 打开编辑弹框 |
|
295 |
showEditDialog(item) { |
|
296 |
var dialogData = { |
|
297 |
type: 'edit', |
|
298 |
...item |
|
299 |
} |
|
300 |
console.log('dialogData', dialogData) |
|
301 |
this.dialogVisible = true |
|
302 |
this.$nextTick(() => { |
|
303 |
this.dialogData = dialogData |
|
304 |
this.$refs['refDialog'].resetFields() |
|
305 |
}) |
|
306 |
}, |
|
307 |
// 关闭编辑弹窗 |
|
308 |
hideDialog() { |
|
309 |
this.dialogData = {} |
|
310 |
this.dialogVisible = false |
7f89d0
|
311 |
// 清空富文本 |
C |
312 |
// this.rangenum = null |
36b711
|
313 |
}, |
L |
314 |
// 提交新增&编辑 |
|
315 |
submitHandle() { |
|
316 |
this.$refs['refDialog'].validate(valid => { |
|
317 |
if (valid) { |
|
318 |
this.submitReq() |
|
319 |
} |
|
320 |
}) |
|
321 |
}, |
|
322 |
// 提交接口 |
|
323 |
submitReq() { |
|
324 |
var { dialogData } = this |
|
325 |
var params = { |
|
326 |
name: dialogData.name, |
|
327 |
isUp: dialogData.isUp |
|
328 |
} |
|
329 |
|
|
330 |
if (dialogData.password) params.password = dialogData.password |
|
331 |
|
|
332 |
var isAdd = dialogData.type === 'add' |
7f89d0
|
333 |
// TODO url |
C |
334 |
var url = isAdd ? 'xxx/add' : 'xxx/edit' |
36b711
|
335 |
|
L |
336 |
!isAdd && (params.id = dialogData.id) |
|
337 |
|
|
338 |
this.postFN({ |
|
339 |
url: url, |
|
340 |
params: params, |
|
341 |
mockData: { |
|
342 |
code: 100, |
|
343 |
msg: '', |
|
344 |
data: {} |
|
345 |
} |
|
346 |
}, () => { |
|
347 |
this.$messageSuc('保存成功') |
|
348 |
this.hideDialog() |
b82c1e
|
349 |
isAdd ? this.reGetList() : this.getList() |
36b711
|
350 |
}) |
L |
351 |
} |
|
352 |
} |
|
353 |
} |
|
354 |
</script> |
|
355 |
|
|
356 |
<style lang="scss" scoped> |
|
357 |
|
|
358 |
</style> |