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 b3903e54
authored
Nov 28, 2022
by
xinla
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
用新的cos上传替换旧的上传组件
1 parent
cac4a044
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
497 additions
and
269 deletions
linkwe-pc/package.json
linkwe-pc/src/api/common.js
linkwe-pc/src/components/TagEllipsis.vue
linkwe-pc/src/components/Upload.vue
linkwe-pc/src/utils/jsencrypt.js
linkwe-pc/package.json
View file @
b3903e5
...
@@ -48,7 +48,7 @@
...
@@ -48,7 +48,7 @@
"benz-amr-recorder"
:
"^1.1.3"
,
"benz-amr-recorder"
:
"^1.1.3"
,
"clipboard"
:
"2.0.4"
,
"clipboard"
:
"2.0.4"
,
"core-js"
:
"^3.20.2"
,
"core-js"
:
"^3.20.2"
,
"cos-js-sdk-v5"
:
"^1.4.1
1
"
,
"cos-js-sdk-v5"
:
"^1.4.1
3
"
,
"crypto-js"
:
"^4.1.1"
,
"crypto-js"
:
"^4.1.1"
,
"driver.js"
:
"^0.9.8"
,
"driver.js"
:
"^0.9.8"
,
"echarts"
:
"^5.3.0"
,
"echarts"
:
"^5.3.0"
,
...
...
linkwe-pc/src/api/common.js
View file @
b3903e5
import
{
decryptAES
}
from
'@/utils/jsencrypt'
import
request
from
'@/utils/request'
import
request
from
'@/utils/request'
import
{
dataURLtoFile
}
from
'@/utils/common'
import
{
dataURLtoFile
}
from
'@/utils/common'
...
@@ -11,6 +12,28 @@ export function upload(data) {
...
@@ -11,6 +12,28 @@ export function upload(data) {
})
})
}
}
// 获取cos配置
export
function
getCosConfig
(
data
)
{
return
request
({
url
:
service
+
'/file/get/config'
,
params
:
data
,
}).
then
(({
data
})
=>
{
let
res
=
{}
Object
.
keys
(
data
).
forEach
((
key
)
=>
{
res
[
key
]
=
decryptAES
(
data
[
key
])
})
return
res
})
}
// 获取视频第一帧
export
function
getVideoPic
(
params
)
{
return
request
({
url
:
window
.
lwConfig
.
services
.
system
+
'/file/getVideoFirstImg/'
,
params
,
})
}
/**
/**
* 下载网络连接文件
* 下载网络连接文件
* @param {*} params
* @param {*} params
...
@@ -20,11 +43,7 @@ export function upload(data) {
...
@@ -20,11 +43,7 @@ export function upload(data) {
}
}
*/
*/
export
function
download
(
url
,
name
)
{
export
function
download
(
url
,
name
)
{
return
(
return
window
.
lwConfig
.
DOMAIN
+
window
.
lwConfig
.
services
.
system
+
`/common/download/url?url=
${
url
}
&name=
${
name
}
`
window
.
lwConfig
.
DOMAIN
+
window
.
lwConfig
.
services
.
system
+
`/common/download/url?url=
${
url
}
&name=
${
name
}
`
)
}
}
/**
/**
...
...
linkwe-pc/src/components/TagEllipsis.vue
View file @
b3903e5
...
@@ -59,5 +59,8 @@ export default {
...
@@ -59,5 +59,8 @@ export default {
.tag-ellipsis
{
.tag-ellipsis
{
display
:
inline-block
;
display
:
inline-block
;
line-height
:
34px
;
line-height
:
34px
;
.el-tag
{
vertical-align
:
middle
;
}
}
}
</
style
>
</
style
>
linkwe-pc/src/components/Upload.vue
View file @
b3903e5
<
script
>
<
script
>
import
{
upload
}
from
'@/api/material'
import
{
getCosConfig
,
getVideoPic
}
from
'@/api/common'
import
Video
from
'video.js'
import
{
dateFormat
,
uuid
}
from
'@/utils/index'
import
BenzAMRRecorder
from
'benz-amr-recorder'
import
Video
from
'video.js'
import
MP4Box
from
'mp4box'
import
Cos
from
'cos-js-sdk-v5'
import
BenzAMRRecorder
from
'benz-amr-recorder'
import
MP4Box
from
'mp4box'
export
default
{
export
default
{
name
:
'Upload'
,
components
:
{},
components
:
{},
props
:
{
props
:
{
// 单文件上传时使用
fileUrl
:
{
fileUrl
:
{
type
:
String
,
type
:
String
,
default
:
''
default
:
''
,
},
fileUrls
:
{
type
:
Array
,
default
:
null
},
},
fileName
:
{
fileName
:
{
type
:
String
,
type
:
String
,
default
:
''
default
:
''
,
},
},
fileNames
:
{
// 多文件上传时使用,例如: [{name: 'food.jpg', url: 'https://xxx.cdn.com/xxx.jpg'}]
fileList
:
{
type
:
Array
,
type
:
Array
,
default
:
()
=>
[]
default
:
()
=>
[],
},
// 监视弹框显示隐藏
dalogChange
:
{
type
:
Boolean
,
default
:
false
},
},
// 0 图片(image)、1 语音(voice)、2 视频(video),3 普通文件(file)
// 0 图片(image)、1 语音(voice)、2 视频(video),3 普通文件(file)
type
:
{
type
:
{
type
:
String
,
type
:
String
,
default
:
'0'
default
:
'0'
,
validator
:
function
(
value
)
{
// 这个值必须匹配下列字符串中的一个
return
[
'0'
,
'1'
,
'2'
,
'3'
].
includes
(
value
)
},
},
// 上传文件大小不能超过 maxSize MB
},
// 上传文件大小不能超过 maxSize MB, 各类型有默认限制 参见: maxSizeDefault
maxSize
:
{
maxSize
:
{
type
:
Number
,
type
:
Number
,
default
:
2
default
:
undefined
,
},
},
// 图片的宽高像素限制 [width(number), height(number)],默认null不限制
// 图片的宽高像素限制 [width(number), height(number)],默认null不限制
maxImgPx
:
{
maxImgPx
:
{
type
:
Array
,
type
:
Array
,
default
:
null
// () => [100, 100]
default
:
null
,
// () => [100, 100]
},
},
// 限制允许上传的文件格式 eg:["bmp", "jpg", "png", "jpeg", "gif"]
// 允许上传的文件格式后缀名 eg:["jpg", "png"],['*']为不限制,各类型有默认限制 参见: formatDefault
format
:
{
format
:
{
type
:
Array
,
type
:
Array
,
default
:
null
default
:
undefined
,
},
// 选择上传文件类型, 用于过滤系统选择文件类型, 默认根据类型自动匹配:见 acceptAuto,
accept
:
{
type
:
String
,
default
:
''
,
},
},
// 是否能上传多个
// 是否能上传多个
multiple
:
{
multiple
:
{
type
:
Boolean
,
type
:
Boolean
,
default
:
false
default
:
false
,
},
},
// 最多上传几个
// multiple为true是有效,最多上传几个,默认不限制,最小为1,大于1是自动开启可多选,
limit
:
{
limit
:
{
type
:
Number
,
type
:
Number
,
default
:
1
default
:
undefined
,
},
},
// 是否限制文件只能上传word/pdf/ppt
// onProgress: {
isThree
:
{
// type: Function,
type
:
Boolean
,
// default: null,
default
:
false
// },
}
// beforeUpload: {
// beforeUpload: {
// type: Function,
// type: Function,
// default: function() {
// default: function() {
// return function() {}
// return function() {}
// },
// },
// },
// },
// 图片操作 目前支持有 view:查看,remove:删除,download:下载
// action: {
// type: Array,
// default: () => ["view", "remove"],
// },
},
},
data
()
{
data
()
{
return
{
return
{
loading
:
false
,
loading
:
false
,
action
:
window
.
lwConfig
.
BASE_API
+
'/file/upload'
,
// (this.type == 0
// ? '/wecom/material/uploadimg'
// : '/common/uploadFile2Cos'),
headers
:
window
.
lwConfig
.
headers
,
// domain: window.lwConfig.BASE_API
dialogImageUrl
:
''
,
fileUrlWatch
:
this
.
fileUrl
,
dialogVisible
:
fals
e
,
fileNameWatch
:
this
.
fileNam
e
,
urls
:
[]
,
fileListWatch
:
this
.
fileList
,
names
:
[],
// 批量上传图片名称
picUrl
:
''
,
// 视频第一帧
picUrl
:
''
,
// 视频第一帧
fileList
:
[]
file
:
undefined
,
speed
:
0
,
// 上传网速
percentage
:
0
,
//上传进度
// cos配置信息
cosConfig
:
{
bucketName
:
''
,
cosImgUrlPrefix
:
''
,
region
:
''
},
cosInstance
:
undefined
,
// cos实例
}
}
},
},
watch
:
{
watch
:
{
fileUrls
:
{
fileUrl
:
{
handler
(
value
)
{
handler
(
value
)
{
this
.
names
=
this
.
fileNames
this
.
fileUrlWatch
=
value
this
.
urls
=
value
},
},
immediate
:
true
},
},
fileUrl
:
{
fileName
:
{
handler
(
value
)
{
handler
(
value
)
{
if
(
this
.
$refs
.
video
)
{
this
.
fileNameWatch
=
value
this
.
$refs
.
video
.
src
=
value
},
}
},
}
loading
(
val
)
{
this
.
$emit
(
'loadingChange'
,
val
)
},
},
dalogChange
(
val
)
{
this
.
$refs
.
multPic
.
clearFiles
()
}
},
},
computed
:
{
computed
:
{
accept
()
{
// 识别选择文件类型
return
[
'image/*'
,
'amr/*'
,
'video/*'
,
'*'
][
this
.
type
]
acceptAuto
()
{
}
return
[
'image/*'
,
'amr/*'
,
'video/*'
][
this
.
type
]
},
},
created
()
{
getCosConfig
().
then
((
res
)
=>
{
this
.
cosConfig
=
res
this
.
cosInstance
=
new
Cos
({
SecretId
:
res
.
secretId
,
SecretKey
:
res
.
secretKey
,
})
})
},
mounted
()
{
// const cosInstance = new Cos({
// // getAuthorization 必选参数
// getAuthorization: function (options, callback) {
// // 服务端例子:https://github.com/tencentyun/qcloud-cos-sts-sdk/blob/master/scope.md
// // 异步获取临时密钥
// var url = window.lwConfig.SYSTEM_API + '/file/get/config' // url替换成您自己的后端服务
// var xhr = new XMLHttpRequest()
// xhr.open('get', url, true)
// xhr.setRequestHeader('Content-Type', 'application/json')
// xhr.onload = function (e) {
// try {
// var data = JSON.parse(e.target.responseText)
// var credentials = data.credentials
// } catch (e) {}
// if (!data || !credentials) {
// return console.error('credentials invalid:\n' + JSON.stringify(data, null, 2))
// }
// callback({
// TmpSecretId: decrypt(credentials.secretId),
// TmpSecretKey: credentials.secretKey,
// SecurityToken: credentials.sessionToken,
// // 建议返回服务器时间作为签名的开始时间,避免用户浏览器本地时间偏差过大导致签名错误
// StartTime: data.startTime, // 时间戳,单位秒,如:1580000000
// ExpiredTime: data.expiredTime, // 时间戳,单位秒,如:1580000000
// // ScopeLimit: true, // 细粒度控制权限需要设为 true,会限制密钥只在相同请求时重复使用
// })
// }
// xhr.send()
// // xhr.send(JSON.stringify(options.Scope))
// },
// })
},
},
created
()
{},
mounted
()
{},
methods
:
{
methods
:
{
handleRemove
(
i
)
{
upload
()
{
this
.
fileList
=
[]
this
.
loading
=
true
if
(
this
.
urls
.
length
===
0
)
{
let
file
=
undefined
this
.
urls
=
[]
if
(
!
this
.
multiple
||
this
.
limit
==
1
)
{
file
=
this
.
file
}
else
{
}
else
{
this
.
urls
.
splice
(
i
,
1
)
// 多选上传是多次调用单传的
this
.
urls
.
forEach
((
el
,
index
)
=>
{
file
=
this
.
file
.
shift
()
let
obj
=
{
url
:
''
,
name
:
''
}
}
obj
.
url
=
el
let
date
=
new
Date
()
this
.
fileList
.
push
(
obj
)
let
format
=
file
.
name
.
match
(
/
\.(\w
+
)
$/g
)
})
format
=
format
&&
format
[
0
]
const
params
=
{
Bucket
:
this
.
cosConfig
.
bucketName
/* 填入您自己的存储桶,必须字段 */
,
Region
:
this
.
cosConfig
.
region
/* 存储桶所在地域,例如ap-beijing,必须字段 */
,
Key
:
`/
${
dateFormat
(
date
,
'yyyy-MM-dd'
)}
/t
${
date
.
getTime
()}
-
${
uuid
()}${
format
}
`
,
/* 存储在桶里的对象键(例如1.jpg,a/b/test.txt),必须字段。*/
// 此处使用的格式: /日期/t时间戳-uid-文件后缀名
}
// 实例可能未初始化完成
if
(
!
this
.
cosInstance
)
{
this
.
$message
.
error
(
'存储空间正忙,请稍后再试'
)
return
}
}
if
(
this
.
names
.
length
===
0
)
{
this
.
names
=
[]
this
.
cosInstance
.
uploadFile
(
{
...
params
,
Body
:
file
/* 必须,上传文件对象,可以是input[type="file"]的file对象 */
,
onProgress
:
(
progressData
)
=>
{
this
.
percentage
=
progressData
.
percent
*
100
this
.
speed
=
(
progressData
.
speed
/
1024
/
1024
).
toFixed
(
2
)
// this.onProgress && this.onProgress(this.percentage, this.speed)
},
},
(
err1
,
data
)
=>
{
this
.
percentage
=
this
.
speed
=
0
if
(
err1
)
{
this
.
loading
=
false
this
.
$message
.
error
(
'上传失败,请稍后再试'
)
}
else
{
}
else
{
this
.
names
.
splice
(
i
,
1
)
let
location
=
'https://'
+
data
.
Location
this
.
names
.
forEach
((
item
,
index
)
=>
{
this
.
fileList
[
index
].
name
=
item
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
}))
}
}
this
.
$emit
(
'update:fileUrls'
,
this
.
urls
)
}
this
.
$emit
(
'update:fileNames'
,
this
.
names
)
},
)
},
remove
(
i
)
{
this
.
$confirm
(
'确定要删除吗?'
,
'提示'
,
{
confirmButtonText
:
'确定'
,
cancelButtonText
:
'取消'
,
type
:
'warning'
,
}).
then
(()
=>
{
let
clone
=
JSON
.
parse
(
JSON
.
stringify
(
this
.
fileList
))
this
.
fileListWatch
.
splice
(
i
,
1
)
clone
.
splice
(
i
,
1
)
this
.
$emit
(
'update:fileList'
,
clone
)
})
},
},
handleExceed
(
file
,
fileList
)
{
handleExceed
(
file
,
fileList
)
{
this
.
$message
.
error
(
`最多上传
${
this
.
limit
}
张`
)
this
.
$message
.
error
(
'最多上传'
+
this
.
limit
+
'张'
)
this
.
loading
=
false
this
.
loading
=
false
},
},
async
handleBeforeUpload
(
file
,
filelist
)
{
async
handleBeforeUpload
(
file
,
filelist
)
{
this
.
loading
=
true
this
.
loading
=
true
let
isFormat
=
true
let
isFormat
=
true
let
isSize
=
true
let
isSize
=
true
if
(
this
.
format
&&
this
.
format
.
length
)
{
// 校验格式
// type: 0 图片(image)、1 语音(voice)、2 视频(video),3 普通文件(file)
let
reg
=
/
\.(\w
+
)
$/g
let
match
=
file
.
name
.
match
(
reg
)
// 统一校验文件后缀名格式
// 如果没有显示配置 format 格式限制,则使用默认下面校验
let
format
=
this
.
format
let
tip
=
''
if
(
!
format
||
!
format
.
length
)
{
let
formatDefault
=
{
0
:
{
tip
:
'png/jpg'
,
value
:
[
'png'
,
'jpg'
,
'jpeg'
]
},
1
:
{
value
:
[
'amr'
]
},
2
:
{
value
:
[
'mp4'
]
},
3
:
{
tip
:
'word/pdf/ppt'
,
value
:
[
'doc'
,
'docx'
,
'pdf'
,
'ppt'
,
'pptx'
,
'pps'
,
'pptsx'
]
},
}
format
=
formatDefault
[
this
.
type
].
value
tip
=
formatDefault
[
this
.
type
].
tip
}
let
match
=
file
.
name
.
match
(
/
\.(\w
+
)
$/g
)
let
fileFormat
=
match
&&
match
[
0
].
replace
(
'.'
,
''
).
toLowerCase
()
let
fileFormat
=
match
&&
match
[
0
].
replace
(
'.'
,
''
).
toLowerCase
()
if
(
!
(
isFormat
=
this
.
format
.
includes
(
fileFormat
)))
{
isFormat
=
format
[
0
]
===
'*'
||
format
.
includes
(
fileFormat
)
this
.
$message
.
error
(
'文件格式不正确,请重新选择'
)
this
.
loading
=
false
return
Promise
.
reject
()
}
}
if
(
this
.
type
===
'0'
)
{
// 图片
isFormat
=
file
.
type
===
'image/jpeg'
||
file
.
type
===
'image/png'
isSize
=
file
.
size
/
1024
/
1024
<
this
.
maxSize
if
(
!
isFormat
)
{
if
(
!
isFormat
)
{
this
.
$message
.
error
(
'上传文件只能是 JPG/PNG
格式!'
)
this
.
$message
.
error
(
'文件格式错误,仅支持 '
+
(
tip
||
format
.
join
(
','
))
+
'
格式!'
)
this
.
loading
=
false
this
.
loading
=
false
return
Promise
.
reject
()
}
}
// 统一校验文件体积
// 如果没有显式配置 maxSize 限制大小,则使用下面默认值,单位 MB,
let
maxSize
=
this
.
maxSize
if
(
!
maxSize
)
{
let
maxSizeDefault
=
{
0
:
2
,
1
:
2
,
2
:
100
,
3
:
50
}
maxSize
||
(
maxSize
=
maxSizeDefault
[
this
.
type
])
}
isSize
=
file
.
size
/
1024
/
1024
<
maxSize
if
(
!
isSize
)
{
if
(
!
isSize
)
{
this
.
$message
.
error
(
'上传文件大小不能超过 2
MB!'
)
this
.
$message
.
error
(
'上传文件大小不能超过 '
+
maxSize
+
'
MB!'
)
this
.
loading
=
false
this
.
loading
=
false
return
Promise
.
reject
()
}
}
// 各类型独有的校验
let
validate
=
true
if
(
this
.
type
===
'0'
)
{
// 图片
let
maxImgPx
=
this
.
maxImgPx
let
maxImgPx
=
this
.
maxImgPx
if
(
maxImgPx
)
{
if
(
maxImgPx
)
{
try
{
try
{
...
@@ -181,11 +307,11 @@
...
@@ -181,11 +307,11 @@
width
=
image
.
width
width
=
image
.
width
height
=
image
.
height
height
=
image
.
height
if
(
width
>
maxImgPx
[
0
])
{
if
(
width
>
maxImgPx
[
0
])
{
isSiz
e
=
false
validat
e
=
false
this
.
$message
.
error
(
`图片“宽”度超过
${
maxImgPx
[
0
]}
像素,请重新选择`
)
this
.
$message
.
error
(
`图片“宽”度超过
${
maxImgPx
[
0
]}
像素,请重新选择`
)
}
else
if
(
height
>
maxImgPx
[
1
])
{
}
else
if
(
height
>
maxImgPx
[
1
])
{
this
.
$message
.
error
(
`图片“高”度超过
${
maxImgPx
[
1
]}
像素,请重新选择`
)
this
.
$message
.
error
(
`图片“高”度超过
${
maxImgPx
[
1
]}
像素,请重新选择`
)
isSiz
e
=
false
validat
e
=
false
}
}
window
.
URL
&&
window
.
URL
.
revokeObjectURL
(
image
.
src
)
window
.
URL
&&
window
.
URL
.
revokeObjectURL
(
image
.
src
)
resolve
()
resolve
()
...
@@ -208,71 +334,45 @@
...
@@ -208,71 +334,45 @@
}
}
}
else
if
(
this
.
type
===
'1'
)
{
}
else
if
(
this
.
type
===
'1'
)
{
// 语音
// 语音
isFormat
=
/.amr$/gi
.
test
(
file
.
name
)
isSize
=
file
.
size
/
1024
/
1024
<
2
if
(
!
isFormat
)
{
this
.
$message
.
error
(
'上传文件只能是 amr 格式!'
)
this
.
loading
=
false
}
if
(
!
isSize
)
{
this
.
$message
.
error
(
'上传文件大小不能超过 2MB!'
)
this
.
loading
=
false
}
let
amr
=
new
BenzAMRRecorder
()
let
amr
=
new
BenzAMRRecorder
()
try
{
try
{
await
amr
.
initWithBlob
(
file
)
await
amr
.
initWithBlob
(
file
)
isSiz
e
=
amr
.
getDuration
()
<=
60
validat
e
=
amr
.
getDuration
()
<=
60
if
(
!
isSiz
e
)
{
if
(
!
validat
e
)
{
this
.
$message
.
error
(
'上传文件时长不能超过 60秒!'
)
this
.
$message
.
error
(
'上传文件时长不能超过 60秒!'
)
this
.
loading
=
false
}
}
}
catch
(
error
)
{
}
catch
(
error
)
{
console
.
log
(
error
)
console
.
log
(
error
)
this
.
$message
.
error
(
'文件
损坏'
)
this
.
$message
.
error
(
'文件已
损坏'
)
}
}
}
else
if
(
this
.
type
===
'2'
)
{
}
else
if
(
this
.
type
===
'2'
)
{
// 视频
// 视频
isFormat
=
file
.
type
===
'video/mp4'
let
result
=
await
this
.
checkVideoCode
(
file
)
isSize
=
file
.
size
/
1024
/
1024
<
100
if
(
!
isFormat
)
{
this
.
$message
.
error
(
'上传文件只能是 mp4 格式!'
)
this
.
loading
=
false
}
let
result
await
this
.
checkVideoCode
(
file
).
then
((
res
)
=>
{
console
.
log
(
res
)
result
=
res
})
if
(
result
.
mime
.
indexOf
(
'video/mp4'
)
===
-
1
)
{
if
(
result
.
mime
.
indexOf
(
'video/mp4'
)
===
-
1
)
{
this
.
$message
.
error
(
'mp4 格式不正确, 请使用标准编码视频!'
)
this
.
$message
.
error
(
'mp4 格式不正确, 请使用标准编码视频!'
)
this
.
loading
=
false
this
.
loading
=
false
return
Promise
.
reject
()
return
Promise
.
reject
()
}
}
if
(
!
isSize
)
{
this
.
$message
.
error
(
'上传文件大小不能超过 100MB!'
)
}
}
else
if
(
this
.
type
===
'3'
)
{
}
else
if
(
this
.
type
===
'3'
)
{
// 普通文件
// 普通文件
isSize
=
file
.
size
/
1024
/
1024
<
50
if
(
!
isSize
)
{
this
.
$message
.
error
(
'上传文件大小不能超过 50MB!'
)
}
if
(
this
.
isThree
)
{
isFormat
=
this
.
fileType
(
file
.
name
)
if
(
!
isFormat
)
{
this
.
$message
.
error
(
'上传文件只能是 word/pdf/ppt!'
)
this
.
loading
=
false
}
}
}
if
(
!
validate
)
{
}
if
(
!
isSize
)
{
this
.
loading
=
false
this
.
loading
=
false
}
}
// if (beforeUpload) {
// if (beforeUpload) {
// return beforeUpload(file)
// return beforeUpload(file)
// }
// }
return
(
isFormat
&&
isSize
)
||
Promise
.
reject
()
if
(
!
this
.
multiple
||
this
.
limit
==
1
)
{
this
.
file
=
file
}
else
{
Array
.
isArray
(
this
.
file
)
||
(
this
.
file
=
[])
// 多选
this
.
file
.
push
(
file
)
}
return
validate
||
Promise
.
reject
()
},
onError
(
err
,
file
,
fileList
)
{
this
.
loading
=
false
this
.
$message
.
error
(
'上传文件失败'
)
},
},
checkVideoCode
(
file
)
{
checkVideoCode
(
file
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
...
@@ -292,107 +392,109 @@
...
@@ -292,107 +392,109 @@
}
}
})
})
},
},
fileType
(
file
)
{
showView
(
index
)
{
let
filecontent
=
JSON
.
parse
(
JSON
.
stringify
(
file
))
let
imager
=
index
!==
undefined
?
this
.
$refs
.
image
[
index
]
:
this
.
$refs
.
image
filecontent
=
filecontent
.
split
(
'.'
)
imager
.
clickHandler
()
let
type
=
filecontent
[
filecontent
.
length
-
1
]
this
.
$nextTick
(()
=>
{
if
([
'doc'
,
'docx'
,
'pdf'
,
'ppt'
,
'pptx'
,
'pps'
,
'pptsx'
].
includes
(
type
))
{
// 为遮罩层添加关闭事件
return
true
let
maskEl
=
imager
.
$children
[
0
].
$refs
[
'el-image-viewer__wrapper'
].
firstChild
}
else
{
maskEl
.
addEventListener
(
'click'
,
()
=>
{
return
false
event
.
stopPropagation
()
}
imager
.
closeViewer
()
})
})
// this.$refs.image.$refs.closeViewer();
},
},
onSuccess
(
res
,
file
)
{
if
(
res
.
code
===
200
)
{
// this.$emit('update:fileUrl', res.data.materialUrl)
// this.$emit('update:fileName', res.data.materialName)
// if (this.type == 0) {
// res.url = res.data.url
// res.fileName = res.data.url
// }
if
(
this
.
fileUrls
||
this
.
fileUrls
===
[])
{
this
.
urls
.
push
(
res
.
data
.
url
)
this
.
names
.
push
(
res
.
data
.
name
)
}
this
.
$emit
(
'update:fileUrl'
,
res
.
data
.
url
)
this
.
$emit
(
'update:fileUrls'
,
this
.
urls
)
this
.
$emit
(
'update:fileName'
,
res
.
data
.
name
)
this
.
$emit
(
'update:fileNames'
,
this
.
names
)
this
.
$emit
(
'update:file'
,
file
)
this
.
loading
=
false
// this.fileUrl = URL.createObjectURL(file.raw)
}
else
{
this
.
loading
=
false
this
.
$message
.
error
(
res
.
msg
)
}
},
},
onError
(
err
,
file
,
fileList
)
{
}
this
.
loading
=
false
this
.
$message
.
error
(
'上传文件失败'
)
}
}
}
</
script
>
</
script
>
<
template
>
<
template
>
<div>
<div>
<div
v-if=
"fileUrls || fileUrls === []"
>
<!-- 多个上传文件列表展示 -->
<div
class=
"img-style"
>
<template
v-if=
"multiple"
>
<!-- 多个图片 -->
<!-- 图片 -->
<div
v-for=
"(item, index) in fileUrls"
:key=
"index"
class=
"img-item"
>
<template
v-if=
"type == 0"
>
<img
class=
"upload-img"
:src=
"item"
alt=
""
@
mouseenter=
"enterImg(index)"
@
mouseleave=
"leaveImg(index)"
/>
<!--
<transition-group>
-->
<span
class=
"mask"
>
<div
v-for=
"(item, index) in fileListWatch"
:key=
"index"
class=
"img-item"
>
<span
class=
"item-delete"
@
click=
"handleRemove(index)"
>
<el-image
<i
class=
"el-icon-delete"
></i>
ref=
"image"
</span>
class=
"upload-img"
</span>
:src=
"item.url"
fit=
"contain"
:preview-src-list=
"fileListWatch.map((e) => e.url)"
alt=
""
/>
<div
class=
"action-mask"
>
<i
class=
"el-icon-search mr5"
@
click=
"showView(index)"
></i>
<!--
<span
v-if=
"action.includes('download')"
@
click=
"download(item)"
>
<i
class=
"el-icon-download"
></i>
</span>
-->
<i
class=
"el-icon-delete mr5"
@
click=
"remove(index)"
></i>
</div>
</div>
</div>
<!--
</transition-group>
-->
</
template
>
<!-- 后续再这里扩展其他文件列表 -->
</template>
<el-upload
<el-upload
ref=
"multPic"
ref=
"multPic"
v-loading=
"loading"
element-loading-text=
"正在上传..."
class=
"uploader"
class=
"uploader"
:accept=
"accept
"
action=
"/api
"
:action=
"action
"
:accept=
"accept || acceptAuto
"
:headers=
"headers
"
:http-request=
"upload
"
:data=
"{ mediaType: type }"
:data=
"{ mediaType: type }"
:show-file-list=
"false"
:show-file-list=
"false"
:file-list="fileList"
:file-list=
"fileListWatch"
:on-success="onSuccess"
:disabled=
"loading"
:on-error="onError"
:multiple=
"multiple && limit != 1"
:before-upload="handleBeforeUpload"
:multiple="multiple"
:limit=
"limit"
:limit=
"limit"
:on-error=
"onError"
:on-exceed=
"handleExceed"
:on-exceed=
"handleExceed"
>
:before-upload=
"handleBeforeUpload"
>
<slot>
<!--
<template>
<i
class=
"el-icon-plus uploader-icon"
></i>
</
template
>
</slot>
</el-upload>
</div>
</div>
<div
v-else
>
<el-upload
ref=
"multPic"
v-loading=
"loading"
element-loading-text="正在上传..."
element-loading-text="正在上传..."
class=
"uploader"
:accept=
"accept"
:action=
"action"
:headers=
"headers"
:data=
"{ mediaType: type }"
:show-file-list=
"false"
:on-success="onSuccess"
:on-success="onSuccess"
:on-error=
"onError"
-->
:before-upload=
"handleBeforeUpload"
>
<slot>
<slot>
<
template
v-if=
"fileUrl || (fileUrls && fileUrls.length)"
>
<i
v-if=
"!loading && !fileUrlWatch"
class=
"el-icon-plus uploader-icon upload-action"
></i>
<transition>
<!-- 上传精度条 -->
<div
class=
"upload-action"
v-if=
"loading"
>
<el-progress
class=
"progress cc"
type=
"circle"
:percentage=
"percentage"
></el-progress>
<div
class=
"el-loading-spinner"
>
<svg
viewBox=
"25 25 50 50"
class=
"circular"
>
<circle
cx=
"50"
cy=
"50"
r=
"20"
fill=
"none"
class=
"path"
></circle>
</svg>
</div>
<div
class=
"cc"
style=
"margin-top: 35px"
>
{{ speed + 'M/s' }}
</div>
</div>
<!-- 单文件上传的文件展示 -->
<
template
v-if=
"!loading && fileUrlWatch && !multiple"
>
<div
v-if=
"type === '0'"
>
<div
v-if=
"type === '0'"
>
<img
v-if=
"fileUrl"
:src=
"fileUrl"
class=
"upload-img"
/>
<el-image
v-if=
"fileUrlWatch"
ref=
"image"
:src=
"fileUrlWatch"
class=
"upload-img"
:preview-src-list=
"[fileUrlWatch]"
fit=
"contain"
/>
<div
class=
"action-mask"
@
click
.
self
.
stop
>
<i
class=
"el-icon-search"
@
click
.
prevent
.
stop=
"showView()"
></i>
<i
class=
"el-icon-edit"
></i>
<!--
<span
v-if=
"action.includes('download')"
@
click
.
prevent
.
stop=
"download(item)"
>
<i
class=
"el-icon-download"
></i>
</span>
-->
<!--
<span
@
click
.
prevent
.
stop=
"remove()"
>
<i
class=
"el-icon-delete"
></i>
</span>
-->
</div>
</div>
</div>
<div
v-else-if=
"type === '2'"
>
<div
v-else-if=
"type === '2'"
>
<video
<video
...
@@ -404,18 +506,28 @@
...
@@ -404,18 +506,28 @@
webkit-playsinline=
"true"
webkit-playsinline=
"true"
playsinline=
"true"
playsinline=
"true"
:autoplay=
"false"
:autoplay=
"false"
preload=
"auto
"
:key=
"fileUrlWatch
"
>
preload=
"auto"
>
<source
:src=
"fileUrl"
type=
"video/mp4"
/>
<source
:src=
"fileUrl
Watch
"
type=
"video/mp4"
/>
</video>
</video>
<div
class=
"action-mask"
style=
"height: 50%"
@
click
.
self
.
stop
>
<i
class=
"el-icon-edit"
></i>
</div>
</div>
<div
v-else
class=
"al"
>
{{
fileNameWatch
||
fileUrlWatch
}}
<i
class=
"el-icon-edit ml10"
></i>
<!-- a链接用本地视频打不开,视频地址使用远程地址 -->
<a
@
click
.
stop
:href=
"/\.mp4$/.test(fileNameWatch) ? fileUrl : fileUrlWatch"
target=
"_blank"
>
<i
class=
"el-icon-view ml10"
style=
"vertical-align: middle"
></i>
</a>
</div>
</div>
<div
v-else
>
{{
fileName
}}
</div>
</
template
>
</
template
>
<i
v-else
class=
"el-icon-plus uploader-icon"
></i
>
</transition
>
</slot>
</slot>
</el-upload>
</el-upload>
</div>
<!-- 上传格式,大小等提示语 -->
<div
class=
"tip"
>
<div
class=
"tip"
>
<slot
name=
"tip"
></slot>
<slot
name=
"tip"
></slot>
</div>
</div>
...
@@ -423,50 +535,62 @@
...
@@ -423,50 +535,62 @@
</template>
</template>
<
style
lang=
"scss"
scoped
>
<
style
lang=
"scss"
scoped
>
::v-deep
.uploader
{
::v-deep
.uploader
{
display
:
inline-block
;
display
:
inline-block
;
vertical-align
:
middle
;
.el-upload
{
.el-upload
{
border-radius
:
6px
;
border-radius
:
6px
;
cursor
:
pointer
;
cursor
:
pointer
;
position
:
relative
;
position
:
relative
;
overflow
:
hidden
;
overflow
:
hidden
;
&:hover
{
border-color
:
#409eff
;
}
}
}
}
}
.uploader-icon
{
.upload-action
{
font-size
:
28px
;
color
:
#8c939d
;
width
:
178px
;
width
:
178px
;
height
:
178px
;
height
:
178px
;
position
:
relative
;
text-align
:
center
;
}
.uploader-icon
{
display
:
block
;
font-size
:
28px
;
line-height
:
178px
;
line-height
:
178px
;
text-align
:
center
;
text-align
:
center
;
color
:
#8c939d
;
border-radius
:
6px
;
border-radius
:
6px
;
border
:
1px
dashed
#d9d9d9
;
border
:
1px
dashed
#d9d9d9
;
transition
:
all
0.3s
;
&:hover
{
border-color
:
$
blue
;
color
:
$
blue
;
}
}
.upload-img
{
}
.progress
{
overflow
:
hidden
;
}
.upload-img
{
width
:
178px
;
width
:
178px
;
height
:
178px
;
height
:
178px
;
display
:
block
;
display
:
block
;
}
}
.tip
{
.tip
{
color
:
#aaa
;
color
:
#aaa
;
font-size
:
12px
;
font-size
:
12px
;
}
}
.img-style
{
.img-item
{
display
:
flex
;
flex-wrap
:
wrap
;
}
.img-item
{
margin-right
:
10px
;
margin-bottom
:
10px
;
position
:
relative
;
position
:
relative
;
}
display
:
inline-block
;
.mask
{
vertical-align
:
middle
;
margin
:
0
10px
10px
0
;
transition
:
all
0.3s
;
}
.action-mask
{
position
:
absolute
;
position
:
absolute
;
display
:
block
;
display
:
flex
;
justify-content
:
space-around
;
align-items
:
center
;
padding
:
0
30px
;
width
:
100%
;
width
:
100%
;
height
:
100%
;
height
:
100%
;
left
:
0
;
left
:
0
;
...
@@ -479,16 +603,8 @@
...
@@ -479,16 +603,8 @@
transition
:
opacity
0.3s
;
transition
:
opacity
0.3s
;
background-color
:
rgba
(
0
,
0
,
0
,
0.5
);
background-color
:
rgba
(
0
,
0
,
0
,
0.5
);
z-index
:
1
;
z-index
:
1
;
line-height
:
178px
;
}
.item-delete
{
.action-mask
:hover
{
display
:
none
;
}
}
.mask
:hover
{
opacity
:
1
;
opacity
:
1
;
background-color
:
rgba
(
0
,
0
,
0
,
0.5
);
}
.item-delete
{
display
:
inline-block
;
}
}
</
style
>
</
style
>
linkwe-pc/src/utils/jsencrypt.js
View file @
b3903e5
...
@@ -2,10 +2,12 @@ import JSEncrypt from 'jsencrypt/bin/jsencrypt'
...
@@ -2,10 +2,12 @@ import JSEncrypt from 'jsencrypt/bin/jsencrypt'
// 密钥对生成 http://web.chacuo.net/netrsakeypair
// 密钥对生成 http://web.chacuo.net/netrsakeypair
const
publicKey
=
'MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAKoR8mX0rGKLqzcWmOzbfj64K8ZIgOdH\n'
+
const
publicKey
=
'MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAKoR8mX0rGKLqzcWmOzbfj64K8ZIgOdH\n'
+
'nzkXSOVOZbFu/TJhZ7rFAN+eaGkl3C4buccQd/EjEsj9ir7ijT7h96MCAwEAAQ=='
'nzkXSOVOZbFu/TJhZ7rFAN+eaGkl3C4buccQd/EjEsj9ir7ijT7h96MCAwEAAQ=='
const
privateKey
=
'MIIBVAIBADANBgkqhkiG9w0BAQEFAASCAT4wggE6AgEAAkEAqhHyZfSsYourNxaY\n'
+
const
privateKey
=
'MIIBVAIBADANBgkqhkiG9w0BAQEFAASCAT4wggE6AgEAAkEAqhHyZfSsYourNxaY\n'
+
'7Nt+PrgrxkiA50efORdI5U5lsW79MmFnusUA355oaSXcLhu5xxB38SMSyP2KvuKN\n'
+
'7Nt+PrgrxkiA50efORdI5U5lsW79MmFnusUA355oaSXcLhu5xxB38SMSyP2KvuKN\n'
+
'PuH3owIDAQABAkAfoiLyL+Z4lf4Myxk6xUDgLaWGximj20CUf+5BKKnlrK+Ed8gA\n'
+
'PuH3owIDAQABAkAfoiLyL+Z4lf4Myxk6xUDgLaWGximj20CUf+5BKKnlrK+Ed8gA\n'
+
'kM0HqoTt2UZwA5E2MzS4EI2gjfQhz5X28uqxAiEA3wNFxfrCZlSZHb0gn2zDpWow\n'
+
'kM0HqoTt2UZwA5E2MzS4EI2gjfQhz5X28uqxAiEA3wNFxfrCZlSZHb0gn2zDpWow\n'
+
...
@@ -28,3 +30,91 @@ export function decrypt(txt) {
...
@@ -28,3 +30,91 @@ export function decrypt(txt) {
return
encryptor
.
decrypt
(
txt
)
// 对数据进行解密
return
encryptor
.
decrypt
(
txt
)
// 对数据进行解密
}
}
// AES加密
import
CryptoJS
from
'crypto-js'
let
keyAES
=
'qykj@20221101_te'
//加密
export
function
encryptAES
(
str
)
{
var
key
=
CryptoJS
.
enc
.
Utf8
.
parse
(
keyAES
)
var
srcs
=
CryptoJS
.
enc
.
Utf8
.
parse
(
str
)
var
encrypted
=
CryptoJS
.
AES
.
encrypt
(
srcs
,
key
,
{
mode
:
CryptoJS
.
mode
.
ECB
,
padding
:
CryptoJS
.
pad
.
Pkcs7
,
})
return
encrypted
.
toString
()
}
//解密
export
function
decryptAES
(
str
)
{
var
key
=
CryptoJS
.
enc
.
Utf8
.
parse
(
keyAES
)
var
decrypt
=
CryptoJS
.
AES
.
decrypt
(
str
,
key
,
{
mode
:
CryptoJS
.
mode
.
ECB
,
padding
:
CryptoJS
.
pad
.
Pkcs7
,
})
return
CryptoJS
.
enc
.
Utf8
.
stringify
(
decrypt
).
toString
()
}
// base64加密
export
function
encryptB64
(
str
)
{
return
window
.
btoa
(
encodeURIComponent
(
str
).
replace
(
/%
([
0-9A-F
]{2})
/g
,
function
(
match
,
p1
)
{
return
String
.
fromCharCode
(
'0x'
+
p1
)
}),
)
}
// base64解密
export
function
decryptB64
(
str
)
{
const
keyStr
=
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='
function
utf8_decode
(
utftext
)
{
var
string
=
''
var
i
=
0
var
c
=
0
var
c1
=
0
var
c2
=
0
while
(
i
<
utftext
.
length
)
{
c
=
utftext
.
charCodeAt
(
i
)
if
(
c
<
128
)
{
string
+=
String
.
fromCharCode
(
c
)
i
++
}
else
if
(
c
>
191
&&
c
<
224
)
{
c1
=
utftext
.
charCodeAt
(
i
+
1
)
string
+=
String
.
fromCharCode
(((
c
&
31
)
<<
6
)
|
(
c1
&
63
))
i
+=
2
}
else
{
c1
=
utftext
.
charCodeAt
(
i
+
1
)
c2
=
utftext
.
charCodeAt
(
i
+
2
)
string
+=
String
.
fromCharCode
(((
c
&
15
)
<<
12
)
|
((
c1
&
63
)
<<
6
)
|
(
c2
&
63
))
i
+=
3
}
}
return
string
}
function
decode
(
input
)
{
var
output
=
''
var
chr1
,
chr2
,
chr3
var
enc1
,
enc2
,
enc3
,
enc4
var
i
=
0
input
=
input
.
replace
(
/
[^
A-Za-z0-9
\+\/\=]
/g
,
''
)
while
(
i
<
input
.
length
)
{
enc1
=
keyStr
.
indexOf
(
input
.
charAt
(
i
++
))
enc2
=
keyStr
.
indexOf
(
input
.
charAt
(
i
++
))
enc3
=
keyStr
.
indexOf
(
input
.
charAt
(
i
++
))
enc4
=
keyStr
.
indexOf
(
input
.
charAt
(
i
++
))
chr1
=
(
enc1
<<
2
)
|
(
enc2
>>
4
)
chr2
=
((
enc2
&
15
)
<<
4
)
|
(
enc3
>>
2
)
chr3
=
((
enc3
&
3
)
<<
6
)
|
enc4
output
=
output
+
String
.
fromCharCode
(
chr1
)
if
(
enc3
!=
64
)
{
output
=
output
+
String
.
fromCharCode
(
chr2
)
}
if
(
enc4
!=
64
)
{
output
=
output
+
String
.
fromCharCode
(
chr3
)
}
}
output
=
utf8_decode
(
output
)
return
output
}
return
decode
(
str
)
}
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