fix issues

pull/330/head
vapao 2021-04-01 09:52:48 +08:00
parent 7dbb2480c6
commit de2bfe4e2c
2 changed files with 10 additions and 6 deletions

View File

@ -41,6 +41,7 @@ export default function () {
} }
function listen() { function listen() {
if (!X_TOKEN) return;
const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:'; const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
ws = new WebSocket(`${protocol}//${window.location.host}/api/ws/notify/?x-token=${X_TOKEN}`); ws = new WebSocket(`${protocol}//${window.location.host}/api/ws/notify/?x-token=${X_TOKEN}`);
ws.onopen = () => ws.send('ok'); ws.onopen = () => ws.send('ok');

View File

@ -3,7 +3,7 @@
* Copyright (c) <spug.dev@gmail.com> * Copyright (c) <spug.dev@gmail.com>
* Released under the AGPL-3.0 License. * Released under the AGPL-3.0 License.
*/ */
import React, { useState } from 'react'; import React, { useState, useEffect } from 'react';
import { Switch, Route } from 'react-router-dom'; import { Switch, Route } from 'react-router-dom';
import { Layout } from 'antd'; import { Layout } from 'antd';
import Sider from './Sider'; import Sider from './Sider';
@ -13,9 +13,8 @@ import routes from '../routes';
import { updatePermissions, hasPermission } from 'libs'; import { updatePermissions, hasPermission } from 'libs';
import styles from './layout.module.less'; import styles from './layout.module.less';
const Routes = [];
function initRoutes(routes) { function initRoutes(routes) {
const Routes = [];
for (let route of routes) { for (let route of routes) {
if (route.component) { if (route.component) {
if (!route.auth || hasPermission(route.auth)) { if (!route.auth || hasPermission(route.auth)) {
@ -25,11 +24,9 @@ function initRoutes(routes) {
initRoutes(route.child) initRoutes(route.child)
} }
} }
return Routes
} }
updatePermissions()
initRoutes(routes)
// 404 // 404
function NotFound() { function NotFound() {
return ( return (
@ -47,6 +44,12 @@ function NotFound() {
export default function () { export default function () {
const [collapsed, setCollapsed] = useState(false) const [collapsed, setCollapsed] = useState(false)
const [Routes, setRoutes] = useState([]);
useEffect(() => {
updatePermissions();
setRoutes(initRoutes(routes));
}, [])
return ( return (
<Layout> <Layout>