diff --git a/package.json b/package.json index 5c614d7..9ed2f57 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ "react": "^18.2.0", "react-dom": "^18.2.0", "react-router": "^6.3.0", - "react-router-dom": "^6.3.0", + "react-router-dom": "6", "uuid": "^8.3.2" }, "devDependencies": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index c4f16f3..30b1802 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -26,7 +26,7 @@ specifiers: react: ^18.2.0 react-dom: ^18.2.0 react-router: ^6.3.0 - react-router-dom: ^6.3.0 + react-router-dom: '6' ts-jest: ^28.0.8 typescript: ^4.8.2 uuid: ^8.3.2 diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 38d9e82..f610d3b 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -63,8 +63,8 @@ "fullscreen": false, "height": 600, "resizable": true, - "title": "秀动", - "width": 800 + "title": "秀动辅助", + "width": 1000 } ] } diff --git a/src/App.tsx b/src/App.tsx index d3c3ef2..9a67c32 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,7 +1,6 @@ -import {Outlet, Route, Routes} from "react-router-dom"; +import {Navigate, Outlet, Route, Routes} from "react-router-dom"; import {DefaultFooter, ProLayout} from "@ant-design/pro-layout"; import route from "./configs/route"; -import Home from "./pages/home"; export default () => { @@ -12,15 +11,15 @@ export default () => { }} >
{dom}
} subMenuItemRender={(_, dom) =>
{dom}
} title="秀动辅助" - logo="https://gw.alipayobjects.com/mdn/rms_b5fcc5/afts/img/A*1NHAQYduQiQAAAAAAAAAAABkARQnAQ" + siderWidth={120} menuHeaderRender={(logo, title) => (
- {logo} {title}
)} @@ -45,19 +44,18 @@ export default () => { }} > - }> - - {route.routes!.map((route, index) => { - return ( - - ); - } - )} + }> + {route.routes!.map((route, index) => { + return ( + + ); + } + )}
diff --git a/src/component/buttons.tsx b/src/component/buttons.tsx index a9da72e..b96913b 100644 --- a/src/component/buttons.tsx +++ b/src/component/buttons.tsx @@ -1,19 +1,24 @@ - import React from "react"; -import {Button, Form, Select, Space} from "antd"; +import {Button, Space} from "antd"; + +export type ButtonsProps = { + buyNow: () => void + buyPickup: () => void + buyTicket: () => void + pickEnable : boolean + ticketEnable : boolean +} -const Buttons: React.FC = () => { +const Buttons: React.FC = (props) => { return ( <> - - - - + + + - ); } diff --git a/src/component/chooseUser.tsx b/src/component/chooseUser.tsx index 76afb16..9022170 100644 --- a/src/component/chooseUser.tsx +++ b/src/component/chooseUser.tsx @@ -1,79 +1,113 @@ import React, {useEffect, useState} from 'react'; import {Button, Select, Space} from 'antd'; +import {post} from "../util/http"; +import {ADDRESS_LIST, AddressInfo, COMMON_PERFORMER, performerInfo} from "../network/api/userInfo"; +import {ApiParams} from "../network/apiParams"; -const {Option} = Select; - - -export type UserInfo = { - id: string; - name: string; - address: string; -} export type UserInfoProps = { - onChange: (value: string) => void; + onPerformerChange: (value: performerInfo[]) => void; + onAddressChange: (value: AddressInfo) => void; } + + const ChooseUser: React.FC = (props) => { - const [userInfoList, setUserInfoList] = useState([]); - const [selectKey, setSelectKey] = useState(-1) + // 观影人信息 + const [performerList, setPerformerList] = useState([]); + const [defaultPerformerId, setDefaultPerformerId] = useState([]); + + // 收货地址 + const [addressList, setAddressList] = useState([]); + const [defaultAddressId, setDefaultAddressId] = useState(); + + + interface PerformerOption { + label: string, + value: number, + performer : performerInfo + } + + interface AddressOption { + label: string, + value: number, + address : AddressInfo + } + + // 初始化 useEffect(() => { - setUserInfoList([ - { - id: "1", - name: "marun", - address: "杭州" - }, - { - id: "2", - name: "marin", - address: "江苏" - }, - ]) + fetchInfo() }, []) - const handleOnChange = function (val: string, option: any) { - props.onChange(val); - setSelectKey(option.key) + // 观影人信息更新 + const handlePerformerChange = function (val: number[],options :PerformerOption[]) { + props.onPerformerChange(options.map((option: any) => { return option.performer})); + setDefaultPerformerId(val); } + + // 收货地址更新 + function handleAddressChange(val: any,option :AddressOption) { + + props.onAddressChange(option.address); + setDefaultAddressId(val); + } + + // 获取用户信息 const fetchInfo = function () { - setUserInfoList([ - { - id: "3", - name: "marun3", - address: "杭州3" - }, - { - id: "4", - name: "marin4", - address: "江苏4" - }, - ]) + post(COMMON_PERFORMER, new ApiParams(), (res) => { + setPerformerList(res.map((item: performerInfo) => { + return { + label:item.name, + value: item.id, + performer : item + } + })); + props.onPerformerChange([res[0]]); + setDefaultPerformerId([res.length > 0 && res[0].id]) + }) + + post(ADDRESS_LIST, new ApiParams(), (res) => { + setAddressList(res.map((item: AddressInfo) => { + return { + label:item.address, + value: item.id, + address : item + } + })); + setDefaultAddressId(res.length > 0 && res[0].id) + }) } + return (
- 观影人: + 观影人    :
收货地址:
diff --git a/src/component/login.tsx b/src/component/login.tsx index ec6d0dd..d58d6eb 100644 --- a/src/component/login.tsx +++ b/src/component/login.tsx @@ -1,9 +1,9 @@ import React from "react"; import {Button, Form, Input, message} from "antd"; import {post} from "../util/http"; -import {LOGIN_PWD} from "../network/request"; import {ApiParams} from "../network/apiParams"; import {store} from "../constant/store"; +import {LOGIN_PWD} from "../network/api/login"; class LoginForm extends React.Component { diff --git a/src/component/search.tsx b/src/component/search.tsx index 6ffd043..552482f 100644 --- a/src/component/search.tsx +++ b/src/component/search.tsx @@ -1,60 +1,53 @@ import React, {useState} from "react"; -import {Button, Card, Input, Select, Form} from "antd"; -// import jsonp from 'reques'; -import qs from 'qs'; +import {Select, Form} from "antd"; +import {post} from "../util/http"; +import {ACTIVITY_DETAIL, ActivityDetail, SEARCH, SearchResult} from "../network/api/search"; +import {ApiParams} from "../network/apiParams"; -const Search: React.FC = () => { - const {Option} = Select; +export type SearchProps = { + activityChange : (value: number) => void +} - let timeout: ReturnType | null; - let currentValue: string; +const Search: React.FC = (props) => { - const fetchData = (value: string, callback: (data: { value: string; text: string }[]) => void) => { - if (timeout) { - clearTimeout(timeout); - timeout = null; - } - currentValue = value; - - const fake = () => { - const str = qs.stringify({ - code: 'utf-8', - q: value, - }); - fetch(`https://suggest.taobao.com/sug?${str}`) - .then((response: any) => response.json()) - .then((d: any) => { - if (currentValue === value) { - const {result} = d; - const data = result.map((item: any) => ({ - value: item[0], - text: item[0], - })); - callback(data); - } - }); - }; + const {Option} = Select; - timeout = setTimeout(fake, 300); + // 演出搜索 + const fetchData = (value: string, callback: (data: any[]) => void) => { + // 判断value 是否是纯数字,纯数字调用activity_detail接口,否则调用activity_search接口 + if (/^\d+$/.test(value)) { + let apiParams = new ApiParams(); + apiParams.set("activityId", value); + post(ACTIVITY_DETAIL, apiParams, (data: ActivityDetail) => { + callback([data]) + }) + } else { + let apiParams = new ApiParams(); + apiParams.set("keyword", value); + apiParams.set("pageNo", 1); + apiParams.set("pageSize", 20); + post(SEARCH, apiParams, (data: SearchResult) => { + callback(data.activityInfo) + }) + } }; const [data, setData] = useState([]); - const [value, setValue] = useState(); + const [value, setValue] = useState(); const handleSearch = (newValue: string) => { if (newValue) { fetchData(newValue, setData); - } else { - setData([]); } }; - const handleChange = (newValue: string) => { + const handleChange = (newValue: number) => { setValue(newValue); + props.activityChange(newValue) }; - const options = data.map(d => ); + const options = data.map(d => ); return ( <> @@ -66,7 +59,6 @@ const Search: React.FC = () => { showSearch value={value} placeholder="搜索" - // style={props.style} defaultActiveFirstOption={false} showArrow={false} filterOption={false} @@ -77,7 +69,6 @@ const Search: React.FC = () => { {options} - ); } diff --git a/src/component/ticket.tsx b/src/component/ticket.tsx index 8fb3e73..36ca457 100644 --- a/src/component/ticket.tsx +++ b/src/component/ticket.tsx @@ -1,22 +1,96 @@ -import React from "react"; -import {Form, Select} from "antd"; +import React, {useEffect, useState} from "react"; +import {Cascader, Form, FormInstance, InputNumber} from "antd"; +import {post} from "../util/http"; +import {TICKET_LIST, TicketInfo, TicketListResult} from "../network/api/ticket"; +import {ApiParams} from "../network/apiParams"; -const Ticket: React.FC = () => { + +export type TicketProps = { + activityId: number | undefined + ticketChange: (tickerInfo: TicketInfo) => void + form: FormInstance +} + +const Ticket: React.FC = (props) => { + const [options, setOptions] = useState([]) + + useEffect(() => { + + if (!props.activityId) { + return; + } + fetchTicket(props.activityId) + }, [props.activityId]) + + + function fetchTicket(activityId: number) { + let apiParams = new ApiParams(); + apiParams.set("activityId", activityId); + post(TICKET_LIST, apiParams, (data: TicketListResult) => { + const newOptions = data.sessions.map((session) => { + return { + value: session.sessionName, + label: session.sessionName, + children: session.ticketList.map((ticket) => { + return { + value: ticket.ticketId, + ticketInfo: ticket, + label: ticket.ticketType + " 库存:" + ticket.remainTicket, + } + }) + } + }) + + // @ts-ignore + setOptions(newOptions) + let defaultTicket = [newOptions[0].value, newOptions[0].children![0].value] + props.form.setFieldsValue({"ticket": defaultTicket}) + props.ticketChange(newOptions[0].children![0].ticketInfo!) + }) + } + + interface Option { + value: number; + label: string; + ticketInfo?: TicketInfo; + children?: Option[]; + } + + + const onChange = (value: any[], option: any) => { + props.ticketChange(option.length > 0 && option[1].ticketInfo!) + }; return ( <> - - + + ); } diff --git a/src/network/api/login.ts b/src/network/api/login.ts new file mode 100644 index 0000000..afe0f5d --- /dev/null +++ b/src/network/api/login.ts @@ -0,0 +1,11 @@ +import {RequestQo} from "../request"; + +//密码登录 +export const LOGIN_PWD: RequestQo = + { + action: "/app/user/login", + bol: false, + type: "REQUEST_QUERY", + uri: "app/000000000000", + prefix: "/app/" + }; diff --git a/src/network/api/order.ts b/src/network/api/order.ts new file mode 100644 index 0000000..320e720 --- /dev/null +++ b/src/network/api/order.ts @@ -0,0 +1,37 @@ +import {RequestQo} from "../request"; + + +// 下单 +export const ORDER_ORDER: RequestQo = + { + action: "/order/order", + bol: false, + type: "REQUEST_QUERY", + uri: "appnj/00000000lcvj", + prefix: "/appnj/" + }; + + +export interface OrderPlaceGoodsBean { + cartId: string + goodsId: number + goodsType: number + num: number + price: number + skuId: string + skuType: number +} + +// 下单结果 +export const ORDER_RESULT: RequestQo = + { + action: "/order/getCoreOrderResult", + bol: false, + type: "REQUEST_QUERY", + uri: "appnj/00000000lcvj", + pathType: "2", + prefix: "/appnj/", + }; + + + diff --git a/src/network/api/search.ts b/src/network/api/search.ts new file mode 100644 index 0000000..8916fd7 --- /dev/null +++ b/src/network/api/search.ts @@ -0,0 +1,171 @@ +import {RequestQo} from "../request"; + + + + export interface ActivityInfo { + activityId: number; + title: string; + activityType: number; + siteName: string; + city: string; + showTime: string; + showStartTime: any; + avatar: string; + price: string; + sellIdentity: number; + isEnd: number; + isTour: number; + leftDay: number; + styles: string[]; + activityPrice: string; + wishCount: number; + styleIds: number[]; + isShowCollection: number; + beginTimeConfirmed: number; + labels: any[]; + couponTicketViews: any[]; + performerName: string; + performerList: string[]; + } + + export interface SearchResult { + activityInfo: ActivityInfo[]; + } + + + +// 搜索列表 +export const SEARCH: RequestQo = + { + action: "/app/activity/search", + bol: false, + type: "REQUEST_QUERY", + uri: "app/00000000lcvj", + prefix: "/app/" + } + + +export interface Site { + id: number; + name: string; + avatar: string; + address: string; + photo: string; + contact: string; + longitude: number; + latitude: number; + cityName: string; + userType: number; +} + +export interface UserInfo { + id: number; + name: string; + avatar: string; + userType: number; + activityRoleType: number; + isCollect: number; +} + +export interface SessionUserInfo { + title: string; + sessionId: number; + selected: number; + isEnd: number; + userInfos: UserInfo[]; +} + +export interface Group { + id: number; + name: string; + avatar: string; + size: number; + joinCount: number; + isJoin: number; + nameEn: string; + desc: string; + joinStatus: number; +} + +export interface GoodsList { + goodsId: number; + goodsName: string; + goodsPoster: string; + bindName: string; + price: string; + buyGroupType: number; +} + +export interface StylesTopic { + id: number; + name: string; +} + +export interface ActivityDetail { + activityId: number; + activityName: string; + price: string; + activityLevel: number; + activityLevelName: string; + showTime: string; + showTimeType: number; + avatar: string; + album: string[]; + document: string; + sellIdentity: number; + activityTag: string; + tags: string; + banner: any[]; + music: any[]; + showLetter: boolean; + letterCount: number; + whetherWantTo: boolean; + wantToNum: number; + site: Site; + host: any[]; + userInfos: any[]; + sessionUserInfos: SessionUserInfo[]; + url: string; + title: string; + showStartTime: number; + showEndTime: number; + group: Group; + goodsList: GoodsList[]; + goodsNum: number; + realName: number; + realNameValidType: number; + shareActivityIds: any[]; + sellTerminal: number; + isShowCollection: number; + serviceTemplateContent: string; + serviceTemplateEnContent: string; + beginTimeConfirmed: number; + notices: any[]; + advertising: any[]; + squadStatus: number; + sellAreaType: number; + serviceTemplates: string[]; + stylesTopic: StylesTopic[]; + isBindHotel: number; + coupons: any[]; + labels: any[]; +} + + +export const ACTIVITY_DETAIL: RequestQo = + { + action: "/app/activity/details", + bol: false, + type: "REQUEST_QUERY", + uri: "app/0h0IuB000000", + prefix: "/app/", + pathType: "17", + } + + + + + + + + diff --git a/src/network/api/ticket.ts b/src/network/api/ticket.ts new file mode 100644 index 0000000..e2c44bd --- /dev/null +++ b/src/network/api/ticket.ts @@ -0,0 +1,57 @@ +import {RequestQo} from "../request"; + + +export interface TicketInfo { + ticketId: string; + ticketType: string; + sellingPrice: number; + costPrice: string; + ticketNum: number; + validateType: number; + time: string; + instruction: string; + countdown: number; + remainTicket: number; + saleStatus: number; + activityId: number; + goodType: number; + telephone: string; + areaCode: string; + limitBuyNum: number; + canBuyNum: number; + cityName: string; + unPayOrderNum: number; + type: number; + buyType: number; + canAddGoods: number; + ticketRecordStatus: number; + startSellNoticeStatus: number; + showRuleTip: boolean; + startTime: any; + showTime: string; + memberNum: number; +} + +export interface Session { + sessionName: string; + sessionId: number; + isConfirmedStartTime: number; + ticketList: TicketInfo[]; +} + +export interface TicketListResult { + sessions: Session[]; + showTime: string; +} + + +// 选票 +export const TICKET_LIST: RequestQo = + { + action: "/app/activity/V2/ticket/list", + bol: false, + type: "REQUEST_QUERY", + uri: "app/0g0IeO00j2rN", + prefix: "/app/", + pathType: "16", + } diff --git a/src/network/api/userInfo.ts b/src/network/api/userInfo.ts new file mode 100644 index 0000000..d8f8639 --- /dev/null +++ b/src/network/api/userInfo.ts @@ -0,0 +1,49 @@ +import {RequestQo} from "../request"; + + +export interface performerInfo { + id: number; + userId: number; + name: string; + documentType: number; + documentTypeStr: string; + showDocumentNumber: string; + isSelf: number; +} + +// 身份信息 +export const COMMON_PERFORMER: RequestQo = + { + action: "/app/commonPerformer/list", + bol: false, + type: "REQUEST_QUERY", + uri: "app/00000000lcvj", + prefix: "/app/" + } + + +export interface AddressInfo { + id: number; + address: string; + postCode: string; + consignee: string; + telephone: string; + isDefault: number; + provinceCode: string; + cityCode: string; + userId: number; + areaCode: string; + createTime: string; + modifyTime: string; + provinceName: string; + cityName: string; +} +// 收货地址 +export const ADDRESS_LIST: RequestQo = + { + action: "/app/address/list", + bol: false, + type: "REQUEST_QUERY", + uri: "app/00000000lcvj", + prefix: "/app/" + } diff --git a/src/network/request.ts b/src/network/request.ts index 0110dfa..ce07ec0 100644 --- a/src/network/request.ts +++ b/src/network/request.ts @@ -1,5 +1,5 @@ // 定义一个新的类型为RequestQo -import {ApiParams, RequestType} from "./apiParams"; +import {RequestType} from "./apiParams"; import {Helpers} from "../util/helpers"; export interface RequestQo { @@ -30,12 +30,3 @@ export const MAKE_TOKEN: RequestQo = prefix : "/app/" } -//密码登录 -export const LOGIN_PWD: RequestQo = - { - action: "/app/user/login", - bol: false, - type: "REQUEST_QUERY", - uri: "app/000000000000", - prefix : "/app/" - }; \ No newline at end of file diff --git a/src/pages/home/index.tsx b/src/pages/home/index.tsx index f9fab41..5901308 100644 --- a/src/pages/home/index.tsx +++ b/src/pages/home/index.tsx @@ -2,24 +2,295 @@ import React from "react"; import LoginForm from "../../component/login"; import {ProCard} from "@ant-design/pro-card"; import ChooseUser from "../../component/chooseUser"; +import Search from "../../component/search"; +import Ticket from "../../component/ticket"; +import Buttons from "../../component/buttons"; +import {Form, message, notification} from "antd"; +import {useForm} from "antd/es/form/Form"; +import {ApiParams} from "../../network/apiParams"; +import {AddressInfo, performerInfo} from "../../network/api/userInfo"; +import {TICKET_LIST, TicketInfo, TicketListResult} from "../../network/api/ticket"; +import {store} from "../../constant/store"; +import {ORDER_ORDER, ORDER_RESULT, OrderPlaceGoodsBean} from "../../network/api/order"; +import {post} from "../../util/http"; -const userChange = (user: string) => { +const Home: React.FC = () => { -} -const Home: React.FC = () => { + + const [activityId, setActivityId] = React.useState(); + const [ticketInfo, setTicketInfo] = React.useState(); + const [performerInfo, setPerformerInfo] = React.useState([]); + const [address, setAddress] = React.useState(); + + + // 捡漏 + const [pickupEnable, setPickupEnable] = React.useState(false); + const [pickupTimer, setPickupTimer] = React.useState(0); + + + // 定时购票 + const [buyTimer, setBuyTimer] = React.useState(0); + const [buyTimerEnable, setBuyTimerEnable] = React.useState(false); + + const [form] = useForm() + + + // 收货地址 + function addressChange(address: AddressInfo) { + setAddress(address) + } + + // 观影人列表 + function performerChange(performers: performerInfo[]) { + setPerformerInfo(performers) + } + + // 演出 + function activityChange(activityId: number) { + setActivityId(activityId) + } + + // 选票 + function ticketChange(ticketInfo: TicketInfo) { + setTicketInfo(ticketInfo) + } + + // 下单信息 + const getOrderRequest = (values: any): ApiParams | void => { + let apiParams = new ApiParams(); + + + if (!ticketInfo) { + message.error("选票错误") + return; + } + + //todo 减去优惠的金额 + let amountPayable = (ticketInfo.sellingPrice) * values.buyCount + + let orderList: OrderPlaceGoodsBean[] = []; + + let orderPlaceGoodsBean: OrderPlaceGoodsBean = { + goodsType: 1, + skuType: 1, + num: values.buyCount, + goodsId: ticketInfo.activityId, + skuId: ticketInfo.ticketId, + cartId: "", + price: ticketInfo.sellingPrice, + } + orderList.push(orderPlaceGoodsBean) + + if (ticketInfo.type == 2 || ticketInfo.type == 3) { + orderPlaceGoodsBean.skuType = ticketInfo.type + } + + + apiParams.set("customerName", address?.consignee ?? "") + apiParams.set("amountPayable", amountPayable) + apiParams.set("totalAmount", (ticketInfo!!.sellingPrice) * values.buyCount) + apiParams.set("source", 0) + apiParams.set("telephone", localStorage.getItem(store.mobile) ?? "") + apiParams.set("orderDetails", orderList) + apiParams.set("areaCode", "86_CN") + apiParams.set("customerRemark", "") + apiParams.set("longitude", 0) + apiParams.set("latitude", 0) + + // 电子票 or 实体票 + if (ticketInfo.type == 2) { + if (!address) { + message.error("实体票请选择收货地址") + return; + } + + apiParams.set("provinceName", address.provinceName); + apiParams.set("cityName", address.cityName); + apiParams.set("address", address.address); + } + + // 实名 + if (ticketInfo.buyType == 2) { + + let performerIds = performerInfo.map((item) => { + return item.id + }) + + if (performerIds.length != values.buyCount) { + message.error("观影人数量选择错误 , 必须与购票数量一致") + return; + } + + apiParams.set("commonPerfomerIds", performerIds); + } + + return apiParams + } + + + // 立即购买 + function buyNow() { + form.validateFields() + .then((values) => { + + let orderRequest = getOrderRequest(values); + if (!orderRequest) { + return; + } + + post(ORDER_ORDER, orderRequest, (data) => { + console.log(data) + let orderJobKey = data.orderJobKey + + + // 查询下单结果 + let resultQuery = new ApiParams(); + resultQuery.set("orderJobKey", orderJobKey) + + post(ORDER_RESULT, resultQuery, function (data) { + if (data == "pending") { + message.error("下单失败 " + data) + return; + } + notification.success({message: "抢票成功:",description : JSON.stringify(data)}) + if (pickupTimer) { + clearInterval(pickupTimer) + setPickupTimer(0) + } + }); + + }, ticketInfo?.ticketId) + + }) + .catch(() => { + }) + ; + } + + // 捡漏 + function buyPickup() { + form.validateFields() + .then((values) => { + + if (!ticketInfo) { + message.error("选票错误") + return; + } + + let orderRequest = getOrderRequest(values); + if (!orderRequest) { + return; + } + + if (pickupTimer) { + // 清除定时器 + clearInterval(pickupTimer) + setPickupTimer(0) + setPickupEnable(false) + return + } + + + setPickupEnable(true) + + // 一秒的定时器 + let newTimer = setInterval(() => { + let apiParams = new ApiParams(); + + apiParams.set("activityId", ticketInfo.activityId) + + post(TICKET_LIST, apiParams, function (data: TicketListResult) { + data.sessions.forEach((session) => { + session.ticketList.forEach((ticket) => { + if (ticket.ticketId == ticketInfo.ticketId && ticket.saleStatus == 1 && ticket.remainTicket > 0) { + buyNow(); + return; + } + }); + }) + }); + + }, 1000) + + setPickupTimer(newTimer) + }) + } + + + + // 定时购票 + function buyTicket() { + + form.validateFields() + .then((values) => { + + if (!ticketInfo) { + message.error("选票错误") + return; + } + + let orderRequest = getOrderRequest(values); + if (!orderRequest) { + return; + } + + if (buyTimer) { + // 清除定时器 + clearInterval(buyTimer) + setBuyTimer(0) + setBuyTimerEnable(false) + return + } + + + setBuyTimerEnable(true) + + let startTime = ticketInfo.startTime; + + + // 一秒的定时器 + let newTimer = setTimeout(() => { + setBuyTimer(0) + setBuyTimerEnable(false) + buyNow() + }, startTime - Date.now() - 100) + + setBuyTimer(newTimer) + }) + } return ( <> - + - + + +
+ + + + + +
+ + ); } diff --git a/src/util/http.ts b/src/util/http.ts index 81244c7..1aee311 100644 --- a/src/util/http.ts +++ b/src/util/http.ts @@ -13,19 +13,27 @@ let baseUrl = 'https://pro2-api.showstart.com' let client = await http.getClient(); const uuid = Helpers.get32RandomID(); +let tokenInit = false; post(MAKE_TOKEN, new ApiParams(), (res) => { localStorage.setItem(store.token, res) + tokenInit = true; }) export function post(requestQo: RequestQo, data: ApiParams, callback: ((res: any) => void), sessionId?: string) { + if (requestQo !== MAKE_TOKEN && !tokenInit) { + setTimeout(() => { + post(requestQo, data, callback, sessionId) + }, 100) + return + } + let request: RequestParams = { action: requestQo.action, z: requestQo.bol, type: requestQo.type, - } let postParams = data.getPostParams(request); @@ -40,8 +48,7 @@ export function post(requestQo: RequestQo, data: ApiParams, callback: ((res: any "CUSUT": Helpers.getSign(), "CUSYSTIME": Helpers.getTimestamp().toString(), } - console.log(headers); - console.log(postParams); + console.log(request); client.post(baseUrl + getUri(requestQo), Body.json(postParams), { headers }).then(res => {