actions.js 5.53 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,
28
  CONFIG_INTEGRATED,
29
  OPENED_MENUS,
dengxiaofeng's avatar
dengxiaofeng committed
30 31 32 33
} from './constants';
export function getConfig(data) {
  return {
    type: GET_CONFIG,
邓晓峰's avatar
邓晓峰 committed
34
    data,
dengxiaofeng's avatar
dengxiaofeng committed
35 36 37 38 39 40 41 42 43
  };
}

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

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
64 65 66 67 68 69 70

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

190 191 192 193 194 195 196
export function updateIntegratedConfig(data) {
  return {
    type: CONFIG_INTEGRATED,
    data,
  };
}

197 198 199 200 201 202 203
export function updateOpenedMenus(data) {
  return {
    type: OPENED_MENUS,
    data,
  };
}

204
export function logout(data) {
邓晓峰's avatar
邓晓峰 committed
205
  // eslint-disable-next-line no-undef
206
  createStoreage.remove('PANDA_STORE');
207
  const integrationClient = localStorage.getItem('integrationClient');
邓晓峰's avatar
邓晓峰 committed
208
  if (window.globalConfig) {
209
    Cookies.set(integrationClient || window.globalConfig.client, '', {
邓晓峰's avatar
邓晓峰 committed
210 211
      path: '/',
    });
邓晓峰's avatar
邓晓峰 committed
212
    window.globalConfig.token = null;
邓晓峰's avatar
邓晓峰 committed
213
    window.globalConfig.access_token = null;
邓晓峰's avatar
邓晓峰 committed
214
    window.globalConfig.apiGatewayDomain = window.location.origin;
邓晓峰's avatar
邓晓峰 committed
215
    window.globalConfig.baseURI = window.location.origin;
邓晓峰's avatar
邓晓峰 committed
216 217
    window.globalConfig.hasGateWay = false;
    window.globalConfig.userInfo = null;
218 219 220
    if (integrationClient) {
      window.globalConfig.client = integrationClient;
    }
杨思琦's avatar
杨思琦 committed
221
    window.qiankunIsCache = null;
杨思琦's avatar
杨思琦 committed
222
    window.qiankunStarted = false;
223
    // window.globalConfig.hasGateWay = ;
邓晓峰's avatar
邓晓峰 committed
224
  }
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239

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

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

  Cookies.set('redirect_state', '', {
    path: '/',
  });
  Cookies.set('site', '', {
    path: '/',
  });
240 241 242
  Cookies.set('singleToken', '', {
    path: '/',
  });
243 244 245 246 247
  // 如果有集成登录client,则 client 切换成集成登录
  if (integrationClient) {
    sessionStorage.setItem('client', integrationClient);
  }
  localStorage.removeItem('integrationClient');
248
  localStorage.removeItem('integrationData');
249
  localStorage.removeItem('integrationConfig');
250
  localStorage.removeItem('access_token');
251
  localStorage.removeItem('password_token');
杨思琦's avatar
杨思琦 committed
252 253
  localStorage.removeItem('password_pwdRegex');
  localStorage.removeItem('password_pwdRegexTip');
杨思琦's avatar
杨思琦 committed
254
  localStorage.removeItem('password_needChange');
邓晓峰's avatar
邓晓峰 committed
255
  // eslint-disable-next-line no-undef,no-restricted-globals
256
  createStoreage.remove(`__PANDA_STORE__${location.hostname}`);
邓晓峰's avatar
邓晓峰 committed
257
  // eslint-disable-next-line no-undef,no-restricted-globals
邓晓峰's avatar
邓晓峰 committed
258 259
  createStoreage.remove(`__PANDA_STORE__MICRO_${location.hostname}`);
  localStorage.removeItem('JmReport-Access-Token');
260

261 262 263 264 265 266 267 268 269 270 271
  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]] &&
272 273 274
        window[products[item]] &&
        window[products[item]].unmount &&
        window[products[item]].unmount({ store });
275 276
    });
  }
杨思琦's avatar
杨思琦 committed
277
  if (window.refreshCurrentToken) clearInterval(window.refreshCurrentToken);
杨思琦's avatar
杨思琦 committed
278
  store.set('event:dropCache');
杨思琦's avatar
杨思琦 committed
279
  window.location.reload();
280 281 282 283
  return {
    type: LOGINOUT,
    data: {
      currentMenuIndex: 0,
邓晓峰's avatar
邓晓峰 committed
284
      complexConfig: {},
邓晓峰's avatar
邓晓峰 committed
285
      globalConfig: window.globalConfig,
邓晓峰's avatar
邓晓峰 committed
286 287 288
    },
  };
}