diff --git a/admin-views/pnpm-lock.yaml b/admin-views/pnpm-lock.yaml index 9ccb1e37..f1b6a62e 100644 --- a/admin-views/pnpm-lock.yaml +++ b/admin-views/pnpm-lock.yaml @@ -2019,7 +2019,7 @@ packages: '@rc-component/portal': 1.1.2(react-dom@17.0.2)(react@17.0.2) classnames: 2.3.2 rc-align: 4.0.15(react-dom@17.0.2)(react@17.0.2) - rc-motion: 2.8.0(react-dom@17.0.2)(react@17.0.2) + rc-motion: 2.9.0(react-dom@17.0.2)(react@17.0.2) rc-resize-observer: 1.3.1(react-dom@17.0.2)(react@17.0.2) rc-util: 5.37.0(react-dom@17.0.2)(react@17.0.2) react: 17.0.2 @@ -6101,7 +6101,7 @@ packages: react-dom: '>=16.9.0' dependencies: '@babel/runtime': 7.22.11 - classnames: 2.3.1 + classnames: 2.3.2 dom-align: 1.12.4 rc-util: 5.37.0(react-dom@17.0.2)(react@17.0.2) react: 17.0.2 @@ -6234,7 +6234,7 @@ packages: dependencies: '@babel/runtime': 7.22.11 '@rc-component/mini-decimal': 1.1.0 - classnames: 2.3.1 + classnames: 2.3.2 rc-util: 5.37.0(react-dom@17.0.2)(react@17.0.2) react: 17.0.2 react-dom: 17.0.2(react@17.0.2) @@ -6293,27 +6293,14 @@ packages: dependencies: '@babel/runtime': 7.22.11 '@rc-component/trigger': 1.15.6(react-dom@17.0.2)(react@17.0.2) - classnames: 2.3.1 - rc-motion: 2.8.0(react-dom@17.0.2)(react@17.0.2) + classnames: 2.3.2 + rc-motion: 2.9.0(react-dom@17.0.2)(react@17.0.2) rc-overflow: 1.3.2(react-dom@17.0.2)(react@17.0.2) rc-util: 5.37.0(react-dom@17.0.2)(react@17.0.2) react: 17.0.2 react-dom: 17.0.2(react@17.0.2) dev: false - /rc-motion@2.8.0(react-dom@17.0.2)(react@17.0.2): - resolution: {integrity: sha512-9gWWzlPvx/IJANj+t+ArqLCQ43rCWYLpOUe6+WJSAGb+b+fqBcfx81qPhg6b+ewa6g3mGNDhkTpBrVrCC4gcXA==} - peerDependencies: - react: '>=16.9.0' - react-dom: '>=16.9.0' - dependencies: - '@babel/runtime': 7.22.11 - classnames: 2.3.1 - rc-util: 5.37.0(react-dom@17.0.2)(react@17.0.2) - react: 17.0.2 - react-dom: 17.0.2(react@17.0.2) - dev: false - /rc-motion@2.9.0(react-dom@17.0.2)(react@17.0.2): resolution: {integrity: sha512-XIU2+xLkdIr1/h6ohPZXyPBMvOmuyFZQ/T0xnawz+Rh+gh4FINcnZmMT5UTIj6hgI0VLDjTaPeRd+smJeSPqiQ==} peerDependencies: @@ -6349,7 +6336,7 @@ packages: react-dom: '>=16.9.0' dependencies: '@babel/runtime': 7.22.11 - classnames: 2.3.1 + classnames: 2.3.2 rc-resize-observer: 1.3.1(react-dom@17.0.2)(react@17.0.2) rc-util: 5.37.0(react-dom@17.0.2)(react@17.0.2) react: 17.0.2 @@ -6405,7 +6392,7 @@ packages: react-dom: '>=16.9.0' dependencies: '@babel/runtime': 7.22.11 - classnames: 2.3.1 + classnames: 2.3.2 rc-util: 5.37.0(react-dom@17.0.2)(react@17.0.2) react: 17.0.2 react-dom: 17.0.2(react@17.0.2) @@ -6457,7 +6444,7 @@ packages: react-dom: '>=16.9.0' dependencies: '@babel/runtime': 7.22.11 - classnames: 2.3.1 + classnames: 2.3.2 rc-util: 5.37.0(react-dom@17.0.2)(react@17.0.2) react: 17.0.2 react-dom: 17.0.2(react@17.0.2) @@ -7985,7 +7972,7 @@ packages: react-dom: ^15.0.0 || ^16.0.0 || ^17.0.0 dependencies: '@babel/runtime': 7.22.11 - classnames: 2.3.1 + classnames: 2.3.2 lodash.throttle: 4.1.1 prop-types: 15.8.1 react: 17.0.2 diff --git a/admin-views/src/declaration.d.ts b/admin-views/src/declaration.d.ts deleted file mode 100644 index bafc9340..00000000 --- a/admin-views/src/declaration.d.ts +++ /dev/null @@ -1,35 +0,0 @@ -declare module "*.svg" { - const content: React.FunctionComponent> - export default content -} - -declare module "*.less" { - const classes: { [className: string]: string } - export default classes -} - -declare module "*/settings.json" { - const value: { - navbar: boolean; - menu: boolean; - footer: boolean; - themeColor: string; - menuWidth: number; - layoutMode: "default" | "top" | "left" | "double"; - theme: "light" | "dark"; - siderTheme: "light" | "dark"; - topTheme: "light" | "dark"; - } - - export default value -} - -declare module "*.png" { - const value: string - export default value -} - -interface Window { - $owl: any; - $adminApiPrefix: string; -} diff --git a/admin-views/src/hooks/userSettings.ts b/admin-views/src/hooks/useSetting.ts similarity index 87% rename from admin-views/src/hooks/userSettings.ts rename to admin-views/src/hooks/useSetting.ts index 6727e863..e852dc60 100644 --- a/admin-views/src/hooks/userSettings.ts +++ b/admin-views/src/hooks/useSetting.ts @@ -2,7 +2,7 @@ import {useSelector} from 'react-redux' import {GlobalState} from '@/store' import {arrayGet} from '@/utils/common' -const useSettings = () => { +const useSetting = () => { const settings:any = useSelector((state: GlobalState) => state.appSettings) const getSetting = (key = '', def = '') => { @@ -16,4 +16,4 @@ const useSettings = () => { } } -export default useSettings +export default useSetting diff --git a/admin-views/src/hooks/useSetup.ts b/admin-views/src/hooks/useSetup.ts index 447e3d39..288f0c86 100644 --- a/admin-views/src/hooks/useSetup.ts +++ b/admin-views/src/hooks/useSetup.ts @@ -1,7 +1,6 @@ import {useMount, useRequest} from 'ahooks' -import {fetchSettings, fetchUserInfo} from '@/service/api' -import {appLoaded} from '@/utils/common' -import {checkLogin} from '@/utils/checkLogin' +import {fetchLogout, fetchSettings, fetchUserInfo} from '@/service/api' +import {appLoaded, inLoginPage, registerGlobalFunction, Token} from '@/utils/common' import useStorage from '@/utils/useStorage' import zhCN from 'antd/locale/zh_CN' import enUS from 'antd/locale/en_US' @@ -65,6 +64,7 @@ const useSetup = (store) => { } }) + // 初始化用户信息 const initUserInfo = useRequest(fetchUserInfo, { manual: true, onSuccess(res) { @@ -75,6 +75,15 @@ const useSetup = (store) => { } }) + // 退出登录 + const logout = useRequest(fetchLogout, { + manual: true, + onFinally() { + Token().clear() + window.location.hash = '#/login' + } + }) + // 获取语言 const getAntdLocale = () => { switch (lang) { @@ -87,17 +96,26 @@ const useSetup = (store) => { } } + // 注册全局函数 + const registerFunctions = () => { + registerGlobalFunction('logout', () => logout.run()) + } + + // 初始化 const init = async () => { await initSettings.runAsync() + setThemeColor(store.getState().settings.themeColor) - if (checkLogin()) { + if (Token().value) { await initUserInfo.runAsync() - } else if (window.location.pathname.replace(/\//g, '') !== 'login') { + } else if (!inLoginPage()) { window.location.hash = '#/login' } + registerFunctions() registerCustomComponents() + appLoaded() } diff --git a/admin-views/src/layout/common/breadcrumb/index.tsx b/admin-views/src/layout/common/breadcrumb/index.tsx index 2d544c5d..9229a952 100644 --- a/admin-views/src/layout/common/breadcrumb/index.tsx +++ b/admin-views/src/layout/common/breadcrumb/index.tsx @@ -7,7 +7,7 @@ import useRoute from "@/routes" import {Icon} from "@iconify/react" export const Breadcrumb = () => { - const [routes] = useRoute() + const {routes} = useRoute() const history = useHistory() const pathname = history.location.pathname const {settings} = useSelector((state: GlobalState) => state) diff --git a/admin-views/src/layout/common/content/index.tsx b/admin-views/src/layout/common/content/index.tsx index 7399e8ce..0f8a15ac 100644 --- a/admin-views/src/layout/common/content/index.tsx +++ b/admin-views/src/layout/common/content/index.tsx @@ -17,7 +17,7 @@ const ArcoContent = Layout.Content export const Content = ({menuCollapsed, noPadding}: { menuCollapsed?: boolean, noPadding?: boolean }) => { const {settings, appSettings} = useSelector((state: GlobalState) => state) - const [routes, defaultRoute] = useRoute() + const {routes, defaultRoute} = useRoute() const navbarHeight = 60 const extraWidth = settings.layoutMode == 'double' ? 65 : 0 diff --git a/admin-views/src/layout/common/double-sider/index.tsx b/admin-views/src/layout/common/double-sider/index.tsx index 21c114b9..58b994d9 100644 --- a/admin-views/src/layout/common/double-sider/index.tsx +++ b/admin-views/src/layout/common/double-sider/index.tsx @@ -24,7 +24,7 @@ export const DoubleSider = ({stateChange}) => { const {settings, appSettings} = useSelector((state: GlobalState) => state) const [collapsed, setCollapsed] = useState(false) const routeMap = useRef>(new Map()) - const [routes, defaultRoute] = useRoute() + const {routes, defaultRoute} = useRoute() const leftMenus = routes.filter((route) => !route.meta.hide) const defaultSelectedKeys = [currentComponent || defaultRoute] diff --git a/admin-views/src/layout/common/menu/index.tsx b/admin-views/src/layout/common/menu/index.tsx index 5c780d22..38c1d9b4 100644 --- a/admin-views/src/layout/common/menu/index.tsx +++ b/admin-views/src/layout/common/menu/index.tsx @@ -25,7 +25,7 @@ const Menu = ( const pathname = history.location.pathname const currentComponent = qs.parseUrl(pathname).url.slice(1) - const [routes, defaultRoute] = useRoute() + const {routes, defaultRoute} = useRoute() const defaultSelectedKeys = [currentComponent || defaultRoute] const paths = (currentComponent || defaultRoute)?.split('/') const defaultOpenKeys = paths?.slice(0, paths.length - 1) diff --git a/admin-views/src/layout/common/nav-bar/index.tsx b/admin-views/src/layout/common/nav-bar/index.tsx index 78740d3e..aec75faf 100644 --- a/admin-views/src/layout/common/nav-bar/index.tsx +++ b/admin-views/src/layout/common/nav-bar/index.tsx @@ -8,13 +8,13 @@ import IconButton from './components/icon-button' import Settings from './components/settings' import styles from './style/index.module.less' import Menu from '../menu' -import {removeToken} from '@/utils/checkLogin' import {useRequest} from 'ahooks' import {fetchLogout} from '@/service/api' import AmisRender from '@/components/AmisRender' import {Breadcrumb} from '@/layout/common/breadcrumb' import Logo from '@/layout/common/Logo' import registerGlobalFunction from '@/utils/registerGlobalFunction' +import {Token} from '@/utils/common' const UserMenu = ({userInfo, darkTheme}) => { if (!userInfo.menus) return null @@ -54,7 +54,7 @@ function Navbar() { const logout = useRequest(fetchLogout, { manual: true, onSuccess() { - removeToken() + Token().clear() window.location.hash = "#/login" } }) diff --git a/admin-views/src/layout/common/tab-bar/index.tsx b/admin-views/src/layout/common/tab-bar/index.tsx index b7952c05..bb774c02 100644 --- a/admin-views/src/layout/common/tab-bar/index.tsx +++ b/admin-views/src/layout/common/tab-bar/index.tsx @@ -11,7 +11,7 @@ import registerGlobalFunction from "@/utils/registerGlobalFunction" const TabBar = () => { const history = useHistory() const pathname = history.location.pathname - const [routes, defaultRoute] = useRoute() + const {routes, defaultRoute} = useRoute() const flattenRoutes = getFlattenRoutes(routes) const [cacheTabs, setCacheTab] = useStorage("cached_tabs", "") const cachedTabs = JSON.parse(cacheTabs || "[]") diff --git a/admin-views/src/layout/layouts.tsx b/admin-views/src/layout/layouts.tsx index f6da7946..68bbb4cd 100644 --- a/admin-views/src/layout/layouts.tsx +++ b/admin-views/src/layout/layouts.tsx @@ -15,7 +15,7 @@ import {useHistory} from 'react-router' export const PageLayout = ({mode = 'default'}: { mode: string }) => { const [collapsed, setCollapsed] = useState(false) const {settings} = useSelector((state: GlobalState) => state) - const [routes] = useRoute() + const {routes} = useRoute() const history = useHistory() const pathname = history.location.pathname diff --git a/admin-views/src/layouts/DoubleLayout/index.tsx b/admin-views/src/layouts/DoubleLayout/index.tsx index ea163a36..466b44cb 100644 --- a/admin-views/src/layouts/DoubleLayout/index.tsx +++ b/admin-views/src/layouts/DoubleLayout/index.tsx @@ -16,7 +16,7 @@ const {Header, Sider, Content} = Layout export const DoubleLayout = () => { const [collapsed, setCollapsed] = useState(false) - const [routes] = useRoute() + const {routes} = useRoute() const history = useHistory() const pathname = history.location.pathname diff --git a/admin-views/src/layouts/components/LayoutBreadcrumb/index.tsx b/admin-views/src/layouts/components/LayoutBreadcrumb/index.tsx index d034823e..f2bb274a 100644 --- a/admin-views/src/layouts/components/LayoutBreadcrumb/index.tsx +++ b/admin-views/src/layouts/components/LayoutBreadcrumb/index.tsx @@ -6,7 +6,7 @@ import {Breadcrumb} from 'antd' import {useHistory} from 'react-router' const LayoutBreadcrumb = () => { - const [routes, _, getCurrentRoute] = useRoute() + const {routes, getCurrentRoute} = useRoute() const {settings} = useSelector((state: GlobalState) => state) const [breadcrumb, setBreadcrumb] = useState([]) const history = useHistory() diff --git a/admin-views/src/layouts/components/LayoutContent/index.tsx b/admin-views/src/layouts/components/LayoutContent/index.tsx index e0236b86..cfeca8da 100644 --- a/admin-views/src/layouts/components/LayoutContent/index.tsx +++ b/admin-views/src/layouts/components/LayoutContent/index.tsx @@ -15,7 +15,7 @@ const ArcoContent = Layout.Content const LayoutContent = () => { const {settings, appSettings} = useSelector((state: GlobalState) => state) - const [routes, defaultRoute] = useRoute() + const {routes, defaultRoute} = useRoute() const flattenRoutes = useMemo(() => getFlattenRoutes(routes) || [], [routes]) const history = useHistory() const pathname = history.location.pathname diff --git a/admin-views/src/layouts/components/LayoutFooter/index.tsx b/admin-views/src/layouts/components/LayoutFooter/index.tsx index 043f0d1b..69ec53c2 100644 --- a/admin-views/src/layouts/components/LayoutFooter/index.tsx +++ b/admin-views/src/layouts/components/LayoutFooter/index.tsx @@ -1,4 +1,4 @@ -import useSettings from '@/hooks/userSettings' +import useSettings from '@/hooks/useSetting' const LayoutFooter = () => { const {getSetting} = useSettings() diff --git a/admin-views/src/layouts/components/LayoutLogo/index.tsx b/admin-views/src/layouts/components/LayoutLogo/index.tsx index 3df2e91d..99e8c8fb 100644 --- a/admin-views/src/layouts/components/LayoutLogo/index.tsx +++ b/admin-views/src/layouts/components/LayoutLogo/index.tsx @@ -1,5 +1,5 @@ import {Image} from 'antd' -import useSettings from '@/hooks/userSettings' +import useSettings from '@/hooks/useSetting' const LayoutLogo = ({onlyLogo = false}) => { const {settings} = useSettings() diff --git a/admin-views/src/layouts/components/LayoutMenu/index.tsx b/admin-views/src/layouts/components/LayoutMenu/index.tsx index 87434a19..74c618d0 100644 --- a/admin-views/src/layouts/components/LayoutMenu/index.tsx +++ b/admin-views/src/layouts/components/LayoutMenu/index.tsx @@ -23,7 +23,7 @@ const LayoutMenu = ( const pathname = history.location.pathname const currentComponent = qs.parseUrl(pathname).url.slice(1) - const [routes, defaultRoute] = useRoute() + const {routes, defaultRoute} = useRoute() const defaultSelectedKeys = [currentComponent || defaultRoute] const paths = (currentComponent || defaultRoute)?.split('/') const defaultOpenKeys = paths?.slice(0, paths.length - 1) diff --git a/admin-views/src/layouts/index.tsx b/admin-views/src/layouts/index.tsx index d9977277..d3e51d61 100644 --- a/admin-views/src/layouts/index.tsx +++ b/admin-views/src/layouts/index.tsx @@ -13,7 +13,7 @@ import {DoubleLayout} from '@/layouts/DoubleLayout' const Layout = () => { // default | top | top-mix | double const mode = 'default' - const [routes] = useRoute() + const {routes} = useRoute() const history = useHistory() const isSmallScreen = useSmallScreen() const [isSm, setIsSm] = useState(isSmallScreen) diff --git a/admin-views/src/main.tsx b/admin-views/src/main.tsx index 85dde042..624ac643 100644 --- a/admin-views/src/main.tsx +++ b/admin-views/src/main.tsx @@ -3,9 +3,6 @@ import React from 'react' import ReactDOM from 'react-dom' import {createStore} from 'redux' import {Provider} from 'react-redux' -import {ConfigProvider as ArcoConfigProvider} from '@arco-design/web-react' -import zhCN from '@arco-design/web-react/es/locale/zh-CN' -import enUS from '@arco-design/web-react/es/locale/en-US' import {HashRouter, Route, Switch} from 'react-router-dom' import rootReducer from './store' import {GlobalContext} from './context' @@ -23,35 +20,22 @@ function Index() { const [lang, setLang] = useStorage('arco-lang', 'zh-CN') - function getArcoLocale() { - switch (lang) { - case 'zh-CN': - return zhCN - case 'en-US': - return enUS - default: - return zhCN - } - } - const contextValue = {lang, setLang} return ( - - - - - - - - {/**/} - - - - - - + + + + + + + {/**/} + + + + + ) diff --git a/admin-views/src/pages/login/form.tsx b/admin-views/src/pages/login/form.tsx index 3f76c4f0..5d0a062d 100644 --- a/admin-views/src/pages/login/form.tsx +++ b/admin-views/src/pages/login/form.tsx @@ -10,9 +10,9 @@ import {GlobalState} from "@/store" import styles from "./style/index.module.less" import {useRequest} from "ahooks" import {fetchCaptcha, fetchLogin, fetchUserInfo} from "@/service/api" -import {setToken} from "@/utils/checkLogin" import registerGlobalFunction from "@/utils/registerGlobalFunction" import useRoute from "@/routes" +import {Token} from '@/utils/common' export default function LoginForm({onlyFunc}: { onlyFunc?: boolean }) { const dispatch = useDispatch() @@ -28,7 +28,7 @@ export default function LoginForm({onlyFunc}: { onlyFunc?: boolean }) { const [rememberPassword, setRememberPassword] = useState(!!loginParams) const {appSettings} = useSelector((state: GlobalState) => state) - const [_, defaultRoute] = useRoute() + const {defaultRoute} = useRoute() const initUserInfo = useRequest(fetchUserInfo, { manual: true, @@ -48,7 +48,7 @@ export default function LoginForm({onlyFunc}: { onlyFunc?: boolean }) { removeLoginParams() } // 记录登录状态 - setToken(token) + Token().set(token) // 获取用户信息 initUserInfo.runAsync().then(() => { window.$owl.refreshRoutes().then(() => { diff --git a/admin-views/src/pages/login/index.tsx b/admin-views/src/pages/login/index.tsx index 46c58804..52d1991d 100644 --- a/admin-views/src/pages/login/index.tsx +++ b/admin-views/src/pages/login/index.tsx @@ -6,14 +6,16 @@ import SimpleLogin from "./template/simple" import DefaultLogin from "./template/default" import AmisLogin from "./template/amis" import {useMount} from "ahooks" +import {inLoginPage} from '@/utils/common' const Login = () => { const t = useLocale(locale) - const {settings, inited, appSettings} = useSelector((state: GlobalState) => state) + const {settings, appSettings} = useSelector((state: GlobalState) => state) const loginTemplate = settings.loginTemplate || "default" useMount(() => { - if (window.location.hash === "#/login") { + if (inLoginPage()) { + // 页面标题 let title = t["login.form.login"] const titleTmp = appSettings.layout?.title if (titleTmp) { @@ -29,7 +31,7 @@ const Login = () => { amis: AmisLogin } - return inited && template[loginTemplate]() + return template[loginTemplate]() } export default Login diff --git a/admin-views/src/routes/index.ts b/admin-views/src/routes/index.ts index 11d78805..e2046023 100644 --- a/admin-views/src/routes/index.ts +++ b/admin-views/src/routes/index.ts @@ -50,7 +50,7 @@ export const staticRoutes: IRoute[] = [ // }, ] -const useRoute = (): [IRoute[], string, any] => { +const useRoute = () => { const {routes} = useSelector((state: GlobalState) => state) const dispatch = useDispatch() const history = useHistory() @@ -87,7 +87,7 @@ const useRoute = (): [IRoute[], string, any] => { const getCurrentRoute = () => getFlattenRoutes(routes).find((tab) => tab.path === history.location.pathname.replace(/\/\d+/g, '/:id')) - return [routes, defaultRoute, getCurrentRoute] + return {routes, defaultRoute, getCurrentRoute} } export default useRoute diff --git a/admin-views/src/service/request/instance.ts b/admin-views/src/service/request/instance.ts index 9824137d..249bb71e 100644 --- a/admin-views/src/service/request/instance.ts +++ b/admin-views/src/service/request/instance.ts @@ -1,6 +1,6 @@ -import axios, {AxiosError, AxiosInstance, AxiosRequestConfig} from "axios" -import {getToken, removeToken} from "@/utils/checkLogin" -import {Message} from "@arco-design/web-react" +import axios, {AxiosError, AxiosInstance, AxiosRequestConfig} from 'axios' +import {Message} from '@arco-design/web-react' +import {goToLoginPage, inLoginPage, Token} from '@/utils/common' export default class CustomAxiosInstance { instance: AxiosInstance @@ -16,7 +16,7 @@ export default class CustomAxiosInstance { async config => { const handleConfig = {...config} // 设置token - const token = getToken() + const token = Token().value handleConfig.headers.Authorization = `Bearer ${token}` @@ -51,10 +51,10 @@ export default class CustomAxiosInstance { } // token失效 - if (backend?.code == 401 && window.location.hash != "#/login") { - removeToken() + if (backend?.code == 401 && !inLoginPage()) { + Token().clear() - window.location.hash = "#/login" + goToLoginPage() } return response diff --git a/admin-views/src/typeings.d.ts b/admin-views/src/typeings.d.ts new file mode 100644 index 00000000..46ec5bae --- /dev/null +++ b/admin-views/src/typeings.d.ts @@ -0,0 +1,7 @@ +interface Window { + $adminApiPrefix: string; + $owl: { + logout: () => void, + refreshRoutes: () => Promise, + } +} diff --git a/admin-views/src/utils/authentication.ts b/admin-views/src/utils/authentication.ts deleted file mode 100644 index 10f06a6d..00000000 --- a/admin-views/src/utils/authentication.ts +++ /dev/null @@ -1,55 +0,0 @@ -export type UserPermission = Record; - -type Auth = { - resource: string | RegExp; - actions?: string[]; -}; - -export interface AuthParams { - requiredPermissions?: Array; - oneOfPerm?: boolean; -} - -const judge = (actions: string[], perm: string[]) => { - if (!perm || !perm.length) { - return false; - } - - if (perm.join('') === '*') { - return true; - } - - return actions.every((action) => perm.includes(action)); -}; - -const auth = (params: Auth, userPermission: UserPermission) => { - const { resource, actions = [] } = params; - if (resource instanceof RegExp) { - const permKeys = Object.keys(userPermission); - const matchPermissions = permKeys.filter((item) => item.match(resource)); - if (!matchPermissions.length) { - return false; - } - return matchPermissions.every((key) => { - const perm = userPermission[key]; - return judge(actions, perm); - }); - } - - const perm = userPermission[resource]; - return judge(actions, perm); -}; - -export default (params: AuthParams, userPermission: UserPermission) => { - const { requiredPermissions, oneOfPerm } = params; - if (Array.isArray(requiredPermissions) && requiredPermissions.length) { - let count = 0; - for (const rp of requiredPermissions) { - if (auth(rp, userPermission)) { - count++; - } - } - return oneOfPerm ? count > 0 : count === requiredPermissions.length; - } - return true; -}; diff --git a/admin-views/src/utils/checkLogin.tsx b/admin-views/src/utils/checkLogin.tsx deleted file mode 100644 index 3e4536f5..00000000 --- a/admin-views/src/utils/checkLogin.tsx +++ /dev/null @@ -1,22 +0,0 @@ -// @ts-ignore -const TokenKey = window.$adminApiPrefix.replace(/^\//, "") + "-token" - -export const checkLogin = () => !!getToken() - -export const setToken = (token: string) => { - localStorage.setItem(TokenKey, token) -} - -export const removeToken = () => localStorage.removeItem(TokenKey) - -export const getToken = () => { - const token = localStorage.getItem(TokenKey) - - if (!token) { - if (window.location.hash !== "#/login") { - window.location.hash = "#/login" - } - } - - return token -} diff --git a/admin-views/src/utils/common.ts b/admin-views/src/utils/common.ts index dc756fc0..acff80b1 100644 --- a/admin-views/src/utils/common.ts +++ b/admin-views/src/utils/common.ts @@ -56,8 +56,10 @@ export const Token = () => { return { value: localStorage.getItem(cacheKey), set: (token: string) => localStorage.setItem(cacheKey, token), - remove: () => localStorage.removeItem(cacheKey), + clear: () => localStorage.removeItem(cacheKey), } } export const inLoginPage = () => window.location.hash == '#/login' + +export const goToLoginPage = () => window.location.hash = '#/login' diff --git a/admin-views/src/vite-env.d.ts b/admin-views/src/vite-env.d.ts deleted file mode 100644 index 11f02fe2..00000000 --- a/admin-views/src/vite-env.d.ts +++ /dev/null @@ -1 +0,0 @@ -///