VUE+ELEMENT UI学习demo

 这几天,看了下vue+element ui的一些知识,现在将其写成一个demo,页面下过如下

代码如下:

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="emp" uri="http://www.montnets.com/emp/i18n/tags/simple" %>
<%@include file="/common/common.jsp" %>
<%
    String iPath = request.getRequestURI().substring(0, request.getRequestURI().lastIndexOf("/"));
    String inheritPath = iPath.substring(0, iPath.lastIndexOf("/"));
    String commonPath = inheritPath.substring(0, inheritPath.lastIndexOf("/"));
    String skinPath = session.getAttribute("stlyeSkin") == null ? "default" : (String) session.getAttribute("stlyeSkin");
    String version = skinPath.contains("frame3.0") ? "v3" : skinPath.contains("frame4.0") ? "v4" : "v2";
    int index = skinPath.lastIndexOf("/");
    String skin = version + "-" + skinPath.substring(index + 1);
%>
<!doctype html>
<style>
    .top_btn {
        margin-bottom: 40px;
    }
    .top_left_btn {
        margin-left: 5px;
        float: left;
        display: block;
        margin-bottom: 10px;
    }
    .top_right_btn {
        margin-right: 5px;
        float: right;
        display: block;
        margin-bottom: 10px;
    }

    .bottom {
        margin-top: 25px;
        float: right;
    }
</style>
<html lang="en">
<head>
    <title>签约信息查询vue练习
    </title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <link href="<%=commonPath%>/common/css/frame.css?V=<%=StaticValue.getJspImpVersion() %>" rel="stylesheet"
          type="text/css"/>
    <link href="<%=skinPath %>/frame.css?V=<%=StaticValue.getJspImpVersion() %>" rel="stylesheet" type="text/css"/>
    <link href="<%=commonPath%>/common/css/vue/index.css?V=<%=StaticValue.getJspImpVersion() %>" rel="stylesheet"
          type="text/css"/>
    <link href="<%=commonPath%>/common/css/vue/index<%="-" + skin%>.css?V=<%=StaticValue.getJspImpVersion() %>"
          rel="stylesheet"
          type="text/css"/>
    <link href="<%=commonPath%>/common/css/vue/iview.css?V=<%=StaticValue.getJspImpVersion() %>" rel="stylesheet"
          type="text/css"/>
    <title>Title</title>
</head>
<body>
<div id="container" class="container" > 
 <%-- container与js中el属性对应的值保持一致--%>
    <span v-html="position"></span>    
  <%-- v-html表示要展示的html,position为后台传输过来的值,需要在js中定义--%>
    <div id="rContent" class="rContent"
         v-if="access"     
         style="margin-left:1.5rem;width: 95%"> 
 <%-- v-if表示只有当满足条件时,才展示div中的东西,access同样为js中定义的属性,可以由后台传值--%>
        <div class="top_btn">
            <div class="top_left_btn">
                <el-button type="primary" size="mini" @click="add">新增
                </el-button> 
  <%--@为v-on标签的缩写,表示给当前页面上的事件进行绑定,add为定义的方法 --%>
            </div>
            <div class="top_right_btn">
                <el-switch
                        v-model="isSearch"
                        active-color="#13ce66"
                        inactive-color="#ff4949"
                        active-text="显示搜索"
                        inactive-text="隐藏搜索">
                </el-switch>  
