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.

index.vue 4.8 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
2 years ago
2 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <template>
  2. <div>
  3. <div>
  4. <SquareTop :static="true" :staticBannerData="staticSquareBanners" :staticSwiperData="staticSquarePreferredRepos">
  5. </SquareTop>
  6. </div>
  7. <div class="ui container">
  8. <SearchBar :static="true" :staticTopicsData="staticSquareTopics" ref="searchBarRef" type="square" :sort="``"
  9. :searchValue="reposListQurey" :topic="``" @change="searchBarChange"></SearchBar>
  10. </div>
  11. <div class="recommend-repos-c">
  12. <RecommendRepos :static="true" :staticSwiperData="staticSquareRecommendRepos"></RecommendRepos>
  13. <a name="search"></a>
  14. </div>
  15. <div class="ui container">
  16. <div class="ui grid">
  17. <div class="computer only ui two wide computer column">
  18. <ReposFilters ref="reposFiltersRef" @change="filtersChange"></ReposFilters>
  19. </div>
  20. <div class="ui sixteen wide mobile twelve wide tablet ten wide computer column">
  21. <ReposList ref="reposListRef" :sort="reposListSortType" :q="reposListQurey" :topic="reposListTopic"
  22. :page="page" :pageSize="pageSize" :pageSizes="pageSizes" @current-change="currentChange"
  23. @size-change="sizeChange">
  24. </ReposList>
  25. </div>
  26. <div class="computer only ui four wide computer column">
  27. <div>
  28. <ActiveUsers></ActiveUsers>
  29. </div>
  30. <div class="active-org-c">
  31. <ActiveOrgs></ActiveOrgs>
  32. </div>
  33. </div>
  34. </div>
  35. </div>
  36. </div>
  37. </template>
  38. <script>
  39. import SquareTop from '../components/SquareTop.vue';
  40. import SearchBar from '../components/SearchBar.vue';
  41. import RecommendRepos from '../components/RecommendRepos.vue';
  42. import ReposFilters from '../components/ReposFilters.vue';
  43. import ReposList from '../components/ReposList.vue';
  44. import ActiveUsers from '../components/ActiveUsers.vue';
  45. import ActiveOrgs from '../components/ActiveOrgs.vue';
  46. import { getUrlSearchParams } from '~/utils';
  47. const staticSquareBanners = JSON.stringify(window.staticSquareBanners || []);
  48. const staticSquarePreferredRepos = window.staticSquarePreferredRepos || [];
  49. const staticSquareTopics = JSON.stringify(window.staticSquareTopics || []);
  50. const staticSquareRecommendRepos = window.staticSquareRecommendRepos || [];
  51. export default {
  52. data() {
  53. return {
  54. reposListSortType: 'mostpopular',
  55. reposListQurey: '',
  56. reposListTopic: '',
  57. page: 1,
  58. pageSize: 15,
  59. pageSizes: [15, 30, 50],
  60. staticSquareBanners: staticSquareBanners,
  61. staticSquarePreferredRepos: staticSquarePreferredRepos,
  62. staticSquareTopics: staticSquareTopics,
  63. staticSquareRecommendRepos: staticSquareRecommendRepos,
  64. };
  65. },
  66. components: {
  67. SquareTop,
  68. SearchBar,
  69. RecommendRepos,
  70. ReposFilters,
  71. ReposList,
  72. ActiveUsers,
  73. ActiveOrgs,
  74. },
  75. methods: {
  76. filtersChange(condition) {
  77. this.page = 1;
  78. this.reposListSortType = condition.key;
  79. this.search();
  80. },
  81. searchBarChange(params) {
  82. this.page = 1;
  83. this.reposListQurey = params.q || '';
  84. this.reposListTopic = params.topic || '';
  85. this.search();
  86. },
  87. currentChange({ page, pageSize }) {
  88. this.page = page;
  89. this.search();
  90. },
  91. sizeChange({ page, pageSize }) {
  92. this.page = 1;
  93. this.pageSize = pageSize;
  94. this.search();
  95. },
  96. search() {
  97. window.location.href = `/explore/repos/square?q=${this.reposListQurey.trim()}&sort=${this.reposListSortType}&topic=${this.reposListTopic.trim()}&page=${this.page}&pageSize=${this.pageSize}`;
  98. }
  99. },
  100. beforeMount() {
  101. const urlParams = getUrlSearchParams();
  102. this.reposListQurey = urlParams.q || '';
  103. this.reposListTopic = urlParams.topic || '';
  104. this.reposListSortType = urlParams.sort || 'mostpopular';
  105. this.page = Number(urlParams.page) || 1;
  106. this.pageSize = this.pageSizes.indexOf(Number(urlParams.pageSize)) >= 0 ? Number(urlParams.pageSize) : 15;
  107. },
  108. mounted() {
  109. this.$nextTick(() => {
  110. this.$refs.reposFiltersRef.setDefaultFilter(this.reposListSortType);
  111. this.$refs.searchBarRef.setDefaultSearch({
  112. q: this.reposListQurey,
  113. topic: this.reposListTopic,
  114. });
  115. const urlParams = getUrlSearchParams();
  116. const page = Number(urlParams.page) || 1;
  117. const reposListSortType = urlParams.sort;
  118. if (page != 1 || reposListSortType) {
  119. window.location.href = '#search';
  120. }
  121. this.$refs.reposListRef.search();
  122. });
  123. window.addEventListener('pageshow', function (e) {
  124. if (e.persisted) {
  125. window.location.reload();
  126. }
  127. }, false);
  128. },
  129. beforeDestroy() { },
  130. };
  131. </script>
  132. <style scoped lang="less">
  133. .recommend-repos-c {
  134. margin: 0 0 54px;
  135. }
  136. .active-org-c {
  137. margin-top: 32px;
  138. }
  139. </style>