|
|
@ -1,51 +1,53 @@ |
|
|
import {_form, _post} from '../http/index' |
|
|
import http from '../http/http'; |
|
|
import { baseUrl } from "../config/env"; |
|
|
|
|
|
import axios from 'axios'; |
|
|
/** |
|
|
const http = axios.create({ |
|
|
* 从上传接口响应中解析文件访问路径(R<String>:data 字段为路径字符串) |
|
|
traditional: true, |
|
|
*/ |
|
|
contentType : "application/json", |
|
|
const parseUploadFilePath = (res) => { |
|
|
timeout: 1000 * 500000, // 1 秒
|
|
|
const body = res?.data; |
|
|
}); |
|
|
if (typeof body === 'string') { |
|
|
const uploadFile = (files,callback) => { |
|
|
return body; |
|
|
files.status = "uploading"; |
|
|
} |
|
|
files.message = "上传中..."; |
|
|
if (body && typeof body.data === 'string') { |
|
|
files.status = "uploading"; |
|
|
return body.data; |
|
|
// 需要使用 FormData 进行文件上传
|
|
|
} |
|
|
let form = new FormData(); |
|
|
if (body && typeof body.data === 'object' && body.data) { |
|
|
form.append("file", files.file); |
|
|
return body.data.url || body.data.fileUrl || body.data.path || body.data.uploadPath || ''; |
|
|
|
|
|
} |
|
|
// 获取 token(从 localStorage 或 sessionStorage 中获取)
|
|
|
return body?.url || body?.fileUrl || body?.path || ''; |
|
|
|
|
|
}; |
|
|
const token = $globalStore.useCommon.token; |
|
|
|
|
|
console.log(token); |
|
|
const uploadFile = (files, callback) => { |
|
|
axios({ |
|
|
files.status = 'uploading'; |
|
|
method: "post", |
|
|
files.message = '上传中...'; |
|
|
url: baseUrl+ "/app-enf/common/file/upload", |
|
|
const form = new FormData(); |
|
|
data: form, |
|
|
form.append('file', files.file); |
|
|
headers: { |
|
|
|
|
|
'clientid': 'f0535c2a32ab4d0496ab9a699b2a7d36', |
|
|
http.post('/app-enf/common/file/upload', form) |
|
|
'Authorization': 'Bearer ' + token |
|
|
|
|
|
} |
|
|
|
|
|
}) |
|
|
|
|
|
.then((res) => { |
|
|
.then((res) => { |
|
|
files.status = "done"; |
|
|
const filePath = parseUploadFilePath(res); |
|
|
files.message = "上传成功"; |
|
|
if (!filePath) { |
|
|
console.log(res); |
|
|
files.status = 'failed'; |
|
|
callback && callback(res); |
|
|
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) => { |
|
|
.catch((err) => { |
|
|
files.status = "failed"; |
|
|
files.status = 'failed'; |
|
|
files.message = "上传失败"; |
|
|
files.message = '上传失败'; |
|
|
console.log(err); |
|
|
console.error('文件上传失败', err?.response?.data || err); |
|
|
}); |
|
|
}); |
|
|
|
|
|
}; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const nameCorrect=(name)=>{ |
|
|
const nameCorrect=(name)=>{ |
|
|
//筛选出两个字人名
|
|
|
|
|
|
let name1=[{}]; |
|
|
let name1=[{}]; |
|
|
name1=String(name).split(" "); |
|
|
name1=String(name).split(" "); |
|
|
// console.log(name1);
|
|
|
|
|
|
if(name1[0].length==2){ |
|
|
if(name1[0].length==2){ |
|
|
if(name1.length>1){ |
|
|
if(name1.length>1){ |
|
|
return (String(name1[0]).substr(0,1)+"\u3000"+String(name1[0]).substr(1)+" "+name1[1]); |
|
|
return (String(name1[0]).substr(0,1)+"\u3000"+String(name1[0]).substr(1)+" "+name1[1]); |
|
|
@ -58,11 +60,10 @@ const nameCorrect=(name)=>{ |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 手机号加密
|
|
|
|
|
|
const encryptPhone=(num)=>{ |
|
|
const encryptPhone=(num)=>{ |
|
|
if(!/^\d{11}$/.test(num))return num; |
|
|
if(!/^\d{11}$/.test(num))return num; |
|
|
const al= num.replace(/(\d{3})\d{4}(\d{4})/, "$1****$2"); |
|
|
const al= num.replace(/(\d{3})\d{4}(\d{4})/, "$1****$2"); |
|
|
return al; |
|
|
return al; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
export{uploadFile,nameCorrect,encryptPhone}; |
|
|
export{uploadFile,nameCorrect,encryptPhone,parseUploadFilePath}; |
|
|
|