<%--v-model实现属性值绑定,isSearch为js中定义的值,可以由后台传输--%>
            </div>
        </div>
        <el-card class="box-card" style="margin-bottom: 0.8rem; width: 100%" v-if="isSearch" shadow="hover">
            <el-form :inline="true" label-width="90px"
                     class="mmsTplForm" style="width: 1000px; margin-left: 2%;padding: 14px 0 5px 0 ; float: left"
                     size="mini"
                     label-position="left">
                <el-form-item label="账号:">
                    <el-input v-model="criteria.acctNo" clearable placeholder="账号" style="width: 195px"/>
                </el-form-item>
                <el-form-item label="手机号码:">
                    <el-input v-model="criteria.phoneNo" clearable placeholder="手机号码" style="width: 195px"/>
                </el-form-item> 
 <%--criteria为后台定义的查询对象,acctNo和phoNo查询对象的属性--%>
            </el-form>
            <el-container>
                <el-header style="padding: 14px 0 5px 0" height="70px">
                    <el-button style="float: left;" type="primary" @click="getQuery" size="mini"
                               icon="el-icon-search">查询
                    </el-button>
                </el-header>
            </el-container>
        </el-card>
        <!--------------------------------------------- 表格代码 --------------------------------------------->
        <el-card class="box-card" shadow="hover">
            <el-table
                    size="mini"
                    :empty-text="emptyText"
                    :data="tableData"
                    v-loading="loading"
                    style="width: 100%;">
     <%--:data等价于V-bind data,v-bind简写为:,实现属性值绑定,emptyText,tableData,loding都为js中定义的属性值--%>
                <el-table-column
                        align="center"
                        prop="cucuno"
                        label="客户号">
                </el-table-column>
                <el-table-column
                        align="center"
                        prop="cutlno"
                        label="电话号码">
                </el-table-column>
                <el-table-column
                        align="center"
                        prop="cuopnt"
                        label="开机构代号">
                </el-table-column>
     <%--prop为element ui中实现表单属性绑定的属性,cucuno,cutlno,cuopnt为后台定义前端页面展示Vo类的属性值--%>           
                <el-table-column
                        align="center"
                        width="350"
                        label="操作">
                    <template slot-scope="scope123" v-if="scope123.row.id != 1 && scope123.row.id != 2 && scope123.row.id != 3">
                      <%--scope123为自己在jsp中随意定义的值--%>  
                      <el-button type="success" size="small" @click="edit(scope123.row)">编辑</el-button>
                        <el-popover
                                :ref="scope123.row.id"
                                placement="top"
                                width="180">
                            <p>确定删除本条数据吗?</p>
                            <div style="text-align: right; margin: 0">
                                <el-button size="mini" type="text" @click="$refs[scope123.row.id].doClose()">取消
                                </el-button>
                                 <%--doClose()方法为vue中原生方法--%>
                                <el-button :loading="delLoading" type="primary" size="mini"
                                           @click="subDelete(scope123.row.id)">确定
                                </el-button>
                            </div>
                            <el-button slot="reference" type="danger" size="mini">删除</el-button>
                        </el-popover>
                    </template>
                </el-table-column>
            </el-table>
        </el-card>
        <!-- 新增编辑弹出框-->
        <el-dialog top="150px" :close-on-click-modal="false" :title="isAdd ? '新增' : '编辑'" :visible.sync="isShow" width="500px" :show-close="false">
            <%--isAdd,isShow为js中定义属性值,用来判断from表单的title是新增还是编辑,表单是否展示--%>
            <el-form ref="testForm" :inline="true" :model="testForm" :rules="rules" size="small" label-width="150px">
                <%--rules为js中自定义的表单校验规则,testForm为js中自定义的表单属性--%>
                <el-form-item label="客户号:">
                    <el-input v-model="testForm.cucuno" placeholder="输入客户号" oninput="value=value.replace(/[^a-zA-Z0-9]/ig,'')"/>
                </el-form-item>
                <%--v-model = "testForm.cucuno 表示绑定testForm表单中的cucuno属性"--%>
                <el-form-item label="电话号码:" >
                    <el-input  v-model="testForm.cutlno" placeholder="输入电话号码" oninput="value=value.replace(/[^\d]/g, '')"/>
                </el-form-item>
                <el-form-item label="开户机构代码:">
                    <el-input  v-model="testForm.cuopnt" placeholder="输入开户机代号" oninput="value=value.replace(/[^a-zA-Z0-9]/ig,'')"/>
                </el-form-item>
                <el-form-item label="备注:">
                    <el-input   v-model="testForm.remark"  placeholder="请输入中文备注" onkeyup="value=value.replace(/[^\u4e00-\u9fa5]/g,'')"/>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button type="text" @click="cancel">取消</el-button>
                <el-button :loading="loading" type="primary" @click="doSubmit">确认</el-button>
            </div>
        </el-dialog>
        <%--分页--%>
        <div class="bottom">
            <el-pagination
                    @size-change="handlePageSize"
                    @current-change="handlePage"
                    :current-page.sync="pageInfo.pageIndex"
                    :page-sizes="pageInfo.pageSizeOpts"
                    :page-size="pageInfo.pageSize"
                    layout="total, sizes, prev, pager, next, jumper"
                    :total="pageInfo.totalRec">
            </el-pagination>
        </div>
    </div>
</div>
<script type="text/javascript">
    document.write("<scr" + "ipt src=\"<%=commonPath%>/common/js/myjquery-a.js?V=<%=StaticValue.getJspImpVersion() %>\"></sc" + "ript>")
</script>
<script src="<%=commonPath %>/common/js/common.js?V=<%=StaticValue.getJspImpVersion() %>"></script>
<script src="<%=commonPath%>/common/i18n/i18nUtil.js"></script>
<script type="text/javascript">
    if (browserData() !== -1) {
        document.write("<scr" + "ipt src=\"<%=commonPath%>/common/js/vue/babel.min.js?V=<%=StaticValue.getJspImpVersion() %>\"></sc" + "ript>")
    }
</script>
<script type="text/javascript">
    if (browserData() !== -1) {
        document.write("<scr" + "ipt src=\"<%=commonPath%>/common/js/vue/browser-polyfill.min.js?V=<%=StaticValue.getJspImpVersion() %>\"></sc" + "ript>")
    }
</script>
<script type="text/javascript">
    document.write("<scr" + "ipt src=\"<%=commonPath%>/common/js/vue/vue.js?V=<%=StaticValue.getJspImpVersion() %>\"></sc" + "ript>")
