diff --git a/zyplayer-doc-ui/wiki-ui/.env.development b/zyplayer-doc-ui/wiki-ui/.env.development index 4473d97a..233f868e 100644 --- a/zyplayer-doc-ui/wiki-ui/.env.development +++ b/zyplayer-doc-ui/wiki-ui/.env.development @@ -2,8 +2,8 @@ ENV = 'development' # base api -# VUE_APP_BASE_API = 'http://local.zyplayer.com:8083/zyplayer-doc-manage' -VUE_APP_BASE_API = 'http://doc.zyplayer.com' +VUE_APP_BASE_API = 'http://local.zyplayer.com:8083/zyplayer-doc-manage' +# VUE_APP_BASE_API = 'http://doc.zyplayer.com' VUE_CLI_BABEL_TRANSPILE_MODULES = true diff --git a/zyplayer-doc-ui/wiki-ui/src/routes.js b/zyplayer-doc-ui/wiki-ui/src/routes.js index f2bff66b..947fbe9d 100644 --- a/zyplayer-doc-ui/wiki-ui/src/routes.js +++ b/zyplayer-doc-ui/wiki-ui/src/routes.js @@ -1,22 +1,37 @@ -import GlobalLayout from './components/layouts/GlobalLayout' -import ShareLayout from './components/layouts/ShareLayout' -import ShareMobileLayout from './components/layouts/ShareMobileLayout' +import GlobalLayout from './components/layouts/GlobalLayout.vue' +import ShareLayout from './components/layouts/ShareLayout.vue' +import ShareMobileLayout from './components/layouts/ShareMobileLayout.vue' + +import Search from './views/page/Search.vue' +import EditorTest from './views/page/EditorTest.vue' +import NoAuth from './views/common/NoAuth.vue' + +import Home from './views/home/Home.vue' +import MyInfo from './views/user/MyInfo.vue' +import Show from './views/page/Show.vue' +import Edit from './views/page/Edit.vue' + +import spaceManage from './views/space/Manage.vue' + +import sharePcHome from './views/page/share/pc/Home.vue' +import sharePcView from './views/page/share/pc/View.vue' +import shareMobileView from './views/page/share/mobile/View.vue' let routes = [ {path: '/', redirect: '/home'}, - {path: '/page/search', name: 'WIKI-全局搜索', component: () => import('@/views/page/Search')}, - {path: '/common/noAuth', name: 'WIKI-没有权限', component: () => import('@/views/common/NoAuth')}, - {path: '/page/editorTest', name: '编辑内容', component: () => import('@/views/page/EditorTest')}, + {path: '/page/search', name: 'WIKI-全局搜索', component: Search}, + {path: '/common/noAuth', name: 'WIKI-没有权限', component: NoAuth}, + {path: '/page/editorTest', name: '编辑内容', component: EditorTest}, { path: '/', name: '页面管理', component: GlobalLayout, children: [ - {path: '/home', name: 'WIKI文档管理', component: () => import('@/views/home/Home')}, - {path: '/user/myInfo', name: 'WIKI-我的信息', component: () => import('@/views/user/MyInfo')}, - {path: '/page/show', name: 'WIKI-内容展示', component: () => import('@/views/page/Show')}, - {path: '/page/edit', name: 'WIKI-编辑内容', component: () => import('@/views/page/Edit')}, - {path: '/space/manage', name: 'WIKI-空间管理', component: () => import('@/views/space/Manage')}, + {path: '/home', name: 'WIKI文档管理', component: Home}, + {path: '/user/myInfo', name: 'WIKI-我的信息', component: MyInfo}, + {path: '/page/show', name: 'WIKI-内容展示', component: Show}, + {path: '/page/edit', name: 'WIKI-编辑内容', component: Edit}, + {path: '/space/manage', name: 'WIKI-空间管理', component: spaceManage}, ] }, { @@ -24,8 +39,8 @@ let routes = [ name: '页面管理', component: ShareLayout, children: [ - {path: '/page/share/home', name: 'WIKI-开放文档', component: () => import('@/views/page/share/pc/Home')}, - {path: '/page/share/view', name: 'WIKI-内容展示', component: () => import('@/views/page/share/pc/View')}, + {path: '/page/share/home', name: 'WIKI-开放文档', component: sharePcHome}, + {path: '/page/share/view', name: 'WIKI-内容展示', component: sharePcView}, ] }, { @@ -33,7 +48,7 @@ let routes = [ name: '页面管理', component: ShareMobileLayout, children: [ - {path: '/page/share/mobile/view', name: 'WIKI-开放文档', component: () => import('@/views/page/share/mobile/View')}, + {path: '/page/share/mobile/view', name: 'WIKI-开放文档', component: shareMobileView}, ] }, ]; diff --git a/zyplayer-doc-ui/wiki-ui/src/views/page/Show.vue b/zyplayer-doc-ui/wiki-ui/src/views/page/Show.vue index f9ec8399..88906b51 100644 --- a/zyplayer-doc-ui/wiki-ui/src/views/page/Show.vue +++ b/zyplayer-doc-ui/wiki-ui/src/views/page/Show.vue @@ -3,9 +3,6 @@ - - -
{{wikiPage.name}}
@@ -33,6 +30,7 @@ 权限设置 查看开放文档 手机端查看 + 导出为Word文档 删除 @@ -84,6 +82,9 @@
+ + +
@@ -187,6 +188,9 @@
+
+ +
@@ -255,6 +259,11 @@ var page = { fullscreen: true, readmodel: true, }, + // 下载为Word + downloadFormParam: { + url: 'zyplayer-doc-wiki/page/download', + param: {} + }, }; }, beforeRouteUpdate(to, from, next) { @@ -287,38 +296,52 @@ var page = { } else if (val == 'showPageHistory') { this.showPageHistory(); } else if (val == 'showOpenPage') { - if (this.spaceInfo.openDoc != 1) { - this.$message.warning("该空间未开放,无法查看开放文档地址"); - } else { - let routeUrl = this.$router.resolve({ - path: '/page/share/view', - query: {pageId: this.wikiPage.id, space: this.spaceInfo.uuid} - }); - window.open(routeUrl.href, '_blank'); - } + this.showOpenPage(); } else if (val == 'showMobileView') { - if (this.spaceInfo.openDoc != 1) { - this.$message.warning("该空间未开放,无法查看开放文档地址"); - } else { - let routeUrl = this.$router.resolve({ - path: '/page/share/mobile/view', - query: {pageId: this.wikiPage.id, space: this.spaceInfo.uuid} + this.showMobileView(); + } else if (val == 'exportWord') { + this.exportWord(); + } + }, + exportWord() { + this.downloadFormParam.param = { + pageId: this.wikiPage.id + }; + setTimeout(() => this.$refs.downloadForm.submit(), 0); + }, + showOpenPage() { + if (this.spaceInfo.openDoc != 1) { + this.$message.warning("该空间未开放,无法查看开放文档地址"); + } else { + let routeUrl = this.$router.resolve({ + path: '/page/share/view', + query: {pageId: this.wikiPage.id, space: this.spaceInfo.uuid} + }); + window.open(routeUrl.href, '_blank'); + } + }, + showMobileView() { + if (this.spaceInfo.openDoc != 1) { + this.$message.warning("该空间未开放,无法查看开放文档地址"); + } else { + let routeUrl = this.$router.resolve({ + path: '/page/share/mobile/view', + query: {pageId: this.wikiPage.id, space: this.spaceInfo.uuid} + }); + this.mobileScanDialogVisible = true; + let hostPath = window.location.href.split("#")[0]; + setTimeout(() => { + this.qrCodeUrl = hostPath + routeUrl.href; + this.$refs.qrCodeDiv.innerHTML = ""; + new QRCode(this.$refs.qrCodeDiv, { + text: this.qrCodeUrl, + width: 250, + height: 250, + colorDark: "#333333", //二维码颜色 + colorLight: "#ffffff", //二维码背景色 + correctLevel: QRCode.CorrectLevel.M//容错率,L/M/H }); - this.mobileScanDialogVisible = true; - let hostPath = window.location.href.split("#")[0]; - setTimeout(() => { - this.qrCodeUrl = hostPath + routeUrl.href; - this.$refs.qrCodeDiv.innerHTML = ""; - new QRCode(this.$refs.qrCodeDiv, { - text: this.qrCodeUrl, - width: 250, - height: 250, - colorDark: "#333333", //二维码颜色 - colorLight: "#ffffff", //二维码背景色 - correctLevel: QRCode.CorrectLevel.M//容错率,L/M/H - }); - }, 0); - } + }, 0); } }, addPageAuthUser() { diff --git a/zyplayer-doc-ui/wiki-ui/src/views/page/components/Navigation.vue b/zyplayer-doc-ui/wiki-ui/src/views/page/components/Navigation.vue index 3cc62c55..52deda67 100644 --- a/zyplayer-doc-ui/wiki-ui/src/views/page/components/Navigation.vue +++ b/zyplayer-doc-ui/wiki-ui/src/views/page/components/Navigation.vue @@ -55,7 +55,7 @@ position: fixed; z-index: 4; top: 150px; - height: calc(100vh - 250px); + max-height: calc(100vh - 250px); width: 100%; overflow-y: auto; padding-left: 16px; diff --git a/zyplayer-doc-wiki/pom.xml b/zyplayer-doc-wiki/pom.xml index 37a26637..88a144c7 100644 --- a/zyplayer-doc-wiki/pom.xml +++ b/zyplayer-doc-wiki/pom.xml @@ -53,6 +53,32 @@ org.eclipse.jgit org.eclipse.jgit + + + org.apache.poi + poi + 4.1.0 + + + org.apache.poi + poi-ooxml + 4.1.0 + + + org.apache.poi + poi-ooxml-schemas + 4.1.0 + + + org.apache.poi + poi-scratchpad + 4.1.0 + + + org.apache.poi + ooxml-schemas + 1.4 + diff --git a/zyplayer-doc-wiki/src/main/java/com/zyplayer/doc/wiki/controller/WikiPageController.java b/zyplayer-doc-wiki/src/main/java/com/zyplayer/doc/wiki/controller/WikiPageController.java index 4da6853c..ae839d87 100644 --- a/zyplayer-doc-wiki/src/main/java/com/zyplayer/doc/wiki/controller/WikiPageController.java +++ b/zyplayer-doc-wiki/src/main/java/com/zyplayer/doc/wiki/controller/WikiPageController.java @@ -28,6 +28,9 @@ import com.zyplayer.doc.wiki.service.git.GitService; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; import com.github.dozermapper.core.Mapper; +import org.apache.poi.poifs.filesystem.DirectoryEntry; +import org.apache.poi.poifs.filesystem.DocumentEntry; +import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.web.bind.annotation.PostMapping; @@ -35,6 +38,11 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; +import javax.servlet.ServletOutputStream; +import javax.servlet.http.HttpServletResponse; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.net.URLEncoder; import java.util.*; import java.util.stream.Collectors; @@ -323,6 +331,47 @@ public class WikiPageController { return this.news(param); } + @PostMapping("/download") + public ResponseJson download(Long pageId, HttpServletResponse response) { + DocUserDetails currentUser = DocUserUtil.getCurrentUser(); + WikiPage wikiPageSel = wikiPageService.getById(pageId); + // 页面已删除 + if (wikiPageSel == null || Objects.equals(wikiPageSel.getDelFlag(), 1)) { + return DocResponseJson.warn("该页面不存在或已删除!"); + } + WikiSpace wikiSpaceSel = wikiSpaceService.getById(wikiPageSel.getSpaceId()); + // 空间已删除 + if (wikiSpaceSel == null || Objects.equals(wikiSpaceSel.getDelFlag(), 1)) { + return DocResponseJson.warn("该页面不存在或已删除!"); + } + // 私人空间 + if (SpaceType.isOthersPrivate(wikiSpaceSel.getType(), currentUser.getUserId(), wikiSpaceSel.getCreateUserId())) { + return DocResponseJson.warn("您没有权限查看该空间的文章详情!"); + } + UpdateWrapper wrapper = new UpdateWrapper<>(); + wrapper.eq("page_id", pageId); + WikiPageContent pageContent = wikiPageContentService.getOne(wrapper); + try { + ByteArrayInputStream bais = new ByteArrayInputStream(pageContent.getContent().getBytes("GBK")); + POIFSFileSystem poifs = new POIFSFileSystem(); + DirectoryEntry directory = poifs.getRoot(); + directory.createDocument("WordDocument", bais); + // 写入流 + response.setContentType("application/vnd.ms-excel"); + response.setCharacterEncoding("utf-8"); + String fileName = URLEncoder.encode(wikiPageSel.getName(), "UTF-8"); + response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".docx"); + ServletOutputStream outputStream = response.getOutputStream(); + poifs.writeFilesystem(outputStream); + bais.close(); + outputStream.close(); + return DocResponseJson.ok(); + } catch (Exception e) { + e.printStackTrace(); + } + return DocResponseJson.warn("导出失败"); + } + @PostMapping("/news") public ResponseJson news(SearchByEsParam param) { // 空间不是自己的