mac
6 months ago
6 changed files with 201 additions and 1 deletions
-
2env.md
-
3src/http/api.ts
-
32src/http/axios_config.ts
-
63src/http/service.ts
-
95src/pages/admin/AdminRecord.tsx
-
7src/pages/admin/index.tsx
@ -0,0 +1,3 @@ |
|||
import request from './service' |
|||
|
|||
export const getRecord = (data: object) => request({ url: '/v1/admin/product', data }) |
@ -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; |
@ -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; |
@ -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>180天质押的FIL数量:</div> |
|||
<div>{record.product_180 || 0}</div> |
|||
</div> |
|||
<div className="row-items mt-2 fz-20"> |
|||
<div>270天质押的FIL数量:</div> |
|||
<div>{record.product_270 || 0}</div> |
|||
</div> |
|||
<div className="row-items mt-2 fz-20"> |
|||
<div>360天质押的FIL数量:</div> |
|||
<div>{record.product_360 || 0}</div> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
) |
|||
} |
|||
|
|||
export default AdminRecord |
Write
Preview
Loading…
Cancel
Save
Reference in new issue