/*
 *系统个人爱好配置信息--localStorage 存储
*/
const sysLocalStorage = {
  state: {
    // 系统个人爱好配置信息
    sysLocal: {
      pageNo: 1, // 页码
      pageSize: 10, // 分页条数
      tabData: {}, // tab当前选中信息
      queryParams: {} // 查询条件
    },
    userUploadProgress: 0 // 文件下载进度
  },
  mutations: {
    // 项目信息
    SET_SYSLOCAL: (state, sysLocal) => {
      const localName = sysLocal.localNameSaveCode // 查询code 名称
      let sysLocalData = {}
      // 取session存的值
      if (sessionStorage.getItem(localName)) {
        sysLocalData = JSON.parse(sessionStorage.getItem(localName))
      }
      const data = {
        ...sysLocalData,
        ...sysLocal
      }
      state.sysLocal = data
      sessionStorage.setItem(localName, JSON.stringify(data))// 存储localStorage
    },
    UPLOAD_USER_PROGRESS: (state, payload) => {
      state.userUploadProgress = payload
    }
  },
  actions: {
    // 系统配置信息
    setSysLocal({ commit }, sysLocal) {
      commit('SET_SYSLOCAL', sysLocal)
    },
    // 清楚系统配置信息
    clearSysLoca({ commit }) {
      return new Promise(resolve => {
        commit('SET_SYSLOCAL', {})
        resolve()
      })
    }
  }
}

export default sysLocalStorage

