search.vue 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <template>
  2. <layout-page>
  3. <view >
  4. <view style="padding: 0 15px 0 15px;">
  5. <uni-segmented-control
  6. :current="current"
  7. :values="tabList"
  8. @clickItem="changeControl"
  9. styleType="text"
  10. activeColor="#00B760"
  11. ></uni-segmented-control>
  12. </view>
  13. <!-- 职位推荐 -->
  14. <RecommendPage v-if="current === 0" :jobList="jobList" />
  15. <!-- 条件筛选 -->
  16. <ConditionPage v-else />
  17. </view>
  18. </layout-page>
  19. </template>
  20. <script setup>
  21. import layoutPage from '@/layout'
  22. import { ref, watch } from 'vue'
  23. import { onShow } from '@dcloudio/uni-app'
  24. import { getAccessToken } from '@/utils/request'
  25. import { showAuthModal } from '@/hooks/useModal'
  26. import { getJobAdvertised } from '@/api/search'
  27. import { userStore } from '@/store/user'
  28. import { formatName } from '@/utils/getText'
  29. import RecommendPage from './components/recommend.vue'
  30. import ConditionPage from './components/condition.vue'
  31. const current = ref(0)
  32. const tabList = ['职位推荐', '条件筛选']
  33. const useUserStore = userStore()
  34. // 职位列表
  35. const jobList = ref([])
  36. const getJobList = async () => {
  37. const { data } = await getJobAdvertised({ status: 0 })
  38. if (data.length) {
  39. jobList.value = data.map(e => {
  40. return { text: `${formatName(e.name)}_${e.areaName ? e.area?.str : '全国'}`, value: e.id }
  41. })
  42. }
  43. }
  44. watch(() => useUserStore.refreshToken, () => {
  45. if (!useUserStore.refreshToken) return jobList.value = []
  46. getJobList()
  47. }, { immediate: true })
  48. onShow(() => {
  49. // 设置自定义tabbar选中值
  50. const currentPage = getCurrentPages()[0] // 获取当前页面实例
  51. const currentTabBar = currentPage?.getTabBar?.()
  52. // 设置当前tab页的下标index
  53. currentTabBar?.setData({ selected: 0 })
  54. if (!getAccessToken()) return showAuthModal()
  55. })
  56. const changeControl = (e) =>{
  57. current.value = e.currentIndex
  58. }
  59. </script>
  60. <style scoped lang="scss">
  61. </style>