通过Element开发基础增删改查页面——Vue项目实战(三)

一、Tab标签页设置

tab标签引入

在这里插入图片描述

<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>

在这里插入图片描述


注:能力有限,还请谅解,争取早日能够写出有质量的文章!

我是皮蛋布丁,一位爱吃皮蛋的热爱运动的废铁程序猿。

在这里插入图片描述

感谢各位大佬光临寒舍~

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值