articleLeft.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  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 useFetchRaw(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. overflow: auto;
  180. }
  181. .nch_sidebar_article_class {
  182. width: 244px;
  183. padding: 12px 0 19px;
  184. overflow: hidden;
  185. text-overflow: ellipsis;
  186. .tabcolor {
  187. background-color: $colorMain;
  188. a {
  189. color: white !important;
  190. }
  191. }
  192. li {
  193. width: 100%;
  194. height: 36px;
  195. line-height: 36px;
  196. text-align: left;
  197. vertical-align: top;
  198. letter-spacing: normal;
  199. word-spacing: normal;
  200. display: inline-block;
  201. &:hover {
  202. background: $colorMain;
  203. a {
  204. color: #fff;
  205. }
  206. }
  207. a {
  208. line-height: 36px;
  209. font-size: 13px;
  210. color: #666666;
  211. display: block;
  212. overflow: hidden;
  213. text-overflow: ellipsis;
  214. white-space: nowrap;
  215. padding: 0 4px;
  216. }
  217. }
  218. }
  219. .nch_sidebar_article_list {
  220. padding: 4px 0px;
  221. min-height: 400px;
  222. li {
  223. margin: 0px 0 15px;
  224. padding: 4px 9px;
  225. cursor: pointer;
  226. div {
  227. padding: 3px 0;
  228. i {
  229. vertical-align: middle;
  230. display: inline-block;
  231. width: 6px;
  232. height: 6px;
  233. margin-right: 10px;
  234. border-radius: 3px;
  235. background-color: #ffa200;
  236. margin-top: 4px;
  237. }
  238. a:link,
  239. a:visited {
  240. color: #333333;
  241. text-decoration: none;
  242. }
  243. .help_name {
  244. width: 200px;
  245. color: #333333;
  246. font-size: 13px;
  247. overflow: hidden;
  248. text-overflow: ellipsis;
  249. display: -webkit-box;
  250. -webkit-line-clamp: 2;
  251. word-break: break-all;
  252. overflow: hidden;
  253. }
  254. .help_name_other {
  255. width: 200px;
  256. color: #ffa200;
  257. font-size: 13px;
  258. overflow: hidden;
  259. text-overflow: ellipsis;
  260. -webkit-line-clamp: 2;
  261. word-break: break-all;
  262. display: -webkit-box;
  263. }
  264. }
  265. .help_time {
  266. color: #999999;
  267. font-size: 12px;
  268. padding-left: 20px;
  269. }
  270. }
  271. }
  272. }
  273. .left_wrap.active {
  274. -webkit-animation: searchTop 0.5s ease-in-out;
  275. animation: searchTop 0.5s ease-in-out;
  276. }
  277. @-webkit-keyframes searchTop {
  278. 0% {
  279. top: -50px;
  280. }
  281. to {
  282. top: 70px;
  283. }
  284. }
  285. @keyframes searchTop {
  286. 0% {
  287. top: -50px;
  288. }
  289. to {
  290. top: 70px;
  291. }
  292. }
  293. </style>