Просмотр исходного кода

♻️ refactor(contract): 统一合同状态管理与优化UI显示

- 重构合同状态管理,使用枚举替代字符串常量
- 将状态值由中文改为英文标识符(pending/active),提高代码规范性
- 创建CONTRACT_STATUS_MAP实现状态值到显示文本的映射
- 修复合同金额显示格式问题,添加适当空格
- 优化表格布局,添加横向滚动支持
- 调整状态判断逻辑,确保状态显示与后端保持一致
- 更新表单初始值和选项配置,统一状态值使用英文标识符

🐛 fix(contract): 修复合同审核状态更新问题

- 修复审核合同状态更新时发送中文状态值的错误,改为发送英文标识符
- 修正状态显示逻辑,确保表格中正确显示状态中文名称
- 修复合同操作按钮显示条件判断错误
yourname 7 месяцев назад
Родитель
Сommit
bb041f449c
2 измененных файлов с 29 добавлено и 29 удалено
  1. 14 12
      src/client/admin/pages/Contracts.tsx
  2. 15 17
      src/server/modules/contracts/hetong.entity.ts

+ 14 - 12
src/client/admin/pages/Contracts.tsx

@@ -8,10 +8,10 @@ import { hetongClient } from '@/client/api';
 import type { InferResponseType } from 'hono/client';
 import dayjs from 'dayjs';
 
-// 合同状态枚举
-const CONTRACT_STATUS = {
-  PENDING: '待审',
-  ACTIVE: '合同有效'
+// 合同状态映射
+const CONTRACT_STATUS_MAP = {
+  pending: '待审',
+  active: '合同有效'
 } as const;
 
 // 定义类型
@@ -128,7 +128,7 @@ const Contracts: React.FC = () => {
       const response = await hetongClient[':id'].$put({
         param: { id },
         json: {
-          status: '合同有效',
+          status: 'active',
           auditTime: new Date().toISOString()
         }
       });
@@ -221,7 +221,7 @@ const Contracts: React.FC = () => {
       dataIndex: 'amount',
       key: 'amount',
       width: 120,
-      render: (amount: number, record: HetongItem) =>
+      render: (amount: number, record: HetongItem) => 
         `${record.currency || 'CNY'} ${Number(amount).toLocaleString()}`,
       align: 'right' as const,
     },
@@ -250,11 +250,11 @@ const Contracts: React.FC = () => {
       key: 'status',
       width: 100,
       render: (status: string) => (
-        <span style={{
-          color: status === '合同有效' ? 'green' : 'orange',
+        <span style={{ 
+          color: status === 'active' ? 'green' : 'orange',
           fontWeight: 'bold'
         }}>
-          {status}
+          {CONTRACT_STATUS_MAP[status as keyof typeof CONTRACT_STATUS_MAP] || status}
         </span>
       ),
     },
@@ -279,7 +279,7 @@ const Contracts: React.FC = () => {
       fixed: 'right' as const,
       render: (_: any, record: HetongItem) => (
         <Space size="small">
-          {record.status === '待审' && (
+          {(record as any).status === 'pending' && (
             <Popconfirm
               title="确认审核此合同?"
               description={`将合同"${record.contractNumber}"状态设为"合同有效"`}
@@ -359,6 +359,7 @@ const Contracts: React.FC = () => {
         }}
         onChange={handleTableChange}
         bordered
+        scroll={{ x: 1200 }}
       />
       
       <Modal
@@ -462,13 +463,14 @@ const Contracts: React.FC = () => {
             <Form.Item
               name="status"
               label="合同状态"
+              initialValue="pending"
               rules={[{ required: true, message: '请选择合同状态' }]}
             >
               <Select
                 placeholder="请选择合同状态"
                 options={[
-                  { label: '待审', value: '待审' },
-                  { label: '合同有效', value: '合同有效' }
+                  { label: '待审', value: 'pending' },
+                  { label: '合同有效', value: 'active' }
                 ]}
               />
             </Form.Item>

+ 15 - 17
src/server/modules/contracts/hetong.entity.ts

@@ -4,12 +4,10 @@ import { Client } from '../clients/client.entity';
 import { z } from '@hono/zod-openapi';
 
 // 合同状态枚举
-export const CONTRACT_STATUS = {
-  PENDING: '待审',
-  ACTIVE: '合同有效'
-} as const;
-
-export type ContractStatusType = typeof CONTRACT_STATUS[keyof typeof CONTRACT_STATUS];
+export enum ContractStatus {
+  PENDING = 'pending',
+  ACTIVE = 'active'
+}
 
 @Entity('hetong')
 export class Hetong {
@@ -44,8 +42,8 @@ export class Hetong {
   @Column({ name: 'type', type: 'varchar', length: 50 })
   type!: string;
 
-  @Column({ name: 'status', type: 'varchar', length: 50, default: '待审' })
-  status!: string;
+  @Column({ name: 'status', type: 'varchar', length: 50, default: 'pending' })
+  status!: ContractStatus;
 
   @Column({ name: 'received_amount', type: 'decimal', precision: 15, scale: 2, default: 0 })
   receivedAmount!: number;
@@ -129,9 +127,9 @@ export const HetongSchema = z.object({
     description: '合同类型',
     example: '服务合同'
   }),
-  status: z.string().max(50).openapi({
-    description: '合同状态:待审/合同有效',
-    example: '待审'
+  status: z.enum(['pending', 'active']).openapi({
+    description: '合同状态:pending待审/active合同有效',
+    example: 'pending'
   }),
   startDate: z.date().openapi({
     description: '开始日期',
@@ -196,9 +194,9 @@ export const CreateHetongDto = z.object({
     description: '合同类型',
     example: '服务合同'
   }),
-  status: z.string().max(50).openapi({
-    description: '合同状态:待审/合同有效',
-    example: '待审'
+  status: z.enum(['pending', 'active']).openapi({
+    description: '合同状态:pending待审/active合同有效',
+    example: 'pending'
   }),
   startDate: z.coerce.date().openapi({
     description: '开始日期',
@@ -255,9 +253,9 @@ export const UpdateHetongDto = z.object({
     description: '合同类型',
     example: '服务合同'
   }),
-  status: z.string().max(50).optional().openapi({
-    description: '合同状态:待审/合同有效',
-    example: '待审'
+  status: z.enum(['pending', 'active']).optional().openapi({
+    description: '合同状态:pending待审/active合同有效',
+    example: 'pending'
   }),
   startDate: z.coerce.date().optional().openapi({
     description: '开始日期',