IStreamTable.vue 5.32 KB
Newer Older
1 2
<template>
  <div class="eContainer-table-block">
zhengxiaokui committed
3 4 5 6 7
    <el-table
      ref="table"
      :data="
        tableData.slice((currentPage - 1) * pageSize, currentPage * pageSize)
      "
潘际乾 committed
8
      style="width: 100%"
liushikai committed
9
      class="eContainer-table"
潘际乾 committed
10 11
      @selection-change="handleSelectionChange"
      :row-key="getRowKey"
liushikai committed
12
      :header-cell-style="{ background: 'rgb(235, 235, 235)', color: 'rgb(51, 51, 51)' }"
zhengxiaokui committed
13
      :highlight-current-row="true"
潘际乾 committed
14
      @row-click="rowClick"
zhengxiaokui committed
15 16 17 18 19 20 21 22
      :border="true"
    >
      <el-table-column
        type="selection"
        width="55"
        v-if="showSelection"
        :reserve-selection="true"
      ></el-table-column>
23 24 25
      <el-table-column
        v-for="(item, key) in tableColumns"
        :key="key"
zhengxiaokui committed
26
        :prop="item.prop"
27 28
        :label="item.label"
        :width="item.width"
denyu committed
29 30 31
      >
      </el-table-column>
      <slot></slot>
32
    </el-table>
liushikai committed
33
    <c-col :span="16">
zhengxiaokui committed
34
    <el-pagination
35 36 37 38 39 40
      class="eContainer-pagination"
      layout="prev, pager, next, jumper"
      :page-sizes="pageSizes"
      :page-size="pageSize"
      :current-page="currentPage"
      :total="tableData.length"
zhengxiaokui committed
41 42
      @size-change="sizeChange"
      @current-change="currentChange"
43
    ></el-pagination>
liushikai committed
44 45
    </c-col>
    <c-col :span="8">
zhengxiaokui committed
46 47 48 49 50 51 52 53
    <div class="paginationLable">
      当前显示第 {{ (currentPage - 1) * pageSize + 1 }}-{{
        currentPage * pageSize > tableData.length
          ? tableData.length
          : currentPage * pageSize
      }}
      条,共 {{ tableData.length }}
    </div>
liushikai committed
54
    </c-col>
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
  </div>
</template>

