【前端代码】数据查询和展示,使用到了分页查询和一些自定义接口

前端页面

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="js/axios-0.18.0.js"></script>
    <script src="js/vue.js"></script>
    <script src="element-ui/lib/index.js"></script>
    <link rel="stylesheet" href="css/msg.css">
    <link rel="stylesheet" href="element-ui/lib/theme-chalk/index.css">
</head>
<body>
<div id="app">
    <!--表单-->
    <el-form :inline="true" :model="selectbrand" class="demo-form-inline">
        <el-form-item label="当前状态">
            <el-select v-model="selectbrand.status" placeholder="当前状态">
                <el-option label="启用" value="1"></el-option>
                <el-option label="禁用" value="0"></el-option>
            </el-select>
        </el-form-item>
        <el-form-item label="企业名称">
            <el-input v-model="selectbrand.companyName" placeholder="企业名称"></el-input>
        </el-form-item>
        <el-form-item label="品牌名称">
            <el-input v-model="selectbrand.brandName" placeholder="品牌名称"></el-input>
        </el-form-item>
        <el-form-item>
            <el-button type="primary" @click="selectBrand">查询</el-button>
        </el-form-item>
    </el-form>
    <!--按钮-->
    <el-row>
        <el-button type="danger" plain @click="deleteByIds">批量删除</el-button>
        <el-button type="primary" plain @click="dialogVisible = true">新增</el-button>
    </el-row>
    <!--添加数据对话框表单-->
    <el-dialog
            title="编辑品牌"
            :visible.sync="dialogVisible"
            width="30%">
        <el-form ref="form" :model="addbrand" label-width="80px">
            <el-form-item label="品牌名称">
                <el-input v-model="addbrand.brandName"></el-input>
            </el-form-item>

            <el-form-item label="企业名称">
                <el-input v-model="addbrand.companyName"></el-input>
            </el-form-item>

            <el-form-item label="排序">
                <el-input v-model="addbrand.ordered"></el-input>
            </el-form-item>

            <el-form-item label="备注">
                <el-input type="textarea" v-model="addbrand.description"></el-input>
            </el-form-item>

            <el-form-item label="状态">
                <el-switch v-model="addbrand.status"
                           active-value="1"
                           inactive-value="0"
                ></el-switch>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="addBrand">提交</el-button>
                <el-button @click="dialogVisible = false">取消</el-button>
            </el-form-item>
        </el-form>
    </el-dialog>
    <!--修改数据表单-->
    <el-dialog
            title="修改品牌"
            :visible.sync="dialog"
            width="30%">
        <el-form ref="form" :model="upbrand" label-width="80px">
            <el-form-item label="品牌名称">
                <el-input v-model="upbrand.brandName"></el-input>
            </el-form-item>

            <el-form-item label="企业名称">
                <el-input v-model="upbrand.companyName"></el-input>
            </el-form-item>

            <el-form-item label="排序">
                <el-input v-model="upbrand.ordered"></el-input>
            </el-form-item>

            <el-form-item label="备注">
                <el-input type="textarea" v-model="upbrand.description"></el-input>
            </el-form-item>

            <el-form-item label="状态">
                <el-switch v-model="upbrand.status"
                           active-value="1"
                           inactive-value="0"
                ></el-switch>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="upBrand">提交</el-button>
                <el-button @click="dialogVisible2 = false">取消</el-button>
            </el-form-item>
        </el-form>
    </el-dialog>
    <!--显示表格-->
    <el-table
            :data="tableData"
            style="width: 100%"
            :row-class-name="tableRowClassName"
            @selection-change="handleSelectionChange"
    >
        <el-table-column
                type="selection"
                align="center">
        </el-table-column>
        <el-table-column
                type="index"
                align="center"
        >
        </el-table-column>
        <el-table-column
                prop="brandName"
                label="品牌名称"
                align="center"
        >
        </el-table-column>
        <el-table-column
                prop="companyName"
                label="企业名称"
                align="center"
        >
        </el-table-column>
        <el-table-column
                prop="ordered"
                label="排序"
                align="center">
        </el-table-column>
        <el-table-column
                prop="statusStr"
                label="当前状态"
                align="center">
        </el-table-column>
        <el-table-column
                label="操作"
                align="center">
            <template slot-scope="scope">
                <el-button type="primary" icon="el-icon-edit" circle @click="updateBrand(scope.row)"></el-button>
                <el-button type="danger" icon="el-icon-delete" circle @click="deleteBrand(scope.row.id)"></el-button>
            </template>
        </el-table-column>
    </el-table>
    <!--分页工具条-->
    <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="currentPage"
            :page-sizes="[5, 10, 15, 20]"
            :page-size="1"
            layout="total, sizes, prev, pager, next, jumper"
            :total="totalCount">
    </el-pagination>
</div>

