articleRight.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <!-- 文章右部分 -->
  2. <template>
  3. <div class="right_wrap">
  4. <!-- 分类列表显示 -->
  5. <div class="nch_article_con" v-if="!showContent">
  6. <div class="title_bar">
  7. <h3>{{ title }}</h3>
  8. </div>
  9. <!-- 分类显示 -->
  10. <ul class="nch_article_list">
  11. <li v-for="(item, index) in cate" :key="index">
  12. <i></i>
  13. <a @click="getContent(item.articleId)" style="cursor: pointer">{{
  14. item.title
  15. }}</a>
  16. <time></time>
  17. </li>
  18. </ul>
  19. </div>
  20. <!-- 文章内容显示 -->
  21. <div v-if="showContent">
  22. <h2 v-html="data.articeContent.title" class="article_title"></h2>
  23. <!-- <p v-html="data.articeContent.createTime" class="article_time"></p> -->
  24. <div class="article_content ql-container">
  25. <div class="ql-editor" v-html="data.articeContent.content"></div>
  26. </div>
  27. </div>
  28. </div>
  29. </template>
  30. <script setup>
  31. import { reactive, getCurrentInstance, onMounted, ref, watchEffect } from "vue";
  32. import { getCurLanguage } from '@/composables/common.js';
  33. const L = getCurLanguage();
  34. defineProps(["cate", "title"]);
  35. const route = useRoute();
  36. const router = useRouter();
  37. const { proxy } = getCurrentInstance();
  38. const data = reactive({
  39. articeContent: {},
  40. });
  41. const showContent = ref(false); //单独声明showContent以便引用
  42. const childMethod = (val) => {
  43. showContent.value = false;
  44. }
  45. //通过articleId获取文章详情
  46. const getContent = (articleId) => {
  47. const params = {
  48. articleId: articleId,
  49. };
  50. get("v3/cms/front/article/articleDetail", params).then((res) => {
  51. if (res.state === 200) {
  52. if (res.data.outUrl) {
  53. window.open(res.data.outUrl,'_blank');
  54. return
  55. }
  56. if (res.data.content) {
  57. res.data.content = quillEscapeToHtml(res.data.content);
  58. }
  59. data.articeContent = res.data;
  60. showContent.value = true;
  61. }
  62. });
  63. };
  64. defineExpose({ childMethod,getContent});
  65. onMounted(() => {
  66. if (route.query.articleId) {
  67. getContent(route.query.articleId);
  68. }
  69. });
  70. watchEffect(() => {
  71. if (route.query.articleId) {
  72. getContent(route.query.articleId);
  73. }
  74. });
  75. </script>
  76. <style lang="scss" scoped>
  77. @import "@/assets/style/vendors.css";
  78. .right_wrap {
  79. background: #fff;
  80. margin-left: 15px;
  81. width: calc(100% - 259px);
  82. float: right;
  83. .nch_article_con {
  84. display: block;
  85. padding: 19px 50px;
  86. margin: 0 auto 10px;
  87. overflow: hidden;
  88. .title_bar {
  89. border-bottom: solid 1px #e6e6e6;
  90. padding-bottom: 15px;
  91. margin-bottom: 15px;
  92. h3 {
  93. font: normal 18px/20px "microsoft yahei";
  94. }
  95. }
  96. .nch_article_list li {
  97. line-height: 20px;
  98. display: block;
  99. height: 30px;
  100. padding: 5px 0;
  101. i {
  102. background: #555555;
  103. vertical-align: middle;
  104. display: inline-block;
  105. width: 3px;
  106. height: 3px;
  107. margin-right: 10px;
  108. }
  109. a {
  110. color: #666;
  111. word-break: break-all;
  112. }
  113. }
  114. }
  115. .article_title {
  116. text-align: center;
  117. font-size: 24px;
  118. line-height: 24px;
  119. margin-top: 20px;
  120. margin-bottom: 20px;
  121. }
  122. .article_time {
  123. font-size: 16px;
  124. text-align: center;
  125. line-height: 40px;
  126. color: #666;
  127. margin-bottom: 20px;
  128. }
  129. .article_content {
  130. padding: 0 20px;
  131. word-break: break-all;
  132. .ql-editor {
  133. padding: 0;
  134. }
  135. }
  136. }
  137. </style>
  138. <style lang="scss">
  139. .right_wrap {
  140. .article_content {
  141. img {
  142. max-width: 900px;
  143. }
  144. a {
  145. display: inline-block;
  146. margin: 5px auto;
  147. color: #0000ff;
  148. text-decoration: underline;
  149. }
  150. table {
  151. border-collapse: collapse;
  152. padding: 0;
  153. }
  154. td,
  155. th {
  156. border: 1px solid #ddd;
  157. padding: 5px 10px;
  158. }
  159. ol li,
  160. ul li {
  161. list-style: unset;
  162. }
  163. }
  164. }
  165. </style>