docs: 补充代码注释

This commit is contained in:
pipipi-pikachu 2021-02-15 16:41:50 +08:00
parent d82641503f
commit 16c0f84297
6 changed files with 48 additions and 11 deletions

View File

@ -62,6 +62,7 @@ export default defineComponent({
const selectedRange = ref([0, 0])
const tempRangeSize = ref({ width: 0, height: 0 })
// 线
const rangeLines = computed(() => {
const width = selectedRange.value[0] * CELL_WIDTH
const height = selectedRange.value[1] * CELL_HEIGHT
@ -73,12 +74,14 @@ export default defineComponent({
]
})
//
const resizablePointStyle = computed(() => {
const width = selectedRange.value[0] * CELL_WIDTH
const height = selectedRange.value[1] * CELL_HEIGHT
return { left: width + 'px', top: height + 'px' }
})
// DOM
const initData = () => {
const _data: string[][] = []
@ -107,12 +110,14 @@ export default defineComponent({
onMounted(initData)
// DOM
const getTableData = () => {
const [col, row] = selectedRange.value
const labels: string[] = []
const series: number[][] = []
//
for (let rowIndex = 0; rowIndex < row; rowIndex++) {
let labelsItem = `类别${rowIndex + 1}`
const labelInputRef = document.querySelector(`#cell-${rowIndex}-0`) as HTMLInputElement
@ -136,8 +141,10 @@ export default defineComponent({
emit('save', data)
}
//
const closeEditor = () => emit('close')
//
const changeSelectRange = (e: MouseEvent) => {
let isMouseDown = true
@ -172,6 +179,7 @@ export default defineComponent({
if (startPageX === endPageX && startPageY === endPageY) return
//
let width = tempRangeSize.value.width
let height = tempRangeSize.value.height
if (width % CELL_WIDTH > CELL_WIDTH * 0.5) width = width + (CELL_WIDTH - width % CELL_WIDTH)

View File

@ -159,6 +159,7 @@ export default defineComponent({
gridColor.value = handleElement.value.gridColor || 'rgba(0, 0, 0, 0.4)'
}, { deep: true, immediate: true })
//
const updateData = (data: ChartData) => {
chartDataEditorVisible.value = false
const props = { data }
@ -166,12 +167,14 @@ export default defineComponent({
addHistorySnapshot()
}
//
const updateFill = (value: string) => {
const props = { fill: value }
store.commit(MutationTypes.UPDATE_ELEMENT, { id: handleElement.value.id, props })
addHistorySnapshot()
}
// 线线线线
const updateOptions = (optionProps: ILineChartOptions & IBarChartOptions & IPieChartOptions) => {
const options = handleElement.value.options || {}
const newOptions = { ...options, ...optionProps }
@ -180,12 +183,14 @@ export default defineComponent({
addHistorySnapshot()
}
//
const updateTheme = (themeColor: string) => {
const props = { themeColor }
store.commit(MutationTypes.UPDATE_ELEMENT, { id: handleElement.value.id, props })
addHistorySnapshot()
}
//
const updateGridColor = (gridColor: string) => {
const props = { gridColor }
store.commit(MutationTypes.UPDATE_ELEMENT, { id: handleElement.value.id, props })

View File

@ -171,6 +171,7 @@ export default defineComponent({
const { addHistorySnapshot } = useHistorySnapshot()
//
const updateFilter = (filter: FilterOption, value: number) => {
const originFilters = handleElement.value.filters || {}
const filters = { ...originFilters, [filter.key]: `${value}${filter.unit}` }
@ -179,20 +180,22 @@ export default defineComponent({
addHistorySnapshot()
}
//
const clipImage = () => {
store.commit(MutationTypes.SET_CLIPING_IMAGE_ELEMENT_ID, handleElement.value.id)
clipPanelVisible.value = false
}
//
const getImageElementDataBeforeClip = () => {
//
//
const imgWidth = handleElement.value.width
const imgHeight = handleElement.value.height
const imgLeft = handleElement.value.left
const imgTop = handleElement.value.top
const originClipRange = handleElement.value.clip ? handleElement.value.clip.range : [[0, 0], [100, 100]]
//
const originWidth = imgWidth / ((originClipRange[1][0] - originClipRange[0][0]) / 100)
const originHeight = imgHeight / ((originClipRange[1][1] - originClipRange[0][1]) / 100)
const originLeft = imgLeft - originWidth * (originClipRange[0][0] / 100)
@ -207,6 +210,7 @@ export default defineComponent({
}
}
//
const presetImageClip = (shape: string, ratio = 0) => {
const {
originClipRange,
@ -216,7 +220,7 @@ export default defineComponent({
originTop,
} = getImageElementDataBeforeClip()
//
//
if (ratio) {
const imageRatio = originHeight / originWidth
@ -243,7 +247,7 @@ export default defineComponent({
},
})
}
//
//
else {
store.commit(MutationTypes.UPDATE_ELEMENT, {
id: handleElement.value.id,
@ -256,6 +260,7 @@ export default defineComponent({
addHistorySnapshot()
}
//
const replaceImage = (files: File[]) => {
const imageFile = files[0]
if (!imageFile) return
@ -266,6 +271,7 @@ export default defineComponent({
addHistorySnapshot()
}
//
const resetImage = () => {
if (handleElement.value.clip) {
const {
@ -293,6 +299,7 @@ export default defineComponent({
addHistorySnapshot()
}
//
const setBackgroundImage = () => {
const background = {
...currentSlide.value.background,

View File

@ -118,6 +118,7 @@ export default defineComponent({
const { addHistorySnapshot } = useHistorySnapshot()
//
const updateFillType = (type: 'gradient' | 'fill') => {
if (type === 'fill') {
store.commit(MutationTypes.REMOVE_ELEMENT_PROPS, {
@ -132,12 +133,14 @@ export default defineComponent({
addHistorySnapshot()
}
//
const updateGradient = (gradientProps: Partial<ShapeGradient>) => {
const props = { gradient: { ...gradient.value, ...gradientProps } }
store.commit(MutationTypes.UPDATE_ELEMENT, { id: handleElement.value.id, props })
addHistorySnapshot()
}
//
const updateFill = (value: string) => {
const props = { fill: value }
store.commit(MutationTypes.UPDATE_ELEMENT, { id: handleElement.value.id, props })

View File

@ -206,6 +206,11 @@ export default defineComponent({
setup() {
const store = useStore()
const handleElement = computed<PPTTableElement>(() => store.getters.handleElement)
const availableFonts = computed(() => store.state.availableFonts)
const fontSizeOptions = [
'12px', '14px', '16px', '18px', '20px', '22px', '24px', '28px', '32px',
]
const textAttrs = ref({
bold: false,
@ -239,8 +244,11 @@ export default defineComponent({
minColCount.value = handleElement.value.data[0].length
}, { deep: true, immediate: true })
const { addHistorySnapshot } = useHistorySnapshot()
const selectedCells = ref<string[]>([])
//
const updateTextAttrState = () => {
if (!handleElement.value) return
@ -281,6 +289,7 @@ export default defineComponent({
}
}
//
const updateSelectedCells = (cells: string[]) => {
selectedCells.value = cells
updateTextAttrState()
@ -291,13 +300,7 @@ export default defineComponent({
emitter.off(EmitterEvents.UPDATE_TABLE_SELECTED_CELL, cells => updateSelectedCells(cells))
})
const availableFonts = computed(() => store.state.availableFonts)
const fontSizeOptions = [
'12px', '14px', '16px', '18px', '20px', '22px', '24px', '28px', '32px',
]
const { addHistorySnapshot } = useHistorySnapshot()
//
const updateTextAttrs = (textAttrProp: Partial<TableCellStyle>) => {
const data: TableCell[][] = JSON.parse(JSON.stringify(handleElement.value.data))
@ -316,6 +319,7 @@ export default defineComponent({
updateTextAttrState()
}
//
const updateTheme = (themeProp: Partial<TableTheme>) => {
const currentTheme = theme.value || {}
const props = { theme: { ...currentTheme, ...themeProp } }
@ -323,6 +327,7 @@ export default defineComponent({
addHistorySnapshot()
}
// /
const toggleTheme = (checked: boolean) => {
if (checked) {
const props = {
@ -342,6 +347,7 @@ export default defineComponent({
addHistorySnapshot()
}
//
const setTableRow = (e: KeyboardEvent) => {
const value = +(e.target as HTMLInputElement).value
const rowCount = handleElement.value.data.length
@ -360,6 +366,8 @@ export default defineComponent({
addHistorySnapshot()
}
//
const setTableCol = (e: KeyboardEvent) => {
const value = +(e.target as HTMLInputElement).value
const colCount = handleElement.value.data[0].length

View File

@ -360,6 +360,7 @@ export default defineComponent({
const lineHeightOptions = [0.9, 1.0, 1.15, 1.2, 1.4, 1.5, 1.8, 2.0, 2.5, 3.0]
const wordSpaceOptions = [0, 1, 2, 3, 4, 5, 6, 8, 10]
//
const updateRichTextAttrs = (attr: TextAttrs) => richTextAttrs.value = attr
emitter.on(EmitterEvents.UPDATE_TEXT_STATE, attr => updateRichTextAttrs(attr))
@ -367,28 +368,33 @@ export default defineComponent({
emitter.off(EmitterEvents.UPDATE_TEXT_STATE, attr => updateRichTextAttrs(attr))
})
//
const emitRichTextCommand = (command: string, value?: string) => {
emitter.emit(EmitterEvents.EXEC_TEXT_COMMAND, { command, value })
}
//
const emitBatchRichTextCommand = (payload: CommandPayload[]) => {
emitter.emit(EmitterEvents.EXEC_TEXT_COMMAND, payload)
}
const { addHistorySnapshot } = useHistorySnapshot()
//
const updateLineHeight = (value: number) => {
const props = { lineHeight: value }
store.commit(MutationTypes.UPDATE_ELEMENT, { id: handleElement.value.id, props })
addHistorySnapshot()
}
//
const updateWordSpace = (value: number) => {
const props = { wordSpace: value }
store.commit(MutationTypes.UPDATE_ELEMENT, { id: handleElement.value.id, props })
addHistorySnapshot()
}
//
const updateFill = (value: string) => {
const props = { fill: value }
store.commit(MutationTypes.UPDATE_ELEMENT, { id: handleElement.value.id, props })