This commit is contained in:
Dede Fuji Abdul
2023-10-24 15:24:21 +07:00
parent 6931e06952
commit 96d8550cfe
9 changed files with 199 additions and 215 deletions

View File

@@ -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
}
})