view.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. <template>
  2. <div class="w-main docs-view">
  3. <v-title>{{$L('文档浏览')}}</v-title>
  4. <div class="view-box">
  5. <div class="view-head">
  6. <div class="header-title">
  7. <span v-if="bookDetail.title">{{bookDetail.title}}</span>
  8. <em v-if="bookDetail.title && docDetail.title">-</em>
  9. {{docDetail.title}}
  10. </div>
  11. <Button class="header-button" size="small" type="primary" ghost @click="toggleFullscreen">{{$L(isFullscreen ? '退出全屏' : '全屏')}}</Button>
  12. </div>
  13. <div class="view-main" :class="{'view-book':isBook}">
  14. <div class="view-menu">
  15. <div class="view-menu-list">
  16. <nested-draggable :lists="sectionLists" :readonly="true" :activeid="sid" @change="handleSection"></nested-draggable>
  17. </div>
  18. </div>
  19. <div class="view-body">
  20. <div class="view-body-content">
  21. <template v-if="docDetail.type=='document'">
  22. <MarkdownPreview v-if="docContent.type=='md'" :initialValue="docContent.content"></MarkdownPreview>
  23. <ReportContent v-else :content="docContent.content"></ReportContent>
  24. </template>
  25. <minder v-else-if="docDetail.type=='mind'" ref="myMind" class="body-mind" v-model="docContent" :readOnly="true"></minder>
  26. <sheet v-else-if="docDetail.type=='sheet'" ref="mySheet" class="body-sheet" v-model="docContent.content" :readOnly="true"></sheet>
  27. <flow v-else-if="docDetail.type=='flow'" ref="myFlow" class="body-flow" v-model="docContent" :readOnly="true"></flow>
  28. </div>
  29. </div>
  30. </div>
  31. </div>
  32. </div>
  33. </template>
  34. <style lang="scss">
  35. .view-body {
  36. .view-body-content {
  37. .markdown-preview,
  38. .report-content {
  39. margin: 0 !important;
  40. padding: 0 !important;
  41. }
  42. .minder-editor-container {
  43. transform: translateZ(0);
  44. }
  45. .body-sheet {
  46. box-sizing: content-box;
  47. * {
  48. box-sizing: content-box;
  49. }
  50. }
  51. }
  52. }
  53. </style>
  54. <style lang="scss" scoped>
  55. .docs-view {
  56. background-color: #ffffff;
  57. .view-box {
  58. display: flex;
  59. flex-direction: column;
  60. position: absolute;
  61. width: 100%;
  62. height: 100%;
  63. .view-head {
  64. display: flex;
  65. flex-direction: row;
  66. align-items: center;
  67. width: 100%;
  68. height: 38px;
  69. box-shadow: 0 1px 5px 0 rgba(0, 0, 0, 0.1);
  70. position: relative;
  71. z-index: 99;
  72. .header-title {
  73. flex: 1;
  74. color: #333333;
  75. padding-left: 12px;
  76. padding-right: 12px;
  77. font-size: 16px;
  78. font-weight: 500;
  79. white-space: nowrap;
  80. em {
  81. padding: 0 3px;
  82. font-weight: normal;
  83. }
  84. }
  85. .header-hint {
  86. padding-right: 22px;
  87. font-size: 12px;
  88. color: #666;
  89. white-space: nowrap;
  90. .ivu-btn {
  91. font-size: 12px;
  92. padding: 0 10px;
  93. }
  94. .ivu-dropdown-item {
  95. font-size: 12px !important;
  96. }
  97. }
  98. .header-button {
  99. font-size: 12px;
  100. margin-right: 12px;
  101. }
  102. }
  103. .view-main {
  104. flex: 1;
  105. width: 100%;
  106. display: flex;
  107. flex-direction: row;
  108. align-items: flex-start;
  109. justify-content: flex-start;
  110. &.view-book {
  111. .view-menu {
  112. border-right: 0;
  113. width: 100%;
  114. .view-menu-list {
  115. padding: 18px 8%;
  116. }
  117. }
  118. .view-body {
  119. display: none;
  120. }
  121. }
  122. .view-menu {
  123. position: relative;
  124. height: 100%;
  125. width: 280px;
  126. border-right: 1px solid #E6ECF1;
  127. .view-menu-list {
  128. position: absolute;
  129. left: 0;
  130. top: 0;
  131. right: 0;
  132. bottom: 0;
  133. padding: 18px 12px;
  134. overflow: auto;
  135. }
  136. }
  137. .view-body {
  138. flex: 1;
  139. height: 100%;
  140. position: relative;
  141. .view-body-content {
  142. position: absolute;
  143. left: 0;
  144. top: 0;
  145. right: 0;
  146. bottom: 0;
  147. padding: 18px;
  148. overflow: auto;
  149. }
  150. }
  151. }
  152. }
  153. }
  154. </style>
  155. <script>
  156. import Vue from 'vue'
  157. import minder from '../../components/docs/minder'
  158. Vue.use(minder)
  159. const Sheet = resolve => require(['../../components/docs/sheet/index'], resolve);
  160. const Flow = resolve => require(['../../components/docs/flow/index'], resolve);
  161. const NestedDraggable = resolve => require(['../../components/docs/NestedDraggable'], resolve);
  162. const MarkdownPreview = resolve => require(['../../components/MDEditor/components/preview/index'], resolve);
  163. const ReportContent = resolve => require(['../../components/report/content'], resolve);
  164. export default {
  165. components: {Sheet, Flow, ReportContent, MarkdownPreview, NestedDraggable},
  166. data () {
  167. return {
  168. loadIng: 0,
  169. sid: 0,
  170. docDetail: { },
  171. docContent: { },
  172. bookDetail: {},
  173. sectionLists: [],
  174. sectionNoDataText: "",
  175. routeName: '',
  176. isBook: false,
  177. isFullscreen: false,
  178. }
  179. },
  180. mounted() {
  181. this.routeName = this.$route.name;
  182. //
  183. document.addEventListener("fullscreenchange", () => {
  184. this.isFullscreen = !!document.fullscreenElement;
  185. });
  186. },
  187. activated() {
  188. this.refreshSid();
  189. },
  190. deactivated() {
  191. if ($A.getToken() === false) {
  192. this.sid = 0;
  193. }
  194. },
  195. watch: {
  196. sid(val) {
  197. if (!val) {
  198. return;
  199. }
  200. val += "";
  201. if (val.substring(0, 1) == 'b') {
  202. this.isBook = true;
  203. this.docDetail.bookid = val.substring(1);
  204. this.getSectionMenu();
  205. } else {
  206. this.isBook = false;
  207. this.refreshDetail();
  208. }
  209. },
  210. '$route' (To) {
  211. if (To.name == 'docs-view') {
  212. this.sid = To.params.sid;
  213. }
  214. },
  215. },
  216. methods: {
  217. refreshSid() {
  218. this.sid = this.$route.params.sid;
  219. if (typeof this.$route.params.other === "object") {
  220. this.$set(this.docDetail, 'title', $A.getObject(this.$route.params.other, 'title'))
  221. }
  222. },
  223. refreshDetail() {
  224. this.docDetail = { };
  225. this.docContent = { };
  226. this.getDetail();
  227. },
  228. getDetail() {
  229. this.loadIng++;
  230. $A.apiAjax({
  231. url: 'docs/section/content',
  232. data: {
  233. act: 'view',
  234. id: this.sid,
  235. },
  236. complete: () => {
  237. this.loadIng--;
  238. },
  239. error: () => {
  240. alert(this.$L('网络繁忙,请稍后再试!'));
  241. },
  242. success: (res) => {
  243. if (res.ret === 1) {
  244. this.docDetail = res.data;
  245. this.docContent = $A.jsonParse(res.data.content);
  246. this.getSectionMenu();
  247. } else {
  248. this.$Modal.error({
  249. title: this.$L('温馨提示'),
  250. content: res.msg,
  251. onOk: () => {
  252. if (res.data == '-1001') {
  253. this.goForward({path: '/', query:{from:encodeURIComponent(window.location.href)}}, true);
  254. }
  255. }
  256. });
  257. }
  258. }
  259. });
  260. },
  261. getSectionMenu() {
  262. this.sectionNoDataText = this.$L("数据加载中.....");
  263. let bookid = this.docDetail.bookid;
  264. $A.apiAjax({
  265. url: 'docs/section/lists',
  266. data: {
  267. act: 'view',
  268. bookid: bookid
  269. },
  270. error: () => {
  271. if (bookid != this.docDetail.bookid) {
  272. return;
  273. }
  274. this.sectionNoDataText = this.$L("数据加载失败!");
  275. },
  276. success: (res) => {
  277. if (bookid != this.docDetail.bookid) {
  278. return;
  279. }
  280. if (res.ret === 1) {
  281. this.bookDetail = res.data.book;
  282. this.sectionLists = res.data.tree;
  283. this.sectionNoDataText = this.$L("没有相关的数据");
  284. } else {
  285. this.sectionLists = [];
  286. this.sectionNoDataText = res.msg;
  287. this.$Modal.error({
  288. title: this.$L('温馨提示'),
  289. content: res.msg,
  290. onOk: () => {
  291. if (res.data == '-1001') {
  292. this.goForward({path: '/', query:{from:encodeURIComponent(window.location.href)}}, true);
  293. }
  294. }
  295. });
  296. }
  297. }
  298. });
  299. },
  300. handleSection(act, detail) {
  301. if (act === 'open') {
  302. this.goForward({name: 'docs-view', params: {sid: detail.id, other: detail || {}}});
  303. this.refreshSid();
  304. }
  305. },
  306. toggleFullscreen() {
  307. if (this.isFullscreen) {
  308. this.exitFullscreen();
  309. } else {
  310. this.launchFullscreen(this.$el);
  311. }
  312. },
  313. launchFullscreen(element) {
  314. if (element.requestFullscreen) {
  315. element.requestFullscreen();
  316. } else if (element.mozRequestFullScreen) {
  317. element.mozRequestFullScreen();
  318. } else if (element.msRequestFullscreen) {
  319. element.msRequestFullscreen();
  320. } else if (element.webkitRequestFullscreen) {
  321. element.webkitRequestFullScreen();
  322. }
  323. },
  324. exitFullscreen() {
  325. if (document.exitFullscreen) {
  326. document.exitFullscreen();
  327. } else if (document.msExitFullscreen) {
  328. document.msExitFullscreen();
  329. } else if (document.mozCancelFullScreen) {
  330. document.mozCancelFullScreen();
  331. } else if (document.webkitExitFullscreen) {
  332. document.webkitExitFullscreen();
  333. }
  334. }
  335. },
  336. }
  337. </script>