فهرست منبع

♻️ refactor(components): 改进LinkmanSelect组件导入方式和类型定义

- 修改LinkmanData接口中mobile和position类型为string | null
- 移除LinkmanSelect组件导出时的命名导出,改为默认导出
- 移除map循环中linkman参数的显式类型声明,利用类型推断

♻️ refactor(pages): 优化OrderRecords页面导入方式和响应检查

- 将组件导入方式从命名导入改为默认导入
- 将响应状态检查从response.status === 200改为response.ok,更准确判断请求成功状态
- 统一修改新增、编辑、删除和列表查询的响应检查逻辑
yourname 8 ماه پیش
والد
کامیت
f5ee9e162a
2فایلهای تغییر یافته به همراه14 افزوده شده و 12 حذف شده
  1. 7 5
      src/client/admin/components/LinkmanSelect.tsx
  2. 7 7
      src/client/admin/pages/OrderRecords.tsx

+ 7 - 5
src/client/admin/components/LinkmanSelect.tsx

@@ -20,15 +20,15 @@ interface LinkmanSelectProps {
 interface LinkmanData {
 interface LinkmanData {
   id: string;
   id: string;
   name: string;
   name: string;
-  mobile?: string;
-  position?: string;
+  mobile?: string | null;
+  position?: string | null;
   clientId: number;
   clientId: number;
 }
 }
 
 
 // 定义联系人列表响应类型
 // 定义联系人列表响应类型
 type ContactsResponse = InferResponseType<typeof linkmanClient.$get, 200>;
 type ContactsResponse = InferResponseType<typeof linkmanClient.$get, 200>;
 
 
-export const LinkmanSelect: React.FC<LinkmanSelectProps> = ({
+const LinkmanSelect: React.FC<LinkmanSelectProps> = ({
   value,
   value,
   onChange,
   onChange,
   clientId,
   clientId,
@@ -86,7 +86,7 @@ export const LinkmanSelect: React.FC<LinkmanSelectProps> = ({
       style={{ width: '100%' }}
       style={{ width: '100%' }}
       notFoundContent={isLoading ? <Spin size="small" /> : '未找到联系人'}
       notFoundContent={isLoading ? <Spin size="small" /> : '未找到联系人'}
     >
     >
-      {linkmanData.map((linkman: LinkmanData) => (
+      {linkmanData.map((linkman) => (
         <Option key={linkman.id} value={linkman.id}>
         <Option key={linkman.id} value={linkman.id}>
           {linkman.name}
           {linkman.name}
           {linkman.mobile && ` (${linkman.mobile})`}
           {linkman.mobile && ` (${linkman.mobile})`}
@@ -95,4 +95,6 @@ export const LinkmanSelect: React.FC<LinkmanSelectProps> = ({
       ))}
       ))}
     </Select>
     </Select>
   );
   );
-};
+};
+
+export default LinkmanSelect;

+ 7 - 7
src/client/admin/pages/OrderRecords.tsx

@@ -5,9 +5,9 @@ import type { ColumnsType } from 'antd/es/table';
 import dayjs from 'dayjs';
 import dayjs from 'dayjs';
 import { InferRequestType, InferResponseType } from 'hono/client';
 import { InferRequestType, InferResponseType } from 'hono/client';
 import { orderRecordClient } from '@/client/api';
 import { orderRecordClient } from '@/client/api';
-import { ClientSelect } from '@/client/admin/components/ClientSelect';
-import { UserSelect } from '@/client/admin/components/UserSelect';
-import { LinkmanSelect } from '@/client/admin/components/LinkmanSelect';
+import ClientSelect from '@/client/admin/components/ClientSelect';
+import UserSelect from '@/client/admin/components/UserSelect';
+import LinkmanSelect from '@/client/admin/components/LinkmanSelect';
 
 
 const { RangePicker } = DatePicker;
 const { RangePicker } = DatePicker;
 const { Option } = Select;
 const { Option } = Select;
@@ -152,7 +152,7 @@ const OrderRecords: React.FC = () => {
         }
         }
       });
       });
       
       
-      if (response.status === 200) {
+      if (response.ok) {
         const result = await response.json();
         const result = await response.json();
         setData(result.data);
         setData(result.data);
         setPagination({
         setPagination({
@@ -234,7 +234,7 @@ const OrderRecords: React.FC = () => {
         param: { id }
         param: { id }
       });
       });
       
       
-      if (response.status === 200) {
+      if (response.ok) {
         message.success('删除成功');
         message.success('删除成功');
         fetchData(pagination.current, pagination.pageSize, searchParams);
         fetchData(pagination.current, pagination.pageSize, searchParams);
       }
       }
@@ -261,7 +261,7 @@ const OrderRecords: React.FC = () => {
           json: formData as UpdateRequest
           json: formData as UpdateRequest
         });
         });
         
         
-        if (response.status === 200) {
+        if (response.ok) {
           message.success('更新成功');
           message.success('更新成功');
           setModalVisible(false);
           setModalVisible(false);
           fetchData(pagination.current, pagination.pageSize, searchParams);
           fetchData(pagination.current, pagination.pageSize, searchParams);
@@ -272,7 +272,7 @@ const OrderRecords: React.FC = () => {
           json: formData as CreateRequest
           json: formData as CreateRequest
         });
         });
         
         
-        if (response.status === 200) {
+        if (response.ok) {
           message.success('新增成功');
           message.success('新增成功');
           setModalVisible(false);
           setModalVisible(false);
           fetchData(1, pagination.pageSize, searchParams);
           fetchData(1, pagination.pageSize, searchParams);