|
|
|
|
import {_form, _post} from '../http/index'
|
|
|
|
|
import { baseUrl } from "../config/env";
|
|
|
|
|
import axios from 'axios';
|
|
|
|
|
const http = axios.create({
|
|
|
|
|
traditional: true,
|
|
|
|
|
contentType : "application/json",
|
|
|
|
|
timeout: 1000 * 500000, // 1 秒
|
|
|
|
|
});
|
|
|
|
|
const uploadFile = (files,callback) => {
|
|
|
|
|
files.status = "uploading";
|
|
|
|
|
files.message = "上传中...";
|
|
|
|
|
files.status = "uploading";
|
|
|
|
|
// 需要使用 FormData 进行文件上传
|
|
|
|
|
let form = new FormData();
|
|
|
|
|
form.append("file", files.file);
|
|
|
|
|
|
|
|
|
|
// 获取 token(从 localStorage 或 sessionStorage 中获取)
|
|
|
|
|
|
|
|
|
|
const token = $globalStore.useCommon.token;
|
|
|
|
|
console.log(token);
|
|
|
|
|
axios({
|
|
|
|
|
method: "post",
|
|
|
|
|
url: baseUrl+ "/app-enf/common/file/upload",
|
|
|
|
|
data: form,
|
|
|
|
|
headers: {
|
|
|
|
|
'clientid': 'f0535c2a32ab4d0496ab9a699b2a7d36',
|
|
|
|
|
'Authorization': 'Bearer ' + token
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.then((res) => {
|
|
|
|
|
files.status = "done";
|
|
|
|
|
files.message = "上传成功";
|
|
|
|
|
console.log(res);
|
|
|
|
|
callback && callback(res);
|
|
|
|
|
})
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
files.status = "failed";
|
|
|
|
|
files.message = "上传失败";
|
|
|
|
|
console.log(err);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const nameCorrect=(name)=>{
|
|
|
|
|
//筛选出两个字人名
|
|
|
|
|
let name1=[{}];
|
|
|
|
|
name1=String(name).split(" ");
|
|
|
|
|
// console.log(name1);
|
|
|
|
|
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};
|