mirror of
https://github.com/Kuingsmile/PicList.git
synced 2026-05-30 20:50:52 +08:00
39 lines
784 B
TypeScript
39 lines
784 B
TypeScript
import { App, InjectionKey, reactive, readonly, UnwrapRef } from 'vue'
|
|
|
|
import { configPaths } from '@/utils/configPaths'
|
|
import { saveConfig } from '@/utils/dataSender'
|
|
|
|
export interface IState {
|
|
defaultPicBed: string
|
|
}
|
|
|
|
export interface IStore {
|
|
state: UnwrapRef<IState>
|
|
setDefaultPicBed: (type: string) => void
|
|
}
|
|
|
|
export const storeKey: InjectionKey<IStore> = Symbol('store')
|
|
|
|
// state
|
|
const state: IState = reactive({
|
|
defaultPicBed: 'smms'
|
|
})
|
|
|
|
// methods
|
|
const setDefaultPicBed = (type: string) => {
|
|
saveConfig({
|
|
[configPaths.picBed.current]: type,
|
|
[configPaths.picBed.uploader]: type
|
|
})
|
|
state.defaultPicBed = type
|
|
}
|
|
|
|
export const store = {
|
|
install (app: App) {
|
|
app.provide(storeKey, {
|
|
state: readonly(state),
|
|
setDefaultPicBed
|
|
})
|
|
}
|
|
}
|