сделал добавление и редактирование линз

This commit is contained in:
Андрей Дувакин 2025-02-20 10:20:48 +05:00
parent c2d5407c22
commit 073ed5fc11
3 changed files with 123 additions and 84 deletions

View File

@ -1,4 +1,5 @@
from sqlalchemy import Integer, Column, DateTime, func from sqlalchemy import Integer, Column, DateTime
from sqlalchemy.sql import func
from app.domain.models import Base from app.domain.models import Base
@ -7,5 +8,5 @@ class BaseModel(Base):
__abstract__ = True __abstract__ = True
id = Column(Integer, primary_key=True, autoincrement=True) id = Column(Integer, primary_key=True, autoincrement=True)
created_at = Column(DateTime, server_default=func.now(), default=func.now, nullable=False) created_at = Column(DateTime, server_default=func.now(), nullable=False)
updated_at = Column(DateTime, server_default=func.now(), default=func.now, onupdate=func.now, nullable=False) updated_at = Column(DateTime, server_default=func.now(), onupdate=func.now(), nullable=False)

View File

@ -4,7 +4,7 @@ import CONFIG from "../../core/Config.jsx";
const deleteLens = async (token, lens_id) => { const deleteLens = async (token, lens_id) => {
try { try {
const response = await axios.delete(`${CONFIG.BASE_URL}/lenses/${lens_id}`, { const response = await axios.delete(`${CONFIG.BASE_URL}/lenses/${lens_id}/`, {
headers: { headers: {
Authorization: `Bearer ${token}`, Authorization: `Bearer ${token}`,
}, },

View File

@ -1,4 +1,4 @@
import {Form, InputNumber, Modal, notification, Select} from "antd"; import {Col, Form, InputNumber, Modal, notification, Row, Select} from "antd";
import {useEffect, useState} from "react"; import {useEffect, useState} from "react";
import PropTypes from "prop-types"; import PropTypes from "prop-types";
import getAllLensTypes from "../../api/lens_types/GetAllLensTypes.jsx"; import getAllLensTypes from "../../api/lens_types/GetAllLensTypes.jsx";
@ -7,14 +7,12 @@ import {useAuth} from "../../AuthContext.jsx";
const LensFormModal = ({visible, onCancel, onSubmit, lens}) => { const LensFormModal = ({visible, onCancel, onSubmit, lens}) => {
const {user} = useAuth(); const {user} = useAuth();
const [form] = Form.useForm(); const [form] = Form.useForm();
const [lensTypes, setLensTypes] = useState([]); const [lensTypes, setLensTypes] = useState([]);
useEffect(() => { useEffect(() => {
fetchLensTypes(); fetchLensTypes();
}, []) }, []);
useEffect(() => { useEffect(() => {
if (visible) { if (visible) {
@ -22,7 +20,7 @@ const LensFormModal = ({visible, onCancel, onSubmit, lens}) => {
if (lens) { if (lens) {
form.setFieldsValue({ form.setFieldsValue({
...lens, ...lens,
}) });
} }
} }
}, [visible, lens]); }, [visible, lens]);
@ -39,7 +37,7 @@ const LensFormModal = ({visible, onCancel, onSubmit, lens}) => {
placement: "topRight", placement: "topRight",
}); });
} }
} };
const handleOk = async () => { const handleOk = async () => {
try { try {
@ -47,7 +45,7 @@ const LensFormModal = ({visible, onCancel, onSubmit, lens}) => {
onSubmit(values); onSubmit(values);
form.resetFields(); form.resetFields();
} catch (error) { } catch (error) {
console.log("Validation Failed:", error) console.log("Validation Failed:", error);
} }
}; };
@ -68,83 +66,123 @@ const LensFormModal = ({visible, onCancel, onSubmit, lens}) => {
centered centered
> >
<Form form={form} layout={"vertical"}> <Form form={form} layout={"vertical"}>
<Form.Item <Row gutter={16}>
name="tor" <Col xs={24} md={12}>
label="Тор" <Form.Item
rules={[{required: true, message: "Введите тор"}]} name="tor"
> label="Тор"
<InputNumber rules={[{required: true, message: "Введите тор"}]}
step={0.1} >
/> <InputNumber
</Form.Item> style={{width: '100%'}}
step={0.1}
<Form.Item
name="trial" />
label="Острота зрения (Trial)" </Form.Item>
rules={[{required: true, message: "Введите остроту зрения"}]} </Col>
> <Col xs={24} md={12}>
<InputNumber <Form.Item
step={0.1} name="trial"
/> label="Острота зрения (Trial)"
</Form.Item> rules={[{required: true, message: "Введите остроту зрения"}]}
>
<Form.Item <InputNumber
name="esa" style={{width: '100%'}}
label="Esa" step={0.1}
rules={[{required: true, message: "Введите esa"}]}
> />
<InputNumber/> </Form.Item>
</Form.Item> </Col>
</Row>
<Form.Item <Row gutter={16}>
name="fvc" <Col xs={24} md={12}>
label="FVC" <Form.Item
rules={[{required: true, message: "Введите fvc"}]} name="esa"
> label="Esa"
<InputNumber/> rules={[{required: true, message: "Введите esa"}]}
</Form.Item> >
<InputNumber
<Form.Item style={{width: '100%'}}
name="preset_refraction" step={0.1}
label="Пресетная рефракция"
rules={[{required: true, message: "Введите пресетную рефракцию"}]} />
> </Form.Item>
<InputNumber/> </Col>
</Form.Item> <Col xs={24} md={12}>
<Form.Item
<Form.Item name="fvc"
name="diameter" label="FVC"
label="Диаметр" rules={[{required: true, message: "Введите fvc"}]}
rules={[{required: true, message: "Введите диаметр"}]} >
> <InputNumber
<InputNumber/> style={{width: '100%'}}
</Form.Item> step={0.1}
<Form.Item />
name="periphery_toricity" </Form.Item>
label="Периферия торичность" </Col>
rules={[{required: true, message: "Введите периферию торичность"}]} </Row>
> <Row gutter={16}>
<InputNumber/> <Col xs={24} md={12}>
</Form.Item> <Form.Item
name="preset_refraction"
<Form.Item label="Пресетная рефракция"
name="side" rules={[{required: true, message: "Введите пресетную рефракцию"}]}
label="Сторона" >
rules={[{required: true, message: "Выберите сторону"}]} <InputNumber
> style={{width: '100%'}}
<Select> step={0.1}
<Select.Option value="left">Левая</Select.Option>
<Select.Option value="right">Правая</Select.Option> />
</Select> </Form.Item>
</Form.Item> </Col>
<Col xs={24} md={12}>
<Form.Item
name="diameter"
label="Диаметр"
rules={[{required: true, message: "Введите диаметр"}]}
>
<InputNumber
style={{width: '100%'}}
step={0.1}
/>
</Form.Item>
</Col>
</Row>
<Row gutter={16}>
<Col xs={24} md={12}>
<Form.Item
name="periphery_toricity"
label="Периферия торичность"
rules={[{required: true, message: "Введите периферию торичность"}]}
>
<InputNumber
style={{width: '100%'}}
step={0.1}
/>
</Form.Item>
</Col>
<Col xs={24} md={12}>
<Form.Item
name="side"
label="Сторона"
rules={[{required: true, message: "Выберите сторону"}]}
>
<Select style={{width: '100%'}}>
<Select.Option value="левая">Левая</Select.Option>
<Select.Option value="правая">Правая</Select.Option>
</Select>
</Form.Item>
</Col>
</Row>
<Form.Item <Form.Item
name="type_id" name="type_id"
label="Тип линзы" label="Тип линзы"
rules={[{required: true, message: "Выберите тип линзы"}]} rules={[{required: true, message: "Выберите тип линзы"}]}
> >
<Select> <Select style={{width: '100%'}}>
{lensTypes.map((type) => ( {lensTypes.map((type) => (
<Select.Option key={type.id} value={type.id}> <Select.Option key={type.id} value={type.id}>
{type.title} {type.title}
@ -154,7 +192,7 @@ const LensFormModal = ({visible, onCancel, onSubmit, lens}) => {
</Form.Item> </Form.Item>
</Form> </Form>
</Modal> </Modal>
) );
}; };
LensFormModal.propTypes = { LensFormModal.propTypes = {