fix(oa): keep page module exports Next-compatible

This commit is contained in:
WuYongJie 2026-08-18 16:39:30 +08:00
parent 8d09d19206
commit 2db8e39666
3 changed files with 169 additions and 160 deletions

View File

@ -0,0 +1,167 @@
import { requireSession } from '@/lib/server-session'
import {
createEmptyOaBoardDashboard,
createMockOaBoardDashboard,
oaBoardService,
} from '@/server/services/oa-board.service'
import { OA_BOARD_DEFAULT_TRACKED_STATUSES } from '@/server/services/oa-board.constants'
import { canViewOaBoardDailyReport } from '@/server/services/oa-board-daily-report-access'
import { readOaBoardLocalPreviewDashboard } from '@/server/services/oa-board-local-preview.service'
import { sampleProgressService } from '@/server/services/sample-progress.service'
import OaBoardClient from './OaBoardClient'
export type OaBoardPageProps = {
searchParams?: Promise<Record<string, string | string[] | undefined>>
}
type OaBoardPageContentProps = OaBoardPageProps & {
embeddedTab?: 'detail'
embeddedTitle?: string
}
export async function OaBoardPageContent({
searchParams,
embeddedTab,
embeddedTitle,
}: OaBoardPageContentProps) {
const allowLocalPreview = process.env.OA_BOARD_LOCAL_PREVIEW === '1'
const session = allowLocalPreview ? null : await requireSession('/login')
const canViewDailyReport = canViewOaBoardDailyReport(session?.authUser)
const params = searchParams ? await searchParams : {}
const readSingleParam = (value: string | string[] | undefined) =>
typeof value === 'string' ? value : ''
const readMultiParam = (value: string | string[] | undefined) =>
(Array.isArray(value) ? value : [value])
.flatMap((entry) => String(entry ?? '').split(','))
.map((entry) => entry.trim())
.filter(Boolean)
const keyword = readSingleParam(params.keyword)
const approvalNumber = readSingleParam(params.approvalNumber)
const overallStatus = readMultiParam(params.overallStatus)
const createdDateStart = readSingleParam(params.createdDateStart)
const createdDateEnd = readSingleParam(params.createdDateEnd)
const productType = readSingleParam(params.productType)
const approvalStage = readSingleParam(params.approvalStage)
const developmentPlan = readSingleParam(params.developmentPlan)
const productPlanner = readSingleParam(params.productPlanner)
const structureDesigner = readSingleParam(params.structureDesigner)
const appearanceDesigner = readSingleParam(params.appearanceDesigner)
const purchaseOwner = readSingleParam(params.purchaseOwner)
const spuOwner = readSingleParam(params.spuOwner)
const owner = readSingleParam(params.owner)
const nodeName = readSingleParam(params.nodeName)
const timeoutOnly = params.timeoutOnly === '1'
const timeoutStatus = readSingleParam(params.timeoutStatus)
const reportDate = readSingleParam(params.reportDate)
const reportMonth = readSingleParam(params.reportMonth)
const loadLiveDashboard = () =>
oaBoardService.getDashboard(
{
keyword: keyword || undefined,
approvalNumber: approvalNumber || undefined,
overallStatus:
overallStatus.length > 0
? overallStatus
: [...OA_BOARD_DEFAULT_TRACKED_STATUSES],
createdDateStart: createdDateStart || undefined,
createdDateEnd: createdDateEnd || undefined,
productType: productType || undefined,
approvalStage: approvalStage || undefined,
developmentPlan: developmentPlan || undefined,
productPlanner: productPlanner || undefined,
structureDesigner: structureDesigner || undefined,
appearanceDesigner: appearanceDesigner || undefined,
purchaseOwner: purchaseOwner || undefined,
spuOwner: spuOwner || undefined,
owner: owner || undefined,
nodeName: nodeName || undefined,
timeoutOnly,
timeoutStatus:
timeoutStatus === 'YES' || timeoutStatus === 'NO'
? timeoutStatus
: undefined,
},
canViewDailyReport ? reportDate || undefined : undefined,
canViewDailyReport ? reportMonth || undefined : undefined,
canViewDailyReport,
)
const resolveDashboard = () =>
loadLiveDashboard()
.then((dashboard) => ({ dashboard, loadErrorMessage: null as string | null }))
.catch((error) => {
const fallbackMessage =
error instanceof Error
? `页面骨架已生成,但读取企划库流程数据失败:${error.message}`
: '页面骨架已生成,但读取企划库流程数据失败。'
const useMockDashboard =
process.env.NODE_ENV !== 'production' ||
process.env.OA_BOARD_LOCAL_PREVIEW === '1'
return {
dashboard: useMockDashboard
? createMockOaBoardDashboard()
: createEmptyOaBoardDashboard(),
loadErrorMessage: useMockDashboard
? `${fallbackMessage} 当前已切换为本地人工验证数据,方便验证流程明细进度。`
: fallbackMessage,
}
})
const result = allowLocalPreview
? await readOaBoardLocalPreviewDashboard()
.then((dashboard) => ({ dashboard, loadErrorMessage: null as string | null }))
.catch(resolveDashboard)
: await resolveDashboard()
const pageStateKey = JSON.stringify({
embeddedTab,
keyword,
approvalNumber,
overallStatus,
createdDateStart,
createdDateEnd,
productType,
approvalStage,
developmentPlan,
productPlanner,
structureDesigner,
appearanceDesigner,
purchaseOwner,
spuOwner,
owner,
nodeName,
timeoutOnly,
timeoutStatus,
reportDate: canViewDailyReport ? reportDate : '',
})
const dashboard = canViewDailyReport
? result.dashboard
: { ...result.dashboard, dailyReport: undefined }
if (!embeddedTab) {
await sampleProgressService.syncFromOaDashboard()
}
const sampleProgressItems = embeddedTab
? []
: await sampleProgressService.listStored()
const currentSampleStageOpeningCodes = embeddedTab
? []
: await sampleProgressService.listCurrentSampleStageOpeningCodes()
return (
<OaBoardClient
key={pageStateKey}
dashboard={dashboard}
loadErrorMessage={result.loadErrorMessage}
sampleProgressItems={sampleProgressItems}
currentSampleStageOpeningCodes={currentSampleStageOpeningCodes}
currentUserName={session?.user.name ?? ''}
embeddedTab={embeddedTab}
embeddedTitle={embeddedTitle}
/>
)
}

