Commit 75e5793a authored by 何虹's avatar 何虹 💬

表格合并项

parent 15968f71
......@@ -108,7 +108,7 @@ export default {
const list = [
{
label: '配置(用户)',
isShow: true,
isShow: false,
onClick: () => {
this.userSysSet('1')
}
......@@ -177,13 +177,11 @@ export default {
if (
top === self &&
(hostname === '0.0.0.0' || hostname === 'localhost')
)
return true
) { return true }
if (
top !== self &&
(hostname !== '0.0.0.0' || hostname !== 'localhost')
)
return false
) { return false }
}
},
getIsDev() {
......@@ -195,21 +193,18 @@ export default {
systemSysDevDb === true ||
systemSysDevDb === '1' ||
systemSysDevDb === 1
)
return true
) { return true }
} else {
// 这是在本地开发时使用没有user_info时
const hostname = location.hostname
if (
top === self &&
(hostname === '0.0.0.0' || hostname === 'localhost')
)
return true
) { return true }
if (
top !== self &&
(hostname !== '0.0.0.0' || hostname !== 'localhost')
)
return false
) { return false }
}
},
onContextmenu(event) {
......
......@@ -53,7 +53,7 @@
:row-style='setRowStyle'
:cell-style="setCellStyle"
@header-click="headerClick"
:span-method="spanMethod"
:span-method="objectSpanMethod"
>
<template v-for='(columnItem,index) in tableColumns'>
......@@ -507,7 +507,7 @@ export default {
const list = [
{
label: '配置(用户)',
isShow: true,
isShow: false,
onClick: () => {
// this.userSysSet('1')
this.userSysTableColumnSet('1')
......@@ -578,7 +578,7 @@ export default {
},
// 表格配置
tableConfig() {
return this.config
return this.config || []
},
// 表格列
tableColumns() {
......@@ -597,8 +597,8 @@ export default {
const sumKey = this.tableColumns.find(item => item.summarizing)
return !!tkeys.length || !!sumKey
},
spanList: function() {
return this.dealWithSpanList()
spanArrConfig: function() {
return this.dealwithMergeCellsConfig()
}
},
mounted() {
......@@ -606,62 +606,66 @@ export default {
this.targetDom = this.$refs.boxtable
},
methods: {
getSpanArr(data, key1, key2) {
const spanList = []
getSpanArr(data, spanArrConfig) {
spanArrConfig.forEach(item => {
const { calculatedColumns } = item
let pos = 0
for (let i = 0; i < data.length; i++) {
for (var i = 0; i < data.length; i++) {
if (i === 0) {
spanList.push(1)
item.list.push(1)
pos = 0
} else {
if (key2) {
if (
data[i][key2] === data[i - 1][key2] &&
data[i][key1] === data[i - 1][key1]
) {
spanList[pos] += 1
spanList.push(0)
} else {
spanList.push(1)
pos = i
}
} else {
// 判断当前元素与上一个元素是否相同
if (data[i][key1] === data[i - 1][key1]) {
spanList[pos] += 1
spanList.push(0)
const dataI = data[i]
const dataIi = data[i - 1]
let sumObjdataI = ''
let sumObjdataIi = ''
calculatedColumns.forEach(k => {
sumObjdataI += dataI[k]
sumObjdataIi += dataIi[k]
})
if (sumObjdataI === sumObjdataIi) {
item.list[pos] += 1
item.list.push(0)
} else {
spanList.push(1)
item.list.push(1)
pos = i
}
}
}
}
return spanList
},
dealWithSpanList() {
const spanList = {}
const tableData = _.cloneDeep(this.tableDat || [])
const config = _.cloneDeep(this.tableConfig || {})
if (config.spanCol) {
let spanCol = config.spanCol
spanCol.forEach(key => {
if (key.indexOf('^') > -1) {
const key1 = key.split('^')[0]
const key2 = key.split('^')[1]
spanList[key1] = this.getSpanArr(tableData, key1, key2)
} else {
spanList[key] = this.getSpanArr(tableData, key)
}
})
}
return spanList
return spanArrConfig
},
dealwithMergeCellsConfig() {
const SpanArrConfig = this.tableConfig.mergeCellsConfig || []
const list = this.transSpanArrConfig(SpanArrConfig)
return this.getSpanArr(this.tableData, list)
},
transSpanArrConfig(SpanArrConfig) {
const list = []
SpanArrConfig.forEach(item => {
const [item0, item1] = item.split('=')
const targetPropList = item0.split(',')
targetPropList.forEach(targetProp => {
const item1_ = item1 || item0
const targetcalculatedList = item1_.split('+')
if (!targetcalculatedList.includes(targetProp)) {
targetcalculatedList.push(targetProp)
}
list.push({
list: [],
targetColumnProp: targetProp, // 目标列
calculatedColumns: targetcalculatedList// 要计算的列
})
})
})
return list
},
spanMethod({ row, column, rowIndex, columnIndex }) {
const prop = column.property
const target = this.spanList[prop]
if (target && target.length) {
const _row = target[rowIndex]
objectSpanMethod({ row, column, rowIndex, columnIndex }) {
const property = column.property
const target = this.spanArrConfig.find(x => x.targetColumnProp === property)
if (target) {
const _row = target.list[rowIndex]
const _col = _row > 0 ? 1 : 0
return {
rowspan: _row,
......@@ -669,6 +673,7 @@ export default {
}
}
},
getIsAdmin() {
const user_info = sessionStorage['user_info']
if (user_info) {
......@@ -681,13 +686,11 @@ export default {
if (
top === self &&
(hostname === '0.0.0.0' || hostname === 'localhost')
)
return true
) { return true }
if (
top !== self &&
(hostname !== '0.0.0.0' || hostname !== 'localhost')
)
return false
) { return false }
}
},
getIsDev() {
......@@ -710,13 +713,11 @@ export default {
if (
top === self &&
(hostname === '0.0.0.0' || hostname === 'localhost')
)
return true
) { return true }
if (
top !== self &&
(hostname !== '0.0.0.0' || hostname !== 'localhost')
)
return false
) { return false }
}
},
onContextmenu(event) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment