view.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. <template>
  2. <div class="w-main docs-view">
  3. <v-title>{{$L('文档浏览')}}-{{$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.content" :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. userInfo: {},
  176. routeName: '',
  177. isBook: false,
  178. isFullscreen: false,
  179. }
  180. },
  181. mounted() {
  182. this.routeName = this.$route.name;
  183. this.userInfo = $A.getUserInfo((res, isLogin) => {
  184. if (this.userInfo.id != res.id) {
  185. this.userInfo = res;
  186. }
  187. }, false);
  188. //
  189. document.addEventListener("fullscreenchange", () => {
  190. this.isFullscreen = !!document.fullscreenElement;
  191. });
  192. },
  193. activated() {
  194. this.refreshSid();
  195. },
  196. deactivated() {
  197. if ($A.getToken() === false) {
  198. this.sid = 0;
  199. }
  200. },
  201. watch: {
  202. sid(val) {
  203. if (!val) {
  204. return;
  205. }
  206. val += "";
  207. if (val.substring(0, 1) == 'b') {
  208. this.isBook = true;
  209. this.docDetail.bookid = val.substring(1);
  210. this.getSectionMenu();
  211. } else {
  212. this.isBook = false;
  213. this.refreshDetail();
  214. }
  215. },
  216. '$route' (To) {
  217. this.sid = To.params.sid;
  218. },
  219. },
  220. methods: {
  221. refreshSid() {
  222. this.sid = this.$route.params.sid;
  223. if (typeof this.$route.params.other === "object") {
  224. this.$set(this.docDetail, 'title', $A.getObject(this.$route.params.other, 'title'))
  225. }
  226. },
  227. refreshDetail() {
  228. this.docDetail = { };
  229. this.docContent = { };
  230. this.getDetail();
  231. },
  232. getDetail() {
  233. this.loadIng++;
  234. $A.apiAjax({
  235. url: 'docs/section/content',
  236. data: {
  237. act: 'view',
  238. id: this.sid,
  239. },
  240. complete: () => {
  241. this.loadIng--;
  242. },
  243. error: () => {
  244. alert(this.$L('网络繁忙,请稍后再试!'));
  245. },
  246. success: (res) => {
  247. if (res.ret === 1) {
  248. this.docDetail = res.data;
  249. this.docContent = $A.jsonParse(res.data.content);
  250. this.getSectionMenu();
  251. } else {
  252. this.$Modal.error({
  253. title: this.$L('温馨提示'),
  254. content: res.msg,
  255. onOk: () => {
  256. if (res.data == '-1001') {
  257. this.goForward({path: '/', query:{from:encodeURIComponent(window.location.href)}}, true);
  258. }
  259. }
  260. });
  261. }
  262. }
  263. });
  264. },
  265. getSectionMenu() {
  266. this.sectionNoDataText = this.$L("数据加载中.....");
  267. let bookid = this.docDetail.bookid;
  268. $A.apiAjax({
  269. url: 'docs/section/lists',
  270. data: {
  271. act: 'view',
  272. bookid: bookid
  273. },
  274. error: () => {
  275. if (bookid != this.docDetail.bookid) {
  276. return;
  277. }
  278. this.sectionNoDataText = this.$L("数据加载失败!");
  279. },
  280. success: (res) => {
  281. if (bookid != this.docDetail.bookid) {
  282. return;
  283. }
  284. if (res.ret === 1) {
  285. this.bookDetail = res.data.book;
  286. this.sectionLists = res.data.tree;
  287. this.sectionNoDataText = this.$L("没有相关的数据");
  288. } else {
  289. this.sectionLists = [];
  290. this.sectionNoDataText = res.msg;
  291. this.$Modal.error({
  292. title: this.$L('温馨提示'),
  293. content: res.msg,
  294. onOk: () => {
  295. if (res.data == '-1001') {
  296. this.goForward({path: '/', query:{from:encodeURIComponent(window.location.href)}}, true);
  297. }
  298. }
  299. });
  300. }
  301. }
  302. });
  303. },
  304. handleSection(act, detail) {
  305. if (act === 'open') {
  306. this.goForward({name: 'docs-view', params: {sid: detail.id, other: detail || {}}});
  307. this.refreshSid();
  308. }
  309. },
  310. toggleFullscreen() {
  311. if (this.isFullscreen) {
  312. this.exitFullscreen();
  313. } else {
  314. this.launchFullscreen(this.$el);
  315. }
  316. },
  317. launchFullscreen(element) {
  318. if (element.requestFullscreen) {
  319. element.requestFullscreen();
  320. } else if (element.mozRequestFullScreen) {
  321. element.mozRequestFullScreen();
  322. } else if (element.msRequestFullscreen) {
  323. element.msRequestFullscreen();
  324. } else if (element.webkitRequestFullscreen) {
  325. element.webkitRequestFullScreen();
  326. }
  327. },
  328. exitFullscreen() {
  329. if (document.exitFullscreen) {
  330. document.exitFullscreen();
  331. } else if (document.msExitFullscreen) {
  332. document.msExitFullscreen();
  333. } else if (document.mozCancelFullScreen) {
  334. document.mozCancelFullScreen();
  335. } else if (document.webkitExitFullscreen) {
  336. document.webkitExitFullscreen();
  337. }
  338. }
  339. },
  340. }
  341. </script>