server.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. <template>
  2. <div class="page-box">
  3. server
  4. </div>
  5. </template>
  6. <script>
  7. import axios from "axios";
  8. import { hotTags, getClicks, getBlogs } from "@/api";
  9. export default {
  10. name: "home",
  11. data() {
  12. return {
  13. /*
  14. * active
  15. * 浏览量排序: views
  16. * 点赞量排序: likes
  17. * 评论数排序: comments
  18. * 发布时间排序: time
  19. * */
  20. active: "views",
  21. tag: "",
  22. searchText: "",
  23. tags: [],
  24. blogsList: [],
  25. clickList: [],
  26. color: [
  27. "#2B6363",
  28. "#DB704D",
  29. "#63B4AE",
  30. "#EA5368",
  31. "#EFA19D",
  32. "#E7CA65",
  33. "#C7C7AB",
  34. "#EA5368",
  35. "#EFA19D",
  36. "#2B6363",
  37. "#DB704D",
  38. ],
  39. total: 0,
  40. pageSize: 15,
  41. size: 1,
  42. };
  43. },
  44. watch: {
  45. tags() {
  46. console.log(119);
  47. },
  48. },
  49. mounted() {
  50. setTimeout(() => {
  51. if (this.$route.query && this.$route.query.search) {
  52. this.searchText = this.$route.query.search;
  53. }
  54. this.getList("views");
  55. this.getTagsFn();
  56. this.getClickListFn();
  57. }, 200);
  58. },
  59. methods: {
  60. async getList(type) {
  61. if (this.active !== type) {
  62. this.active = type;
  63. }
  64. const params = {
  65. sort: this.active,
  66. tag: this.tag,
  67. searchText: this.searchText,
  68. size: this.size,
  69. pageSize: this.pageSize,
  70. };
  71. const res = await getBlogs(params);
  72. this.total = res.data.total;
  73. this.blogsList = res.data.list;
  74. },
  75. async getClickListFn() {
  76. const res = await getClicks();
  77. this.clickList = res.data;
  78. },
  79. async getTagsFn() {
  80. const res = await hotTags();
  81. console.log("8080", res);
  82. this.tags = res.data.map((item) => {
  83. return {
  84. name: item,
  85. color: this.color[Math.floor(Math.random() * 9)],
  86. };
  87. });
  88. },
  89. showDetail(id) {
  90. this.$router.push({
  91. path: "/blogDetails",
  92. query: {
  93. id,
  94. },
  95. });
  96. },
  97. search() {
  98. this.tag = "";
  99. this.total = 0;
  100. this.pageSize = 15;
  101. this.size = 1;
  102. this.getList();
  103. },
  104. searchTag(tag) {
  105. this.tag = tag;
  106. this.searchText = "";
  107. this.total = 0;
  108. this.pageSize = 15;
  109. this.size = 1;
  110. this.getList();
  111. },
  112. sizeChange(size) {
  113. this.size = size;
  114. this.getList();
  115. },
  116. },
  117. };
  118. </script>
  119. <style lang="less" scoped>
  120. .home-box {
  121. //background-color: #ffffff;
  122. .event-box {
  123. padding: 15px 20px;
  124. margin-bottom: 20px;
  125. background-color: #ffffff;
  126. border-radius: 4px;
  127. .sort-box {
  128. //font-size: 14px;
  129. span {
  130. &:hover {
  131. cursor: pointer;
  132. }
  133. }
  134. }
  135. .active {
  136. color: #409eff;
  137. }
  138. }
  139. .body-box {
  140. display: flex;
  141. .bolg-box {
  142. flex: 1;
  143. .list-box {
  144. display: flex;
  145. flex-wrap: wrap;
  146. .item {
  147. //width: 300px;
  148. background-color: #ffffff;
  149. flex: 1 1 260px;
  150. margin-right: 15px;
  151. margin-bottom: 15px;
  152. img {
  153. cursor: pointer;
  154. }
  155. }
  156. img {
  157. }
  158. }
  159. }
  160. .other-box {
  161. .tag-box {
  162. border-radius: 4px;
  163. width: 280px;
  164. background-color: #f8f9fb;
  165. margin-bottom: 24px;
  166. .title {
  167. text-align: left;
  168. padding-left: 5px;
  169. &:before {
  170. content: "";
  171. display: block;
  172. position: relative;
  173. top: 35px;
  174. width: 85px;
  175. height: 2px;
  176. border-radius: 4px;
  177. background: #2c3e50;
  178. }
  179. }
  180. .tags {
  181. padding: 0 5px;
  182. text-align: left;
  183. min-height: 150px;
  184. .tag {
  185. font-size: 14px;
  186. color: #ffffff;
  187. cursor: pointer;
  188. padding: 1px 5px;
  189. border-radius: 4px;
  190. margin-right: 5px;
  191. margin-bottom: 5px;
  192. display: inline-block;
  193. transition: all 0.3ms;
  194. &:hover {
  195. color: #409eff;
  196. }
  197. }
  198. }
  199. }
  200. .click-box {
  201. border-radius: 4px;
  202. width: 280px;
  203. background-color: #f8f9fb;
  204. .title {
  205. text-align: left;
  206. padding-left: 5px;
  207. &:before {
  208. content: "";
  209. display: block;
  210. position: relative;
  211. top: 35px;
  212. width: 85px;
  213. height: 2px;
  214. border-radius: 4px;
  215. background: #2c3e50;
  216. }
  217. }
  218. .list-box {
  219. //height: 250px;
  220. min-height: 250px;
  221. max-height: 470px;
  222. //max-height: 50vh;
  223. padding: 5px;
  224. overflow: scroll;
  225. background-color: #f8f9fb;
  226. .item {
  227. cursor: pointer;
  228. .index {
  229. margin-bottom: 5px;
  230. img {
  231. cursor: pointer;
  232. }
  233. .name {
  234. transition: color ease-in-out 0.3s;
  235. background-color: #000000;
  236. color: #ffffff;
  237. }
  238. &:hover {
  239. .name {
  240. color: #409eff;
  241. }
  242. }
  243. }
  244. .other {
  245. display: flex;
  246. margin-bottom: 10px;
  247. img {
  248. cursor: pointer;
  249. width: 70px;
  250. height: 70px;
  251. }
  252. .content {
  253. text-align: left;
  254. color: #333;
  255. padding-left: 10px;
  256. font-size: 18px;
  257. }
  258. &:hover {
  259. .content {
  260. color: #409eff;
  261. }
  262. }
  263. }
  264. }
  265. }
  266. }
  267. }
  268. }
  269. }
  270. </style>