user.js 1.25 KB
export const state = {
	//用户数据
	userInfo: {},
	//存储告警徽标数据
	badgeInfo: 0
};
export const mutations = {
	//储存用户信息
	setUserInfo(state, data) {
		if (data) {
			state.userInfo = Object.assign({}, state.userInfo, data);
			// #ifdef H5
			window.sessionStorage.setItem('userInfo', JSON.stringify(state.userInfo));
			// #endif
			// #ifndef H5
			uni.setStorageSync('userInfo', state.userInfo);
			// #endif
		}
	},
	// 退出APP
	emptyUserInfo(state) {
		state.userInfo = {};
		// #ifdef H5
		window.sessionStorage.removeItem("userInfo");
		// #endif
		// #ifndef H5
		uni.removeStorageSync("userInfo");
		// #endif
	},
};
export const actions = {
	//更新告警徽标数
	updateBadgeTotal({
		state,
		commit
	}, data) {
		let httpData = {
			page: 1,
			pageSize: 10,
			status: data.status == 'CLEARED_ACK' ? null : data.status,
			startTime: data.startTime,
			endTime: data.endTime,
			severity: data.severity,
			deviceType: data.deviceType,
			organizationId: data.organizationId,
			alarmType: data.alarmType
		};
		uni.$u.http
			.get('/yt/alarm', {
				params: httpData,
				custom: {
					load: false
				}
			})
			.then(res => {
				state.badgeInfo = res.total
			})
			.catch(e => {
				uni.$u.toast(e.data?.message);
			});
	}
};