#I9FSZ3 解决导出word没有图片的问题
This commit is contained in:
5
pom.xml
5
pom.xml
@@ -166,6 +166,11 @@
|
||||
<artifactId>hutool-all</artifactId>
|
||||
<version>5.6.6</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jsoup</groupId>
|
||||
<artifactId>jsoup</artifactId>
|
||||
<version>1.17.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.zyplayer</groupId>
|
||||
<artifactId>zyplayer-doc-core</artifactId>
|
||||
|
||||
@@ -15,6 +15,7 @@ public class DocUserDetails {
|
||||
private Long userId;
|
||||
private String username;
|
||||
private String password;
|
||||
private String accessToken;
|
||||
private boolean enabled;
|
||||
private List<UserAuthInfo> userAuthList;
|
||||
|
||||
|
||||
@@ -69,6 +69,7 @@ public class DocUserUtil {
|
||||
* 设置当前用户
|
||||
*/
|
||||
public static void setCurrentUser(String accessToken, DocUserDetails docUser) {
|
||||
docUser.setAccessToken(accessToken);
|
||||
DOC_USER_DETAILS.set(docUser);
|
||||
CacheUtil.put(accessToken, docUser);
|
||||
CacheUtil.put(CachePrefix.LOGIN_USER_ID_TOKEN + docUser.getUserId(), accessToken);
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
# 端口和根路径,jar启动时依此处配置,放tomcat后以tomcat的配置为准
|
||||
server:
|
||||
port: ${SERVER_PORT:8083}
|
||||
@@ -19,6 +18,12 @@ zyplayer:
|
||||
doc:
|
||||
# ------zyplayer_doc_manage相关配置------
|
||||
manage:
|
||||
# 管理端的数据库配置
|
||||
datasource:
|
||||
driverClassName: ${DATASOURCE_DRIVER:com.mysql.cj.jdbc.Driver}
|
||||
url: jdbc:mysql://${DATASOURCE_HOST_PORT:127.0.0.1:3306}/${DATASOURCE_DATABASE:zyplayer_doc_opensource}?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&autoReconnect=true&useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true
|
||||
username: ${DATASOURCE_USER:root}
|
||||
password: ${DATASOURCE_PASSWORD:root}
|
||||
enable:
|
||||
#wiki模块的是否加载,没有此配置也为true,只有填写false才是不加载
|
||||
wiki: ${ZYPLAYER_ENABLE_WIKI:true}
|
||||
@@ -30,28 +35,12 @@ zyplayer:
|
||||
upgradePropertiesUrl: https://gitee.com/zyplayer/zyplayer-doc/raw/master/upgrade.properties
|
||||
# 系统根域名,调试UI时需要使用,同时需要在host文件里配置:127.0.0.1 local.zyplayer.com
|
||||
originDomainRegex: .*\.zyplayer\.com(:\d+|)$
|
||||
# 管理端的数据库配置
|
||||
datasource:
|
||||
driverClassName: ${DATASOURCE_DRIVER:com.mysql.cj.jdbc.Driver}
|
||||
url: jdbc:mysql://${DATASOURCE_HOST_PORT:127.0.0.1:3306}/${DATASOURCE_DATABASE:zyplayer_doc}?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&autoReconnect=true&useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true
|
||||
username: ${DATASOURCE_USER:root}
|
||||
password: ${DATASOURCE_PASSWORD:root}
|
||||
# ------WIKI文档相关------
|
||||
wiki:
|
||||
# WIKI文档的文件上传后的存储目录,!!截图或文件还是很重要的,建议您还要定期备份此目录的文件呢!!
|
||||
upload-path: ${SERVER_PORT:/zyplayerDoc/wikiFiles}
|
||||
# 是否检查目录有被系统定期清理的风险,强烈建议开启
|
||||
upload-path: ${WIKI_UPLOAD_PATH:D:/zyplayerDoc/wikiFiles}
|
||||
# 是否检查目录有被系统定期清理的风险,建议开启
|
||||
upload-path-check: true
|
||||
# git本地仓库地址,用于管理WIKI的历史版本
|
||||
git-local-path: ${SERVER_PORT:/zyplayerDoc/wikiGitFiles}
|
||||
# git远程仓库地址,可选配置项,如果存在则会每次修改后push到此仓库,必须先创建远程仓库,项目初始化时会去拉取
|
||||
# 如果没有配置此项,则只会在维护一个本地的git仓库,使用简单
|
||||
# 例:https://gitee.com/zyplayer/zyplayer-doc-wiki-files.git
|
||||
git-remote-url:
|
||||
# git远程仓库登录账号
|
||||
git-remote-username:
|
||||
# git远程仓库登录密码
|
||||
git-remote-password:
|
||||
# ------数据库相关配置------
|
||||
db:
|
||||
# 最大允许导出的行数,设置的过大有可能会导致内存溢出
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
ENV = 'development'
|
||||
|
||||
# base api
|
||||
VITE_APP_BASE_API = 'http://local.zyplayer.com:8083/zyplayer-doc'
|
||||
VITE_APP_BASE_API = 'http://local.zyplayer.com:8083'
|
||||
# VITE_APP_BASE_API = 'http://zyplayer.com'
|
||||
|
||||
|
||||
|
||||
21
zyplayer-doc-ui/wiki-ui/src/assets/api/hostUtils.js
Normal file
21
zyplayer-doc-ui/wiki-ui/src/assets/api/hostUtils.js
Normal file
@@ -0,0 +1,21 @@
|
||||
let baseApi = import.meta.env.VITE_APP_BASE_API;
|
||||
|
||||
export function fixRequestUrl(url) {
|
||||
return fixTwoUrl(baseApi, url);
|
||||
}
|
||||
|
||||
export function fixTwoUrl(url1, url2) {
|
||||
if (!url1 || !url2) {
|
||||
if (!url1 && !url2) {
|
||||
return '';
|
||||
}
|
||||
return url1 || url2;
|
||||
}
|
||||
if (url1.endsWith('/') && url2.startsWith('/')) {
|
||||
return url1 + url2.substring(1);
|
||||
}
|
||||
if (!url1.endsWith('/') && !url2.startsWith('/')) {
|
||||
return url1 + '/' + url2;
|
||||
}
|
||||
return url1 + url2;
|
||||
}
|
||||
@@ -95,6 +95,7 @@ import PageAuthDialog from '@/views/page/show/PageAuthDialog.vue'
|
||||
import MobileQrScanDialog from '@/views/page/show/MobileQrScanDialog.vue'
|
||||
import AboutDialog from "@/views/common/AboutDialog.vue"
|
||||
import UserMessagePopover from "./UserMessagePopover.vue"
|
||||
import {fixRequestUrl} from "@/assets/api/hostUtils";
|
||||
|
||||
let router = useRouter();
|
||||
let storePage = useStorePageData();
|
||||
@@ -177,9 +178,14 @@ const deleteWikiPage = () => {
|
||||
}
|
||||
// 下载为Word
|
||||
let downloadFormRef = ref();
|
||||
let downloadFormParam = ref({url: 'zyplayer-doc-wiki/page/download', param: {}});
|
||||
let downloadFormParam = ref({url: fixRequestUrl('zyplayer-doc-wiki/page/download'), param: {}});
|
||||
const exportWord = () => {
|
||||
downloadFormParam.value.param = {pageId: storePage.pageInfo.id};
|
||||
let pageViewContent = document.getElementById('pageContentBox');
|
||||
let innerHtml = pageViewContent.innerHTML || '';
|
||||
downloadFormParam.value.param = {
|
||||
pageId: storePage.pageInfo.id,
|
||||
content: innerHtml,
|
||||
};
|
||||
setTimeout(() => downloadFormRef.value.submit(), 0);
|
||||
}
|
||||
// 手机扫码
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<el-col :span="navigationList.length > 0 ? 18 : 24">
|
||||
<div style="max-width: 1000px; margin: 0 auto; padding-left: 10px">
|
||||
<div class="wiki-title" ref="wikiTitleRef">{{ storePage.pageInfo.name }}</div>
|
||||
<div ref="pageContentRef" class="wiki-page-content">
|
||||
<div id="pageContentBox" ref="pageContentRef" class="wiki-page-content">
|
||||
<div v-html="pageShowDetail" class="markdown-body" v-if="wikiPage.editorType == 2" v-highlight></div>
|
||||
<div v-html="pageShowDetail" class="wang-editor-body" v-else></div>
|
||||
</div>
|
||||
|
||||
@@ -49,8 +49,10 @@
|
||||
<groupId>com.zyplayer</groupId>
|
||||
<artifactId>zyplayer-doc-core</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.jsoup</groupId>
|
||||
<artifactId>jsoup</artifactId>
|
||||
</dependency>
|
||||
<!--docx4j-->
|
||||
<dependency>
|
||||
<groupId>org.docx4j</groupId>
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package com.zyplayer.doc.wiki.controller;
|
||||
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import cn.hutool.system.SystemUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
@@ -30,17 +33,25 @@ import com.zyplayer.doc.wiki.service.common.WikiPageAuthService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.RegExUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.docx4j.XmlUtils;
|
||||
import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
|
||||
import org.docx4j.openpackaging.parts.WordprocessingML.AltChunkType;
|
||||
import org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart;
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.nodes.Element;
|
||||
import org.jsoup.nodes.Entities;
|
||||
import org.jsoup.select.Elements;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.ServletOutputStream;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.File;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
@@ -417,8 +428,9 @@ public class WikiPageController {
|
||||
}
|
||||
|
||||
@PostMapping("/download")
|
||||
public ResponseJson<Object> download(Long pageId, HttpServletResponse response) {
|
||||
public ResponseJson<Object> download(Long pageId, String content, HttpServletRequest request, HttpServletResponse response) {
|
||||
DocUserDetails currentUser = DocUserUtil.getCurrentUser();
|
||||
String requestURI = request.getRequestURL().toString();
|
||||
WikiPage wikiPageSel = wikiPageService.getById(pageId);
|
||||
// 页面已删除
|
||||
if (wikiPageSel == null || Objects.equals(wikiPageSel.getDelFlag(), 1)) {
|
||||
@@ -433,15 +445,17 @@ public class WikiPageController {
|
||||
if (SpaceType.isOthersPrivate(wikiSpaceSel.getType(), currentUser.getUserId(), wikiSpaceSel.getCreateUserId())) {
|
||||
return DocResponseJson.warn("您没有权限查看该空间的文章详情!");
|
||||
}
|
||||
UpdateWrapper<WikiPageContent> wrapper = new UpdateWrapper<>();
|
||||
wrapper.eq("page_id", pageId);
|
||||
WikiPageContent pageContent = wikiPageContentService.getOne(wrapper);
|
||||
if (pageContent == null || StringUtils.isBlank(pageContent.getContent())) {
|
||||
return DocResponseJson.warn("文档内容为空,不能导出!");
|
||||
}
|
||||
try {
|
||||
String content = pageContent.getContent();
|
||||
String fileName = URLEncoder.encode(wikiPageSel.getName(), "UTF-8");
|
||||
String fileName = URLEncoder.encode(wikiPageSel.getName(), "UTF-8").replaceAll("\\+", "%20");
|
||||
String domainUri = requestURI.substring(0, requestURI.indexOf("/zyplayer-doc-wiki") + 1);
|
||||
// 解析内容,并替换图片URL
|
||||
Document document = Jsoup.parse(content);
|
||||
document.outputSettings().syntax(Document.OutputSettings.Syntax.xml).escapeMode(Entities.EscapeMode.xhtml);
|
||||
Elements images = document.select("img");
|
||||
for (Element image : images) {
|
||||
image.attr("src", domainUri + image.attr("src"));
|
||||
}
|
||||
content = document.html();
|
||||
content = "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Strict//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">\n" +
|
||||
"<html lang=\"zh\">\n" +
|
||||
"<head>\n" +
|
||||
|
||||
Reference in New Issue
Block a user