修复令牌bug

This commit is contained in:
CaIon 2023-11-03 22:38:17 +08:00
parent 9eb8ad6786
commit e06186fe0c
7 changed files with 328 additions and 308 deletions

View File

@ -89,215 +89,217 @@ function App() {
return ( return (
<Layout> <Layout>
<Routes> <Layout.Content>
<Route <Routes>
path='/' <Route
element={ path='/'
<Suspense fallback={<Loading></Loading>}> element={
<Home />
</Suspense>
}
/>
<Route
path='/channel'
element={
<PrivateRoute>
<Channel />
</PrivateRoute>
}
/>
<Route
path='/channel/edit/:id'
element={
<Suspense fallback={<Loading></Loading>}>
<EditChannel />
</Suspense>
}
/>
<Route
path='/channel/add'
element={
<Suspense fallback={<Loading></Loading>}>
<EditChannel />
</Suspense>
}
/>
<Route
path='/token'
element={
<PrivateRoute>
<Token />
</PrivateRoute>
}
/>
<Route
path='/token/edit/:id'
element={
<Suspense fallback={<Loading></Loading>}>
<EditToken />
</Suspense>
}
/>
<Route
path='/token/add'
element={
<Suspense fallback={<Loading></Loading>}>
<EditToken />
</Suspense>
}
/>
<Route
path='/redemption'
element={
<PrivateRoute>
<Redemption />
</PrivateRoute>
}
/>
<Route
path='/redemption/edit/:id'
element={
<Suspense fallback={<Loading></Loading>}>
<EditRedemption />
</Suspense>
}
/>
<Route
path='/redemption/add'
element={
<Suspense fallback={<Loading></Loading>}>
<EditRedemption />
</Suspense>
}
/>
<Route
path='/user'
element={
<PrivateRoute>
<User />
</PrivateRoute>
}
/>
<Route
path='/user/edit/:id'
element={
<Suspense fallback={<Loading></Loading>}>
<EditUser />
</Suspense>
}
/>
<Route
path='/user/edit'
element={
<Suspense fallback={<Loading></Loading>}>
<EditUser />
</Suspense>
}
/>
<Route
path='/user/add'
element={
<Suspense fallback={<Loading></Loading>}>
<AddUser />
</Suspense>
}
/>
<Route
path='/user/reset'
element={
<Suspense fallback={<Loading></Loading>}>
<PasswordResetConfirm />
</Suspense>
}
/>
<Route
path='/login'
element={
<Suspense fallback={<Loading></Loading>}>
<LoginForm />
</Suspense>
}
/>
<Route
path='/register'
element={
<Suspense fallback={<Loading></Loading>}>
<RegisterForm />
</Suspense>
}
/>
<Route
path='/reset'
element={
<Suspense fallback={<Loading></Loading>}>
<PasswordResetForm />
</Suspense>
}
/>
<Route
path='/oauth/github'
element={
<Suspense fallback={<Loading></Loading>}>
<GitHubOAuth />
</Suspense>
}
/>
<Route
path='/setting'
element={
<PrivateRoute>
<Suspense fallback={<Loading></Loading>}> <Suspense fallback={<Loading></Loading>}>
<Setting /> <Home />
</Suspense> </Suspense>
</PrivateRoute> }
} />
/> <Route
<Route path='/channel'
path='/topup' element={
element={ <PrivateRoute>
<PrivateRoute> <Channel />
</PrivateRoute>
}
/>
<Route
path='/channel/edit/:id'
element={
<Suspense fallback={<Loading></Loading>}> <Suspense fallback={<Loading></Loading>}>
<TopUp /> <EditChannel />
</Suspense> </Suspense>
</PrivateRoute> }
} />
/> <Route
<Route path='/channel/add'
path='/log' element={
element={ <Suspense fallback={<Loading></Loading>}>
<PrivateRoute> <EditChannel />
<Log /> </Suspense>
</PrivateRoute> }
} />
/> <Route
<Route path='/token'
path='/midjourney' element={
element={ <PrivateRoute>
<PrivateRoute> <Token />
<Midjourney /> </PrivateRoute>
</PrivateRoute> }
} />
/> <Route
<Route path='/token/edit/:id'
path='/about' element={
element={ <Suspense fallback={<Loading></Loading>}>
<Suspense fallback={<Loading></Loading>}> <EditToken />
<About /> </Suspense>
</Suspense> }
} />
/> <Route
<Route path='/token/add'
path='/chat' element={
element={ <Suspense fallback={<Loading></Loading>}>
<Suspense fallback={<Loading></Loading>}> <EditToken />
<Chat /> </Suspense>
</Suspense> }
} />
/> <Route
<Route path='*' element={ path='/redemption'
<NotFound /> element={
} /> <PrivateRoute>
</Routes> <Redemption />
</PrivateRoute>
}
/>
<Route
path='/redemption/edit/:id'
element={
<Suspense fallback={<Loading></Loading>}>
<EditRedemption />
</Suspense>
}
/>
<Route
path='/redemption/add'
element={
<Suspense fallback={<Loading></Loading>}>
<EditRedemption />
</Suspense>
}
/>
<Route
path='/user'
element={
<PrivateRoute>
<User />
</PrivateRoute>
}
/>
<Route
path='/user/edit/:id'
element={
<Suspense fallback={<Loading></Loading>}>
<EditUser />
</Suspense>
}
/>
<Route
path='/user/edit'
element={
<Suspense fallback={<Loading></Loading>}>
<EditUser />
</Suspense>
}
/>
<Route
path='/user/add'
element={
<Suspense fallback={<Loading></Loading>}>
<AddUser />
</Suspense>
}
/>
<Route
path='/user/reset'
element={
<Suspense fallback={<Loading></Loading>}>
<PasswordResetConfirm />
</Suspense>
}
/>
<Route
path='/login'
element={
<Suspense fallback={<Loading></Loading>}>
<LoginForm />
</Suspense>
}
/>
<Route
path='/register'
element={
<Suspense fallback={<Loading></Loading>}>
<RegisterForm />
</Suspense>
}
/>
<Route
path='/reset'
element={
<Suspense fallback={<Loading></Loading>}>
<PasswordResetForm />
</Suspense>
}
/>
<Route
path='/oauth/github'
element={
<Suspense fallback={<Loading></Loading>}>
<GitHubOAuth />
</Suspense>
}
/>
<Route
path='/setting'
element={
<PrivateRoute>
<Suspense fallback={<Loading></Loading>}>
<Setting />
</Suspense>
</PrivateRoute>
}
/>
<Route
path='/topup'
element={
<PrivateRoute>
<Suspense fallback={<Loading></Loading>}>
<TopUp />
</Suspense>
</PrivateRoute>
}
/>
<Route
path='/log'
element={
<PrivateRoute>
<Log />
</PrivateRoute>
}
/>
<Route
path='/midjourney'
element={
<PrivateRoute>
<Midjourney />
</PrivateRoute>
}
/>
<Route
path='/about'
element={
<Suspense fallback={<Loading></Loading>}>
<About />
</Suspense>
}
/>
<Route
path='/chat'
element={
<Suspense fallback={<Loading></Loading>}>
<Chat />
</Suspense>
}
/>
<Route path='*' element={
<NotFound />
} />
</Routes>
</Layout.Content>
</Layout> </Layout>
); );
} }

