Commit f2d43b1b by zhangquan

初次提交

1 parent e0aec565
This diff could not be displayed because it is too large.
...@@ -3,11 +3,16 @@ ...@@ -3,11 +3,16 @@
"version": "0.1.0", "version": "0.1.0",
"private": true, "private": true,
"dependencies": { "dependencies": {
"@ant-design/icons": "^5.0.1",
"@testing-library/jest-dom": "^5.16.5", "@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.4.0", "@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0", "@testing-library/user-event": "^13.5.0",
"antd": "^5.2.1",
"axios": "^1.3.3",
"echarts": "^5.4.1",
"react": "^18.2.0", "react": "^18.2.0",
"react-dom": "^18.2.0", "react-dom": "^18.2.0",
"react-router-dom": "^6.8.1",
"react-scripts": "5.0.1", "react-scripts": "5.0.1",
"web-vitals": "^2.1.4" "web-vitals": "^2.1.4"
}, },
......
import logo from './logo.svg'; import React, { useState } from "react";
import './App.css'; import "./App.css";
import { useRoutes, Link } from "react-router-dom";
import router from "./router";
function App() { function App() {
const outlet = useRoutes(router);
return ( return (
<div className="App"> <div className="App">
<header className="App-header"> <React.Suspense fallback={<div>Loading...</div>}>{outlet}</React.Suspense>
<img src={logo} className="App-logo" alt="logo" />
<p>
Edit <code>src/App.js</code> and save to reload.
</p>
<a
className="App-link"
href="https://reactjs.org"
target="_blank"
rel="noopener noreferrer"
>
Learn React
</a>
</header>
</div> </div>
); );
} }
......
const errorHandle = (error: Error) => {
console.log("error", error);
};
export default errorHandle;
import HttpRequest from "./request";
import config from "../../config";
const baseUrl =
process.env.NODE_ENV === "development"
? config.baseUrl.dev
: config.baseUrl.pro;
const axios = new HttpRequest(baseUrl);
export default axios;
// 以class类来实现axios实例化
import axios, { AxiosInstance, AxiosRequestConfig, AxiosResponse } from "axios";
// 自定义 promise interface
import { HttpResponse } from "../../type/index";
class HttpRequest {
private baseUrl: string;
constructor(baseUrl: string) {
this.baseUrl = baseUrl;
}
// 获取axios实例的配置
getInsideConfig() {
const config = {
baseURL: this.baseUrl,
headers: {
"Content-Type": "application/json;charset=utf-8",
},
timeout: 1000 * 10,
};
return config;
}
// 设定拦截器
interceptors(instance: AxiosInstance) {
// 添加请求拦截器
instance.interceptors.request.use(
(config) => {
// 添加token
const token = sessionStorage.getItem("token") || "";
if (token) {
(config.headers as any).Authorization = "Bearer " + token;
}
// console.log('config:' + JSON.stringify(config))
// 在发送请求之前做些什么
return config;
},
(error: Error) => {
// 对请求错误做些什么
return Promise.reject(error);
}
);
// 添加响应拦截器
instance.interceptors.response.use(
(response) => {
// console.log("response:" + JSON.stringify(response));
// 对响应数据做点什么
if (response.status === 200) {
// return response.data
// 跟上边直接返回都是一样的(也可以不加Promise.resolve)
return Promise.resolve(response.data);
} else {
return Promise.reject(response);
}
},
(error: Error) => {
// 对响应错误做点什么
// debugger
return Promise.reject(error);
}
);
}
// 创建实例
request(options: AxiosRequestConfig) {
const instance = axios.create();
const newOptions = Object.assign(this.getInsideConfig(), options);
this.interceptors(instance);
return instance(newOptions);
}
get(
url: string,
config?: AxiosRequestConfig
): Promise<AxiosResponse> & Promise<HttpResponse> {
const options = Object.assign(
{
method: "get",
url: url,
},
config
);
return this.request(options);
}
post(
url: string,
data?: any
): Promise<AxiosResponse> & Promise<HttpResponse> {
return this.request({
method: "post",
url: url,
data: data,
});
}
}
export default HttpRequest;
import React from 'react'; import React from "react";
import ReactDOM from 'react-dom/client'; import ReactDOM from "react-dom/client";
import './index.css'; import "./index.css";
import App from './App'; import App from "./App";
import reportWebVitals from './reportWebVitals'; // import reportWebVitals from "./reportWebVitals";
import { BrowserRouter } from "react-router-dom";
const root = ReactDOM.createRoot(document.getElementById('root')); const root = ReactDOM.createRoot(document.getElementById("root"));
root.render( root.render(
<React.StrictMode> <React.StrictMode>
<BrowserRouter>
<App /> <App />
</BrowserRouter>
</React.StrictMode> </React.StrictMode>
); );
// If you want to start measuring performance in your app, pass a function // If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log)) // to log results (for example: reportWebVitals(console.log))
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals // or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
reportWebVitals(); // reportWebVitals();
import { lazy } from 'react'
import { Navigate } from 'react-router-dom'
const Home = lazy(()=> import("../views/Home"))
const Mine = lazy(()=> import("../views/Mine"))
const Detail = lazy(()=> import("../views/Detail"))
const Classify = lazy(()=> import("../views/Classify"))
const Ranking = lazy(()=> import("../views/Ranking"))
const Login = lazy(()=> import("../views/Login/index"))
const routers = [
{
path: '/',
element: <Navigate to="/login" />
},
{
path: "/login",
element: <Login />
},
{
path: "/",
element: <Home />,
children: [
{
path: "/detail",
element: <Detail />
},
{
path: "/ranking",
element: <Ranking />
},
{
path: "/mine",
element: <Mine />
},
{
path: "/classify",
element: <Classify />
}
]
},
]
export default routers
\ No newline at end of file \ No newline at end of file
/**
* 存放公共的类型声明文件
*/
export interface HttpResponse {
code?: number;
data?: any;
message?: string | Record<string, any>; // 定义 字符串,对象类型
[propname: string]: any;
}
//项目分类
export interface ProjectItem {
id?: number;
name: string;
addr: string;
remark: string;
[property: string]: any;
}
//项目分类里api
export interface ProjectApi {
id?: number;
projectId: number;
method: string;
url: string;
baseUrl?: string;
remark: string;
content: string;
createDate?: Date;
updateDate?: Date;
}
//项目条件判断
export interface ConditionItem {
id?: number;
name: string;
content: string;
createDate?: Date;
updateDate?: Date;
}
//用户相关信息
export interface UserMessage {
id?: number;
roleId?: number;
name?: string;
account?: string;
password: string;
createDate?: Date;
updateDate?: Date;
}
import React, { useState } from 'react';
function Classify() {
return <div>Classify</div>
}
export default Classify
\ No newline at end of file \ No newline at end of file
import React, { useState } from 'react';
function Detail() {
return <div>Detail</div>
}
export default Detail
\ No newline at end of file \ No newline at end of file
import React, { useState } from 'react';
import { ProfileOutlined, AppstoreOutlined, BarChartOutlined, ShopOutlined } from '@ant-design/icons';
import { Menu } from 'antd';
import { useNavigate, Outlet } from 'react-router-dom'
const items = [
{
label: '绩效排名',
key: 'ranking',
icon: <BarChartOutlined />,
},
{
label: '绩效明细',
key: 'detail',
icon: <ProfileOutlined />
},
{
label: '绩效分类',
key: 'classify',
icon: <AppstoreOutlined />
},
{
label: '我的',
key: 'mine',
icon: <ShopOutlined />
},
];
function Home() {
const [current, setCurrent] = useState('ranking');
const navigateTo = useNavigate()
const onClick = (e)=>{
navigateTo(e.key)
setCurrent(e.key);
}
return (<div>
<Menu onClick={onClick} selectedKeys={[current]} mode="horizontal" items={items} />
<Outlet />
</div>)
}
export default Home
\ No newline at end of file \ No newline at end of file
.ctnr {
display: flex;
}
.ant-form {
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
width: 520px;
padding: 35px 35px 15px;
margin: 120px auto;
background-color: #eee;
}
import React from 'react';
import './index.css'
import { Button, Checkbox, Form, Input } from 'antd';
const onFinish = (values) => {
console.log('Success:', values);
};
const onFinishFailed = (errorInfo) => {
console.log('Failed:', errorInfo);
};
const App = () => {
return (
<div className='ctnr'>
<Form
name="basic"
labelCol={{ span: 6 }}
wrapperCol={{ span: 16 }}
style={{ maxWidth: 600 }}
initialValues={{ remember: true }}
onFinish={onFinish}
onFinishFailed={onFinishFailed}
autoComplete="off"
>
<Form.Item
label="员工姓名"
name="username"
rules={[{ required: true, message: 'Please input your username!' }]}
>
<Input />
</Form.Item>
<Form.Item
label="密码"
name="password"
rules={[{ required: true, message: 'Please input your password!' }]}
>
<Input.Password />
</Form.Item>
<Form.Item name="remember" valuePropName="checked" wrapperCol={{span: 16 }}>
<Checkbox>记住密码</Checkbox>
</Form.Item>
<Form.Item wrapperCol={{ span: 24 }}>
<Button type="primary" htmlType="submit">
登录
</Button>
</Form.Item>
</Form>
</div>
)
}
export default App;
\ No newline at end of file \ No newline at end of file
import React, { useState } from 'react';
function Mine() {
return <div>Mine</div>
}
export default Mine
\ No newline at end of file \ No newline at end of file
import React, { useEffect, useRef } from 'react';
import * as echarts from 'echarts';
import { echartData } from './constantData'
let echartOptions = echartData
function Ranking() {
let myChart = null;
const initChart = () => {
let element = document.getElementById('chartDom');
myChart = echarts.init(element);
myChart.clear()
echartOptions && myChart.setOption(echartOptions);
}
useEffect(() => {
initChart()
window.addEventListener("resize", () => {
myChart && myChart.resize();
});
// 组件销毁前卸载监听方法
return () => {
window.removeEventListener("resize", () => {
myChart && myChart.resize();
});
}
}, [])
return (
<div id='chartDom' style={{ width: '80%', margin: '0 auto', height: '600px' }}></div>
)
}
export default Ranking
\ No newline at end of file \ No newline at end of file
const echartData = {
legend: {},
tooltip: {},
dataset: {
dimensions: ["product", "2015", "2016", "2017"],
source: [
["product", "2015", "2016", "2017"],
["Matcha Latte", 43.3, 85.8, 93.7],
["Milk Tea", 83.1, 73.4, 55.1],
["Cheese Cocoa", 86.4, 65.2, 82.5],
["Walnut Brownie", 72.4, 53.9, 39.1],
],
},
xAxis: { type: "category" },
yAxis: {},
// Declare several bar series, each will be mapped
// to a column of dataset.source by default.
series: [{ type: "bar" }, { type: "bar" }, { type: "bar" }],
};
export { echartData };
This diff could not be displayed because it is too large.
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!