-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
Merge pull request #139 from j10ccc/refactor/general-service
refactor(store): 使用 pinia 重构 system 和 service store
Showing
12 changed files
with
364 additions
and
322 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
type OptionsType = { | ||
campus: "屏峰" | "朝晖" | "莫干山"; | ||
category: "全部" | "失物" | "寻物", | ||
kind: "全部" | string; | ||
}; | ||
|
||
export default function useLostFoundList(options: OptionsType) { | ||
Check failure on line 7 in src/hooks/lostfound/useLostFoundList.ts
|
||
|
||
} |
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,27 +1,12 @@ | ||
import { createStore } from "vuex"; | ||
import createPersistedState from "vuex-persistedstate"; | ||
import { ServiceStoreType, ServiceStore } from "./service"; | ||
import { SystemStoreType, SystemStore } from "./system"; | ||
import { persistedStateStorage } from "../utils/storage"; | ||
import { createPinia } from "pinia"; | ||
import piniaPluginPersistedstate from "pinia-plugin-persistedstate"; | ||
import { useSystemStore } from "./system"; | ||
import { useServiceStore } from "./service"; | ||
|
||
interface StoreType { | ||
service: ServiceStoreType; | ||
system: SystemStoreType; | ||
} | ||
const pinia = createPinia(); | ||
pinia.use(piniaPluginPersistedstate); | ||
|
||
const store = createStore<StoreType>({ | ||
modules: { | ||
service: ServiceStore, | ||
system: SystemStore | ||
}, | ||
plugins: [ | ||
createPersistedState({ | ||
storage: persistedStateStorage | ||
}) | ||
] | ||
}); | ||
const serviceStore = store.state.service; | ||
const systemStore = store.state.system; | ||
|
||
export default store; | ||
export { serviceStore, systemStore }; | ||
export { | ||
useSystemStore, | ||
useServiceStore | ||
}; |
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,28 +1,35 @@ | ||
import { Announcement } from "src/types/Announcement"; | ||
import { defineStore } from "pinia"; | ||
import { ref } from "vue"; | ||
|
||
export interface AnnouncementType { | ||
announcements: Announcement[]; | ||
updateCounter: number; | ||
} | ||
|
||
export const AnnouncementStore = { | ||
state: () => ({ | ||
announcements: [], | ||
updateCounter: 0 | ||
}), | ||
mutations: { | ||
setAnnouncements(state: AnnouncementType, value: Announcement[]) { | ||
if (state.announcements.length != value.length) | ||
state.updateCounter = Math.abs( | ||
value.length - state.announcements.length | ||
); | ||
state.announcements = value; | ||
}, | ||
clearAnnouncements(state: AnnouncementType) { | ||
state.announcements = []; | ||
}, | ||
clearAnnouncementsUpdateCounter(state: AnnouncementType) { | ||
state.updateCounter = 0; | ||
} | ||
} | ||
}; | ||
export const useAnnouncementStore = defineStore("announcement", () => { | ||
const announcements = ref<Announcement[]>(); | ||
const updateCounter = ref(0); | ||
|
||
const setAnnouncements = (value: Announcement[]) => { | ||
if (announcements.value?.length != value.length) | ||
updateCounter.value = Math.abs( | ||
value.length - announcements.value!.length | ||
); | ||
announcements.value = value; | ||
}; | ||
const clearAnnouncements = () => { | ||
announcements.value = []; | ||
}; | ||
const clearAnnouncementsUpdateCounter = () => { | ||
updateCounter.value = 0; | ||
}; | ||
return { | ||
announcements, | ||
updateCounter, | ||
setAnnouncements, | ||
clearAnnouncements, | ||
clearAnnouncementsUpdateCounter | ||
}; | ||
}); | ||
|
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,37 +1,54 @@ | ||
import { CardConsume } from "@/types/CardConsume"; | ||
import { ref } from "vue"; | ||
import { defineStore } from "pinia"; | ||
|
||
export interface CardServiceType { | ||
balance?: number; | ||
today: CardConsume[]; | ||
history: CardConsume[]; | ||
updateTime: { | ||
today?: Date; | ||
history?: Date; | ||
balance?: Date; | ||
}; | ||
} | ||
export const CardServiceStore = { | ||
state: () => ({ | ||
balance: 0, | ||
history: [], | ||
today: [], | ||
updateTime: { | ||
balance: undefined, | ||
history: undefined, | ||
today: undefined | ||
} | ||
}), | ||
|
||
mutations: { | ||
setCardBalance(state: CardServiceType, value: number) { | ||
state.balance = value; | ||
state.updateTime.balance = new Date(); | ||
}, | ||
setCardToday(state: CardServiceType, value: CardConsume[]) { | ||
if (value !== null) state.today = value; | ||
else state.today = []; | ||
state.updateTime.today = new Date(); | ||
}, | ||
clearCardToday(state: CardServiceType) { | ||
state.today = []; | ||
} | ||
} | ||
}; | ||
export const useCardServiceStore = defineStore("card", () => { | ||
const balance = ref<number>(); | ||
const history = ref<CardConsume[]>([]); | ||
const today = ref<CardConsume[]>([]); | ||
const updateTime = ref<{ | ||
balance?: Date; | ||
history?: Date; | ||
today?: Date; | ||
}>({ | ||
balance: undefined, | ||
history: undefined, | ||
today: undefined | ||
}); | ||
|
||
const setCardBalance = (value: number) => { | ||
balance.value = value; | ||
updateTime.value.balance = new Date(); | ||
}; | ||
|
||
const setCardToday = (value: CardConsume[]) => { | ||
if (value !== null) today.value = value; | ||
else today.value = []; | ||
updateTime.value.today = new Date(); | ||
}; | ||
|
||
const clearCardToday = () => { | ||
today.value = []; | ||
}; | ||
|
||
return { | ||
balance, | ||
history, | ||
today, | ||
updateTime, | ||
setCardBalance, | ||
setCardToday, | ||
clearCardToday | ||
}; | ||
}); |
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,54 +1,48 @@ | ||
import { Score } from "@/types/Score"; | ||
import { ServiceStoreType } from "."; | ||
import { ref } from "vue"; | ||
import { defineStore } from "pinia"; | ||
|
||
type ScoreServiceStoreType = ServiceStoreType["score"]; | ||
export const useScoreServiceStore = defineStore("score", () => { | ||
const readScoreMarks = ref(); | ||
const findNewScoresTime = ref(); | ||
const scorePeriod = ref("期末"); | ||
|
||
export const ScoreServiceStore = { | ||
state: { | ||
readScoreMarks: [], // 所有已读成绩的标记 | ||
findNewScoresTime: undefined, | ||
scorePeriod: "期末" // 记录当前成绩页面选中的期中/期末 | ||
}, | ||
/** | ||
* 拆入已读成绩 | ||
* 提取成标记存入数组 | ||
* @param state | ||
* @param value 成绩 | ||
*/ | ||
const insertReadScore = (value: Score) => { | ||
readScoreMarks.value.push({ | ||
name: value.lessonID, | ||
scorePoint: value.scorePoint, | ||
val: true | ||
}); | ||
}; | ||
/** | ||
* 发现新出成绩之后的操作 | ||
* - 标记时间 | ||
* @param state | ||
*/ | ||
const findNewScore = () => { | ||
findNewScoresTime.value = new Date(); | ||
}; | ||
|
||
mutations: { | ||
|
||
/** | ||
* 拆入已读成绩 | ||
* 提取成标记存入数组 | ||
* @param state | ||
* @param value 成绩 | ||
*/ | ||
insertReadScore( | ||
state: ScoreServiceStoreType, | ||
value: Score | ||
) { | ||
state.readScoreMarks.push({ | ||
name: value.lessonID, | ||
scorePoint: value.scorePoint, | ||
val: true | ||
}); | ||
}, | ||
|
||
/** | ||
* 发现新出成绩之后的操作 | ||
* - 标记时间 | ||
* @param state | ||
*/ | ||
findNewScore(state: ScoreServiceStoreType) { | ||
state.findNewScoresTime = new Date(); | ||
}, | ||
|
||
/** | ||
* 更新当前选中的成绩时期(期中/期末) | ||
* @param state | ||
* @param value 更新的period | ||
*/ | ||
changeScorePeriod( | ||
state: ScoreServiceStoreType, | ||
value: "期中" | "期末" | ||
) { | ||
state.scorePeriod = value; | ||
} | ||
|
||
} | ||
}; | ||
/** | ||
* 更新当前选中的成绩时期(期中/期末) | ||
* @param state | ||
* @param value 更新的period | ||
*/ | ||
const changeScorePeriod = (value: "期中" | "期末") => { | ||
scorePeriod.value = value; | ||
}; | ||
return { | ||
readScoreMarks, | ||
findNewScoresTime, | ||
scorePeriod, | ||
insertReadScore, | ||
findNewScore, | ||
changeScorePeriod | ||
}; | ||
}); |
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