View File

@ -71,7 +71,7 @@ const LogsTable = () => {
isAdminUser ? isAdminUser ?
record.type === 0 || record.type === 2 ? record.type === 0 || record.type === 2 ?
<div> <div>
{<Tag color={stringToColor(text)} size='large'> {text} </Tag>} {<Tag color={colors[parseInt(text) % colors.length]} size='large'> {text} </Tag>}
</div> </div>
: :
<></> <></>

View File

@ -187,21 +187,21 @@ const TokensTable = () => {
const closeEdit = () => { const closeEdit = () => {
setShowEdit(false); setShowEdit(false);
setEditingToken({ // setEditingToken({
id: undefined, // id: undefined,
}); // });
} }
const setTokensFormat = (tokens) => { const setTokensFormat = (tokens) => {
setTokens(tokens); setTokens(tokens);
if (tokens.length === ITEMS_PER_PAGE) { if (tokens.length >= ITEMS_PER_PAGE) {
setTokenCount(tokens.length + ITEMS_PER_PAGE); setTokenCount(tokens.length + ITEMS_PER_PAGE);
} else { } else {
setTokenCount(tokens.length); setTokenCount(tokens.length);
} }
} }
// let pageData = tokens.slice((activePage - 1) * ITEMS_PER_PAGE, activePage * ITEMS_PER_PAGE); let pageData = tokens.slice((activePage - 1) * ITEMS_PER_PAGE, activePage * ITEMS_PER_PAGE);
const loadTokens = async (startIdx) => { const loadTokens = async (startIdx) => {
setLoading(true); setLoading(true);
const res = await API.get(`/api/token/?p=${startIdx}`); const res = await API.get(`/api/token/?p=${startIdx}`);
@ -450,11 +450,12 @@ const TokensTable = () => {
onClick={searchTokens} style={{marginRight: 8}}>查询</Button> onClick={searchTokens} style={{marginRight: 8}}>查询</Button>
</Form> </Form>
<Table style={{marginTop: 20}} columns={columns} dataSource={tokens} pagination={{ <Table style={{marginTop: 20}} columns={columns} dataSource={pageData} pagination={{
currentPage: activePage, currentPage: activePage,
pageSize: ITEMS_PER_PAGE, pageSize: ITEMS_PER_PAGE,
total: tokenCount, total: tokenCount,
pageSizeOpts: [10, 20, 50, 100], showSizeChanger: true,
pageSizeOptions: [10, 20, 50, 100],
onPageChange: handlePageChange, onPageChange: handlePageChange,
}} loading={loading} rowSelection={rowSelection}> }} loading={loading} rowSelection={rowSelection}>
</Table> </Table>

View File

@ -8,6 +8,15 @@ body {
scrollbar-width: none; scrollbar-width: none;
color: var(--semi-color-text-0) !important; color: var(--semi-color-text-0) !important;
background-color: var( --semi-color-bg-0) !important; background-color: var( --semi-color-bg-0) !important;
height: 100%;
}
#root {
height: 100%;
}
.semi-layout {
height: 100%;
} }
.tableShow { .tableShow {
@ -40,7 +49,7 @@ code {
/*display: flex;*/ /*display: flex;*/
/*flex-direction: column;*/ /*flex-direction: column;*/
/*width: 100%;*/ /*width: 100%;*/
height: 100vh; height: 100%;
overflow: hidden; overflow: hidden;
} }

View File

@ -22,7 +22,6 @@ root.render(
<UserProvider> <UserProvider>
<BrowserRouter> <BrowserRouter>
<Layout> <Layout>
<Sider> <Sider>
<SiderBar/> <SiderBar/>
</Sider> </Sider>
@ -37,11 +36,12 @@ root.render(
> >
<App/> <App/>
</Content> </Content>
<Footer></Footer> {/*<Layout.Footer>*/}
{/* <Footer></Footer>*/}
{/*</Layout.Footer>*/}
</Layout> </Layout>
<ToastContainer/>
</Layout> </Layout>
<ToastContainer/>
{/*<Footer />*/}
</BrowserRouter> </BrowserRouter>
</UserProvider> </UserProvider>
</StatusProvider> </StatusProvider>

View File

@ -112,6 +112,7 @@ const EditToken = (props) => {
return ( return (
<> <>
<SideSheet <SideSheet
placement={isEdit ? 'right' : 'left'}
title={<Title level={3}>{isEdit ? '更新令牌信息' : '创建新的令牌'}</Title>} title={<Title level={3}>{isEdit ? '更新令牌信息' : '创建新的令牌'}</Title>}
headerStyle={{borderBottom: '1px solid var(--semi-color-border)'}} headerStyle={{borderBottom: '1px solid var(--semi-color-border)'}}
bodyStyle={{borderBottom: '1px solid var(--semi-color-border)'}} bodyStyle={{borderBottom: '1px solid var(--semi-color-border)'}}

View File

@ -1,7 +1,8 @@
import React, {useEffect, useState} from 'react'; import React, {useEffect, useState} from 'react';
import {Button, Confirm, Form, Grid, Header, Segment, Statistic} from 'semantic-ui-react'; import {Button, Card, Confirm, Form, Grid, Header, Segment, Statistic} from 'semantic-ui-react';
import {API, showError, showInfo, showSuccess} from '../../helpers'; import {API, isMobile, showError, showInfo, showSuccess} from '../../helpers';
import {renderNumber, renderQuota} from '../../helpers/render'; import {renderNumber, renderQuota} from '../../helpers/render';
import {Col, Layout, Row, Typography} from "@douyinfe/semi-ui";
const TopUp = () => { const TopUp = () => {
const [redemptionCode, setRedemptionCode] = useState(''); const [redemptionCode, setRedemptionCode] = useState('');
@ -162,95 +163,101 @@ const TopUp = () => {
return ( return (
<div> <div>
<Segment> <Layout>
<Confirm <Layout.Header>
open={open} <h3>我的钱包</h3>
content={'充值数量:' + topUpCount + ',充值金额:' + renderAmount() + ',是否确认充值?'} </Layout.Header>
cancelButton='取消充值' <Layout.Content>
confirmButton="确定" <div style={{marginTop: 20, paddingLeft: isMobile()?0:200, paddingRight: isMobile()?0:200}}>
onCancel={handleCancel} <Card
onConfirm={onlineTopUp} style={{width: '100%', padding: '20px'}}
/> >
<Header as='h3'>充值额度</Header> <Confirm
<Grid columns={2} stackable> open={open}
<Grid.Column> content={'充值数量:' + topUpCount + ',充值金额:' + renderAmount() + ',是否确认充值?'}
<Form> cancelButton='取消充值'
<Form.Input confirmButton="确定"
placeholder='兑换码' onCancel={handleCancel}
name='redemptionCode' onConfirm={onlineTopUp}
value={redemptionCode}
onChange={(e) => {
setRedemptionCode(e.target.value);
}}
/> />
<Button color='green' onClick={openTopUpLink}> <h3>兑换</h3>
获取兑换码 <Grid columns={2} stackable>
</Button> <Grid.Column>
<Button color='yellow' onClick={topUp} disabled={isSubmitting}> <Form>
{isSubmitting ? '兑换中...' : '兑换'} <Form.Input
</Button> placeholder='兑换码'
</Form> name='redemptionCode'
</Grid.Column> value={redemptionCode}
<Grid.Column> onChange={(e) => {
<Statistic.Group widths='one'> setRedemptionCode(e.target.value);
<Statistic> }}
<Statistic.Value>{renderQuota(userQuota)}</Statistic.Value> />
<Statistic.Label>剩余额度</Statistic.Label> <Button color='green' onClick={openTopUpLink}>
</Statistic> 获取兑换码
</Statistic.Group> </Button>
</Grid.Column> <Button color='yellow' onClick={topUp} disabled={isSubmitting}>
</Grid> {isSubmitting ? '兑换中...' : '兑换'}
</Segment> </Button>
<Segment> </Form>
<Header as='h3'>在线充值最低1</Header> </Grid.Column>
<Grid columns={2} stackable> <Grid.Column>
<Grid.Column> <Statistic.Group widths='one'>
<Form> <Statistic>
<Form.Input <Statistic.Value>{renderQuota(userQuota)}</Statistic.Value>
placeholder='充值金额最低1' <Statistic.Label>剩余额度</Statistic.Label>
name='redemptionCount' </Statistic>
type={'number'} </Statistic.Group>
value={topUpCount} </Grid.Column>
autoComplete={'off'} </Grid>
onChange={async (e) => { </Card>
setTopUpCount(e.target.value); <Card
await getAmount(e.target.value); style={{width: '100%', padding: '20px'}}
}} >
/> <Header as='h3'>在线充值最低1</Header>
{/*<Form.Input*/} <Grid columns={2} stackable>
{/* placeholder='充值码,如果你没有充值码,可不填写'*/} <Grid.Column>
{/* name='redemptionCount'*/} <Form>
{/* value={topUpCode}*/} <Form.Input
{/* onChange={(e) => {*/} placeholder='充值金额最低1'
{/* setTopUpCode(e.target.value);*/} name='redemptionCount'
{/* }}*/} type={'number'}
{/*/>*/} value={topUpCount}
<Button color='blue' onClick={ autoComplete={'off'}
async () => { onChange={async (e) => {
preTopUp('zfb') setTopUpCount(e.target.value);
} await getAmount(e.target.value);
}> }}
支付宝 />
</Button> <Button color='blue' onClick={
<Button color='green' onClick={ async () => {
async () => { preTopUp('zfb')
preTopUp('wx') }
} }>
}> 支付宝
微信 </Button>
</Button> <Button color='green' onClick={
</Form> async () => {
</Grid.Column> preTopUp('wx')
<Grid.Column> }
<Statistic.Group widths='one'> }>
<Statistic> 微信
<Statistic.Value>{renderAmount()}</Statistic.Value> </Button>
<Statistic.Label>支付金额</Statistic.Label> </Form>
</Statistic> </Grid.Column>
</Statistic.Group> <Grid.Column>
</Grid.Column> <Statistic.Group widths='one'>
</Grid> <Statistic>
</Segment> <Statistic.Value>{renderAmount()}</Statistic.Value>
<Statistic.Label>支付金额</Statistic.Label>
</Statistic>
</Statistic.Group>
</Grid.Column>
</Grid>
</Card>
</div>
</Layout.Content>
</Layout>
</div> </div>
); );