update
This commit is contained in:
@@ -1,21 +1,23 @@
|
||||
import { ref } from 'vue'
|
||||
import { defineStore } from 'pinia'
|
||||
import type { RouteRecordRaw } from 'vue-router'
|
||||
import { readDataJson, writeDataJson } from '@/utils/storage'
|
||||
|
||||
export const useCommandPalattesStore = defineStore('command_palettes', () => {
|
||||
const open = ref(false);
|
||||
const open = ref(false)
|
||||
|
||||
const controlStatus = ref(false)
|
||||
const keyFStatus = ref(false)
|
||||
|
||||
function showCommandPalettes() {
|
||||
const showCommandPalettes = () => {
|
||||
open.value = true;
|
||||
}
|
||||
|
||||
function handleOnDismissCommandPalettes() {
|
||||
const handleOnDismissCommandPalettes = () => {
|
||||
open.value = false;
|
||||
}
|
||||
|
||||
function onKeyPressed(event: KeyboardEvent) {
|
||||
const onKeyPressed = (event: KeyboardEvent) => {
|
||||
if (event.key === 'Control') {
|
||||
console.log('control pressed');
|
||||
controlStatus.value = true
|
||||
@@ -31,7 +33,7 @@ export const useCommandPalattesStore = defineStore('command_palettes', () => {
|
||||
}
|
||||
}
|
||||
|
||||
function onKeyUp(event: KeyboardEvent) {
|
||||
const onKeyUp = (event: KeyboardEvent) => {
|
||||
if (event.key === 'Control') {
|
||||
console.log('control released');
|
||||
controlStatus.value = false
|
||||
@@ -43,5 +45,39 @@ export const useCommandPalattesStore = defineStore('command_palettes', () => {
|
||||
}
|
||||
}
|
||||
|
||||
return { open, showCommandPalettes, handleOnDismissCommandPalettes, onKeyPressed, onKeyUp }
|
||||
const readRecent = (): RouteRecordRaw[] => {
|
||||
const recent = readDataJson('recentmenu')
|
||||
if (recent) {
|
||||
try {
|
||||
JSON.parse(recent)
|
||||
} catch (error) {
|
||||
return recent as RouteRecordRaw[]
|
||||
}
|
||||
}
|
||||
return [] as RouteRecordRaw[]
|
||||
}
|
||||
|
||||
const addRecent = (menu: RouteRecordRaw) => {
|
||||
const lastRecent = readRecent()
|
||||
const index = lastRecent.findIndex((item: RouteRecordRaw) => item.path === menu.path)
|
||||
if (index > -1) {
|
||||
lastRecent.splice(index, 1)
|
||||
}
|
||||
lastRecent.unshift(menu)
|
||||
if (lastRecent.length > 5) {
|
||||
lastRecent.pop()
|
||||
}
|
||||
|
||||
writeDataJson('recentmenu', lastRecent)
|
||||
}
|
||||
|
||||
return {
|
||||
open,
|
||||
showCommandPalettes,
|
||||
handleOnDismissCommandPalettes,
|
||||
onKeyPressed,
|
||||
onKeyUp,
|
||||
addRecent,
|
||||
readRecent
|
||||
}
|
||||
})
|
Reference in New Issue
Block a user