File size: 3,573 Bytes
89ce340 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
<template>
<div
class="static-table"
:style="{ width: totalWidth + 'px' }"
>
<table
:class="{
'theme': theme,
'row-header': theme?.rowHeader,
'row-footer': theme?.rowFooter,
'col-header': theme?.colHeader,
'col-footer': theme?.colFooter,
}"
:style="`--themeColor: ${theme?.color}; --subThemeColor1: ${subThemeColor[0]}; --subThemeColor2: ${subThemeColor[1]}`"
>
<colgroup>
<col span="1" v-for="(width, index) in colSizeList" :key="index" :width="width">
</colgroup>
<tbody>
<tr v-for="(rowCells, rowIndex) in data" :key="rowIndex" :style="{ height: cellMinHeight + 'px' }">
<td
class="cell"
:style="{
borderStyle: outline.style,
borderColor: outline.color,
borderWidth: outline.width + 'px',
...getTextStyle(cell.style),
}"
v-for="(cell, colIndex) in rowCells"
:key="cell.id"
:rowspan="cell.rowspan"
:colspan="cell.colspan"
v-show="!hideCells.includes(`${rowIndex}_${colIndex}`)"
>
<div class="cell-text" :style="{ minHeight: (cellMinHeight - 4) + 'px' }" v-html="formatText(cell.text)" />
</td>
</tr>
</tbody>
</table>
</div>
</template>
<script lang="ts" setup>
import { computed, ref, watch } from 'vue'
import type { PPTElementOutline, TableCell, TableTheme } from '@/types/slides'
import { getTextStyle, formatText } from './utils'
import useHideCells from './useHideCells'
import useSubThemeColor from './useSubThemeColor'
const props = withDefaults(defineProps<{
data: TableCell[][]
width: number
cellMinHeight: number
colWidths: number[]
outline: PPTElementOutline
theme?: TableTheme
editable?: boolean
}>(), {
editable: true,
})
const colSizeList = ref<number[]>([])
const totalWidth = computed(() => colSizeList.value.reduce((a, b) => a + b))
watch([
() => props.colWidths,
() => props.width,
], () => {
colSizeList.value = props.colWidths.map(item => item * props.width)
}, { immediate: true })
const cells = computed(() => props.data)
const { hideCells } = useHideCells(cells)
const theme = computed(() => props.theme)
const { subThemeColor } = useSubThemeColor(theme)
</script>
<style lang="scss" scoped>
.static-table {
position: relative;
user-select: none;
}
table {
width: 100%;
position: relative;
table-layout: fixed;
border-collapse: collapse;
border-spacing: 0;
border: 0;
word-wrap: break-word;
user-select: none;
--themeColor: $themeColor;
--subThemeColor1: $themeColor;
--subThemeColor2: $themeColor;
&.theme {
background-color: #fff;
tr:nth-child(2n) .cell {
background-color: var(--subThemeColor1);
}
tr:nth-child(2n + 1) .cell {
background-color: var(--subThemeColor2);
}
&.row-header {
tr:first-child .cell {
background-color: var(--themeColor);
}
}
&.row-footer {
tr:last-child .cell {
background-color: var(--themeColor);
}
}
&.col-header {
tr .cell:first-child {
background-color: var(--themeColor);
}
}
&.col-footer {
tr .cell:last-child {
background-color: var(--themeColor);
}
}
}
.cell {
position: relative;
white-space: normal;
word-wrap: break-word;
vertical-align: middle;
background-clip: padding-box;
}
.cell-text {
padding: 5px;
line-height: 1.5;
}
}
</style> |