Skip to content

Commit

Permalink
push
Browse files Browse the repository at this point in the history
  • Loading branch information
hfljzrxsj committed Apr 7, 2024
1 parent b778c42 commit 7ed9186
Show file tree
Hide file tree
Showing 27 changed files with 1,043 additions and 591 deletions.
9 changes: 1 addition & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4071,22 +4071,15 @@
"@mui/icons-material": "5.8.4",
"classnames": "^2.3.2",
"axios": "^0.24.0",
"uuid": "^8.3.2",
"vite": "^5.0.11",
"@mui/lab": "5.0.0-alpha.110",
"mockjs": "^1.1.0",
"echarts": "^5.2.1",
"@mui/system": "5.14.0",
"react-router": "^6.14.1",
"postcss-sass": "^0.3.5",
"postcss-scss": "^1.0.6",
"sass": "^1.63.6",
"sass-loader": "^12.6.0",
"scss-bundle": "^3.1.2",
"node-sass": "9.0.0",
"@rollup/plugin-commonjs": "20.0.0",
"@vitejs/plugin-legacy": "5.3.1",
"rollup-plugin-commonjs": "^10.1.0"
"node-sass": "9.0.0"
},
"devDependencies": {
"coffee-script": "^1.10.0",
Expand Down
3 changes: 3 additions & 0 deletions src/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
VITE_DBName=table
VITE_sqlFolder=assets
VITE_configFile=assets/config.json
3 changes: 3 additions & 0 deletions src/.env.development
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
VITE_DBName=table
VITE_sqlFolder=assets
VITE_configFile=assets/config.json
4 changes: 3 additions & 1 deletion src/.env.production
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
VITE_baseURL=http://121.196.247.3
VITE_DBName=table
VITE_sqlFolder=assets
VITE_configFile=assets/config.json
2 changes: 1 addition & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Provider } from 'react-redux';
import store from './store';
import SnackbarAlert from './components/SnackbarAlert';
import { CssBaseline, ScopedCssBaseline, StyledEngineProvider, useMediaQuery } from '@mui/material';
import './mock';
// import './mock';

