refactor: Notice 的Mobx store 迁移到 zustand; 仅保留管理未读数量
parent
bff8a1ea78
commit
c06df03754
@ -1,51 +0,0 @@
|
||||
import { create } from 'zustand';
|
||||
import { devtools } from 'zustand/middleware';
|
||||
|
||||
import { fetchJSON, postForm, } from '@/utils/request';
|
||||
import { HT_HOST } from '@/config';
|
||||
|
||||
/**
|
||||
* Notice 相关的请求
|
||||
*/
|
||||
|
||||
export const fetchBulletinList = async (LMI_SN) => {
|
||||
const { errcode, Result } = await fetchJSON(`${HT_HOST}/service-Cooperate/Cooperate/GetBulletinList`, { LMI_SN });
|
||||
return errcode !== 0 ? [] : Result;
|
||||
};
|
||||
|
||||
export const fetchBulletinUnReadCount = async (LMI_SN) => {
|
||||
const { errcode, Result } = await fetchJSON(`${HT_HOST}/service-Cooperate/Cooperate/GetBulletinUnReadCount`, { LMI_SN });
|
||||
return errcode !== 0 ? 0 : Result.CCP_BulletinCount;
|
||||
}
|
||||
|
||||
export const fetchNoticeDetail = async (LMI_SN, CCP_BLID) => {
|
||||
const { errcode, Result } = await fetchJSON(`${HT_HOST}/service-Cooperate/Cooperate/GetBulletinDetail`, { LMI_SN, CCP_BLID });
|
||||
return errcode !== 0 ? {} : Result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notice Store
|
||||
*/
|
||||
const initialState = {
|
||||
noticeUnRead: 0, //未读公告数量
|
||||
};
|
||||
export const useNoticeStore = create(
|
||||
devtools((set, get) => ({
|
||||
// 初始化状态
|
||||
...initialState,
|
||||
|
||||
// state actions
|
||||
setNoticeUnRead: (noticeUnRead) => set(() => ({ noticeUnRead })),
|
||||
|
||||
reset: () => set(initialState),
|
||||
|
||||
// side effects
|
||||
getBulletinUnReadCount: async (LMI_SN) => {
|
||||
const { setNoticeUnRead } = get();
|
||||
const noticeUnRead = await fetchBulletinUnReadCount(LMI_SN);
|
||||
setNoticeUnRead(noticeUnRead);
|
||||
},
|
||||
|
||||
}))
|
||||
);
|
||||
export default useNoticeStore;
|
Loading…
Reference in New Issue