亚洲激情专区-91九色丨porny丨老师-久久久久久久女国产乱让韩-国产精品午夜小视频观看

溫馨提示×

溫馨提示×

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

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

基于Vue+element-ui 的Table二次封裝的實現

發布時間:2020-09-03 16:59:59 來源:腳本之家 閱讀:391 作者:bilimumu 欄目:web開發

本人第一次寫這個 寫的不好還望指出來

作為一個由于公司產品的升級然促使我從一個后端人員自學變成前端的開發人員 !

公司做的數據管理系統所以離不開表格了 然后表格樣式統一啥的就想到封裝一個element-ui 里面的table+Pagination了

效果圖

基于Vue+element-ui 的Table二次封裝的實現

表格組件的引入與使用

<com-table title="監測數據" v-model="tableData4" @selection-change="handleSelectionChange">
    <template>
     <el-table-column type="selection" width="55" align="center">
     </el-table-column>
     <el-table-column prop="name" label="表格名稱" align="center">
     </el-table-column>
     <el-table-column label="測點" align="center">
      <template slot-scope="scope" v-if="scope.row.point.visible">
       <el-input v-model="scope.row.point.value" placeholder="請輸入內容" @focus="focuspoint(scope.row.point)"></el-input>
      </template>
     </el-table-column>
     <el-table-column label="項目" align="center">
      <template slot-scope="scope" v-if="scope.row.item.visible">
       <el-input v-model="scope.row.item.value" placeholder="請輸入內容" @focus="focusitem(scope.row.item)"></el-input>
      </template>
     </el-table-column>
    </template>
   </com-table>

使用插槽slot 使用起來就和原來的table一樣了

