console
new Vue({
el: '#app',
components: {},
props: [],
data() {
return {
ThArr: ["date", "name", "address"],
tableData: [
{
"innerCode": "001",
"date" : {
"value": "--",
"isSequenceIconShow": false,
"isSequenceSelected": false
},
"name" : {
"value": "--",
"isSequenceIconShow": false,
"isSequenceSelected": false
},
"address" : {
"value": "--",
"isSequenceIconShow": false,
"isSequenceSelected": false
},
},
{
"innerCode": "002",
"date" : {
"value": "--",
"isSequenceIconShow": false,
"isSequenceSelected": false
},
"name" : {
"value": "--",
"isSequenceIconShow": false,
"isSequenceSelected": false
},
"address" : {
"value": "--",
"isSequenceIconShow": false,
"isSequenceSelected": false
},
},
{
"innerCode": "003",
"date" : {
"value": "--",
"isSequenceIconShow": false,
"isSequenceSelected": false
},
"name" : {
"value": "--",
"isSequenceIconShow": false,
"isSequenceSelected": false
},
"address" : {
"value": "--",
"isSequenceIconShow": false,
"isSequenceSelected": false
},
},
],
currentSqueArr: [],
currentStockCode: '',
currentProp: ''
}
},
methods: {
cellMouseEnter(row, column, cell, event) {
let prop = column.property
this.$nextTick(() => {
row[prop].isSequenceIconShow = true
})
this.currentStockCode = row.innerCode
this.currentProp = prop
},
cellMouseLeave(row, column, cell, event) {
let isExisted = this.currentSqueArr.find(item => {
return item.prop === this.currentProp && item.stock === this.currentStockCode
})
if (!isExisted) {
this.hideCurSqueIcon(row, column)
}
},
hideCurSqueIcon(row, column) {
let prop = column.property
this.$nextTick(() => {
row[prop].isSequenceIconShow = false
row[prop].isSequenceSelected = false
})
},
activeSquesIcon() {
let curIndex = this.tableData.findIndex(item => item.innerCode === this.currentStockCode)
let curStockObj = this.tableData[curIndex]
this.$nextTick(() => {
curStockObj[this.currentProp].isSequenceSelected = true
})
},
async hideAllSquesIcon() {
console.log('隐藏所有时序图icon')
if (this.currentSqueArr.length <= 2) {
let index = this.tableData.findIndex(item => item.innerCode === this.currentSqueArr[0].stock)
let row = this.tableData[index]
let prop = this.currentSqueArr[0].prop
await this.$nextTick(() => {
row[prop].isSequenceSelected = false
row[prop].isSequenceIconShow = false
})
console.log('时序图长度小于等于2')
}
else {
if (this.currentSqueArr[0].stock === this.currentSqueArr[1].stock) {
let index = this.tableData.findIndex(item => item.innerCode === this.currentSqueArr[0].stock)
let row = this.tableData[index]
await this.$nextTick(() => {
this.currentSqueArr.forEach(item => {
row[item.prop].isSequenceSelected = false
row[item.prop].isSequenceIconShow = false
})
})
console.log('取消之前一行的icon选中状态')
}
else if (this.currentSqueArr[0].prop === this.currentSqueArr[1].prop) {
await this.$nextTick(() => {
this.tableData.forEach(item => {
item[this.currentSqueArr[0].prop].isSequenceSelected = false
item[this.currentSqueArr[0].prop].isSequenceIconShow = false
})
})
console.log('取消之前一列的icon选中状态')
}
}
},
async clickSequenceIcon() {
let currentCell = {
prop: this.currentProp,
stock: this.currentStockCode
}
let isExistedIndex = this.currentSqueArr.findIndex(item => {
return item.prop === this.currentProp && item.stock === this.currentStockCode
})
if (this.currentSqueArr.length === 0) {
console.log('第一次点击的元素,直接添加进数组')
this.currentSqueArr.push(currentCell)
this.activeSquesIcon()
}
else if (isExistedIndex !== -1) {
await this.deleteCurSqueItem(this.currentProp, this.currentStockCode, isExistedIndex)
}
else if (this.currentSqueArr.length >= 6) {
alert('最多展示6个标的的时序图')
}
else {
this.currentSqueArr.push(currentCell)
if (this.currentSqueArr[0].prop === this.currentSqueArr[1].prop) {
if (this.currentProp === this.currentSqueArr[0].prop) {
this.activeSquesIcon()
} else {
await this.hideAllSquesIcon()
this.currentSqueArr = []
this.currentSqueArr.push(currentCell)
this.activeSquesIcon()
}
}
else if (this.currentSqueArr[0].stock === this.currentSqueArr[1].stock) {
if (this.currentStockCode === this.currentSqueArr[0].stock) {
this.activeSquesIcon()
} else {
await this.hideAllSquesIcon()
this.currentSqueArr = []
this.currentSqueArr.push(currentCell)
this.activeSquesIcon()
}
}
else {
await this.hideAllSquesIcon()
console.error('既不同行也不同列:删除时序图数组')
this.currentSqueArr = []
this.currentSqueArr.push(currentCell)
this.activeSquesIcon()
}
}
console.log('当前的时序图数组为:')
console.log( this.currentSqueArr)
},
}
})
<script src="https://cdn.bootcss.com/vue/2.6.10/vue.js"></script>
<script src="https://cdn.bootcss.com/vuex/3.1.1/vuex.js"></script>
<link href="https://cdn.bootcss.com/element-ui/2.12.0/theme-chalk/index.css" rel="stylesheet">
<script src="https://cdn.bootcss.com/element-ui/2.12.0/index.js"></script>
<div id="app">
<el-table
:data="tableData"
@cell-mouse-enter="cellMouseEnter"
@cell-mouse-leave="cellMouseLeave"
style="width: 100%">
<el-table-column
v-for="(item,index) in ThArr"
:prop="item"
:label="item"
width="180">
<template slot-scope="scope">
<i class="iconfont icon-charts_line" @click="clickSequenceIcon" v-show="scope.row[item].isSequenceIconShow" :class="{isSelected: scope.row[item].isSequenceSelected}"></i>
<span class="ellipsis-line">{{ scope.row[item].value }}</span>
</template>
</el-table-column>
</el-table>
</div>
.pointer{
cursor: pointer;
}
.red-font{
color: #f00;
}
.icon-charts_line {
cursor: pointer;
}
.isSelected {
color: red;
}