You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

RecommendRepos.vue 5.3 kB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <template>
  2. <div class="repo-selected-bg">
  3. <div class="ui container _repo_container _repo-selected-container" style="padding-top:3rem;padding-bottom:3rem;">
  4. <div class="_repo_title"><span>{{ $t('repos.selectedFields') }}</span></div>
  5. <div class="_repo-selected-list">
  6. <div class="swiper-wrapper" id="_repo-selected"></div>
  7. <div class="swiper-pagination _repo-selected-swiper-pagination"></div>
  8. </div>
  9. </div>
  10. </div>
  11. </template>
  12. <script>
  13. import { getHomePageData } from '~/apis/modules/repos';
  14. import LetterAvatar from '~/utils/letteravatar';
  15. export default {
  16. name: "RecommendRepos",
  17. props: {
  18. static: { type: Boolean, default: false },
  19. staticSwiperData: { type: Array, default: () => [] },
  20. },
  21. components: {},
  22. data() {
  23. return {
  24. swiperHandler: null,
  25. };
  26. },
  27. methods: {
  28. renderRepos(json) {
  29. var selectedRepoEl = document.getElementById("_repo-selected");
  30. var html = "";
  31. if (json != null && json.length > 0) {
  32. var repoMap = {};
  33. for (var i = 0, iLen = json.length; i < iLen; i++) {
  34. var repo = json[i];
  35. var label = repo.Label;
  36. if (repoMap[label]) {
  37. repoMap[label].push(repo);
  38. } else {
  39. repoMap[label] = [repo];
  40. }
  41. }
  42. for (var label in repoMap) {
  43. var repos = repoMap[label];
  44. var labelSearch = repos[0].Label;
  45. html += `<div class="swiper-slide"><div><a style="color:rgb(50, 145, 248);font-size:16px;font-weight:550;" href="/explore/repos?q=&topic=${labelSearch}&sort=hot"># ${label}</a></div>`;
  46. for (var i = 0, iLen = repos.length; i < iLen; i++) {
  47. if (i >= 4) break;
  48. var repo = repos[i];
  49. html += `<div class="ui fluid card">
  50. <div class="content">
  51. ${repo["Avatar"] ? `<img style="border-radius: 100%;" class="left floated mini ui image" src="${repo["Avatar"]}">` : `<img style="border-radius: 100%;" class="left floated mini ui image" avatar="${repo["OwnerName"]}">`}
  52. <span class="header nowrap" style="color:rgb(50, 145, 248);font-size:14px;" href="javascript:;" title="${repo["Alias"]}">${repo["Alias"]}</span>
  53. <div class="description nowrap-2" style="rgba(136,136,136,1);;font-size:12px;" title="${repo["Description"]}">${repo["Description"]}</div>
  54. </div>
  55. <a style="position:absolute;height:100%;width:100%;" href="/${repo["OwnerName"]}/${repo["Name"]}"></a>
  56. </div>`;
  57. }
  58. html += '</div>'
  59. }
  60. this.swiperHandler = new Swiper("._repo-selected-list", {
  61. slidesPerView: 1,
  62. spaceBetween: 25,
  63. pagination: {
  64. el: "._repo-selected-swiper-pagination",
  65. clickable: true,
  66. },
  67. autoplay: {
  68. delay: 4500,
  69. disableOnInteraction: false,
  70. },
  71. breakpoints: {
  72. 768: {
  73. slidesPerView: 3,
  74. },
  75. 1024: {
  76. slidesPerView: 4,
  77. },
  78. 1200: {
  79. slidesPerView: 4,
  80. },
  81. 1600: {
  82. slidesPerView: 4,
  83. }
  84. },
  85. });
  86. selectedRepoEl.innerHTML = html;
  87. this.swiperHandler.updateSlides();
  88. this.swiperHandler.updateProgress();
  89. LetterAvatar.transform();
  90. }
  91. }
  92. },
  93. mounted() {
  94. if (this.static) {
  95. this.renderRepos(this.staticSwiperData);
  96. } else {
  97. getHomePageData().then(res => {
  98. this.renderRepos(res.data.repo);
  99. }).catch(err => {
  100. console.log(err);
  101. });
  102. }
  103. },
  104. };
  105. </script>
  106. <style scoped lang="less">
  107. .repo-selected-bg {
  108. background: url("data:image/svg+xml;charset=utf8,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20xmlns%3Axlink%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxlink%22%20version%3D%221.1%22%3E%3Cdefs%3E%3ClinearGradient%20id%3D%221%22%20x1%3D%220%22%20x2%3D%221%22%20y1%3D%220%22%20y2%3D%220%22%20gradientTransform%3D%22matrix(0.11899999999999993%2C%201.217%2C%20-0.24039506172839506%2C%200.11899999999999993%2C%200.269%2C%20-0.22)%22%3E%3Cstop%20stop-color%3D%22%23ffffff%22%20stop-opacity%3D%220.47%22%20offset%3D%220%22%3E%3C%2Fstop%3E%3Cstop%20stop-color%3D%22%23e5e7eb%22%20stop-opacity%3D%220.3%22%20offset%3D%221%22%3E%3C%2Fstop%3E%3C%2FlinearGradient%3E%3C%2Fdefs%3E%3Crect%20width%3D%22100%25%22%20height%3D%22100%25%22%20fill%3D%22url(%231)%22%3E%3C%2Frect%3E%3C%2Fsvg%3E");
  109. }
  110. ._repo_title {
  111. font-size: 18px;
  112. color: rgb(16, 16, 16);
  113. text-align: center;
  114. margin-bottom: 1em;
  115. font-weight: bold;
  116. }
  117. ._repo-selected-list {
  118. overflow: hidden;
  119. padding: 1em 1em 3em 1em;
  120. text-align: left;
  121. position: relative;
  122. }
  123. /deep/._repo-selected-swiper-pagination .swiper-pagination-bullet {
  124. width: 8px;
  125. height: 8px;
  126. border-radius: 100%;
  127. background: #76cbed;
  128. }
  129. /deep/._repo-selected-swiper-pagination .swiper-pagination-bullet-active {
  130. width: 40px;
  131. border-radius: 4px;
  132. }
  133. /deep/ ._repo-selected-list .card {
  134. border-radius: 6px;
  135. background-color: #FFF;
  136. box-shadow: 0px 5px 10px 0px rgba(105, 192, 255, .3);
  137. border: 1px solid rgba(105, 192, 255, .4);
  138. }
  139. /deep/ ._repo-selected-list .header {
  140. line-height: 40px !important;
  141. }
  142. </style>