|
|
@@ -1,26 +1,67 @@
|
|
|
<template>
|
|
|
<div>
|
|
|
<!-- :header-cell-style="{background:'#EEEEEE',color:'#333'}" -->
|
|
|
- <el-table ref="table" :row-class-name="tableClassName" highlight-current-row :data="data" size="mini" :height="height ? height : data.length <= 5?'280px':'calc(100vh - 268px)'" @row-click="rowClick" :style="{width:'100%',minHeight:minHeight?minHeight:''}" :header-cell-style="{background:'#fafafafa',height:'40px',color:'#000000',fontSize:'12px'}"
|
|
|
- :cell-style="{height:'40px',color:'#666666',fontWeight:'400'}" border @selection-change="selectionChange"
|
|
|
- :row-key="rowKey"
|
|
|
- >
|
|
|
- <el-table-column
|
|
|
- type="selection"
|
|
|
- width="35" fixed v-if="checkbox">
|
|
|
+ <el-table
|
|
|
+ ref="table"
|
|
|
+ :row-class-name="tableClassName"
|
|
|
+ highlight-current-row
|
|
|
+ :data="data"
|
|
|
+ size="mini"
|
|
|
+ :height="
|
|
|
+ height ? height : data.length <= 5 ? '280px' : 'calc(100vh - 268px)'
|
|
|
+ "
|
|
|
+ :fit="tool.calculatedColumnWidth($refs.table, layout)"
|
|
|
+ @row-click="rowClick"
|
|
|
+ :style="{ width: '100%', minHeight: minHeight ? minHeight : '' }"
|
|
|
+ :header-cell-style="{
|
|
|
+ background: '#fafafafa',
|
|
|
+ height: '40px',
|
|
|
+ color: '#000000',
|
|
|
+ fontSize: '12px',
|
|
|
+ }"
|
|
|
+ :cell-style="{ height: '40px', color: '#666666', fontWeight: '400' }"
|
|
|
+ border
|
|
|
+ @selection-change="selectionChange"
|
|
|
+ :row-key="rowKey"
|
|
|
+ >
|
|
|
+ <el-table-column type="selection" width="35" fixed v-if="checkbox">
|
|
|
</el-table-column>
|
|
|
- <el-table-column show-overflow-tooltip v-for="(col,index) in layout" :key="col.tablecolid" :prop="col.columnname" :label="col.title" :min-width="tool.calcTableColWidth($refs.table,layout,index)" :fixed="fixedName ? fixedName.indexOf(col.columnname)!= -1?redirect ? redirect : 'right' :false : false">
|
|
|
- <template v-slot:header="{ column,$index }" v-if="customHeader">
|
|
|
+ <el-table-column
|
|
|
+ show-overflow-tooltip
|
|
|
+ v-for="(col, index) in layout"
|
|
|
+ :key="col.tablecolid"
|
|
|
+ :prop="col.columnname"
|
|
|
+ :label="col.title"
|
|
|
+ :min-width="col.width || 150"
|
|
|
+ :fixed="
|
|
|
+ fixedName
|
|
|
+ ? fixedName.indexOf(col.columnname) != -1
|
|
|
+ ? redirect
|
|
|
+ ? redirect
|
|
|
+ : 'right'
|
|
|
+ : false
|
|
|
+ : false
|
|
|
+ "
|
|
|
+ >
|
|
|
+ <template v-slot:header="{ column, $index }" v-if="customHeader">
|
|
|
<slot name="header" :data="column"></slot>
|
|
|
</template>
|
|
|
<template slot-scope="scope">
|
|
|
<div class="table-panel">
|
|
|
<!-- 自定义表格显示内容 -->
|
|
|
- <slot v-if="custom" name="customcol" :column="{data:scope.row,columnname:col.columnname}"></slot>
|
|
|
+ <slot
|
|
|
+ v-if="custom"
|
|
|
+ name="customcol"
|
|
|
+ :column="{ data: scope.row, columnname: col.columnname }"
|
|
|
+ ></slot>
|
|
|
<!-- 否则就是默认 -->
|
|
|
- <span v-else>{{scope.row[col.columnname]}}</span>
|
|
|
+ <span v-else>{{ scope.row[col.columnname] }}</span>
|
|
|
<!-- 操作结构内容 -->
|
|
|
- <slot v-if="col.columnname === 'operation'" name="opreation" :data="scope.row"></slot>
|
|
|
+ <slot
|
|
|
+ v-if="col.columnname === 'operation'"
|
|
|
+ name="opreation"
|
|
|
+ :data="scope.row"
|
|
|
+ ></slot>
|
|
|
</div>
|
|
|
</template>
|
|
|
</el-table-column>
|
|
|
@@ -29,8 +70,8 @@
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
-import {mapGetters} from "vuex"
|
|
|
-import Sortable from 'sortablejs'
|
|
|
+import { mapGetters } from "vuex";
|
|
|
+import Sortable from "sortablejs";
|
|
|
export default {
|
|
|
/*
|
|
|
layout:表结构数据;
|
|
|
@@ -38,63 +79,76 @@ export default {
|
|
|
custom:是否启用自定义结构;
|
|
|
opwidth:操作列宽度
|
|
|
*/
|
|
|
- props:['layout','data','custom','height','fixedName','width','checkbox','redirect','customHeader','minHeight','rowKey'],
|
|
|
- data () {
|
|
|
+ props: [
|
|
|
+ "layout",
|
|
|
+ "data",
|
|
|
+ "custom",
|
|
|
+ "height",
|
|
|
+ "fixedName",
|
|
|
+ "width",
|
|
|
+ "checkbox",
|
|
|
+ "redirect",
|
|
|
+ "customHeader",
|
|
|
+ "minHeight",
|
|
|
+ "rowKey",
|
|
|
+ ],
|
|
|
+ data() {
|
|
|
return {
|
|
|
- list:[],
|
|
|
- isCopy:true,
|
|
|
- isRowSort:true,
|
|
|
- highlightCurrentRow:[],
|
|
|
- isShowTreeStyle:true
|
|
|
- }
|
|
|
+ list: [],
|
|
|
+ isCopy: true,
|
|
|
+ isRowSort: true,
|
|
|
+ highlightCurrentRow: [],
|
|
|
+ isShowTreeStyle: true,
|
|
|
+ };
|
|
|
},
|
|
|
- computed:{
|
|
|
+ computed: {
|
|
|
...mapGetters({
|
|
|
- loading:'loading'
|
|
|
- })
|
|
|
+ loading: "loading",
|
|
|
+ }),
|
|
|
},
|
|
|
- watch:{
|
|
|
- data(val){
|
|
|
- this.doLayout()
|
|
|
- }
|
|
|
+ watch: {
|
|
|
+ data(val) {
|
|
|
+ this.doLayout();
|
|
|
+ },
|
|
|
},
|
|
|
- methods:{
|
|
|
- rowClick (row) {
|
|
|
- this.$emit('rowClick',row)
|
|
|
+ methods: {
|
|
|
+ rowClick(row) {
|
|
|
+ this.$emit("rowClick", row);
|
|
|
},
|
|
|
- tableClassName ({row,rowIndex}) {
|
|
|
- row.index = rowIndex
|
|
|
+ tableClassName({ row, rowIndex }) {
|
|
|
+ row.index = rowIndex;
|
|
|
},
|
|
|
- selectionChange(row){
|
|
|
- this.$emit('selectionChange',row)
|
|
|
+ selectionChange(row) {
|
|
|
+ this.$emit("selectionChange", row);
|
|
|
},
|
|
|
- doLayout(){
|
|
|
- if (this.$refs.table){
|
|
|
- this.$nextTick(()=>{
|
|
|
- this.$refs.table.doLayout()
|
|
|
- })
|
|
|
+ doLayout() {
|
|
|
+ if (this.$refs.table) {
|
|
|
+ this.$nextTick(() => {
|
|
|
+ this.$refs.table.doLayout();
|
|
|
+ });
|
|
|
}
|
|
|
},
|
|
|
initSort() {
|
|
|
- if (!this.isRowSort) return
|
|
|
- const el = this.$refs['table'].$el.querySelector('.el-table__body-wrapper > table > tbody')
|
|
|
+ if (!this.isRowSort) return;
|
|
|
+ const el = this.$refs["table"].$el.querySelector(
|
|
|
+ ".el-table__body-wrapper > table > tbody"
|
|
|
+ );
|
|
|
new Sortable(el, {
|
|
|
animation: 150, // 动画
|
|
|
- onEnd: evt => {
|
|
|
- const curRow = this.data.splice(evt.oldIndex, 1)[0]
|
|
|
- this.$nextTick(()=>{
|
|
|
- this.data.splice(evt.newIndex, 0, curRow)
|
|
|
- this.$emit('rowSort', this.data)
|
|
|
- })
|
|
|
- }
|
|
|
- })
|
|
|
- }
|
|
|
+ onEnd: (evt) => {
|
|
|
+ const curRow = this.data.splice(evt.oldIndex, 1)[0];
|
|
|
+ this.$nextTick(() => {
|
|
|
+ this.data.splice(evt.newIndex, 0, curRow);
|
|
|
+ this.$emit("rowSort", this.data);
|
|
|
+ });
|
|
|
+ },
|
|
|
+ });
|
|
|
+ },
|
|
|
},
|
|
|
- mounted () {
|
|
|
- this.initSort()
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
+ mounted() {
|
|
|
+ this.initSort();
|
|
|
+ },
|
|
|
+};
|
|
|
</script>
|
|
|
<style>
|
|
|
</style>
|