import { defineStore } from 'pinia' import { store } from '@/store' import { getFilter } from '@/api/home/filter' import { getConfig } from '@/api/system/user' import { asideMap } from "@/config/final"; import { cloneDeep, isEqual } from "lodash-es"; import type { AsideConfig } from '/#/api' export interface ConfigState { systemConfig: AsideConfig | null customConfig: string[] | null asideValue: any listKey: number searchValue: string isAllowDownload: boolean timeNum: number filterConfig: string[] // 过滤筛选条件 } export const useFinalStore = defineStore({ id: 'app-final', state: (): ConfigState => ({ systemConfig: null, customConfig: null, asideValue: null, listKey: 0, searchValue: "", isAllowDownload: true, timeNum: 0, filterConfig: [], }), getters: { getSystemConfig(): AsideConfig | null { return this.systemConfig }, getCustomConfig(): string[] | null { return this.customConfig }, getAsideValue(): any { return this.asideValue }, getSearchValue(): any { return this.searchValue }, getIsAllowDownload(): any { return this.isAllowDownload }, getTimeNum(): any { return this.timeNum }, getFilterConfig(): any { return this.filterConfig }, }, actions: { setSystemConfig(config: AsideConfig) { this.systemConfig = config console.log("systemConfig----------", config); }, setAsideValue(value) { this.asideValue = value }, setListKey() { this.listKey = new Date().getTime() }, setSearchValue(value) { this.searchValue = value }, setIsAllowDownload(value) { this.isAllowDownload = value }, setTimeNum(value) { this.timeNum = value }, // 设置个性化配置 setCustomConfig(value) { this.customConfig = value }, setFilterConfig(value) { this.filterConfig = value }, // 获取系统配置信息 async fetchConfig() { // const response = await getConfig() // console.log("response.data----------", response.data); // this.setSystemConfig(response.data) // return response.data let list: any = {}; let tempAsideMap = cloneDeep(asideMap); Object.keys(tempAsideMap).map(key => { list[key] = "Y"; }); console.log("setSystemConfig---------------", list); this.setSystemConfig(list); return list }, // // 获取终审个性化配置 async fetchCustomConfig() { const res = await getFilter(1) const { data } = res const list = data && data.searchcount ? data.searchcount.split(',') : []; console.log("listkey---------------", list); this.customConfig = list return list }, }, }) // Need to be used outside the setup export function useFinal() { return useFinalStore(store) }