faet: 新增保存快捷键
This commit is contained in:
parent
24fba75f28
commit
c3738fab45
@ -19,7 +19,8 @@ export enum MenuEnum {
|
|||||||
DOWN = 'down',
|
DOWN = 'down',
|
||||||
CLEAR = 'clear',
|
CLEAR = 'clear',
|
||||||
BACK = 'back',
|
BACK = 'back',
|
||||||
FORWORD = 'forward'
|
FORWORD = 'forward',
|
||||||
|
SAVE = 'save'
|
||||||
}
|
}
|
||||||
|
|
||||||
// Win 键盘枚举
|
// Win 键盘枚举
|
||||||
|
@ -163,6 +163,19 @@ export const fetchRouteParams = () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* * 通过硬解析获取当前路由下的参数
|
||||||
|
* @returns object
|
||||||
|
*/
|
||||||
|
export const fetchRouteParamsByhistory = () => {
|
||||||
|
try {
|
||||||
|
return document.location.hash.split('/').pop() || ''
|
||||||
|
} catch (error) {
|
||||||
|
window['$message'].warning('查询路由信息失败,请联系管理员!')
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* * 回到主页面
|
* * 回到主页面
|
||||||
* @param confirm
|
* @param confirm
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
|
import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
|
||||||
|
import { useSync } from './useSync.hook'
|
||||||
import { WinKeyboard, MacKeyboard, MenuEnum } from '@/enums/editPageEnum'
|
import { WinKeyboard, MacKeyboard, MenuEnum } from '@/enums/editPageEnum'
|
||||||
import throttle from 'lodash/throttle'
|
import throttle from 'lodash/throttle'
|
||||||
import debounce from 'lodash/debounce'
|
import debounce from 'lodash/debounce'
|
||||||
@ -6,7 +7,7 @@ import debounce from 'lodash/debounce'
|
|||||||
import keymaster from 'keymaster'
|
import keymaster from 'keymaster'
|
||||||
// Keymaster可以支持识别以下组合键: ⇧,shift,option,⌥,alt,ctrl,control,command,和⌘
|
// Keymaster可以支持识别以下组合键: ⇧,shift,option,⌥,alt,ctrl,control,command,和⌘
|
||||||
const chartEditStore = useChartEditStore()
|
const chartEditStore = useChartEditStore()
|
||||||
|
const useSyncIns = useSync()
|
||||||
const winCtrlMerge = (e: string) => `${WinKeyboard.CTRL}+${e}`
|
const winCtrlMerge = (e: string) => `${WinKeyboard.CTRL}+${e}`
|
||||||
const winShiftMerge = (e: string) => `${WinKeyboard.SHIFT}+${e}`
|
const winShiftMerge = (e: string) => `${WinKeyboard.SHIFT}+${e}`
|
||||||
const winAltMerge = (e: string) => `${WinKeyboard.ALT}+${e}`
|
const winAltMerge = (e: string) => `${WinKeyboard.ALT}+${e}`
|
||||||
@ -22,6 +23,7 @@ export const winKeyboardValue = {
|
|||||||
[MenuEnum.DELETE]: 'delete',
|
[MenuEnum.DELETE]: 'delete',
|
||||||
[MenuEnum.BACK]: winCtrlMerge('z'),
|
[MenuEnum.BACK]: winCtrlMerge('z'),
|
||||||
[MenuEnum.FORWORD]: winCtrlMerge(winShiftMerge('z')),
|
[MenuEnum.FORWORD]: winCtrlMerge(winShiftMerge('z')),
|
||||||
|
[MenuEnum.SAVE]: winCtrlMerge('s'),
|
||||||
}
|
}
|
||||||
|
|
||||||
// 这个 Ctrl 后面还是换成了 ⌘
|
// 这个 Ctrl 后面还是换成了 ⌘
|
||||||
@ -41,6 +43,7 @@ export const macKeyboardValue = {
|
|||||||
[MenuEnum.DELETE]: macCtrlMerge('backspace'),
|
[MenuEnum.DELETE]: macCtrlMerge('backspace'),
|
||||||
[MenuEnum.BACK]: macCtrlMerge('z'),
|
[MenuEnum.BACK]: macCtrlMerge('z'),
|
||||||
[MenuEnum.FORWORD]: macCtrlMerge(macShiftMerge('z')),
|
[MenuEnum.FORWORD]: macCtrlMerge(macShiftMerge('z')),
|
||||||
|
[MenuEnum.SAVE]: macCtrlMerge('s'),
|
||||||
}
|
}
|
||||||
|
|
||||||
// Win 快捷键列表
|
// Win 快捷键列表
|
||||||
@ -57,6 +60,8 @@ const winKeyList: Array<string> = [
|
|||||||
|
|
||||||
winKeyboardValue.back,
|
winKeyboardValue.back,
|
||||||
winKeyboardValue.forward,
|
winKeyboardValue.forward,
|
||||||
|
|
||||||
|
winKeyboardValue.save,
|
||||||
]
|
]
|
||||||
|
|
||||||
// Mac 快捷键列表
|
// Mac 快捷键列表
|
||||||
@ -73,6 +78,8 @@ const macKeyList: Array<string> = [
|
|||||||
|
|
||||||
macKeyboardValue.back,
|
macKeyboardValue.back,
|
||||||
macKeyboardValue.forward,
|
macKeyboardValue.forward,
|
||||||
|
|
||||||
|
macKeyboardValue.save,
|
||||||
]
|
]
|
||||||
|
|
||||||
// 初始化监听事件
|
// 初始化监听事件
|
||||||
@ -121,6 +128,11 @@ export const useAddKeyboard = () => {
|
|||||||
case keyboardValue.forward:
|
case keyboardValue.forward:
|
||||||
keymaster(e, throttle(() => { chartEditStore.setForward(); return false }, 200))
|
keymaster(e, throttle(() => { chartEditStore.setForward(); return false }, 200))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
// 保存 ct+s
|
||||||
|
case keyboardValue.save:
|
||||||
|
keymaster(e, throttle(() => { useSyncIns.dataSyncUpdate(); return false }, 200))
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
winKeyList.forEach((key: string) => {
|
winKeyList.forEach((key: string) => {
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
import { onUnmounted } from 'vue';
|
import { onUnmounted } from 'vue';
|
||||||
import { useRoute } from 'vue-router'
|
import { httpErrorHandle, fetchRouteParamsByhistory } from '@/utils'
|
||||||
import { httpErrorHandle } from '@/utils'
|
|
||||||
import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
|
import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
|
||||||
import { EditCanvasTypeEnum, ChartEditStoreEnum } from '@/store/modules/chartEditStore/chartEditStore.d'
|
import { EditCanvasTypeEnum, ChartEditStoreEnum } from '@/store/modules/chartEditStore/chartEditStore.d'
|
||||||
import { useChartHistoryStore } from '@/store/modules/chartHistoryStore/chartHistoryStore'
|
import { useChartHistoryStore } from '@/store/modules/chartHistoryStore/chartHistoryStore'
|
||||||
@ -18,7 +17,6 @@ import { SyncEnum } from '@/enums/editPageEnum'
|
|||||||
export const useSync = () => {
|
export const useSync = () => {
|
||||||
const chartEditStore = useChartEditStore()
|
const chartEditStore = useChartEditStore()
|
||||||
const chartHistoryStore = useChartHistoryStore()
|
const chartHistoryStore = useChartHistoryStore()
|
||||||
const routerParamsInfo = useRoute()
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* * 组件动态注册
|
* * 组件动态注册
|
||||||
@ -71,8 +69,7 @@ export const useSync = () => {
|
|||||||
const dataSyncFetch = async () => {
|
const dataSyncFetch = async () => {
|
||||||
chartEditStore.setEditCanvas(EditCanvasTypeEnum.SAVE_STATUS, SyncEnum.START)
|
chartEditStore.setEditCanvas(EditCanvasTypeEnum.SAVE_STATUS, SyncEnum.START)
|
||||||
try {
|
try {
|
||||||
const { id } = routerParamsInfo.params
|
const res: any = await fetchProjectApi({ projectId: fetchRouteParamsByhistory() })
|
||||||
const res: any = await fetchProjectApi({ projectId: id[0] })
|
|
||||||
if (res.code === ResultEnum.SUCCESS) {
|
if (res.code === ResultEnum.SUCCESS) {
|
||||||
if (res.data) {
|
if (res.data) {
|
||||||
const data = JSON.parse(res.data)
|
const data = JSON.parse(res.data)
|
||||||
@ -93,13 +90,10 @@ export const useSync = () => {
|
|||||||
|
|
||||||
// 数据保存
|
// 数据保存
|
||||||
const dataSyncUpdate = async () => {
|
const dataSyncUpdate = async () => {
|
||||||
|
|
||||||
chartEditStore.setEditCanvas(EditCanvasTypeEnum.SAVE_STATUS, SyncEnum.START)
|
chartEditStore.setEditCanvas(EditCanvasTypeEnum.SAVE_STATUS, SyncEnum.START)
|
||||||
// 获取id
|
|
||||||
const { id } = routerParamsInfo.params
|
|
||||||
|
|
||||||
let params = new FormData()
|
let params = new FormData()
|
||||||
params.append('projectId', id[0])
|
params.append('projectId', fetchRouteParamsByhistory())
|
||||||
params.append('content', JSON.stringify(chartEditStore.getStorageInfo || {}))
|
params.append('content', JSON.stringify(chartEditStore.getStorageInfo || {}))
|
||||||
const res: any = await saveProjectApi(params)
|
const res: any = await saveProjectApi(params)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user