/* * @Author: fxs bjnsfxs@163.com * @Date: 2024-08-28 11:46:10 * @LastEditors: fxs bjnsfxs@163.com * @LastEditTime: 2024-10-12 17:07:58 * @FilePath: \Game-Backstage-Management-System\src\stores\useCommon.ts * @Description:通用的store,在多个页面均会使用 * */ import { reactive } from 'vue' import { defineStore } from 'pinia' import { getLocalInfo, saveLocalInfo } from '@/utils/localStorage/localStorage' interface SelectInfo { gid: string pf: Array } interface GameInfo { gid: string gameName: string } export const useCommonStore = defineStore('commonStore', () => { // 这里是是为了去初始化selectInfo,当用户第一次进入网站的时候,是没有selectInfo的,所以需要初始化 let gid = getLocalInfo('selectInfo', 'gid') gid = gid ? gid : '1001' let pf = getLocalInfo('selectInfo', 'pf') if (pf.length > 1) { pf = [pf[0]] } pf = pf ? pf : ['wx'] const selectInfo = reactive({ gid: gid as string, pf: pf as string[] }) saveLocalInfo('selectInfo', selectInfo) // 同上 let tempPf = getLocalInfo('tempMultipleChioce', 'pf') tempPf = tempPf ? tempPf : [selectInfo.pf[0]] // 临时使用的多选pf,为了不与selectInfo冲突 // pf初始化的时候更seleinfo的一致,但是后续的修改不会影响selectInfo const tempMultipleChioce = reactive({ gid: gid as string, pf: tempPf as string[] }) saveLocalInfo('tempMultipleChioce', tempMultipleChioce) /** * @description: 保存现有的selectInfo * @return {*} */ const saveSelectInfo = () => { localStorage.setItem('selectInfo', JSON.stringify(selectInfo)) } /** * @description: 保存现有的tempMultipleChioce * @return {*} */ const saveTempMultipleChioce = () => { localStorage.setItem('tempMultipleChioce', JSON.stringify(tempMultipleChioce)) } const allGameInfo = reactive>([]) return { selectInfo, allGameInfo, tempMultipleChioce, saveSelectInfo, saveTempMultipleChioce } })