溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

Vue實現(xiàn)表格批量審核功能實例代碼

發(fā)布時間:2020-08-21 17:18:28 來源:腳本之家 閱讀:238 作者:face light~ 欄目:web開發(fā)

本文實例為大家分享了Vue實現(xiàn)表格批量審核功能的具體代碼,供大家參考,具體內(nèi)容如下

1 前端部分

效果如下圖所示:

Vue實現(xiàn)表格批量審核功能實例代碼

1.1 html部分

 <el-form-item>
   <el-button type="success" icon="el-icon-search" @click="auditServer()" :disabled="this.sels.length === 0">批量審核</el-button>
    <el-button @click="toggleSelection()">取消選擇</el-button>
    </el-form-item>
    </br>
    <el-table border :fit="true" ref="multipleTable" height="520" :data="listData" :highlight-current-row="true" size="small" @selection-change="selsChange" @row-click="handleChange">
      <el-table-column type="selection" width="55"></el-table-column>
      <el-table-column prop="applcd" label="微服務編碼" show-overflow-tooltip width="130px" sortable fixed="left"></el-table-column>
        <el-table-column prop="servcd" label="服務編碼" show-overflow-tooltip width="130px" sortable fixed="left"></el-table-column>
 </el-table>

代碼說明:

1)為table添加屬性

@selection-change="selsChange" @row-click="handleChange"

2)添加一列 指定type為selection,表示該表格可選擇

<el-table-column type="selection" width="55"></el-table-column>

3)當沒有選擇服務時,按鈕不可選;

:disabled="this.sels.length === 0"

1.2 js部分

export default {
 data () {
  return {

   sels:[],


 methods: {


  selsChange(sels) {
    this.sels = sels
  },

  handleChange(row, event, column) {
    this.$refs.multipleTable.toggleRowSelection(row)
  },
  auditServer () {
   var servids = this.sels.map(item => item.servid).join(",")
   var params = {
    serverIds:servids
   }
     debugger
     auditServer(params).then(
     function (res) {
     debugger
      if(res.code === 200){
      this.$message({
           message: res.data,
           type: 'success'
          })
      this.dialogFormVisible = false
      }else{
      this.$message({
         message: '錯誤信息:'+res.message,
         type: 'error'
        });
      }
        this.loadData()
     }.bind(this)
    )
  },

  toggleSelection(){
  this.$refs.multipleTable.clearSelection();
  }
 }
}

2 后端部分

2.1 mapper.xml

批量修改的Mybatis實現(xiàn)方式,注意sql語句的書寫

<!--審核服務信息-->
  <update id="auditServers" parameterType="java.util.List">
    update sdcp_serv
    SET ISAUDITED ='1'
    where servid in
    <foreach collection="list" index="index" item="item"
         separator="," open="(" close=")">
      #{item,jdbcType=VARCHAR}
    </foreach>
</update>

2.2 mapper.java(對應的接口)

int auditServers(List<String> servids);

2.3 controller

/**  
 * @Description: 批量審核服務信息 
 * @param @param map
 * @param @return
 * @param @throws Exception  參數(shù) 
 * @return Object  返回類型  
 */ 
    @RequestMapping(value = "/auditServers", method = RequestMethod.POST)
    public Object auditServers(@RequestBody Map<String, Object> map) throws Exception {
      if (map.get("serverIds")!=null){
        String serverIds = (String) map.get("serverIds");
        List<String> ids = Arrays.asList(serverIds.split(","));
        apiServerMapper.auditServers(ids);
      }
      return ResponseData.success("服務信息修改成功");
 }

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持億速云。

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權內(nèi)容。

AI