mirror of
https://github.com/pipipi-pikachu/PPTist.git
synced 2025-04-15 02:20:00 +08:00
feat: 表格支持主动调整高度(#77)
This commit is contained in:
parent
9135d0a77b
commit
6bc30dc4c3
@ -164,6 +164,7 @@ export default () => {
|
|||||||
colHeader: false,
|
colHeader: false,
|
||||||
colFooter: false,
|
colFooter: false,
|
||||||
},
|
},
|
||||||
|
cellMinHeight: 36,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -517,6 +517,8 @@ export interface TableTheme {
|
|||||||
*
|
*
|
||||||
* colWidths: 列宽数组,如[30, 50, 20]表示三列宽度分别为30%, 50%, 20%
|
* colWidths: 列宽数组,如[30, 50, 20]表示三列宽度分别为30%, 50%, 20%
|
||||||
*
|
*
|
||||||
|
* cellMinHeight: 单元格最小高度
|
||||||
|
*
|
||||||
* data: 表格数据
|
* data: 表格数据
|
||||||
*/
|
*/
|
||||||
export interface PPTTableElement extends PPTBaseElement {
|
export interface PPTTableElement extends PPTBaseElement {
|
||||||
@ -524,6 +526,7 @@ export interface PPTTableElement extends PPTBaseElement {
|
|||||||
outline: PPTElementOutline
|
outline: PPTElementOutline
|
||||||
theme?: TableTheme
|
theme?: TableTheme
|
||||||
colWidths: number[]
|
colWidths: number[]
|
||||||
|
cellMinHeight: number
|
||||||
data: TableCell[][]
|
data: TableCell[][]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
<template v-if="handlerVisible">
|
<template v-if="handlerVisible">
|
||||||
<ResizeHandler
|
<ResizeHandler
|
||||||
class="operate-resize-handler"
|
class="operate-resize-handler"
|
||||||
v-for="point in textElementResizeHandlers"
|
v-for="point in resizeHandlers"
|
||||||
:key="point.direction"
|
:key="point.direction"
|
||||||
:type="point.direction"
|
:type="point.direction"
|
||||||
:rotate="elementInfo.rotate"
|
:rotate="elementInfo.rotate"
|
||||||
@ -70,5 +70,5 @@ const outlineWidth = computed(() => props.elementInfo.outline.width || 1)
|
|||||||
const scaleWidth = computed(() => (props.elementInfo.width + outlineWidth.value) * canvasScale.value)
|
const scaleWidth = computed(() => (props.elementInfo.width + outlineWidth.value) * canvasScale.value)
|
||||||
const scaleHeight = computed(() => props.elementInfo.height * canvasScale.value)
|
const scaleHeight = computed(() => props.elementInfo.height * canvasScale.value)
|
||||||
|
|
||||||
const { textElementResizeHandlers, borderLines } = useCommonOperate(scaleWidth, scaleHeight)
|
const { resizeHandlers, borderLines } = useCommonOperate(scaleWidth, scaleHeight)
|
||||||
</script>
|
</script>
|
@ -119,6 +119,8 @@ export default (
|
|||||||
const elOriginWidth = element.width
|
const elOriginWidth = element.width
|
||||||
const elOriginHeight = element.height
|
const elOriginHeight = element.height
|
||||||
|
|
||||||
|
const originTableCellMinHeight = element.type === 'table' ? element.cellMinHeight : 0
|
||||||
|
|
||||||
const elRotate = ('rotate' in element && element.rotate) ? element.rotate : 0
|
const elRotate = ('rotate' in element && element.rotate) ? element.rotate : 0
|
||||||
const rotateRadian = Math.PI * elRotate / 180
|
const rotateRadian = Math.PI * elRotate / 180
|
||||||
|
|
||||||
@ -412,6 +414,16 @@ export default (
|
|||||||
path,
|
path,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (el.type === 'table') {
|
||||||
|
let cellMinHeight = originTableCellMinHeight + (height - elOriginHeight) / el.data.length
|
||||||
|
cellMinHeight = cellMinHeight < 36 ? 36 : cellMinHeight
|
||||||
|
|
||||||
|
if (cellMinHeight === originTableCellMinHeight) return { ...el, left, width }
|
||||||
|
return {
|
||||||
|
...el, left, top, width, height,
|
||||||
|
cellMinHeight: cellMinHeight < 36 ? 36 : cellMinHeight,
|
||||||
|
}
|
||||||
|
}
|
||||||
return { ...el, left, top, width, height }
|
return { ...el, left, top, width, height }
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -82,7 +82,7 @@
|
|||||||
:min="minSize"
|
:min="minSize"
|
||||||
:max="800"
|
:max="800"
|
||||||
:step="5"
|
:step="5"
|
||||||
:disabled="isHorizontalText"
|
:disabled="isHorizontalText || handleElement!.type === 'table'"
|
||||||
:value="height"
|
:value="height"
|
||||||
@change="value => updateHeight(value as number)"
|
@change="value => updateHeight(value as number)"
|
||||||
style="flex: 4;"
|
style="flex: 4;"
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
<StaticTable
|
<StaticTable
|
||||||
:data="elementInfo.data"
|
:data="elementInfo.data"
|
||||||
:width="elementInfo.width"
|
:width="elementInfo.width"
|
||||||
|
:cellMinHeight="elementInfo.cellMinHeight"
|
||||||
:colWidths="elementInfo.colWidths"
|
:colWidths="elementInfo.colWidths"
|
||||||
:outline="elementInfo.outline"
|
:outline="elementInfo.outline"
|
||||||
:theme="elementInfo.theme"
|
:theme="elementInfo.theme"
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
<col span="1" v-for="(width, index) in colSizeList" :key="index" :width="width">
|
<col span="1" v-for="(width, index) in colSizeList" :key="index" :width="width">
|
||||||
</colgroup>
|
</colgroup>
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr v-for="(rowCells, rowIndex) in tableCells" :key="rowIndex">
|
<tr v-for="(rowCells, rowIndex) in tableCells" :key="rowIndex" :style="{ height: cellMinHeight + 'px' }">
|
||||||
<td
|
<td
|
||||||
class="cell"
|
class="cell"
|
||||||
:class="{
|
:class="{
|
||||||
@ -53,11 +53,12 @@
|
|||||||
v-if="activedCell === `${rowIndex}_${colIndex}`"
|
v-if="activedCell === `${rowIndex}_${colIndex}`"
|
||||||
class="cell-text"
|
class="cell-text"
|
||||||
:class="{ 'active': activedCell === `${rowIndex}_${colIndex}` }"
|
:class="{ 'active': activedCell === `${rowIndex}_${colIndex}` }"
|
||||||
|
:style="{ minHeight: (cellMinHeight - 4) + 'px' }"
|
||||||
:value="cell.text"
|
:value="cell.text"
|
||||||
@updateValue="value => handleInput(value, rowIndex, colIndex)"
|
@updateValue="value => handleInput(value, rowIndex, colIndex)"
|
||||||
@insertExcelData="value => insertExcelData(value, rowIndex, colIndex)"
|
@insertExcelData="value => insertExcelData(value, rowIndex, colIndex)"
|
||||||
/>
|
/>
|
||||||
<div v-else class="cell-text" v-html="formatText(cell.text)" />
|
<div v-else class="cell-text" :style="{ minHeight: (cellMinHeight - 4) + 'px' }" v-html="formatText(cell.text)" />
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
@ -89,6 +90,10 @@ const props = defineProps({
|
|||||||
type: Number,
|
type: Number,
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
|
cellMinHeight: {
|
||||||
|
type: Number,
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
colWidths: {
|
colWidths: {
|
||||||
type: Array as PropType<number[]>,
|
type: Array as PropType<number[]>,
|
||||||
required: true,
|
required: true,
|
||||||
@ -700,10 +705,6 @@ table {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tr {
|
|
||||||
height: 36px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.cell {
|
.cell {
|
||||||
position: relative;
|
position: relative;
|
||||||
white-space: normal;
|
white-space: normal;
|
||||||
@ -724,7 +725,6 @@ table {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.cell-text {
|
.cell-text {
|
||||||
min-height: 32px;
|
|
||||||
padding: 5px;
|
padding: 5px;
|
||||||
line-height: 1.5;
|
line-height: 1.5;
|
||||||
user-select: none;
|
user-select: none;
|
||||||
|
@ -17,10 +17,7 @@
|
|||||||
<col span="1" v-for="(width, index) in colSizeList" :key="index" :width="width">
|
<col span="1" v-for="(width, index) in colSizeList" :key="index" :width="width">
|
||||||
</colgroup>
|
</colgroup>
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr
|
<tr v-for="(rowCells, rowIndex) in data" :key="rowIndex" :style="{ height: cellMinHeight + 'px' }">
|
||||||
v-for="(rowCells, rowIndex) in data"
|
|
||||||
:key="rowIndex"
|
|
||||||
>
|
|
||||||
<td
|
<td
|
||||||
class="cell"
|
class="cell"
|
||||||
:style="{
|
:style="{
|
||||||
@ -35,7 +32,7 @@
|
|||||||
:colspan="cell.colspan"
|
:colspan="cell.colspan"
|
||||||
v-show="!hideCells.includes(`${rowIndex}_${colIndex}`)"
|
v-show="!hideCells.includes(`${rowIndex}_${colIndex}`)"
|
||||||
>
|
>
|
||||||
<div class="cell-text" v-html="formatText(cell.text)" />
|
<div class="cell-text" :style="{ minHeight: (cellMinHeight - 4) + 'px' }" v-html="formatText(cell.text)" />
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
@ -59,6 +56,10 @@ const props = defineProps({
|
|||||||
type: Number,
|
type: Number,
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
|
cellMinHeight: {
|
||||||
|
type: Number,
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
colWidths: {
|
colWidths: {
|
||||||
type: Array as PropType<number[]>,
|
type: Array as PropType<number[]>,
|
||||||
required: true,
|
required: true,
|
||||||
@ -144,10 +145,6 @@ table {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tr {
|
|
||||||
height: 36px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.cell {
|
.cell {
|
||||||
position: relative;
|
position: relative;
|
||||||
white-space: normal;
|
white-space: normal;
|
||||||
@ -156,7 +153,6 @@ table {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.cell-text {
|
.cell-text {
|
||||||
min-height: 32px;
|
|
||||||
padding: 5px;
|
padding: 5px;
|
||||||
line-height: 1.5;
|
line-height: 1.5;
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
@mousedown.stop
|
@mousedown.stop
|
||||||
:data="elementInfo.data"
|
:data="elementInfo.data"
|
||||||
:width="elementInfo.width"
|
:width="elementInfo.width"
|
||||||
|
:cellMinHeight="elementInfo.cellMinHeight"
|
||||||
:colWidths="elementInfo.colWidths"
|
:colWidths="elementInfo.colWidths"
|
||||||
:outline="elementInfo.outline"
|
:outline="elementInfo.outline"
|
||||||
:theme="elementInfo.theme"
|
:theme="elementInfo.theme"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user