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

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