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

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