Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
H
horse
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
向伟
horse
Commits
b7463bfe
Commit
b7463bfe
authored
Nov 22, 2021
by
zhengke
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1
parent
91312517
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
115 additions
and
0 deletions
+115
-0
common.ts
src/utils/common.ts
+115
-0
No files found.
src/utils/common.ts
0 → 100644
View file @
b7463bfe
import
{
Loading
}
from
'quasar'
interface
itemParams
{
[
propName
:
string
]:
any
}
/**
* 配置相关
*/
export
function
CommonConfig
()
{
return
{
FileConfig
:
{
FileUrl
:
'http://192.168.10.214:8130'
,
//本地服务器文件预览地址
UploadUrl
:
"http://192.168.10.214:8120"
,
//本地上传文件地址
}
}
}
/**
* 上传文件
*/
export
function
UploadSelfFile
(
path
,
file
,
callback
,
configObj
)
{
//用户登录缓存
const
cacheInfo
:
itemParams
=
JSON
.
parse
(
window
.
localStorage
[
"loginUserInfo"
]);
//上传配置
let
uploadConfig
:
itemParams
=
{};
if
(
cacheInfo
&&
cacheInfo
.
data
&&
cacheInfo
.
data
.
UploadConfig
)
{
uploadConfig
=
cacheInfo
.
data
.
UploadConfig
;
}
//获取文件扩展名
// const index:string = file.name.lastIndexOf(".");
// let suffix:string = file.name.substr(index);
// const MyDate:any = new Date()
// var timestamp1 = Date.parse(MyDate) + "_" + (Math.ceil(Math.random() * 1000));
const
str
=
'/Test'
;
const
newPath
=
"/EduSystem"
+
str
+
'/Upload/'
+
path
;
const
uploadLoadding
=
Loading
;
uploadLoadding
.
show
({
message
:
'正在上传文件,请稍后...'
})
if
(
uploadConfig
)
{
switch
(
uploadConfig
.
StoreType
)
{
//上传文件到腾讯云
// case 1:
// newPath += "/" + timestamp1 + "" + suffix;
// UploadFileToTencent(uploadConfig, newPath, file, uploadLoadding, callback);
// break;
// //上传文件到阿里云
// case 2:
// newPath += "/" + timestamp1 + "" + suffix;
// UploadFileToALi(uploadConfig, newPath, file, uploadLoadding, callback);
// break;
//上传文件到自己文件服务器
case
3
:
UploadFileToSystem
(
uploadConfig
,
newPath
,
file
,
uploadLoadding
,
callback
,
configObj
);
break
;
}
}
}
/**
* 上传文件到本地文件系统
*/
export
function
UploadFileToSystem
(
uploadConfig
,
fileFullPath
,
fileObj
,
uploadLoadding
,
successCall
,
configObj
)
{
const
fileConfig
:
itemParams
=
CommonConfig
();
const
locationName
:
string
=
window
.
location
.
hostname
;
if
(
locationName
.
indexOf
(
'localhost'
)
!==
-
1
)
{
uploadConfig
.
UploadDomain
=
fileConfig
.
FileConfig
.
UploadUrl
;
uploadConfig
.
CustomDomain
=
fileConfig
.
FileConfig
.
FileUrl
;
}
let
url
=
uploadConfig
.
UploadDomain
+
"/Upload?filePath="
+
fileFullPath
;
if
(
configObj
)
{
//是否转换图片
if
(
configObj
.
isTrans
&&
configObj
.
isTrans
==
1
)
{
url
+=
"&isTrans=1"
}
if
(
configObj
.
isCreateCover
&&
configObj
.
isCreateCover
==
1
)
{
url
+=
"&isCreateCover=1"
}
}
const
formData
=
new
FormData
()
formData
.
append
(
'myfile'
,
fileObj
)
const
xhr
=
new
XMLHttpRequest
()
xhr
.
onload
=
function
()
{
uploadLoadding
.
hide
();
const
jsonObj
:
itemParams
=
JSON
.
parse
(
xhr
.
responseText
);
if
(
jsonObj
.
StatusCode
===
1
&&
successCall
)
{
const
tempArray
:
any
=
[];
if
(
jsonObj
.
OtherFile
&&
jsonObj
.
OtherFile
.
length
>
0
)
{
jsonObj
.
OtherFile
.
forEach
(
item
=>
{
tempArray
.
push
(
uploadConfig
.
CustomDomain
+
item
);
})
}
const
uploadResult
:
itemParams
=
{
Code
:
1
,
FileName
:
fileObj
.
name
,
FileUrl
:
uploadConfig
.
CustomDomain
+
jsonObj
.
FilePath
,
VideoCoverImg
:
uploadConfig
.
CustomDomain
+
jsonObj
.
VideoCoverImg
,
ExtFile
:
tempArray
}
if
(
successCall
)
{
successCall
(
uploadResult
);
}
}
}
xhr
.
open
(
'post'
,
url
,
true
)
xhr
.
send
(
formData
)
}
// export function UploadFileToTencent(){
// }
// export function UploadFileToALi(){
// }
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment