Commit f84927b8 authored by zhengke's avatar zhengke

no message

parent 76abc980
...@@ -32,56 +32,38 @@ export let urlTobase64 = (file, suc) => { ...@@ -32,56 +32,38 @@ export let urlTobase64 = (file, suc) => {
* 上传文件 * 上传文件
*/ */
export function UploadSelfFile(path, file, callback, configObj) { export function UploadSelfFile(path, file, callback, configObj) {
//用户登录缓存 if (file.url.indexOf('.excel') == -1) {
var cacheInfo = uni.getStorageSync("userInfo") uni.showToast({
//上传配置 title: '请上传 excel 格式文件',
var uploadConfig = ""; icon:'none',
if (cacheInfo && cacheInfo.UploadConfig) { duration: 2000
uploadConfig = cacheInfo.UploadConfig; });
return false;
} }
//获取文件扩展名
var index = file.url.lastIndexOf(".");
var suffix = file.url.substr(index);
var timestamp1 = Date.parse(new Date()) + "_" + (Math.ceil(Math.random() * 1000));
let str = '/Test';
var newPath = "/EduSystem" + str + '/Upload/' + path;
uni.showLoading({ uni.showLoading({
title: '文件上传中...' title: '文件上传中...'
}); });
if (uploadConfig) { UploadFileToSystem(uploadConfig, newPath, file, callback, configObj);
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;
}
}
} }
/** /**
* 上传文件到本地文件系统 * 上传文件到本地文件系统
*/ */
export function UploadFileToSystem(uploadConfig, fileFullPath, fileObj, successCall, configObj) { export function UploadFileToSystem(uploadConfig, fileFullPath, fileObj, successCall, configObj) {
let url = uploadConfig.UploadDomain + "/Upload?filePath=" + fileFullPath; // let url = uploadConfig.UploadDomain + "/Upload?filePath=" + fileFullPath;
if (configObj) { console.log(fileFullPath,'------===')
//是否转换图片 let host = ''
if (configObj.isTrans && configObj.isTrans == 1) { if (process.env.NODE_ENV === "development") {
url += "&isTrans=1" host = 'http://192.168.10.36:8082/api'
} } else {
if (configObj.isCreateCover && configObj.isCreateCover == 1) { host = 'https://eduapi.oytour.com/api'
url += "&isCreateCover=1" }
} let params = {
Uid:1,
CourseId:1,
ExamName:''
} }
let url = host + "/Upload/UploadStuExamScore?Files=" + fileObj +'&params=' + JSON.stringify(params) ;
uni.uploadFile({ uni.uploadFile({
url: url, url: url,
filePath: fileObj.url, filePath: fileObj.url,
...@@ -90,6 +72,8 @@ export function UploadFileToSystem(uploadConfig, fileFullPath, fileObj, successC ...@@ -90,6 +72,8 @@ export function UploadFileToSystem(uploadConfig, fileFullPath, fileObj, successC
'myfile': fileObj 'myfile': fileObj
}, },
success(res) { success(res) {
uni.hideLoading();
return
uni.hideLoading(); uni.hideLoading();
let jsonObj = JSON.parse(res.data) let jsonObj = JSON.parse(res.data)
let index = jsonObj.FilePath.indexOf(".") let index = jsonObj.FilePath.indexOf(".")
...@@ -104,6 +88,7 @@ export function UploadFileToSystem(uploadConfig, fileFullPath, fileObj, successC ...@@ -104,6 +88,7 @@ export function UploadFileToSystem(uploadConfig, fileFullPath, fileObj, successC
successCall(uploadResult); successCall(uploadResult);
}, },
fail(err) { fail(err) {
uni.hideLoading();
console.log("uploadErr", err) console.log("uploadErr", err)
} }
}); });
......
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