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

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