Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
S
saas-dml
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
EzijingWeb
saas-dml
Commits
92350afc
提交
92350afc
authored
4月 10, 2023
作者:
陈志磊
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update
上级
62752e78
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
57 行增加
和
73 行删除
+57
-73
AppUpload.vue
src/components/base/AppUpload.vue
+53
-69
UploadEventsDialog.vue
src/modules/user/components/UploadEventsDialog.vue
+2
-2
UploadUserDialog.vue
src/modules/user/components/UploadUserDialog.vue
+2
-2
没有找到文件。
src/components/base/AppUpload.vue
浏览文件 @
92350afc
<
script
lang=
"ts"
setup
>
<
script
lang=
"ts"
setup
>
import
type
{
UploadProps
,
UploadUserFile
}
from
'element-plus'
import
{
ElMessage
}
from
'element-plus'
import
{
ElMessage
}
from
'element-plus'
import
{
Plus
}
from
'@element-plus/icons-vue'
import
{
Plus
}
from
'@element-plus/icons-vue'
import
type
{
UploadProps
,
UploadUserFile
}
from
'element-plus'
import
md5
from
'blueimp-md5'
import
md5
from
'blueimp-md5'
import
{
getSignature
}
from
'@/api/base'
import
{
getSignature
}
from
'@/api/base'
interface
Props
{
const
props
=
withDefaults
(
modelValue
:
string
|
{
name
:
string
;
url
:
string
}[]
defineProps
<
{
prefix
?:
string
modelValue
:
string
|
[]
size
?:
number
prefix
?:
string
limit
?:
number
size
?:
number
beforeUpload
?:
(
file
:
any
)
=>
void
beforeUploadFiles
?:
(
file
:
any
)
=>
boolean
|
void
}
onChange
?:
(
file
:
any
,
files
:
any
)
=>
void
}
>
(),
const
props
=
withDefaults
(
defineProps
<
Props
>
(),
{
{
prefix
:
'upload/saas-dml/'
prefix
:
'upload/admin/'
})
}
)
const
emit
=
defineEmits
([
'update:modelValue'
,
'success'
])
const
emit
=
defineEmits
([
'update:modelValue'
])
const
uploadData
=
ref
()
const
uploadData
=
ref
()
const
fileList
=
ref
<
UploadUserFile
[]
>
([])
const
fileList
=
ref
<
UploadUserFile
[]
>
([])
watchEffect
(()
=>
{
watch
(
fileList
.
value
=
Array
.
isArray
(
props
.
modelValue
)
?
props
.
modelValue
.
map
(
item
=>
({
...
item
}))
:
[]
()
=>
props
.
modelValue
,
})
value
=>
{
fileList
.
value
=
Array
.
isArray
(
value
)
?
[...
value
]
:
[]
}
)
const
showFileList
=
computed
(()
=>
{
const
showFileList
=
computed
(()
=>
{
return
Array
.
isArray
(
props
.
modelValue
)
return
Array
.
isArray
(
props
.
modelValue
)
...
@@ -33,16 +37,8 @@ const showFileList = computed(() => {
...
@@ -33,16 +37,8 @@ const showFileList = computed(() => {
// 上传之前
// 上传之前
const
handleBeforeUpload
=
async
(
file
:
any
)
=>
{
const
handleBeforeUpload
=
async
(
file
:
any
)
=>
{
if
(
props
.
limit
&&
fileList
.
value
.
length
>=
props
.
limit
&&
props
.
limit
>
1
)
{
ElMessage
.
error
(
`只能上传
${
props
.
limit
}
个文件`
)
return
false
}
if
(
props
.
size
&&
file
.
size
>
props
.
size
)
{
ElMessage
.
error
(
`文件大小不能超过
${
props
.
size
/
1024
/
1024
}
M`
)
return
false
}
const
fileName
=
file
.
name
const
fileName
=
file
.
name
const
key
=
props
.
prefix
+
md5
(
fileName
+
new
Date
().
getTime
())
+
fileName
.
substr
(
fileName
.
lastIndexOf
(
'.'
))
const
key
=
props
.
prefix
+
md5
(
fileName
+
new
Date
().
getTime
())
+
'/'
+
fileName
const
response
:
Record
<
string
,
any
>
=
await
getSignature
()
const
response
:
Record
<
string
,
any
>
=
await
getSignature
()
uploadData
.
value
=
{
uploadData
.
value
=
{
key
,
key
,
...
@@ -53,42 +49,29 @@ const handleBeforeUpload = async (file: any) => {
...
@@ -53,42 +49,29 @@ const handleBeforeUpload = async (file: any) => {
url
:
`
${
response
.
host
}
/
${
key
}
`
url
:
`
${
response
.
host
}
/
${
key
}
`
}
}
file
.
url
=
`
${
response
.
host
}
/
${
key
}
`
file
.
url
=
`
${
response
.
host
}
/
${
key
}
`
if
(
props
.
beforeUpload
)
{
if
(
props
.
beforeUpload
Files
)
{
return
props
.
beforeUpload
(
file
)
return
props
.
beforeUpload
Files
(
file
)
}
}
}
}
// 上传成功
// 上传成功
const
handleSuccess
=
(
response
:
any
,
file
:
any
,
files
:
any
)
=>
{
const
handleSuccess
:
UploadProps
[
'onSuccess'
]
=
(
response
,
file
:
any
,
files
:
any
)
=>
{
if
(
!
files
.
every
((
item
:
any
)
=>
item
.
status
===
'success'
))
return
if
(
!
files
.
every
((
item
:
any
)
=>
item
.
status
===
'success'
))
return
if
(
showFileList
.
value
)
{
if
(
showFileList
.
value
)
{
if
(
props
.
limit
&&
props
.
limit
===
1
)
{
emit
(
const
last
=
files
[
files
.
length
-
1
]
'update:modelValue'
,
emit
(
'update:modelValue'
,
[
files
.
map
((
item
:
any
)
=>
{
{
return
{
name
:
last
.
name
,
name
:
item
.
name
,
url
:
last
.
url
||
last
.
raw
?
.
url
,
url
:
item
.
url
||
item
.
raw
.
url
,
size
:
last
.
size
||
last
.
raw
?
.
size
,
size
:
item
.
size
||
item
.
raw
.
size
,
type
:
last
.
type
||
last
.
raw
?
.
type
type
:
item
.
type
||
item
.
raw
.
type
}
}
])
})
}
else
{
)
emit
(
'update:modelValue'
,
files
.
map
((
item
:
any
)
=>
{
return
{
name
:
item
.
name
,
url
:
item
.
url
||
item
.
raw
?.
url
,
size
:
item
.
size
||
item
.
raw
?.
size
,
type
:
item
.
type
||
item
.
raw
?.
type
}
})
)
}
}
else
{
}
else
{
emit
(
'update:modelValue'
,
file
.
raw
.
url
)
emit
(
'update:modelValue'
,
file
.
raw
.
url
)
}
}
emit
(
'success'
,
file
,
files
)
}
}
// 上传限制
// 上传限制
...
@@ -97,12 +80,12 @@ const handleExceed: UploadProps['onExceed'] = () => {
...
@@ -97,12 +80,12 @@ const handleExceed: UploadProps['onExceed'] = () => {
}
}
// 删除
// 删除
const
handleRemove
:
UploadProps
[
'onRemove'
]
=
(
file
,
f
iles
)
=>
{
const
handleRemove
:
UploadProps
[
'onRemove'
]
=
(
uploadFile
,
uploadF
iles
)
=>
{
if
(
showFileList
.
value
)
{
if
(
showFileList
.
value
)
{
emit
(
emit
(
'update:modelValue'
,
'update:modelValue'
,
f
iles
.
map
((
item
:
any
)
=>
{
uploadF
iles
.
map
((
item
:
any
)
=>
{
return
{
name
:
item
.
name
,
url
:
item
.
url
||
item
.
raw
.
url
}
return
{
name
:
item
.
name
,
url
:
item
.
url
||
item
.
raw
.
url
,
size
:
item
.
size
,
type
:
item
.
type
}
})
})
)
)
}
else
{
}
else
{
...
@@ -112,7 +95,7 @@ const handleRemove: UploadProps['onRemove'] = (file, files) => {
...
@@ -112,7 +95,7 @@ const handleRemove: UploadProps['onRemove'] = (file, files) => {
// 预览
// 预览
const
handlePreview
:
UploadProps
[
'onPreview'
]
=
uploadFile
=>
{
const
handlePreview
:
UploadProps
[
'onPreview'
]
=
uploadFile
=>
{
window
.
open
(
uploadFile
.
url
)
console
.
log
(
uploadFile
)
}
}
</
script
>
</
script
>
...
@@ -127,22 +110,24 @@ const handlePreview: UploadProps['onPreview'] = uploadFile => {
...
@@ -127,22 +110,24 @@ const handlePreview: UploadProps['onPreview'] = uploadFile => {
:on-preview=
"handlePreview"
:on-preview=
"handlePreview"
:on-success=
"handleSuccess"
:on-success=
"handleSuccess"
:file-list=
"fileList"
:file-list=
"fileList"
:limit=
"1"
class=
"uploader"
class=
"uploader"
>
>
<slot>
<template
v-if=
"showFileList"
>
<template
v-if=
"showFileList"
>
<template
v-if=
"$attrs['list-type'] === 'picture-card'"
>
<template
v-if=
"$attrs['list-type'] === 'picture-card'"
>
<el-icon><Plus
/></el-icon>
<el-icon><Plus
/></el-icon>
</
template
>
</
template
>
<
template
v-else-if=
"props.beforeUploadFiles"
>
<
template
v-else
>
<el-button
type=
"primary"
size=
"default"
round
>
上传图片/视频附件
</el-button>
<el-button
type=
"primary"
plain
round
>
本地文件
</el-button>
</
template
>
</
template
>
<
template
v-else
>
<el-button
type=
"primary"
class=
"app-upload-btn"
>
点击上传
</el-button>
</
template
>
</
template
>
<div
class=
"avatar-uploader"
v-els
e
>
</templat
e>
<el-image
:src=
"(modelValue as string)"
fit=
"contain"
v-if=
"modelValue"
/
>
<div
class=
"avatar-uploader"
v-else
>
<el-icon
v-else
class=
"avatar-uploader-icon"
><Plus
/></el-icon
>
<el-image
:src=
"(modelValue as string)"
fit=
"contain"
v-if=
"modelValue"
/
>
<
/div
>
<
el-icon
v-else
class=
"avatar-uploader-icon"
><Plus
/></el-icon
>
</
slot
>
</
div
>
<
template
#
tip
>
<
template
#
tip
>
<div
class=
"el-upload__tip"
><slot
name=
"tip"
></slot></div>
<div
class=
"el-upload__tip"
><slot
name=
"tip"
></slot></div>
</
template
>
</
template
>
...
@@ -152,7 +137,6 @@ const handlePreview: UploadProps['onPreview'] = uploadFile => {
...
@@ -152,7 +137,6 @@ const handlePreview: UploadProps['onPreview'] = uploadFile => {
<
style
lang=
"scss"
>
<
style
lang=
"scss"
>
.uploader
{
.uploader
{
flex
:
1
;
flex
:
1
;
overflow
:
hidden
;
}
}
.avatar-uploader
{
.avatar-uploader
{
width
:
178px
;
width
:
178px
;
...
...
src/modules/user/components/UploadEventsDialog.vue
浏览文件 @
92350afc
...
@@ -60,7 +60,7 @@ const fetchFileUpload = () => {
...
@@ -60,7 +60,7 @@ const fetchFileUpload = () => {
// })
// })
}
}
const
fileData
=
$ref
([])
const
fileData
=
$ref
<
any
>
([])
</
script
>
</
script
>
<
template
>
<
template
>
...
@@ -81,7 +81,7 @@ const fileData = $ref([])
...
@@ -81,7 +81,7 @@ const fileData = $ref([])
</el-form>
</el-form>
<div
class=
"btn-box"
>
<div
class=
"btn-box"
>
<el-button
style=
"margin-right: 20px"
type=
"primary"
@
click=
"downloadTemplate"
>
下载事件数据模板
</el-button>
<el-button
style=
"margin-right: 20px"
type=
"primary"
@
click=
"downloadTemplate"
>
下载事件数据模板
</el-button>
<AppUpload
v-model=
"fileData"
:limit=
"1"
>
<AppUpload
v-model=
"fileData"
>
<el-button
type=
"primary"
>
上传事件数据
</el-button>
<el-button
type=
"primary"
>
上传事件数据
</el-button>
</AppUpload>
</AppUpload>
<!--
<el-upload
<!--
<el-upload
...
...
src/modules/user/components/UploadUserDialog.vue
浏览文件 @
92350afc
...
@@ -51,7 +51,7 @@ const fetchFileUpload = () => {
...
@@ -51,7 +51,7 @@ const fetchFileUpload = () => {
}
}
}
}
const
fileData
=
$ref
([])
const
fileData
=
$ref
<
any
>
([])
</
script
>
</
script
>
<
template
>
<
template
>
...
@@ -76,7 +76,7 @@ const fileData = $ref([])
...
@@ -76,7 +76,7 @@ const fileData = $ref([])
</el-form>
</el-form>
<div
class=
"btn-box"
>
<div
class=
"btn-box"
>
<el-button
type=
"primary"
style=
"margin-right: 20px"
@
click=
"downloadTemplate"
>
下载用户数据模板
</el-button>
<el-button
type=
"primary"
style=
"margin-right: 20px"
@
click=
"downloadTemplate"
>
下载用户数据模板
</el-button>
<AppUpload
v-model=
"fileData"
:limit=
"1"
>
<AppUpload
v-model=
"fileData"
>
<el-button
type=
"primary"
>
上传用户数据
</el-button>
<el-button
type=
"primary"
>
上传用户数据
</el-button>
</AppUpload>
</AppUpload>
<!--
<el-upload
<!--
<el-upload
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论