Commit d1b0f930 authored by 黄奎's avatar 黄奎

上传修改

parent 51e4fecb
...@@ -12,9 +12,11 @@ ...@@ -12,9 +12,11 @@
"dependencies": { "dependencies": {
"@quasar/extras": "^1.0.0", "@quasar/extras": "^1.0.0",
"@riophae/vue-treeselect": "^0.4.0", "@riophae/vue-treeselect": "^0.4.0",
"ali-oss": "^6.12.0",
"axios": "^0.18.1", "axios": "^0.18.1",
"co": "^4.6.0", "co": "^4.6.0",
"core-js": "^3.6.5", "core-js": "^3.6.5",
"cos-js-sdk-v5": "^1.1.5",
"element-ui": "^2.14.1", "element-ui": "^2.14.1",
"js-md5": "^0.7.3", "js-md5": "^0.7.3",
"lockr": "^0.8.5", "lockr": "^0.8.5",
......
...@@ -18,55 +18,147 @@ export function getFontConfig() { ...@@ -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({ Loading.show({
message: '正在上传文件,请稍后...' message: '正在上传文件,请稍后...'
}) })
var newPath = '/Upload/' + path + "/"; if (uploadConfig) {
let url = uploadMsg.uploadUrl + "/Upload?filePath=" + newPath; switch (uploadConfig.StoreType) {
// if (isTrans && isTrans == 1) { //上传文件到腾讯云
// url += "&isTrans=1" 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() let formData = new FormData()
formData.append('myfile', file) formData.append('myfile', fileObj)
let xhr = new XMLHttpRequest() let xhr = new XMLHttpRequest()
xhr.onload = function () { xhr.onload = function () {
var jsonObj = JSON.parse(xhr.responseText); var jsonObj = JSON.parse(xhr.responseText);
if (jsonObj.StatusCode == 1 && callback) { if (jsonObj.StatusCode == 1 && successCall) {
var tempArray = []; var tempArray = [];
if (jsonObj.OtherFile && jsonObj.OtherFile.length > 0) { if (jsonObj.OtherFile && jsonObj.OtherFile.length > 0) {
jsonObj.OtherFile.forEach(item => { jsonObj.OtherFile.forEach(item => {
tempArray.push(uploadMsg.imgDomain + item); tempArray.push(uploadConfig.CustomDomain + item);
}) })
} }
Loading.hide();
var uploadResult = { var uploadResult = {
resultCode: 1, Code: 1,
FileName: file.name, FileName: fileObj.name,
FileUrl: uploadMsg.imgDomain + jsonObj.FilePath, FileUrl: uploadConfig.CustomDomain + jsonObj.FilePath,
VideoCoverImg: uploadMsg.imgDomain + jsonObj.VideoCoverImg, VideoCoverImg: uploadConfig.CustomDomain + jsonObj.VideoCoverImg,
ExtFile: tempArray ExtFile: tempArray
} }
callback(uploadResult); if (successCall) {
successCall(uploadResult);
}
} }
} }
xhr.open('post', url, true) xhr.open('post', url, true)
xhr.send(formData) 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 @@ ...@@ -90,7 +90,7 @@
}, },
uploadFile(files) { uploadFile(files) {
UploadSelfFile('course', files[0], res => { UploadSelfFile('course', files[0], res => {
if (res.resultCode == 1) { if (res.Code == 1) {
this.objOption.CoverImg = res.FileUrl; this.objOption.CoverImg = res.FileUrl;
} }
}) })
......
...@@ -90,7 +90,7 @@ ...@@ -90,7 +90,7 @@
}, },
uploadFile(files) { uploadFile(files) {
UploadSelfFile('course', files[0], res => { UploadSelfFile('course', files[0], res => {
if (res.resultCode == 1) { if (res.Code == 1) {
this.objOption.CoverImg = res.FileUrl; this.objOption.CoverImg = res.FileUrl;
} }
}) })
......
...@@ -85,7 +85,7 @@ ...@@ -85,7 +85,7 @@
methods: { methods: {
uploadFile(files) { uploadFile(files) {
UploadSelfFile('assistIcon', files[0], 1, res => { UploadSelfFile('assistIcon', files[0], 1, res => {
if (res.resultCode == 1) { if (res.Code == 1) {
this.objOption.PlanName = res.FileName; this.objOption.PlanName = res.FileName;
this.objOption.PlanFileExtension = getFileExt(res.FileName); this.objOption.PlanFileExtension = getFileExt(res.FileName);
this.objOption.SourceUrl = res.FileUrl; this.objOption.SourceUrl = res.FileUrl;
......
...@@ -197,7 +197,7 @@ ...@@ -197,7 +197,7 @@
}, },
uploadFile(files) { uploadFile(files) {
UploadSelfFile('assistIcon', files[0], res => { UploadSelfFile('assistIcon', files[0], res => {
if (res.resultCode == 1) { if (res.Code == 1) {
this.objOption.AssistIcon = res.FileUrl; this.objOption.AssistIcon = res.FileUrl;
} }
}) })
......
...@@ -73,7 +73,7 @@ ...@@ -73,7 +73,7 @@
<div class="col-6 q-pb-lg" style="margin-top:20px;"> <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" <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 :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> :factory="uploadFile" no-thumbnails>
</q-uploader> </q-uploader>
</div> </div>
...@@ -310,7 +310,7 @@ ...@@ -310,7 +310,7 @@
}, },
uploadFile(files) { uploadFile(files) {
UploadSelfFile('studentIcon', files[0], res => { UploadSelfFile('studentIcon', files[0], res => {
if (res.resultCode == 1) { if (res.Code == 1) {
this.objOption.UserIcon = res.FileUrl; this.objOption.UserIcon = res.FileUrl;
} }
}) })
......
...@@ -160,7 +160,7 @@ ...@@ -160,7 +160,7 @@
}, },
uploadFile(files) { uploadFile(files) {
UploadSelfFile('studentIcon', files[0], res => { UploadSelfFile('studentIcon', files[0], res => {
if (res.resultCode == 1) { if (res.Code == 1) {
this.objOption.StuIcon = res.FileUrl; this.objOption.StuIcon = res.FileUrl;
} }
}) })
......
...@@ -267,7 +267,7 @@ ...@@ -267,7 +267,7 @@
}, },
uploadFile(files) { uploadFile(files) {
UploadSelfFile('teacherIcon', files[0], res => { UploadSelfFile('teacherIcon', files[0], res => {
if (res.resultCode == 1) { if (res.Code == 1) {
if (this.uploadType == 1) { if (this.uploadType == 1) {
this.objOption.TeacherHead = res.FileUrl; this.objOption.TeacherHead = res.FileUrl;
} else if (this.uploadType == 2) { } else if (this.uploadType == 2) {
......
...@@ -380,14 +380,14 @@ ...@@ -380,14 +380,14 @@
}, },
uploadFile(files) { uploadFile(files) {
UploadSelfFile('studentIcon', files[0], res => { UploadSelfFile('studentIcon', files[0], res => {
if (res.resultCode == 1) { if (res.Code == 1) {
this.NoticeBaseInfo.Image = res.FileUrl; this.NoticeBaseInfo.Image = res.FileUrl;
} }
}) })
}, },
uploadFile2(files){ uploadFile2(files){
UploadSelfFile('studentIcon', files.file, res => { UploadSelfFile('studentIcon', files.file, res => {
if (res.resultCode == 1) { if (res.Code == 1) {
let obj = { let obj = {
name:res.FileName, name:res.FileName,
url:res.FileUrl, url:res.FileUrl,
......
...@@ -146,11 +146,9 @@ ...@@ -146,11 +146,9 @@
let newArr = []; let newArr = [];
newArr.push(file.file) newArr.push(file.file)
UploadSelfFile('Temporary', file.file, x => { UploadSelfFile('Temporary', file.file, x => {
console.log(x)
let url = x.FileUrl let url = x.FileUrl
this.submitFileList.push(url) this.submitFileList.push(url)
this.fileList.push({ this.fileList.push({
// url: x.res.requestUrls[0].split("?")[0]
url: x.FileUrl url: x.FileUrl
}) })
}); });
......
...@@ -81,18 +81,11 @@ export default { ...@@ -81,18 +81,11 @@ export default {
//域名管理对象 //域名管理对象
Vue.prototype.domainManager = function () { Vue.prototype.domainManager = function () {
let domainUrl = 'http://192.168.1.13:8083'; 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; let locationName = window.location.hostname;
if (locationName.indexOf('testerp.oytour') !== -1) { if (locationName.indexOf('testerp.oytour') !== -1) {
domainUrl = "http://testapi.oytour.com"; domainUrl = "http://testapi.oytour.com";
uploadUrl = "http://upload.oytour.com";
imgFileUrl = "http://imgfile.oytour.com";
} else if (locationName.indexOf('oytour') !== -1) { } else if (locationName.indexOf('oytour') !== -1) {
domainUrl = "http://reborn.oytour.com"; domainUrl = "http://reborn.oytour.com";
uploadUrl = "http://upload.oytour.com";
imgFileUrl = "http://imgfile.oytour.com";
} }
var obj = { var obj = {
//主地址 //主地址
...@@ -105,13 +98,6 @@ export default { ...@@ -105,13 +98,6 @@ export default {
LocalTemplateFileDownLoadUrl: domainUrl, LocalTemplateFileDownLoadUrl: domainUrl,
//本站文件流下载地址 //本站文件流下载地址
LocalFileStreamDownLoadUrl: domainUrl + "/api/file/GetFileFromWebApi", LocalFileStreamDownLoadUrl: domainUrl + "/api/file/GetFileFromWebApi",
//PDF文件预览地址
PDFViewUrl: domainUrl + "/plug/pdf/web/viewer.html?file=",
//上传站点
UploadUrl: uploadUrl,
//文件站点
ViittoFileUrl: imgFileUrl,
}; };
return obj; return obj;
}, },
...@@ -269,6 +255,7 @@ export default { ...@@ -269,6 +255,7 @@ export default {
var sorttype = type || "asc"; var sorttype = type || "asc";
var results = []; var results = [];
var totalSum = {}; var totalSum = {};
function grouporder(source, orders, totalSum) { function grouporder(source, orders, totalSum) {
source.sort(function (a, b) { source.sort(function (a, b) {
var convertA = a[orders[0]]; 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