style: use date picker for manufacture date
This commit is contained in:
@@ -14,6 +14,7 @@
|
|||||||
"@ant-design/icons": "^6.1.0",
|
"@ant-design/icons": "^6.1.0",
|
||||||
"antd": "^6.3.1",
|
"antd": "^6.3.1",
|
||||||
"axios": "^1.13.6",
|
"axios": "^1.13.6",
|
||||||
|
"dayjs": "^1.11.21",
|
||||||
"qrcode": "^1.5.4",
|
"qrcode": "^1.5.4",
|
||||||
"react": "^19.2.4",
|
"react": "^19.2.4",
|
||||||
"react-dom": "^19.2.4",
|
"react-dom": "^19.2.4",
|
||||||
|
|||||||
Generated
+10
-7
@@ -17,6 +17,9 @@ importers:
|
|||||||
axios:
|
axios:
|
||||||
specifier: ^1.13.6
|
specifier: ^1.13.6
|
||||||
version: 1.13.6
|
version: 1.13.6
|
||||||
|
dayjs:
|
||||||
|
specifier: ^1.11.21
|
||||||
|
version: 1.11.21
|
||||||
qrcode:
|
qrcode:
|
||||||
specifier: ^1.5.4
|
specifier: ^1.5.4
|
||||||
version: 1.5.4
|
version: 1.5.4
|
||||||
@@ -872,8 +875,8 @@ packages:
|
|||||||
csstype@3.2.3:
|
csstype@3.2.3:
|
||||||
resolution: {integrity: sha512-z1HGKcYy2xA8AGQfwrn0PAy+PB7X/GSj3UVJW9qKyn43xWa+gl5nXmU4qqLMRzWVLFC8KusUX8T/0kCiOYpAIQ==}
|
resolution: {integrity: sha512-z1HGKcYy2xA8AGQfwrn0PAy+PB7X/GSj3UVJW9qKyn43xWa+gl5nXmU4qqLMRzWVLFC8KusUX8T/0kCiOYpAIQ==}
|
||||||
|
|
||||||
dayjs@1.11.19:
|
dayjs@1.11.21:
|
||||||
resolution: {integrity: sha512-t5EcLVS6QPBNqM2z8fakk/NKel+Xzshgt8FFKAn+qwlD1pzZWxh0nVCrvFK7ZDb6XucZeF9z8C7CBWTRIVApAw==}
|
resolution: {integrity: sha512-98IT+HOahAisibz/yjKbzuOBwYcjJ7BCLPzARyHiyEBmRz4fatF+KPJszEHXsGYjUG234aH/cOjW1wwTbKUZlA==}
|
||||||
|
|
||||||
debug@4.4.3:
|
debug@4.4.3:
|
||||||
resolution: {integrity: sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==}
|
resolution: {integrity: sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==}
|
||||||
@@ -1679,7 +1682,7 @@ snapshots:
|
|||||||
react: 19.2.4
|
react: 19.2.4
|
||||||
react-dom: 19.2.4(react@19.2.4)
|
react-dom: 19.2.4(react@19.2.4)
|
||||||
|
|
||||||
'@rc-component/picker@1.9.0(dayjs@1.11.19)(react-dom@19.2.4(react@19.2.4))(react@19.2.4)':
|
'@rc-component/picker@1.9.0(dayjs@1.11.21)(react-dom@19.2.4(react@19.2.4))(react@19.2.4)':
|
||||||
dependencies:
|
dependencies:
|
||||||
'@rc-component/overflow': 1.0.0(react-dom@19.2.4(react@19.2.4))(react@19.2.4)
|
'@rc-component/overflow': 1.0.0(react-dom@19.2.4(react@19.2.4))(react@19.2.4)
|
||||||
'@rc-component/resize-observer': 1.1.1(react-dom@19.2.4(react@19.2.4))(react@19.2.4)
|
'@rc-component/resize-observer': 1.1.1(react-dom@19.2.4(react@19.2.4))(react@19.2.4)
|
||||||
@@ -1689,7 +1692,7 @@ snapshots:
|
|||||||
react: 19.2.4
|
react: 19.2.4
|
||||||
react-dom: 19.2.4(react@19.2.4)
|
react-dom: 19.2.4(react@19.2.4)
|
||||||
optionalDependencies:
|
optionalDependencies:
|
||||||
dayjs: 1.11.19
|
dayjs: 1.11.21
|
||||||
|
|
||||||
'@rc-component/portal@2.2.0(react-dom@19.2.4(react@19.2.4))(react@19.2.4)':
|
'@rc-component/portal@2.2.0(react-dom@19.2.4(react@19.2.4))(react@19.2.4)':
|
||||||
dependencies:
|
dependencies:
|
||||||
@@ -2022,7 +2025,7 @@ snapshots:
|
|||||||
'@rc-component/mutate-observer': 2.0.1(react-dom@19.2.4(react@19.2.4))(react@19.2.4)
|
'@rc-component/mutate-observer': 2.0.1(react-dom@19.2.4(react@19.2.4))(react@19.2.4)
|
||||||
'@rc-component/notification': 1.2.0(react-dom@19.2.4(react@19.2.4))(react@19.2.4)
|
'@rc-component/notification': 1.2.0(react-dom@19.2.4(react@19.2.4))(react@19.2.4)
|
||||||
'@rc-component/pagination': 1.2.0(react-dom@19.2.4(react@19.2.4))(react@19.2.4)
|
'@rc-component/pagination': 1.2.0(react-dom@19.2.4(react@19.2.4))(react@19.2.4)
|
||||||
'@rc-component/picker': 1.9.0(dayjs@1.11.19)(react-dom@19.2.4(react@19.2.4))(react@19.2.4)
|
'@rc-component/picker': 1.9.0(dayjs@1.11.21)(react-dom@19.2.4(react@19.2.4))(react@19.2.4)
|
||||||
'@rc-component/progress': 1.0.2(react-dom@19.2.4(react@19.2.4))(react@19.2.4)
|
'@rc-component/progress': 1.0.2(react-dom@19.2.4(react@19.2.4))(react@19.2.4)
|
||||||
'@rc-component/qrcode': 1.1.1(react-dom@19.2.4(react@19.2.4))(react@19.2.4)
|
'@rc-component/qrcode': 1.1.1(react-dom@19.2.4(react@19.2.4))(react@19.2.4)
|
||||||
'@rc-component/rate': 1.0.1(react-dom@19.2.4(react@19.2.4))(react@19.2.4)
|
'@rc-component/rate': 1.0.1(react-dom@19.2.4(react@19.2.4))(react@19.2.4)
|
||||||
@@ -2043,7 +2046,7 @@ snapshots:
|
|||||||
'@rc-component/upload': 1.1.0(react-dom@19.2.4(react@19.2.4))(react@19.2.4)
|
'@rc-component/upload': 1.1.0(react-dom@19.2.4(react@19.2.4))(react@19.2.4)
|
||||||
'@rc-component/util': 1.9.0(react-dom@19.2.4(react@19.2.4))(react@19.2.4)
|
'@rc-component/util': 1.9.0(react-dom@19.2.4(react@19.2.4))(react@19.2.4)
|
||||||
clsx: 2.1.1
|
clsx: 2.1.1
|
||||||
dayjs: 1.11.19
|
dayjs: 1.11.21
|
||||||
react: 19.2.4
|
react: 19.2.4
|
||||||
react-dom: 19.2.4(react@19.2.4)
|
react-dom: 19.2.4(react@19.2.4)
|
||||||
scroll-into-view-if-needed: 3.1.0
|
scroll-into-view-if-needed: 3.1.0
|
||||||
@@ -2108,7 +2111,7 @@ snapshots:
|
|||||||
|
|
||||||
csstype@3.2.3: {}
|
csstype@3.2.3: {}
|
||||||
|
|
||||||
dayjs@1.11.19: {}
|
dayjs@1.11.21: {}
|
||||||
|
|
||||||
debug@4.4.3:
|
debug@4.4.3:
|
||||||
dependencies:
|
dependencies:
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { useEffect, useState } from 'react';
|
|||||||
import {
|
import {
|
||||||
Button,
|
Button,
|
||||||
Card,
|
Card,
|
||||||
|
DatePicker,
|
||||||
Form,
|
Form,
|
||||||
Image,
|
Image,
|
||||||
Input,
|
Input,
|
||||||
@@ -23,11 +24,12 @@ import {
|
|||||||
UploadOutlined,
|
UploadOutlined,
|
||||||
} from '@ant-design/icons';
|
} from '@ant-design/icons';
|
||||||
import type { UploadFile } from 'antd';
|
import type { UploadFile } from 'antd';
|
||||||
|
import dayjs, { type Dayjs } from 'dayjs';
|
||||||
import { productTracesApi } from '@/services/api';
|
import { productTracesApi } from '@/services/api';
|
||||||
import type { CreateProductTraceRequest, ProductTrace, UpdateProductTraceRequest } from '@/types';
|
import type { CreateProductTraceRequest, ProductTrace, UpdateProductTraceRequest } from '@/types';
|
||||||
|
|
||||||
type ProductTraceFormValues = Omit<CreateProductTraceRequest, 'manufactureDate'> & {
|
type ProductTraceFormValues = Omit<CreateProductTraceRequest, 'manufactureDate'> & {
|
||||||
manufactureDate: string;
|
manufactureDate: Dayjs;
|
||||||
};
|
};
|
||||||
|
|
||||||
function formatDate(value: string) {
|
function formatDate(value: string) {
|
||||||
@@ -35,15 +37,6 @@ function formatDate(value: string) {
|
|||||||
return new Date(value).toLocaleDateString('zh-CN');
|
return new Date(value).toLocaleDateString('zh-CN');
|
||||||
}
|
}
|
||||||
|
|
||||||
function toDateInputValue(value: string) {
|
|
||||||
if (!value) return '';
|
|
||||||
return new Date(value).toISOString().slice(0, 10);
|
|
||||||
}
|
|
||||||
|
|
||||||
function dateInputToISOString(value: string) {
|
|
||||||
return new Date(`${value}T00:00:00+08:00`).toISOString();
|
|
||||||
}
|
|
||||||
|
|
||||||
function ProductTracesPage() {
|
function ProductTracesPage() {
|
||||||
const [traces, setTraces] = useState<ProductTrace[]>([]);
|
const [traces, setTraces] = useState<ProductTrace[]>([]);
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
@@ -110,7 +103,7 @@ function ProductTracesPage() {
|
|||||||
companyPhone: trace.companyPhone,
|
companyPhone: trace.companyPhone,
|
||||||
deviceInfo: trace.deviceInfo,
|
deviceInfo: trace.deviceInfo,
|
||||||
warrantyPeriod: trace.warrantyPeriod,
|
warrantyPeriod: trace.warrantyPeriod,
|
||||||
manufactureDate: toDateInputValue(trace.manufactureDate),
|
manufactureDate: dayjs(trace.manufactureDate),
|
||||||
serialNumber: trace.serialNumber,
|
serialNumber: trace.serialNumber,
|
||||||
officialWebsite: trace.officialWebsite,
|
officialWebsite: trace.officialWebsite,
|
||||||
});
|
});
|
||||||
@@ -133,7 +126,7 @@ function ProductTracesPage() {
|
|||||||
companyPhone: values.companyPhone,
|
companyPhone: values.companyPhone,
|
||||||
deviceInfo: values.deviceInfo,
|
deviceInfo: values.deviceInfo,
|
||||||
warrantyPeriod: values.warrantyPeriod,
|
warrantyPeriod: values.warrantyPeriod,
|
||||||
manufactureDate: dateInputToISOString(values.manufactureDate),
|
manufactureDate: values.manufactureDate.toDate().toISOString(),
|
||||||
officialWebsite: values.officialWebsite || '',
|
officialWebsite: values.officialWebsite || '',
|
||||||
};
|
};
|
||||||
saved = await productTracesApi.update(editingTrace.serialNumber, payload);
|
saved = await productTracesApi.update(editingTrace.serialNumber, payload);
|
||||||
@@ -142,7 +135,7 @@ function ProductTracesPage() {
|
|||||||
...values,
|
...values,
|
||||||
officialWebsite: values.officialWebsite || '',
|
officialWebsite: values.officialWebsite || '',
|
||||||
serialNumber: values.serialNumber.trim(),
|
serialNumber: values.serialNumber.trim(),
|
||||||
manufactureDate: dateInputToISOString(values.manufactureDate),
|
manufactureDate: values.manufactureDate.toDate().toISOString(),
|
||||||
};
|
};
|
||||||
saved = await productTracesApi.create(payload);
|
saved = await productTracesApi.create(payload);
|
||||||
}
|
}
|
||||||
@@ -367,7 +360,7 @@ function ProductTracesPage() {
|
|||||||
<Input placeholder="例如:1 年 / 2027-06-05 前" />
|
<Input placeholder="例如:1 年 / 2027-06-05 前" />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item name="manufactureDate" label="出厂日期" rules={[{ required: true, message: '请选择出厂日期' }]}>
|
<Form.Item name="manufactureDate" label="出厂日期" rules={[{ required: true, message: '请选择出厂日期' }]}>
|
||||||
<Input type="date" />
|
<DatePicker style={{ width: '100%' }} />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item name="serialNumber" label="产品序列号" rules={[{ required: true, message: '请输入产品序列号' }]}>
|
<Form.Item name="serialNumber" label="产品序列号" rules={[{ required: true, message: '请输入产品序列号' }]}>
|
||||||
<Input disabled={Boolean(editingTrace)} />
|
<Input disabled={Boolean(editingTrace)} />
|
||||||
|
|||||||
Reference in New Issue
Block a user