审查视图

src/views/nav1/perm.vue 13.9 KB
1 2 3 4 5 6
<template>
	<section>
		<!--工具条-->
		<el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
			<el-form :inline="true" :model="filters">
				<el-form-item>
7 8 9 10
					<el-input v-model="filters.name" placeholder="权限名称">
						<template slot="prepend">权限名称</template>
					</el-input>
11 12
				</el-form-item>
				<el-form-item>
13
					<el-button type="primary" v-on:click="getTableList()"  icon="el-icon-search">查&emsp;&emsp;询</el-button>
14 15
				</el-form-item>
				<el-form-item>
16
					<el-button type="success" @click="handleAdd" icon="el-icon-document">新&emsp;&emsp;增</el-button>
17 18 19 20 21
				</el-form-item>
			</el-form>
		</el-col>

		<!--列表-->
22 23 24
		<el-table :data="tableList" highlight-current-row v-loading="listLoading" @selection-change="selsChange"
				  tooltip-effect="dark"
				  style="border-radius: 10px 10px 0px 0px;line-height: 25px;"
小范 authored
25
				  height="600px"
26
				  :header-cell-style="{background:'#6F8294',color:'#FFFFFF'}" size="small"
27 28
				  row-key="permissionId"
				  border
朱兆平 authored
29
				  :row-class-name="tableRowClassName"
30
				  :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
31
		>
32 33
			<el-table-column type="selection" width="55">
			</el-table-column>
34 35 36
			<!--<el-table-column type="index" width="60">-->
			<!--</el-table-column>-->
			<el-table-column prop="permissionId" label="ID" width="130" sortable>
37
			</el-table-column>
38
			<el-table-column prop="name" label="权限名称" min-width="150" sortable>
39
			</el-table-column>
40 41
<!--			<el-table-column prop="description" label="描述" min-width="120" sortable>-->
<!--			</el-table-column>-->
42
			<el-table-column prop="ismenu" label="是否目录" width="100" :formatter="formatState" sortable>
43
			</el-table-column>
朱兆平 authored
44 45 46
			<el-table-column prop="path" label="访问路径" width="300" sortable>
			</el-table-column>
			<el-table-column prop="permissionOrder" label="排序" width="100" sortable>
47
			</el-table-column>
48
			<el-table-column label="操作" min-width="150" fixed="right">
49
				<template slot-scope="scope">
50 51 52
					<el-button size="mini" @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
					<el-button type="success" @click="handleEdit(scope.$index, scope.row)">白名单</el-button>
					<el-button type="danger"  @click="handleDel(scope.$index, scope.row)">删除</el-button>
53 54 55 56 57 58 59
				</template>
			</el-table-column>
		</el-table>

		<!--工具条-->
		<el-col :span="24" class="toolbar">
			<el-button type="danger" @click="batchRemove" :disabled="this.sels.length===0">批量删除</el-button>
shenhailong authored
60
			<el-pagination layout="total, prev, pager, next" @current-change="handleCurrentChange" :page-size="pageSize" :total="total" style="float:right;">
61 62 63 64 65
			</el-pagination>
		</el-col>


		<!--新增界面-->
66 67 68 69 70
		<el-dialog :title="dialogMap[dialogStatus]" :visible.sync="addFormVisible" :close-on-click-modal="false">
			<el-form :model="addForm" label-width="110px" :rules="addFormRules" ref="addForm">

				<el-form-item label="ID">
					<span>{{addForm.permissionId}}</span>
小范 authored
71
				</el-form-item>
72
				<el-row :gutter="20">
朱兆平 authored
73
					<el-col :span="8">
74 75 76 77
						<el-form-item label="权限名称" prop="name">
							<el-input v-model="addForm.name" auto-complete="off" placeholder="请输入权限名称:例如:用户新增权限"></el-input>
						</el-form-item>
					</el-col>
朱兆平 authored
78
					<el-col :span="8">
79 80 81 82
						<el-form-item label="权限描述" prop="description">
							<el-input v-model="addForm.description" auto-complete="off" placeholder="请输入权限描述:例如:用户管理员"></el-input>
						</el-form-item>
					</el-col>
朱兆平 authored
83 84 85 86 87
					<el-col :span="8">
						<el-form-item label="图标" prop="iconCls">
							<el-input v-model="addForm.iconCls" auto-complete="off" placeholder="element icon图标名称"></el-input>
						</el-form-item>
					</el-col>
