Commit 3793ae2f by 前端

table组件添加状态

1 parent de1428a6
<template> <template>
<div :class="['gl-tab', 'gl-tab-' + type]"> <div :class="['gl-tab', 'gl-tab-' + type]">
<el-tabs ref="tab" v-bind="$attrs" v-on="$listeners"> <el-tabs ref="tab" :closable="closable" v-bind="$attrs" v-on="$listeners" @edit="removeTab">
<el-tab-pane v-for="(item, index) in tabPaneList" :key="index" v-bind="item" v-on="item.listeners"> <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> <span slot="label" style="padding: 0 10px">{{ item.label }}</span>
</el-tab-pane> </el-tab-pane>
</el-tabs> </el-tabs>
...@@ -14,7 +14,8 @@ export default { ...@@ -14,7 +14,8 @@ export default {
data() { data() {
return { return {
activeName: '' activeName: '',
list: ''
} }
}, },
...@@ -26,20 +27,50 @@ export default { ...@@ -26,20 +27,50 @@ export default {
type: { type: {
type: String, type: String,
default: '' default: ''
},
edit: {
type: Boolean,
default: false
} }
}, },
// watch: { watch: {
// 'activeName.value'(val) { tabPaneList: {
// console.log(val) handler(val) {
// } this.list = val
// }, },
immediate: true
}
},
computed: {
closable() {
return this.type == 'card' && this.edit
}
},
mounted() { 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> </script>
...@@ -83,7 +114,7 @@ export default { ...@@ -83,7 +114,7 @@ export default {
font-size: 14px; font-size: 14px;
color: #666666; color: #666666;
line-height: 40px; line-height: 40px;
background: #f8f8f8; background: #fafafa;
border-radius: 4px 4px 0 0; border-radius: 4px 4px 0 0;
margin-right: 1px; margin-right: 1px;
max-width: 140px; max-width: 140px;
...@@ -92,6 +123,10 @@ export default { ...@@ -92,6 +123,10 @@ export default {
overflow: hidden; overflow: hidden;
padding: 0 10px !important; padding: 0 10px !important;
} }
.el-icon-close {
margin-left: -2px;
margin-right: 10px;
}
&__active-bar { &__active-bar {
height: 0px; height: 0px;
background-color: transparent; background-color: transparent;
...@@ -110,8 +145,7 @@ export default { ...@@ -110,8 +145,7 @@ export default {
.gl-tab-btn /deep/ .el-tabs { .gl-tab-btn /deep/ .el-tabs {
.el-tabs__nav { .el-tabs__nav {
border-radius: 4px; border-radius: 4px;
background: #F8F8F8; background: #f8f8f8;
} }
&__item { &__item {
&.is-active, &.is-active,
......
...@@ -23,6 +23,10 @@ ...@@ -23,6 +23,10 @@
{{ item.formatter(scope.row) | tableCellFormat }} {{ item.formatter(scope.row) | tableCellFormat }}
</span> </span>
</template> </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"> <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]"> <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 : '' }"> <span slot="reference" class="line-ellipsis" :style="{ '-webkit-line-clamp': item.line ? item.line : '' }">
...@@ -54,7 +58,6 @@ ...@@ -54,7 +58,6 @@
<!-- 递归 --> <!-- 递归 -->
<sub-el-table-column v-if="item.children" :data="item.children" :tableData="tableData" :getListApi="getListApi"></sub-el-table-column> <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>
<el-table-column class-name="gl-btns" v-if="tableParams.tableOption" label="操作" :align="tableParams.tableOption.align || 'left'" :width="tableParams.tableOption.width || '200'" fixed="right"> <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"> <template slot-scope="scope">
...@@ -77,12 +80,13 @@ ...@@ -77,12 +80,13 @@
<script> <script>
import noDataImgUrl from '@/assets/empty.png' import noDataImgUrl from '@/assets/empty.png'
import SubElTableColumn from './sub-el-table-column.vue' import SubElTableColumn from './sub-el-table-column.vue'
import { filterEnum } from '../../../utils/index'
// import GlSubTableColumn from '../../GlSubTableColumn' // import GlSubTableColumn from '../../GlSubTableColumn'
// import GlSubTable from '../../GlSubTable' // import GlSubTable from '../../GlSubTable'
export default { export default {
name: 'GLTable', name: 'GLTable',
components: { components: {
SubElTableColumn, SubElTableColumn
// GlSubTableColumn, // GlSubTableColumn,
// GlSubTable // GlSubTable
}, },
...@@ -321,6 +325,9 @@ export default { ...@@ -321,6 +325,9 @@ export default {
}, },
methods: { methods: {
filterEnum(callValue, enumData, searchProps,colors) {
return filterEnum(callValue, enumData, searchProps,colors)
},
findShowHeadCol() { findShowHeadCol() {
// findShowHeadCol事件 // findShowHeadCol事件
this.tableColumns = [] this.tableColumns = []
...@@ -454,6 +461,7 @@ export default { ...@@ -454,6 +461,7 @@ export default {
}, },
mounted() { mounted() {
console.log(filterEnum)
this.tableInit() this.tableInit()
// 注册事件 -- 防抖 // 注册事件 -- 防抖
window.onresize = () => { window.onresize = () => {
...@@ -483,7 +491,7 @@ export default { ...@@ -483,7 +491,7 @@ export default {
.el-table .cell { .el-table .cell {
line-height: 1.2; line-height: 1.2;
} }
.gl-btns .el-button+.el-button { .gl-btns .el-button + .el-button {
margin-left: 10px; margin-left: 10px;
} }
.glsx-table p { .glsx-table p {
...@@ -685,4 +693,28 @@ export default { ...@@ -685,4 +693,28 @@ export default {
.el-table.hightline .el-table__fixed th.is-leaf:first-child { .el-table.hightline .el-table__fixed th.is-leaf:first-child {
border: none; 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> </style>
...@@ -3,7 +3,22 @@ ...@@ -3,7 +3,22 @@
* @param {*} value 要判断的值 * @param {*} value 要判断的值
* @returns 值的类型 * @returns 值的类型
*/ */
export const objectType = (value) =>{ export const objectType = value => {
const res = Object.prototype.toString.call(value).slice(8,-1) const res = Object.prototype.toString.call(value).slice(8, -1)
return res 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!