import { getNoticeApi } from "@/api"; export default { namespaced: true, state() { return { isOPen: false, data: { id: "", tipEndTime: "", tipStartTime: "", imageUrl: "", imageUrlEn: "", title: "", titleEn: "", description: "", descriptionEn: "", infoUrl: "", infoUrlEn: "", version: "", }, }; }, getters: { content: (state) => state.data, status: (state) => state.isOPen, }, mutations: { setData(state, payload) { state.data = payload; }, setStatus(state, payload) { state.isOPen = payload; }, }, actions: { async getNotice({ commit, state }) { const data = await getNoticeApi(); console.log("state", state); const preState = state.data; data.data && Object.keys(data.data).forEach((i) => { if (i in preState) { preState[i] = data.data[i]; } }); if (preState.tipStartTime && preState.tipEndTime) { const start = new Date(preState.tipStartTime); const end = new Date(preState.tipEndTime); const date = Date.now(); const noticeIds = localStorage.getItem("noticeIds") ? Array.isArray(JSON.parse(localStorage.getItem("noticeIds"))) ? JSON.parse(localStorage.getItem("noticeIds")) : [] : []; if (date > start && date < end) { if (!Array.from(noticeIds).includes(preState.id)) { noticeIds.push(preState.id); localStorage.setItem("noticeIds", JSON.stringify(noticeIds)); commit("setStatus", true); } } else { commit("setStatus", false); } } console.log("preState", preState); commit("setData", preState); }, }, };