search.vue 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 && !uni.getStorageSync('isPersonalToken')) {
  46. getJobList()
  47. }
  48. }, { immediate: true })
  49. onShow(() => {
  50. // 设置自定义tabbar选中值
  51. const currentPage = getCurrentPages()[0] // 获取当前页面实例
  52. const currentTabBar = currentPage?.getTabBar?.()
  53. // 设置当前tab页的下标index
  54. currentTabBar?.setData({ selected: 0 })
  55. if (!getAccessToken()) return showAuthModal()
  56. })
  57. const changeControl = (e) =>{
  58. current.value = e.currentIndex
  59. }
  60. </script>
  61. <style scoped lang="scss">
  62. </style>