Browse Source

feat():充电站管理新增图片上传

tags/PMS_V1.0.0_Alpha5
zhugy 1 year ago
parent
commit
ba813ceaf8
  1. 33
      src/pages/NewEnergy/ChargeStationMgm/index.scss
  2. 154
      src/pages/NewEnergy/ChargeStationMgm/loadable.jsx

33
src/pages/NewEnergy/ChargeStationMgm/index.scss

@ -1,9 +1,9 @@
.add-station-modal { .add-station-modal {
.add-station-body { .add-station-body {
display: flex; display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
justify-content: space-between;
.left,.right {
width: calc(50% - 10px);
.row { .row {
width: 100%; width: 100%;
margin: 10px 0; margin: 10px 0;
@ -17,5 +17,32 @@
.cc-form-name,.form-select-single-name { .cc-form-name,.form-select-single-name {
width: 100px; width: 100px;
} }
.ant-upload,.ant-upload-picture-card-wrapper {
width: 100%;
height: 100%;
}
}
.right {
.img-box {
position: relative;
height: 100%;
.del {
position: absolute;
top: 3px;
right: 3px;
width: 30px;
height: 30px;
text-align: center;
line-height: 22px;
font-size: 18px;
border-radius: 50%;
border: 1px solid red;
background: #dd1e1e47;
color: #fff;
cursor: pointer;
z-index: 999;
}
}
}
} }
} }

154
src/pages/NewEnergy/ChargeStationMgm/loadable.jsx

@ -3,11 +3,12 @@ import {
message, message,
Modal, Modal,
Button, Button,
Cascader
Upload,
} from "antd"; } from "antd";
import ajax from "@/services"; import ajax from "@/services";
import { useSessionStorageState, useSetState } from "ahooks" import { useSessionStorageState, useSetState } from "ahooks"
import { TableModule, FormInput, FormSelect, FormTreeSelectNew } from "@/components";
import { LoadingOutlined, PlusOutlined } from '@ant-design/icons';
import { TableModule, FormInput, FormSelect, FormTreeSelectNew, ImgError } from "@/components";
import "./index.scss"; import "./index.scss";
@ -20,8 +21,6 @@ function Appointment() {
const [total, setTotal] = useState(0); const [total, setTotal] = useState(0);
// //
const [detailData, setDetailData] = useState({}); const [detailData, setDetailData] = useState({});
//
const [siteList, setSiteList] = useState([]);
// //
const [areaList, setAreaList] = useState([]); const [areaList, setAreaList] = useState([]);
// //
@ -34,10 +33,14 @@ function Appointment() {
site_type: "", site_type: "",
area: "", area: "",
operator: "", operator: "",
count: ""
count: "",
img: ""
} }
const [addFormData, setAddFormData] = useSetState(initAdd); const [addFormData, setAddFormData] = useSetState(initAdd);
//
const [formData, setFormData] = useSetState({}); const [formData, setFormData] = useSetState({});
// load
const [loading, setLoading] = useState(false);
// //
const initFormData = { const initFormData = {
operator: "0", operator: "0",
@ -100,16 +103,16 @@ function Appointment() {
align: "center", align: "center",
fixed: "right", fixed: "right",
width: 100, width: 100,
render: (text, record, index) => {
return (
<>
<Button type="primary" onClick={() => openModal(index, record)}>
</Button>
</>
)
// render: (text, record, index) => {
// return (
// <>
// <Button type="primary" onClick={() => openModal(index, record)}>
//
// </Button>
// </>
// )
},
// },
}, },
]; ];
@ -133,7 +136,7 @@ function Appointment() {
label: "站点状态", label: "站点状态",
options: [ options: [
{ value: "0", label: "全部" }, { value: "0", label: "全部" },
...siteList
...sysConfig?.stationType || []
], ],
defaultValue: "0", defaultValue: "0",
placeholder: "请选择站点状态", placeholder: "请选择站点状态",
@ -148,24 +151,9 @@ function Appointment() {
]; ];
const init = () => { const init = () => {
getSiteStatus()
getAreaList() getAreaList()
getAllOperator() getAllOperator()
} }
//
const getSiteStatus = () => {
ajax.getSiteStatus().then((res) => {
const { status, data } = res
if (status === 20000) {
if (data && data.length) {
data.shift()
setSiteList(data);
}
} else {
message.error(res.message)
}
});
}
// //
const getAreaList = () => { const getAreaList = () => {
ajax.getAreaTree().then((res) => { ajax.getAreaTree().then((res) => {
@ -216,10 +204,42 @@ function Appointment() {
// //
const handelAdd = () => { const handelAdd = () => {
setAddFormData(initAdd) setAddFormData(initAdd)
setLoading(false)
setDetailVisible(true) setDetailVisible(true)
} }
const handelOk = () => { const handelOk = () => {
if(!addFormData.name) {
message.warn("请输入充电站名称")
return
}
if(!addFormData.code) {
message.warn("请输入充电站编码")
return
}
if(!addFormData.count) {
message.warn("请输入车位数量")
return
}
if(!addFormData.address) {
message.warn("请输入详细地址")
return
}
if(!addFormData.site_type) {
message.warn("请选择站点类型")
return
}
if(!addFormData.area) {
message.warn("请选择所属区域")
return
}
if(!addFormData.operator) {
message.warn("请选择商户名称")
return
}
if(!addFormData.img) {
message.warn("请上传充电照片")
return
}
ajax.addStation(addFormData).then((res) => { ajax.addStation(addFormData).then((res) => {
if (res.status === 20000) { if (res.status === 20000) {
message.success("新增成功") message.success("新增成功")
@ -231,6 +251,51 @@ function Appointment() {
} }
}); });
} }
//
const beforeUpload = (file) => {
const picFormat = ['image/jpeg', 'image/png', 'image/jpg', 'image/bmp']
const isJpgOrPng = picFormat.includes(file.type)
if (!isJpgOrPng) {
message.error('图片上传格式只支持 jpeg,png,jpg,bmp!');
}
// const isLt10M = file.size / 1024 / 1024 < 10;
// if (!isLt10M) {
// message.error(' 10MB!');
// }
return isJpgOrPng;
};
const handleChange = (info) => {
if (info.file.status === 'uploading') {
setLoading(true)
return;
}
if (info.file.status === 'done') {
let res = info.file.response
setLoading(false)
if (res.status === 20000) {
setAddFormData({ img: res.data })
} else {
message.error(res.message)
}
}
};
const handelDel = (e) => {
e.preventDefault()
setAddFormData({ img: "" })
setLoading(false)
}
const uploadButton = (
<div>
{loading ? <LoadingOutlined /> : <PlusOutlined />}
<div
style={{
marginTop: 8,
}}
>
图片上传
</div>
</div>
);
useEffect(() => { useEffect(() => {
init() init()
@ -263,7 +328,7 @@ function Appointment() {
<Modal <Modal
title="添加充电站" title="添加充电站"
open={detailVisible} open={detailVisible}
width={500}
width={800}
className="add-station-modal" className="add-station-modal"
onCancel={() => { onCancel={() => {
setDetailVisible(false); setDetailVisible(false);
@ -272,6 +337,7 @@ function Appointment() {
destroyOnClose destroyOnClose
> >
<div className="add-station-body"> <div className="add-station-body">
<div className="left">
<div className="row"> <div className="row">
<FormInput <FormInput
yisaLabel="充电站名称" yisaLabel="充电站名称"
@ -312,7 +378,7 @@ function Appointment() {
<FormSelect <FormSelect
yisaLabel="站点类型" yisaLabel="站点类型"
placeholder="请选择站点类型" placeholder="请选择站点类型"
yisaData={siteList}
yisaData={sysConfig?.stationType || []}
value={addFormData.site_type} value={addFormData.site_type}
onChange={e => { setAddFormData({ site_type: e }) }} onChange={e => { setAddFormData({ site_type: e }) }}
/> />
@ -357,6 +423,28 @@ function Appointment() {
/> />
</div> </div>
</div> </div>
<div className="right">
<Upload
name="file"
listType="picture-card"
className="avatar-uploader"
showUploadList={false}
action={"http://10.10.128.65:3001/mock/11/api/com/common/file_upload"}
// action={sysConfig.apiHost + "api/com/common/file_upload"}
beforeUpload={beforeUpload}
onChange={handleChange}
>
{addFormData.img ? (
<div className="img-box">
<ImgError src={addFormData.img} />
<div className="del" onClick={handelDel}>x</div>
</div>
) : (
uploadButton
)}
</Upload>
</div>
</div>
</Modal> </Modal>
</> </>
); );

Loading…
Cancel
Save