欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Vue.js实现简单动态数据处理

程序员文章站 2022-07-11 10:54:25
直接上代码吧 <%@ page contenttype="text/html;charset=utf-8" %> <...

直接上代码吧

<%@ page contenttype="text/html;charset=utf-8" %>
<html>
<head>
  <title>libgoodscontroller测试页面</title>
  <meta name="layout" content="main"/>
  <script type="text/javascript" src="${resource(base: '..', dir: 'js', file: 'jquery-2.1.3.js')}"></script>
  <script type="text/javascript" src="${resource(base: '..', dir: 'js', file: 'vue.min.js')}"></script>
  <script>
    $(function() {
      //列表选中id
      var tableselectid;
      //列表选中tr
      var seltr = null;
      //列表json
      var printjson;

      //初始化过滤器
      vue.filter('isauditformatter', function (value) {
        if(value == true){
          return "已审核";
        }
        else return "未审核";
      });

      vue.filter('isenabledformatter',function (value){
        if(value == true){
          return "启用";
        }
        else return "停用";
      });

      vue.filter('goodstypeformatter',function (value){
        if(value == "1"){
          return "零售";
        }
        else return "餐饮";
      });

      var object_crud = new vue({
        el: '#object_crud',
        data: {
          //显示json
          message:'',
          //对象
          object : '',
          //对象数组
          list : ''
        },
        methods: {
          //分页查询并显示数据
          showdata: function () {
            var _self = this;
            var url = "...";
            $.ajax({
              type: 'get',
              url: url,
              success:function(data) {
                printjson = json.stringify(data);
                _self.list = data.data.rows;
              }
            });
          },
          //显示查询json
          showjson:function(){
            this.message = printjson;
          },
          //清空查询返回json
          clearjson:function(){
            this.message = "";
          },
          //选中列表行 点击事件
          onclick:function (evt) {
            var _self = this;
            var el = evt.srcelement?evt.srcelement:evt.target;
            if(el.tagname.touppercase() !="td") return;
            var tr = el.parentnode;
            tr.style.backgroundcolor="yellow";
            if(seltr !=null)
            {
              seltr.style.backgroundcolor ="white";
            }
            seltr = tr;
            tableselectid = seltr.cells[0].innerhtml;
            //通过id获取对象
            var url = "...";
            $.ajax({
              type: 'get',
              url: url,
              success:function(data) {
                if(data.result == "true"){
                  _self.object = data.data;
                }
              }
            });
          },
          //启用 选中的 记录
          enable:function(){
            var _self = this;
            var url = "...";
            $.ajax({
              type: 'get',
              url: url,
              success:function(data) {
                _self.message = json.stringify(data);
                if(data.result == "true"){
                  _self.showdata();
                }
              }
            });
          },
          //停用 选中的 记录
          unenable:function(){
            var _self = this;
            var url = "...";
            $.ajax({
              type: 'get',
              url: url,
              success:function(data) {
                _self.message = json.stringify(data);
                if(data.result == "true"){
                  _self.showdata();
                }
              }
            });
          },
          //删除 记录
          delete:function(){
            var _self = this;
            var url = "...";
            $.ajax({
              type: 'get',
              url: url,
              success:function(data) {
                _self.message = json.stringify(data);
                if(data.result == "true") {
                  _self.showdata();
                }
              }
            });
          },
          save:function(){
            var _self = this;
            var url = "...";
            $.ajax({
              type: 'post',
              url: url,
              data:{
                id:$('#id').val()
                /*...*/
              },
              success:function(data) {
                _self.message = json.stringify(data);
                if(data.result == "true"){
                  _self.showdata();
                }
              }
            });
          }
        }
      })
    });
  </script>
</head>

<body>
<div style="text-align: center" id="test_title">
  <font color="#ff1493" size="6">商品信息管理服务(web-service-libgoods)接口测试</font> <br><br><br>
</div>


