|
|
@@ -612,6 +612,7 @@ function getImages(designerInstance) {
|
|
|
continue
|
|
|
}
|
|
|
images.push({
|
|
|
+ shapeName: shape.name(),
|
|
|
sheetName: sheet.name(),
|
|
|
imgX: shape.x(),
|
|
|
imgY: shape.y(),
|
|
|
@@ -1152,6 +1153,127 @@ function openCamera() {
|
|
|
emit('openCamera')
|
|
|
}
|
|
|
|
|
|
+function getPictureSource(photoData) {
|
|
|
+ if (!photoData?.base64) return ''
|
|
|
+ if (photoData.base64.startsWith('data:')) return photoData.base64
|
|
|
+ return `data:${photoData.type || 'image/jpeg'};base64,${photoData.base64}`
|
|
|
+}
|
|
|
+
|
|
|
+function getCellRangeOffset(sheet, row, col) {
|
|
|
+ let x = 0
|
|
|
+ let y = 0
|
|
|
+ for (let c = 0; c < col; c++) {
|
|
|
+ x += sheet.getColumnWidth(c)
|
|
|
+ }
|
|
|
+ for (let r = 0; r < row; r++) {
|
|
|
+ y += sheet.getRowHeight(r)
|
|
|
+ }
|
|
|
+ return { x, y }
|
|
|
+}
|
|
|
+
|
|
|
+function getCellRangeSize(sheet, row, col, rowCount, colCount) {
|
|
|
+ let width = 0
|
|
|
+ let height = 0
|
|
|
+ for (let c = 0; c < colCount; c++) {
|
|
|
+ width += sheet.getColumnWidth(col + c)
|
|
|
+ }
|
|
|
+ for (let r = 0; r < rowCount; r++) {
|
|
|
+ height += sheet.getRowHeight(row + r)
|
|
|
+ }
|
|
|
+ return { width, height }
|
|
|
+}
|
|
|
+
|
|
|
+function getTargetPictureCell() {
|
|
|
+ if (!designer.value) return null
|
|
|
+ const spreadInstance = designer.value.getWorkbook()
|
|
|
+ const sheet = currentCell.value?.sheet || spreadInstance.getActiveSheet()
|
|
|
+ let row = currentCell.value?.row
|
|
|
+ let col = currentCell.value?.col
|
|
|
+
|
|
|
+ if ((row === null || row === undefined || col === null || col === undefined) && sheet) {
|
|
|
+ row = sheet.getActiveRowIndex?.()
|
|
|
+ col = sheet.getActiveColumnIndex?.()
|
|
|
+ }
|
|
|
+
|
|
|
+ if ((row === null || row === undefined || col === null || col === undefined) && sheet) {
|
|
|
+ const selection = sheet.getSelections?.()?.[0]
|
|
|
+ row = selection?.row
|
|
|
+ col = selection?.col
|
|
|
+ }
|
|
|
+
|
|
|
+ if (row === null || row === undefined || col === null || col === undefined || row < 0 || col < 0) {
|
|
|
+ return null
|
|
|
+ }
|
|
|
+
|
|
|
+ return { sheet, row, col }
|
|
|
+}
|
|
|
+
|
|
|
+function handleTakePhotoData(photoData) {
|
|
|
+ console.log("处理图片。。。。。")
|
|
|
+ const targetCell = getTargetPictureCell()
|
|
|
+ if (!targetCell) {
|
|
|
+ showDialog('请先选择需要插入图片的单元格')
|
|
|
+ return false
|
|
|
+ }
|
|
|
+
|
|
|
+ const pictureSource = getPictureSource(photoData)
|
|
|
+ if (!pictureSource) {
|
|
|
+ showDialog('图片数据为空')
|
|
|
+ return false
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ const { sheet, row, col } = targetCell
|
|
|
+ const targetRange = getMergedCellRange(sheet, row, col) || {
|
|
|
+ row,
|
|
|
+ col,
|
|
|
+ rowCount: 1,
|
|
|
+ colCount: 1,
|
|
|
+ }
|
|
|
+ const { x, y } = getCellRangeOffset(sheet, targetRange.row, targetRange.col)
|
|
|
+ const { width, height } = getCellRangeSize(
|
|
|
+ sheet,
|
|
|
+ targetRange.row,
|
|
|
+ targetRange.col,
|
|
|
+ targetRange.rowCount,
|
|
|
+ targetRange.colCount,
|
|
|
+ )
|
|
|
+ const pictureName = `addPicture_${targetRange.row}_${targetRange.col}_${Date.now()}`
|
|
|
+ const maxPictureWidth = Math.max(width * 0.72, 1)
|
|
|
+ const maxPictureHeight = Math.max(height * 0.72, 1)
|
|
|
+ const sourceWidth = Number(photoData.width) || maxPictureWidth
|
|
|
+ const sourceHeight = Number(photoData.height) || maxPictureHeight
|
|
|
+ const scale = Math.min(maxPictureWidth / sourceWidth, maxPictureHeight / sourceHeight)
|
|
|
+ const pictureWidth = Math.max(sourceWidth * scale, 1)
|
|
|
+ const pictureHeight = Math.max(sourceHeight * scale, 1)
|
|
|
+ const pictureX = x + (width - pictureWidth) / 2
|
|
|
+ const pictureY = y + (height - pictureHeight) / 2
|
|
|
+ const picture = sheet.shapes.addPictureShape(
|
|
|
+ pictureName,
|
|
|
+ pictureSource,
|
|
|
+ pictureX,
|
|
|
+ pictureY,
|
|
|
+ pictureWidth,
|
|
|
+ pictureHeight,
|
|
|
+ )
|
|
|
+
|
|
|
+ picture.startRow?.(targetRange.row)
|
|
|
+ picture.startColumn?.(targetRange.col)
|
|
|
+ picture.endRow?.(targetRange.row + targetRange.rowCount - 1)
|
|
|
+ picture.endColumn?.(targetRange.col + targetRange.colCount - 1)
|
|
|
+ picture.allowMove?.(true)
|
|
|
+ picture.allowResize?.(true)
|
|
|
+
|
|
|
+ sheet.repaint?.()
|
|
|
+ showDialog('图片已插入')
|
|
|
+ return true
|
|
|
+ } catch (error) {
|
|
|
+ console.error('插入图片失败:', error)
|
|
|
+ showDialog('插入图片失败')
|
|
|
+ return false
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
async function renderFeeTemplateAndReturnData(blob, bindingPathSchema, equipTemplateList) {
|
|
|
if (!designer.value) return
|
|
|
const spreadInstance = designer.value.getWorkbook()
|
|
|
@@ -1282,6 +1404,7 @@ defineExpose({
|
|
|
onWebViewResize,
|
|
|
updateCheckItemData,
|
|
|
handleCameraResult,
|
|
|
+ handleTakePhotoData,
|
|
|
setKeyboardHeight,
|
|
|
renderFeeTemplateAndReturnData,
|
|
|
signleRenderFeeTemplateAndReturnData,
|