| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- import Vue from 'vue'
- import Vuex from 'vuex'
- import { Notification } from 'element-ui'
- import public_data from './data' // 公共数据
- import config_data from './config-data' // 配置数据
- Vue.use(Vuex)
- const store = new Vuex.Store({
- state: {
- user_name: '' || localStorage.getItem('user_name'),
- admin: localStorage.getItem('admin') || false,
- token: '' || localStorage.getItem('token'),
- name: '' || localStorage.getItem('name'),
- backend_type: localStorage.getItem('backend_type') || '1', // 1:站机端、2:中心端
- defaultActive: localStorage.getItem('defaultActive') || '/layout/real_time_monitoring',
- del_user: ['user_name', 'admin', 'token', 'name', 'backend_type', 'defaultActive'],
- notification_list: [], // 存放消息提示,长度超过 3 则删除第一个
- },
- mutations: {
- // 将用户信息存在 localStorage 中
- handle_save_user(state, user) {
- Object.keys(user).forEach(key => {
- state[key] = user[key]
- localStorage.setItem(`${key}`, user[key])
- })
- },
- // 保存获取目前所在位置
- handle_save_defaultActive(state, defaultActive) {
- state.defaultActive = defaultActive
- localStorage.setItem('defaultActive', defaultActive)
- },
- // 保存后台类型
- handle_save_backend_type(state, backend_type) {
- state.backend_type = backend_type
- localStorage.setItem('backend_type', backend_type)
- },
- // 新预警提示
- handle_new_alarm(state, message) {
- // 当弹出的预警超过三条时,先删除数组第一个元素,然后消息提示,最后把最新一条报警添加进去
- if (state.notification_list.length == 3) {
- state.notification_list[0].close()
- state.notification_list.shift()
- }
- let new_alarm = Notification({
- type: 'warning',
- showClose: true,
- title: '告警消息',
- dangerouslyUseHTMLString: true,
- message: message,
- position: 'bottom-right',
- duration: 30000,
- })
- state.notification_list.push(new_alarm)
- },
- },
- // 引入公共数据
- modules: {
- public_data,
- config_data,
- },
- })
- export default store
|