<div id="object_crud">

  测试介绍:<br><br>
  <div class="description" style="height:auto;width:auto;border-top: 1px dashed #f00;
  border-bottom: 1px dashed #f00;border-left: 1px dashed #f00;border-right: 1px dashed #f00">
    1.条件查询并分页(查询条件:商品名称模糊查询,商品类别,分页参数)<br>
    2.新增商品<br>
    3.更新商品<br>
    4.删除商品<br>
    5.启用/停用商品
  </div><br><br>

  1.商品名称:<g:textfield name="querystr" id="querystr1" value="佳能"></g:textfield>
  商品类型 :
  <g:radio value="2" name="goodstypesearch"></g:radio>餐饮
  <g:radio value="1" name="goodstypesearch" checked="true"></g:radio>零售
  列表参数: 当前页:<g:textfield name="page" value="0"></g:textfield> 每页显示:<g:textfield name="pagesize" value="20"></g:textfield>
  <button v-on:click="showdata">查询</button>
  <button v-on:click="showjson">显示json</button>
  <br><br>

  测试结果json:<button v-on:click="clearjson">清空测试结果</button>
  <br><br>
  <div class="jsonresult" style="height:auto;width:auto;border-top: 1px dashed #f00;
  border-bottom: 1px dashed #f00;border-left: 1px dashed #f00;border-right: 1px dashed #f00">
    {{message}}
  </div><br><br>

  测试列表:
  <br><br>
  <div style="height:auto;width:auto;border-top: 1px dashed #f00;
  border-bottom: 1px dashed #f00;border-left: 1px dashed #f00;border-right: 1px dashed #f00">
    <table id="table" style="border:2";>
      <thead>
      <tr>
        <th style='width:3%; text-align: left'>id</th>
        <th style='width:10%; text-align: left'>商品编码</th>
        <th style='width:5%; text-align: left'>商品类别</th>
        <th style='width:10%; text-align: left'>商品名称</th>
        <th style='width:10%; text-align: left'>简称</th>
        <th style='width:5%; text-align: left'>是否审核</th>
        <th style='width:5%; text-align: left'>是否启用</th>
      </tr>
      </thead>
      <tbody>
      <tr v-for="data in list" v-on:click="onclick">
        <td>{{data.id}}</td>
        <td>{{data.barcode}}</td>
        <td>{{data.goodstype | goodstypeformatter}}</td>
        <td>{{data.name}}</td>
        <td>{{data.shortname}}</td>
        <td>{{data.isaudit | isauditformatter}}</td>
        <td>{{data.isenabled | isenabledformatter}}</td>
      </tr>
      </tbody>
    </table>
  </div>

  <br><br>
  2.<button v-on:click="save">保存</button> <br><br>
  3.<button v-on:click="save">更新</button> <br><br>
  4.<button v-on:click="delete">删除</button> <br><br>
  5.<button v-on:click="enable">启用</button> 
  <button v-on:click="unenable">停用</button>br><br>

  商品对象:
  <div class="z333" style="height:auto;width:auto;border-top: 1px dashed #f00;
  border-bottom: 1px dashed #f00;border-left: 1px dashed #f00;border-right: 1px dashed #f00"><br>
    <g:form name="myform">
      id(测试启/停用,删除):<g:textfield name="id" v-model="object.id"></g:textfield><br><br>
      商品编码:<g:textfield name="barcode" v-model="object.barcode"></g:textfield><font color="red"> *</font><br><br>
      商品名称:<g:textfield name="name" v-model="object.name"></g:textfield><font color="red"> *</font><br><br>
      商品类别:<g:radio value="2" name="goodstype" v-model="object.goodstype"></g:radio>餐饮
      <g:radio value="1" name="goodstype" v-model="object.goodstype"></g:radio>零售<font color="red"> *</font><br><br>
      商品简称:<g:textfield name="shortname" v-model="object.shortname"></g:textfield><br><br>
      商品分类:<g:textfield name="categoryname" v-model="object.categoryname"></g:textfield><br><br>
      品牌编码:<g:textfield name="brandcode" v-model="object.brandcode"></g:textfield><br><br>
      产地:<g:textfield name="productarea" v-model="object.productarea"></g:textfield><br><br>
      单位:<g:textfield name="unitname" v-model="object.unitname"></g:textfield><br><br>
      规格:<g:textfield name="goodsspec" v-model="object.goodsspec"></g:textfield><br><br>
      拼音码:<g:textfield name="pycode" v-model="object.pycode"></g:textfield><br><br>
      备注:<g:textfield name="remark" v-model="object.remark"></g:textfield><br><br>
    </g:form>
  </div><br><br>
</div>
</body>
</html>

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。