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 => {
let pos = 0 const { calculatedColumns } = item
for (let i = 0; i < data.length; i++) { let pos = 0
if (i === 0) { for (var i = 0; i < data.length; i++) {
spanList.push(1) if (i === 0) {
pos = 0 item.list.push(1)
} else { pos = 0
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 return spanArrConfig
}, },
dealWithSpanList() { dealwithMergeCellsConfig() {
const spanList = {} const SpanArrConfig = this.tableConfig.mergeCellsConfig || []
const tableData = _.cloneDeep(this.tableDat || []) const list = this.transSpanArrConfig(SpanArrConfig)
const config = _.cloneDeep(this.tableConfig || {}) return this.getSpanArr(this.tableData, list)
if (config.spanCol) { },
let spanCol = config.spanCol transSpanArrConfig(SpanArrConfig) {
spanCol.forEach(key => { const list = []
if (key.indexOf('^') > -1) { SpanArrConfig.forEach(item => {
const key1 = key.split('^')[0] const [item0, item1] = item.split('=')
const key2 = key.split('^')[1] const targetPropList = item0.split(',')
spanList[key1] = this.getSpanArr(tableData, key1, key2) targetPropList.forEach(targetProp => {
} else { const item1_ = item1 || item0
spanList[key] = this.getSpanArr(tableData, key) const targetcalculatedList = item1_.split('+')
if (!targetcalculatedList.includes(targetProp)) {
targetcalculatedList.push(targetProp)
} }
list.push({
list: [],
targetColumnProp: targetProp, // 目标列
calculatedColumns: targetcalculatedList// 要计算的列
})
}) })
} })
return spanList 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