actions.js 4.38 KB
Newer Older
1
import Cookies from 'js-cookie';
2
import { store } from '@wisdom-utils/utils';
dengxiaofeng's avatar
dengxiaofeng committed
3
import {
邓晓峰's avatar
邓晓峰 committed
4
  CLEAR_RCENT_KEYWORD,
邓晓峰's avatar
邓晓峰 committed
5 6
  COMPLEX_CONFIG,
  COMPLEX_PATHNAME,
邓晓峰's avatar
邓晓峰 committed
7
  CREATE_CONEXT,
邓晓峰's avatar
邓晓峰 committed
8
  EXTEND_OPEN_KEY,
邓晓峰's avatar
邓晓峰 committed
9
  GENERATE_MENU,
dengxiaofeng's avatar
dengxiaofeng committed
10
  GET_CONFIG,
邓晓峰's avatar
邓晓峰 committed
11
  GET_CURRENT_INDEX,
邓晓峰's avatar
邓晓峰 committed
12
  GET_CURRENT_ROUTES,
dengxiaofeng's avatar
dengxiaofeng committed
13
  GET_ERROR_CONFIG,
14
  GET_MICRO_MOUNTED_STATUS,
邓晓峰's avatar
邓晓峰 committed
15
  GET_PATHNAME,
邓晓峰's avatar
邓晓峰 committed
16 17 18
  GET_RCENT_KEYWORD,
  GET_RECENT_PRODUCT,
  GET_RECENT_VISITED,
邓晓峰's avatar
邓晓峰 committed
19
  GET_THEME_CONFIG,
邓晓峰's avatar
邓晓峰 committed
20
  LOGIN_MODE,
21
  LOGINOUT,
邓晓峰's avatar
邓晓峰 committed
22
  SELECT_MENU_KEY,
邓晓峰's avatar
邓晓峰 committed
23
  SLIDER_MENU_MODE,
邓晓峰's avatar
邓晓峰 committed
24
  VALIDATE_AUTH,
25
  MAP_VIEW,
lihonglin's avatar
lihonglin committed
26
  AMAP_VIEW,
邓晓峰's avatar
邓晓峰 committed
27
  PD_VIEW,
dengxiaofeng's avatar
dengxiaofeng committed
28 29 30 31
} from './constants';
export function getConfig(data) {
  return {
    type: GET_CONFIG,
邓晓峰's avatar
邓晓峰 committed
32
    data,
dengxiaofeng's avatar
dengxiaofeng committed
33 34 35 36 37 38 39 40 41
  };
}

export function getConfigError(error) {
  return {
    type: GET_ERROR_CONFIG,
    error,
  };
}
邓晓峰's avatar
邓晓峰 committed
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61

export function getCurrentRoute(data) {
  return {
    type: GET_CURRENT_ROUTES,
    data,
  };
}
export function createContext(data) {
  return {
    type: CREATE_CONEXT,
    data,
  };
}

export function generateMenu(data) {
  return {
    type: GENERATE_MENU,
    data,
  };
}
邓晓峰's avatar
邓晓峰 committed
62 63 64 65 66 67 68

export function updageSetting(data) {
  return {
    type: GET_THEME_CONFIG,
    data,
  };
}
邓晓峰's avatar
邓晓峰 committed
69 70 71 72

export function updateRecentKeywords(data) {
  return {
    type: GET_RCENT_KEYWORD,
邓晓峰's avatar
邓晓峰 committed
73 74
    data,
  };
邓晓峰's avatar
邓晓峰 committed
75 76 77 78 79
}

export function updateRecentVisited(data) {
  return {
    type: GET_RECENT_VISITED,
邓晓峰's avatar
邓晓峰 committed
80 81
    data,
  };
邓晓峰's avatar
邓晓峰 committed
82 83 84 85 86
}

export function updateCurrentIndex(data) {
  return {
    type: GET_CURRENT_INDEX,
邓晓峰's avatar
邓晓峰 committed
87 88
    data,
  };
邓晓峰's avatar
邓晓峰 committed
89 90 91 92 93
}

export function updateRecentProduct(data) {
  return {
    type: GET_RECENT_PRODUCT,
邓晓峰's avatar
邓晓峰 committed
94 95
    data,
  };
邓晓峰's avatar
邓晓峰 committed
96 97 98 99
}

export function clearRecentProduct() {
  return {
邓晓峰's avatar
邓晓峰 committed
100 101
    type: CLEAR_RCENT_KEYWORD,
  };
邓晓峰's avatar
邓晓峰 committed
102 103 104 105 106
}

export function updateCollapsed(data) {
  return {
    type: SLIDER_MENU_MODE,
邓晓峰's avatar
邓晓峰 committed
107 108
    data,
  };
邓晓峰's avatar
邓晓峰 committed
109 110 111 112 113
}

export function changeLoginMode(data) {
  return {
    type: LOGIN_MODE,
邓晓峰's avatar
邓晓峰 committed
114 115
    data,
  };
邓晓峰's avatar
邓晓峰 committed
116 117 118 119 120
}

