Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
江名洋
/
linkwe-scrm
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 0312d6f1
authored
Mar 30, 2023
by
姜鹏凯
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
上传方式支持本地
1 parent
632dcb68
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
47 additions
and
2 deletions
linkwe-pc/src/components/UploadToCos.vue
linkwe-pc/src/components/UploadToCos.vue
View file @
0312d6f
<
script
>
<
script
>
import
{
getCosConfig
,
getVideoPic
}
from
'@/api/common'
import
{
getCosConfig
,
getVideoPic
,
upload
}
from
'@/api/common'
import
{
dateFormat
,
uuid
}
from
'@/utils/index'
import
{
dateFormat
,
uuid
}
from
'@/utils/index'
// import Video from 'video.js'
// import Video from 'video.js'
import
Cos
from
'cos-js-sdk-v5'
import
Cos
from
'cos-js-sdk-v5'
...
@@ -131,11 +131,13 @@
...
@@ -131,11 +131,13 @@
created
()
{
created
()
{
getCosConfig
().
then
((
res
)
=>
{
getCosConfig
().
then
((
res
)
=>
{
this
.
cosConfig
=
res
this
.
cosConfig
=
res
console
.
log
(
this
.
cosConfig
)
if
(
this
.
cosConfig
.
fileObject
==
'tencentOss'
)
{
if
(
this
.
cosConfig
.
fileObject
==
'tencentOss'
)
{
this
.
cosInstance
=
new
Cos
({
this
.
cosInstance
=
new
Cos
({
SecretId
:
res
.
secretId
,
SecretId
:
res
.
secretId
,
SecretKey
:
res
.
secretKey
SecretKey
:
res
.
secretKey
})
})
}
else
if
(
this
.
cosConfig
.
fileObject
==
'local'
)
{
}
else
{
}
else
{
let
region
=
this
.
cosConfig
.
region
.
split
(
'//'
)[
1
]
let
region
=
this
.
cosConfig
.
region
.
split
(
'//'
)[
1
]
this
.
ossObj
=
new
OSS
({
this
.
ossObj
=
new
OSS
({
...
@@ -187,10 +189,53 @@
...
@@ -187,10 +189,53 @@
upload
()
{
upload
()
{
if
(
this
.
cosConfig
.
fileObject
==
'tencentOss'
)
{
if
(
this
.
cosConfig
.
fileObject
==
'tencentOss'
)
{
this
.
tencentFn
()
this
.
tencentFn
()
}
else
{
}
else
if
(
this
.
cosConfig
.
fileObject
==
'local'
)
{
this
.
localFn
()
}
else
if
(
this
.
cosConfig
.
fileObject
==
'aliOss'
)
{
this
.
aliOss
()
this
.
aliOss
()
}
}
},
},
localFn
()
{
this
.
loading
=
true
let
file
=
undefined
if
(
!
this
.
multiple
||
this
.
limit
==
1
)
{
file
=
this
.
file
}
else
{
// 多选上传是多次调用单传的
file
=
this
.
file
.
shift
()
}
let
formData
=
new
FormData
()
formData
.
append
(
'file'
,
file
)
upload
(
formData
).
then
((
dd
)
=>
{
if
(
dd
.
code
==
200
)
{
let
location
=
dd
.
data
.
url
this
.
$emit
(
'upSuccess'
,
location
)
this
.
type
==
2
?
//获取视频第一帧画面
getVideoPic
({
url
:
location
}).
then
((
res
)
=>
{
this
.
loading
=
false
this
.
$emit
(
'getPicUrl'
,
res
.
data
.
url
)
})
:
(
this
.
loading
=
false
)
// 使用本地链接提供预览,避免上传后下载的问题
let
url
=
window
.
URL
.
createObjectURL
(
file
)
let
name
=
file
.
name
if
(
!
this
.
multiple
)
{
this
.
fileUrlWatch
=
url
this
.
$emit
(
'update:fileUrl'
,
location
)
this
.
$emit
(
'update:fileName'
,
(
this
.
fileNameWatch
=
name
))
}
else
{
this
.
fileListWatch
=
this
.
fileListWatch
.
concat
({
name
,
url
})
this
.
$emit
(
'update:fileList'
,
this
.
fileList
.
concat
({
name
,
url
:
location
}))
}
}
else
{
this
.
loading
=
false
this
.
$message
.
error
(
'上传失败,请稍后再试'
)
}
})
},
async
aliOss
()
{
async
aliOss
()
{
this
.
loading
=
true
this
.
loading
=
true
let
file
=
undefined
let
file
=
undefined
...
...
Write
Preview
Markdown
is supported
Attach a file
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 post a comment