2024-09-09 17:53:07 +08:00
|
|
|
import { defineStore } from 'pinia'
|
|
|
|
import type { Layout } from './layout.types'
|
2024-09-11 13:46:40 +08:00
|
|
|
import { reactive, ref, toRaw, watch } from 'vue'
|
|
|
|
import db from '@/db'
|
2024-09-09 17:53:07 +08:00
|
|
|
|
|
|
|
const defaultLayout: Layout = {
|
|
|
|
content: [[], [], []],
|
|
|
|
current: 0,
|
|
|
|
currentPage: 0,
|
|
|
|
dir: {},
|
2024-09-11 13:46:40 +08:00
|
|
|
dock: [null, null, null, null, null, null, null, null, null, null],
|
2024-09-09 17:53:07 +08:00
|
|
|
simple: false,
|
|
|
|
loading: true
|
|
|
|
}
|
|
|
|
|
|
|
|
export default defineStore('layout', () => {
|
2024-09-11 13:46:40 +08:00
|
|
|
const state = reactive(defaultLayout)
|
|
|
|
const ready = ref(false)
|
|
|
|
db.getItem<Layout>('layout').then((res) => {
|
|
|
|
if (res) {
|
|
|
|
Object.assign(state, res)
|
|
|
|
}
|
|
|
|
ready.value = true
|
|
|
|
})
|
|
|
|
watch(
|
|
|
|
[ready, state],
|
|
|
|
([re, s]) => {
|
|
|
|
if (!re) return
|
|
|
|
db.setItem('layout', toRaw(s))
|
|
|
|
},
|
|
|
|
{ deep: true }
|
|
|
|
)
|
|
|
|
watch(
|
|
|
|
() => state.current,
|
|
|
|
() => {
|
|
|
|
state.currentPage = 0
|
|
|
|
}
|
|
|
|
)
|
2024-09-09 17:53:07 +08:00
|
|
|
return {
|
2024-09-11 13:46:40 +08:00
|
|
|
state,
|
|
|
|
ready
|
2024-09-09 17:53:07 +08:00
|
|
|
}
|
|
|
|
})
|