diff --git a/spug_web2/src/libs/app.js b/spug_web2/src/libs/app.js
new file mode 100644
index 0000000..ce191a6
--- /dev/null
+++ b/spug_web2/src/libs/app.js
@@ -0,0 +1,45 @@
+import {isSubArray, loadJSONStorage} from "@/libs/utils.js";
+
+class App {
+ constructor() {
+ this.lang = localStorage.getItem('lang') || 'zh';
+ this.theme = localStorage.getItem('theme') || 'light';
+ this.stable = loadJSONStorage('stable', {});
+ this.session = loadJSONStorage('session', {});
+ }
+
+ get access_token() {
+ return this.session['access_token'] || '';
+ }
+
+ get nickname() {
+ return this.session['nickname'];
+ }
+
+ hasPermission(code) {
+ const {isSuper, permissions} = this.session;
+ if (!code || isSuper) return true;
+ for (let item of code.split('|')) {
+ if (isSubArray(permissions, item.split('&'))) {
+ return true
+ }
+ }
+ return false
+ }
+
+ updateSession(data) {
+ Object.assign(this.session, data);
+ localStorage.setItem('session', JSON.stringify(this.session));
+ }
+
+ getStable(key) {
+ return this.stable[key] ?? {};
+ }
+
+ updateStable(key, data) {
+ this.stable[key] = data;
+ localStorage.setItem('stable', JSON.stringify(this.stable));
+ }
+}
+
+export default new App();
\ No newline at end of file
diff --git a/spug_web2/src/libs/http.js b/spug_web2/src/libs/http.js
index 27cb706..efc9665 100644
--- a/spug_web2/src/libs/http.js
+++ b/spug_web2/src/libs/http.js
@@ -1,6 +1,6 @@
import useSWR from 'swr'
import {message} from 'antd'
-import session from '@/libs/session'
+import app from '@/libs/app.js'
import {redirect} from 'react-router-dom'
function fetcher(resource, init) {
@@ -33,7 +33,7 @@ function SWRGet(url, params) {
}
function request(method, url, params) {
- const init = {method, headers: {'X-Token': session.access_token}}
+ const init = {method, headers: {'X-Token': app.accessToken}}
if (['GET', 'DELETE'].includes(method)) {
if (params) url = `${url}?${new URLSearchParams(params).toString()}`
return fetcher(url, init)
diff --git a/spug_web2/src/libs/index.js b/spug_web2/src/libs/index.js
index e0e157e..0867c20 100644
--- a/spug_web2/src/libs/index.js
+++ b/spug_web2/src/libs/index.js
@@ -1,11 +1,11 @@
import React from 'react'
import http from './http'
-import session from './session'
+import app from './app.js'
const SContext = React.createContext({})
export * from './utils.js'
export {
+ app,
http,
- session,
SContext,
}
diff --git a/spug_web2/src/libs/session.js b/spug_web2/src/libs/session.js
deleted file mode 100644
index 03fa021..0000000
--- a/spug_web2/src/libs/session.js
+++ /dev/null
@@ -1,43 +0,0 @@
-import {isSubArray} from "@/libs/utils.js";
-
-class Session {
- constructor() {
- this._session = {};
- this.lang = localStorage.getItem('lang') || 'zh';
- this.theme = localStorage.getItem('theme') || 'light';
- const tmp = localStorage.getItem('session');
- if (tmp) {
- try {
- this._session = JSON.parse(tmp);
- } catch (e) {
- localStorage.removeItem('session');
- }
- }
- }
-
- get access_token() {
- return this._session['access_token'] || '';
- }
-
- get nickname() {
- return this._session['nickname'];
- }
-
- hasPermission(code) {
- const {isSuper, permissions} = this._session;
- if (!code || isSuper) return true;
- for (let item of code.split('|')) {
- if (isSubArray(permissions, item.split('&'))) {
- return true
- }
- }
- return false
- }
-
- update(data) {
- Object.assign(this._session, data);
- localStorage.setItem('session', JSON.stringify(this._session));
- }
-}
-
-export default new Session();
\ No newline at end of file
diff --git a/spug_web2/src/libs/utils.js b/spug_web2/src/libs/utils.js
index 5539857..384e9d6 100644
--- a/spug_web2/src/libs/utils.js
+++ b/spug_web2/src/libs/utils.js
@@ -42,4 +42,16 @@ export function includes(s, keys) {
} else {
return isInclude(s, keys)
}
+}
+
+export function loadJSONStorage(key, defaultValue = null) {
+ const tmp = localStorage.getItem(key)
+ if (tmp) {
+ try {
+ return JSON.parse(tmp)
+ } catch (e) {
+ localStorage.removeItem(key)
+ }
+ }
+ return defaultValue
}
\ No newline at end of file
diff --git a/spug_web2/src/routes.jsx b/spug_web2/src/routes.jsx
index f97c77f..3994486 100644
--- a/spug_web2/src/routes.jsx
+++ b/spug_web2/src/routes.jsx
@@ -1,4 +1,4 @@
-import {AiOutlineDesktop, AiOutlineCloudServer, AiOutlineCluster} from 'react-icons/ai'
+import {FaDesktop, FaServer, FaSitemap} from 'react-icons/fa6'
import Layout from './layout/index.jsx'
import ErrorPage from './error-page.jsx'
import LoginIndex from './pages/login/index.jsx'
@@ -16,18 +16,18 @@ let routes = [
path: 'home',
element:
,
title: t('工作台'),
- icon:
,
+ icon:
,
},
{
path: 'host',
element:
,
title: t('主机管理'),
- icon:
+ icon:
},
{
path: 'exec',
title: t('批量执行'),
- icon:
,
+ icon:
,
children: [
{
path: 'task',