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.4 kB

3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. export default {
  15. name: "RecommendRepos",
  16. props: {
  17. static: { type: Boolean, default: false },
  18. staticSwiperData: { type: Array, default: () => [] },
  19. },
  20. components: {},
  21. data() {
  22. return {
  23. swiperHandler: null,
  24. };
  25. },
  26. methods: {
  27. renderRepos(json) {
  28. var selectedRepoEl = document.getElementById("_repo-selected");
  29. var html = "";
  30. if (json != null && json.length > 0) {
  31. var repoMap = {};
  32. for (var i = 0, iLen = json.length; i < iLen; i++) {
  33. var repo = json[i];
  34. var label = repo.Label;
  35. if (repoMap[label]) {
  36. repoMap[label].push(repo);
  37. } else {
  38. repoMap[label] = [repo];
  39. }
  40. }
  41. for (var label in repoMap) {
  42. var repos = repoMap[label];
  43. var labelSearch = repos[0].Label;
  44. 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>`;
  45. for (var i = 0, iLen = repos.length; i < iLen; i++) {
  46. if (i >= 4) break;
  47. var repo = repos[i];
  48. html += `<div class="ui fluid card">
  49. <div class="content">
  50. ${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"]}">`}
  51. <span class="header nowrap" style="color:rgb(50, 145, 248);font-size:14px;" href="javascript:;" title="${repo["Alias"]}">${repo["Alias"]}</span>
  52. <div class="description nowrap-2" style="rgba(136,136,136,1);;font-size:12px;" title="${repo["Description"]}">${repo["Description"]}</div>
  53. </div>
  54. <a style="position:absolute;height:100%;width:100%;" href="/${repo["OwnerName"]}/${repo["Name"]}"></a>
  55. </div>`;
  56. }
  57. html += '</div>'
  58. }
  59. this.swiperHandler = new Swiper("._repo-selected-list", {
  60. slidesPerView: 1,
  61. spaceBetween: 25,
  62. pagination: {
  63. el: "._repo-selected-swiper-pagination",
  64. clickable: true,
  65. },
  66. autoplay: {
  67. delay: 4500,
  68. disableOnInteraction: false,
  69. },
  70. breakpoints: {
  71. 768: {
  72. slidesPerView: 3,
  73. },
  74. 1024: {
  75. slidesPerView: 4,
  76. },
  77. 1200: {
  78. slidesPerView: 4,
  79. },
  80. 1600: {
  81. slidesPerView: 4,
  82. }
  83. },
  84. });
  85. selectedRepoEl.innerHTML = html;
  86. this.swiperHandler.updateSlides();
  87. this.swiperHandler.updateProgress();
  88. this.$nextTick(() => {
  89. if (typeof LetterAvatar != 'undefined') {
  90. LetterAvatar && LetterAvatar.transform();
  91. }
  92. });
  93. }
  94. }
  95. },
  96. mounted() {
  97. if (this.static) {
  98. this.renderRepos(this.staticSwiperData);
  99. } else {
  100. getHomePageData().then(res => {
  101. this.renderRepos(res.data.repo);
  102. }).catch(err => {
  103. console.log(err);
  104. });
  105. }
  106. },
  107. };
  108. </script>
  109. <style scoped lang="less">
  110. .repo-selected-bg {
  111. 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");
  112. }
  113. ._repo_title {
  114. font-size: 18px;
  115. color: rgb(16, 16, 16);
  116. text-align: center;
  117. margin-bottom: 1em;
  118. font-weight: bold;
  119. }
  120. ._repo-selected-list {
  121. overflow: hidden;
  122. padding: 1em 1em 3em 1em;
  123. text-align: left;
  124. position: relative;
  125. }
  126. /deep/._repo-selected-swiper-pagination .swiper-pagination-bullet {
  127. width: 8px;
  128. height: 8px;
  129. border-radius: 100%;
  130. background: #76cbed;
  131. }
  132. /deep/._repo-selected-swiper-pagination .swiper-pagination-bullet-active {
  133. width: 40px;
  134. border-radius: 4px;
  135. }
  136. /deep/ ._repo-selected-list .card {
  137. border-radius: 6px;
  138. background-color: #FFF;
  139. box-shadow: 0px 5px 10px 0px rgba(105, 192, 255, .3);
  140. border: 1px solid rgba(105, 192, 255, .4);
  141. }
  142. /deep/ ._repo-selected-list .header {
  143. line-height: 40px !important;
  144. }
  145. </style>