Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Y
yile_pdftoimage
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
template admin
yile_pdftoimage
Commits
9b142e47
Commit
9b142e47
authored
Dec 06, 2024
by
liujiangnan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: PDF转图片
parent
fa23b016
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
76 deletions
+21
-76
index.html
form/index.html
+2
-2
index.js
form/index.js
+19
-74
No files found.
form/index.html
View file @
9b142e47
...
@@ -23,7 +23,7 @@
...
@@ -23,7 +23,7 @@
<div
id=
"edit-data"
class=
"edit-data"
>
<div
id=
"edit-data"
class=
"edit-data"
>
<el-upload
class=
"upload-demo"
drag
<el-upload
class=
"upload-demo"
drag
:action=
"uploadPdfUrl"
:action=
"uploadPdfUrl"
:data=
"uploadPdfData
"
data=
"
"
:show-file-list=
"false"
:show-file-list=
"false"
:on-success=
"handleCoverSuccess"
:on-success=
"handleCoverSuccess"
:on-error=
"handleCoverError"
:on-error=
"handleCoverError"
...
@@ -32,7 +32,7 @@
...
@@ -32,7 +32,7 @@
>
>
<i
class=
"el-icon-upload"
></i>
<i
class=
"el-icon-upload"
></i>
<div
class=
"el-upload__text"
>
将文件拖到此处,或
<em>
点击上传
</em></div>
<div
class=
"el-upload__text"
>
将文件拖到此处,或
<em>
点击上传
</em></div>
<div
class=
"el-upload__tip"
slot=
"tip"
>
只能上传pdf
/ppt/word
文件,且不超过100Mb
</div>
<div
class=
"el-upload__tip"
slot=
"tip"
>
只能上传pdf文件,且不超过100Mb
</div>
</el-upload>
</el-upload>
<!-- 添加进度条和取消按钮 -->
<!-- 添加进度条和取消按钮 -->
...
...
form/index.js
View file @
9b142e47
...
@@ -13,33 +13,19 @@ new Vue({
...
@@ -13,33 +13,19 @@ new Vue({
created
()
{
created
()
{
window
.
courseware
.
getData
(
async
(
dt
)
=>
{
window
.
courseware
.
getData
(
async
(
dt
)
=>
{
this
.
fileData
=
dt
;
this
.
fileData
=
dt
;
if
(
this
.
fileData
&&
this
.
fileData
.
ppt_html
)
{
this
.
showErrorMsg
=
true
;
this
.
showErrorMsg
=
await
this
.
checkUrl
(
this
.
fileData
.
ppt_html
);
if
(
!
this
.
showErrorMsg
&&
this
.
fileData
.
items
.
length
==
0
)
{
await
this
.
setPptImageItems
();
}
}
},
key
);
},
key
);
window
[
'
air
'
].
getUploadCallback
=
(
url
,
data
)
=>
{
window
[
'
air
'
].
getUploadCallback
=
(
url
,
data
)
=>
{
this
.
uploadUrl
=
url
;
this
.
uploadUrl
=
url
;
this
.
uploadCover
=
data
;
this
.
uploadCover
=
data
;
this
.
uploadData
=
data
;
this
.
uploadData
=
data
;
};
};
setInterval
(
async
()
=>
{
if
(
this
.
fileData
&&
this
.
fileData
.
ppt_html
)
{
this
.
showErrorMsg
=
await
this
.
checkUrl
(
this
.
fileData
.
ppt_html
);
if
(
!
this
.
showErrorMsg
&&
this
.
fileData
.
items
.
length
==
0
)
{
await
this
.
setPptImageItems
();
}
}
},
5000
);
},
},
data
()
{
data
()
{
var
protocolStr
=
document
.
location
.
protocol
;
return
{
return
{
//封面上传相关
//封面上传相关
fileData
:
null
,
fileData
:
null
,
uploadPdfUrl
:
`
${
protocolStr
}
//opensource.iteachabc.com/pdfUpload`
,
uploadUrl
:
window
.
courseware
.
uploadUrl
(),
uploadUrl
:
window
.
courseware
.
uploadUrl
(),
uploadCover
:
window
.
courseware
.
uploadData
(),
uploadCover
:
window
.
courseware
.
uploadData
(),
uploadData
:
window
.
courseware
.
uploadData
(),
uploadData
:
window
.
courseware
.
uploadData
(),
...
@@ -51,57 +37,6 @@ new Vue({
...
@@ -51,57 +37,6 @@ new Vue({
}
}
},
},
methods
:
{
methods
:
{
async
setPptImageItems
()
{
if
(
!
this
.
fileData
||
!
this
.
fileData
.
ppt_html
)
{
return
;
}
let
index
=
1
;
let
url
=
this
.
fileData
.
ppt_html
.
replace
(
"
index.html
"
,
`pic/
${
index
}
.jpg`
);
let
flag
=
await
this
.
checkUrl
(
url
);
while
(
!
flag
)
{
this
.
fileData
.
items
.
push
({
text_en
:
''
,
text_cn
:
''
,
audio_url
:
''
,
image_url
:
url
,
audio_name
:
''
,
audio_size
:
''
,
audio_duration
:
''
,
isPlaying
:
false
,
});
index
++
;
url
=
this
.
fileData
.
ppt_html
.
replace
(
"
index.html
"
,
`pic/
${
index
}
.jpg`
);
flag
=
await
this
.
checkUrl
(
url
);
}
this
.
save
();
},
// 检查 URL 是否可访问
async
checkUrl
(
url
)
{
try
{
const
response
=
await
fetch
(
url
);
const
text
=
await
response
.
text
();
// 检查返回内容是否包含错误 XML
if
(
text
.
includes
(
'
<Error>
'
)
&&
text
.
includes
(
'
<Code>NoSuchKey</Code>
'
))
{
return
true
;
}
else
{
return
false
;
}
}
catch
(
error
)
{
console
.
error
(
'
检查URL时出错:
'
,
error
);
return
true
;
}
},
getProxiedUrl
(
url
)
{
try
{
if
(
document
.
domain
==
'
localhost
'
)
{
return
url
;
}
const
urlObj
=
new
URL
(
url
);
return
`
${
urlObj
.
pathname
}${
urlObj
.
search
}${
urlObj
.
hash
}
`
;
}
catch
(
e
)
{
return
url
;
}
},
customUpload
(
options
)
{
customUpload
(
options
)
{
this
.
uploading
=
true
;
this
.
uploading
=
true
;
this
.
uploadProgress
=
0
;
this
.
uploadProgress
=
0
;
...
@@ -142,7 +77,7 @@ new Vue({
...
@@ -142,7 +77,7 @@ new Vue({
this
.
xhr
=
null
;
this
.
xhr
=
null
;
};
};
xhr
.
open
(
'
POST
'
,
this
.
uploadUrl
,
true
);
xhr
.
open
(
'
POST
'
,
this
.
upload
Pdf
Url
,
true
);
xhr
.
send
(
formData
);
xhr
.
send
(
formData
);
},
},
cancelUpload
()
{
cancelUpload
()
{
...
@@ -160,11 +95,21 @@ new Vue({
...
@@ -160,11 +95,21 @@ new Vue({
this
.
fileData
=
{
this
.
fileData
=
{
name
:
file
.
name
,
name
:
file
.
name
,
url
:
response
.
url
,
url
:
response
.
url
,
ppt_html
:
response
.
ppt_html
?
response
.
ppt_html
.
replace
(
"
staging-
"
,
""
):
""
,
items
:
[],
items
:
[],
};
};
if
(
response
.
imagesUrls
){
this
.
fileData
.
items
=
response
.
imagesUrls
.
map
(
item
=>
({
text_en
:
''
,
text_cn
:
''
,
audio_url
:
''
,
image_url
:
item
,
audio_name
:
''
,
audio_size
:
''
,
audio_duration
:
''
,
isPlaying
:
false
,
}));
}
this
.
save
();
this
.
save
();
this
.
showErrorMsg
=
false
;
}
}
},
},
handleCoverError
(
err
,
file
,
fileList
)
{
handleCoverError
(
err
,
file
,
fileList
)
{
...
@@ -177,15 +122,15 @@ new Vue({
...
@@ -177,15 +122,15 @@ new Vue({
this
.
$message
.
warning
(
'
请等待当前文件上传完成或取消上传
'
);
this
.
$message
.
warning
(
'
请等待当前文件上传完成或取消上传
'
);
return
false
;
return
false
;
}
}
const
is
Office
=
(
file
.
type
===
'
application/pdf
'
||
file
.
type
.
indexOf
(
`application/vnd.openxmlformats`
)
==
0
);
const
is
Pdf
=
(
file
.
type
===
'
application/pdf
'
);
const
isLt2M
=
file
.
size
/
1024
/
1024
/
1024
<
2
;
const
isLt2M
=
file
.
size
/
1024
/
1024
/
1024
<
2
;
if
(
!
is
Office
)
{
if
(
!
is
Pdf
)
{
this
.
$message
.
error
(
'
上传文件必须是PDF
/Word/PPT
!
'
);
this
.
$message
.
error
(
'
上传文件必须是PDF!
'
);
}
else
if
(
!
isLt2M
)
{
}
else
if
(
!
isLt2M
)
{
this
.
$message
.
error
(
'
上传文件大小不能超过 200MB!
'
);
this
.
$message
.
error
(
'
上传文件大小不能超过 200MB!
'
);
}
}
return
is
Office
&&
isLt2M
;
return
is
Pdf
&&
isLt2M
;
},
},
save
()
{
save
()
{
...
...
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