88 89 90
				</el-row>
				<el-row :gutter="20">
					<el-col>
91
						<el-form-item label="菜单访问路径" prop="path">
92
							<el-input v-model="addForm.path" auto-complete="off" placeholder="设置为前端router的path值"></el-input>
93 94 95 96 97
<!--							<el-cascader-panel-->
<!--									v-model="addForm.path"-->
<!--									:options="cascaderOptions"-->
<!--									:props="pannelProps"-->
<!--							></el-cascader-panel>-->
98 99 100
						</el-form-item>
					</el-col>
				</el-row>
101
				<el-form-item label="接口访问路径" prop="url">
102 103 104 105 106 107
					<el-input v-model="addForm.url" auto-complete="off" placeholder="设置为后端微服务路径:例如:/cloud-user-center/user/update"></el-input>
					<el-cascader-panel
							v-model="addForm.url"
							:options="tableList"
							:props="pannelUrlProps"
					></el-cascader-panel>
小范 authored
108
				</el-form-item>
109 110 111
				<el-row :gutter="20">
					<el-col :span="8">
						<el-form-item label="权限排序" prop="permissionOrder">
朱兆平 authored
112 113 114 115 116
							<el-input
									placeholder="请输入权限排序,如001"
									v-model="addForm.permissionOrder"
									clearable>
							</el-input>
117 118 119 120 121 122 123 124 125 126 127 128 129
						</el-form-item>
					</el-col>
					<el-col :span="8">
						<el-form-item label="设置权限上级" prop="parentId">
							<el-input v-model="addForm.parentId" auto-complete="off" placeholder="请输入或者选择适配权限"></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="8">
						<el-button type="info" size="mini" @click="drawer = true">设置权限上级</el-button>
					</el-col>
				</el-row>

朱兆平 authored
130
				<el-form-item label="是否目录" prop="ismenu">
shenhailong authored
131 132 133 134 135 136
					<el-switch
							v-model="addForm.ismenu"
							active-color="#13ce66"
							inactive-color="#ff4949"
							active-text="是"
							inactive-text="否"
137
					>
shenhailong authored
138
					</el-switch>
139
				</el-form-item>
朱兆平 authored
140 141 142 143 144 145 146 147 148 149
				<el-form-item label="是否隐藏" prop="hidden">
					<el-switch
							v-model="addForm.hidden"
							active-color="#13ce66"
							inactive-color="#ff4949"
							active-text="是"
							inactive-text="否"
					>
					</el-switch>
				</el-form-item>
150 151 152
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button @click.native="addFormVisible = false">取消</el-button>
153
				<el-button type="primary" @click.native="dialogStatus==='create'?addSubmit():editSubmit()" :loading="addLoading">提交</el-button>
154 155
			</div>
		</el-dialog>
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

		<el-drawer
				title="设置权限上级"
				:visible.sync="drawer"
				append-to-body
				withHeader>
			<el-row>
				<el-col :span="7" :offset="1">
					<span style="color:#E6A23C">不设置为顶级权限</span>
				</el-col>
				<el-col :span="8" >
					<el-button type="primary" @click.native="treeMerge(false)">合并节点</el-button>
				</el-col>
				<el-col :span="8">
					<el-button type="primary" @click.native="treeMerge(true)">展开节点</el-button>
				</el-col>




			</el-row>
			<el-tree :data="tableList" :props="treeDefaultProps"
					 @check="clickDeal"
					 :default-expand-all = "treeExpand"
					 show-checkbox
					 highlight-current
					 check-strictly
					 node-key="permissionId" ref="tree">
			</el-tree>
		</el-drawer>
186 187 188 189 190 191 192
	</section>
</template>

<script>
	import util from '../../common/js/util'
	//import NProgress from 'nprogress'
	import { getList, remove, batchRemove, edit, add } from '../../api/perm_api';
193
	import moment from 'moment'
