审查视图

src/views/nav1/perm.vue 11.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>
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>

		<!--列表-->
shenhailong authored
19 20 21 22 23
		<el-table :data="tableList" highlight-current-row v-loading="listLoading" @selection-change="selsChange" style="width: 100%;"
				  row-key="permissionId"
				  border
				  :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
		>
24 25
			<el-table-column type="selection" width="55">
			</el-table-column>
shenhailong authored
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>
shenhailong authored
30
			<el-table-column prop="name" label="权限名称" min-width="150" sortable>
31
			</el-table-column>
shenhailong authored
32
			<el-table-column prop="description" label="描述" min-width="120" sortable>
33
			</el-table-column>
shenhailong authored
34
			<el-table-column prop="ismenu" label="是否目录" width="100" :formatter="formatState" sortable>
35
			</el-table-column>
shenhailong authored
36
			<el-table-column prop="url" label="访问路径" width="300" sortable>
37
			</el-table-column>
shenhailong authored
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
			</el-pagination>
		</el-col>

		<!--编辑界面-->
54
		<el-dialog title="编辑" :visible.sync="editFormVisible" :close-on-click-modal="false">
55 56
			<el-form :model="editForm" label-width="80px" :rules="editFormRules" ref="editForm">
				<el-form-item label="ID">
shenhailong authored
57
					<span>{{editForm.permissionId}}</span>
58
				</el-form-item>
shenhailong authored
59 60
				<el-form-item label="权限名称" prop="name">
					<el-input v-model="editForm.name" auto-complete="off" placeholder="请输入权限名称:例如:用户新增权限"></el-input>
61
				</el-form-item>
shenhailong authored
62
				<el-form-item label="权限描述" prop="description">
63 64
					<el-input v-model="editForm.description" auto-complete="off" placeholder="请输入权限描述:例如:用户管理员"></el-input>
				</el-form-item>
shenhailong authored
65 66 67 68 69 70 71 72 73 74 75 76
				<el-form-item label="权限总路径" prop="path">
					<el-input v-model="editForm.path" auto-complete="off" placeholder="请输入父目录ID:例如:123"></el-input>
				</el-form-item>
				<el-form-item label="权限路径" prop="url">
					<el-input v-model="editForm.url" auto-complete="off" placeholder="请输入权限描述:例如:/user/update"></el-input>
				</el-form-item>
				<el-form-item label="权限排序" prop="permissionOrder">
					<el-input v-model="editForm.permissionOrder" auto-complete="off" placeholder="请输入权限排序:例如:123"></el-input>
				</el-form-item>
				<el-form-item label="父目录ID" prop="parentId">
					<el-input v-model="editForm.parentId" auto-complete="off" placeholder="请输入父目录ID:例如:123"></el-input>
				</el-form-item>
77
				<el-form-item label="ismenu" prop="ismenu">
shenhailong authored
78 79 80 81 82 83 84 85 86
					<el-switch
							v-model="editForm.ismenu"
							active-color="#13ce66"
							inactive-color="#ff4949"
							active-text="是"
							inactive-text="否"
							active-value="1"
							inactive-value="0">
					</el-switch>
87 88 89 90 91 92 93 94 95
				</el-form-item>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button @click.native="editFormVisible = false">取消</el-button>
				<el-button type="primary" @click.native="editSubmit" :loading="editLoading">提交</el-button>
			</div>
		</el-dialog>

		<!--新增界面-->
96
		<el-dialog title="新增" :visible.sync="addFormVisible" :close-on-click-modal="false">
97
			<el-form :model="addForm" label-width="80px" :rules="addFormRules" ref="addForm">
shenhailong authored
98 99
				<el-form-item label="权限名称" prop="name">
					<el-input v-model="addForm.name" auto-complete="off" placeholder="请输入权限名称:例如:用户新增权限"></el-input>
100 101 102 103
				</el-form-item>
				<el-form-item label="权限描述" prop="description">
					<el-input v-model="addForm.description" auto-complete="off" placeholder="请输入权限描述:例如:用户管理员"></el-input>
				</el-form-item>
shenhailong authored
104 105 106
				<el-form-item label="权限总路径" prop="path">
					<el-input v-model="addForm.path" auto-complete="off" placeholder="请输入父目录ID:例如:123"></el-input>
				</el-form-item>
