<div>
<el-tabs v-model="activeName" type="card">
<el-tab-pane label="部门管理" name="depManager"><DepManager></DepManager></el-tab-pane>
<el-tab-pane label="职位管理" name="posManager"><PosManager></PosManager></el-tab-pane>
<el-tab-pane label="角色管理" name="roleManager"><RoleManager></RoleManager></el-tab-pane>
</el-tabs>
</div>
<template>
<div>
<div>
<el-input
size="small"
class="addPosInput"
placeholder="添加职位... "
prefix-icon="el-icon-plus"
v-model="pos.name">
</el-input>
<el-button icon="el-icon-plus" size="small" type="primary">添加</el-button>
</div>
<div class="posManagerMain">
<el-table
:data="positions"
border
stripe
size="small"
style="width: 70%">
<el-table-column
prop="id"
label="编号"
width="55">
</el-table-column>
<el-table-column
prop="name"
label="职位名称"
width="120">
</el-table-column>
<el-table-column
prop="createDate"
label="创建时间">
</el-table-column>
</el-table>
</div>
</div>
</template>
<script>
export default {
name: "PosManager",
data() {
return {
pos : {
name : ""
},
positions: []
}
}
}
</script>
<style scoped>
</style>
数据结构:
{
"status": 200,
"msg": null,
"obj": [{
createDate: "2022-06-25"
createDateFormate: "2022-06-25 17:45:20"
createTime: "2022-06-25 17:45:20"
createUserId: 1
createUserName: "系统管理员"
deleted: 0
id: 1
name: "技术总监"
updateDate: "2022-06-25"
updateDateFormate: "2022-06-25 17:45:25"
updateTime: "2022-06-25 17:45:25"
updateUserId: 1
updateUserName: "系统管理员"
}]
}
前端代码:
<template>
<div>
<div>
<el-input
size="small"
class="addPosInput"
placeholder="添加职位... "
prefix-icon="el-icon-plus"
@keydown.enter.native="addPosition"
v-model="pos.name">
</el-input>
<el-button icon="el-icon-plus" size="small" type="primary" @click="addPosition">添加</el-button>
<el-button @click="deleteMany" type="danger" size="small" style="margin-top: 8px;" :disabled="multipleSelection.length==0">批量删除</el-button>
</div>
<div class="posManagerMain">
<!-- 多选框的点击事件 @selection-change="handleSelectionChange-->
<el-table
:data="positions"
border
stripe
@selection-change="handleSelectionChange"
size="small"
style="width: 70%">
<!-- 多选框-->
<el-table-column
type="selection"
width="55">
</el-table-column>
<el-table-column
prop="id"
label="编号"
width="55">
</el-table-column>
<el-table-column
prop="name"
label="职位名称"
width="120">
</el-table-column>
<el-table-column
prop="createUserName"
label="创建人">
</el-table-column>
<el-table-column
prop="createTime"
label="创建时间">
</el-table-column>
<el-table-column
prop="updateUserName"
label="更新人">
</el-table-column>
<el-table-column
prop="updateTime"
label="更新时间">
</el-table-column>
<el-table-column label="操作">
<template slot-scope="scope">
<el-button
size="mini"
@click="showEditView(scope.$index, scope.row)">编辑</el-button>
<el-button
size="mini"
type="danger"
@click="handleDelete(scope.$index, scope.row)">删除</el-button>
</template>
</el-table-column>
</el-table>
</div>
<!-- 对话框-->
<el-dialog
title="修改职位"
:visible.sync="dialogVisible"
width="30%">
<div>
<el-tag>职位名称</el-tag>
<el-input class="updatePosInput" size="small" v-model="updatePos.name"></el-input>
</div>
<span slot="footer" class="dialog-footer">
<el-button size="small" @click="dialogVisible = false">取 消</el-button>
<el-button size="small" type="primary" @click="doUpdate">确 定</el-button>
</span>
</el-dialog>
</div>
</template>
<script>
export default {
name: "PosManager",
data() {
return {
pos : {
name : ""
},
dialogVisible:false,
updatePos: {
name:''
},
multipleSelection: [],
positions: []
}
},
//数据初始化
mounted() {
this.initPositions();
},
methods: {
deleteMany() {
this.$confirm('此操作将永久删除【' + this.multipleSelection.length + '】条记录, 是否继续?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
let ids = '?';
this.multipleSelection.forEach(item => {
ids += 'ids=' + item.id + '&';
})
this.deleteRequest("/system/basic/pos/" + ids).then( resp => {
if (resp) {
this.initPositions();
}
});
}).catch(() => {
this.$message({
type: 'info',
message: '已取消删除'
});
});
},
handleSelectionChange(val) {
this.multipleSelection = val;
console.log(val);
},
showEditView(index,data) {
// this.updatePos = data;
//拷贝属性(防止点击【取消】按钮无法返回原来数值)
Object.assign(this.updatePos,data);
this.dialogVisible = true;
},
doUpdate() {
this.putRequest("/system/basic/pos/",this.updatePos).then(resp => {
if (resp) {
//刷新数据
this.initPositions();
this.updatePos.name = '';
//隐藏对话框
this.dialogVisible = false;
}
});
},
handleDelete(index, data) {
this.$confirm('此操作将永久删除【' + data.name + '】职位, 是否继续?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
this.deleteRequest("/system/basic/pos/" + data.id).then(resp => {
if (resp) {
this.initPositions();
}
})
}).catch(() => {
this.$message({
type: 'info',
message: '已取消删除'
});
});
},
addPosition() {
if (this.pos.name) {
this.postRequest("system/basic/pos/", this.pos).then(resp => {
if (resp) {
//刷新数据
this.initPositions();
//清空数据
this.pos.name = '';
}
})
} else {
this.$message.error('职位名称不可以为空!');
}
},
initPositions() {
this.getRequest("/system/basic/pos/").then(resp => {
if (resp) {
this.positions = resp.obj;
}
})
}
}
}
</script>
<style scoped>
.addPosInput {
width: 300px;
margin-right: 8px;
}
.posManagerMain {
margin-top: 10px;
}
.updatePosInput {
width: 200px;
margin-left: 8px;
}
</style>
我是皮蛋布丁,一位爱吃皮蛋的热爱运动的废铁程序猿。