View File

@ -1,165 +1,7 @@
import { requireSession } from '@/lib/server-session'
import {
createEmptyOaBoardDashboard,
createMockOaBoardDashboard,
oaBoardService,
} from '@/server/services/oa-board.service'
import { OA_BOARD_DEFAULT_TRACKED_STATUSES } from '@/server/services/oa-board.constants'
import { canViewOaBoardDailyReport } from '@/server/services/oa-board-daily-report-access'
import { readOaBoardLocalPreviewDashboard } from '@/server/services/oa-board-local-preview.service'
import OaBoardClient from './OaBoardClient'
import { sampleProgressService } from '@/server/services/sample-progress.service'
import { OaBoardPageContent, type OaBoardPageProps } from './OaBoardPageContent'
export const dynamic = 'force-dynamic'
type OaBoardPageProps = {
searchParams?: Promise<Record<string, string | string[] | undefined>>
}
type OaBoardPageContentProps = OaBoardPageProps & {
embeddedTab?: 'detail'
embeddedTitle?: string
}
export async function OaBoardPageContent({
searchParams,
embeddedTab,
embeddedTitle,
}: OaBoardPageContentProps) {
const allowLocalPreview = process.env.OA_BOARD_LOCAL_PREVIEW === '1'
const session = allowLocalPreview ? null : await requireSession('/login')
const canViewDailyReport = canViewOaBoardDailyReport(session?.authUser)
const params = searchParams ? await searchParams : {}
const readSingleParam = (value: string | string[] | undefined) =>
typeof value === 'string' ? value : ''
const readMultiParam = (value: string | string[] | undefined) =>
(Array.isArray(value) ? value : [value])
.flatMap((entry) => String(entry ?? '').split(','))
.map((entry) => entry.trim())
.filter(Boolean)
const keyword = readSingleParam(params.keyword)
const approvalNumber = readSingleParam(params.approvalNumber)
const overallStatus = readMultiParam(params.overallStatus)
const createdDateStart = readSingleParam(params.createdDateStart)
const createdDateEnd = readSingleParam(params.createdDateEnd)
const productType = readSingleParam(params.productType)
const approvalStage = readSingleParam(params.approvalStage)
const developmentPlan = readSingleParam(params.developmentPlan)
const productPlanner = readSingleParam(params.productPlanner)
const structureDesigner = readSingleParam(params.structureDesigner)
const appearanceDesigner = readSingleParam(params.appearanceDesigner)
const purchaseOwner = readSingleParam(params.purchaseOwner)
const spuOwner = readSingleParam(params.spuOwner)
const owner = readSingleParam(params.owner)
const nodeName = readSingleParam(params.nodeName)
const timeoutOnly = params.timeoutOnly === '1'
const timeoutStatus = readSingleParam(params.timeoutStatus)
const reportDate = readSingleParam(params.reportDate)
const reportMonth = readSingleParam(params.reportMonth)
const loadLiveDashboard = () =>
oaBoardService.getDashboard(
{
keyword: keyword || undefined,
approvalNumber: approvalNumber || undefined,
overallStatus:
overallStatus.length > 0
? overallStatus
: [...OA_BOARD_DEFAULT_TRACKED_STATUSES],
createdDateStart: createdDateStart || undefined,
createdDateEnd: createdDateEnd || undefined,
productType: productType || undefined,
approvalStage: approvalStage || undefined,
developmentPlan: developmentPlan || undefined,
productPlanner: productPlanner || undefined,
structureDesigner: structureDesigner || undefined,
appearanceDesigner: appearanceDesigner || undefined,
purchaseOwner: purchaseOwner || undefined,
spuOwner: spuOwner || undefined,
owner: owner || undefined,
nodeName: nodeName || undefined,
timeoutOnly,
timeoutStatus: timeoutStatus === 'YES' || timeoutStatus === 'NO' ? timeoutStatus : undefined,
},
canViewDailyReport ? reportDate || undefined : undefined,
canViewDailyReport ? reportMonth || undefined : undefined,
canViewDailyReport,
)
const resolveDashboard = () =>
loadLiveDashboard()
.then((dashboard) => ({ dashboard, loadErrorMessage: null as string | null }))
.catch((error) => {
const fallbackMessage =
error instanceof Error
? `页面骨架已生成,但读取企划库流程数据失败:${error.message}`
: '页面骨架已生成,但读取企划库流程数据失败。'
const useMockDashboard =
process.env.NODE_ENV !== 'production' || process.env.OA_BOARD_LOCAL_PREVIEW === '1'
return {
dashboard: useMockDashboard ? createMockOaBoardDashboard() : createEmptyOaBoardDashboard(),
loadErrorMessage: useMockDashboard
? `${fallbackMessage} 当前已切换为本地人工验证数据,方便验证流程明细进度。`
: fallbackMessage,
}
})
const result = allowLocalPreview
? await readOaBoardLocalPreviewDashboard()
.then((dashboard) => ({ dashboard, loadErrorMessage: null as string | null }))
.catch(resolveDashboard)
: await resolveDashboard()
const pageStateKey = JSON.stringify({
embeddedTab,
keyword,
approvalNumber,
overallStatus,
createdDateStart,
createdDateEnd,
productType,
approvalStage,
developmentPlan,
productPlanner,
structureDesigner,
appearanceDesigner,
purchaseOwner,
spuOwner,
owner,
nodeName,
timeoutOnly,
timeoutStatus,
reportDate: canViewDailyReport ? reportDate : '',
})
const dashboard = canViewDailyReport
? result.dashboard
: { ...result.dashboard, dailyReport: undefined }
if (!embeddedTab) {
await sampleProgressService.syncFromOaDashboard()
}
const sampleProgressItems = embeddedTab ? [] : await sampleProgressService.listStored()
const currentSampleStageOpeningCodes = embeddedTab
? []
: await sampleProgressService.listCurrentSampleStageOpeningCodes()
return (
<OaBoardClient
key={pageStateKey}
dashboard={dashboard}
loadErrorMessage={result.loadErrorMessage}
sampleProgressItems={sampleProgressItems}
currentSampleStageOpeningCodes={currentSampleStageOpeningCodes}
currentUserName={session?.user.name ?? ''}
embeddedTab={embeddedTab}
embeddedTitle={embeddedTitle}
/>
)
}
export default async function OaBoardPage(props: OaBoardPageProps) {
return OaBoardPageContent(props)
}

View File

@ -1,5 +1,5 @@
import { redirect } from 'next/navigation'
import { OaBoardPageContent } from '@/app/intake/oa-board/page'
import { OaBoardPageContent } from '@/app/intake/oa-board/OaBoardPageContent'
import { requireSession } from '@/lib/server-session'
import { supplyChainPermissionSettingsService } from '@/server/services/supply-chain-permission-settings.service'