articleLeft.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. <!-- 文章页面左侧栏 -->
  2. <template>
  3. <div :class="leftFixed?'left_wrap active' :'left_wrap'">
  4. <div class="article_left">
  5. <div class="nch_module nch_module_style01">
  6. <div class="title">
  7. <h3>{{ L["文章分类"] }}</h3>
  8. </div>
  9. <div class="article_content">
  10. <ul class="nch_sidebar_article_class">
  11. <li
  12. v-for="(item, index) in data.allCategory"
  13. :key="item.categoryId"
  14. :class="data.curindex == index ? 'tabcolor' : ''"
  15. >
  16. <nuxt-link
  17. :to="{ path: 'article', query: { categoryId: item.categoryId } }"
  18. replace
  19. >
  20. <a @click="getArticalDetail(item.categoryName, index, item.categoryId)">{{ item.categoryName }}<i style="float:right;">></i></a>
  21. </nuxt-link>
  22. </li>
  23. </ul>
  24. </div>
  25. </div>
  26. <div class="nch_module nch_module_style02">
  27. <div class="title">
  28. <h3>{{ L["最新文章"] }}</h3>
  29. </div>
  30. <div class="article_content">
  31. <ul class="nch_sidebar_article_list">
  32. <li
  33. v-for="(item, index) in data.cate"
  34. :key="index"
  35. @click="toDetail(item.articleId, index)"
  36. >
  37. <div class="sortes">
  38. <i></i>
  39. <a
  40. :class="data.articleIndex == index ? 'help_name_other' : 'help_name'"
  41. >{{ item.title }}</a
  42. >
  43. </div>
  44. <p class="help_time">
  45. <span>{{ item.createTime }}</span>
  46. </p>
  47. </li>
  48. </ul>
  49. </div>
  50. </div>
  51. </div>
  52. </div>
  53. </template>
  54. <script setup>
  55. import { useRoute, onBeforeRouteUpdate } from "vue-router";
  56. import { getCurLanguage } from '@/composables/common.js';
  57. const props = defineProps(["categoryId"]);
  58. const L = getCurLanguage();
  59. const route = useRoute();
  60. const data = reactive({
  61. curindex: 0,
  62. cate: "",
  63. allCategory: "",
  64. articleIndex: -1,
  65. });
  66. //获取文章分类数据
  67. const getArticalList = async () => {
  68. const params1 = {};
  69. params1.cateSize = 100;
  70. const {data:value} = await useFetch(apiUrl+'v3/cms/front/article/helpList',{params:params1})
  71. const res = value._rawValue
  72. if (res.state === 200) {
  73. data.allCategory = res.data;
  74. if (!route.query.categoryId && !route.query.articleId) {
  75. //获取服务中心数据
  76. if (res.data.length > 0) {
  77. emit(
  78. "getArticalDetail",
  79. res.data[0].categoryName,
  80. res.data[0].categoryId,
  81. true
  82. );
  83. }
  84. } else {
  85. for (let i = 0; i < data.allCategory.length; i++) {
  86. if (data.allCategory[i].categoryId == route.query.categoryId) {
  87. data.curindex = i;
  88. emit("settitle", data.allCategory[i].categoryName);
  89. } else {
  90. let idx = data.allCategory[i].articleList.findIndex(
  91. (x) => x.articleId == route.query.articleId
  92. );
  93. if (idx > -1) {
  94. data.curindex = i;
  95. emit("settitle", data.allCategory[i].categoryName);
  96. }
  97. }
  98. }
  99. }
  100. }
  101. };
  102. getArticalList();
  103. const emit = defineEmits(["seeDetail","getArticalDetail"])
  104. // 文章详情
  105. const toDetail = (articleId, index) => {
  106. emit("seeDetail", articleId);
  107. data.articleIndex = index;
  108. };
  109. // 通过Id获取文章详情
  110. const getArticalDetail = (categoryName, index, categoryId) => {
  111. data.curindex = index;
  112. data.articleIndex = -1;
  113. emit("getArticalDetail", categoryName, categoryId);
  114. };
  115. //获取文章列表
  116. const getList = () => {
  117. const params = {};
  118. params.size = 6;
  119. get("v3/cms/front/article/articleList", params).then((res) => {
  120. if (res.state == 200) {
  121. data.cate = res.data;
  122. }
  123. });
  124. };
  125. getList();
  126. //滚动事件
  127. const leftFixed = ref(false)
  128. if (process.client) {
  129. const handleScrollLeft = () => {
  130. var height = 600;
  131. var scrollTop =
  132. window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop;
  133. if (scrollTop > height) {
  134. leftFixed.value = true;
  135. } else {
  136. leftFixed.value = false;
  137. }
  138. };
  139. window.addEventListener("scroll", handleScrollLeft);
  140. }
  141. </script>
  142. <style lang="scss" scoped>
  143. @import "@/assets/style/theme.scss";
  144. .sortes {
  145. display: flex;
  146. }
  147. .left_wrap {
  148. width: 244px;
  149. min-height: 700px;
  150. float: left;
  151. &.active{
  152. position: fixed;
  153. top: 70px;
  154. z-index: 1;
  155. }
  156. .nch_module {
  157. margin-bottom: 10px;
  158. max-height: 400px;
  159. background-color: #fff;
  160. .title {
  161. background-color: #efefef;
  162. height: 34px;
  163. color: #333333;
  164. font-size: 14px;
  165. text-align: center;
  166. h3 {
  167. color: #333;
  168. margin: 0;
  169. font-weight: 600;
  170. font: normal 14px/34px "microsoft yahei";
  171. }
  172. }
  173. }
  174. .nch_module_style01 {
  175. border-top: solid 3px #c89d7b;
  176. }
  177. .nch_module_style02 {
  178. border-top: solid 4px #ffa200;
  179. }
  180. .nch_sidebar_article_class {
  181. width: 244px;
  182. padding: 12px 0 19px;
  183. overflow: hidden;
  184. text-overflow: ellipsis;
  185. .tabcolor {
  186. background-color: $colorMain;
  187. a {
  188. color: white !important;
  189. }
  190. }
  191. li {
  192. width: 100%;
  193. height: 36px;
  194. line-height: 36px;
  195. text-align: left;
  196. vertical-align: top;
  197. letter-spacing: normal;
  198. word-spacing: normal;
  199. display: inline-block;
  200. &:hover {
  201. background: $colorMain;
  202. a {
  203. color: #fff;
  204. }
  205. }
  206. a {
  207. line-height: 36px;
  208. font-size: 13px;
  209. color: #666666;
  210. display: block;
  211. overflow: hidden;
  212. text-overflow: ellipsis;
  213. white-space: nowrap;
  214. padding: 0 4px;
  215. }
  216. }
  217. }
  218. .nch_sidebar_article_list {
  219. padding: 4px 0px;
  220. min-height: 400px;
  221. li {
  222. margin: 0px 0 15px;
  223. padding: 4px 9px;
  224. cursor: pointer;
  225. div {
  226. padding: 3px 0;
  227. i {
  228. vertical-align: middle;
  229. display: inline-block;
  230. width: 6px;
  231. height: 6px;
  232. margin-right: 10px;
  233. border-radius: 3px;
  234. background-color: #ffa200;
  235. margin-top: 4px;
  236. }
  237. a:link,
  238. a:visited {
  239. color: #333333;
  240. text-decoration: none;
  241. }
  242. .help_name {
  243. width: 200px;
  244. color: #333333;
  245. font-size: 13px;
  246. overflow: hidden;
  247. text-overflow: ellipsis;
  248. display: -webkit-box;
  249. -webkit-line-clamp: 2;
  250. word-break: break-all;
  251. overflow: hidden;
  252. }
  253. .help_name_other {
  254. width: 200px;
  255. color: #ffa200;
  256. font-size: 13px;
  257. overflow: hidden;
  258. text-overflow: ellipsis;
  259. -webkit-line-clamp: 2;
  260. word-break: break-all;
  261. display: -webkit-box;
  262. }
  263. }
  264. .help_time {
  265. color: #999999;
  266. font-size: 12px;
  267. padding-left: 20px;
  268. }
  269. }
  270. }
  271. }
  272. .left_wrap.active {
  273. -webkit-animation: searchTop 0.5s ease-in-out;
  274. animation: searchTop 0.5s ease-in-out;
  275. }
  276. @-webkit-keyframes searchTop {
  277. 0% {
  278. top: -50px;
  279. }
  280. to {
  281. top: 70px;
  282. }
  283. }
  284. @keyframes searchTop {
  285. 0% {
  286. top: -50px;
  287. }
  288. to {
  289. top: 70px;
  290. }
  291. }
  292. </style>