Commit 3793ae2f by 前端

table组件添加状态

1 parent de1428a6
<template>
<div :class="['gl-tab', 'gl-tab-' + type]">
<el-tabs ref="tab" v-bind="$attrs" v-on="$listeners">
<el-tab-pane v-for="(item, index) in tabPaneList" :key="index" v-bind="item" v-on="item.listeners">
<el-tabs ref="tab" :closable="closable" v-bind="$attrs" v-on="$listeners" @edit="removeTab">
<el-tab-pane v-for="(item, index) in list" :key="item.name" v-bind="item" v-on="item.listeners">
<span slot="label" style="padding: 0 10px">{{ item.label }}</span>
</el-tab-pane>
</el-tabs>
......@@ -14,7 +14,8 @@ export default {
data() {
return {
activeName: ''
activeName: '',
list: ''
}
},
......@@ -26,20 +27,50 @@ export default {
type: {
type: String,
default: ''
},
edit: {
type: Boolean,
default: false
}
},
// watch: {
// 'activeName.value'(val) {
// console.log(val)
// }
// },
watch: {
tabPaneList: {
handler(val) {
this.list = val
},
immediate: true
}
},
computed: {
closable() {
return this.type == 'card' && this.edit
}
},
mounted() {
this.activeName = this.$refs.tab
this.activeName = this.$refs.tab.activeName
},
methods: {}
methods: {
removeTab(targetName) {
let tabs = this.list
let activeName = this.activeName
if (activeName === targetName) {
tabs.forEach((tab, index) => {
if (tab.name === targetName) {
let nextTab = tabs[index + 1] || tabs[index - 1]
if (nextTab) {
activeName = nextTab.name
}
}
})
}
this.activeName = activeName
this.list = tabs.filter(tab => tab.name !== targetName)
}
}
}
</script>
......@@ -83,7 +114,7 @@ export default {
font-size: 14px;
color: #666666;
line-height: 40px;
background: #f8f8f8;
background: #fafafa;
border-radius: 4px 4px 0 0;
margin-right: 1px;
max-width: 140px;
......@@ -92,6 +123,10 @@ export default {
overflow: hidden;
padding: 0 10px !important;
}
.el-icon-close {
margin-left: -2px;
margin-right: 10px;
}
&__active-bar {
height: 0px;
background-color: transparent;
......@@ -110,8 +145,7 @@ export default {
.gl-tab-btn /deep/ .el-tabs {
.el-tabs__nav {
border-radius: 4px;
background: #F8F8F8;
background: #f8f8f8;
}
&__item {
&.is-active,
......@@ -128,7 +162,7 @@ export default {
color: #666666;
line-height: 36px;
}
&__active-bar {
height: 0px;
background-color: transparent;
......
......@@ -23,6 +23,10 @@
{{ item.formatter(scope.row) | tableCellFormat }}
</span>
</template>
<template v-else-if="item.enum">
<span v-if="item.colors" class="task_icon" :style="{ background: filterEnum(scope.row[item.prop], item.enum, item.searchProps,item.colors).color }"></span>
<span>{{ item.enum && filterEnum(scope.row[item.prop], item.enum, item.searchProps).label }}</span>
</template>
<template v-else-if="getListApi">
<el-popover v-if="scope.row[item.prop] && scope.row[item.prop].length >= Math.ceil((item.width - 36) / 14) * item.line" placement="top" popper-class="base-popper" trigger="hover" :content="scope.row[item.prop]">
<span slot="reference" class="line-ellipsis" :style="{ '-webkit-line-clamp': item.line ? item.line : '' }">
......@@ -54,7 +58,6 @@
<!-- 递归 -->
<sub-el-table-column v-if="item.children" :data="item.children" :tableData="tableData" :getListApi="getListApi"></sub-el-table-column>
</el-table-column>
<el-table-column class-name="gl-btns" v-if="tableParams.tableOption" label="操作" :align="tableParams.tableOption.align || 'left'" :width="tableParams.tableOption.width || '200'" fixed="right">
<template slot-scope="scope">
......@@ -77,12 +80,13 @@
<script>
import noDataImgUrl from '@/assets/empty.png'
import SubElTableColumn from './sub-el-table-column.vue'
import { filterEnum } from '../../../utils/index'
// import GlSubTableColumn from '../../GlSubTableColumn'
// import GlSubTable from '../../GlSubTable'
export default {
name: 'GLTable',
components: {
SubElTableColumn,
SubElTableColumn
// GlSubTableColumn,
// GlSubTable
},
......@@ -321,6 +325,9 @@ export default {
},
methods: {
filterEnum(callValue, enumData, searchProps,colors) {
return filterEnum(callValue, enumData, searchProps,colors)
},
findShowHeadCol() {
// findShowHeadCol事件
this.tableColumns = []
......@@ -454,6 +461,7 @@ export default {
},
mounted() {
console.log(filterEnum)
this.tableInit()
// 注册事件 -- 防抖
window.onresize = () => {
......@@ -483,7 +491,7 @@ export default {
.el-table .cell {
line-height: 1.2;
}
.gl-btns .el-button+.el-button {
.gl-btns .el-button + .el-button {
margin-left: 10px;
}
.glsx-table p {
......@@ -685,4 +693,28 @@ export default {
.el-table.hightline .el-table__fixed th.is-leaf:first-child {
border: none;
}
.task_icon {
width: 6px;
height: 6px;
border-radius: 50%;
display: inline-block;
vertical-align: middle;
margin-right: 8px;
background: #2cca74;
}
.green-icon {
&::after {
background: #2cca74;
}
}
.yellow-icon {
&::after {
background: #fdb757;
}
}
.gray-icon {
&::after {
background: #999;
}
}
</style>
/**
*
*
* @param {*} value 要判断的值
* @returns 值的类型
*/
export const objectType = (value) =>{
const res = Object.prototype.toString.call(value).slice(8,-1)
export const objectType = value => {
const res = Object.prototype.toString.call(value).slice(8, -1)
return res
}
export function filterEnum(callValue, enumData, searchProps, colors) {
const value = searchProps.value ? searchProps.value : 'value'
const label = searchProps.label ? searchProps.label : 'label'
let filterData = {}
let index = -1
let storage = {}
if (Array.isArray(enumData)) filterData = enumData.find(item => item[value] === callValue)
if (Array.isArray(colors)) index = enumData.findIndex(item => item[value] === callValue)
storage = {
label: filterData ? filterData[label] : '--',
color: index!=-1&&colors[index]
}
return storage
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!