Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
submodule
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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
web_component
submodule
Commits
0516c083
Commit
0516c083
authored
Jun 02, 2020
by
zhangwenshuai
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix upload
parent
2c82bb10
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
12 deletions
+24
-12
index.tsx
components/apolloTable/component/base/extra/upload/index.tsx
+24
-12
No files found.
components/apolloTable/component/base/extra/upload/index.tsx
View file @
0516c083
...
@@ -11,10 +11,8 @@ message.config({
...
@@ -11,10 +11,8 @@ message.config({
});
});
const
UploadCom
=
(
props
)
=>
{
const
UploadCom
=
(
props
)
=>
{
const
{
const
{
onChange
,
CDN_HOST
,
getFormat
,
setFormat
,
data
,
domain
}
=
props
;
onChange
,
CDN_HOST
,
getFormat
,
setFormat
,
data
,
domain
,
const
selfProps
=
antiAssign
(
props
,
[
'onChange'
,
'CDN_HOST'
,
'data'
]);
}
=
props
;
const
selfProps
=
antiAssign
(
props
,
[
'onChange'
,
'CDN_HOST'
]);
const
getFormatFileList
=
(
fileList
=
[])
=>
{
const
getFormatFileList
=
(
fileList
=
[])
=>
{
if
(
!
fileList
)
{
if
(
!
fileList
)
{
return
[];
return
[];
...
@@ -39,8 +37,8 @@ const UploadCom = (props) => {
...
@@ -39,8 +37,8 @@ const UploadCom = (props) => {
if
(
typeof
setFormat
===
'function'
)
{
if
(
typeof
setFormat
===
'function'
)
{
return
setFormat
(
fileList
);
return
setFormat
(
fileList
);
}
}
const
d
ata
=
file
.
response
||
{};
const
resD
ata
=
file
.
response
||
{};
const
url
=
`
${
domain
?
`https://
${
domain
}
`
:
CDN_HOST
}
/
${
d
ata
.
key
}
`
;
const
url
=
`
${
domain
?
`https://
${
domain
}
`
:
CDN_HOST
}
/
${
resD
ata
.
key
}
`
;
return
{
return
{
uid
:
file
.
uid
,
uid
:
file
.
uid
,
name
:
file
.
name
,
name
:
file
.
name
,
...
@@ -55,19 +53,26 @@ const UploadCom = (props) => {
...
@@ -55,19 +53,26 @@ const UploadCom = (props) => {
},
[
props
.
value
]);
},
[
props
.
value
]);
const
previewModel
=
useRef
<
any
>
();
const
previewModel
=
useRef
<
any
>
();
// 自定义七牛文件唯一key
// 自定义七牛文件唯一key
const
getKey
=
(
file
:
any
)
=>
{
const
getKey
=
(
file
:
any
)
=>
{
if
(
!
file
)
return
;
if
(
!
file
)
return
;
const
suffix
=
file
.
name
.
match
(
/
\.\w
+$/
)[
0
];
const
suffix
=
file
.
name
.
match
(
/
\.\w
+$/
)[
0
];
const
rand6
=
getRandom
();
const
rand6
=
getRandom
();
const
time
=
moment
().
format
(
'YYYYMMDDHHmmss'
);
const
time
=
moment
().
format
(
'YYYYMMDDHHmmss'
);
return
time
+
rand6
+
suffix
;
return
time
+
rand6
+
suffix
;
};
};
const
[
extraData
,
setExtraData
]
=
useState
({});
// 七牛上传额外数据,token和key
// 七牛上传额外数据,token和key
const
get
Data
=
async
(
file
:
any
)
=>
{
const
get
Token
=
async
(
)
=>
{
let
ext
ra
Data
=
data
||
{};
let
extData
=
data
||
{};
if
(
typeof
data
===
'function'
)
{
if
(
typeof
data
===
'function'
)
{
extraData
=
await
data
();
const
res
=
await
data
();
if
(
res
&&
res
.
success
)
{
extData
=
res
.
data
;
}
}
}
setExtraData
(
extData
);
};
const
getData
=
(
file
:
any
)
=>
{
return
{
return
{
...
extraData
,
...
extraData
,
key
:
getKey
(
file
),
key
:
getKey
(
file
),
...
@@ -107,20 +112,27 @@ const UploadCom = (props) => {
...
@@ -107,20 +112,27 @@ const UploadCom = (props) => {
}
}
};
};
const
onRemove
=
(
file
)
=>
{
const
onRemove
=
(
file
)
=>
{
const
newFileList
=
fileList
.
filter
((
item
)
=>
{
return
item
.
uid
!==
file
.
uid
;
});
const
newFileList
=
fileList
.
filter
((
item
)
=>
{
return
item
.
uid
!==
file
.
uid
;
});
onSaveFileList
(
newFileList
);
onSaveFileList
(
newFileList
);
};
};
const
beforeUpload
=
async
()
=>
{
await
getToken
();
return
true
;
};
return
(
return
(
<
div
className=
{
s
.
container
}
>
<
div
className=
{
s
.
container
}
>
<
Upload
<
Upload
className=
{
s
.
upload
}
className=
{
s
.
upload
}
listType=
"picture"
listType=
"picture"
action=
"https://upload-z1.qiniup.com/"
// 七牛上传地址
action=
"https://upload-z1.qiniup.com/"
// 七牛上传地址
data=
{
getData
}
multiple
multiple
fileList=
{
fileList
}
fileList=
{
fileList
}
{
...
selfProps
}
{
...
selfProps
}
data=
{
getData
}
beforeUpload=
{
beforeUpload
}
onChange=
{
changeFileList
}
onChange=
{
changeFileList
}
onRemove=
{
onRemove
}
onRemove=
{
onRemove
}
previewFile=
{
previewFile
}
previewFile=
{
previewFile
}
...
...
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