diff --git a/apps/server/src/trpc/trpc.router.ts b/apps/server/src/trpc/trpc.router.ts index 783a33b..202d333 100644 --- a/apps/server/src/trpc/trpc.router.ts +++ b/apps/server/src/trpc/trpc.router.ts @@ -51,7 +51,9 @@ export class TrpcRouter { nextCursor = nextItem.id; } + const disabledAccounts = this.trpcService.getBlockedAccountIds(); return { + blocks: disabledAccounts, items, nextCursor, }; diff --git a/apps/server/src/trpc/trpc.service.ts b/apps/server/src/trpc/trpc.service.ts index e843c05..86802a8 100644 --- a/apps/server/src/trpc/trpc.service.ts +++ b/apps/server/src/trpc/trpc.service.ts @@ -91,16 +91,20 @@ export class TrpcService { return dayjs.tz(new Date(), 'Asia/Shanghai').format('YYYY-MM-DD'); } - private async getAvailableAccount() { + getBlockedAccountIds() { const today = this.getTodayDate(); const disabledAccounts = blockedAccountsMap.get(today) || []; this.logger.debug('disabledAccounts: ', disabledAccounts); + return disabledAccounts.filter(Boolean); + } + private async getAvailableAccount() { + const disabledAccounts = this.getBlockedAccountIds(); const account = await this.prismaService.account.findFirst({ where: { status: statusMap.ENABLE, NOT: { - id: { in: disabledAccounts.filter(Boolean) }, + id: { in: disabledAccounts }, }, }, }); diff --git a/apps/web/src/components/StatusDropdown.tsx b/apps/web/src/components/StatusDropdown.tsx index 0d2fa21..10c0f96 100644 --- a/apps/web/src/components/StatusDropdown.tsx +++ b/apps/web/src/components/StatusDropdown.tsx @@ -6,12 +6,7 @@ import { DropdownItem, Button, } from '@nextui-org/react'; - -const statusMap = { - 0: '失效', - 1: '启用', - 2: '禁用', -}; +import { statusMap } from '@web/constants'; export function StatusDropdown({ value = 1, @@ -24,7 +19,7 @@ export function StatusDropdown({ - {Object.entries(statusMap).map(([value, label]) => { + {Object.entries(statusMap).map(([key, value]) => { return ( - - {label} + + {value.label} ); })} diff --git a/apps/web/src/constants.ts b/apps/web/src/constants.ts new file mode 100644 index 0000000..ca2f21e --- /dev/null +++ b/apps/web/src/constants.ts @@ -0,0 +1,5 @@ +export const statusMap = { + 0: { label: '失效', color: 'danger' }, + 1: { label: '启用', color: 'success' }, + 2: { label: '禁用', color: 'warning' }, +} as const; diff --git a/apps/web/src/pages/accounts/index.tsx b/apps/web/src/pages/accounts/index.tsx index 1923c2f..2275ed8 100644 --- a/apps/web/src/pages/accounts/index.tsx +++ b/apps/web/src/pages/accounts/index.tsx @@ -12,6 +12,7 @@ import { TableColumn, TableHeader, TableRow, + Chip, } from '@nextui-org/react'; import { QRCodeSVG } from 'qrcode.react'; import { toast } from 'sonner'; @@ -19,6 +20,7 @@ import { PlusIcon } from '@web/components/PlusIcon'; import dayjs from 'dayjs'; import { StatusDropdown } from '@web/components/StatusDropdown'; import { trpc } from '@web/utils/trpc'; +import { statusMap } from '@web/constants'; const AccountPage = () => { const { isOpen, onOpen, onClose, onOpenChange } = useDisclosure(); @@ -97,11 +99,32 @@ const AccountPage = () => { loadingContent={} > {data?.items.map((item) => { + const isBlocked = data?.blocks.includes(item.id); + return ( {item.id} {item.name} + {isBlocked ? ( + + 今日小黑屋 + + ) : ( + + {statusMap[item.status].label} + + )} + + + {dayjs(item.updatedAt).format('YYYY-MM-DD')} + + { @@ -114,11 +137,7 @@ const AccountPage = () => { }); }} > - - - {dayjs(item.updatedAt).format('YYYY-MM-DD')} - - +