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,7 +1,7 @@
import { ref, computed } from 'vue'
import { defineStore } from 'pinia'
import { dispatchNotification } from '@/components/Notification'
import { readData, removeData, writeData } from './storage'
import { readData, removeData, writeData } from '@/utils/storage'
import router from '@/router'
export const useAuthStore = defineStore('auth', () => {

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

View File

@ -1,28 +0,0 @@
import { EncryptStorage } from 'encrypt-storage'
const encryptStorage = new EncryptStorage('qwertyuiopasdfghjklzxcvbnm-1234567890')
const writeData = (key: string, data: any) => encryptStorage.setItem(key, data)
const writeDataJson = (key: string, data: any) => encryptStorage.setItem(key, JSON.stringify(data))
const removeData = (key: string) => encryptStorage.removeItem(key)
const readData = (key: string) => {
try {
return encryptStorage.getItem(key)
} catch (error) {
return undefined
}
}
const readDataJson = (key: string) => {
try {
return encryptStorage.getItem(key)
} catch (error) {
return undefined
}
}
export {
removeData,
writeData,
writeDataJson,
readData,
readDataJson
}