审查视图

src/views/nav1/perm.vue 13.8 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
							<el-input-number v-model="addForm.permissionOrder"
											 auto-complete="off"
											 controls-position="right"
											 placeholder="请输入权限排序:例如:123"></el-input-number>
116 117 118 119 120 121 122 123 124 125 126 127 128
						</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
129
				<el-form-item label="是否目录" prop="ismenu">
shenhailong authored
130 131 132 133 134 135
					<el-switch
							v-model="addForm.ismenu"
							active-color="#13ce66"
							inactive-color="#ff4949"
							active-text="是"
							inactive-text="否"
136
					>
shenhailong authored
137
					</el-switch>
138
				</el-form-item>
朱兆平 authored
139 140 141 142 143 144 145 146 147 148
				<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>
149 150 151
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button @click.native="addFormVisible = false">取消</el-button>
152
				<el-button type="primary" @click.native="dialogStatus==='create'?addSubmit():editSubmit()" :loading="addLoading">提交</el-button>
153 154
			</div>
		</el-dialog>
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

		<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>
185 186 187 188 189 190 191
	</section>
</template>

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

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

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

								//NProgress.done();
								this.$message({
									message: '提交成功',
									type: 'success'
								});
368 369
								this.$refs['addForm'].resetFields();
								this.addFormVisible = false;
shenhailong authored
370
								this.getTableList();
371 372 373 374 375 376 377 378 379 380 381 382 383 384
							}).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');
385
							add(para).then((res) => {
386 387 388 389 390 391 392 393
								this.addLoading = false;
								//NProgress.done();
								this.$message({
									message: '提交成功',
									type: 'success'
								});
								this.$refs['addForm'].resetFields();
								this.addFormVisible = false;
shenhailong authored
394
								this.getTableList();
395 396 397 398 399 400 401 402 403 404
							}).catch(error => alert(error));
						});
					}
				});
			},
			selsChange: function (sels) {
				this.sels = sels;
			},
			//批量删除
			batchRemove: function () {
shenhailong authored
405
				var ids = this.sels.map(item => item.permissionId).toString();
406 407 408 409 410 411
				this.$confirm('确认删除选中记录吗?', '提示', {
					type: 'warning'
				}).then(() => {
					this.listLoading = true;
					//NProgress.start();
					let para = { ids: ids };
412
					batchRemove(para).then((res) => {
413 414 415 416 417 418
						this.listLoading = false;
						//NProgress.done();
						this.$message({
							message: '删除成功',
							type: 'success'
						});
shenhailong authored
419
						this.getTableList();
420 421 422 423
					});
				}).catch(() => {

				});
424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441
			},
			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
442 443
			},
			tableRowClassName({row, rowIndex}) {
444
				if (row.parentId === 0 || row.ismenu) {
朱兆平 authored
445 446 447 448 449
					return 'warning-row';
				} else {
					return 'success-row';
				}
				return '';
450 451 452 453
			}
		},
		mounted() {
			this.getTableList();
454
			// this.cascaderOptions = this.$router.options.routes;
455 456 457 458 459
		}
	}

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

	.el-table .success-row {
		background: #f0f9eb;
	}
477
478
小范 authored
479
</style>