12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- /*
- * @Author: fxs bjnsfxs@163.com
- * @Date: 2024-08-28 11:46:10
- * @LastEditors: fxs bjnsfxs@163.com
- * @LastEditTime: 2024-09-28 17:10:24
- * @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<string>
- }
- 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')
- pf = pf ? pf : ['wx']
- const selectInfo = reactive<SelectInfo>({
- 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<SelectInfo>({
- 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<Array<GameInfo>>([])
- return { selectInfo, allGameInfo, tempMultipleChioce, saveSelectInfo, saveTempMultipleChioce }
- })
|