export function updateAuthValidate(data) {
  return {
    type: VALIDATE_AUTH,
邓晓峰's avatar
邓晓峰 committed
121 122
    data,
  };
邓晓峰's avatar
邓晓峰 committed
123 124 125 126 127
}

export function updatePathname(data) {
  return {
    type: GET_PATHNAME,
邓晓峰's avatar
邓晓峰 committed
128 129
    data,
  };
邓晓峰's avatar
邓晓峰 committed
130 131 132 133 134
}

export function updateSelectedKeys(data) {
  return {
    type: SELECT_MENU_KEY,
邓晓峰's avatar
邓晓峰 committed
135 136
    data,
  };
邓晓峰's avatar
邓晓峰 committed
137 138 139 140 141
}

export function updateOpenKeys(data) {
  return {
    type: EXTEND_OPEN_KEY,
邓晓峰's avatar
邓晓峰 committed
142 143
    data,
  };
邓晓峰's avatar
邓晓峰 committed
144 145 146 147 148
}

export function updateComplexConfig(data) {
  return {
    type: COMPLEX_CONFIG,
邓晓峰's avatar
邓晓峰 committed
149 150
    data,
  };
邓晓峰's avatar
邓晓峰 committed
151 152 153 154 155
}

export function updateComplexPathName(data) {
  return {
    type: COMPLEX_PATHNAME,
邓晓峰's avatar
邓晓峰 committed
156 157 158
    data,
  };
}
159 160 161 162 163 164 165

export function updateMicroMounted(data) {
  return {
    type: GET_MICRO_MOUNTED_STATUS,
    data,
  };
}
166

lihonglin's avatar
lihonglin committed
167 168 169 170 171 172 173
export function updageAMapView(data) {
  return {
    type: AMAP_VIEW,
    data,
  };
}

174 175 176 177 178 179 180
export function updageMapView(data) {
  return {
    type: MAP_VIEW,
    data,
  };
}

邓晓峰's avatar
邓晓峰 committed
181 182 183 184 185 186 187
export function updatePdCesiumView(data) {
  return {
    type: PD_VIEW,
    data,
  };
}

188
export function logout(data) {
邓晓峰's avatar
邓晓峰 committed
189
  // eslint-disable-next-line no-undef
190
  createStoreage.remove('PANDA_STORE');
邓晓峰's avatar
邓晓峰 committed
191 192 193 194
  if (window.globalConfig) {
    Cookies.set(window.globalConfig.client, '', {
      path: '/',
    });
邓晓峰's avatar
邓晓峰 committed
195
    window.globalConfig.token = null;
邓晓峰's avatar
邓晓峰 committed
196
    window.globalConfig.access_token = null;
邓晓峰's avatar
邓晓峰 committed
197
    window.globalConfig.apiGatewayDomain = window.location.origin;
邓晓峰's avatar
邓晓峰 committed
198
    window.globalConfig.baseURI = window.location.origin;
邓晓峰's avatar
邓晓峰 committed
199 200
    window.globalConfig.hasGateWay = false;
    window.globalConfig.userInfo = null;
201
    // window.globalConfig.hasGateWay = ;
邓晓峰's avatar
邓晓峰 committed
202
  }
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218

  Cookies.set('token', '', {
    path: '/',
  });

  Cookies.set('loginMode', '', {
    path: '/',
  });

  Cookies.set('redirect_state', '', {
    path: '/',
  });
  Cookies.set('site', '', {
    path: '/',
  });
  localStorage.removeItem('access_token');
邓晓峰's avatar
邓晓峰 committed
219
  // eslint-disable-next-line no-undef,no-restricted-globals
220
  createStoreage.remove(`__PANDA_STORE__${location.hostname}`);
邓晓峰's avatar
邓晓峰 committed
221
  // eslint-disable-next-line no-undef,no-restricted-globals
邓晓峰's avatar
邓晓峰 committed
222 223
  createStoreage.remove(`__PANDA_STORE__MICRO_${location.hostname}`);
  localStorage.removeItem('JmReport-Access-Token');
224

225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240
  const products =
    window.globalConfig &&
    (window.globalConfig.products || []).map(item => {
      if (item.PackageName === 'civweb4') {
        return 'web4_console';
      }
      return `${item.PackageName}-main`;
    });
  if (products) {
    Object.keys(products).forEach(item => {
      window[products[item]] &&
      window[products[item]] &&
      window[products[item]].unmount &&
      window[products[item]].unmount({ store });
    });
  }
241

242 243 244 245
  return {
    type: LOGINOUT,
    data: {
      currentMenuIndex: 0,
邓晓峰's avatar
邓晓峰 committed
246
      complexConfig: {},
邓晓峰's avatar
邓晓峰 committed
247
      globalConfig: window.globalConfig,
邓晓峰's avatar
邓晓峰 committed
248 249 250
    },
  };
}