-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
74 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,38 @@ | ||
import { defineStore } from 'pinia' | ||
import type { FetchOptions } from '@types' | ||
|
||
type Config = Omit<FetchOptions, 'cookie'> & { | ||
isMinimize: boolean | ||
} | ||
|
||
export const useConfigStore = defineStore('config', () => { | ||
const now = Date.now() | ||
const localData = JSON.parse(localStorage.getItem('fetchOptions') || '{}') as Config | ||
const KEY_MINIMIZE = 'archiver-isMinimize' | ||
|
||
const isMinimize = ref(localStorage.getItem(KEY_MINIMIZE) === 'true') | ||
|
||
const state = reactive<Config>({ | ||
const state = reactive<FetchOptions>({ | ||
uid: '', | ||
name: '', | ||
isFetchAll: true, | ||
largePic: true, | ||
repostPic: true, | ||
hasRepost: true, | ||
hasComment: true, | ||
hasFavorite: true, | ||
commentCount: 6, | ||
dateRange: [now, now], | ||
isMinimize: true, | ||
}) | ||
|
||
// 判断 key 是否都相等,如果相等则初始化配置 | ||
function initConfig() { | ||
const keys = Object.keys(state) | ||
const localKeys = Object.keys(localData) | ||
const isSame = keys.every(key => localKeys.includes(key)) | ||
|
||
if (isSame) | ||
setConfig(localData) | ||
} | ||
|
||
function setConfig(config: Partial<Config>) { | ||
function setConfig(config: Partial<FetchOptions>) { | ||
Object.assign(state, config) | ||
} | ||
|
||
watchEffect(() => { | ||
localStorage.setItem('fetchOptions', JSON.stringify(state)) | ||
}) | ||
function toggleMinimize() { | ||
isMinimize.value = !isMinimize.value | ||
localStorage.setItem(KEY_MINIMIZE, isMinimize.value.toString()) | ||
} | ||
|
||
return { | ||
state, | ||
isMinimize, | ||
setConfig, | ||
initConfig, | ||
toggleMinimize, | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters