Selaa lähdekoodia

🐞 fix(头像): 头像

头像
tags/小炒逻辑变更前
唐学波 2 vuotta sitten
vanhempi
commit
47183d8acf
2 muutettua tiedostoa jossa 30 lisäystä ja 22 poistoa
  1. +1
    -0
      package.json
  2. +29
    -22
      src/pages/sys/sysSettings/components/EnterpriseLog.jsx

+ 1
- 0
package.json Näytä tiedosto

@@ -74,6 +74,7 @@
"react-dev-inspector": "^1.1.1",
"react-dom": "^17.0.0",
"react-helmet-async": "^1.0.4",
"swagger-ui-react": "^4.14.0",
"umi": "^3.5.0",
"umi-serve": "^1.9.10"
},


+ 29
- 22
src/pages/sys/sysSettings/components/EnterpriseLog.jsx Näytä tiedosto

@@ -35,6 +35,7 @@ const EnterpriseLog = () => {
allUrl: '',
seeUrl: '',
});

const uploadProps = {
name: 'file',
showUploadList: false,
@@ -44,15 +45,23 @@ const EnterpriseLog = () => {
headers: {
'Content-Type': 'application/octet-stream',
},
customRequest({ action, file, headers, onError, onProgress, onSuccess, withCredentials }) {
customRequest({
action,
file,
headers,
onError,
onProgress,
onSuccess,
withCredentials,
}) {

//覆盖action 上传之前获取上传地址
var index = file.name.lastIndexOf('.');
var index = file.name.lastIndexOf(".");
var ext = file.name.substr(index + 1);

let fileData = null;
GetCosRequestURL({ directory: "logo", fileExtension: ext, method: "PUT" }).then((r) => {
SetCosInfo(r)
action = r.fileUrl + '?' + r.param;
action = r.allUrl;
const reader = new FileReader();
reader.readAsArrayBuffer(file);
reader.onload = (e) => {
@@ -60,24 +69,20 @@ const EnterpriseLog = () => {
// 在文件读取结束后执行的操作
fileData = e.target.result;
// 使用 axios 进行文件上传的请求
axios
.put(action, fileData, {
withCredentials,
headers,
onUploadProgress: ({ total, loaded }) => {
// 进行上传进度输出,更加直观
onProgress({ percent: Math.round((loaded / total) * 100).toFixed(2) }, file);
},
})
.then((response) => {
console.log('onSuccess', response, file);
if (response.status == 200 || response.statusText == 'OK') {
setUrl(r.seeUrl);
CompanyInfo.logo = r.seeUrl;
updateCompany(CompanyInfo);
}
// onSuccess(response, file);
})
axios.put(action, fileData, {
withCredentials,
headers,
onUploadProgress: ({ total, loaded }) => {
// 进行上传进度输出,更加直观
onProgress({ percent: Math.round(loaded / total * 100).toFixed(2) }, file);
},
}).then(response => {
console.log('onSuccess', response, file);
if (response.status == 200 || response.statusText == 'OK') {
setUrl(r.seeUrl)
}
// onSuccess(response, file);
})
.catch(onError);
};
});
@@ -87,6 +92,8 @@ const EnterpriseLog = () => {
},
};
},
//defaultFileList: props.location.query.values ? props.location.query.values : null

};
return (
<div className={styles.baseView}>


Ladataan…
Peruuta
Tallenna