From ef37c59e055a990ce247b265b27d3fcef430a243 Mon Sep 17 00:00:00 2001 From: 杨磊 <505174330@qq.com> Date: 星期五, 15 八月 2025 10:19:18 +0800 Subject: [PATCH] first submit --- src/store/index.js | 123 +++++++++++++++++++++++++++++++++++++++++ 1 files changed, 123 insertions(+), 0 deletions(-) diff --git a/src/store/index.js b/src/store/index.js new file mode 100644 index 0000000..06a2414 --- /dev/null +++ b/src/store/index.js @@ -0,0 +1,123 @@ +import Vue from "vue"; +import Vuex from "vuex"; +import tool from "@/assets/js/toolClass"; +import { tokenKey, userInfoKey } from "@/assets/js/config"; + +Vue.use(Vuex); + +export default new Vuex.Store({ + state: { + token: tool.getCookie(tokenKey), + userInfo: tool.getCookie(userInfoKey) + ? JSON.parse(tool.getCookie(userInfoKey)) + : null, + //涔﹀煄娴忚鍘嗗彶 + historyBook: [], + //鐢靛瓙鏍蜂功鍒楄〃 + electronicBookList: [], + //绾歌川鏍蜂功鐢宠鍒楄〃 + paperCopiesList: [], + keepAliveList: [], + }, + getters: {}, + mutations: { + changeLogin(state, val) { + if (val) { + state.token = val; + tool.setCookie(tokenKey, val); + } else { + state.token = null; + tool.delCookie(tokenKey); + } + }, + + changeUserInfo(state, val) { + if (val) { + // 榛樿澶村儚 + // if (!val.icon) + // val.icon = require("@/assets/images/common/pageHeader/userIcon.png"); + state.userInfo = JSON.parse(JSON.stringify(val)); + tool.setCookie(userInfoKey, JSON.stringify(val)); + } else { + state.userInfo = null; + tool.delCookie(userInfoKey); + } + }, + //璁剧疆娴忚璁板綍 + setHistoryBook(state, val) { + let currentIndex = ""; + if (state.historyBook.length > 0) { + var res = state.historyBook.some((item, index) => { + if (item.id == val.id) { + currentIndex = index; + return true; + } + }); + if (!res) { + state.historyBook.unshift(val); + } else { + state.historyBook.splice(currentIndex, 1); + state.historyBook.unshift(val); + } + } else { + state.historyBook.unshift(val); + } + }, + //鍒犻櫎娴忚璁板綍 + deleteHistoryBook(state, val) { + state.historyBook.splice(val, 1); + }, + //澧炲姞鐢靛瓙鏍蜂功 + addEbookList(state, val) { + state.electronicBookList.push(val); + }, + //澧炲姞绾歌川鏍蜂功 + addPbookList(state, val) { + state.paperCopiesList.push(val); + }, + //鍒犻櫎鐢靛瓙鏍蜂功 + deleteEbookList(state, val) { + if (val == "all") { + state.electronicBookList = []; + } else { + state.electronicBookList.splice(val, 1); + } + }, + //鍒犻櫎绾歌川鏍蜂功 + deletePbookList(state, val) { + if (val == "all") { + state.paperCopiesList = []; + } else { + state.paperCopiesList.splice(val, 1); + } + }, + emptyBookList(state, val) { + state.electronicBookList = []; + state.paperCopiesList = []; + }, + deleteAllHistory(state) { + state.historyBook = []; + }, + addKeepAlive(state, val) { + state.keepAliveList.push(val); + console.log("state", state.keepAliveList); + }, + delKeepAlive(state, val) { + if (state.keepAliveList.findIndex((item) => item == val) != -1) { + state.keepAliveList.splice( + state.keepAliveList.findIndex((item) => item == val), + 1 + ); + } + }, + }, + actions: { + setUserInfo(context, val) { + context.commit("changeUserInfo", val); + }, + setToken(context, val) { + context.commit("changeLogin", val); + }, + }, + modules: {}, +}); -- Gitblit v1.9.1