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

表格合并项

parent 15968f71
...@@ -108,7 +108,7 @@ export default { ...@@ -108,7 +108,7 @@ export default {
const list = [ const list = [
{ {
label: '配置(用户)', label: '配置(用户)',
isShow: true, isShow: false,
onClick: () => { onClick: () => {
this.userSysSet('1') this.userSysSet('1')
} }
...@@ -177,13 +177,11 @@ export default { ...@@ -177,13 +177,11 @@ export default {
if ( if (
top === self && top === self &&
(hostname === '0.0.0.0' || hostname === 'localhost') (hostname === '0.0.0.0' || hostname === 'localhost')
) ) { return true }
return true
if ( if (
top !== self && top !== self &&
(hostname !== '0.0.0.0' || hostname !== 'localhost') (hostname !== '0.0.0.0' || hostname !== 'localhost')
) ) { return false }
return false
} }
}, },
getIsDev() { getIsDev() {
...@@ -195,21 +193,18 @@ export default { ...@@ -195,21 +193,18 @@ export default {
systemSysDevDb === true || systemSysDevDb === true ||
systemSysDevDb === '1' || systemSysDevDb === '1' ||
systemSysDevDb === 1 systemSysDevDb === 1
) ) { return true }
return true
} else { } else {
// 这是在本地开发时使用没有user_info时 // 这是在本地开发时使用没有user_info时
const hostname = location.hostname const hostname = location.hostname
if ( if (
top === self && top === self &&
(hostname === '0.0.0.0' || hostname === 'localhost') (hostname === '0.0.0.0' || hostname === 'localhost')
) ) { return true }
return true
if ( if (
top !== self && top !== self &&
(hostname !== '0.0.0.0' || hostname !== 'localhost') (hostname !== '0.0.0.0' || hostname !== 'localhost')
) ) { return false }
return false
} }
}, },
onContextmenu(event) { onContextmenu(event) {
......
...@@ -53,7 +53,7 @@ ...@@ -53,7 +53,7 @@
:row-style='setRowStyle' :row-style='setRowStyle'
:cell-style="setCellStyle" :cell-style="setCellStyle"
@header-click="headerClick" @header-click="headerClick"
:span-method="spanMethod" :span-method="objectSpanMethod"
> >
<template v-for='(columnItem,index) in tableColumns'> <template v-for='(columnItem,index) in tableColumns'>
...@@ -507,7 +507,7 @@ export default { ...@@ -507,7 +507,7 @@ export default {
const list = [ const list = [
{ {
label: '配置(用户)', label: '配置(用户)',
isShow: true, isShow: false,
onClick: () => { onClick: () => {
// this.userSysSet('1') // this.userSysSet('1')
this.userSysTableColumnSet('1') this.userSysTableColumnSet('1')
...@@ -578,7 +578,7 @@ export default { ...@@ -578,7 +578,7 @@ export default {
}, },
// 表格配置 // 表格配置
tableConfig() { tableConfig() {
return this.config return this.config || []
}, },
// 表格列 // 表格列
tableColumns() { tableColumns() {
...@@ -597,8 +597,8 @@ export default { ...@@ -597,8 +597,8 @@ export default {
const sumKey = this.tableColumns.find(item => item.summarizing) const sumKey = this.tableColumns.find(item => item.summarizing)
return !!tkeys.length || !!sumKey return !!tkeys.length || !!sumKey
}, },
spanList: function() { spanArrConfig: function() {
return this.dealWithSpanList() return this.dealwithMergeCellsConfig()
} }
}, },
mounted() { mounted() {
...@@ -606,62 +606,66 @@ export default { ...@@ -606,62 +606,66 @@ export default {
this.targetDom = this.$refs.boxtable this.targetDom = this.$refs.boxtable
}, },
methods: { methods: {
getSpanArr(data, key1, key2) { getSpanArr(data, spanArrConfig) {
const spanList = [] spanArrConfig.forEach(item => {
const { calculatedColumns } = item
let pos = 0 let pos = 0
for (let i = 0; i < data.length; i++) { for (var i = 0; i < data.length; i++) {
if (i === 0) { if (i === 0) {
spanList.push(1) item.list.push(1)
pos = 0 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 { } else {
// 判断当前元素与上一个元素是否相同 // 判断当前元素与上一个元素是否相同
if (data[i][key1] === data[i - 1][key1]) { const dataI = data[i]
spanList[pos] += 1 const dataIi = data[i - 1]
spanList.push(0) 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 { } else {
spanList.push(1) item.list.push(1)
pos = i 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 spanArrConfig
return spanList },
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 }) { objectSpanMethod({ row, column, rowIndex, columnIndex }) {
const prop = column.property const property = column.property
const target = this.spanList[prop] const target = this.spanArrConfig.find(x => x.targetColumnProp === property)
if (target && target.length) { if (target) {
const _row = target[rowIndex] const _row = target.list[rowIndex]
const _col = _row > 0 ? 1 : 0 const _col = _row > 0 ? 1 : 0
return { return {
rowspan: _row, rowspan: _row,
...@@ -669,6 +673,7 @@ export default { ...@@ -669,6 +673,7 @@ export default {
} }
} }
}, },
getIsAdmin() { getIsAdmin() {
const user_info = sessionStorage['user_info'] const user_info = sessionStorage['user_info']
if (user_info) { if (user_info) {
...@@ -681,13 +686,11 @@ export default { ...@@ -681,13 +686,11 @@ export default {
if ( if (
top === self && top === self &&
(hostname === '0.0.0.0' || hostname === 'localhost') (hostname === '0.0.0.0' || hostname === 'localhost')
) ) { return true }
return true
if ( if (
top !== self && top !== self &&
(hostname !== '0.0.0.0' || hostname !== 'localhost') (hostname !== '0.0.0.0' || hostname !== 'localhost')
) ) { return false }
return false
} }
}, },
getIsDev() { getIsDev() {
...@@ -710,13 +713,11 @@ export default { ...@@ -710,13 +713,11 @@ export default {
if ( if (
top === self && top === self &&
(hostname === '0.0.0.0' || hostname === 'localhost') (hostname === '0.0.0.0' || hostname === 'localhost')
) ) { return true }
return true
if ( if (
top !== self && top !== self &&
(hostname !== '0.0.0.0' || hostname !== 'localhost') (hostname !== '0.0.0.0' || hostname !== 'localhost')
) ) { return false }
return false
} }
}, },
onContextmenu(event) { 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