// store.js

import Vue from 'vue';
import Vuex from 'vuex';
import user from './modules/user';
import notifyService from "@/api/notify/notifyService";
import userService from "@/api/sys/userService";

Vue.use(Vuex);

// store.js
export default new Vuex.Store({
	modules: {
		user
	},
	state: {
		userInfo: null, // 新增：存储用户信息
		messageDataList: [],
		triggerShowOpen: false // 新增状态
	},
	mutations: {
		setMessageDataList(state, dataList) {
			state.messageDataList = dataList;
		},
		setTriggerShowOpen(state, value) {
			state.triggerShowOpen = value;
		},
		setUserInfo(state, userInfo) {
			state.userInfo = userInfo;  // 新增：用于存储用户信息
		}
	},
	actions: {
		async loadmore({ commit }) {
			const data = await notifyService.getUnreadCountByIsSelf({
				isSelf: true
			});
			return data;
		},
		triggerShowOpen({ commit }) {
			commit('setTriggerShowOpen', true); // 触发状态改变
		},
		resetTriggerShowOpen({ commit }) {
			commit('setTriggerShowOpen', false); // 重置状态
		},
		async fetchUserInfo({ commit }) {
			try {
				const userInfo = await userService.info();  // 调用你的 API 获取用户信息
				commit('setUserInfo', userInfo);  // 提交 mutation 保存用户信息
			} catch (error) {
				console.error('获取用户信息失败:', error);
			}
		}
	},
});

