审查视图

src/views/nav1/perm.vue 12.3 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>
shenhailong authored
7
					<el-input v-model="filters.name" placeholder="权限名称"></el-input>
8 9
				</el-form-item>
				<el-form-item>
shenhailong authored
10
					<el-button type="primary" v-on:click="getTableList()">查询</el-button>
11 12 13 14 15 16 17 18
				</el-form-item>
				<el-form-item>
					<el-button type="primary" @click="handleAdd">新增</el-button>
				</el-form-item>
			</el-form>
		</el-col>

		<!--列表-->
19
		<el-table :data="tableList" highlight-current-row v-loading="listLoading" @selection-change="selsChange" style="width: 100%;"
20 21 22
				  row-key="permissionId"
				  border
				  :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
23
		>
24 25
			<el-table-column type="selection" width="55">
			</el-table-column>
26 27 28
			<!--<el-table-column type="index" width="60">-->
			<!--</el-table-column>-->
			<el-table-column prop="permissionId" label="ID" width="130" sortable>
29
			</el-table-column>
30
			<el-table-column prop="name" label="权限名称" min-width="150" sortable>
31
			</el-table-column>
32
			<el-table-column prop="description" label="描述" min-width="120" sortable>
33
			</el-table-column>
34
			<el-table-column prop="ismenu" label="是否目录" width="100" :formatter="formatState" sortable>
35
			</el-table-column>
36
			<el-table-column prop="url" label="访问路径" width="300" sortable>
37
			</el-table-column>
38
			<el-table-column label="操作" min-width="100">
39 40 41 42 43 44 45 46 47 48
				<template slot-scope="scope">
					<el-button size="small" @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
					<el-button type="danger" size="small" @click="handleDel(scope.$index, scope.row)">删除</el-button>
				</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
49
			<el-pagination layout="total, prev, pager, next" @current-change="handleCurrentChange" :page-size="pageSize" :total="total" style="float:right;">
50 51 52 53 54
			</el-pagination>
		</el-col>


		<!--新增界面-->
55 56 57 58 59
		<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
60
				</el-form-item>
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
				<el-row :gutter="20">
					<el-col :span="12">
						<el-form-item label="权限名称" prop="name">
							<el-input v-model="addForm.name" auto-complete="off" placeholder="请输入权限名称:例如:用户新增权限"></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="权限描述" prop="description">
							<el-input v-model="addForm.description" auto-complete="off" placeholder="请输入权限描述:例如:用户管理员"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row :gutter="20">
					<el-col>
						<el-form-item label="权限总路径" prop="path">
							<el-input v-model="addForm.path" auto-complete="off" placeholder="设置为前端router的path值"></el-input>
							<el-cascader-panel
									v-model="addForm.path"
									:options="cascaderOptions"
									:props="pannelProps"
							></el-cascader-panel>
						</el-form-item>
					</el-col>
				</el-row>
				<el-form-item label="具体访问路径" prop="url">
					<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
92
				</el-form-item>
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
				<el-row :gutter="20">
					<el-col :span="8">
						<el-form-item label="权限排序" prop="permissionOrder">
							<el-input v-model="addForm.permissionOrder" auto-complete="off" placeholder="请输入权限排序:例如:123"></el-input>
						</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>


				<el-form-item label="是否是目录" prop="ismenu">
shenhailong authored
111 112 113 114 115 116
					<el-switch
							v-model="addForm.ismenu"
							active-color="#13ce66"
							inactive-color="#ff4949"
							active-text="是"
							inactive-text="否"
117
					>
shenhailong authored
118
					</el-switch>
119 120 121 122
				</el-form-item>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button @click.native="addFormVisible = false">取消</el-button>
123
				<el-button type="primary" @click.native="dialogStatus==='create'?addSubmit():editSubmit()" :loading="addLoading">提交</el-button>
124 125
			</div>
		</el-dialog>
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

		<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>
156 157 158 159 160 161 162
	</section>
</template>

<script>
	import util from '../../common/js/util'
	//import NProgress from 'nprogress'
	import { getList, remove, batchRemove, edit, add } from '../../api/perm_api';
163
	import moment from 'moment'
