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.

SearchBar.vue 7.0 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. <template>
  2. <div class="search-bar">
  3. <div class="search-bar-l">
  4. <div class="search-c">
  5. <div class="search-input-c">
  6. <input type="text" :placeholder="serchPlaceHolder" v-model="keyword" @keyup.enter="search">
  7. </div>
  8. <div class="search-btn" @click="search">搜索</div>
  9. </div>
  10. <el-button class="apply-btn" type="primary" icon="el-icon-plus" size="medium" @click="apply">申请展示项目</el-button>
  11. <el-button class="apply-btn" type="primary" icon="el-icon-s-management" size="medium" v-if="isTechAdmin"
  12. @click="manage">管理展示项目</el-button>
  13. <div class="openi-link-c">
  14. <a class="openi-link" target="_blank" href="javascript:;">OpenI启智社区开源指南</a>
  15. </div>
  16. </div>
  17. <div class="sort-c">
  18. <el-select class="select" size="medium" v-model="sortType" @change="changeSort" placeholder="排序" clearable>
  19. <el-option v-for="item in sortList" :key="item.k" :label="item.v" :value="item.k" />
  20. </el-select>
  21. </div>
  22. </div>
  23. </template>
  24. <script>
  25. import { getIsTechAdmin } from '~/apis/modules/tech';
  26. export default {
  27. name: "SearchBar",
  28. props: {
  29. type: { type: Number, default: -1 }, // 0-tech_view, 1-repo_view
  30. condition: { type: Object, default: () => ({}) },
  31. },
  32. components: {},
  33. data() {
  34. return {
  35. keyword: '',
  36. serchPlaceHolder: '',
  37. sortType: '',
  38. techSortList: [{
  39. k: 'time',
  40. v: '最近更新',
  41. }, {
  42. k: 'count',
  43. v: '项目成果数',
  44. }],
  45. repoSortList: [
  46. {
  47. k: 'mostpopular',
  48. v: '近期热门',
  49. }, {
  50. k: 'recentupdate',
  51. v: '最近更新',
  52. }, {
  53. k: 'newest',
  54. v: '最近创建',
  55. }
  56. ],
  57. sortList: [],
  58. isTechAdmin: false,
  59. };
  60. },
  61. methods: {
  62. search() {
  63. this.$emit('changeCondition', {
  64. q: this.keyword.trim()
  65. });
  66. },
  67. apply() {
  68. window.location.href = '/tech/new';
  69. },
  70. manage() {
  71. window.location.href = '/tech/admin_view';
  72. },
  73. changeSort() {
  74. this.$emit('changeCondition', {
  75. sort: this.sortType
  76. });
  77. }
  78. },
  79. watch: {
  80. condition: {
  81. handler(newVal) {
  82. this.keyword = newVal.q;
  83. this.sortType = newVal.sort;
  84. },
  85. immediate: true,
  86. deep: true,
  87. },
  88. },
  89. beforeMount() {
  90. if (this.type == 0) {
  91. this.sortList = this.techSortList;
  92. this.serchPlaceHolder = '搜索科技项目名称';
  93. } else if (this.type == 1) {
  94. this.serchPlaceHolder = '搜索项目名称/简介/标签';
  95. this.sortList = this.repoSortList;
  96. }
  97. getIsTechAdmin().then(res => {
  98. res = res.data;
  99. if (res.data && res.data.is_admin) {
  100. this.isTechAdmin = true;
  101. }
  102. }).catch(err => {
  103. console.log(err);
  104. });
  105. },
  106. mounted() { },
  107. };
  108. </script>
  109. <style scoped lang="less">
  110. .search-bar {
  111. margin: 30px 0;
  112. display: flex;
  113. justify-content: space-between;
  114. .search-bar-l {
  115. display: flex;
  116. .search-c {
  117. display: flex;
  118. align-items: center;
  119. justify-content: center;
  120. margin-right: 20px;
  121. .search-input-c {
  122. width: 268px;
  123. height: 40px;
  124. border-color: rgba(0, 61, 192, 0.73);
  125. border-width: 2px;
  126. border-style: solid;
  127. font-size: 14px;
  128. line-height: 20px;
  129. padding: 8px;
  130. display: flex;
  131. color: rgb(136, 136, 136);
  132. align-items: center;
  133. 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(6.123233995736766e-17%2C%201%2C%20-0.014005111865831027%2C%206.123233995736766e-17%2C%200.5%2C%200)%22%3E%3Cstop%20stop-color%3D%22%23e2d1ea%22%20stop-opacity%3D%221%22%20offset%3D%220%22%3E%3C%2Fstop%3E%3Cstop%20stop-color%3D%22%23ffffff%22%20stop-opacity%3D%221%22%20offset%3D%220.3%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");
  134. input {
  135. width: 100%;
  136. border: none;
  137. outline: none;
  138. }
  139. }
  140. .search-btn {
  141. height: 40px;
  142. font-size: 14px;
  143. line-height: 20px;
  144. padding: 0px;
  145. display: flex;
  146. color: rgb(255, 255, 255);
  147. align-items: center;
  148. text-align: center;
  149. justify-content: center;
  150. padding: 0 20px;
  151. cursor: pointer;
  152. 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(-1.1800000000000002%2C%200.9499999999999998%2C%20-0.23749999999999996%2C%20-1.1800000000000002%2C%201.024%2C%200.047)%22%3E%3Cstop%20stop-color%3D%22%23bbd2f2%22%20stop-opacity%3D%221%22%20offset%3D%220.02%22%3E%3C%2Fstop%3E%3Cstop%20stop-color%3D%22%23003dc0%22%20stop-opacity%3D%220.73%22%20offset%3D%221%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");
  153. }
  154. }
  155. .apply-btn {
  156. margin-left: 20px;
  157. border-color: rgb(31, 1, 115);
  158. border-width: 1px;
  159. border-style: solid;
  160. border-radius: 6px;
  161. font-size: 14px;
  162. 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(6.123233995736766e-17%2C%201%2C%20-0.08281144868278038%2C%206.123233995736766e-17%2C%200.5%2C%200)%22%3E%3Cstop%20stop-color%3D%22%233291f8%22%20stop-opacity%3D%221%22%20offset%3D%220%22%3E%3C%2Fstop%3E%3Cstop%20stop-color%3D%22%23060075%22%20stop-opacity%3D%220.73%22%20offset%3D%221%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");
  163. &:hover {
  164. opacity: 0.9;
  165. }
  166. &:active {
  167. opacity: 0.8;
  168. }
  169. }
  170. .openi-link-c {
  171. margin-left: 20px;
  172. display: flex;
  173. align-items: center;
  174. justify-content: center;
  175. .openi-link {
  176. text-decoration: underline;
  177. color: rgb(50, 145, 248);
  178. }
  179. }
  180. }
  181. .sort-c {
  182. display: flex;
  183. align-items: center;
  184. justify-content: center;
  185. justify-self: flex-end;
  186. }
  187. }
  188. </style>