|
@@ -49,6 +49,7 @@
|
|
|
>
|
|
>
|
|
|
特殊符号
|
|
特殊符号
|
|
|
</button>
|
|
</button>
|
|
|
|
|
+ <!--<button class="generate-page-btn" @click="handleGeneratePage">生成续页</button>-->
|
|
|
<button
|
|
<button
|
|
|
id="prevCellBtn"
|
|
id="prevCellBtn"
|
|
|
class="prev-cell-btn"
|
|
class="prev-cell-btn"
|
|
@@ -152,6 +153,10 @@ const props = defineProps({
|
|
|
type: String,
|
|
type: String,
|
|
|
default: '',
|
|
default: '',
|
|
|
},
|
|
},
|
|
|
|
|
+ copyConfig: {
|
|
|
|
|
+ type: Object,
|
|
|
|
|
+ default: null,
|
|
|
|
|
+ },
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
const emit = defineEmits([
|
|
const emit = defineEmits([
|
|
@@ -300,6 +305,7 @@ function formatterOADateNumber(input) {
|
|
|
return OADate !== null ? new Date(Math.round(OADate - 25569) * 86400000) : null
|
|
return OADate !== null ? new Date(Math.round(OADate - 25569) * 86400000) : null
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+// 只过滤出当前sheet页需要的字段
|
|
|
function getSheetBindingPathData(sheet, dataSource) {
|
|
function getSheetBindingPathData(sheet, dataSource) {
|
|
|
const boundFields = new Set()
|
|
const boundFields = new Set()
|
|
|
const tableMap = new Map()
|
|
const tableMap = new Map()
|
|
@@ -552,6 +558,7 @@ function getDefaultSchema(designerInstance) {
|
|
|
)
|
|
)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+let dataCount = 0
|
|
|
function setDataSource(designerInstance, schemaData, dataSourceValues) {
|
|
function setDataSource(designerInstance, schemaData, dataSourceValues) {
|
|
|
dataSourceValues =
|
|
dataSourceValues =
|
|
|
!is(dataSourceValues, 'Object') && is(dataSourceValues, 'String')
|
|
!is(dataSourceValues, 'Object') && is(dataSourceValues, 'String')
|
|
@@ -566,6 +573,18 @@ function setDataSource(designerInstance, schemaData, dataSourceValues) {
|
|
|
const resultDataSource = deepMergeSchemaValue(formatterSource, dataSourceValues)
|
|
const resultDataSource = deepMergeSchemaValue(formatterSource, dataSourceValues)
|
|
|
|
|
|
|
|
const spreadInstance = designerInstance.getWorkbook()
|
|
const spreadInstance = designerInstance.getWorkbook()
|
|
|
|
|
+ const {
|
|
|
|
|
+ dataSource: continuePageProceedDataSource,
|
|
|
|
|
+ sheetToRecordRowCount,
|
|
|
|
|
+ totalDataCount,
|
|
|
|
|
+ } = processContinueDataSource(spreadInstance, resultDataSource)
|
|
|
|
|
+ dataCount = totalDataCount
|
|
|
|
|
+ processContinuePage(
|
|
|
|
|
+ spreadInstance,
|
|
|
|
|
+ continuePageProceedDataSource,
|
|
|
|
|
+ sheetToRecordRowCount,
|
|
|
|
|
+ totalDataCount,
|
|
|
|
|
+ )
|
|
|
registerCellValuesChangeEventHandlerForEverySheet(spreadInstance.sheets)
|
|
registerCellValuesChangeEventHandlerForEverySheet(spreadInstance.sheets)
|
|
|
for (const sheet of spreadInstance.sheets) {
|
|
for (const sheet of spreadInstance.sheets) {
|
|
|
const tables = sheet.tables?.all() || []
|
|
const tables = sheet.tables?.all() || []
|
|
@@ -573,8 +592,9 @@ function setDataSource(designerInstance, schemaData, dataSourceValues) {
|
|
|
const table = tables[i]
|
|
const table = tables[i]
|
|
|
table.expandBoundRows(true)
|
|
table.expandBoundRows(true)
|
|
|
}
|
|
}
|
|
|
- const filterResultDataSource = getSheetBindingPathData(sheet, resultDataSource)
|
|
|
|
|
|
|
+ const filterResultDataSource = getSheetBindingPathData(sheet, continuePageProceedDataSource)
|
|
|
const dataSource = new GC.Spread.Sheets.Bindings.CellBindingSource(filterResultDataSource)
|
|
const dataSource = new GC.Spread.Sheets.Bindings.CellBindingSource(filterResultDataSource)
|
|
|
|
|
+ console.log('@@@every sheet datasource.......', dataSource)
|
|
|
sheet.setDataSource(dataSource)
|
|
sheet.setDataSource(dataSource)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -601,6 +621,200 @@ function getDataSource(designerInstance) {
|
|
|
return dataSource
|
|
return dataSource
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+function processContinueDataSource(spreadInstance, dataSource) {
|
|
|
|
|
+ if (!props.copyConfig?.isContinuePage) {
|
|
|
|
|
+ return dataSource
|
|
|
|
|
+ }
|
|
|
|
|
+ console.log('@@@@@datasource', dataSource)
|
|
|
|
|
+ dataSource = { ...dataSource }
|
|
|
|
|
+ const copyConfig = props.copyConfig
|
|
|
|
|
+ const continuePageSheetName = copyConfig.sheetName
|
|
|
|
|
+ console.log('@@@@copyconfig....', copyConfig)
|
|
|
|
|
+ // 数据扁平化
|
|
|
|
|
+ // 0. 收集所有sheet页中的bindingPath字段集合,根据sheet页分组
|
|
|
|
|
+ const sheetToFieldListMap = {}
|
|
|
|
|
+ const fieldListToSheetNameMap = new Map()
|
|
|
|
|
+ for (const sheet of spreadInstance.sheets) {
|
|
|
|
|
+ const boundFields = new Set()
|
|
|
|
|
+ for (let row = 0; row < sheet.getRowCount(); row++) {
|
|
|
|
|
+ for (let col = 0; col < sheet.getColumnCount(); col++) {
|
|
|
|
|
+ const bindingPath = sheet.getBindingPath(row, col)
|
|
|
|
|
+ if (bindingPath) {
|
|
|
|
|
+ boundFields.add(bindingPath)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ const currentSheetName = sheet.name()
|
|
|
|
|
+ sheetToFieldListMap[currentSheetName] = boundFields
|
|
|
|
|
+ fieldListToSheetNameMap.set(boundFields, currentSheetName)
|
|
|
|
|
+ }
|
|
|
|
|
+ console.log('@@@@sheetToFieldListMap....', sheetToFieldListMap)
|
|
|
|
|
+
|
|
|
|
|
+ // 每个 sheet 的数据行数
|
|
|
|
|
+ const sheetToRecordRowCount = {}
|
|
|
|
|
+ for (let sheetName in sheetToFieldListMap) {
|
|
|
|
|
+ const fieldList = [...sheetToFieldListMap[sheetName]]
|
|
|
|
|
+ let maxSuffixNum = 0
|
|
|
|
|
+ let minSuffixNum = -1
|
|
|
|
|
+ for (let i = 0; i < fieldList.length; i++) {
|
|
|
|
|
+ const field = fieldList[i]
|
|
|
|
|
+ const suffixNumStr = field.split('_')[1]
|
|
|
|
|
+ if (suffixNumStr == null || suffixNumStr == '') {
|
|
|
|
|
+ continue
|
|
|
|
|
+ }
|
|
|
|
|
+ const suffixNum = Number(suffixNumStr)
|
|
|
|
|
+ maxSuffixNum = suffixNum > maxSuffixNum ? suffixNum : maxSuffixNum
|
|
|
|
|
+ if (minSuffixNum === -1) {
|
|
|
|
|
+ minSuffixNum = suffixNum
|
|
|
|
|
+ } else {
|
|
|
|
|
+ minSuffixNum = suffixNum < minSuffixNum ? suffixNum : minSuffixNum
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ sheetToRecordRowCount[sheetName] = maxSuffixNum - minSuffixNum + 1
|
|
|
|
|
+ }
|
|
|
|
|
+ console.log('@@@@sheetToRecordRowCount.....', sheetToRecordRowCount)
|
|
|
|
|
+
|
|
|
|
|
+ // 1. 对于字段集合,取用copyConfig的sheetName对应sheet,识别 {filed}_{++num} 模式的字段,取出 {field} 部分组成的数组
|
|
|
|
|
+ const continuePageFieldSet = sheetToFieldListMap[continuePageSheetName]
|
|
|
|
|
+ console.log('@@@copyConfigContinuePageFieldSet...', continuePageFieldSet)
|
|
|
|
|
+
|
|
|
|
|
+ const prefixFieldSet = new Set()
|
|
|
|
|
+ const pattern = /^(.+)_(\d+)$/
|
|
|
|
|
+ for (const continuePageField of continuePageFieldSet) {
|
|
|
|
|
+ if (!continuePageField.match(pattern)) {
|
|
|
|
|
+ continue
|
|
|
|
|
+ }
|
|
|
|
|
+ prefixFieldSet.add(continuePageField.split('_')[0])
|
|
|
|
|
+ }
|
|
|
|
|
+ console.log('@@@prefixFieldSet.....', prefixFieldSet)
|
|
|
|
|
+
|
|
|
|
|
+ // 2. 遍历 {field}数组,取出 {field}_1 的数据,按逗号切割出数组,根据数组下标设置遍历,实现数据扁平处理
|
|
|
|
|
+ // 1. 遍历过程中,对dataSource的 {field}_{i+1} 设置值
|
|
|
|
|
+ // 2. 仅当{field}数组为0时,判断 {field}_{i+1} 在哪一个sheet,给sheet分页对应的recordCount加一
|
|
|
|
|
+ let totalDataCount = 0
|
|
|
|
|
+ let firstFlag = true
|
|
|
|
|
+ for (const prefixField of prefixFieldSet) {
|
|
|
|
|
+ const columnDataSource = dataSource[prefixField + '_1']
|
|
|
|
|
+ if (columnDataSource == null) {
|
|
|
|
|
+ break
|
|
|
|
|
+ }
|
|
|
|
|
+ if (firstFlag) {
|
|
|
|
|
+ totalDataCount = columnDataSource.length
|
|
|
|
|
+ firstFlag = false
|
|
|
|
|
+ } else {
|
|
|
|
|
+ if (totalDataCount !== columnDataSource.length) {
|
|
|
|
|
+ console.error('续页处理的数据,格式错误,字段为: ', prefixField)
|
|
|
|
|
+ continue
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ for (let i = 0; i < columnDataSource.length; i++) {
|
|
|
|
|
+ const cellData = columnDataSource[i]
|
|
|
|
|
+ const dataSourceKey = `${prefixField}_${i + 1}`
|
|
|
|
|
+ dataSource[dataSourceKey] = cellData
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ console.log('@@@flatDataSource.....', dataSource)
|
|
|
|
|
+
|
|
|
|
|
+ return { dataSource, sheetToRecordRowCount, totalDataCount }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+// 续页生成,超出一览表(第一页),把续页(第二页)从隐藏改成显示,超出续页(第二页),拷贝续页,copyRange范围内的bindingPath做递增修改
|
|
|
|
|
+function processContinuePage(spreadInstance, dataSource, sheetToRecordRowCount, totalDataCount) {
|
|
|
|
|
+ if (!props.copyConfig?.isContinuePage) {
|
|
|
|
|
+ return dataSource
|
|
|
|
|
+ }
|
|
|
|
|
+ console.log('@@@@@datasource', dataSource, '@@@totalDataCount', totalDataCount)
|
|
|
|
|
+ dataSource = { ...dataSource }
|
|
|
|
|
+ const copyConfig = props.copyConfig
|
|
|
|
|
+ const copyRange = copyConfig.copyRange
|
|
|
|
|
+ const col = parseInt(copyRange.topLeft.split(',')[0])
|
|
|
|
|
+ const row = parseInt(copyRange.topLeft.split(',')[1])
|
|
|
|
|
+ const colCount = parseInt(copyRange.topRight.split(',')[0]) - col + 1
|
|
|
|
|
+ let rowCount = parseInt(copyRange.bottomLeft.split(',')[1]) - row + 1
|
|
|
|
|
+ const isHiddenContinuePage = copyConfig.hidden
|
|
|
|
|
+ const continuePageSheetName = copyConfig.sheetName
|
|
|
|
|
+
|
|
|
|
|
+ // 转换sheetName为对应数组下标,数组元素为对应页的数据行数量
|
|
|
|
|
+ const sheetIdxToRecordCountArray = new Array(spreadInstance.sheets.length).fill(0)
|
|
|
|
|
+ for (const sheet of spreadInstance.sheets) {
|
|
|
|
|
+ const sheetName = sheet.name()
|
|
|
|
|
+ const sheetIdx = spreadInstance.getSheetIndex(sheetName)
|
|
|
|
|
+ sheetIdxToRecordCountArray[sheetIdx] = sheetToRecordRowCount[sheetName]
|
|
|
|
|
+ }
|
|
|
|
|
+ console.log('@@@sheetIdxToRecordCountArray', sheetIdxToRecordCountArray)
|
|
|
|
|
+
|
|
|
|
|
+ // 一览表
|
|
|
|
|
+ let actualCursor = sheetIdxToRecordCountArray[0]
|
|
|
|
|
+ if (totalDataCount <= actualCursor) {
|
|
|
|
|
+ if (isHiddenContinuePage) {
|
|
|
|
|
+ spreadInstance.getSheet(1).visible(false)
|
|
|
|
|
+ }
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 一览表+续页表
|
|
|
|
|
+ actualCursor = actualCursor + rowCount
|
|
|
|
|
+ if (totalDataCount > sheetIdxToRecordCountArray[0] && totalDataCount <= actualCursor) {
|
|
|
|
|
+ spreadInstance.getSheet(1).visible(true)
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+ spreadInstance.getSheet(1).visible(true)
|
|
|
|
|
+
|
|
|
|
|
+ let continuePageSuffixNum = 2
|
|
|
|
|
+ let copyPageIdx = 2
|
|
|
|
|
+ // 一览表+续页表+续页行为
|
|
|
|
|
+ while (totalDataCount > actualCursor) {
|
|
|
|
|
+ const newSheetName = `${continuePageSheetName}_${continuePageSuffixNum}`
|
|
|
|
|
+ spreadInstance.commandManager().execute({
|
|
|
|
|
+ cmd: 'copySheet',
|
|
|
|
|
+ sheetName: continuePageSheetName,
|
|
|
|
|
+ targetIndex: copyPageIdx,
|
|
|
|
|
+ newName: newSheetName,
|
|
|
|
|
+ includeBindingSource: true,
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ const currentCopiedSheet = spreadInstance.getSheet(copyPageIdx)
|
|
|
|
|
+ alterContinuePageBindingPath(currentCopiedSheet, actualCursor + 1, col, row, rowCount, colCount)
|
|
|
|
|
+
|
|
|
|
|
+ actualCursor += rowCount
|
|
|
|
|
+ continuePageSuffixNum += 1
|
|
|
|
|
+ copyPageIdx += 1
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ const sheetToFieldListMap = {}
|
|
|
|
|
+ for (const sheet of spreadInstance.sheets) {
|
|
|
|
|
+ const boundFields = new Set()
|
|
|
|
|
+ for (let row = 0; row < sheet.getRowCount(); row++) {
|
|
|
|
|
+ for (let col = 0; col < sheet.getColumnCount(); col++) {
|
|
|
|
|
+ const bindingPath = sheet.getBindingPath(row, col)
|
|
|
|
|
+ if (bindingPath) {
|
|
|
|
|
+ boundFields.add(bindingPath)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ const currentSheetName = sheet.name()
|
|
|
|
|
+ sheetToFieldListMap[currentSheetName] = boundFields
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ console.log('@@@validateFieldMap......', sheetToFieldListMap)
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+function alterContinuePageBindingPath(sheet, startNum, startCol, startRow, rowCount, columnCount) {
|
|
|
|
|
+ for (let r = startRow; r < startRow + rowCount; r++) {
|
|
|
|
|
+ for (let c = startCol; c < startCol + columnCount; c++) {
|
|
|
|
|
+ const cellBindingPath = sheet.getBindingPath(r, c)
|
|
|
|
|
+ if (cellBindingPath == null) {
|
|
|
|
|
+ continue
|
|
|
|
|
+ }
|
|
|
|
|
+ const bindingPrefix = cellBindingPath.split('_')[0]
|
|
|
|
|
+ const newBindingPath = bindingPrefix + '_' + startNum
|
|
|
|
|
+ sheet.setBindingPath(r, c, newBindingPath)
|
|
|
|
|
+ }
|
|
|
|
|
+ startNum += 1
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
function getImages(designerInstance) {
|
|
function getImages(designerInstance) {
|
|
|
const spreadInstance = designerInstance.getWorkbook()
|
|
const spreadInstance = designerInstance.getWorkbook()
|
|
|
const images = []
|
|
const images = []
|
|
@@ -1047,7 +1261,7 @@ function openAndEditRecordFn() {
|
|
|
|
|
|
|
|
spreadInstance.open(
|
|
spreadInstance.open(
|
|
|
blob,
|
|
blob,
|
|
|
- () => {
|
|
|
|
|
|
|
+ async () => {
|
|
|
const activedSheet = spreadInstance.getActiveSheet()
|
|
const activedSheet = spreadInstance.getActiveSheet()
|
|
|
initDesignerSheetConfig(activedSheet)
|
|
initDesignerSheetConfig(activedSheet)
|
|
|
|
|
|
|
@@ -1112,6 +1326,13 @@ function initSpreadInputEvents(spreadInstance) {
|
|
|
console.log('悬浮输入框事件已绑定')
|
|
console.log('悬浮输入框事件已绑定')
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+function handleDataJson(dataJson) {
|
|
|
|
|
+ if (!props.copyConfig?.isContinuePage) {
|
|
|
|
|
+ return dataJson
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
function saveRecord() {
|
|
function saveRecord() {
|
|
|
if (!designer.value) return
|
|
if (!designer.value) return
|
|
|
|
|
|
|
@@ -1124,6 +1345,8 @@ function saveRecord() {
|
|
|
const schemaJSON = getDefaultSchema(designer.value)
|
|
const schemaJSON = getDefaultSchema(designer.value)
|
|
|
const images = getImages(designer.value)
|
|
const images = getImages(designer.value)
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
emit('save', {
|
|
emit('save', {
|
|
|
blob: base64,
|
|
blob: base64,
|
|
|
instId: props.checkItemData.instId,
|
|
instId: props.checkItemData.instId,
|
|
@@ -1201,7 +1424,14 @@ function getTargetPictureCell() {
|
|
|
col = selection?.col
|
|
col = selection?.col
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (row === null || row === undefined || col === null || col === undefined || row < 0 || col < 0) {
|
|
|
|
|
|
|
+ if (
|
|
|
|
|
+ row === null ||
|
|
|
|
|
+ row === undefined ||
|
|
|
|
|
+ col === null ||
|
|
|
|
|
+ col === undefined ||
|
|
|
|
|
+ row < 0 ||
|
|
|
|
|
+ col < 0
|
|
|
|
|
+ ) {
|
|
|
return null
|
|
return null
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -1209,7 +1439,7 @@ function getTargetPictureCell() {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function handleTakePhotoData(photoData) {
|
|
function handleTakePhotoData(photoData) {
|
|
|
- console.log("处理图片。。。。。")
|
|
|
|
|
|
|
+ console.log('处理图片。。。。。')
|
|
|
const targetCell = getTargetPictureCell()
|
|
const targetCell = getTargetPictureCell()
|
|
|
if (!targetCell) {
|
|
if (!targetCell) {
|
|
|
showDialog('请先选择需要插入图片的单元格')
|
|
showDialog('请先选择需要插入图片的单元格')
|
|
@@ -1338,7 +1568,7 @@ function updateCheckItemData(newData) {
|
|
|
|
|
|
|
|
spreadInstance.open(
|
|
spreadInstance.open(
|
|
|
blob,
|
|
blob,
|
|
|
- () => {
|
|
|
|
|
|
|
+ async () => {
|
|
|
const activedSheet = spreadInstance.getActiveSheet()
|
|
const activedSheet = spreadInstance.getActiveSheet()
|
|
|
initDesignerSheetConfig(activedSheet)
|
|
initDesignerSheetConfig(activedSheet)
|
|
|
|
|
|
|
@@ -1582,6 +1812,28 @@ defineExpose({
|
|
|
opacity: 0.7;
|
|
opacity: 0.7;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+.generate-page-btn {
|
|
|
|
|
+ display: flex;
|
|
|
|
|
+ align-items: center;
|
|
|
|
|
+ justify-content: center;
|
|
|
|
|
+ min-width: 60px;
|
|
|
|
|
+ height: 35px;
|
|
|
|
|
+ padding: 6px 12px;
|
|
|
|
|
+ font-size: 12px;
|
|
|
|
|
+ font-weight: 500;
|
|
|
|
|
+ color: white;
|
|
|
|
|
+ cursor: pointer;
|
|
|
|
|
+ background: #6f42c1;
|
|
|
|
|
+ border: none;
|
|
|
|
|
+ border-radius: 4px;
|
|
|
|
|
+ transition: all 0.2s ease;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+.generate-page-btn:hover {
|
|
|
|
|
+ background: #5a32a3;
|
|
|
|
|
+ transform: translateY(-1px);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
.floating-input-wrapper {
|
|
.floating-input-wrapper {
|
|
|
position: relative;
|
|
position: relative;
|
|
|
width: 100%;
|
|
width: 100%;
|