|
|
@@ -71,12 +71,14 @@
|
|
|
<script lang="ts">
|
|
|
import { computed, defineComponent, nextTick, onMounted, onUnmounted, PropType, ref, watch } from 'vue'
|
|
|
import debounce from 'lodash/debounce'
|
|
|
-import tinycolor from 'tinycolor2'
|
|
|
import { useStore } from '@/store'
|
|
|
-import { PPTElementOutline, TableCell, TableCellStyle, TableTheme } from '@/types/slides'
|
|
|
+import { PPTElementOutline, TableCell, TableTheme } from '@/types/slides'
|
|
|
import { ContextmenuItem } from '@/components/Contextmenu/types'
|
|
|
import { KEYS } from '@/configs/hotkey'
|
|
|
import { createRandomCode } from '@/utils/common'
|
|
|
+import { getTextStyle } from './utils'
|
|
|
+import useHideCells from './useHideCells'
|
|
|
+import useSubThemeColor from './useSubThemeColor'
|
|
|
|
|
|
import CustomTextarea from './CustomTextarea.vue'
|
|
|
|
|
|
@@ -127,19 +129,9 @@ export default defineComponent({
|
|
|
},
|
|
|
})
|
|
|
|
|
|
- // 通过表格的主题色计算辅助颜色
|
|
|
- const subThemeColor = ref(['', ''])
|
|
|
- watch(() => props.theme, () => {
|
|
|
- if (props.theme) {
|
|
|
- const rgba = tinycolor(props.theme.color).toRgb()
|
|
|
- const subRgba1 = { r: rgba.r, g: rgba.g, b: rgba.b, a: rgba.a * 0.3 }
|
|
|
- const subRgba2 = { r: rgba.r, g: rgba.g, b: rgba.b, a: rgba.a * 0.1 }
|
|
|
- subThemeColor.value = [
|
|
|
- `rgba(${[subRgba1.r, subRgba1.g, subRgba1.b, subRgba1.a].join(',')})`,
|
|
|
- `rgba(${[subRgba2.r, subRgba2.g, subRgba2.b, subRgba2.a].join(',')})`,
|
|
|
- ]
|
|
|
- }
|
|
|
- }, { immediate: true })
|
|
|
+ // 主题辅助色
|
|
|
+ const theme = computed(() => props.theme)
|
|
|
+ const { subThemeColor } = useSubThemeColor(theme)
|
|
|
|
|
|
// 计算表格每一列的列宽和总宽度
|
|
|
const colSizeList = ref<number[]>([])
|
|
|
@@ -173,26 +165,8 @@ export default defineComponent({
|
|
|
})
|
|
|
|
|
|
// 无效的单元格位置(被合并的单元格位置)集合
|
|
|
- const hideCells = computed(() => {
|
|
|
- const hideCells = []
|
|
|
-
|
|
|
- for (let i = 0; i < tableCells.value.length; i++) {
|
|
|
- const rowCells = tableCells.value[i]
|
|
|
-
|
|
|
- for (let j = 0; j < rowCells.length; j++) {
|
|
|
- const cell = rowCells[j]
|
|
|
-
|
|
|
- if (cell.colspan > 1 || cell.rowspan > 1) {
|
|
|
- for (let row = i; row < i + cell.rowspan; row++) {
|
|
|
- for (let col = row === i ? j + 1 : j; col < j + cell.colspan; col++) {
|
|
|
- hideCells.push(`${row}_${col}`)
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- return hideCells
|
|
|
- })
|
|
|
+ const cells = computed(() => props.data)
|
|
|
+ const { hideCells } = useHideCells(cells)
|
|
|
|
|
|
// 当前选中的单元格集合
|
|
|
const selectedCells = computed(() => {
|
|
|
@@ -526,33 +500,6 @@ export default defineComponent({
|
|
|
document.removeEventListener('keydown', keydownListener)
|
|
|
})
|
|
|
|
|
|
- // 计算单元格文本样式
|
|
|
- const getTextStyle = (style?: TableCellStyle) => {
|
|
|
- if (!style) return {}
|
|
|
- const {
|
|
|
- bold,
|
|
|
- em,
|
|
|
- underline,
|
|
|
- strikethrough,
|
|
|
- color,
|
|
|
- backcolor,
|
|
|
- fontsize,
|
|
|
- fontname,
|
|
|
- align,
|
|
|
- } = style
|
|
|
-
|
|
|
- return {
|
|
|
- fontWeight: bold ? 'bold' : 'normal',
|
|
|
- fontStyle: em ? 'italic' : 'normal',
|
|
|
- textDecoration: `${underline ? 'underline' : ''} ${strikethrough ? 'line-through' : ''}`,
|
|
|
- color: color || '#000',
|
|
|
- backgroundColor: backcolor || '',
|
|
|
- fontSize: fontsize || '14px',
|
|
|
- fontFamily: fontname || '微软雅黑',
|
|
|
- textAlign: align || 'left',
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
// 单元格文字输入时更新表格数据
|
|
|
const handleInput = debounce(function() {
|
|
|
emit('change', tableCells.value)
|