107 108 109
				<el-form-item label="权限路径" prop="url">
					<el-input v-model="addForm.url" auto-complete="off" placeholder="请输入权限描述:例如:/user/update"></el-input>
				</el-form-item>
shenhailong authored
110 111
				<el-form-item label="权限排序" prop="permissionOrder">
					<el-input v-model="addForm.permissionOrder" auto-complete="off" placeholder="请输入权限排序:例如:123"></el-input>
112 113 114 115
				</el-form-item>
				<el-form-item label="父目录ID" prop="parentId">
					<el-input v-model="addForm.parentId" auto-complete="off" placeholder="请输入父目录ID:例如:123"></el-input>
				</el-form-item>
116
				<el-form-item label="ismenu" prop="ismenu">
shenhailong authored
117 118 119 120 121 122 123 124 125
					<el-switch
							v-model="addForm.ismenu"
							active-color="#13ce66"
							inactive-color="#ff4949"
							active-text="是"
							inactive-text="否"
							active-value="1"
							inactive-value="0">
					</el-switch>
126 127 128 129 130 131 132 133 134 135 136 137 138 139
				</el-form-item>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button @click.native="addFormVisible = false">取消</el-button>
				<el-button type="primary" @click.native="addSubmit" :loading="addLoading">提交</el-button>
			</div>
		</el-dialog>
	</section>
</template>

<script>
	import util from '../../common/js/util'
	//import NProgress from 'nprogress'
	import { getList, remove, batchRemove, edit, add } from '../../api/perm_api';
shenhailong authored
140
	import moment from 'moment'
