index.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <template>
  2. <div class="search d-flex align-center">
  3. <v-menu :close-delay="1" :open-delay="0" v-bind="$attrs">
  4. <template v-slot:activator="{ isActive, props }">
  5. <v-btn
  6. style="height: 100%; font-size: 16px;"
  7. variant="text"
  8. density="comfortable"
  9. :append-icon="isActive ? 'mdi mdi-menu-up' : 'mdi mdi-menu-down'"
  10. color="primary"
  11. v-bind="props"
  12. >
  13. {{ defineProps.text }}
  14. </v-btn>
  15. </template>
  16. <jobTypeCard v-if="defineProps.text === '职位类型'" isBuryingPoint class="jobTypeCardBox" @handleJobClick="handleClickJob"></jobTypeCard>
  17. </v-menu>
  18. <!-- <div style="position: relative;">
  19. <div class="jobBox d-flex pl-5" :class="{'drawer': drawer}" @click.stop="drawer = !drawer">
  20. <span>{{ text }}</span>
  21. <span class="mdi mdi-chevron-down px-2" style="font-size: 18px;"></span>
  22. </div>
  23. <jobTypeCard class="jobTypeCardBox" v-if="drawer" @click.stop=""></jobTypeCard>
  24. </div> -->
  25. <v-text-field
  26. v-model="value"
  27. placeholder="搜索职位/公司"
  28. color="primary"
  29. variant="plain"
  30. density="compact"
  31. :hide-details="true"
  32. class="ml-3 px-2"
  33. style="height: 100%; line-height: 100%;"
  34. @keyup.enter="handleSearch"
  35. ></v-text-field>
  36. <div class="searchBtn" @click="handleSearch">搜索</div>
  37. </div>
  38. </template>
  39. <script setup>
  40. import { useSharedState } from '@/store/sharedState'
  41. import jobTypeCard from '@/components/jobTypeCard'
  42. import { ref, watch } from 'vue'
  43. import { useRoute, useRouter } from 'vue-router'
  44. defineOptions({ name:'common-components-headSearch'})
  45. const route = useRoute(); const router = useRouter()
  46. const emits = defineEmits(['update:modelValue', 'handleSearch', 'handleJobClick'])// 定义一个或多个自定义事件
  47. const defineProps = defineProps({
  48. modelValue: [String, Number],
  49. text: {
  50. type: String,
  51. default: '职位类型'
  52. },
  53. })
  54. // const value = ref('')
  55. const value = ref(defineProps.modelValue)
  56. let drawer = ref(false)
  57. if (route.query && route.query?.content) value.value = route.query.content
  58. // 点击外部关闭职位下拉
  59. const sharedState = useSharedState()
  60. // 监听 layoutClickCount 变化
  61. watch(() => sharedState.layoutClickCount, () => {
  62. if (drawer.value) drawer.value = false
  63. });
  64. const handleSearch = () => {
  65. // 职位搜索页传参,其它的跳转到职位搜索页
  66. if (route.path !== '/recruit/position') {
  67. if (value.value) router.push(`/recruit/position?content=${value.value}`)
  68. else router.push('/recruit/position')
  69. } else emits('handleSearch', value.value)
  70. }
  71. const handleClickJob = (val) => {
  72. // 职位搜索页点击传参, 其它的跳转到职位搜索页
  73. if (route.path !== '/recruit/position') router.push(`/recruit/position?positionId=${val.id}`)
  74. else emits('handleJobClick', val)
  75. }
  76. </script>
  77. <style lang="scss" scoped>
  78. .search {
  79. height: 50px;
  80. width: 800px;
  81. margin: 0 auto;
  82. border: 2px solid var(--v-primary-base);
  83. border-radius: 5px;
  84. .jobBox {
  85. cursor: pointer;
  86. &:hover {
  87. color: var(--v-primary-base);
  88. }
  89. span {
  90. max-width: 150px;
  91. white-space: nowrap;
  92. overflow: hidden;
  93. text-overflow: ellipsis;
  94. }
  95. }
  96. .drawer {
  97. color: var(--v-primary-base);
  98. }
  99. .searchBtn {
  100. width: 100px;
  101. height: 50px; line-height: 48px;
  102. text-align: center;
  103. font-size: 18px;
  104. color: #fff;
  105. background-color: var(--v-primary-base);
  106. cursor: pointer;
  107. }
  108. .jobTypeCardBox {
  109. position: absolute;
  110. top: 42px;
  111. left: 0;
  112. }
  113. }
  114. </style>