解决我的账单页面报错 & 提交记录添加套餐号筛选
This commit is contained in:
@@ -3,6 +3,11 @@ import {PageRecord} from '@/lib/api'
|
||||
import {Batch} from '@/lib/models/batch'
|
||||
import {callByUser} from './base'
|
||||
|
||||
export async function pageBatch(props: {page: number, size: number}) {
|
||||
export async function pageBatch(props: {
|
||||
page: number
|
||||
size: number
|
||||
time_start?: Date
|
||||
time_end?: Date
|
||||
resource_no?: string}) {
|
||||
return callByUser<PageRecord<Batch>>('/api/batch/page', props)
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
'use client'
|
||||
import {useCallback, useEffect, useState} from 'react'
|
||||
import {Suspense, useCallback, useEffect, useState} from 'react'
|
||||
import {PageRecord} from '@/lib/api'
|
||||
import {Bill} from '@/lib/models'
|
||||
import {useStatus} from '@/lib/states'
|
||||
@@ -141,6 +141,7 @@ export default function BillsPage(props: BillsPageProps) {
|
||||
</Form>
|
||||
</section>
|
||||
|
||||
<Suspense>
|
||||
<DataTable
|
||||
data={data.list}
|
||||
status={status}
|
||||
@@ -273,26 +274,26 @@ export default function BillsPage(props: BillsPageProps) {
|
||||
<span>手机网站</span>
|
||||
</>
|
||||
) : (
|
||||
<span>-</span>
|
||||
<></>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
},
|
||||
},
|
||||
{
|
||||
accessorKey: 'created_at', header: '创建时间', cell: ({row}) => (
|
||||
format(new Date(row.original.created_at), 'yyyy-MM-dd HH:mm:ss')
|
||||
),
|
||||
accessorKey: 'created_at',
|
||||
header: '创建时间',
|
||||
cell: ({row}) => {
|
||||
const createdAt = row.original.created_at
|
||||
if (!createdAt) return <span></span>
|
||||
const date = new Date(createdAt)
|
||||
if (isNaN(date.getTime())) return <span></span>
|
||||
return format(date, 'yyyy-MM-dd HH:mm:ss')
|
||||
},
|
||||
},
|
||||
// {
|
||||
// accessorKey: 'action', header: `操作`, cell: item => (
|
||||
// <div className="flex gap-2">
|
||||
// -
|
||||
// </div>
|
||||
// ),
|
||||
// },
|
||||
]}
|
||||
/>
|
||||
</Suspense>
|
||||
</Page>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -93,7 +93,6 @@ export default function ChannelsPage(props: ChannelsPageProps) {
|
||||
// ======================
|
||||
// render
|
||||
// ======================
|
||||
console.log(data.list, 'data.listdata.list')
|
||||
|
||||
return (
|
||||
<Page>
|
||||
@@ -215,11 +214,35 @@ export default function ChannelsPage(props: ChannelsPageProps) {
|
||||
},
|
||||
{
|
||||
header: '提取时间',
|
||||
cell: ({row}) => format(row.original.created_at, 'yyyy-MM-dd HH:mm:ss'),
|
||||
cell: ({row}) => {
|
||||
const timeValue = row.original.created_at
|
||||
if (!timeValue) return <div>-</div>
|
||||
|
||||
try {
|
||||
const date = new Date(timeValue)
|
||||
if (isNaN(date.getTime())) return <div>-</div>
|
||||
return <div>{format(date, 'yyyy-MM-dd HH:mm:ss')}</div>
|
||||
}
|
||||
catch {
|
||||
return <div>-</div>
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
header: '过期时间',
|
||||
cell: ({row}) => format(row.original.expired_at, 'yyyy-MM-dd HH:mm:ss'),
|
||||
cell: ({row}) => {
|
||||
const timeValue = row.original.expired_at
|
||||
if (!timeValue) return <div>-</div>
|
||||
|
||||
try {
|
||||
const date = new Date(timeValue)
|
||||
if (isNaN(date.getTime())) return <div>-</div>
|
||||
return <div>{format(date, 'yyyy-MM-dd HH:mm:ss')}</div>
|
||||
}
|
||||
catch {
|
||||
return <div>-</div>
|
||||
}
|
||||
},
|
||||
},
|
||||
]}
|
||||
/>
|
||||
|
||||
@@ -15,6 +15,7 @@ import DatePicker from '@/components/date-picker'
|
||||
import {Button} from '@/components/ui/button'
|
||||
import {EraserIcon, SearchIcon} from 'lucide-react'
|
||||
import {pageBatch} from '@/actions/batch'
|
||||
import {Input} from '@/components/ui/input'
|
||||
|
||||
export type RecordPageProps = {}
|
||||
|
||||
@@ -34,6 +35,7 @@ export default function RecordPage(props: RecordPageProps) {
|
||||
const filterSchema = z.object({
|
||||
time_start: z.date().optional(),
|
||||
time_end: z.date().optional(),
|
||||
resource_no: z.string().optional(),
|
||||
})
|
||||
type FilterSchema = z.infer<typeof filterSchema>
|
||||
|
||||
@@ -42,6 +44,7 @@ export default function RecordPage(props: RecordPageProps) {
|
||||
defaultValues: {
|
||||
time_start: undefined,
|
||||
time_end: undefined,
|
||||
resource_no: '',
|
||||
},
|
||||
})
|
||||
|
||||
@@ -53,7 +56,9 @@ export default function RecordPage(props: RecordPageProps) {
|
||||
const result = await pageBatch({
|
||||
page,
|
||||
size,
|
||||
...filter,
|
||||
time_start: filter.time_start,
|
||||
time_end: filter.time_end,
|
||||
resource_no: filter.resource_no || undefined,
|
||||
})
|
||||
|
||||
if (result.success && result.data) {
|
||||
@@ -88,12 +93,22 @@ export default function RecordPage(props: RecordPageProps) {
|
||||
<section className="flex justify-between">
|
||||
<div></div>
|
||||
<Form form={filterForm} handler={filterHandler} className="flex-auto flex flex-wrap gap-4 items-end">
|
||||
<FormField name="resource_no" label={<span className="text-sm">套餐编号</span>}>
|
||||
{({id, field}) => (
|
||||
<Input
|
||||
{...field}
|
||||
id={id}
|
||||
className="h-9"
|
||||
value={field.value ?? ''}
|
||||
/>
|
||||
)}
|
||||
</FormField>
|
||||
<fieldset className="flex flex-col gap-2 items-start">
|
||||
<div>
|
||||
<legend className="block text-sm">提取时间</legend>
|
||||
<legend className="block text-sm">过期时间</legend>
|
||||
</div>
|
||||
<div className="flex gap-1 items-center">
|
||||
<FormField<FilterSchema, 'time_start'> name="time_start">
|
||||
<FormField<FilterSchema, 'time_start'> name="time_start" >
|
||||
{({field}) => (
|
||||
<DatePicker
|
||||
placeholder="选择开始时间"
|
||||
@@ -144,6 +159,10 @@ export default function RecordPage(props: RecordPageProps) {
|
||||
onSizeChange: size => fetchRecords(1, size),
|
||||
}}
|
||||
columns={[
|
||||
{
|
||||
header: '套餐编号',
|
||||
accessorKey: 'resource.resource_no',
|
||||
},
|
||||
{
|
||||
header: '批次号',
|
||||
cell: ({row}) => <div>{row.original.batch_no}</div>,
|
||||
@@ -174,11 +193,6 @@ export default function RecordPage(props: RecordPageProps) {
|
||||
cell: ({row}) => <div>{row.original.count}</div>,
|
||||
accessorKey: 'count',
|
||||
},
|
||||
// {
|
||||
// header: '资源数量',
|
||||
// cell: ({row}) => <div>{row.original.resource_id}</div>,
|
||||
// accessorKey: 'resource_id',
|
||||
// },
|
||||
{
|
||||
header: '提取时间',
|
||||
cell: ({row}) => {
|
||||
|
||||
@@ -186,7 +186,7 @@ export default function ResourceList({resourceType}: ResourceListProps) {
|
||||
const live = resourceKey === 'long'
|
||||
? (row.original as Resource<2>).long.live
|
||||
: (row.original as Resource<1>).short.live
|
||||
return <span>{isLong ? `${live}小时` : `${live}分钟`}</span>
|
||||
return <span>{isLong ? `${live}分钟` : `${live}分钟`}</span>
|
||||
},
|
||||
},
|
||||
{
|
||||
|
||||
@@ -73,20 +73,6 @@ export default function Extract(props: ExtractProps) {
|
||||
)}
|
||||
>
|
||||
<CardSection>
|
||||
{/* <Alert variant="warn" className="flex items-center justify-between">
|
||||
<span className="flex items-center gap-2">
|
||||
<CircleAlert/>
|
||||
<AlertTitle className="flex text-gray-900">提取IP前需要将本机IP添加到白名单后才可使用</AlertTitle>
|
||||
</span>
|
||||
<Link
|
||||
href="/admin/whitelist"
|
||||
className="flex-none text-orange-600 font-medium ml-2 flex gap-0.5 items-center"
|
||||
>
|
||||
<span>添加白名单</span>
|
||||
<ArrowRight className="size-4"/>
|
||||
</Link>
|
||||
</Alert> */}
|
||||
|
||||
<FormFields/>
|
||||
</CardSection>
|
||||
|
||||
@@ -516,8 +502,6 @@ function SelectRegion() {
|
||||
const regionType = useWatch({control, name: 'regionType'})
|
||||
const prov = useWatch({control, name: 'prov'})
|
||||
const city = useWatch({control, name: 'city'})
|
||||
console.log(regionType, 'regionType')
|
||||
console.log(prov, 'prov', city, 'city')
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-4 md:max-w-[calc(160px*2+1rem)]">
|
||||
@@ -696,9 +680,9 @@ function name(resource: Resource) {
|
||||
// 短效套餐
|
||||
switch (resource.short.type) {
|
||||
case 1:
|
||||
return `短效包时 ${resource.short.live} 分钟`
|
||||
return `${resource.short?.sku?.name}`
|
||||
case 2:
|
||||
return `短效包量 ${resource.short.live} 分钟`
|
||||
return `${resource.short?.sku?.name}`
|
||||
}
|
||||
break
|
||||
|
||||
@@ -706,9 +690,9 @@ function name(resource: Resource) {
|
||||
// 长效套餐
|
||||
switch (resource.long.type) {
|
||||
case 1:
|
||||
return `长效包时 ${resource.long.live} 小时`
|
||||
return `${resource.long?.sku?.name}`
|
||||
case 2:
|
||||
return `长效包量 ${resource.long.live} 小时`
|
||||
return `${resource.long?.sku?.name}`
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
@@ -185,10 +185,7 @@ function usePurchasePrice(profile: User | null, selection: PurchaseSelection) {
|
||||
return
|
||||
}
|
||||
|
||||
if (!response.success) {
|
||||
throw new Error(response.message || '获取价格失败')
|
||||
}
|
||||
|
||||
if (response.success) {
|
||||
setPriceData({
|
||||
price: response.data.price,
|
||||
actual: response.data.actual ?? response.data.price ?? '0.00',
|
||||
@@ -196,6 +193,7 @@ function usePurchasePrice(profile: User | null, selection: PurchaseSelection) {
|
||||
})
|
||||
setIsError(false)
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
if (requestId !== requestIdRef.current) {
|
||||
return
|
||||
|
||||
@@ -8,6 +8,11 @@ type ResourceShort = {
|
||||
used: number
|
||||
daily: number
|
||||
last_at?: Date
|
||||
sku?: sku
|
||||
}
|
||||
|
||||
type sku = {
|
||||
name: string
|
||||
}
|
||||
|
||||
type ResourceLong = {
|
||||
@@ -20,6 +25,7 @@ type ResourceLong = {
|
||||
used: number
|
||||
daily: number
|
||||
last_at?: Date
|
||||
sku?: sku
|
||||
}
|
||||
|
||||
export type Resource<T extends 1 | 2 = 1 | 2> = {
|
||||
|
||||
Reference in New Issue
Block a user