TabSysParamsIcon.js
5.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/* eslint-disable */
import React, { useEffect, useState } from "react";
import { Form, Col, Upload, Image as ImageNew, message } from "antd";
import * as commonConfig from "@/utils/config";
// 判断图片是否存在
const checkImgExists = (imgUrl, success, error) => {
const ImgObj = new Image();
ImgObj.src = imgUrl;
ImgObj.onload = () => {
ImgObj.fileSize > 0 || (ImgObj.width > 0 && ImgObj.height > 0)
? success()
: error();
};
ImgObj.onerror = () => {
error();
};
};
const TabSysParamIcon = props => {
const { enabled, dispatch } = props;
// 刷新页面
const [, setRefresher] = useState(0);
const refresh = () => {
setRefresher(pre => pre + 1);
};
const [iconData, setIconData] = useState([
{ title: "标签页icon", imageUrl: "" },
{ title: "登录页logo", imageUrl: "" },
{ title: "主页logo", imageUrl: "" },
{ title: "版权logo", imageUrl: "" },
{ title: "后台登陆logo", imageUrl: "" },
{ title: "后台导航logo", imageUrl: "" }
]);
// 获取默认数据
useEffect(() => {
for (let index = 0; index < 6; index++) {
const imgUrl = `${
commonConfig.server_host
}file/downloadLogo?sLogoName=logo${index +
1}&date=${new Date().getTime()}`;
if (
checkImgExists(
imgUrl,
() => {
setIconData(pre => {
pre[index].imageUrl = imgUrl;
return pre;
});
refresh();
},
() => {
refresh();
}
)
) {
}
}
}, []);
return (
<>
{iconData.map(({ title, imageUrl, bPreview = !enabled }, index) => {
const uploadProps = {
listType: "picture-card",
className: "avatar-uploader",
action: `${
commonConfig.server_host
}file/uploadLogo?sLogoName=logo${index + 1}`,
disabled: bPreview,
onChange: info => {
const { fileList } = info;
const file = fileList[fileList.length - 1];
const { status, response } = file;
if (status === "done") {
if (response && response.code === 1) {
const imageUrlNew = `${
commonConfig.server_host
}file/downloadLogo?sLogoName=logo${index +
1}&date=${new Date().getTime()}`;
const iconDataNew = [...iconData];
iconDataNew[index].imageUrl = imageUrlNew;
setIconData(iconDataNew);
const logoImageInfo = [];
iconDataNew.forEach(({ imageUrl }, index) => {
if (index < 4) {
logoImageInfo.push(imageUrl);
}
});
dispatch({
type: "content/saveLogoImageInfo",
payload: {
logoImageInfo
}
});
} else if (response && response.code === -1) {
message.error(response.msg);
}
}
},
accept: "image/*",
showUploadList: false,
openFileDialogOnClick: !bPreview
};
return (
<Col span={8} key={index}>
<Form.Item
label={title}
labelCol={{ span: 12 }}
wrapperCol={{ span: 12 }}
>
<Upload {...uploadProps}>
{imageUrl ? (
<ImageNew
key={imageUrl}
src={imageUrl}
alt="avatar"
style={{
width: "100%"
}}
preview={bPreview}
// onMouseMove={e => {
// if (e && e.target) {
// const { clientX, clientY } = e;
// const { right, top } = e.target.getBoundingClientRect();
// console.log("=====", clientX, clientY, right, top);
// if (
// right > clientX &&
// right - clientX < 20 &&
// top < clientY &&
// clientY - top < 20
// ) {
// if (!bPreview) {
// console.log("=====true");
// // setIconData(pre => {
// // pre[index].bPreview = true;
// // return pre;
// // });
// }
// } else if (bPreview) {
// console.log("=====false");
// // setIconData(pre => {
// // pre[index].bPreview = false;
// // return pre;
// // });
// }
// }
// }}
/>
) : (
<div>
<div
style={{
marginTop: 8
}}
>
上传
</div>
</div>
)}
</Upload>
</Form.Item>
</Col>
);
})}
</>
);
};
export default TabSysParamIcon;