164 165 166 167
	export default {
		data() {
			return {
				filters: {
168
					name: ''
169
				},
170
				cascaderOptions:[],
171 172
				tableList: [],
				total: 0,
173 174
				pageNum: 1,
				pageSize: 500,
175 176
				listLoading: false,
				sels: [],//列表选中列
177 178 179
				treeDefaultProps: {
					children: 'children',
					label: 'name',
180
				},
181 182 183 184 185
				pannelProps: {
					children: 'children',
					label: 'name',
					value: 'path',
					checkStrictly: true,
朱兆平 authored
186
				},
187 188 189 190 191 192 193 194
				pannelUrlProps: {
					children: 'children',
					label: 'name',
					value: 'url',
					checkStrictly: true,
					emitPath: false
				},
				treeExpand: true,
195
				addFormVisible: false,//新增界面是否显示
196 197 198 199 200 201
				dialogMap: {
					update: '编辑',
					create: '新增',
				},
				dialogStatus: 'create',
				drawer: false,
202 203
				addLoading: false,
				addFormRules: {
204
					name: [
205 206
						{ required: true, message: '请输入权限名称', trigger: 'blur' }
					],
207 208 209 210 211
					path: [
						{ required: true, message: '请输入总路径', trigger: 'blur' }
					],
					url: [
						{ required: true, message: '请输入权限路径', trigger: 'blur' }
shenhailong authored
212
					],
213 214 215
					permissionOrder: [
						{ required: true, message: '请输入排序字段', trigger: 'blur' }
					]
216 217 218
				},
				//新增界面数据
				addForm: {
219 220 221 222
					permissionId:'',
					description: '',
					name: '',
					url: '',
shenhailong authored
223
					path: '',
224 225 226 227 228 229
					parentId: 0,
					ismenu: true,
					permissionOrder: '0',
					chidren: [],
					component: '',
					method: ''
230 231 232 233 234 235 236 237 238
				}

			}
		},
		methods: {
			//性别显示转换
			formatSex: function (row, column) {
				return row.sex == 1 ? '男' : row.sex == 0 ? '女' : '未知';
			},
239 240 241
			formatState: function (row, column) {
				return row.ismenu == true ? '是' : row.ismenu == false ? '否' : '未知';
			},
242 243 244 245 246 247 248
			handleCurrentChange(val) {
				this.pageNum = val;
				this.getTableList();
			},
			//获取列表
			getTableList() {
				let para = {
249 250 251
					pageNum: this.pageNum,
					pageSize: this.pageSize,
					name: this.filters.name
252 253 254
				};
				this.listLoading = true;
				//NProgress.start();
255
				getList(para).then((res) => {
256 257 258 259 260
					this.total = res.data.total;
					this.tableList = res.data.list;
					this.listLoading = false;
					//NProgress.done();
				}).catch((error) => {
261 262 263 264 265
					this.listLoading = false;
					if(null!= error.response && error.response!==undefined){
						let status= error.response.status;
						let msg = error.response.statusText;
						alert(status+msg);
266
					}else {
267
						alert(error);
268 269 270 271 272 273 274 275 276 277 278
					}
				});

			},
			//删除
			handleDel: function (index, row) {
				this.$confirm('确认删除该记录吗?', '提示', {
					type: 'warning'
				}).then(() => {
					this.listLoading = true;
					//NProgress.start();
shenhailong authored
279
					let para = { permissionId: row.permissionId };
280
					remove(para).then((res) => {
281 282 283 284 285 286
						this.listLoading = false;
						//NProgress.done();
						this.$message({
							message: '删除成功',
							type: 'success'
						});
shenhailong authored
287
						this.getTableList();
288
					}).catch((error) => {
289 290
						this.listLoading = false;
						alert(error);
291 292 293
					});
				}).catch();
			},
294
			/**
295
			 * 显示编辑界面
296 297 298
			 * @param index
			 * @param row 为这行的数据对象
			 */
299
			handleEdit: function (index, row) {
300 301 302
				this.addFormVisible = true;
				this.dialogStatus= 'update',
				this.addForm = Object.assign({}, row);
303 304 305 306
			},
			//显示新增界面,每次点开初始化数据
			handleAdd: function () {
				this.addFormVisible = true;
307
				this.dialogStatus= 'create',
308
				this.addForm = {
309 310 311 312 313 314 315 316
					description: '',
					name: '',
					url: '',
					path: '',
					parentId: 0,
					ismenu: '',
					permissionOrder:'0'
317 318 319 320
				};
			},
			//编辑
			editSubmit: function () {
321
				this.$refs.addForm.validate((valid) => {
322 323
					if (valid) {
						this.$confirm('确认提交吗?', '提示', {}).then(() => {
324
							this.addLoading = true;
325
							//NProgress.start();
326 327 328 329
							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) => {
330 331 332 333 334 335

								//NProgress.done();
								this.$message({
									message: '提交成功',
									type: 'success'
								});
336 337
								this.$refs['addForm'].resetFields();
								this.addFormVisible = false;
shenhailong authored
338
								this.getTableList();
339 340 341 342 343 344 345 346 347 348 349 350 351 352
							}).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');
353
							add(para).then((res) => {
354 355 356 357 358 359 360 361
								this.addLoading = false;
								//NProgress.done();
								this.$message({
									message: '提交成功',
									type: 'success'
								});
								this.$refs['addForm'].resetFields();
								this.addFormVisible = false;
shenhailong authored
362
								this.getTableList();
363 364 365 366 367 368 369 370 371 372
							}).catch(error => alert(error));
						});
					}
				});
			},
			selsChange: function (sels) {
				this.sels = sels;
			},
			//批量删除
			batchRemove: function () {
shenhailong authored
373
				var ids = this.sels.map(item => item.permissionId).toString();
374 375 376 377 378 379
				this.$confirm('确认删除选中记录吗?', '提示', {
					type: 'warning'
				}).then(() => {
					this.listLoading = true;
					//NProgress.start();
					let para = { ids: ids };
380
					batchRemove(para).then((res) => {
381 382 383 384 385 386
						this.listLoading = false;
						//NProgress.done();
						this.$message({
							message: '删除成功',
							type: 'success'
						});
shenhailong authored
387
						this.getTableList();
388 389 390 391
					});
				}).catch(() => {

				});
392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409
			},
			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;
				}
410 411 412 413
			}
		},
		mounted() {
			this.getTableList();
414
			this.cascaderOptions = this.$router.options.routes;
415 416 417 418 419
		}
	}

</script>
420 421 422 423 424 425 426 427 428 429
<style rel="stylesheet/scss" lang="scss">
	.el-drawer.rtl {
		overflow: scroll
	}
	.el-row{
		.el-col {
			margin-right: 0px;
		}
	}
430 431

</style>