Commit d1b0f930 authored by 黄奎's avatar 黄奎

上传修改

parent 51e4fecb
......@@ -12,9 +12,11 @@
"dependencies": {
"@quasar/extras": "^1.0.0",
"@riophae/vue-treeselect": "^0.4.0",
"ali-oss": "^6.12.0",
"axios": "^0.18.1",
"co": "^4.6.0",
"core-js": "^3.6.5",
"cos-js-sdk-v5": "^1.1.5",
"element-ui": "^2.14.1",
"js-md5": "^0.7.3",
"lockr": "^0.8.5",
......
......@@ -18,55 +18,147 @@ export function getFontConfig() {
};
}
/**
* 文件上传配置
*/
var uploadMsg = {
//http://imgfile.oytour.com http://192.168.1.214:8130
//http://upload.oytour.com http://192.168.1.214:8120
imgDomain: "http://192.168.1.214:8130",
uploadUrl: "http://192.168.1.214:8120",
}
/**
* 自定义上传文件
*/
export function UploadSelfFile(path, file, callback) {
export function UploadSelfFile(path, file, callback, configObj) {
//用户登录缓存
var cacheInfo = JSON.parse(window.localStorage["loginUserInfo"]);
//上传配置
var uploadConfig = "";
if (cacheInfo && cacheInfo.data && cacheInfo.data.UploadConfig) {
uploadConfig = cacheInfo.data.UploadConfig;
}
console.log("uploadConfig", uploadConfig);
//获取文件扩展名
console.log("file", file);
var index = file.name.lastIndexOf(".");
var suffix = file.name.substr(index);
var timestamp1 = Date.parse(new Date()) + "_" + (Math.ceil(Math.random() * 1000));
let str = '/Test';
var newPath = "/EduSystem" + str + '/Upload/' + path;
Loading.show({
message: '正在上传文件,请稍后...'
})
var newPath = '/Upload/' + path + "/";
let url = uploadMsg.uploadUrl + "/Upload?filePath=" + newPath;
// if (isTrans && isTrans == 1) {
// url += "&isTrans=1"
// }
if (uploadConfig) {
switch (uploadConfig.StoreType) {
//上传文件到腾讯云
case 1:
newPath += "/" + timestamp1 + "" + suffix;
UploadFileToTencent(uploadConfig, newPath, file, callback);
break;
//上传文件到阿里云
case 2:
newPath += "/" + timestamp1 + "" + suffix;
UploadFileToALi(uploadConfig, newPath, file, callback);
break;
//上传文件到自己文件服务器
case 3:
UploadFileToSystem(uploadConfig, newPath, file, callback, configObj);
break;
}
}
Loading.hide();
}
/**
* 上传文件到本地文件系统
*/
export function UploadFileToSystem(uploadConfig, fileFullPath, fileObj, successCall, configObj) {
let url = uploadConfig.UploadDomain + "/Upload?filePath=" + fileFullPath;
if (configObj) {
//是否转换图片
if (configObj.isTrans && configObj.isTrans == 1) {
url += "&isTrans=1"
}
}
let formData = new FormData()
formData.append('myfile', file)
formData.append('myfile', fileObj)
let xhr = new XMLHttpRequest()
xhr.onload = function () {
var jsonObj = JSON.parse(xhr.responseText);
if (jsonObj.StatusCode == 1 && callback) {
if (jsonObj.StatusCode == 1 && successCall) {
var tempArray = [];
if (jsonObj.OtherFile && jsonObj.OtherFile.length > 0) {
jsonObj.OtherFile.forEach(item => {
tempArray.push(uploadMsg.imgDomain + item);
tempArray.push(uploadConfig.CustomDomain + item);
})
}
Loading.hide();
var uploadResult = {
resultCode: 1,
FileName: file.name,
FileUrl: uploadMsg.imgDomain + jsonObj.FilePath,
VideoCoverImg: uploadMsg.imgDomain + jsonObj.VideoCoverImg,
Code: 1,
FileName: fileObj.name,
FileUrl: uploadConfig.CustomDomain + jsonObj.FilePath,
VideoCoverImg: uploadConfig.CustomDomain + jsonObj.VideoCoverImg,
ExtFile: tempArray
}
callback(uploadResult);
if (successCall) {
successCall(uploadResult);
}
}
}
xhr.open('post', url, true)
xhr.send(formData)
}
/**
* 上传文件到阿里云
*/
export function UploadFileToALi(uploadConfig, fileFullPath, fileObj, successCall) {
var OSS = require('ali-oss');
var oss = new OSS({
region: uploadConfig.Region,
accessKeyId: uploadConfig.SecretId,
accessKeySecret: uploadConfig.SecretKey,
bucket: uploadConfig.Bucket
})
var result = oss.multipartUpload(fileFullPath, fileObj, {
progress: function* (p) {}
}).then(res => {
var uploadResult = {
Code: 1,
FileName: fileObj.name,
FileUrl: res.res.requestUrls[0].split('?')[0].replace('http', 'https')
}
if (successCall) {
successCall(uploadResult);
}
})
}
/**
* 上传文件到腾讯云
*/
export function UploadFileToTencent(uploadConfig, fileFullPath, fileObj, successCall) {
var COS = require('cos-js-sdk-v5');
var cos = new COS({
SecretId: uploadConfig.SecretId,
SecretKey: uploadConfig.SecretKey,
});
cos.putObject({
Bucket: uploadConfig.Bucket,
Region: uploadConfig.Region, //存储桶所在地域,必须字段
Key: fileFullPath, //文件名
StorageClass: 'STANDARD',
Body: fileObj, // 上传文件对象
onProgress: function (progressData) {}
}, function (err, data) {
if (data && data.statusCode == 200) {
var uploadResult = {
Code: 1,
FileName: fileObj.name,
FileUrl: "https://" + data.Location
}
if (successCall) {
successCall(uploadResult);
}
} else {
/*上传文件异常*/
console.log(err || data);
}
});
}
/**
* 获取省市区
*/
......
......@@ -90,7 +90,7 @@
},
uploadFile(files) {
UploadSelfFile('course', files[0], res => {
if (res.resultCode == 1) {
if (res.Code == 1) {
this.objOption.CoverImg = res.FileUrl;
}
})
......
......@@ -90,7 +90,7 @@
},
uploadFile(files) {
UploadSelfFile('course', files[0], res => {
if (res.resultCode == 1) {
if (res.Code == 1) {
this.objOption.CoverImg = res.FileUrl;
}
})
......
......@@ -85,7 +85,7 @@
methods: {
uploadFile(files) {
UploadSelfFile('assistIcon', files[0], 1, res => {
if (res.resultCode == 1) {
if (res.Code == 1) {
this.objOption.PlanName = res.FileName;
this.objOption.PlanFileExtension = getFileExt(res.FileName);
this.objOption.SourceUrl = res.FileUrl;
......
......@@ -197,7 +197,7 @@
},
uploadFile(files) {
UploadSelfFile('assistIcon', files[0], res => {
if (res.resultCode == 1) {
if (res.Code == 1) {
this.objOption.AssistIcon = res.FileUrl;
}
})
......
......@@ -73,7 +73,7 @@
<div class="col-6 q-pb-lg" style="margin-top:20px;">
<q-uploader style="display: inline-block;max-height: 320px;max-width: 100%; background-repeat:no-repeat"
:style="{'background-image':'url(' + objOption.UserIcon + ')'}" max-files="1" hide-upload-btn
@rejected="onRejected" label="头像" :max-file-size="512*1024" accept=".jpg, image/*" auto-upload
@rejected="onRejected" label="头像" :max-file-size="10240*1024" accept=".jpg, image/*" auto-upload
:factory="uploadFile" no-thumbnails>
</q-uploader>
</div>
......@@ -310,7 +310,7 @@
},
uploadFile(files) {
UploadSelfFile('studentIcon', files[0], res => {
if (res.resultCode == 1) {
if (res.Code == 1) {
this.objOption.UserIcon = res.FileUrl;
}
})
......
......@@ -160,7 +160,7 @@
},
uploadFile(files) {
UploadSelfFile('studentIcon', files[0], res => {
if (res.resultCode == 1) {
if (res.Code == 1) {
this.objOption.StuIcon = res.FileUrl;
}
})
......
......@@ -267,7 +267,7 @@
},
uploadFile(files) {
UploadSelfFile('teacherIcon', files[0], res => {
if (res.resultCode == 1) {
if (res.Code == 1) {
if (this.uploadType == 1) {
this.objOption.TeacherHead = res.FileUrl;
} else if (this.uploadType == 2) {
......
......@@ -380,14 +380,14 @@
},
uploadFile(files) {
UploadSelfFile('studentIcon', files[0], res => {
if (res.resultCode == 1) {
if (res.Code == 1) {
this.NoticeBaseInfo.Image = res.FileUrl;
}
})
},
uploadFile2(files){
UploadSelfFile('studentIcon', files.file, res => {
if (res.resultCode == 1) {
if (res.Code == 1) {
let obj = {
name:res.FileName,
url:res.FileUrl,
......
......@@ -146,11 +146,9 @@
let newArr = [];
newArr.push(file.file)
UploadSelfFile('Temporary', file.file, x => {
console.log(x)
let url = x.FileUrl
this.submitFileList.push(url)
this.fileList.push({
// url: x.res.requestUrls[0].split("?")[0]
url: x.FileUrl
})
});
......
......@@ -68,7 +68,7 @@ export default {
}
return pwd;
},
Vue.prototype.md5 = md5;
Vue.prototype.md5 = md5;
//ERP本地缓存
Vue.prototype.getLocalStorage = function () {
var localStorageData = window.localStorage["loginUserInfo"];
......@@ -81,18 +81,11 @@ export default {
//域名管理对象
Vue.prototype.domainManager = function () {
let domainUrl = 'http://192.168.1.13:8083';
let uploadUrl = "http://192.168.1.214:8120"; //上传文件站点
let imgFileUrl = "http://192.168.1.214:8130"; //文件预览站点
let locationName = window.location.hostname;
if (locationName.indexOf('testerp.oytour') !== -1) {
domainUrl = "http://testapi.oytour.com";
uploadUrl = "http://upload.oytour.com";
imgFileUrl = "http://imgfile.oytour.com";
} else if (locationName.indexOf('oytour') !== -1) {
domainUrl = "http://reborn.oytour.com";
uploadUrl = "http://upload.oytour.com";
imgFileUrl = "http://imgfile.oytour.com";
}
var obj = {
//主地址
......@@ -105,13 +98,6 @@ export default {
LocalTemplateFileDownLoadUrl: domainUrl,
//本站文件流下载地址
LocalFileStreamDownLoadUrl: domainUrl + "/api/file/GetFileFromWebApi",
//PDF文件预览地址
PDFViewUrl: domainUrl + "/plug/pdf/web/viewer.html?file=",
//上传站点
UploadUrl: uploadUrl,
//文件站点
ViittoFileUrl: imgFileUrl,
};
return obj;
},
......@@ -269,6 +255,7 @@ export default {
var sorttype = type || "asc";
var results = [];
var totalSum = {};
function grouporder(source, orders, totalSum) {
source.sort(function (a, b) {
var convertA = a[orders[0]];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment