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.

SquareTop.vue 8.5 kB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  1. <template>
  2. <div class="ui _repo_container_bg">
  3. <div class="ui container _repo_container _content_container">
  4. <div class="_repo_top_left">
  5. <a :href="bannerData[0] ? bannerData[0].url : ''">
  6. <div class="_repo_top_left_img">
  7. <img :src="bannerData[0] ? bannerData[0].src : ''">
  8. </div>
  9. </a>
  10. </div>
  11. <div class="_repo_top_middle">
  12. <div class="_repo_top_middle_header">
  13. <div class="_repo_top_mid_item" :class="(tabIndex == index) ? '_foucs' : ''" v-for="(item, index) in tabs"
  14. :key="index" @click="changeTab(item, index)">
  15. <i :class="item.icon"></i>
  16. <span>{{ item.label }}</span>
  17. </div>
  18. </div>
  19. <div class="_repo_top_middle_content">
  20. <div class="_repo_top_mid_repo_list">
  21. <div class="swiper-wrapper" id="_repo_top_mid_repo"></div>
  22. <div class="swiper-pagination"></div>
  23. </div>
  24. </div>
  25. </div>
  26. <div class="_repo_top_right">
  27. <a :href="bannerData[1] ? bannerData[1].url : ''">
  28. <div class="_repo_top_right_img">
  29. <img :src="bannerData[1] ? bannerData[1].src : ''">
  30. </div>
  31. </a>
  32. </div>
  33. </div>
  34. </div>
  35. </template>
  36. <script>
  37. import { getPromoteData } from '~/apis/modules/common';
  38. import { getReposSquareTabData } from '~/apis/modules/repos';
  39. export default {
  40. name: "SquareTop",
  41. props: {},
  42. components: {},
  43. data() {
  44. return {
  45. swiperHandler: null,
  46. tabIndex: 0,
  47. tabs: [{
  48. key: 'preferred',
  49. icon: 'ri-fire-line',
  50. label: this.$t('repos.preferred'),
  51. }, {
  52. key: 'incubation',
  53. icon: 'ri-award-line',
  54. label: this.$t('repos.openIIncubation'),
  55. }, {
  56. key: 'hot-paper',
  57. icon: 'ri-file-damage-line',
  58. label: this.$t('repos.hotPapers'),
  59. }],
  60. bannerData: [],
  61. };
  62. },
  63. methods: {
  64. initSwiper() {
  65. this.swiperHandler = new Swiper("._repo_top_mid_repo_list", {
  66. slidesPerView: 1,
  67. spaceBetween: 20,
  68. pagination: {
  69. el: "._repo_top_mid_repo_list .swiper-pagination",
  70. clickable: true,
  71. },
  72. autoplay: {
  73. delay: 4500,
  74. disableOnInteraction: false,
  75. },
  76. breakpoints: {
  77. 768: {
  78. slidesPerView: 2,
  79. },
  80. 1024: {
  81. slidesPerView: 2,
  82. },
  83. 1200: {
  84. slidesPerView: 3,
  85. },
  86. },
  87. });
  88. },
  89. renderSwiper(data) {
  90. const swiperEl = document.getElementById("_repo_top_mid_repo");
  91. let html = '';
  92. for (let i = 0, iLen = data.length; i < iLen; i++) {
  93. html += `<div class="swiper-slide">`;
  94. for (let j = i; j < i + 2; j++) {
  95. let dataJ = data[j];
  96. if (dataJ === undefined) break;
  97. html += `<div class="_repo_sw_card">
  98. <div class="_repo_sw_card_title _repo_nowrap"><a href="/${dataJ.OwnerName}/${dataJ.Name}" title="${dataJ.Name}">${dataJ.Name}</a></div>
  99. <div class="_repo_sw_card_descr _repo_nowrap_line_2" title="${dataJ.Description}">${dataJ.Description}</div>
  100. <div class="_repo_sw_card_label _repo_nowrap">`
  101. const topics = dataJ.Topics || [];
  102. for (let k = 0, kLen = topics.length; k < kLen; k++) {
  103. html += `<span><a href="/explore/repos?q=&topic=${topics[k]}&sort=hot">${topics[k]}</a></span>`
  104. }
  105. html += `</div>
  106. </div>`;
  107. }
  108. html += `</div>`;
  109. i++;
  110. }
  111. this.swiperHandler.removeAllSlides();
  112. swiperEl.innerHTML = html;
  113. this.swiperHandler.updateSlides();
  114. this.swiperHandler.updateProgress();
  115. },
  116. getBannerData() {
  117. getPromoteData('/repos/square_banner').then(res => {
  118. const data = res.data;
  119. try {
  120. const list = JSON.parse(data);
  121. this.bannerData = list;
  122. } catch (err) {
  123. console.log(err);
  124. }
  125. }).catch(err => {
  126. console.log(err);
  127. });
  128. },
  129. getTabData() {
  130. getReposSquareTabData(this.tabs[this.tabIndex].key).then(res => {
  131. res = res.data;
  132. if (res.Code == 0) {
  133. const data = res.Data.Repos || [];
  134. this.renderSwiper(data);
  135. }
  136. }).catch(err => {
  137. console.log(err);
  138. });
  139. },
  140. changeTab(item, index) {
  141. this.tabIndex = index;
  142. this.getTabData();
  143. },
  144. },
  145. mounted() {
  146. this.initSwiper();
  147. this.getBannerData();
  148. this.getTabData();
  149. },
  150. };
  151. </script>
  152. <style scoped lang="less">
  153. ._repo_container_bg {
  154. width: 100%;
  155. height: 450px;
  156. 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.4999999999999999%2C%20-0.8660000000000001%2C%200.07722000385802469%2C%200.4999999999999999%2C%20-0.183%2C%200.683)%22%3E%3Cstop%20stop-color%3D%22%239aceec%22%20stop-opacity%3D%221%22%20offset%3D%220%22%3E%3C%2Fstop%3E%3Cstop%20stop-color%3D%22%23eeeeee%22%20stop-opacity%3D%221%22%20offset%3D%220.99%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");
  157. position: relative;
  158. }
  159. ._content_container {
  160. display: flex !important;
  161. margin: 0 auto !important;
  162. height: 100% !important;
  163. }
  164. ._repo_top_left {
  165. width: 243px;
  166. height: 100%;
  167. position: relative;
  168. }
  169. ._repo_top_left_img {
  170. width: 100%;
  171. height: 346px;
  172. position: absolute;
  173. bottom: 0;
  174. border-top-left-radius: 10px;
  175. overflow: hidden;
  176. }
  177. ._repo_top_left_img img {
  178. height: 100%;
  179. width: 100%;
  180. }
  181. ._content_container img[src=""],
  182. img:not([src]) {
  183. opacity: 0;
  184. }
  185. ._repo_top_right {
  186. width: 243px;
  187. height: 100%;
  188. position: relative;
  189. }
  190. ._repo_top_right_img {
  191. width: 100%;
  192. height: 346px;
  193. position: absolute;
  194. bottom: 0;
  195. border-top-right-radius: 10px;
  196. overflow: hidden;
  197. }
  198. ._repo_top_right_img img {
  199. height: 100%;
  200. width: 100%;
  201. }
  202. ._repo_top_middle {
  203. flex: 1;
  204. height: 100%;
  205. position: relative;
  206. }
  207. ._repo_top_middle_header {
  208. width: 100%;
  209. height: 42px;
  210. position: absolute;
  211. bottom: 346px;
  212. display: flex;
  213. align-items: center;
  214. background: raba(0, 0, 255, 0.3);
  215. padding: 0 20px;
  216. }
  217. ._repo_top_mid_item {
  218. padding: 0px 16px;
  219. font-size: 18px;
  220. color: rgba(47, 9, 69, 0.64);
  221. height: 100%;
  222. display: flex;
  223. align-items: center;
  224. cursor: pointer;
  225. box-sizing: border-box;
  226. border-bottom: 3px solid transparent;
  227. }
  228. ._repo_top_mid_item i {
  229. margin-right: 5px;
  230. }
  231. ._repo_top_mid_item._foucs {
  232. background-color: rgba(255, 255, 255, 0.3);
  233. color: rgb(16, 16, 16);
  234. cursor: default;
  235. border-bottom: 3px solid rgba(16, 16, 16, 0.8);
  236. }
  237. ._repo_top_middle_content {
  238. width: 100%;
  239. height: 346px;
  240. position: absolute;
  241. bottom: 0;
  242. background: rgba(255, 255, 255, 0.3);
  243. padding: 20px 20px;
  244. overflow: hidden;
  245. }
  246. ._repo_top_mid_repo_list {
  247. overflow: hidden;
  248. }
  249. /deep/._repo_sw_card {
  250. height: 128px;
  251. border-color: rgb(255, 255, 255);
  252. border-width: 1px;
  253. border-style: solid;
  254. font-size: 14px;
  255. padding: 10px;
  256. background: rgba(255, 255, 255, 0.6);
  257. margin-bottom: 20px;
  258. box-sizing: border-box;
  259. }
  260. /deep/._repo_nowrap {
  261. overflow: hidden;
  262. text-overflow: ellipsis;
  263. white-space: nowrap;
  264. }
  265. /deep/._repo_nowrap_line_2 {
  266. overflow: hidden;
  267. text-overflow: ellipsis;
  268. word-break: break-all;
  269. font-size: 12px;
  270. color: rgb(136, 136, 136);
  271. display: -webkit-box;
  272. -webkit-box-orient: vertical;
  273. -webkit-line-clamp: 2;
  274. max-height: 45px;
  275. white-space: break-spaces;
  276. }
  277. /deep/._repo_sw_card a {
  278. color: inherit;
  279. }
  280. /deep/._repo_sw_card_title {
  281. font-weight: 700;
  282. font-size: 16px;
  283. color: rgba(26, 40, 51, 1);
  284. margin-bottom: 10px;
  285. }
  286. /deep/._repo_sw_card_descr {
  287. font-size: 14px;
  288. color: rgba(80, 85, 89, 1);
  289. margin-bottom: 10px;
  290. min-height: 42px;
  291. }
  292. /deep/._repo_sw_card_label {
  293. color: rgb(26, 40, 51);
  294. font-size: 14px;
  295. }
  296. /deep/._repo_sw_card_label span {
  297. border-radius: 4px;
  298. background: rgba(232, 232, 232, 0.6);
  299. padding: 0px 6px 2px;
  300. margin-right: 10px;
  301. }
  302. /deep/._repo_top_mid_repo_list .swiper-pagination-bullet {
  303. width: 8px;
  304. height: 8px;
  305. border-radius: 100%;
  306. background: #76cbed;
  307. }
  308. /deep/._repo_top_mid_repo_list .swiper-pagination-bullet-active {
  309. width: 40px;
  310. border-radius: 4px;
  311. }
  312. </style>