yinghe-lowcode-zln
Version:
基于vue、ant-design-vue,datagrid的低代码平台
112 lines (108 loc) • 4.32 kB
JavaScript
export function setExcelData (xs, { ri = 0, ci = 0 }, text, isDrag = false, style, merge) {
const cell = { [ci]: { 'text': text } }
// 第一个单元格样式
if (style || style === 0) {
cell[ci]['style'] = style
}
if (merge) {
// 加入合并单元格
cell[ci]['merge'] = merge
}
let tableData = {}
const rowsData = xs.getData().rows
if (rowsData[ri]) {
// 有数据
const cells = { ...rowsData[ri].cells, ...cell }
tableData = { 'rows': {
...rowsData, [ri]: { cells, isDrag }
}
}
} else {
tableData = {
'rows': {
...rowsData, [ri]: { 'cells': cell, isDrag }
}
}
}
// 加入高度设置
const row = xs.getData().rows[ri]
const height = row && row.height
if (height) {
tableData.rows[ri].height = height
}
xs.loadData(tableData)
}
export function selectPolyList (xs, name) {
// 下拉改变单元格值
// const data = xs.data.getSelectArea()
const data = xs.data.selector.range
if (data.sri < 0 || data.sci < 0) return
if (!xs.data.rows['_'][data.sri]) return
const textr = xs.data.rows['_'][data.sri].cells[data.sci].text
if (textr !== '' && textr.indexOf('#{') !== -1) {
if (name === 'group') {
if (xs.data.rows['_'][data.sri].cells[data.sci].direction === 'right') return
xs.data.rows['_'][data.sri].cells[data.sci].aggregate = 'group'
const text = xs.data.rows['_'][data.sri].cells[data.sci].text
const newxsdata = text.replace(subStringStr(text, '#{', '}').split('.')[1], 'group(' + subStringStr(text, '#{', '}').split('.')[1] + ')')
xsSetNewdata(xs, data, newxsdata)
} else if (name === 'select') {
if (xs.data.rows['_'][data.sri].cells[data.sci].direction === 'right') return
xs.data.rows['_'][data.sri].cells[data.sci].aggregate = 'select'
const text = xs.data.rows['_'][data.sri].cells[data.sci].text
const subtext = subStringStr(text, '#{', '}').split('.')[1]
const newxsdata = text.replace(subtext, subStringStr(subtext, 'group(', ')'))
xsSetNewdata(xs, data, newxsdata)
}
}
}
export function selectDirectionList (xs, name) {
// 下拉改变单元格值
// const data = xs.data.getSelectArea()
const data = xs.data.selector.range
if (data.sri < 0 || data.sci < 0) return
if (!xs.data.rows['_'][data.sri]) return
const textr = xs.data.rows['_'][data.sri].cells[data.sci].text
if (textr !== '' && textr.indexOf('#{') !== -1) {
if (name === 'right') {
xs.data.rows['_'][data.sri].cells[data.sci].direction = 'right'
const text = xs.data.rows['_'][data.sri].cells[data.sci].text
const text2 = subStringStr(text, '#{', '}').split('.')[1]
let text4 = ''
if (text2.indexOf('group(') !== -1) {
text4 = subStringStr(text2, 'group(', ')')
} else {
text4 = text2
}
const text3 = 'groupRight(' + text4 + ')'
const newxsdata = text.replace(text2, text3)
xsSetNewdata(xs, data, newxsdata)
} else if (name === 'down') {
xs.data.rows['_'][data.sri].cells[data.sci].direction = 'down'
const text = xs.data.rows['_'][data.sri].cells[data.sci].text
const subtext = subStringStr(text, '#{', '}').split('.')[1]
const newxsdata = text.replace(subtext, subStringStr(subtext, 'groupRight(', ')'))
xsSetNewdata(xs, data, newxsdata)
}
}
}
function subStringStr (str, strStart, strEnd) {
/* 找出指定的2个字符在 该字符串里面的 位置 */
const strStartIndex = str.indexOf(strStart)
const strEndIndex = str.indexOf(strEnd)
/* index 为负数 即表示该字符串中 没有该字符 */
if (strStartIndex < 0) {
return ''
}
if (strEndIndex < 0) {
return ''
}
/* 开始截取 */
const result = str.substring(strStartIndex, strEndIndex).substring(strStart.length)
return result
}
function xsSetNewdata (xs, data, newxsdata) {
xs.data.rows['_'][data.sri].cells[data.sci].text = newxsdata
// vm.excel.excelValue = newxsdata
xs.sheet.reload()
}