Index.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. <template>
  2. <div class="hello" v-if="showComp">
  3. <Header></Header>
  4. <div id="header"></div>
  5. <div class="container doc-container" id="doc-container">
  6. <div id="left-side">
  7. <LeftMenu
  8. ref="leftMenu"
  9. :get_page_content="get_page_content"
  10. :keyword="keyword"
  11. :item_info="item_info"
  12. :search_item="search_item"
  13. v-if="item_info"
  14. ></LeftMenu>
  15. </div>
  16. <div id="right-side">
  17. <div
  18. id="p-content"
  19. @mouseenter="showfullPageBtn = true"
  20. @mouseleave="showfullPageBtn = false"
  21. >
  22. <div class="doc-title-box" id="doc-title-box">
  23. <span id="doc-title-span" class="dn"></span>
  24. <h2 id="doc-title">{{page_title}}</h2>
  25. <i
  26. class="el-icon-full-screen"
  27. id="full-page"
  28. v-show="showfullPageBtn"
  29. @click="clickFullPage"
  30. ></i>
  31. <el-badge
  32. :value="attachment_count"
  33. class="item"
  34. id="attachment"
  35. v-if="attachment_count"
  36. @click.native="ShowAttachment"
  37. >
  38. <i class="el-icon-upload"></i>
  39. </el-badge>
  40. </div>
  41. <div id="doc-body">
  42. <div id="page_md_content" class="page_content_main">
  43. <Editormd v-bind:content="content" v-if="page_id" type="html" :keyword="keyword"></Editormd>
  44. </div>
  45. </div>
  46. </div>
  47. <OpBar
  48. :page_id="page_id"
  49. :item_id="item_info.item_id"
  50. :item_info="item_info"
  51. :page_info="page_info"
  52. ></OpBar>
  53. </div>
  54. </div>
  55. <BackToTop></BackToTop>
  56. <Toc v-if="page_id && showToc"></Toc>
  57. <!-- 附件列表 -->
  58. <AttachmentList
  59. callback
  60. :item_id="page_info.item_id"
  61. :manage="false"
  62. :page_id="page_info.page_id"
  63. ref="AttachmentList"
  64. ></AttachmentList>
  65. <Footer></Footer>
  66. </div>
  67. </template>
  68. <script>
  69. import Editormd from '@/components/common/Editormd'
  70. import BackToTop from '@/components/common/BackToTop'
  71. import Toc from '@/components/item/show/show_regular_item/Toc'
  72. import LeftMenu from '@/components/item/show/show_regular_item/LeftMenu'
  73. import OpBar from '@/components/item/show/show_regular_item/OpBar'
  74. import AttachmentList from '@/components/page/edit/AttachmentList'
  75. import { rederPageContent } from '@/models/page'
  76. export default {
  77. props: {
  78. item_info: '',
  79. search_item: '',
  80. keyword: ''
  81. },
  82. data() {
  83. return {
  84. content: '###正在加载...',
  85. page_id: '',
  86. page_title: '',
  87. dialogVisible: false,
  88. share_item_link: '',
  89. qr_item_link: '',
  90. page_info: '',
  91. copyText: '',
  92. attachment_count: '',
  93. fullPage: false,
  94. showfullPageBtn: false,
  95. showToc: true,
  96. showComp: true
  97. }
  98. },
  99. components: {
  100. Editormd,
  101. LeftMenu,
  102. OpBar,
  103. BackToTop,
  104. Toc,
  105. AttachmentList
  106. },
  107. methods: {
  108. // 获取页面内容
  109. get_page_content(page_id) {
  110. if (page_id <= 0) {
  111. return
  112. }
  113. this.adaptScreen()
  114. var that = this
  115. this.request('/api/page/info', {
  116. 'page_id': page_id
  117. }, 'post', false).then((data) => {
  118. // loading.close();
  119. if (data.error_code === 0) {
  120. that.content = rederPageContent(data.data.page_content)
  121. that.page_title = data.data.page_title
  122. that.page_info = data.data
  123. that.attachment_count =
  124. data.data.attachment_count > 0
  125. ? data.data.attachment_count
  126. : ''
  127. // 切换变量让它重新加载、渲染子组件
  128. that.page_id = 0
  129. that.item_info.default_page_id = page_id
  130. that.$nextTick(() => {
  131. that.page_id = page_id
  132. // 页面回到顶部
  133. document.body.scrollTop = document.documentElement.scrollTop = 0
  134. document.title = that.page_title + '--ShowDoc'
  135. })
  136. } else {
  137. // that.$alert(data.error_message);
  138. }
  139. })
  140. },
  141. // 根据屏幕宽度进行响应(应对移动设备的访问)
  142. adaptToMobile() {
  143. let childRef = this.$refs.leftMenu // 获取子组件
  144. childRef.hide_menu()
  145. this.show_page_bar = false
  146. var doc_container = document.getElementById('doc-container')
  147. doc_container.style.width = '95%'
  148. doc_container.style.padding = '5px'
  149. var header = document.getElementById('header')
  150. header.style.height = '10px'
  151. var docTitle = document.getElementById('doc-title-box')
  152. docTitle.style.marginTop = '40px'
  153. this.showToc = false
  154. },
  155. // 根据屏幕宽度进行响应。应对小屏幕pc设备(如笔记本)的访问
  156. adaptToSmallpc() {
  157. var doc_container = document.getElementById('doc-container')
  158. doc_container.style.width = 'calc( 95% - 300px )'
  159. doc_container.style.marginLeft = '300px'
  160. doc_container.style.padding = '20px'
  161. var header = document.getElementById('header')
  162. header.style.height = '20px'
  163. var docTitle = document.getElementById('doc-title-box')
  164. docTitle.style.marginTop = '30px'
  165. },
  166. // 响应式
  167. adaptScreen() {
  168. this.$nextTick(() => {
  169. // 根据屏幕宽度进行响应(应对移动设备的访问)
  170. if (this.isMobile() || window.innerWidth < 1300) {
  171. if (window.innerWidth < 1300 && window.innerWidth > 1100) {
  172. this.adaptToSmallpc()
  173. } else {
  174. this.adaptToMobile()
  175. }
  176. }
  177. })
  178. },
  179. onCopy() {
  180. this.$message(this.$t('copy_success'))
  181. },
  182. ShowAttachment() {
  183. let childRef = this.$refs.AttachmentList // 获取子组件
  184. childRef.show()
  185. },
  186. clickFullPage() {
  187. // 点击放大页面。由于历史包袱,只能操作dom。这是不规范的,但是现在没时间重构整块页面
  188. if (this.fullPage) {
  189. // 通过v-if指令起到刷新组件的作用
  190. this.showComp = false
  191. this.$nextTick(() => {
  192. this.showComp = true
  193. })
  194. } else {
  195. this.adaptToMobile()
  196. // 切换变量让它重新加载、渲染子组件
  197. var page_id = this.page_id
  198. this.page_id = 0
  199. this.$nextTick(() => {
  200. this.page_id = page_id
  201. setTimeout(() => {
  202. $('.editormd-html-preview').css('font-size', '16px')
  203. }, 200)
  204. })
  205. $('#left-side').hide()
  206. $('.op-bar').hide()
  207. }
  208. this.fullPage = !this.fullPage
  209. }
  210. },
  211. mounted() {
  212. this.adaptScreen()
  213. this.set_bg_grey()
  214. }
  215. }
  216. </script>
  217. <!-- Add "scoped" attribute to limit CSS to this component only -->
  218. <style scoped>
  219. .page_content_main {
  220. width: 800px;
  221. margin: 0 auto;
  222. height: 50%;
  223. overflow: visible;
  224. }
  225. .editormd-html-preview {
  226. width: 95%;
  227. font-size: 16px;
  228. overflow-y: hidden;
  229. }
  230. #attachment {
  231. float: right;
  232. font-size: 25px;
  233. margin-top: -40px;
  234. margin-right: 5px;
  235. cursor: pointer;
  236. color: #abd1f1;
  237. }
  238. #full-page {
  239. float: right;
  240. font-size: 25px;
  241. margin-top: -50px;
  242. margin-right: 30px;
  243. cursor: pointer;
  244. color: #ccc;
  245. }
  246. #page_md_content {
  247. padding: 10px 10px 90px 10px;
  248. overflow: hidden;
  249. font-size: 11pt;
  250. line-height: 1.7;
  251. color: #333;
  252. }
  253. .doc-container {
  254. position: static;
  255. -webkit-box-shadow: 0px 1px 6px #ccc;
  256. -moz-box-shadow: 0px 1px 6px #ccc;
  257. -ms-box-shadow: 0px 1px 6px #ccc;
  258. -o-box-shadow: 0px 1px 6px #ccc;
  259. box-shadow: 0px 1px 6px #ccc;
  260. background-color: #fff;
  261. border-bottom: 1px solid #d9d9d9;
  262. margin-bottom: 20px;
  263. width: 800px;
  264. min-height: 750px;
  265. margin-left: auto;
  266. margin-right: auto;
  267. padding: 20px;
  268. }
  269. #header {
  270. height: 80px;
  271. }
  272. #doc-body {
  273. width: 95%;
  274. margin: 0 auto;
  275. background-color: #fff;
  276. }
  277. .doc-title-box {
  278. height: auto;
  279. width: auto;
  280. border-bottom: 1px solid #ebebeb;
  281. padding-bottom: 10px;
  282. width: 100%;
  283. margin: 10px auto;
  284. text-align: center;
  285. }
  286. pre ol {
  287. list-style: none;
  288. }
  289. .markdown-body pre {
  290. background-color: #f7f7f9;
  291. border: 1px solid #e1e1e8;
  292. }
  293. .hljs {
  294. background-color: #f7f7f9;
  295. }
  296. .tool-bar {
  297. margin-top: -38px;
  298. }
  299. .editormd-html-preview,
  300. .editormd-preview-container {
  301. padding: 0px;
  302. font-size: 14px;
  303. }
  304. </style>