feat: 图表数据编辑添加快捷键:回车聚焦到下一行(#44)

This commit is contained in:
pipipi-pikachu 2021-06-22 21:42:47 +08:00
parent 702e91e9b4
commit 5111c5ec3e
2 changed files with 33 additions and 2 deletions

View File

@ -84,6 +84,12 @@ export const HOTKEY_DOC = [
{ label: '在右侧插入一列', value: 'Ctrl + →' }, { label: '在右侧插入一列', value: 'Ctrl + →' },
], ],
}, },
{
type: '图表数据编辑',
children: [
{ label: '聚焦到下一行', value: 'Enter' },
],
},
{ {
type: '文本编辑', type: '文本编辑',
children: [ children: [

View File

@ -29,6 +29,7 @@
:class="['item', { 'selected': rowIndex <= selectedRange[1] && colIndex <= selectedRange[0] }]" :class="['item', { 'selected': rowIndex <= selectedRange[1] && colIndex <= selectedRange[0] }]"
:id="`cell-${rowIndex - 1}-${colIndex - 1}`" :id="`cell-${rowIndex - 1}-${colIndex - 1}`"
autocomplete="off" autocomplete="off"
@focus="focusCell = [rowIndex - 1, colIndex - 1]"
> >
</td> </td>
</tr> </tr>
@ -44,8 +45,9 @@
</template> </template>
<script lang="ts"> <script lang="ts">
import { computed, defineComponent, onMounted, onUnmounted, PropType, ref } from 'vue'
import { ChartData } from '@/types/slides' import { ChartData } from '@/types/slides'
import { computed, defineComponent, onMounted, PropType, ref } from 'vue' import { KEYS } from '@/configs/hotkey'
const CELL_WIDTH = 100 const CELL_WIDTH = 100
const CELL_HEIGHT = 32 const CELL_HEIGHT = 32
@ -61,6 +63,7 @@ export default defineComponent({
setup(props, { emit }) { setup(props, { emit }) {
const selectedRange = ref([0, 0]) const selectedRange = ref([0, 0])
const tempRangeSize = ref({ width: 0, height: 0 }) const tempRangeSize = ref({ width: 0, height: 0 })
const focusCell = ref<[number, number] | null>(null)
// 线 // 线
const rangeLines = computed(() => { const rangeLines = computed(() => {
@ -110,6 +113,27 @@ export default defineComponent({
onMounted(initData) onMounted(initData)
//
const moveNextRow = () => {
if (!focusCell.value) return
const [rowIndex, colIndex] = focusCell.value
const inputRef = document.querySelector(`#cell-${rowIndex + 1}-${colIndex}`) as HTMLInputElement
inputRef && inputRef.focus()
}
const keyboardListener = (e: KeyboardEvent) => {
const key = e.key.toUpperCase()
if (key === KEYS.ENTER) moveNextRow()
}
onMounted(() => {
document.addEventListener('keydown', keyboardListener)
})
onUnmounted(() => {
document.removeEventListener('keydown', keyboardListener)
})
// DOM // DOM
const getTableData = () => { const getTableData = () => {
const [col, row] = selectedRange.value const [col, row] = selectedRange.value
@ -200,8 +224,9 @@ export default defineComponent({
tempRangeSize, tempRangeSize,
rangeLines, rangeLines,
resizablePointStyle, resizablePointStyle,
changeSelectRange,
selectedRange, selectedRange,
focusCell,
changeSelectRange,
getTableData, getTableData,
closeEditor, closeEditor,
} }