Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
foreign
/
customer-service
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
5135e8c3
authored
Dec 03, 2021
by
杨铁龙
Browse files
Options
_('Browse Files')
Download
Plain Diff
Merge branch 'master' of
http://gitlab.corp.qinqinxiaobao.com:9880/uniplat/customer-service
parents
9124b947
86f18628
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
70 additions
and
7 deletions
components/message-item/video-message.vue
service/index.ts
service/upload.ts
components/message-item/video-message.vue
View file @
5135e8c3
...
...
@@ -13,20 +13,20 @@
</
template
>
<
script
lang=
"ts"
>
import
{
Component
}
from
"vue-property-decorator"
;
import
BaseMessage
from
"./index"
;
import
VideoPlayerIcon
from
"./video-player-icon.vue"
;
import
{
Component
}
from
"vue-property-decorator"
;
import
BaseMessage
from
"./index"
;
import
VideoPlayerIcon
from
"./video-player-icon.vue"
;
@
Component
({
components
:
{
VideoPlayerIcon
}
})
export
default
class
Index
extends
BaseMessage
{
@
Component
({
components
:
{
VideoPlayerIcon
}
})
export
default
class
Index
extends
BaseMessage
{
mounted
()
{
this
.
buildMessageUrl
();
}
}
}
</
script
>
<
style
lang=
"less"
scoped
>
.video-message
{
.video-message
{
height
:
160px
;
width
:
200px
;
background-color
:
#000
!important
;
...
...
service/index.ts
0 → 100644
View file @
5135e8c3
export
*
from
"./upload"
\ No newline at end of file
service/upload.ts
View file @
5135e8c3
...
...
@@ -7,3 +7,63 @@ export async function uploadFile(file: File, uploading?: (p: number) => void) {
});
return
`
${
sdk
.
global
.
baseUrl
}${
url
}
`
;
}
export
const
enum
UploadType
{
Default
,
Image
,
Camera
}
/**
* x
* @param type UploadType 默认值 UploadType.Default
* @param size 可不传 单位M
* @returns
*/
export
function
chooseFileAndUpload
(
type
=
UploadType
.
Default
,
size
?:
number
)
{
return
chooseFile
(
type
).
then
(
r
=>
{
const
sdk
=
Chat
.
getSdk
();
return
sdk
.
uploadFileV2
(
r
)
})
}
/**
*
* @param type UploadType
* @param size 可不传 单位M
* @returns
*/
export
function
chooseFile
(
type
=
UploadType
.
Default
,
size
?:
number
)
{
return
new
Promise
<
File
>
((
resolve
,
reject
)
=>
{
const
target
=
document
.
createElement
(
'input'
);
target
.
setAttribute
(
'type'
,
'file'
);
// 添加这个属性,就可以唤起相机的功能
(
type
===
UploadType
.
Camera
)
&&
target
.
setAttribute
(
'capture'
,
'camera'
);
// 这里如果不加属性 accept 是 "image/*" 或者 "video/*",就默认打开摄像头,既可以拍照也可以录像
(
type
===
UploadType
.
Image
)
&&
target
.
setAttribute
(
'accept'
,
'image/*'
);
target
.
setAttribute
(
'style'
,
'display:none'
);
// 监听改变事件
target
.
addEventListener
(
'change'
,
(
e
:
Event
)
=>
{
// 拿到文件对象
if
(
e
&&
e
.
target
)
{
const
t
=
e
.
target
as
HTMLInputElement
;
const
{
files
}
=
t
;
if
(
files
)
{
// 返回的是一个文件对象
if
(
size
&&
files
[
0
].
size
>=
size
*
1024
*
1024
)
{
reject
(
`上传的
${
type
===
UploadType
.
Default
?
"文件"
:
"图片"
}
太大了~`
);
return
;
}
resolve
(
files
[
0
]);
setTimeout
(()
=>
target
.
remove
(),
200
);
return
;
}
}
reject
(
new
Error
(
'系统不支持'
));
setTimeout
(()
=>
target
.
remove
(),
200
);
});
document
.
body
.
appendChild
(
target
);
// 这里是模拟点击了input控件
target
.
click
();
});
}
\ 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