import comTable from '@/components/common/com-table'
import { GetTempletExportList, GetTempletExportInfo } from '../../../api/transfer/index'
import ApiConfig from '@/api/ApiConfig'
export default {
 name: 'templet',
 components: {
  comTable
 },
 data() {
  return {
   tableData4: [],
   exporttableData: [],
   multipleSelection: [],
   currentpoint: null,
   currentitem: null,
   itemdialogshow: false,
   pointdialogshow: false,
   path: new ApiConfig().GetConfig().SysPath,
   checkeditem: [],//選中數據
  }
 },
 computed: {
  moduletype() {
   return this.$store.state.moduletype;
  },
  userinfo() {
   return this.$store.state.user.userInfo;
  }
 },
 watch: {
  moduletype() {
   this.init();
  }
 },
 created() {
  this.init();
 },
 methods: {
  init() {
   GetTempletExportList(this.userinfo.cityid, this.moduletype).then(re => {
    this.exporttableData = re.data;
    this.tableData4 = [];
    re.data.map(item => {
     this.tableData4.push({
      name: item.fldTableDesc,
      point: {
       visible: false,
       value: ''
      },
      item: {
       visible: true,
       value: item.ItemList
      }
     })
    })
   }, (error) => {
    this.$message({
     customClass: 'el-message_new',
     message: error,
     type: 'error'
    });
   })
  },
  handleSelectionChange(val) {
   console.log(val)
   this.multipleSelection = val;
  },
  focuspoint(val) {
   this.currentpoint = val;
  },
  focusitem(val) {
   this.currentitem = val;
   this.itemdialogshow = true;
  },
  itemconfirm() {
   this.itemdialogshow = !this.itemdialogshow;
  },
  itemhandleClose(done) {
   this.itemdialogshow = false;
  },
  ItemGroupSelectchange(val) {
   this.checkeditem = val;
   console.log(this.checkeditem);
   let groupitemcontent = [];
   val.map(item => {
    groupitemcontent.push(item.fldItemName);
   })
   this.currentitem.value = groupitemcontent.join(',');
  },
  submit() {
   if (this.multipleSelection.length > 0) {
    let message = "";
    let data = [];
    let name = "";
    this.multipleSelection.map((item, index) => {
     name = item.name;
     let str = item.name;
     let info = false;
     if (item.item.visible && item.item.value == "") {
      message += `表[${str}]請選擇因子`;
      info = true;
     }
     if (item.point.visible && item.point.value == "") {
      if (info) {
       message += `、請選擇測點/斷面!`;
      } else {
       message += `表[${str}]請選擇測點/斷面!`;
      }
      info = true;
     }
     if (info) {
      message += "<br/>"
     }
     data.push({
      "AutoID": "1",
      "STCode": "",
      "PCode": "",
      "RCode": "",
      "RScode": "",
      "GDCODE": "",
      "type": this.moduletype,
      "itemcodeList": item.item.value.split(',').join('^'),
      "path": `${this.path.TempletExportSetting}${this.moduletype}.json`,
      "IsNeedNullData": "Y"
     })

    })
    if (message == "") {
     GetTempletExportInfo(data).then(re => {
      if (re.status == "ok") {
       var exportdata = eval((re.data));
       const { export_json_to_excel } = require("../../../libs/Export2Excel");
       if (exportdata[0].merg.length != 0) {
        var exdata = [];
        var itemlistUnit = [];
        var itemlistfldCharCode = [];
        for (var z = 0; z < exportdata[0].head.length - this.checkeditem.length; z++) {
         itemlistUnit.push(exportdata[0].head[z]);
         itemlistfldCharCode.push(exportdata[0].head[z])
        }
        this.checkeditem.map(item => {
         itemlistUnit.push(item.fldUnit);
         itemlistfldCharCode.push(item.fldCharCode);
        })
        var exdata = this.formatJson(exportdata[0].head, exportdata[0].data);
        exdata.unshift(itemlistUnit);
        exdata.unshift(itemlistfldCharCode);
        exdata.unshift(exportdata[0].head);
        console.log(exdata)
        exportdata[0].merg.push([0, 0, exportdata[0].head.length - 1, 0])
        export_json_to_excel([name], exdata, name, exportdata[0].merg);
       } else {
        var exdata = this.formatJson(exportdata[0].head, exportdata[0].data);
        exdata.unshift(exportdata[0].head);
        exportdata[0].merg.push([0, 0, exportdata[0].head.length - 1, 0])
        export_json_to_excel([name], exdata, name, exportdata[0].merg);
       }

      } else {
       this.$message({
        message: '導出失敗!',
        type: 'error'
       });
      }
     })
    } else {
     this.$message({
      dangerouslyUseHTMLString: true,
      customClass: 'el-message_new',
      message: message,
      type: 'warning'
     });
    }
   } else {
    this.$message({
     customClass: 'el-message_new',
     message: '請先選擇要導出的列表!',
     type: 'warning'
    });
   }
  },
  formatJson(filterVal, jsonData) {
   return jsonData.map(v =>
    filterVal.map(j => {
     return v[j];
    })
   );
  }
 }
}

comTable組件

<template>
 <div class="com-table">
  <div class="com-table-title" v-if="title">
   {{title}}
  </div>
  <div :class="[title?'com-table-content':'com-table-content-nottitle']">
   <el-table v-loading="loading" ref="multipleTable" stripe :data="tableData"  height="100%" border @selection-change="handleSelectionChange" @row-click="rowClick" @row-dblclick='rowDblclick' @cell-dblclick="celldblclick">
    <slot></slot>
   </el-table>
  </div>
  <div class="com-table-page">
   <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="PageIndex" :page-sizes="page_sizes" :page-size="Size" :layout="layout" :total="total">
   </el-pagination>
  </div>
 </div>
