search.vue 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 { dealDictArrayData } from '@/utils/position'
  28. import { userStore } from '@/store/user'
  29. import { formatName } from '@/utils/getText'
  30. import RecommendPage from './components/recommend.vue'
  31. import ConditionPage from './components/condition.vue'
  32. const current = ref(0)
  33. const tabList = ['职位推荐', '条件筛选']
  34. const useUserStore = userStore()
  35. // 职位列表
  36. const jobList = ref([])
  37. const getJobList = async () => {
  38. const { data } = await getJobAdvertised({ status: 0 })
  39. if (data.length) {
  40. const list = dealDictArrayData([], data)
  41. jobList.value = list.map(e => {
  42. return { text: `${formatName(e.name)}_${e.areaName ? e.area?.str : '全国'}`, value: e.id, data: e }
  43. })
  44. }
  45. }
  46. watch(() => useUserStore.refreshToken, () => {
  47. if (!useUserStore.refreshToken) return jobList.value = []
  48. getJobList()
  49. }, { immediate: true })
  50. onShow(() => {
  51. // 设置自定义tabbar选中值
  52. const currentPage = getCurrentPages()[0] // 获取当前页面实例
  53. const currentTabBar = currentPage?.getTabBar?.()
  54. // 设置当前tab页的下标index
  55. currentTabBar?.setData({ selected: 0 })
  56. if (!getAccessToken()) return showAuthModal()
  57. })
  58. const changeControl = (e) =>{
  59. current.value = e.currentIndex
  60. }
  61. </script>
  62. <style scoped lang="scss">
  63. </style>