Ant Design Vue 表单组件table之 <s-table>

本文介绍了Ant Design Vue中的s-table组件,该组件在使用上简化了分页处理,只需后端返回相应参数即可。查询功能通过设置queryParam与columns对应字段匹配实现,排序功能通过传递sortField和sortOrder参数给后端进行数据排序。此外,文章还展示了s-table的查询、排序和分页配置示例代码。

代码如下:

    # 查询条件
    <a-form layout="inline">
      <a-row :gutter="48">
        <template v-if="advanced">
          <a-col :md="8" :sm="24">
             <a-form-item label="id">
               <a-input v-model="queryParam.id" allow-clear style="width: 100%"/>
             </a-form-item>
           </a-col>
       	  <a-col :md="8" :sm="24">
            <a-form-item label="日期">
             <a-range-picker v-model="queryParam.updateTime" showTime format="YYYY-MM-DD HH:mm:ss" style="width: 100%" placeholder="请输入日期"/>
       	    </a-form-item>
          </a-col>
           <a-col :md="8" :sm="24">
                <a-form-item label="类型">
                  <a-select v-model="queryParam.do" placeholder="请选择" default-value="0">
                    <a-select-option value="">全部</a-select-option>
                    <a-select-option value="0">是</a-select-option>
                    <a-select-option value="1">否</a-select-option>
                  </a-select>
                </a-form-item>
             </a-col>
         </template>
     <a-col :md="!advanced && 8 || 24" :sm="24">
       <span class="table-page-search-submitButtons" :style="advanced && { float: 'right', overflow: 'hidden' } || {} ">
           <a-button type="primary" @click="$refs.table.refresh(true)">查询</a-button>
       </span>
      </a-col>
    </a-row>
   </a-form>
<template>
  <s-table
    ref="table"
    size="default"
    :columns="columns"
    :data="loadData"
  >
  </s-table>
</template>

<script>
  import { STable } from '@/components'
  # 分装的方法
  import { getUserList } from '@/api/user'
  export default {
    components: {
      STable
    },
    data() {
      return {
        columns: [
          {
            title: 'id',
            align: 'center',
            dataIndex: 'id'
          },
          {
            title: '名称',
            align: 'center',
            dataIndex: 'name'
          },
          {
            title: '状态',
            align: 'center',
            dataIndex: 'status',
          },
          {
            title: '更新时间',
            align: 'center',
            dataIndex: 'updateTime',
            sorter: true
          }
        ],
        // 查询条件参数
        queryParam: {},
        // 加载数据方法 必须为 Promise 对象
        loadData: parameter => {
          const requestParameters = Object.assign({}, parameter, this.queryParam)
          return getUserList(requestParameters)
          .then(res => {
            console.log(res)
            return res.data
          })
        }
      }
    }
  }
</script>

介绍

  1. s-table 和 官网的 a-table相比,目前发现,就是不用处理分页,只要后端返回相应参数即可。
  2. 查询,只要确保 queryParam的属性和columns中对应的字段一致即可。
  3. 排序,s-table 表单的排序,会向后端传输两个参数,sortField与sortOrder。sortField代表排序的字段,sortOrder代表是升序还是降序,如下是升序。分页传的参数为 pageNo和pagesize。 如下:在这里插入图片描述
  4. 后台传回来的参数格式,包括四个分页需要用到的参数,如下:在这里插入图片描述
下面是一段增加Qtime的代码,要实现每一行Qtime均可以Add,这里要如何实现 <a-modal :visible="addQtimeVisible" title="Add Qtime" @ok="handleAddQtimeOk" @cancel="handleAddQtimeCancel" :width="900"> <a-form :form="form"> <a-row :gutter="16"> <a-col :span="4"> <a-form-item label="QTime Type"> <a-select placeholder="请选择" v-model="groupResultQtimes.controlType" style="width: 100%"> <a-select-option value="Max Time">Max Time</a-select-option> <a-select-option value="Min Time">Min Time</a-select-option> </a-select> </a-form-item> </a-col> <a-col :span="4"> <a-form-item label="QTime Period"> <a-input-number :value="groupResultQtimes.intervalTime" placeholder="输入时间" style="width: 100%" /> </a-form-item> </a-col> <a-col :span="4"> <a-form-item label="QTime From Seq"> <a-select placeholder="请选择" v-model="groupResultQtimes.strStepSeq" style="width: 100%"> <a-select-option v-for="item in groupStepSeqList" :key="item">{{ item }}</a-select-option> </a-select> </a-form-item> </a-col> <a-col :span="4"> <a-form-item label="QTime To Seq"> <a-select placeholder="请选择" v-model="groupResultQtimes.endStepSeq" style="width: 100%"> <a-select-option v-for="item in groupStepSeqList" :key="item">{{ item }}</a-select-option> </a-select> </a-form-item> </a-col> <a-col :span="4"> <a-form-item label="QTime Expire Action"> <a-select placeholder="请选择" v-model="groupResultQtimes.expireAction" style="width: 100%"> <a-select-option value="Hold Lot">Hold Lot</a-select-option> <a-select-option value="Show Message">Show Message</a-select-option> </a-select> </a-form-item> </a-col> <a-col :span="1"> </a-col> <a-col :span="2"> <a-form-item label=" " :colon="false"> <a-button type="primary" html-type="submit" block @click="AddGroupResultQtime">Add</a-button> </a-form-item> </a-col> </a-row> </a-form> <a-card style="margin-top: 20px" title="QtimeInfomation"> <a-table :columns="StepQtimeColumns" :data-source="StepQtime" rowKey="id" :locale="{ emptyText: '暂无数据' }"> <template #action="text, record"> <span> <a-popconfirm title="确定删除?" @confirm="deleteStepQtime(record.id)"> <a>删除</a> </a-popconfirm> </span> </template> </a-table> </a-card> </a-modal>
最新发布
12-19
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值