</template>
<script>
import commomway from '../../common/commonway.js' //分頁
export default {
 name: 'com-table',
 props: {
  value: {//數據
   type: [Array, Object],
   default: () => {
    return [];
   }
  },
  PageSize: {//當前一頁顯示多少條數據
   type: Number,
   default: 20
  },
  page_sizes: {//分頁規則
   type: Array,
   default: () => {
    return [1, 20, 40, 60, 80]
   }
  },
  current_page: {//當前所在頁
   type: Number,
   default: () => {
    return 1;
   }
  },
  layout: {
   type: String,
   default: () => {
    return 'total, sizes, prev, pager, next, jumper';
   }
  },
  title: {//表格title
   type: String,
   default: () => {
    return '';
   }
  },
  loading: {
   type: Boolean,
   default: false
  }
 },
 data() {
  return {
   tableData: [],
   //頁數索引  
   PageIndex: this.current_page,
   //每頁顯示的數量
   Size: this.PageSize,
   oldmultipleSelection: [],//舊的選中值
   multipleSelection: []//當前選中數據
  }
 },
 watch: {
  value(val) {
   this.getpagedata();
  },
  tableData(val) {
   // console.log(val);
  },
  multipleSelection(val, old) {
   this.oldmultipleSelection = old;
  }

 },
 mounted() {
  this.getpagedata();
 },
 computed: {
  total() {
   return this.value.length;
  }
 },
 methods: {
  //獲得分頁后的數據
  getpagedata() {
   var common = new commomway();
   this.tableData = common.pagination(this.PageIndex, this.Size, this.value, false);
   this.$emit("input", this.value);
   setTimeout(() => {//由于表格重新渲染延遲執行勾選
    this.toggleSelection(this.oldmultipleSelection)
   }, 20)

  },
  //點擊每頁顯示數量時觸發
  handleSizeChange: function (val) {
   this.Size = val;
   this.getpagedata();
   this.$emit('handleSizeChange', val);
  },
  //翻頁的時候觸發
  handleCurrentChange: function (val) {
   this.PageIndex = val;
   this.getpagedata();
   this.$emit('handleCurrentChange', val);

  },
  handleSelectionChange(val) {
   this.multipleSelection = val;
   this.$emit('selection-change', val);
  },
  toggleSelection(rows) {//勾選值
   if (rows) {
    rows.forEach(row => {
     this.$refs.multipleTable.toggleRowSelection(row);
    });
   } else {
    this.$refs.multipleTable.clearSelection();
   }
  },
  rowClick(row, event, column){
    this.$emit('row-click', row, event, column);
  },
  celldblclick(row, column, cell, event){
   this.$emit('cell-dblclick', row, column, cell, event);
  },
  rowDblclick(row,enent){
   //console.log(row,enent)
  }
 }
}
</script>
<style lang="sass">
 @import "./com-table.scss";
</style>

commonway.js

class CommonWay {
 /**
  * description:對數組的分頁處理
  * author:bilimumu
  * date:2017-10-28 
  * @param {number} [pageNo=1] 頁碼
  * @param {number} [pageSize=10] 每頁顯示條數 
  * @param {any} [obj=[]] 待分頁的數組
  * @param {Boolean} [iscreateNewdata=true] 是否創建新的數據
  * @returns 返回新的數組
  * @memberof CommonWay
  */
 pagination(pageNo = 1, pageSize = 10, obj = [], iscreateNewdata = true) {
  var array = [];
  if (iscreateNewdata) {
   array = JSON.parse(JSON.stringify(obj));
  } else {
   array = obj;
  }
  var offset = (pageNo - 1) * pageSize;
  return (offset + pageSize >= array.length) ? array.slice(offset, array.length) : array.slice(offset, offset + pageSize);
 }
}

export default CommonWay

com-table.scss

.com-table {
 height: 100%;
 width: 100%;
 &-title {
  color: #FFF;
  background: #42A2F5;
  padding: 0;
  font-size: 15px;
  height: 40px;
  line-height: 40px;
  text-indent: 8px;
 }
 &-content {
  width: 100%;
  height: calc(100% - 40px - 55px);
 }
 &-content-nottitle {
  width: 100%;
  height: calc(100% - 55px);
 }
 &-page {
  height: 55px;
  width: 100%;
  background: #EFF3F8;
  display: flex;
  align-items: center;
  justify-content: center;
 }
}

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

向AI問一下細節

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

AI

通道| 富平县| 玉环县| 抚宁县| 舒兰市| 和田县| 廊坊市| 当涂县| 梨树县| 姜堰市| 扬中市| 石景山区| 阿鲁科尔沁旗| 浙江省| 深泽县| 自贡市| 辽宁省| 苍梧县| 密云县| 南丰县| 桃园县| 古田县| 白银市| 仁怀市| 玉田县| 克东县| 平潭县| 成武县| 陆丰市| 渝中区| 镇康县| 梧州市| 应城市| 当涂县| 昆山市| 邵武市| 汨罗市| 廉江市| 安徽省| 托克逊县| 安西县|