* 初始化登录
()
| 300 | * 初始化登录 |
| 301 | */ |
| 302 | function initLogin() { |
| 303 | const userName = getCookie('username'); |
| 304 | const tenantName = getCookie('tenant_name') || 'Unknown'; |
| 305 | updateAccountContext( |
| 306 | userName |
| 307 | ? [ |
| 308 | { |
| 309 | id: 'username', |
| 310 | disabled: !!userName, |
| 311 | icon: 'person', |
| 312 | name: userName, |
| 313 | }, |
| 314 | { |
| 315 | id: 'divider', |
| 316 | type: 'divider', |
| 317 | }, |
| 318 | { |
| 319 | id: 'tenant-change', |
| 320 | icon: 'feedback', |
| 321 | name: tenantName, |
| 322 | onClick: () => showLoginModal(), |
| 323 | }, |
| 324 | { |
| 325 | id: ID_COLLECTIONS.ADD_TENANT, |
| 326 | name: '新增租户', |
| 327 | icon: 'person-add', |
| 328 | onClick: () => { |
| 329 | const node = document.createElement('div'); |
| 330 | node.id = 'add-tenant-modal'; |
| 331 | document.getElementById('molecule')!.appendChild(node); |
| 332 | const root = createRoot(node); |
| 333 | root.render(<AddTenantModal />); |
| 334 | }, |
| 335 | }, |
| 336 | { |
| 337 | id: 'logout', |
| 338 | icon: 'log-out', |
| 339 | name: '登出', |
| 340 | onClick: () => { |
| 341 | http.post('/taier/api/user/logout') |
| 342 | .then((res) => { |
| 343 | if (!res.data) { |
| 344 | return message.error('登出失败'); |
| 345 | } |
| 346 | // clear login infos in cookie |
| 347 | deleteCookie('userId'); |
| 348 | deleteCookie('username'); |
| 349 | deleteCookie('tenantId'); |
| 350 | deleteCookie('tenant_name'); |
| 351 | window.location.reload(); |
| 352 | }) |
| 353 | .catch(() => { |
| 354 | message.error('登出失败'); |
| 355 | }); |
| 356 | }, |
| 357 | }, |
| 358 | ] |
| 359 | : [ |
no test coverage detected