constant.ts
Overview
The constant.ts file serves as a centralized mapping and export module for running status constants used throughout the application. It imports an enumeration of running statuses from a knowledge base module (@/constants/knowledge) and defines a corresponding mapping object, RunningStatusMap, which associates each status with a user-friendly label and a color code. This mapping is useful for UI components or services that need to display status information with consistent text and color styling.
Additionally, this file re-exports all exports from the @/constants/knowledge module, effectively making it a pass-through module that consolidates related constants into one import point.
Detailed Explanation
Imported Entities
RunningStatus (enum)
Imported from the@/constants/knowledgemodule, this enum defines possible states of a process or task lifecycle (e.g.,UNSTART,RUNNING,CANCEL,DONE,FAIL).
Exported Constants
RunningStatusMap
export const RunningStatusMap = {
[RunningStatus.UNSTART]: {
label: 'UNSTART',
color: 'cyan',
},
[RunningStatus.RUNNING]: {
label: 'Parsing',
color: 'blue',
},
[RunningStatus.CANCEL]: { label: 'CANCEL', color: 'orange' },
[RunningStatus.DONE]: { label: 'SUCCESS', color: 'geekblue' },
[RunningStatus.FAIL]: { label: 'FAIL', color: 'red' },
};
Purpose
Provides a mapping from eachRunningStatusenum value to a descriptive label string and a color string. This allows UI components or logs to consistently represent the status with both text and color.Properties
Each key corresponds to a status value fromRunningStatus. The value is an object with:label(string): A human-readable string describing the status.color(string): A color name or code used for UI display purposes.
Example Usage
import { RunningStatusMap, RunningStatus } from './constant'; function renderStatus(status: RunningStatus) { const statusInfo = RunningStatusMap[status]; console.log(`Status: ${statusInfo.label}, Color: ${statusInfo.color}`); // UI rendering code could use statusInfo.color for color styling }
Re-exported Entities
export * from '@/constants/knowledge';
This line re-exports all exports from the
@/constants/knowledgemodule.This means any consumer importing from
constant.tscan also access all constants and enums defined in the knowledge module without importing it separately.This supports modularity and reduces import complexity in other parts of the application.
Implementation Details
The
RunningStatusMapuses computed property names ([RunningStatus.UNSTART]) to dynamically assign keys based on enum values.The color values used are common UI color names or theme color identifiers (e.g., 'cyan', 'blue', 'orange', 'geekblue', 'red').
The label for the
RUNNINGstatus is customized as'Parsing', indicating a specific meaning in the application context.
Interaction with Other Parts of the System
Source of Truth: The
RunningStatusenum is defined in@/constants/knowledge, making that module the authoritative source for status constants.Consumers: Any UI components, services, or utilities that need to represent or interpret running statuses can import
RunningStatusMapto obtain labels and colors.Modular Exporting: By re-exporting from
@/constants/knowledge, this file acts as a convenient consolidation point for importing running status-related constants.
Visual Diagram
flowchart TD
A[constant.ts] --> B[Import RunningStatus Enum]
A --> C[Define RunningStatusMap]
A --> D[Re-export all from @/constants/knowledge]
C --> E[UNSTART: {label, color}]
C --> F[RUNNING: {label, color}]
C --> G[CANCEL: {label, color}]
C --> H[DONE: {label, color}]
C --> I[FAIL: {label, color}]
Summary
constant.tsprovides a mapping from running status enum values to descriptive labels and colors.It imports the running status enumeration from an external knowledge constants module.
It re-exports all constants from the knowledge module for simplified imports elsewhere.
This file is primarily a utility for UI representation and consistent usage of status-related constants across the application.