<script>

    new Vue({
        el: "#app",

        data() {
            return {
                // 添加数据对话框是否展示的标记
                dialogVisible: false,
                //修改数据对话框是否展示的标记
                dialog: false,
                // 品牌模型数据
                brand: {
                    status: '',
                    brandName: '',
                    companyName: '',
                    id: "",
                    ordered: "",
                    description: ""
                },

                //回显数据模型和修改数据模型
                upbrand: {
                    status: '',
                    brandName: '',
                    companyName: '',
                    id: "",
                    ordered: "",
                    description: ""
                },
                // 表格数据
                tableData: [],
                // 复选框选中数据集合
                multipleSelection: [],
                //id集合
                selectedIds: [],
                addbrand: {
                    status: '',
                    brandName: '',
                    companyName: '',
                    ordered: "",
                    description: ""
                },
                selectbrand: {
                    status: '',
                    brandName: '',
                    companyName: '',
                },
                //当前页码
                currentPage:1,
                //每页显示的条数
                pageSize:5,
                //总条数
                totalCount:""

            }
        },
        methods: {
            tableRowClassName({row, rowIndex}) {
                if (rowIndex === 1) {
                    return 'warning-row';
                } else if (rowIndex === 3) {
                    return 'success-row';
                }
                return '';
            },
            //查询所有
            selectAll() {
                var _this = this
                axios({
                    method: "get",
                    url: "http://localhost:8080/element_test_demo/brand/selectAll?currentPage="+_this.currentPage+"&pageSize="+_this.pageSize,

                }).then(function (resp) {
                    _this.tableData = resp.data.rows;
                    _this.totalCount = resp.data.totalCount
                });
            },
            // 复选框选中后执行的方法
            handleSelectionChange(val) {
                this.multipleSelection = val

            },
            // 查询方法,调用post方法,但是在请求路径中也有附带参数
            selectBrand() {
                axios.post("http://localhost:8080/element_test_demo/brand/selectBrand?currentPage="+this.currentPage+"&pageSize="+this.pageSize,this.selectbrand).then((resp)=>{
                    this.tableData = resp.data.rows;
                    this.totalCount = resp.data.totalCount
                })
            },
            // 添加数据
            addBrand() {
                var _this = this
                axios({
                    method: "post",
                    url: "http://localhost:8080/element_test_demo/brand/addBrand",
                    data: _this.addbrand
                }).then(function (resp) {
                    if (resp.data == "success") {
                        _this.dialogVisible = false;
                        _this.selectAll()
                        // 弹出消息提示
                        _this.$message({
                            message: '恭喜你,添加成功',
                            type: 'success'
                        });
                    }
                });
            },
            //分页
            handleSizeChange(val) {
                //获取每页显示的条数
                this.pageSize=val;
                this.selectAll();

            },
            handleCurrentChange(val) {
                //获取当前页面
                this.currentPage=val;
                this.selectAll();
            },
            //删除
            deleteBrand(id) {
                //弹出提示框,判断是否删除
                this.$confirm('此操作将永久删除数据, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    //如果确认则删除
                    var _this = this;
                    axios({
                        method: "post",
                        url: "http://localhost:8080/element_test_demo/brand/deleteBrand",
                        data: id
                    }).then(function (resp) {
                        if (resp.data == "success") {
                            _this.selectAll();
                            _this.$message({
                                message: '恭喜你,删除成功',
                                type: 'success'
                            });
                        }
                    });
                }).catch(() => {
                    //如果取消则取消删除
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    });
                });

            },
            //批量删除
            deleteByIds() {
                this.$confirm('此操作将永久删除数据, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    for (let i = 0; i < this.multipleSelection.length; i++) {
                        let selectionElement = this.multipleSelection[i];
                        this.selectedIds[i] = selectionElement.id;
                    }
                    var _this = this;
                    axios({
                        method: "post",
                        url: "http://localhost:8080/element_test_demo/brand/deleteByIds",
                        data: _this.selectedIds
                    }).then(function (resp) {
                        if (resp.data == "success") {
                            _this.selectAll();
                            _this.$message({
                                type: 'success',
                                message: '删除成功!'
                            });
                        }
                    });
                }).catch(() => {
                    _this.$message({
                        type: 'info',
                        message: '已取消删除'
                    });
                });
            },
            //修改数据
            updateBrand(row) {
                this.upbrand.brandName = row.brandName;
                this.upbrand.companyName = row.companyName;
                this.upbrand.description = row.description;
                this.upbrand.ordered = row.ordered;
                this.upbrand.status = row.status + "";
                this.upbrand.id = row.id;
                this.dialog = true;
            },
            upBrand(){
                this.$confirm('此操作将修改数据, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    var _this = this;
                    axios({
                        method: "post",
                        url: "http://localhost:8080/element_test_demo/brand/updateBrand",
                        data: _this.upbrand
                    }).then(function (resp) {
                        if (resp.data == "success") {
                            _this.selectAll();
                            _this.dialog=false
                            _this.$message({
                                message: '恭喜你,修改成功',
                                type: 'success'
                            });

                        }
                    });
                }).catch(() => {
                    //如果取消则取消删除
                    this.$message({
                        type: 'info',
                        message: '已取消修改'
                    });
                });
            }

        },
        mounted() {
            this.selectAll();
        }
    });
</script>
</body>
</html>

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值