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

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
2 years ago
2 years ago
2 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  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 _repo_top-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-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.Alias}">${dataJ.Alias}</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. <a href="/${dataJ.OwnerName}/${dataJ.Name}" style="position:absolute;width:100%;height:100%;top:0;left:0;"></a>
  107. </div>`;
  108. }
  109. html += `</div>`;
  110. i++;
  111. }
  112. this.swiperHandler.removeAllSlides();
  113. swiperEl.innerHTML = html;
  114. this.swiperHandler.updateSlides();
  115. this.swiperHandler.updateProgress();
  116. },
  117. getBannerData() {
  118. getPromoteData('/repos/square_banner').then(res => {
  119. const data = res.data;
  120. try {
  121. const list = JSON.parse(data);
  122. this.bannerData = list;
  123. } catch (err) {
  124. console.log(err);
  125. }
  126. }).catch(err => {
  127. console.log(err);
  128. });
  129. },
  130. getTabData() {
  131. getReposSquareTabData(this.tabs[this.tabIndex].key).then(res => {
  132. res = res.data;
  133. if (res.Code == 0) {
  134. const data = res.Data.Repos || [];
  135. this.renderSwiper(data);
  136. }
  137. }).catch(err => {
  138. console.log(err);
  139. });
  140. },
  141. changeTab(item, index) {
  142. this.tabIndex = index;
  143. this.getTabData();
  144. },
  145. },
  146. mounted() {
  147. this.initSwiper();
  148. this.getBannerData();
  149. this.getTabData();
  150. },
  151. };
  152. </script>
  153. <style scoped lang="less">
  154. ._repo_container_bg {
  155. width: 100%;
  156. height: 450px;
  157. 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");
  158. position: relative;
  159. }
  160. ._content_container {
  161. display: flex !important;
  162. margin: 0 auto !important;
  163. height: 100% !important;
  164. }
  165. ._repo_top_left {
  166. width: 243px;
  167. height: 100%;
  168. position: relative;
  169. }
  170. ._repo_top_left_img {
  171. width: 100%;
  172. height: 346px;
  173. position: absolute;
  174. bottom: 0;
  175. border-top-left-radius: 10px;
  176. overflow: hidden;
  177. }
  178. ._repo_top_left_img img {
  179. height: 100%;
  180. width: 100%;
  181. }
  182. ._content_container img[src=""],
  183. img:not([src]) {
  184. opacity: 0;
  185. }
  186. ._repo_top_right {
  187. width: 243px;
  188. height: 100%;
  189. position: relative;
  190. }
  191. ._repo_top_right_img {
  192. width: 100%;
  193. height: 346px;
  194. position: absolute;
  195. bottom: 0;
  196. border-top-right-radius: 10px;
  197. overflow: hidden;
  198. }
  199. ._repo_top_right_img img {
  200. height: 100%;
  201. width: 100%;
  202. }
  203. ._repo_top_middle {
  204. flex: 1;
  205. height: 100%;
  206. position: relative;
  207. }
  208. ._repo_top_middle_header {
  209. width: 100%;
  210. height: 42px;
  211. position: absolute;
  212. bottom: 346px;
  213. display: flex;
  214. align-items: center;
  215. background: raba(0, 0, 255, 0.3);
  216. padding: 0 20px;
  217. }
  218. ._repo_top_mid_item {
  219. padding: 0px 16px;
  220. font-size: 18px;
  221. color: rgba(47, 9, 69, 0.64);
  222. height: 100%;
  223. display: flex;
  224. align-items: center;
  225. cursor: pointer;
  226. box-sizing: border-box;
  227. border-bottom: 3px solid transparent;
  228. }
  229. ._repo_top_mid_item i {
  230. margin-right: 5px;
  231. }
  232. ._repo_top_mid_item._foucs {
  233. background-color: rgba(255, 255, 255, 0.3);
  234. color: rgb(16, 16, 16);
  235. cursor: default;
  236. border-bottom: 3px solid rgba(16, 16, 16, 0.8);
  237. }
  238. ._repo_top_middle_content {
  239. width: 100%;
  240. height: 346px;
  241. position: absolute;
  242. bottom: 0;
  243. background: rgba(255, 255, 255, 0.3);
  244. padding: 20px 20px;
  245. overflow: hidden;
  246. }
  247. ._repo_top_mid_repo_list {
  248. overflow: hidden;
  249. }
  250. /deep/._repo_sw_card {
  251. height: 128px;
  252. border-color: rgb(255, 255, 255);
  253. border-width: 1px;
  254. border-style: solid;
  255. font-size: 14px;
  256. padding: 10px;
  257. background: rgba(255, 255, 255, 0.6);
  258. margin-bottom: 20px;
  259. box-sizing: border-box;
  260. position: relative;
  261. }
  262. /deep/._repo_nowrap {
  263. overflow: hidden;
  264. text-overflow: ellipsis;
  265. white-space: nowrap;
  266. }
  267. /deep/._repo_nowrap_line_2 {
  268. overflow: hidden;
  269. text-overflow: ellipsis;
  270. word-break: break-all;
  271. font-size: 12px;
  272. color: rgb(136, 136, 136);
  273. display: -webkit-box;
  274. -webkit-box-orient: vertical;
  275. -webkit-line-clamp: 2;
  276. max-height: 45px;
  277. white-space: break-spaces;
  278. }
  279. /deep/._repo_sw_card a {
  280. color: inherit;
  281. }
  282. /deep/._repo_sw_card_title {
  283. font-weight: 700;
  284. font-size: 14px;
  285. color: rgba(26, 40, 51, 1);
  286. margin-bottom: 10px;
  287. }
  288. /deep/._repo_sw_card_descr {
  289. font-size: 12px;
  290. color: rgba(80, 85, 89, 1);
  291. margin-bottom: 10px;
  292. min-height: 42px;
  293. }
  294. /deep/._repo_sw_card_label {
  295. color: rgb(26, 40, 51);
  296. font-size: 14px;
  297. }
  298. /deep/._repo_sw_card_label span {
  299. border-radius: 4px;
  300. background: rgba(232, 232, 232, 0.6);
  301. padding: 0px 6px 2px;
  302. margin-right: 10px;
  303. }
  304. /deep/._repo_top_mid_repo_list .swiper-pagination-bullet {
  305. width: 8px;
  306. height: 8px;
  307. border-radius: 100%;
  308. background: #76cbed;
  309. }
  310. /deep/._repo_top_mid_repo_list .swiper-pagination-bullet-active {
  311. width: 40px;
  312. border-radius: 4px;
  313. }
  314. </style>