Commit 55a80bad authored by cellee's avatar cellee

修复设施图片key值错误问题

Signed-off-by: cellee's avatarcellee <893264950@qq.com>
parent 01a17551
...@@ -27,11 +27,16 @@ const Facilitys = (props: any) => { ...@@ -27,11 +27,16 @@ const Facilitys = (props: any) => {
const [previewTitle, setpreviewTitle] = useState(''); const [previewTitle, setpreviewTitle] = useState('');
// 图片地址 // 图片地址
const [previewImage, setpreviewImage] = useState(''); const [previewImage, setpreviewImage] = useState('');
// // 默认Id
const [idKey, setidKey] = useState(10001); const [idKey, setidKey] = useState(10001);
// 当前操作的Id
const [idPush, setidPush] = useState(null as any);
// 传递给后台加 key // 传递给后台加 key
const updetaTow = (key: any) => { const updetaTow = (key: any) => {
console.log(key);
setidPush(key);
let data = updata; let data = updata;
data.identification = key; data.identification = key;
return data; return data;
...@@ -58,28 +63,29 @@ const Facilitys = (props: any) => { ...@@ -58,28 +63,29 @@ const Facilitys = (props: any) => {
accept: '.jpeg,.png,.jpg', accept: '.jpeg,.png,.jpg',
action: '/tos/image/upload', action: '/tos/image/upload',
onChange(info: any) { onChange(info: any) {
// console.log(info);
if (info.file.status === 'done') { if (info.file.status === 'done') {
message.success(`${info.file.name} file uploaded successfully`); message.success(`${info.file.name} file uploaded successfully`);
// 后台返回的内容
let data = info.file.response.data;
// 拿到key 值 开始存储 // 拿到key 值 开始存储
let key = parseInt(info.fileList[0].response.data.identification); let key = parseInt(data.identification);
// 重命名图片的名称 // 重命名图片的名称
info.fileList[0].name = info.file.response.data.imageName; info.file.name = data.imageName;
let list = FacilitysList; let list = FacilitysList;
setidKey(idKey + 1); setidKey(idKey + 1);
list[key] = { list[key] = {
id: idKey, id: idKey,
name: FacilitysList[key].name, name: FacilitysList[key].name,
fileList: info.fileList, fileList: [info.file],
disabled: false, disabled: false,
}; };
// 存储到mode里面去 // 存储到mode里面去
dispatch({ type: module + '/genxin', list }); dispatch({ type: module + '/genxin', list });
console.log(list); // 清除操作ID
setidPush(null);
} else if (info.file.status === 'error') { } else if (info.file.status === 'error') {
message.error(`${info.file.name} file upload failed.`); message.error(`${info.file.name} file upload failed.`);
} }
...@@ -117,9 +123,9 @@ const Facilitys = (props: any) => { ...@@ -117,9 +123,9 @@ const Facilitys = (props: any) => {
//删除动作 //删除动作
const deleteImg = (key: any, id: any) => { const deleteImg = (key: any, id: any) => {
// console.log(key);
let list = FacilitysList; let list = FacilitysList;
// list[key].name = '';
list[key].name = '';
list.splice(key, 1); list.splice(key, 1);
// 存储到mode里面去 // 存储到mode里面去
dispatch({ type: module + '/genxin', list }); dispatch({ type: module + '/genxin', list });
...@@ -150,6 +156,11 @@ const Facilitys = (props: any) => { ...@@ -150,6 +156,11 @@ const Facilitys = (props: any) => {
dispatch({ type: module + '/genxin', list }); dispatch({ type: module + '/genxin', list });
}; };
//点击新增按钮
const handleChange = (a) => {
console.log(a);
};
return ( return (
<> <>
<Form.Item name="picList" required={false} style={{ marginBottom: 0 }}> <Form.Item name="picList" required={false} style={{ marginBottom: 0 }}>
...@@ -166,12 +177,13 @@ const Facilitys = (props: any) => { ...@@ -166,12 +177,13 @@ const Facilitys = (props: any) => {
: false : false
} }
// data={updata} // data={updata}
data={updetaTow(index)} // 携带数据 data={() => updetaTow(index)} // 携带数据
disabled={disabled} // 禁止 disabled={disabled} // 禁止
onPreview={handlePreview} // 预览 onPreview={handlePreview} // 预览
onRemove={() => { onRemove={() => {
deleteImgs(index, item.id); deleteImgs(index, item.id);
}} //移除 }} //移除
// onChange={handleChange} // 点击确认
> >
{FacilitysList[index].fileList.length > 0 ? null : uploadButton} {FacilitysList[index].fileList.length > 0 ? null : uploadButton}
</Upload> </Upload>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment