Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
P
poc-fe
Project
Project
Details
Activity
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
poc
poc-fe
Commits
5fbf2a29
Commit
5fbf2a29
authored
Nov 22, 2024
by
nick zheng
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'beta' into 'master'
chore: 应用更新头像支持裁切 See merge request
!88
parents
520e97cc
c494f7af
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
16 deletions
+20
-16
upload-image.vue
src/components/upload-image/upload-image.vue
+20
-16
No files found.
src/components/upload-image/upload-image.vue
View file @
5fbf2a29
<
script
setup
lang=
"ts"
>
<
script
setup
lang=
"ts"
>
import
{
computed
,
ref
,
useSlots
}
from
'vue'
import
{
computed
,
ref
,
useSlots
,
useTemplateRef
}
from
'vue'
import
CustomIcon
from
'../custom-icon/custom-icon.vue'
import
CustomIcon
from
'../custom-icon/custom-icon.vue'
import
{
fetchUpload
}
from
'@/apis/upload'
import
{
fetchUpload
}
from
'@/apis/upload'
import
ImageCropper
from
'@/components/image-cropper/image-cropper.vue'
interface
Emit
{
interface
Emit
{
(
e
:
'formatError'
):
void
(
e
:
'formatError'
):
void
...
@@ -20,7 +21,7 @@ const props = defineProps({
...
@@ -20,7 +21,7 @@ const props = defineProps({
},
},
listType
:
{
listType
:
{
type
:
Array
,
type
:
Array
,
default
:
()
=>
[
'jpg'
,
'png'
,
'jpeg'
,
'
svg'
,
'
gif'
],
default
:
()
=>
[
'jpg'
,
'png'
,
'jpeg'
,
'gif'
],
},
},
width
:
{
width
:
{
type
:
Number
,
type
:
Number
,
...
@@ -36,6 +37,8 @@ const emit = defineEmits<Emit>()
...
@@ -36,6 +37,8 @@ const emit = defineEmits<Emit>()
const
slots
=
useSlots
()
const
slots
=
useSlots
()
const
imageCropperRef
=
useTemplateRef
<
InstanceType
<
typeof
ImageCropper
>
|
null
>
(
'imageCropperRef'
)
const
uploadLoading
=
ref
(
false
)
const
uploadLoading
=
ref
(
false
)
const
isShowImageMask
=
ref
(
false
)
const
isShowImageMask
=
ref
(
false
)
...
@@ -66,24 +69,23 @@ async function handleUploadImage(event: any) {
...
@@ -66,24 +69,23 @@ async function handleUploadImage(event: any) {
return
return
}
}
const
URL
=
window
.
URL
||
window
.
webkitURL
if
(
imageCropperRef
.
value
&&
file
)
{
const
img
=
new
Image
()
const
URL
=
window
.
URL
||
window
.
webkitURL
img
.
src
=
URL
.
createObjectURL
(
file
)
imageCropperRef
.
value
.
cropImage
(
URL
.
createObjectURL
(
file
)).
then
(
async
(
file
)
=>
{
const
formData
=
new
FormData
()
formData
.
append
(
'file'
,
file
)
img
.
onload
=
async
function
()
{
uploadLoading
.
value
=
true
const
formData
=
new
FormData
()
formData
.
append
(
'file'
,
file
)
uploadLoading
.
value
=
true
const
res
=
await
fetchUpload
(
formData
).
finally
(()
=>
{
uploadLoading
.
value
=
false
event
.
target
.
value
=
null
})
const
res
=
await
fetchUpload
(
formData
).
finally
(()
=>
{
if
(
res
.
code
===
0
)
{
uploadLoading
.
value
=
false
uploadImageUrl
.
value
=
res
.
data
as
string
event
.
target
.
value
=
null
}
})
})
if
(
res
.
code
===
0
)
{
uploadImageUrl
.
value
=
res
.
data
as
string
}
}
}
}
}
</
script
>
</
script
>
...
@@ -120,5 +122,7 @@ async function handleUploadImage(event: any) {
...
@@ -120,5 +122,7 @@ async function handleUploadImage(event: any) {
<input
id=
"upload"
type=
"file"
:accept=
"uploadImageType"
class=
"hidden"
@
change=
"handleUploadImage"
/>
<input
id=
"upload"
type=
"file"
:accept=
"uploadImageType"
class=
"hidden"
@
change=
"handleUploadImage"
/>
</div>
</div>
<ImageCropper
ref=
"imageCropperRef"
/>
</div>
</div>
</
template
>
</
template
>
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