141 142 143 144
	export default {
		data() {
			return {
				filters: {
shenhailong authored
145
					name: ''
146 147 148
				},
				tableList: [],
				total: 0,
shenhailong authored
149 150
				pageNum: 1,
				pageSize: 100,
151 152 153 154 155 156
				listLoading: false,
				sels: [],//列表选中列
				//编辑界面是否显示
				editFormVisible: false,
				editLoading: false,
				editFormRules: {
shenhailong authored
157
					roleName: [
158 159 160 161 162
						{ required: true, message: '请输入权限名称', trigger: 'blur' }
					]
				},
				//编辑界面数据
				editForm: {
shenhailong authored
163 164 165 166 167 168 169 170
					permissionId:'',
					description: '',
					name: '',
					url: '',
					path: '',
					parentId: '',
					ismenu: '',
					permissionOrder:''
171 172 173 174 175
				},

				addFormVisible: false,//新增界面是否显示
				addLoading: false,
				addFormRules: {
shenhailong authored
176
					name: [
177 178
						{ required: true, message: '请输入权限名称', trigger: 'blur' }
					],
shenhailong authored
179 180 181 182 183 184 185 186
					description: [
						{ required: true, message: '请输入权限描述', trigger: 'blur' }
					],
					paht: [
						{ required: true, message: '请输入总路径', trigger: 'blur' }
					],
					url: [
						{ required: true, message: '请输入权限路径', trigger: 'blur' }
shenhailong authored
187
					],
shenhailong authored
188 189 190 191 192 193
					permissionOrder: [
						{ required: true, message: '请输入排序字段', trigger: 'blur' }
					],
					parentId: [
						{ required: true, message: '请输入父类ID', trigger: 'blur' }
					]
194 195 196
				},
				//新增界面数据
				addForm: {
shenhailong authored
197 198 199
					description: '',
					name: '',
					url: '',
shenhailong authored
200
					path: '',
shenhailong authored
201
					parentId: '',
shenhailong authored
202 203
					ismenu: '',
					permissionOrder:''
shenhailong authored
204
205 206 207 208 209 210 211 212 213
				}

			}
		},
		methods: {
			//性别显示转换
			formatSex: function (row, column) {
				return row.sex == 1 ? '男' : row.sex == 0 ? '女' : '未知';
			},
shenhailong authored
214 215 216
			formatState: function (row, column) {
				return row.ismenu == true ? '是' : row.ismenu == false ? '否' : '未知';
			},
217 218 219 220 221 222 223
			handleCurrentChange(val) {
				this.pageNum = val;
				this.getTableList();
			},
			//获取列表
			getTableList() {
				let para = {
shenhailong authored
224 225 226
					pageNum: this.pageNum,
					pageSize: this.pageSize,
					name: this.filters.name
227 228 229
				};
				this.listLoading = true;
				//NProgress.start();
shenhailong authored
230
				getList(para).then((res) => {
231 232 233 234 235 236
					this.total = res.data.total;
					this.tableList = res.data.list;
					this.listLoading = false;
					//NProgress.done();
				}).catch((error) => {
shenhailong authored
237 238 239 240 241
					this.listLoading = false;
					if(null!= error.response && error.response!==undefined){
						let status= error.response.status;
						let msg = error.response.statusText;
						alert(status+msg);
242
					}else {
shenhailong authored
243
						alert(error);
244 245 246 247 248 249 250 251 252 253 254 255 256 257
					}



				});

			},
			//删除
			handleDel: function (index, row) {
				this.$confirm('确认删除该记录吗?', '提示', {
					type: 'warning'
				}).then(() => {
					this.listLoading = true;
					//NProgress.start();
shenhailong authored
258
					let para = { permissionId: row.permissionId };
shenhailong authored
259
					remove(para).then((res) => {
260 261 262 263 264 265
						this.listLoading = false;
						//NProgress.done();
						this.$message({
							message: '删除成功',
							type: 'success'
						});
shenhailong authored
266
						this.getTableList();
267
					}).catch((error) => {
shenhailong authored
268 269
						this.listLoading = false;
						alert(error);
270 271 272
					});
				}).catch();
			},
shenhailong authored
273
			/**
274
			 * 显示编辑界面
shenhailong authored
275 276 277
			 * @param index
			 * @param row 为这行的数据对象
			 */
278 279 280 281 282 283 284 285
			handleEdit: function (index, row) {
				this.editFormVisible = true;
				this.editForm = Object.assign({}, row);
			},
			//显示新增界面,每次点开初始化数据
			handleAdd: function () {
				this.addFormVisible = true;
				this.addForm = {
shenhailong authored
286 287 288 289 290 291 292 293
					username: '',
					password: '',
					sex: 1,
					address: '',
					realname: '',
					email:	'',
					mobilephone: '',
					age: 1
294 295 296 297 298 299 300 301 302 303
				};
			},
			//编辑
			editSubmit: function () {
				this.$refs.editForm.validate((valid) => {
					if (valid) {
						this.$confirm('确认提交吗?', '提示', {}).then(() => {
							this.editLoading = true;
							//NProgress.start();
							let para = Object.assign({}, this.editForm);
shenhailong authored
304 305 306
							para.creattime = moment(para.creattime).format('YYYY-MM-DD HH:mm:ss');
							this.editLoading = false;
							edit(para).then((res) => {
307 308 309 310 311 312 313 314

								//NProgress.done();
								this.$message({
									message: '提交成功',
									type: 'success'
								});
								this.$refs['editForm'].resetFields();
								this.editFormVisible = false;
shenhailong authored
315
								this.getTableList();
316 317 318 319 320 321 322 323 324 325 326 327 328 329
							}).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');
shenhailong authored
330
							add(para).then((res) => {
331 332 333 334 335 336 337 338
								this.addLoading = false;
								//NProgress.done();
								this.$message({
									message: '提交成功',
									type: 'success'
								});
								this.$refs['addForm'].resetFields();
								this.addFormVisible = false;
shenhailong authored
339
								this.getTableList();
340 341 342 343 344 345 346 347 348 349
							}).catch(error => alert(error));
						});
					}
				});
			},
			selsChange: function (sels) {
				this.sels = sels;
			},
			//批量删除
			batchRemove: function () {
shenhailong authored
350
				var ids = this.sels.map(item => item.permissionId).toString();
351 352 353 354 355 356
				this.$confirm('确认删除选中记录吗?', '提示', {
					type: 'warning'
				}).then(() => {
					this.listLoading = true;
					//NProgress.start();
					let para = { ids: ids };
shenhailong authored
357
					batchRemove(para).then((res) => {
358 359 360 361 362 363
						this.listLoading = false;
						//NProgress.done();
						this.$message({
							message: '删除成功',
							type: 'success'
						});
shenhailong authored
364
						this.getTableList();
365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380
					});
				}).catch(() => {

				});
			}
		},
		mounted() {
			this.getTableList();
		}
	}

</script>

<style scoped>

</style>