You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
69 lines
2.1 KiB
69 lines
2.1 KiB
import http from '../http/http';
|
|
|
|
/**
|
|
* 从上传接口响应中解析文件访问路径(R<String>:data 字段为路径字符串)
|
|
*/
|
|
const parseUploadFilePath = (res) => {
|
|
const body = res?.data;
|
|
if (typeof body === 'string') {
|
|
return body;
|
|
}
|
|
if (body && typeof body.data === 'string') {
|
|
return body.data;
|
|
}
|
|
if (body && typeof body.data === 'object' && body.data) {
|
|
return body.data.url || body.data.fileUrl || body.data.path || body.data.uploadPath || '';
|
|
}
|
|
return body?.url || body?.fileUrl || body?.path || '';
|
|
};
|
|
|
|
const uploadFile = (files, callback) => {
|
|
files.status = 'uploading';
|
|
files.message = '上传中...';
|
|
const form = new FormData();
|
|
form.append('file', files.file);
|
|
|
|
http.post('/app-enf/common/file/upload', form)
|
|
.then((res) => {
|
|
const filePath = parseUploadFilePath(res);
|
|
if (!filePath) {
|
|
files.status = 'failed';
|
|
files.message = '上传失败';
|
|
console.error('上传响应缺少文件路径', res?.data);
|
|
return;
|
|
}
|
|
files.status = 'done';
|
|
files.message = '上传成功';
|
|
files.url = filePath;
|
|
// 兼容 enforcementPlanAdd 等页面的 res.url 写法
|
|
callback && callback({ url: filePath, data: res?.data, raw: res });
|
|
})
|
|
.catch((err) => {
|
|
files.status = 'failed';
|
|
files.message = '上传失败';
|
|
console.error('文件上传失败', err?.response?.data || err);
|
|
});
|
|
};
|
|
|
|
const nameCorrect=(name)=>{
|
|
let name1=[{}];
|
|
name1=String(name).split(" ");
|
|
if(name1[0].length==2){
|
|
if(name1.length>1){
|
|
return (String(name1[0]).substr(0,1)+"\u3000"+String(name1[0]).substr(1)+" "+name1[1]);
|
|
}else{
|
|
return (String(name1[0]).substr(0,1)+"\u3000"+String(name1[0]).substr(1));
|
|
}
|
|
|
|
}else{
|
|
return name;
|
|
}
|
|
}
|
|
|
|
const encryptPhone=(num)=>{
|
|
if(!/^\d{11}$/.test(num))return num;
|
|
const al= num.replace(/(\d{3})\d{4}(\d{4})/, "$1****$2");
|
|
return al;
|
|
}
|
|
|
|
export{uploadFile,nameCorrect,encryptPhone,parseUploadFilePath};
|
|
|