194
	export default {
195
		name:'Perm',
196 197 198
		data() {
			return {
				filters: {
199
					name: ''
200
				},
201
				cascaderOptions:[],
202 203
				tableList: [],
				total: 0,
204 205
				pageNum: 1,
				pageSize: 500,
206 207
				listLoading: false,
				sels: [],//列表选中列
208 209 210
				treeDefaultProps: {
					children: 'children',
					label: 'name',
211
				},
212 213 214 215 216
				pannelProps: {
					children: 'children',
					label: 'name',
					value: 'path',
					checkStrictly: true,
朱兆平 authored
217
				},
218 219 220 221 222 223 224 225
				pannelUrlProps: {
					children: 'children',
					label: 'name',
					value: 'url',
					checkStrictly: true,
					emitPath: false
				},
				treeExpand: true,
226
				addFormVisible: false,//新增界面是否显示
227 228 229 230 231 232
				dialogMap: {
					update: '编辑',
					create: '新增',
				},
				dialogStatus: 'create',
				drawer: false,
233 234
				addLoading: false,
				addFormRules: {
235
					name: [
236 237
						{ required: true, message: '请输入权限名称', trigger: 'blur' }
					],
238 239 240 241 242
					path: [
						{ required: true, message: '请输入总路径', trigger: 'blur' }
					],
					url: [
						{ required: true, message: '请输入权限路径', trigger: 'blur' }
shenhailong authored
243
					],
244 245 246
					permissionOrder: [
						{ required: true, message: '请输入排序字段', trigger: 'blur' }
					]
247 248 249
				},
				//新增界面数据
				addForm: {
250 251 252 253
					permissionId:'',
					description: '',
					name: '',
					url: '',
shenhailong authored
254
					path: '',
255 256 257 258 259
					parentId: 0,
					ismenu: true,
					permissionOrder: '0',
					chidren: [],
					component: '',
朱兆平 authored
260 261 262
					method: '*',
					hidden: false,
					iconCls:''
263 264 265 266 267 268 269 270 271
				}

			}
		},
		methods: {
			//性别显示转换
			formatSex: function (row, column) {
				return row.sex == 1 ? '男' : row.sex == 0 ? '女' : '未知';
			},
272 273 274
			formatState: function (row, column) {
				return row.ismenu == true ? '是' : row.ismenu == false ? '否' : '未知';
			},
275 276 277 278 279 280 281
			handleCurrentChange(val) {
				this.pageNum = val;
				this.getTableList();
			},
			//获取列表
			getTableList() {
				let para = {
282 283 284
					pageNum: this.pageNum,
					pageSize: this.pageSize,
					name: this.filters.name
285 286 287
				};
				this.listLoading = true;
				//NProgress.start();
288
				getList(para).then((res) => {
289 290 291 292 293
					this.total = res.data.total;
					this.tableList = res.data.list;
					this.listLoading = false;
					//NProgress.done();
				}).catch((error) => {
294 295 296 297 298
					this.listLoading = false;
					if(null!= error.response && error.response!==undefined){
						let status= error.response.status;
						let msg = error.response.statusText;
						alert(status+msg);
299
					}else {
300
						alert(error);
301 302 303 304 305 306 307 308 309 310 311
					}
				});

			},
			//删除
			handleDel: function (index, row) {
				this.$confirm('确认删除该记录吗?', '提示', {
					type: 'warning'
				}).then(() => {
					this.listLoading = true;
					//NProgress.start();
shenhailong authored
312
					let para = { permissionId: row.permissionId };
313
					remove(para).then((res) => {
314 315 316 317 318 319
						this.listLoading = false;
						//NProgress.done();
						this.$message({
							message: '删除成功',
							type: 'success'
						});
shenhailong authored
320
						this.getTableList();
321
					}).catch((error) => {
322 323
						this.listLoading = false;
						alert(error);
324 325 326
					});
				}).catch();
			},
327
			/**
328
			 * 显示编辑界面
329 330 331
			 * @param index
			 * @param row 为这行的数据对象
			 */
332
			handleEdit: function (index, row) {
333 334 335
				this.addFormVisible = true;
				this.dialogStatus= 'update',
				this.addForm = Object.assign({}, row);
336 337 338 339
			},
			//显示新增界面,每次点开初始化数据
			handleAdd: function () {
				this.addFormVisible = true;
340
				this.dialogStatus= 'create',
341
				this.addForm = {
342 343 344 345 346 347 348 349
					description: '',
					name: '',
					url: '',
					path: '',
					parentId: 0,
					ismenu: '',
					permissionOrder:'0'
350 351 352 353
				};
			},
			//编辑
			editSubmit: function () {
354
				this.$refs.addForm.validate((valid) => {
355 356
					if (valid) {
						this.$confirm('确认提交吗?', '提示', {}).then(() => {
357
							this.addLoading = true;
358
							//NProgress.start();
359 360 361 362
							let para = Object.assign({}, this.addForm);
							para.creattime = moment(para.creattime).format('YYYY-MM-DD HH:mm:ss');
							this.addLoading = false;
							edit(para).then((res) => {
363 364 365 366 367 368

								//NProgress.done();
								this.$message({
									message: '提交成功',
									type: 'success'
								});
369 370
								this.$refs['addForm'].resetFields();
								this.addFormVisible = false;
shenhailong authored
371
								this.getTableList();
372 373 374 375 376 377 378 379 380 381 382 383 384 385
							}).catch(error => alert(error));
						});
					}
				});
			},
			//新增
			addSubmit: function () {
				this.$refs.addForm.validate((valid) => {
					if (valid) {
						this.$confirm('确认提交吗?', '提示', {}).then(() => {
							this.addLoading = true;
							//NProgress.start();
							let para = Object.assign({}, this.addForm);
							para.birth = (!para.birth || para.birth == '') ? '' : util.formatDate.format(new Date(para.birth), 'yyyy-MM-dd');
386
							add(para).then((res) => {
387 388 389 390 391 392 393 394
								this.addLoading = false;
								//NProgress.done();
								this.$message({
									message: '提交成功',
									type: 'success'
								});
								this.$refs['addForm'].resetFields();
								this.addFormVisible = false;
shenhailong authored
395
								this.getTableList();
396 397 398 399 400 401 402 403 404 405
							}).catch(error => alert(error));
						});
					}
				});
			},
			selsChange: function (sels) {
				this.sels = sels;
			},
			//批量删除
			batchRemove: function () {
406
				var ids = this.sels.map(item => item.permissionId);
407 408 409 410 411
				this.$confirm('确认删除选中记录吗?', '提示', {
					type: 'warning'
				}).then(() => {
					this.listLoading = true;
					//NProgress.start();
412 413 414 415 416 417
					// let para = { ids: ids };
					batchRemove(ids).then((response) => {
						let res = response.data;
						if (res.code !== '200') {
							return this.$message.error(res.msg);
						}
418 419 420 421 422
						//NProgress.done();
						this.$message({
							message: '删除成功',
							type: 'success'
						});
shenhailong authored
423
						this.getTableList();
424
					});
425 426 427 428
				}).catch((err) => {
					this.$message.error(err);
				}).finally(() => {
					this.listLoading = false;
429
				});
430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447
			},
			showDrawer: function(){
				this.drawer = true;
				this.$nextTick(() => {
					//反向适配
					this.$refs.tree.setCheckedKeys([this.addForm.parentId]);
				});
			},
			clickDeal: function (currentObj, treeStatus) {
				this.addForm.parentId = currentObj.permissionId;
				this.$refs.tree.setCheckedKeys([currentObj.permissionId]);
				// this.drawer = false;
			},
			treeMerge: function (expand) {
				this.treeExpand = expand;
				for(var i=0;i<this.$refs.tree.store._getAllNodes().length;i++){
					this.$refs.tree.store._getAllNodes()[i].expanded=this.treeExpand;
				}
朱兆平 authored
448 449
			},
			tableRowClassName({row, rowIndex}) {
450
				if (row.parentId === 0 || row.ismenu) {
朱兆平 authored
451 452 453 454 455
					return 'warning-row';
				} else {
					return 'success-row';
				}
				return '';
456 457 458 459
			}
		},
		mounted() {
			this.getTableList();
460
			// this.cascaderOptions = this.$router.options.routes;
461 462 463 464 465
		}
	}

</script>
466
<style rel="stylesheet/scss" lang="scss">
小范 authored
467
468 469 470 471 472 473 474 475
	.el-drawer.rtl {
		overflow: scroll
	}
	.el-row{
		.el-col {
			margin-right: 0px;
		}
	}
朱兆平 authored
476 477 478 479 480 481 482
	.el-table .warning-row {
		background: oldlace;
	}

	.el-table .success-row {
		background: #f0f9eb;
	}
483
484
小范 authored
485
</style>