diff --git a/package.json b/package.json index 96e7272d..736f5513 100644 --- a/package.json +++ b/package.json @@ -57,6 +57,7 @@ "lodash": "^4.17.21", "moment": "^2.29.4", "omit.js": "^2.0.2", + "query-string": "^8.1.0", "querystring": "^0.2.1", "rc-menu": "^9.9.2", "rc-util": "^5.32.2", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 37c4e3bb..18823e53 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -34,6 +34,9 @@ dependencies: omit.js: specifier: ^2.0.2 version: 2.0.2 + query-string: + specifier: ^8.1.0 + version: registry.npmmirror.com/query-string@8.1.0 querystring: specifier: ^0.2.1 version: 0.2.1 @@ -4521,7 +4524,7 @@ packages: resolution: {integrity: sha512-/e0cEGrR2bIWQD7pRl3dl9dcyRGeC9hoW0OCvUTT/hjY0EfUrkd6G8ZanVghPMpDuY5usxq9GVcvrT8KNXLWvA==} dependencies: '@babel/runtime': registry.npmmirror.com/@babel/runtime@7.22.3 - query-string: 6.14.1 + query-string: registry.npmmirror.com/query-string@6.14.1 dev: true /@umijs/lint@4.0.69(eslint@8.35.0)(jest@29.5.0)(styled-components@5.3.11)(stylelint@14.8.2)(typescript@5.0.2): @@ -6635,11 +6638,6 @@ packages: resolution: {integrity: sha512-VBBaLc1MgL5XpzgIP7ny5Z6Nx3UrRkIViUkPUdtl9aya5amy3De1gsUUSB1g3+3sExYNjCAsAznmukyxCb1GRA==} dev: true - /decode-uri-component@0.2.2: - resolution: {integrity: sha512-FqUYQ+8o158GyGTrMFJms9qh3CqTKvAqgqsTnkLI8sKu0028orqBhxNMFkFen0zGyg6epACD32pjVk58ngIErQ==} - engines: {node: '>=0.10'} - dev: true - /dedent@0.7.0: resolution: {integrity: sha512-Q6fKUPqnAHAyhiUgFU7BUzLiv0kd8saH9al7tnu5Q/okj6dnupxyTgFIBjVzJATdfIAm9NAsvXNzjaKa+bxVyA==} dev: true @@ -8059,11 +8057,6 @@ packages: dependencies: to-regex-range: 5.0.1 - /filter-obj@1.1.0: - resolution: {integrity: sha512-8rXg1ZnX7xzy2NGDVkBVaAy+lSlPNwad13BtgSlLuxfIslyt5Vg64U7tFcCt4WS1R0hvtnQybT/IyCkGZ3DpXQ==} - engines: {node: '>=0.10.0'} - dev: true - /finalhandler@1.2.0: resolution: {integrity: sha512-5uXcUVftlQMFnWC9qu/svkWv3GTd2PfUhK/3PLkYNAe7FbqJMt3515HaxE6eRL74GdsriiwujiawdaB1BpEISg==} engines: {node: '>= 0.8'} @@ -12049,16 +12042,6 @@ packages: engines: {node: '>=0.6'} dev: true - /query-string@6.14.1: - resolution: {integrity: sha512-XDxAeVmpfu1/6IjyT/gXHOl+S0vQ9owggJ30hhWKdHAsNPOcasn5o9BW0eejZqL2e4vMjhAxoW3jVHcD6mbcYw==} - engines: {node: '>=6'} - dependencies: - decode-uri-component: 0.2.2 - filter-obj: 1.1.0 - split-on-first: 1.1.0 - strict-uri-encode: 2.0.0 - dev: true - /querystring-es3@0.2.1: resolution: {integrity: sha512-773xhDQnZBMFobEiztv8LIl70ch5MSF/jUQVlhwFyBILqq96anmoctVIYz+ZRp0qbCKATTn6ev02M3r7Ga5vqA==} engines: {node: '>=0.4.x'} @@ -14318,11 +14301,6 @@ packages: hasBin: true dev: true - /split-on-first@1.1.0: - resolution: {integrity: sha512-43ZssAJaMusuKWL8sKUBQXHWOpq8d6CfN/u1p4gUzfJkM05C8rxTmYrkIPTXapZpORA6LkkzcUulJ8FqA7Uudw==} - engines: {node: '>=6'} - dev: true - /split2@4.2.0: resolution: {integrity: sha512-UcjcJOWknrNkF6PLX83qcHM6KHgVKNkV62Y8a5uYDVv9ydGQVwAHMKqHdJje1VTWpljG0WYpCDhrCdAOYH4TWg==} engines: {node: '>= 10.x'} @@ -20135,6 +20113,13 @@ packages: engines: {node: '>=0.10'} dev: true + registry.npmmirror.com/decode-uri-component@0.4.1: + resolution: {integrity: sha512-+8VxcR21HhTy8nOt6jf20w0c9CADrw1O8d+VZ/YzzCt4bJ3uBjw+D1q2osAB8RnpwwaeYBxy0HyKQxD5JBMuuQ==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/decode-uri-component/-/decode-uri-component-0.4.1.tgz} + name: decode-uri-component + version: 0.4.1 + engines: {node: '>=14.16'} + dev: false + registry.npmmirror.com/deepmerge@4.3.1: resolution: {integrity: sha512-3sUqbMEc77XqpdNO7FRyRog+eW3ph+GYCbj+rK+uYyRMuwsVy0rMiVtPn+QJlKFvWP/1PYpapqYn0Me2knFn+A==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/deepmerge/-/deepmerge-4.3.1.tgz} name: deepmerge @@ -20947,6 +20932,13 @@ packages: engines: {node: '>=0.10.0'} dev: true + registry.npmmirror.com/filter-obj@5.1.0: + resolution: {integrity: sha512-qWeTREPoT7I0bifpPUXtxkZJ1XJzxWtfoWWkdVGqa+eCr3SHW/Ocp89o8vLvbUuQnadybJpjOKu4V+RwO6sGng==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/filter-obj/-/filter-obj-5.1.0.tgz} + name: filter-obj + version: 5.1.0 + engines: {node: '>=14.16'} + dev: false + registry.npmmirror.com/find-root@1.1.0: resolution: {integrity: sha512-NKfW6bec6GfKc0SGx1e07QZY9PE99u0Bft/0rzSD5k3sO/vwkVUpDUKVm5Gpp5Ue3YfShPFTX2070tDs5kB9Ng==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/find-root/-/find-root-1.1.0.tgz} name: find-root @@ -23993,9 +23985,20 @@ packages: decode-uri-component: registry.npmmirror.com/decode-uri-component@0.2.2 filter-obj: registry.npmmirror.com/filter-obj@1.1.0 split-on-first: registry.npmmirror.com/split-on-first@1.1.0 - strict-uri-encode: registry.npmmirror.com/strict-uri-encode@2.0.0 + strict-uri-encode: 2.0.0 dev: true + registry.npmmirror.com/query-string@8.1.0: + resolution: {integrity: sha512-BFQeWxJOZxZGix7y+SByG3F36dA0AbTy9o6pSmKFcFz7DAj0re9Frkty3saBn3nHo3D0oZJ/+rx3r8H8r8Jbpw==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/query-string/-/query-string-8.1.0.tgz} + name: query-string + version: 8.1.0 + engines: {node: '>=14.16'} + dependencies: + decode-uri-component: registry.npmmirror.com/decode-uri-component@0.4.1 + filter-obj: registry.npmmirror.com/filter-obj@5.1.0 + split-on-first: registry.npmmirror.com/split-on-first@3.0.0 + dev: false + registry.npmmirror.com/querystring-es3@0.2.1: resolution: {integrity: sha512-773xhDQnZBMFobEiztv8LIl70ch5MSF/jUQVlhwFyBILqq96anmoctVIYz+ZRp0qbCKATTn6ev02M3r7Ga5vqA==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/querystring-es3/-/querystring-es3-0.2.1.tgz} name: querystring-es3 @@ -24938,6 +24941,13 @@ packages: engines: {node: '>=6'} dev: true + registry.npmmirror.com/split-on-first@3.0.0: + resolution: {integrity: sha512-qxQJTx2ryR0Dw0ITYyekNQWpz6f8dGd7vffGNflQQ3Iqj9NJ6qiZ7ELpZsJ/QBhIVAiDfXdag3+Gp8RvWa62AA==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/split-on-first/-/split-on-first-3.0.0.tgz} + name: split-on-first + version: 3.0.0 + engines: {node: '>=12'} + dev: false + registry.npmmirror.com/split2@4.2.0: resolution: {integrity: sha512-UcjcJOWknrNkF6PLX83qcHM6KHgVKNkV62Y8a5uYDVv9ydGQVwAHMKqHdJje1VTWpljG0WYpCDhrCdAOYH4TWg==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/split2/-/split2-4.2.0.tgz} name: split2 @@ -25000,13 +25010,6 @@ packages: version: 1.0.1 dev: true - registry.npmmirror.com/strict-uri-encode@2.0.0: - resolution: {integrity: sha512-QwiXZgpRcKkhTj2Scnn++4PKtWsH0kpzZ62L2R6c/LUVYv7hVnZqcg2+sMuT6R7Jusu1vviK/MFsu6kNJfWlEQ==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/strict-uri-encode/-/strict-uri-encode-2.0.0.tgz} - name: strict-uri-encode - version: 2.0.0 - engines: {node: '>=4'} - dev: true - registry.npmmirror.com/string-width@4.2.3: resolution: {integrity: sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/string-width/-/string-width-4.2.3.tgz} name: string-width diff --git a/src/app.tsx b/src/app.tsx index cb7d8555..2f977cfc 100644 --- a/src/app.tsx +++ b/src/app.tsx @@ -1,6 +1,7 @@ -import { Footer, Question, SelectLang, AvatarDropdown, AvatarName } from '@/components'; +import { AvatarDropdown, AvatarName, Footer, Question, SelectLang } from '@/components'; import { currentUser as queryCurrentUser } from '@/services/system/login'; import { LinkOutlined } from '@ant-design/icons'; +import queryString from 'query-string'; import type { Settings as LayoutSettings } from '@ant-design/pro-components'; import { PageLoading, SettingDrawer } from '@ant-design/pro-components'; import type { RunTimeLayoutConfig } from '@umijs/max'; @@ -8,9 +9,23 @@ import { history, Link } from '@umijs/max'; import defaultSettings from '../config/defaultSettings'; import { errorConfig } from './requestErrorConfig'; import { App } from 'antd'; +import { isLoginPath, isSessionExpiredPath } from '@/utils/is'; +import { PageEnum } from '@/enums'; const isDev = process.env.NODE_ENV === 'development'; -const loginPath = '/login'; + +const goLogin = () => { + const query = queryString.parse(history.location.search); + const { redirect } = query as { redirect: string }; + history.replace({ + pathname: PageEnum.BASE_LOGIN, + search: + redirect && + queryString.stringify({ + redirect: redirect, + }), + }); +}; /** * @see https://umijs.org/zh-CN/plugins/plugin-initial-state @@ -27,27 +42,11 @@ export async function getInitialState(): Promise<{ // @ts-nocheck console.log('%c欢迎使用 WeCoding 统一身份认证中心', 'font-size: 24px;font-weight: bold'); const fetchUserInfo = async () => { - try { - return await queryCurrentUser({ - skipErrorHandler: true, - }); - } catch (error) { - history.push(loginPath); - } - return undefined; + return await queryCurrentUser().catch(() => undefined); }; - // 如果不是登录页面,执行 - const { location } = history; - if (location.pathname !== loginPath) { - const currentUser = await fetchUserInfo(); - return { - fetchUserInfo, - currentUser, - settings: defaultSettings as Partial, - }; - } return { fetchUserInfo, + currentUser: isLoginPath() ? undefined : await fetchUserInfo(), settings: defaultSettings as Partial, }; } @@ -68,10 +67,17 @@ export const layout: RunTimeLayoutConfig = ({ initialState, setInitialState }) = }, footerRender: () =>