function filterTreeIds (data) {
const selectIds = []
const filterIds = function (data) {
if (data.children && data.children.length) {
selectIds.push(data.id)
data.children.forEach(item => {
if (item.children && item.children.length) {
filterIds(item)
} else {
selectIds.push(item.id)
}
})
}
}
filterIds(data)
return selectIds
}
function setTableHeight (_this) {
_this.$nextTick(() => {
if (_this.$refs.tableWrap) {
_this.tableHeight = _this.$refs.tableWrap.offsetHeight
}
})
window.onresize = () => {
return (() => {
if (_this.$refs.tableWrap) {
const tableWrapHeight = _this.$refs.tableWrap.offsetHeight
_this.tableHeight = tableWrapHeight
}
})()
}
}
function calcWidth (prop, tableData, title, num = 0) {
let flexWidth = 0
let columnContent = ''
const canvas = document.createElement('canvas')
const context = canvas.getContext('2d')
context.font = '14px Microsoft YaHei'
if (tableData.length === 0) {
const width = context.measureText(title)
flexWidth = width.width + 50 + num
return flexWidth + 'px'
}
if ((prop === '') && title) {
columnContent = title
} else {
let index = 0
for (let i = 0; i < tableData.length; i++) {
const nowTemp = tableData[i][prop] + ''
const maxTemp = tableData[index][prop] + ''
const nowTempW = context.measureText(nowTemp).width
const maxTempW = context.measureText(maxTemp).width
if (nowTempW > maxTempW) {
index = i
}
}
columnContent = tableData[index][prop]
const columnW = context.measureText(columnContent).width
const titleW = context.measureText(title).width
if (columnW < titleW) {
columnContent = title || ''
}
}
const width = context.measureText(columnContent)
flexWidth = width.width + 50 + num
return flexWidth + 'px'
}
function textWrap (text, maxNum) {
let str = ''
const arr = text.split(' ')
let tmp = ''
arr.forEach((item) => {
if (item.length >= maxNum) {
str = str + item + '\n'
} else {
if (tmp.length + item.length < maxNum) {
tmp = tmp + item + ' '
} else {
str = str + tmp + '\n'
tmp = item + ' '
}
}
})
str = str + tmp
return str
}