</script>
<script type="text/javascript">
    document.write("<scr" + "ipt src=\"<%=commonPath%>/common/js/vue/index.js?V=<%=StaticValue.getJspImpVersion() %>\"></sc" + "ript>")
</script>
<script type="text/javascript">
    if (browserData() === -1) {
        document.write("<scr" + "ipt src=\"<%=iPath %>/test.js?V=<%=StaticValue.getJspImpVersion() %>\"></sc" + "ript>")
    }
</script>
<script src="<%=iPath %>/test.js?V=<%=StaticValue.getJspImpVersion() %>"
        type="text/babel"></script>
</body>
</html>

 

js

$(function () {
  new Vue({
        el: "#container",    //绑定jsp中div的id,可以理解为开始绑定vue
        data: {              //data为定义jsp页面中需要的一些数据
            isSearch: true,
            isShow: false,
            isAdd : true,
            testForm: {
                id: '',
                cucuno: '',
                cutlno: '',
                cuopnt:'',
                remark:''
            },
            // 校验规则
            rules: {
                cucuno: [
                    {required: true, message: '请输入客户号号', trigger: 'blur'},
                    {min: 3, max: 3, message: '长度 3 个字符', trigger: 'blur'}
                ],
                cutlno: [
                    {required: true, message: '请输入电话号码', trigger: 'blur'},
                    {min: 6, max: 6, message: '长度在 6 个字符', trigger: 'blur'}
                ],
                cuopnt:[
                    {required: true, message: '请输入客户号', trigger: 'blur'},
                    {min: 3, max: 3, message: '长度在 3 个字符', trigger: 'blur'}
                ]
            },
            pageInfo: {
                pageIndex: 1, // 当前页数
                totalRec: 0, //数据总数
                pageSize: 15,   // 每页条数
                pageSizeOpts: [5, 10, 15, 20, 50],   // 每页条数切换的配置
                totalPage: 0 // 总页数
            },
            // 查询条件
            criteria: {
                phoneNo: "",
                acctNo: ""
            },
            loading: false,
            tableColumns: [],
            tableData: [],
            access: false,
            menuCode: '',
            position: '',
            emptyText: "请点击查询获取数据",
            delLoading: false
        },
        //钩子函数,vue所写页面,自动加载时执行这路面定义的属性
        created: function () {
            this.getInitData()
            this.getQuery()
        },
        //统一采用 _this 去 指向 this
        methods: {
            // 获取初始化参数的方法
            getInitData() {
                let _this = this
                $.ajax({
                    type: "POST",
                    url: 'que_siginInfomation.htm',
                    data: "method=initData",
                    dataType: 'json',
                    async: false,
                    success: function (result) {
                        if (result) {
                            let data = result.data
                            _this.menuCode = data['menuCode']
                            _this.position = data['position']
                            _this.access = data['access']
                        }
                    },
                    error: function () {
                        _this.$message.error('很抱歉,连接异常!')
                    }
                })
            },
            getQuery() {
                let _this = this;
                let query = {
                    pageInfo: _this.pageInfo,
                    criteria: _this.criteria
                }
                _this.loading = true
                $.ajax({
                    type: "POST",
                    url: 'que_siginInfomation.htm?method=query',
                    data: JSON.stringify(query),
                    dataType: 'json',
                    contentType: "application/json",
                    success: function (result) {
                        if (result) {
                            let data = result.data
                            _this.tableData = data['data']
                            _this.pageInfo.totalPage = data['totalPage']
                            _this.pageInfo.totalRec = data['total']
                        }
                        _this.loading = false
                    },
                    error: function () {
                        _this.loading = false
                        _this.$message.error('很抱歉,连接异常!')
                    }
                });
            },
            // 打开 add 页面
            add() {
                this.testForm = {
                    id: '',
                    cucuno: '',
                    cutlno: '',
                    cuopnt:'',
                    remark:''
                }
                this.isShow = true
            },
            cancel() {
                this.isShow = false
            },
            doSubmit() {
                this.loading = true
                this.$refs['testForm'].validate((valid) => {
                    if (valid) {
                        alert("新增成功");
                        this.loading = false
                        this.isShow = false
                        // 对页面进行刷新
                        this.getQuery()
                    } else {
                        alert("参数校验不通过");
                        this.loading = false
                         return false
                     }
            })
            },
            subDelete(id) {
                this.delLoading = true
                alert("删除成功id为"+id+"的数据");
                this.$refs[id].doClose()
                this.delLoading = false
                this.getQuery()
            },
            edit(row) {
                this.testForm = {
                    id: row.id,
                    cucuno: row.cucuno,
                    cutlno: row.cutlno,
                    cuopnt: row.cuopnt,
                    remark:''
                }
                this.isAdd = false
                this.isShow = true
            },
            // 更改分页
            handlePage(value) {
                this.pageInfo.pageIndex = value
                this.getQuery()
            },
            handlePageSize(value) {
                this.pageInfo.pageSize = value
                this.getQuery()
            }
        }
    })
})


 

 

 

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值