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