Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
pptist
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
viitto
pptist
Commits
288c6e0f
Commit
288c6e0f
authored
Dec 02, 2023
by
罗超
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修复行程内容初始化渲染时,图片尺寸问题
parent
8fd06b25
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
76 additions
and
9 deletions
+76
-9
FileService.ts
src/services/FileService.ts
+35
-0
index.vue
src/views/Editor/Thumbnails/index.vue
+41
-9
No files found.
src/services/FileService.ts
0 → 100644
View file @
288c6e0f
class
FileService
{
static
getImageSizeWithoutDownloading
=
async
(
url
:
string
):
Promise
<
{
width
:
number
;
height
:
number
}
>
=>
{
const
response
=
await
fetch
(
url
,
{
method
:
'HEAD'
});
// Use HEAD request to get metadata
const
contentLength
=
response
.
headers
.
get
(
'Content-Length'
);
if
(
!
contentLength
)
{
throw
new
Error
(
'Unable to determine Content-Length'
);
}
const
rangeEnd
=
Math
.
min
(
parseInt
(
contentLength
,
10
),
1024
);
// Read the first 1KB of data
const
partialResponse
=
await
fetch
(
url
,
{
headers
:
{
Range
:
`bytes=0-
${
rangeEnd
}
`
,
},
});
const
blob
=
await
partialResponse
.
blob
();
const
objectURL
=
URL
.
createObjectURL
(
blob
);
const
image
=
new
Image
();
return
new
Promise
((
resolve
,
reject
)
=>
{
image
.
onload
=
()
=>
{
resolve
({
width
:
image
.
width
,
height
:
image
.
height
});
URL
.
revokeObjectURL
(
objectURL
);
};
image
.
onerror
=
reject
;
image
.
src
=
objectURL
;
});
}
}
export
default
FileService
\ No newline at end of file
src/views/Editor/Thumbnails/index.vue
View file @
288c6e0f
...
...
@@ -64,6 +64,9 @@ import ThumbnailSlide from '@/views/components/ThumbnailSlide/index.vue'
import
LayoutPool
from
'./LayoutPool.vue'
import
Popover
from
'@/components/Popover.vue'
import
Draggable
from
'vuedraggable'
import
{
ElLoading
}
from
'element-plus'
import
FileService
from
'@/services/FileService'
import
{
VIEWPORT_SIZE
,
VIEWPORT_VER_SIZE
}
from
'@/configs/canvas'
const
mainStore
=
useMainStore
()
const
slidesStore
=
useSlidesStore
()
...
...
@@ -166,7 +169,15 @@ queryObj.value = inject(injectKeyDataSource).queryObj
// 获取行程团数据初始化数据
const
GetTripFiledData
=
async
()
=>
{
console
.
log
(
'初始化行程'
,
'----------'
)
const
loadingObj
=
ElLoading
.
service
({
text
:
'正在渲染团队数据'
,
lock
:
true
})
let
maxWidth
=
VIEWPORT_SIZE
,
maxHeight
=
VIEWPORT_VER_SIZE
,
viewportRatio
=
slidesStore
.
viewportRatio
if
(
viewportRatio
<
1
){
maxWidth
=
VIEWPORT_VER_SIZE
maxHeight
=
VIEWPORT_SIZE
}
const
slidesData
=
slides
.
value
try
{
let
queryMsg
=
{
...
...
@@ -177,12 +188,15 @@ const GetTripFiledData = async () =>{
if
(
!
dataRes
.
data
.
data
)
return
const
travel
=
dataRes
.
data
.
data
const
cursors
=
[]
as
Array
<
any
>
slidesData
.
forEach
((
x
,
index
)
=>
{
x
.
elements
.
forEach
(
y
=>
{
if
(
y
.
TemplateDataSource
&&
y
.
TemplateDataSource
.
Content
){
for
(
let
index
=
0
;
index
<
slidesData
.
length
;
index
++
)
{
const
x
=
slidesData
[
index
]
as
any
;
for
(
let
j
=
0
;
j
<
x
.
elements
.
length
;
j
++
)
{
const
y
=
x
.
elements
[
j
];
if
(
y
.
TemplateDataSource
&&
y
.
TemplateDataSource
.
Content
){
let
dataPath
=
y
.
TemplateDataSource
.
Content
.
split
(
'.'
)
let
value
=
JSON
.
parse
(
JSON
.
stringify
(
travel
));
dataPath
.
forEach
((
oo
,
i
)
=>
{
for
(
let
i
=
0
;
i
<
dataPath
.
length
;
i
++
)
{
const
oo
=
dataPath
[
i
];
if
(
value
&&
value
[
oo
]){
if
(
i
==
0
&&
Array
.
isArray
(
value
[
oo
])){
let
temp
=
cursors
.
find
(
item
=>
item
.
key
==
oo
)
...
...
@@ -193,7 +207,6 @@ const GetTripFiledData = async () =>{
cursors
.
push
(
temp
)
}
if
(
y
.
TemplateDataSource
.
index
!=
null
&&
y
.
TemplateDataSource
.
index
>=
0
){
console
.
log
(
value
[
oo
],
'-------'
)
if
(
value
[
oo
].
length
>
temp
.
index
)
value
=
value
[
oo
][
y
.
TemplateDataSource
.
index
]
}
else
{
if
(
value
[
oo
].
length
>
temp
.
index
)
value
=
value
[
oo
][
temp
.
index
]
...
...
@@ -205,24 +218,43 @@ const GetTripFiledData = async () =>{
}
else
{
value
=
null
}
}
)
}
if
(
value
&&
typeof
(
value
)
==
'string'
){
//替换
y
.
content
=
y
.
content
.
replace
(
getHtmlPlainText
(
y
.
content
),
value
)
}
else
if
(
value
&&
Array
.
isArray
(
value
)){
//替换
if
(
y
.
type
==
'image'
){
console
.
log
(
'下载图片开始'
,
new
Date
().
getSeconds
())
try
{
let
tempSize
=
await
FileService
.
getImageSizeWithoutDownloading
(
value
[
0
])
if
(
tempSize
.
width
>
maxWidth
){
let
ratio
=
maxWidth
/
tempSize
.
width
tempSize
.
width
=
maxWidth
tempSize
.
height
=
tempSize
.
height
*
ratio
}
if
(
tempSize
.
height
>
maxHeight
){
let
ratio
=
maxHeight
/
tempSize
.
height
tempSize
.
height
=
maxHeight
tempSize
.
width
=
tempSize
.
width
*
ratio
}
if
(
y
.
left
<
0
)
y
.
left
=
0
if
(
y
.
top
<
0
)
y
.
top
=
0
y
.
width
=
tempSize
.
width
y
.
height
=
tempSize
.
height
}
catch
(
error
)
{
}
y
.
src
=
value
[
0
]
}
}
}
})
}
)
}
}
slidesStore
.
setSlides
(
slidesData
)
}
}
catch
(
error
)
{
console
.
log
(
"triptemplateGetTripFiledData"
,
error
);
}
loadingObj
.
close
()
}
// 获取行程模版数据
...
...
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