setting.js 821 Bytes
Newer Older
jim's avatar
jim committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
export default {
  namespace: 'setting',

  state: {
    collapse: false,
    silderTheme: 'dark',
    themeColor: '#1890FF',
    layout: 'sidemenu',
    grid: 'Fluid',
    fixedHeader: false,
    autoHideHeader: false,
    fixSiderbar: false,
    colorWeak: 'close',
  },
  reducers: {
    changeSetting(state, { payload }) {
      const urlParams = new URL(window.location.href);
      let urlParamsString = '';
      Object.keys(payload).forEach((key) => {
        if (payload[key] && state[key] !== undefined && key !== 'collapse') {
          urlParamsString += `${key}:${payload[key]};`;
        }
      });
      urlParams.searchParams.set('setting', urlParamsString);
      window.history.replaceState(null, 'setting', urlParams.href);
      return {
        ...state,
        ...payload,
      };
    },
  },
};