<script>
export default {
  props: {
    columns: {
      type: Array,
      default: () => {
        return [];
      },
    },
    list: {
      type: Array,
      default: () => {
        return [];
      },
    },
潘际乾 committed
73 74
    showSelection: {
      type: Boolean,
zhengxiaokui committed
75 76
      default: false,
    },
77 78 79
  },
  computed: {
    tableColumns() {
zhengxiaokui committed
80
      const columnArr = [];
潘际乾 committed
81
      const lines = this.columns;
zhengxiaokui committed
82 83
      const etyReg = /\"([^\"]*)\"/;
      const obj = {};
潘际乾 committed
84
      for (let i = 0; i < lines.length; i++) {
zhengxiaokui committed
85 86 87 88 89 90 91 92 93
        const line = lines[i];
        if (etyReg.test(line)) {
          const gs = line.match(etyReg);
          const columnName = gs[1];
          const newLine = line.replace(gs[0], "_");
          const colPropArr = newLine.split(" ");
          const positionArr = colPropArr[1].split(":");
          if (!obj[positionArr[0]]) {
            obj[positionArr[0]] = [];
潘际乾 committed
94
          }
zhengxiaokui committed
95 96 97 98 99 100
          obj[positionArr[0]].push({
            idx: colPropArr[0],
            prop: columnName,
            width: colPropArr[3] + 'px',
          });
        }
101
      }
潘际乾 committed
102
      for (const k in obj) {
zhengxiaokui committed
103 104 105 106 107 108
        if (Object.hasOwnProperty.call(obj, k)) {
          const o = obj[k];
          const tableColumn = o.map((item) => item.prop).join("\n");
          columnArr.push({
            prop: tableColumn,
            label: tableColumn,
liushikai committed
109 110
            width: o[0].width,
            // width: "auto",
zhengxiaokui committed
111 112 113 114
            index: k,
            children: o,
          });
        }
潘际乾 committed
115
      }
zhengxiaokui committed
116 117 118
      return columnArr.sort((a, b) => {
        return parseInt(a.index) - parseInt(b.index);
      });
119 120
    },
    tableData() {
潘际乾 committed
121
      // return this.list.map((row) => {
zhengxiaokui committed
122
      // 	const res = {}
潘际乾 committed
123
      //   const vals = row.split("\t");
zhengxiaokui committed
124 125 126 127
      // 	for (let i = 0; i < vals.length; i++) {
      // 		res[`${i}`] = vals[i];
      // 	}
      // 	return res;
潘际乾 committed
128
      // });
zhengxiaokui committed
129
      const arr = [];
潘际乾 committed
130
      for (let i = 0; i < this.list.length; i++) {
zhengxiaokui committed
131 132 133 134 135 136 137 138 139 140
        const d = this.list[i];
        const items = d.split("\t");
        const it = {};
        for (let j = 0; j < this.tableColumns.length; j++) {
          const column = this.tableColumns[j];
          it[column["prop"]] = column.children
            .map((c) => items[c["idx"]] || " ")
            .join("\n");
        }
        it["IDX"] = i;
141
        it['INR'] = items[0];
wangguangchao committed
142 143 144
        if(it['INR'].length < 8){
          it['INR'] = items[1];
        }
hulei committed
145
        it.srcStr = d;
zhengxiaokui committed
146
        arr.push(it);
潘际乾 committed
147
      }
zhengxiaokui committed
148
      return arr;
149 150 151 152
    },
  },
  data() {
    return {
zhengxiaokui committed
153 154
      currentPage: 1,
      pageSizes: [5, 10, 20, 30, 40, 50, 100],
liushikai committed
155
      pageSize: 10,
zhengxiaokui committed
156
    };
157 158
  },
  methods: {
zhengxiaokui committed
159 160 161 162 163 164
    sizeChange(size) {
      this.pageSize = size;
    },
    currentChange(currentPage) {
      this.currentPage = currentPage;
    },
潘际乾 committed
165
    handleSelectionChange(val) {
zhengxiaokui committed
166
      this.$emit("multipleSelect", this.getSelectedRowIndex(val));
潘际乾 committed
167 168
    },
    getRowKey(row) {
zhengxiaokui committed
169
      return row["IDX"];
潘际乾 committed
170 171
    },
    getSelectedRowIndex(val) {
zhengxiaokui committed
172
      const indexArr = [];
潘际乾 committed
173 174 175 176
      for (let j = 0; j < val.length; j++) {
        const v = val[j];
        for (let i = 0; i < this.tableData.length; i++) {
          const data = this.tableData[i];
zhengxiaokui committed
177 178 179
          if (v["IDX"] === data["IDX"]) {
            indexArr.push(i);
          }
潘际乾 committed
180 181
        }
      }
zhengxiaokui committed
182
      return indexArr;
潘际乾 committed
183 184 185 186
    },
    // 行点击,设置高亮
    rowClick(row, column, event) {
      this.$refs.table.setCurrentRow(row);
zhengxiaokui committed
187 188 189
      this.$emit("chooseRowEvent", row);
    },
  },
190 191 192 193
};
</script>

<style>
zhengxiaokui committed
194
.eContainer-table-block {
潘际乾 committed
195 196
  margin-top: 15px;
}
zhengxiaokui committed
197 198 199 200 201 202
.eContainer-table-block .paginationLable {
  font-size: 12px;
  color: #808080;
  height: 26px;
  line-height: 26px;
  float: right;
liushikai committed
203
  /* margin-top: 20px; */
204 205 206 207 208 209 210 211 212 213
}
.eContainer-table-block .el-table__body-wrapper {
  overflow: auto;
}
.el-table .warning-row {
  background: oldlace;
}
.el-table .success-row {
  background: #f0f9eb;
}
潘际乾 committed
214

zhengxiaokui committed
215 216
.eContainer-table-block .el-table .cell {
  white-space: pre-wrap;
潘际乾 committed
217
}
218
</style>