Browse Source

添加质押统计

master
mac 6 months ago
parent
commit
c769206274
  1. 2
      env.md
  2. 3
      src/http/api.ts
  3. 32
      src/http/axios_config.ts
  4. 63
      src/http/service.ts
  5. 95
      src/pages/admin/AdminRecord.tsx
  6. 7
      src/pages/admin/index.tsx

2
env.md

@ -3,3 +3,5 @@ GENERATE_SOURCEMAP=false
REACT_APP_CHAINID=56
REACT_APP_DAY_TIME=86400
REACT_APP_SHARE_URL='https://app.sofil.io/index.html'
REACT_APP_SIGN_KEY="sofivnlasknal"
REACT_APP_BASE_URL='http://203.161.57.92:8085'

3
src/http/api.ts

@ -0,0 +1,3 @@
import request from './service'
export const getRecord = (data: object) => request({ url: '/v1/admin/product', data })

32
src/http/axios_config.ts

@ -0,0 +1,32 @@
export default {
baseURL: process.env.REACT_APP_BASE_URL + '/api',
// baseURL: process.env.NODE_ENV === 'development' ? 'http://192.168.124.22:10002/api' : window.location.origin + '/api',
method: 'post',
//`timeout`选项定义了请求发出的延迟毫秒数
//如果请求花费的时间超过延迟的时间,那么请求会被终止
timeout: 60 * 1000,
//发送请求前允许修改数据
transformRequest: [function (data: any) {
return data;
}],
//数据发送到then/catch方法之前允许数据改动
transformResponse: [function (data: any) {
return data;
}],
// headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
headers: { 'Content-Type': 'application/json; charset=UTF-8' },
// withCredentials: false,//跨域请求时是否携带cookie
responseType: 'json',//响应数据类型
// xsrfCookieName: 'XSRF-TOKEN',
// xsrfHeaderName: 'X-XSRF-TOKEN',
onUploadProgress: function (progressEvent: any) { },//上传进度事件
onDownloadProgress: function (progressEvent: any) { },//下载进度事件
//`validateStatus`定义了是否根据http相应状态码,来resolve或者reject promise
//如果`validateStatus`返回true(或者设置为`null`或者`undefined`),那么promise的状态将会是resolved,否则其状态就是rejected
validateStatus: function (status: number) {
return status >= 200 && status < 300 // 默认的
},
//`maxRedirects`定义了在nodejs中重定向的最大数量
maxRedirects: 5
} as any;

63
src/http/service.ts

@ -0,0 +1,63 @@
import axiosConfig from "./axios_config";
import axios, { AxiosResponse } from "axios";
import signGenerator from "../utils/sign/sign";
import { Toast } from "react-vant";
import sortParam from "../utils/sign/sort";
import store from "../store";
const service = axios.create(axiosConfig);
// 请求拦截
service.interceptors.request.use(
(config) => {
if (!config.data) config.data = {};
let ps = config.params ? sortParam(config.params) : "";
let timestamp = new Date().getTime();
let signData = {
uri: "/api" + config.url,
timestamp: timestamp,
args: ps,
};
let sign = signGenerator(signData);
(config.headers as any).sign = sign;
(config.headers as any).timestamp = timestamp;
if (config.data instanceof FormData) return config;
config.data = JSON.stringify(config.data);
return config;
},
(error) => {
return Promise.reject(error);
}
);
// 响应拦截
service.interceptors.response.use(
(res: any) => {
try {
let data = JSON.parse(res.data);
if (data.code !== 0) {
Toast.info({
message: data.msg,
duration: 2000,
});
}
return data;
} catch (error) {
return null;
}
},
(error) => {
try {
if (error.response) {
let data = JSON.parse(error.response.data);
Toast.info(data.err);
return data;
}
} catch (error) {
console.error(error);
}
}
);
export default service;

95
src/pages/admin/AdminRecord.tsx

@ -0,0 +1,95 @@
import { useEffect, useState } from "react"
import { Calendar, Cell } from "react-vant";
import { getRecord } from "~/http/api";
import { getTime } from "~/utils";
const AdminRecord = () => {
const [record, setRecord] = useState({} as any)
const getData = async (data: object) => {
const res: any = await getRecord(data)
console.log(res);
if (res.code === 0) {
setRecord(res.data)
}
}
const initialTime = () => {
var today = new Date();
var yesterday = new Date(today);
yesterday.setDate(today.getDate() - 1);
yesterday.setHours(0, 0, 0, 0);
var endOfYesterday = new Date(yesterday);
endOfYesterday.setHours(23, 59, 59, 999);
const start = new Date(yesterday).getTime()
const end = new Date(endOfYesterday).getTime()
const params = {
start_time: Math.floor(start / 1000),
end_time: Math.floor(end / 1000)
}
return params
}
const onConfirm = (e: any) => {
const start = new Date(e[0]).getTime();
const end = new Date(new Date(e[1]).setMinutes(new Date(e[1]).getMinutes() - 1)).getTime()
getData({
start_time: Math.floor(start / 1000),
end_time: Math.floor(end / 1000)
})
}
useEffect(() => {
getData(initialTime())
}, [])
return (
<div className="mt-2">
<Calendar
type='range'
minDate={new Date(2024, 4, 1)}
onConfirm={onConfirm}
>
{(val: any, actions) => (
<Cell
isLink
title='日期区间'
titleStyle={{ flex: 'none' }}
value={
val
? val.map((el: any) => el.toLocaleDateString()).join('~')
: '请选择日期'
}
onClick={() => actions.open()}
/>
)}
</Calendar>
<div className="mt-5">
<div className="row-items fz-20">
<div>180FIL数量</div>
<div>{record.product_180 || 0}</div>
</div>
<div className="row-items mt-2 fz-20">
<div>270FIL数量</div>
<div>{record.product_270 || 0}</div>
</div>
<div className="row-items mt-2 fz-20">
<div>360FIL数量</div>
<div>{record.product_360 || 0}</div>
</div>
</div>
</div>
)
}
export default AdminRecord

7
src/pages/admin/index.tsx

@ -7,6 +7,7 @@ import AdminPledge from "./AdminPledge"
import AdminPool from './AdminPool'
import AdminNFT from './AdminNFT'
import AdminSet from './AdminSet'
import AdminRecord from './AdminRecord'
const Admin = () => {
@ -47,6 +48,7 @@ const Admin = () => {
<Tabs.TabPane title="質押合約"></Tabs.TabPane>
<Tabs.TabPane title="池子合約"></Tabs.TabPane>
<Tabs.TabPane title="NFT設置"></Tabs.TabPane>
<Tabs.TabPane title="质押记录"></Tabs.TabPane>
{
isDeploy && (
<Tabs.TabPane title="管理員設置"></Tabs.TabPane>
@ -63,7 +65,10 @@ const Admin = () => {
tabIndex === 2 && <AdminNFT />
}
{
tabIndex === 3 && <AdminSet />
tabIndex === 3 && <AdminRecord />
}
{
tabIndex === 4 && <AdminSet />
}
</div>
)

Loading…
Cancel
Save