export const commonUseRequestParams = {
loadingDelay: 300,
Expand Down
52 changes: 12 additions & 40 deletions src/Route/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@ import {
} from 'react-router-dom';
import type { RRNstring } from '@/types';
import MainFrame from '@/pages';
import Login from '@/pages/Login';
// import Login from '@/pages/Login';
import { lazy, Suspense } from 'react';
import { CircularProgress } from '@mui/material';
import Order from '@/pages/Order';
import Product from '@/pages/Product';
import PersistentDrawerLeft from '@/pages/Test/MUIMenu';
import { Backdrop, CircularProgress } from '@mui/material';
import WebSQL from '@/pages/WebSQL';
// import { renderRoutes } from 'react-router-config';

export enum pathString {
Expand All @@ -22,9 +20,6 @@ export enum pathString {
const Overview = lazy(() => import('@/pages/Overview'));
export const menuItems: Array<RouteObject> = ([
{ path: '', id: '目录', element: <Suspense fallback={<CircularProgress />}><Overview /></Suspense> },
{ path: pathString.order, id: '订单管理', element: <Suspense fallback={<CircularProgress />}><Order /></Suspense> },
{ path: pathString.product, id: '商品管理', element: <Suspense fallback={<CircularProgress />}><Product /></Suspense> },
{ path: pathString.stock, id: '库存管理' },
]);
export const concatUrl = (...args: ReadonlyArray<RRNstring>) => (`/${args.join('/')}`);
// const UseRoutes = () => useRoutes(menuItems);
Expand All @@ -37,41 +32,18 @@ export default function MyRoute () {
return (
<Routes>
<Route
path={pathString.login}
element={<Login />}
/>
<Route
// path='/'
element={<MainFrame />}
>
{
menuItems.map((item, index) => (
<Route key={index} path={item.path ?? ''} element={item.element}
>
{
item.children?.map((child, index) =>
<Route key={index} path={child.path ?? ''} element={child.element}
// loader={e => {
// console.log(e);
// return e;
// }}
// action={e => {
// console.log(e);
// return e;
// }}
// shouldRevalidate={e => {
// console.log(e);
// return Boolean(e);
// }}
/>
)
}
</Route>
))
}
{/* {renderRoutes(menuItems)} */}
<Route
index
element={<Suspense fallback={<Backdrop open={true}><CircularProgress /></Backdrop>}><Overview /></Suspense>}
/>
<Route
path=':subtitle/:id'
element={<WebSQL />}
>
</Route>
</Route>
<Route path='hjx' element={<PersistentDrawerLeft />} />
</Routes>
);
}
124 changes: 58 additions & 66 deletions src/actions/axios_instance.ts
Original file line number Diff line number Diff line change
@@ -1,77 +1,69 @@
import { concatUrl, pathString } from "@/Route";
import axios, { type AxiosRequestConfig } from "axios";
import { redirect } from 'react-router';
export const successCode = 1000;
export const adminIdString = 'adminId';
export const Authorization = 'Authorization';
export const orgId = 'orgId';
import axios from "axios";
// export const successCode = 1000;
// export const adminIdString = 'adminId';
// export const Authorization = 'Authorization';
// export const orgId = 'orgId';
const defaults = axios.defaults;
export const { common } = defaults.headers;
// const { common } = defaults.headers;
const source = axios.CancelToken.source();
const errorAction = () => {
localStorage.removeItem(Authorization);
redirect(concatUrl(pathString.login));
// localStorage.removeItem(Authorization);
// redirect(concatUrl(pathString.login));
// window.location.href = `#${concatUrl(pathString.login)}`;
};
defaults.baseURL = import.meta.env.VITE_baseURL;
// defaults.baseURL = import.meta.env.VITE_baseURL;
defaults.withCredentials = false;
common[Authorization] ??= localStorage.getItem(Authorization) ?? '';
common[adminIdString] ??= localStorage.getItem(adminIdString) ?? '';
export const getLocalStorageFromJSON = (s: string, backup?: string) => {
try {
const getJWT = localStorage.getItem(Authorization) ?? backup;
if (!getJWT)
return '';
return String(JSON.parse((atob(getJWT.split('.')?.[1] ?? '')))?.[s]);
}
catch (e) {
console.error(e);
return '';
}
};
export const level = 'level';
export const getLevel = (backup?: string) => getLocalStorageFromJSON(level, backup);
common[level] ??= getLevel();
common[orgId] ??= getLocalStorageFromJSON(orgId);
// export const getLocalStorageFromJSON = (s: string, backup?: string) => {
// try {
// const getJWT = localStorage.getItem(Authorization) ?? backup;
// if (!getJWT)
// return '';
// return String(JSON.parse((atob(getJWT.split('.')?.[1] ?? '')))?.[s]);
// }
// catch (e) {
// console.error(e);
// return '';
// }
// };
const controller = new AbortController();
defaults.signal = controller.signal;
defaults.cancelToken = source.token;
const cacheStorage = window.caches;
const { adapter } = defaults;
export const stringify = (e: unknown) => {
try {
return JSON.stringify(e);
}
catch (e) {
console.error(e);
return '';
}
};
const createCacheKey = ({ url, headers, params, data }: Pick<AxiosRequestConfig, 'url' | 'headers' | 'params' | 'data'>
) => ([url, headers?.[Authorization], headers?.[adminIdString], headers?.[level], stringify(params), stringify(data)].join('_'));
if (adapter && typeof adapter === 'function') {
defaults.adapter = async (req) => {
if (!cacheStorage) {
return adapter(req);
}
const { url = '', headers = {}, params, data } = req;
console.log('请求', url, params, data);
const cacheKey = createCacheKey({ url, headers, params, data });
const cache = await cacheStorage?.open(url);
const cacheRes = await cache?.match(cacheKey);
if (cacheRes) {
const resJson = await cacheRes.json();
// if (stringify(resJson)) {
return resJson;
// }
}
const res = await adapter(req);
const { status, data: resData } = res;
if (status === 200 && typeof resData === 'string' && resData.includes(String(successCode)))
await cache?.put(cacheKey, new Response(stringify(res)));
return res;
};
}
// const cacheStorage = window.caches;
// const { adapter } = defaults;
// export const stringify = (e: unknown) => {
// try {
// return JSON.stringify(e);
// }
// catch (e) {
// console.error(e);
// return '';
// }
// };
// const createCacheKey = ({ url, headers, params, data }: Pick<AxiosRequestConfig, 'url' | 'headers' | 'params' | 'data'>
// ) => ([url, headers?.[Authorization], headers?.[adminIdString], headers?.[level], stringify(params), stringify(data)].join('_'));
// if (adapter && typeof adapter === 'function') {
// defaults.adapter = async (req) => {
// if (!cacheStorage) {
// return adapter(req);
// }
// const { url = '', headers = {}, params, data } = req;
// console.log('请求', url, params, data);
// const cacheKey = createCacheKey({ url, headers, params, data });
// const cache = await cacheStorage?.open(url);
// const cacheRes = await cache?.match(cacheKey);
// if (cacheRes) {
// const resJson = await cacheRes.json();
// // if (stringify(resJson)) {
// return resJson;
// // }
// }
// const res = await adapter(req);
// const { status, data: resData } = res;
// if (status === 200 && typeof resData === 'string' && resData.includes(String(successCode)))
// await cache?.put(cacheKey, new Response(stringify(res)));
// return res;
// };
// }
// export const axios_instance = axios.create({
// baseURL: import.meta.env.VITE_baseURL,
// // timeout: 20000,
Expand All @@ -95,7 +87,7 @@ axios.interceptors.request.use(

axios.interceptors.response.use(
async (res) => {
if (res.data.code === 1003) {
if (res.status === 401) {
errorAction();
}
// if (!cacheStorage)
Expand Down
3 changes: 0 additions & 3 deletions src/actions/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import { dateFormat, timeFormat } from "@/components/FilterDialogWithBreadcrumbs";
import { regionName } from "@/components/MyTable";
import type { DistributionOfTerminalSalesArray } from "@/pages/SalesVolumeMonitoring/DistributionOfTerminalSales";
import type { SalesSituationOfTerminalSubChannels_labelType } from "@/pages/SalesVolumeMonitoring/SalesSituationOfTerminalSubChannels";
import type { TOP10ModelInformation_labelType } from "@/pages/SalesVolumeMonitoring/TOP10ModelInformation";
import { enumActionName, enumSeverity, enumSnackbarAlert, type snackbarAlertAction } from "@/store/SnackBarRuducer";
import axios from "axios";
import type { Dispatch } from "redux";
Expand Down
10 changes: 10 additions & 0 deletions src/components/AppBar/_index.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@
display: flex;
flex-direction: column;
gap: 9q;
align-items: center;

button {
text-transform: none;
}

> label {
margin-right: 0;
margin-left: 0;
}

> p > span {
font-weight: 900;
Expand Down
Loading

0 comments on commit 7ed9186

Please sign in to comment.