Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cy-admin-ui
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
webpack
cy-admin-ui
Commits
0f9fe073
Commit
0f9fe073
authored
Feb 16, 2022
by
廖伟胜
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改上传文件组件结构
parent
1b956aa6
Changes
8
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
1041 additions
and
684 deletions
+1041
-684
index.js
packages/form/upload/index.js
+1
-1
upload-audio.vue
packages/form/upload/src/upload-audio.vue
+70
-86
upload-file.vue
packages/form/upload/src/upload-file.vue
+307
-125
upload-img-list.vue
packages/form/upload/src/upload-img-list.vue
+8
-26
upload-img.vue
packages/form/upload/src/upload-img.vue
+206
-146
upload-video.vue
packages/form/upload/src/upload-video.vue
+367
-112
upload.vue
packages/form/upload/src/upload.vue
+77
-182
layout-form.vue
packages/layout/src/layout-form.vue
+5
-6
No files found.
packages/form/upload/index.js
View file @
0f9fe073
import
Upload
from
'./src/upload
-img-list
'
;
import
Upload
from
'./src/upload'
;
/* istanbul ignore next */
Upload
.
install
=
function
(
Vue
)
{
...
...
packages/form/upload/src/
base-upload
.vue
→
packages/form/upload/src/
upload-audio
.vue
View file @
0f9fe073
<
template
>
<div>
<el-upload
ref=
"upload"
:show-file-list=
"false"
:on-preview=
"handler().handlePreview()"
:on-progress=
"(event, file, fileList)=>handler().uploadVideoProcess(event, file, fileList)"
:file-list=
"data"
:list-type=
"listType"
:on-exceed=
"(files, fileList)=>handler().handleExceed(files,fileList)"
:drag=
"uploadStyle === 'drag' ? true : false"
:limit=
"limit"
:on-success=
"(file) => handler().imageSuccess(file)"
:action=
"uploadDomain"
:before-upload=
"init().beforeUpload"
:multiple=
"multiple"
:headers=
"headers"
class=
"avatar-uploader"
>
<div
v-if=
"uploadType === 'image'"
style=
"display:inline"
>
<div
v-for=
"(item, index) in data"
:key=
"index"
style=
"float:left;"
@
click=
"handler().getIndex(index)"
>
<div
:style=
"style"
class=
"avatar"
>
<i
v-if=
"showDel"
class=
"el-icon-close delete-icon"
title=
"删除"
@
click
.
stop=
"data.splice(index, 1)"
/>
<div
:style=
"`background-image:url($
{item.url})`" class="img"/>
</div>
</div>
</div>
<div
v-if=
"data.length >0 && uploadType === 'video'"
style=
"display:inline"
@
click=
"handler().getIndex(index)"
>
<div
v-for=
"(item,index) in data"
:key=
"index"
style=
"float:left;"
>
<div
:style=
"style"
class=
"avatar"
>
<el-upload
ref=
"upload"
:show-file-list=
"false"
:on-preview=
"handler().handlePreview()"
:file-list=
"data"
:list-type=
"listType"
:on-exceed=
"(files, fileList)=>handler().handleExceed(files,fileList)"
:drag=
"uploadStyle === 'drag' ? true : false"
:limit=
"limit"
:on-success=
"(file) => handler().imageSuccess(file)"
:action=
"uploadDomain"
:before-upload=
"init().beforeUpload"
:multiple=
"multiple"
:headers=
"headers"
class=
"avatar-uploader"
>
<!--音频-->
<div
v-if=
"data.length >0"
style=
"display:inline"
>
<div
v-for=
"(item,index) in data"
:key=
"index"
style=
"float:left;"
@
click
.
stop=
"handler().getIndex(index)"
>
<div
class=
"avatar"
>
<i
class=
"el-icon-close delete-icon"
title=
"删除"
@
click
.
stop=
"data.splice(index, 1)"
/>
<video
id=
"myVideo"
:src=
"item.url"
class=
"avatar video-avatar video_text"
controls=
"controls"
>
您的浏览器不支持视频播放
</video>
<aplayer
class=
"audio-player"
:music=
"item"
></aplayer>
</div>
</div>
<el-progress
v-if=
"videoFlag == true"
type=
"circle"
:percentage=
"videoUploadPercent"
style=
"margin-top:7px;"
></el-progress>
</div>
<i
class=
"el-icon-upload"
v-if=
"uploadStyle === 'drag'"
></i>
<div
class=
"el-upload__text"
v-if=
"uploadStyle === 'drag'"
>
将文件拖到此处,或
<em>
点击上传
</em></div>
<el-button
v-if=
"uploadStyle === 'button' || uploadType === 'file'"
size=
"small"
type=
"primary"
>
点击上传
</el-button>
<i
v-else-if=
"uploadStyle === 'icon' || uploadType === 'image'"
:style=
"style"
class=
"avatar el-icon-plus avatar-uploader-icon"
>
<!--图片和视频-->
<i
:style=
"style"
class=
"avatar el-icon-plus avatar-uploader-icon"
>
<span
class=
"upload-label"
>
{{
label
}}
</span>
</i>
<!--文件类型提示-->
<div
slot=
"tip"
class=
"el-upload__tip"
style=
"margin-top:15px"
>
只能上传
{{
handler
().
listByString
(
fileType
)
}}
文件,且不超过500kb
</div>
</el-upload>
<p
class=
"Upload_pictures"
>
<span></span>
<span>
最多可以上传1个视频,建议大小50M,推荐格式mp4
</span>
</p>
<!-- 文件列表 -->
<transition-group
v-if=
"uploadType === 'file'"
class=
"upload-file-list el-upload-list el-upload-list--text"
name=
"el-fade-in-linear"
tag=
"ul"
>
<li
:key=
"index"
class=
"el-upload-list__item ele-upload-list__item-content"
v-for=
"(file, index) in data"
>
<el-link
:href=
"`$
{baseUrl}${file.url}`" :underline="false" target="_blank">
{{
file
}}
<span
class=
"el-icon-document"
>
{{
file
.
name
}}
</span>
</el-link>
<div
class=
"ele-upload-list__item-content-action"
>
<el-link
:underline=
"false"
@
click=
"handleDelete(index)"
type=
"danger"
>
删除
</el-link>
</div>
</li>
</transition-group>
<span
class=
"upload-tips"
>
{{
tips
}}
</span>
</div>
</
template
>
...
...
@@ -60,6 +28,7 @@ import { mapState } from 'vuex'
import
{
getToken
}
from
'@/utils/auth'
// 验权
export
default
{
name
:
'uploadAudio'
,
props
:
{
//上传文字描述
label
:
{
...
...
@@ -100,6 +69,10 @@ export default{
type
:
Boolean
,
default
:
true
,
},
fileSize
:{
type
:
Number
,
default
:
3
},
// 上传图片后是否显示图
show
:
{
type
:
Boolean
,
...
...
@@ -212,8 +185,8 @@ export default{
},
},
watch: {
value(
) {
this.data = this.
value
value(value
) {
this.data = this.
init().data(value)
},
data() {
this.$emit('
input
', this.data)
...
...
@@ -224,27 +197,47 @@ export default{
this.index = null;
this.data = this.value
this.init().token()
// if(this.uploadType === '
video
'){
// this.handler().initVideo();
// }
},
methods: {
init() {
return {
// 上传前置操作
beforeUpload: (file) => {
if(this.uploadType === '
video
'){
var fileSize = file.size / 1024 / 1024 < 50;
if (['
video
/
mp4
', '
video
/
ogg
', '
video
/
flv
', '
video
/
avi
', '
video
/
wmv
', '
video
/
rmvb
', '
video
/
mov
'].indexOf(file.type) == -1) {
this.$message("请上传正确的视频格式");
return false;
}
if (!fileSize) {
this.$message("视频大小不能超过50MB");
return false;
// 初始化返回数据
value: (list) => {
let value = ''
const { dataType } = this
switch(dataType) {
case '
string
': // 字符串类型以逗号隔开
value = list.join('
,
')
break
case '
json
':
value = JSON.stringify(list)
break
case '
array
':
value = list
break
}
this.isShowUploadVideo = false;
return value
},
// 初始化数据
data: (value) => {
let data = ''
const { dataType } = this
switch(dataType) {
case '
string
': // 字符串类型以逗号隔开
data = value ? value.split('
,
') : []
break
case '
json
':
data = value ? JSON.parse(value) : []
break
case '
array
':
data = value
break
}
data = Array.isArray(data) ? data : []
return data
},
// 上传前置操作
beforeUpload: (file) => {
// 校检文件类型
if (this.fileType) {
let fileExtension = "";
...
...
@@ -272,7 +265,7 @@ export default{
const { name } = file
let path = `${dayjs().format('
YYYY
/
MM
/
DD
')}/${dayjs().format('
YYYYMMDDHHmmss
')}${Math.ceil(Math.random() * 1000000 % 1000000)}`
console.log('
path
', path)
//
console.log('
path
', path)
path = path.replace('
(
', '')
path = path.replace('
)
', '')
path = path.replace('
', '')
...
...
@@ -323,13 +316,6 @@ export default{
this.data = this.index != null ? this.data.splice(this.index,1,attr) : this.data.push(attr);
this.$refs.upload.clearFiles();
},
//进度条
uploadVideoProcess:(event, file, fileList)=>{
if(this.uploadType === '
video
'){
this.videoFlag = true;
this.videoUploadPercent = file.percentage.toFixed(0) * 1;
}
},
//获取索引
getIndex:(index)=>{
this.index = index;
...
...
@@ -339,20 +325,18 @@ export default{
this.$message.error(`上传文件数量不能超过 ${this.limit} 个!`);
},
handlePreview:(file)=>{
console.log(file);
},
initVideo:()=>{
//初始化视频方法
let myPlayer = this.$video(myVideo, {
//是否显示控制栏
controls: true,
//是否自动播放,muted:静音播放
autoplay: false,
//是否静音播放
muted:false,
//是否流体自适应容器宽高
fluid:true,
});
// console.log(file);
},
//过滤数组
listByString:(data)=>{
let attr = '';
if(typeof data == '
object
' || typeof data == '
array
'){
data.map((item)=>{
attr+=item+'
/
'
})
attr = attr.slice(0,attr.length-1);
}
return attr
},
// 获取文件名称
getFileName:(name)=>{
...
...
packages/form/upload/src/upload-file.vue
View file @
0f9fe073
This diff is collapsed.
Click to expand it.
packages/form/upload/src/upload-img-list.vue
View file @
0f9fe073
...
...
@@ -3,18 +3,14 @@
<div
v-for=
"(item, index) in list"
:key=
"index"
class=
"avatar-uploader img"
>
<div
class=
"img-box"
>
<i
v-if=
"edit"
class=
"el-icon-close delete-icon"
title=
"删除"
@
click
.
stop=
"list.splice(index, 1)"
/>
<
uploadi
mg
v-model=
"list"
<
UploadI
mg
v-model=
"list
[index]
"
:multiple=
"false"
:show-del=
"false"
:tips=
"tips"
:source=
"source"
:uploadstyle=
"uploadstyle"
:datatype=
"datatype"
:listtype=
"listtype"
:size=
"size"
class=
"uploadimg"
>
</uploadimg>
class=
"uploadImg"
/>
</div>
</div>
<div
v-if=
"list.length
<
limit
&&
edit
"
class=
"avatar-uploader"
>
...
...
@@ -26,10 +22,6 @@
:tips=
"tips"
:source=
"source"
:size=
"size"
v-model=
"value"
:dataType=
"dataType"
:uploadStyle=
"uploadStyle"
:listType=
"listType"
class=
"uploadImg"
@
on-success=
"(e) => handler().upload(e)"
/>
</div>
...
...
@@ -38,9 +30,8 @@
<
script
>
import
UploadImg
from
'./upload-img'
export
default
{
name
:
'CyUploadImg'
,
name
:
'CyUploadImg
List
'
,
components
:
{
UploadImg
,
},
...
...
@@ -51,10 +42,10 @@ export default{
},
limit
:
{
// 图片上传数量限制,默认10
type
:
Number
,
default
:
1
0
,
default
:
1
,
},
value
:
{
type
:
null
,
type
:
[
String
,
Object
,
Array
]
,
default
:
null
,
},
edit
:
{
// 是否可编辑
...
...
@@ -84,16 +75,6 @@ export default{
type
:
Number
,
default
:
100
,
},
//上传组件风格
uploadStyle
:{
type
:
String
,
default
:
'icon'
},
//文件样式
listType
:{
type
:
String
,
default
:
''
},
},
data
()
{
return
{
...
...
@@ -113,7 +94,7 @@ export default{
},
},
created
()
{
this
.
list
=
this
.
init
().
data
(
this
.
value
)
;
this
.
list
=
this
.
init
().
data
(
this
.
value
)
},
methods
:
{
init
()
{
...
...
@@ -188,6 +169,7 @@ export default{
<
style
lang=
"scss"
scoped
>
.upload-imags-list
{
font-size
:
0
;
overflow
:
auto
;
.avatar-uploader
{
display
:
block
;
display
:
inline-block
;
...
...
packages/form/upload/src/upload-img.vue
View file @
0f9fe073
This diff is collapsed.
Click to expand it.
packages/form/upload/src/upload-video.vue
View file @
0f9fe073
This diff is collapsed.
Click to expand it.
packages/form/upload/src/upload.vue
View file @
0f9fe073
<
template
>
<div
class=
"upload-imags-list"
>
<div
class=
"img-box"
>
<UploadImg
v-model=
"list"
<div>
<UploadImageList
v-if=
"type === 'image'"
:label=
"label"
:limit=
"limit"
:edit=
"edit"
v-model=
"value"
:showDel=
"showDel"
:dialog=
"dialog"
:data-type=
"dataType"
:multiple=
"multiple"
:show-del=
"false"
:tips=
"tips"
:source=
"source"
:size=
"size"
/>
<UploadFile
v-if=
"type === 'file'"
:label=
"label"
:limit=
"limit"
:uploadType=
"uploadType"
:showDel=
"showDel"
v-model=
"value"
:edit=
"edit"
:dialog=
"dialog"
:data-type=
"dataType"
:tips=
"tips"
:source=
"source"
:size=
"size"
/>
<UploadVideo
v-if=
"type === 'video'"
:label=
"label"
:limit=
"limit"
:edit=
"edit"
:showDel=
"showDel"
v-model=
"value"
:dialog=
"dialog"
:data-type=
"dataType"
:tips=
"tips"
:source=
"source"
:size=
"size"
/>
<UploadAudio
v-if=
"type === 'audio'"
:label=
"label"
:limit=
"limit"
:edit=
"edit"
:showDel=
"showDel"
v-model=
"value"
:dialog=
"dialog"
class=
"uploadImg"
/>
</div>
:data-type=
"dataType"
:tips=
"tips"
:source=
"source"
:size=
"size"
/>
</div>
</
template
>
<
script
>
import
UploadImg
from
'./base-upload'
export
default
{
name
:
'Upload'
,
import
UploadImageList
from
'./upload-img-list'
import
UploadFile
from
'./upload-file'
import
UploadVideo
from
'./upload-video'
import
UploadAudio
from
'./upload-audio'
export
default
{
name
:
'CyUpload'
,
components
:
{
UploadImg
,
UploadImageList
,
UploadFile
,
UploadVideo
,
UploadAudio
,
},
props
:
{
// 上传类型,可选值,image,file,video,audio
type
:
{
type
:
String
,
default
:
'image'
,
},
label
:
{
type
:
String
,
default
:
'上传'
,
},
limit
:
{
//
文件
上传数量限制,默认10
limit
:
{
//
图片
上传数量限制,默认10
type
:
Number
,
default
:
10
,
},
//是否删除
showDel
:{
type
:
Boolean
,
default
:
true
,
},
//上传类型
uploadType
:{
type
:
String
,
default
:
'file'
default
:
1
,
},
value
:
{
type
:
[
String
,
Object
,
Array
],
default
:
null
,
},
// 是否多选
multiple
:
{
type
:
Boolean
,
default
:
false
,
},
edit
:
{
// 是否可编辑
type
:
Boolean
,
default
:
true
,
},
// 是否使用
文件
库组件
// 是否使用
图片
库组件
dialog
:
{
type
:
Boolean
,
default
:
true
,
},
//是否
多选文件
multiple
:
{
//是否
显示可删除
showDel
:
{
type
:
Boolean
,
default
:
false
default
:
true
,
},
//
文件
列表数据结构,json,array,string
//
图片
列表数据结构,json,array,string
dataType
:
{
type
:
String
,
default
:
'string'
,
...
...
@@ -83,148 +120,6 @@ export default{
type
:
Number
,
default
:
100
,
},
//上传组件风格
uploadStyle
:{
type
:
String
,
default
:
'icon'
},
//文件样式
listType
:{
type
:
String
,
default
:
''
},
},
data
()
{
return
{
dialog_visible
:
false
,
qiniuToken
:
''
,
list
:
[],
// 文件列表
index
:
''
,
}
},
watch
:
{
value
(
value
)
{
this
.
list
=
this
.
init
().
data
(
value
)
},
list
(
value
)
{
const
data
=
this
.
init
().
value
(
value
)
this
.
$emit
(
'input'
,
data
)
},
},
created
()
{
this
.
list
=
this
.
init
().
data
(
this
.
value
)
},
methods
:
{
init
()
{
return
{
// 初始化返回数据
value
:
(
list
)
=>
{
let
value
=
''
const
{
dataType
}
=
this
switch
(
dataType
)
{
case
'string'
:
// 字符串类型以逗号隔开
value
=
list
.
join
(
','
)
break
case
'json'
:
value
=
JSON
.
stringify
(
list
)
break
case
'array'
:
value
=
list
break
}
return
value
},
// 初始化数据
data
:
(
value
)
=>
{
let
data
=
''
const
{
dataType
}
=
this
if
(
value
!=
null
){
switch
(
dataType
)
{
case
'string'
:
// 字符串类型以逗号隔开
data
=
value
?
value
.
split
(
','
)
:
[]
break
case
'json'
:
data
=
value
?
JSON
.
parse
(
value
)
:
[]
break
case
'array'
:
data
=
value
break
}
}
data
=
Array
.
isArray
(
data
)
?
data
:
[]
return
data
},
}
},
handler
()
{
return
{
upload
:
(
key
)
=>
{
this
.
list
.
push
(
key
)
},
choiceImg
:
(
index
)
=>
{
if
(
!
this
.
edit
)
{
return
}
this
.
index
=
index
this
.
$refs
.
uploadImg
.
show
()
},
confirm
:
(
data
)
=>
{
const
{
index
,
limit
}
=
this
let
{
list
}
=
this
if
(
index
===
''
)
{
list
=
list
.
concat
(
data
)
}
else
{
list
.
splice
(
index
,
1
,
data
)
}
this
.
list
=
list
.
slice
(
0
,
limit
)
const
value
=
this
.
init
().
value
(
this
.
list
)
this
.
$emit
(
'input'
,
value
)
},
}
},
},
}
</
script
>
<
style
lang=
"scss"
scoped
>
.upload-imags-list
{
font-size
:
0
;
.avatar-uploader
{
display
:
block
;
display
:
inline-block
;
margin-right
:
5px
;
margin-bottom
:
5px
;
float
:
left
;
.img-box
{
width
:
100%
;
height
:
100%
;
box-sizing
:
border-box
;
border-radius
:
4px
;
position
:
relative
;
.delete-icon
{
position
:
absolute
;
top
:
0
;
right
:
0
;
font-size
:
16px
;
background
:
red
;
color
:
white
;
border-radius
:
4px
;
z-index
:
100
;
cursor
:
pointer
;
}
.img
{
background-position
:
center
;
background-size
:
contain
;
background-repeat
:
no-repeat
;
width
:
100%
;
height
:
100%
;
}
}
.avatar-uploader-icon
{
box-sizing
:
border-box
;
}
}
}
</
style
>
packages/layout/src/layout-form.vue
View file @
0f9fe073
...
...
@@ -48,7 +48,7 @@
<cyupload
:ref=
"form[item.field]"
v-model=
"form[item.field]"
:
uploadT
ype=
"item.type"
:
t
ype=
"item.type"
:limit=
"(item.upload && item.upload.limit) || 1"
:size=
"(item.upload && item.upload.size) || 100"
:dataType=
"(item.upload && item.upload.dataType) || 'array'"
...
...
@@ -58,6 +58,7 @@
:multiple=
"(item.upload && item.upload.multiple) || false"
:tips=
"(item.upload && item.upload.tips) || ''"
:source=
"(item.upload && item.upload.source) || ''"
:fileType=
"(item.upload && item.upload.fileType)"
/>
<!--
<cy-upload
:ref=
"form[item.field]"
...
...
@@ -109,12 +110,10 @@
<
script
>
import
request
from
'@/utils/request'
import
{
getDicts
}
from
'@/api/system/dict/data'
import
uploadImg
from
'../../form/upload/src/upload-img'
import
uploadFile
from
'../../form/upload/src/upload-file'
import
Cyupload
from
'../../form/upload/src/upload'
export
default
{
components
:{
uploadImg
,
uploadFile
,
Cyupload
Cyupload
},
props
:
{
primaryKey
:
{
...
...
@@ -260,8 +259,8 @@ export default {
fieldList
.
forEach
(
item
=>
{
const
{
field
,
type
}
=
item
let
{
value
,
placeholder
,
attr
,
checkboxGroup
,
dict
,
options
}
=
item
console
.
log
(
options
);
console
.
log
(
value
);
//
console.log(options);
//
console.log(value);
attr
=
attr
||
{}
checkboxGroup
=
checkboxGroup
||
{}
if
(
!
placeholder
)
{
...
...
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