Files
dvcp_v2_webapp/ui/dv/layout/AiDvTable/AiDvTable.vue

341 lines
7.0 KiB
Vue
Raw Normal View History

2023-03-08 15:45:56 +08:00
<template>
2024-01-16 02:53:07 +08:00
<section class="AiDvTable">
2024-03-25 13:48:28 +08:00
<el-table v-if="simple" class="simple" :data="tableData" max-height="calc(100% - 40px)">
<el-table-column v-for="item in columns" :key="item.prop" v-bind="item">
<template v-slot="{row}">
<div :style="{color:item.color}" v-text="row[item.prop]"/>
</template>
</el-table-column>
2024-01-16 02:53:07 +08:00
</el-table>
<div v-else class="aiDvTable" :class="'aiDvTable-' + theme + ' aiDvTable-' + size">
<div class="header" :style="headerStyle">
2023-03-08 17:03:00 +08:00
<span
2024-01-16 02:53:07 +08:00
v-for="(item, index) in header"
:key="index"
:style="{
2023-03-15 15:18:19 +08:00
width: config[index].width ? config[index].width + 'px' : '',
textAlign: config[index].align,
flex: config[index].width ? 'inherit' : 1
2023-03-08 17:16:03 +08:00
}">
2023-03-08 17:03:00 +08:00
{{ item.v }}
</span>
2024-01-16 02:53:07 +08:00
</div>
<div class="body">
<div class="row" v-for="(item, index) in body" :class="[stripe === '1' ? 'stripe' : '']" :key="index">
<div
v-for="(column, i) in item"
:key="i"
:style="{
2023-03-15 15:18:19 +08:00
color: config[i].color,
textAlign: config[i].align,
2023-04-24 10:34:41 +08:00
fontSize: config[i].fontSize,
2023-03-15 15:18:19 +08:00
width: config[i].width ? config[i].width + 'px' : '',
flex: config[i].width ? 'inherit' : 1
2023-03-08 17:32:42 +08:00
}">
2024-01-16 02:53:07 +08:00
<i v-if="isShowIndex === '1' && i === 0">{{ index + 1 }}</i>
<render-slot
v-if="config[i].render"
:render="config[i].render"
:row="item"
:column="column">
</render-slot>
<span v-else :title="column" @click="onClick(config[i], item)">{{ column }}</span>
</div>
2023-03-08 17:03:00 +08:00
</div>
2023-03-08 15:45:56 +08:00
</div>
</div>
2024-01-16 02:53:07 +08:00
</section>
2023-03-08 15:45:56 +08:00
</template>
<script>
2024-03-25 13:48:28 +08:00
2024-01-16 02:53:07 +08:00
export default {
name: 'AiDvTable',
components: {
renderSlot: {
functional: true,
props: {
render: Function,
column: {type: [String, Number]},
row: {type: [Array, Object]},
},
render: (h, data) => {
let params = {
row: data.props.row
}
if (data.props.column) {
params.column = data.props.column
2023-04-25 16:01:09 +08:00
}
2024-01-16 02:53:07 +08:00
return data.props.render(h, params)
2023-04-25 16:01:09 +08:00
}
2024-01-16 02:53:07 +08:00
}
},
props: {
data: {
type: Array,
default: () => []
2023-03-08 15:45:56 +08:00
},
2024-01-16 02:53:07 +08:00
headerStyle: {
type: Object,
default: () => {
2023-03-08 15:45:56 +08:00
}
},
2024-01-16 02:53:07 +08:00
isShowIndex: {
type: String,
default: '0'
2023-03-08 15:45:56 +08:00
},
2024-01-16 02:53:07 +08:00
stripe: {
type: String,
default: '1'
2023-03-08 15:45:56 +08:00
},
2024-01-16 02:53:07 +08:00
theme: {
type: String,
default: '0'
},
2023-03-08 15:45:56 +08:00
2024-01-16 02:53:07 +08:00
config: {
type: Array,
default: () => []
},
2023-03-08 17:03:00 +08:00
2024-01-16 02:53:07 +08:00
size: {
type: String,
default: 'small'
},
simple: Boolean
},
data() {
return {
header: [],
body: []
}
},
computed: {
columns: v => v.header.map((e, i) => {
let item = {}
Object.values(e).forEach(label => {
2024-03-25 13:48:28 +08:00
const {align, width, color} = v.config[i]
2024-01-16 02:53:07 +08:00
item.align = align
item.prop = `col${i}`
item.label = label
2024-03-25 13:48:28 +08:00
item.width = width
item.color = color
2024-01-16 02:53:07 +08:00
})
return item
}),
tableData: v => v.body.map(arr => {
const item = {}
Object.values(arr).forEach((value, i) => {
item[`col${i}`] = value
})
return item
})
},
watch: {
data: {
handler(v) {
this.init(v)
2023-04-25 16:01:09 +08:00
},
2024-01-16 02:53:07 +08:00
deep: true,
immediate: true
}
},
methods: {
init(value) {
if (!value.length) {
this.header = []
this.body = []
return false
}
const headerKey = Object.keys(value[0])[0]
const bodyKey = Object.keys(value[0]).filter(v => {
return v !== headerKey
})
2023-04-25 16:01:09 +08:00
2024-01-16 02:53:07 +08:00
this.header = value.map(v => {
return {
v: v[headerKey]
2023-04-25 16:01:09 +08:00
}
2024-01-16 02:53:07 +08:00
})
this.body = bodyKey.map(v => {
return value.map(e => e[v])
})
},
onClick(config, e) {
if (config.click && typeof config.click === 'function') {
return config.click.call(this, e)
2023-03-08 15:45:56 +08:00
}
2024-01-16 02:53:07 +08:00
},
2023-03-08 15:45:56 +08:00
}
2024-01-16 02:53:07 +08:00
}
2023-03-08 15:45:56 +08:00
</script>
<style lang="scss" scoped>
2024-01-16 02:53:07 +08:00
@import "../../dv";
2023-03-10 17:15:31 +08:00
2024-03-25 13:48:28 +08:00
.AiDvTable {
height: 100%;
}
2024-01-16 02:53:07 +08:00
.aiDvTable {
height: 100%;
overflow: hidden;
2023-03-10 17:15:31 +08:00
2024-01-16 02:53:07 +08:00
::-webkit-scrollbar {
width: 5px;
height: 14px;
}
2023-03-10 17:15:31 +08:00
2024-01-16 02:53:07 +08:00
::-webkit-scrollbar-corner {
background: transparent;
}
2023-03-10 17:15:31 +08:00
2024-01-16 02:53:07 +08:00
::-webkit-scrollbar-thumb {
min-height: 20px;
background-clip: content-box;
box-shadow: 0 0 0 5px rgba(116, 148, 170, 0.5) inset;
}
::-webkit-scrollbar-track {
box-shadow: 1px 1px 5px rgba(116, 148, 170, 0.5) inset;
}
.header {
display: flex;
align-items: center;
width: 100%;
height: 40px;
font-size: 16px;
padding: 0 16px;
color: rgba(255, 255, 255, 0.7);
background: rgba(70, 70, 70, 0.35);
span {
flex: 1;
text-align: center;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
-o-text-overflow: ellipsis;
&:first-child {
text-align: left;
}
2023-03-10 17:15:31 +08:00
}
2024-01-16 02:53:07 +08:00
}
2023-03-10 17:15:31 +08:00
2024-01-16 02:53:07 +08:00
.body {
height: calc(100% - 40px);
padding: 10px 0;
overflow-y: auto;
box-sizing: border-box;
.row {
2023-03-08 15:45:56 +08:00
display: flex;
align-items: center;
width: 100%;
2024-01-16 02:53:07 +08:00
height: 52px;
2023-03-10 10:05:02 +08:00
padding: 0 16px;
2024-01-16 02:53:07 +08:00
box-sizing: border-box;
&.stripe:nth-of-type(2n) {
background: rgba(48, 48, 48, 0.4);
}
2023-03-08 15:45:56 +08:00
2024-01-16 02:53:07 +08:00
div {
display: flex;
align-items: center;
justify-content: center;
2023-03-08 15:45:56 +08:00
flex: 1;
2024-01-16 02:53:07 +08:00
font-size: 16px;
2023-03-08 15:45:56 +08:00
text-align: center;
2024-01-16 02:53:07 +08:00
color: #ffffff;
2023-03-08 15:45:56 +08:00
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
2024-01-16 02:53:07 +08:00
-o-text-overflow: ellipsis;
2023-03-08 15:45:56 +08:00
2024-01-16 02:53:07 +08:00
span {
2023-03-08 15:45:56 +08:00
flex: 1;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
2024-01-16 02:53:07 +08:00
-o-text-overflow: ellipsis;
}
i {
width: 20px;
height: 20px;
line-height: 20px;
margin-right: 10px;
text-align: center;
font-size: 12px;
color: #18FEFE;
font-style: normal;
background: url(./asset/rankbg.png) no-repeat;
background-size: 100% 100%;
}
&:first-child {
justify-content: start;
text-align: left;
2023-03-08 15:45:56 +08:00
}
}
}
2024-01-16 02:53:07 +08:00
}
2023-03-10 17:15:31 +08:00
2024-01-16 02:53:07 +08:00
&.aiDvTable-mini {
.header {
height: 36px;
}
2023-04-25 14:32:47 +08:00
2024-01-16 02:53:07 +08:00
.row {
height: 40px;
2023-04-25 14:32:47 +08:00
}
2024-01-16 02:53:07 +08:00
}
2023-04-25 14:32:47 +08:00
2024-01-16 02:53:07 +08:00
&.aiDvTable-1 {
::-webkit-scrollbar {
width: 5px;
height: 14px;
}
2023-03-10 17:15:31 +08:00
2024-01-16 02:53:07 +08:00
::-webkit-scrollbar-corner {
background: transparent;
}
2023-03-10 17:15:31 +08:00
2024-01-16 02:53:07 +08:00
::-webkit-scrollbar-thumb {
min-height: 20px;
background-clip: content-box;
box-shadow: 0 0 0 5px rgba(250, 181, 108, 0.5) inset;
}
2023-03-10 17:15:31 +08:00
2024-01-16 02:53:07 +08:00
::-webkit-scrollbar-track {
box-shadow: 1px 1px 5px rgba(50, 181, 108, 0.5) inset;
}
2023-03-10 17:15:31 +08:00
2024-01-16 02:53:07 +08:00
.header {
background: rgba(226, 121, 81, 0.2);
}
.body {
div {
i {
color: #FFA086;
background: url(./asset/rankbg-dj.png) no-repeat;
background-size: 100% 100%;
2023-03-10 17:15:31 +08:00
}
}
}
2023-03-08 15:45:56 +08:00
}
2024-01-16 02:53:07 +08:00
}
2023-03-08 15:45:56 +08:00
</style>