Skip to content

Commit 13d0e6a

Browse files
committed
show quota
1 parent 06dab07 commit 13d0e6a

File tree

6 files changed

+82
-10
lines changed

6 files changed

+82
-10
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "pushy-admin",
33
"private": true,
44
"scripts": {
5-
"dev": "PUBLIC_API=https://update.reactnative.cn/api rsbuild dev",
5+
"dev": "PUBLIC_API=https://5.rnupdate.online/api rsbuild dev",
66
"dev:local": "PUBLIC_API=http://localhost:9000 rsbuild dev",
77
"build": "NODE_ENV=production rsbuild build",
88
"preview": "rsbuild preview",

src/components/sider.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ export default function Sider() {
130130
const SiderMenu = ({ selectedKeys }: SiderMenuProps) => {
131131
const { user, displayExpireDay, displayRemainingDays } = useUserInfo();
132132
const { apps } = useAppList();
133-
const quota = quotas[user?.tier as keyof typeof quotas];
133+
const quota = user.quota || quotas[user?.tier as keyof typeof quotas];
134134
const pvQuota = quota?.pv;
135135
const consumedQuota = user?.checkQuota;
136136
const percent =

src/constants/quotas.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,4 @@ export const quotas = {
6262
bundleSize: '200m',
6363
pv: 100000000,
6464
},
65-
};
65+
} as const;

src/pages/user.tsx

Lines changed: 60 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
import { AlipayCircleOutlined } from '@ant-design/icons';
22
import type { MenuProps } from 'antd';
3-
import { Button, Descriptions, Dropdown, Popover, Space, Spin } from 'antd';
3+
import {
4+
Button,
5+
Descriptions,
6+
Dropdown,
7+
message,
8+
Popover,
9+
Space,
10+
Spin,
11+
} from 'antd';
412
import { type ReactNode, useState } from 'react';
513
import { api } from '@/services/api';
614
import { useUserInfo } from '@/utils/hooks';
@@ -38,6 +46,9 @@ const PurchaseButton = ({
3846
className="ml-6"
3947
icon={<AlipayCircleOutlined />}
4048
onClick={async () => {
49+
if (tier === 'custom') {
50+
return message.error('定制版用户付费请联系客服');
51+
}
4152
setLoading(true);
4253
await purchase(tier);
4354
}}
@@ -122,8 +133,39 @@ function UserPanel() {
122133
</div>
123134
);
124135
}
125-
const { name, email, tier } = user;
126-
const currentQuota = quotas[tier as keyof typeof quotas];
136+
const { name, email, tier, quota } = user;
137+
const defaultQuota = quotas[tier as keyof typeof quotas];
138+
const currentQuota = quota || defaultQuota;
139+
140+
const tierDisplay = currentQuota.title;
141+
const quotaTableData = [
142+
{ key: 'app', item: '应用数量', value: `${currentQuota.app} 个` },
143+
{
144+
key: 'package',
145+
item: '每个应用原生包数量',
146+
value: `${currentQuota.package} 个`,
147+
},
148+
{
149+
key: 'packageSize',
150+
item: '单个原生包大小',
151+
value: currentQuota.packageSize,
152+
},
153+
{
154+
key: 'bundle',
155+
item: '每个应用热更包数量',
156+
value: `${currentQuota.bundle} 个`,
157+
},
158+
{
159+
key: 'bundleSize',
160+
item: '单个热更包大小',
161+
value: currentQuota.bundleSize,
162+
},
163+
{
164+
key: 'pv',
165+
item: '每日总查询次数',
166+
value: `${currentQuota.pv.toLocaleString()} 次`,
167+
},
168+
];
127169
return (
128170
<div className="body">
129171
<Descriptions
@@ -136,8 +178,10 @@ function UserPanel() {
136178
<Descriptions.Item label="邮箱">{email}</Descriptions.Item>
137179
<Descriptions.Item label="服务版本">
138180
<Space>
139-
{currentQuota.title}
140-
<UpgradeDropdown currentQuota={currentQuota} />
181+
{tierDisplay}
182+
{!quota && defaultQuota && (
183+
<UpgradeDropdown currentQuota={defaultQuota} />
184+
)}
141185
</Space>
142186
</Descriptions.Item>
143187
<Descriptions.Item label="服务有效期至">
@@ -165,6 +209,17 @@ function UserPanel() {
165209
)}
166210
</Space>
167211
</Descriptions.Item>
212+
<Descriptions.Item label="额度详情">
213+
{quotaTableData.map(({ key, item, value }) => (
214+
<div key={key}>
215+
{item}{value} <br />
216+
</div>
217+
))}
218+
<div className="h-px my-4 w-md bg-gray-300" />
219+
<div className="text-xm text-gray-500">
220+
如有定制需求(限高级版以上),请联系 QQ 客服 34731408
221+
</div>
222+
</Descriptions.Item>
168223
</Descriptions>
169224
<br />
170225
<Button href={PRICING_LINK} target="_blank">

src/types.d.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,28 @@ declare module '*.jpg' {
1313
export default content;
1414
}
1515

16+
type Tier = 'free' | 'standard' | 'premium' | 'pro' | 'custom';
17+
1618
interface User {
1719
email: string;
1820
id: number;
1921
name: string;
20-
tier: 'free' | 'standard' | 'premium' | 'pro';
22+
tier: Tier;
2123
tierExpiresAt?: string;
2224
checkQuota?: number;
2325
last7dAvg?: number;
26+
quota?: Quota;
27+
}
28+
29+
export interface Quota {
30+
base?: Exclude<Tier, 'custom'>;
31+
app: number;
32+
package: number;
33+
packageSize: string;
34+
bundle: number;
35+
bundleSize: string;
36+
pv: number;
37+
price?: number;
2438
}
2539

2640
interface App {
@@ -115,6 +129,6 @@ interface AuditLog {
115129
userAgent?: string;
116130
apiTokens?: {
117131
tokenSuffix: string;
118-
}
132+
};
119133
createdAt: string;
120134
}

src/utils/hooks.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ export const useUserInfo = () => {
2626
const displayRemainingDays = isExpiringSoon
2727
? `(剩余 ${remainingDays} 天,之后转为免费版)`
2828
: '';
29+
if (data?.tier === 'custom') {
30+
data.quota.title = '定制版';
31+
}
2932
return {
3033
user: getToken() ? data : null,
3134
displayExpireDay,

0 commit comments

Comments
 (0)