search.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <template>
  2. <view>
  3. <Navbar :showLogo="true" />
  4. <layout-page>
  5. <view :style="{'padding-top': navbarHeight + 'px'}">
  6. <view class="commonBackground"></view>
  7. <view class="box defaultBgc">
  8. <!-- <SwiperAd v-if="swiperAdList?.length" margin="0 10px 10px 10px" :list="swiperAdList" imgUrlKey="img" :strType="false" /> -->
  9. <view>
  10. <uni-segmented-control
  11. :current="current"
  12. :values="tabList"
  13. @clickItem="changeControl"
  14. styleType="text"
  15. activeColor="#00B760"
  16. ></uni-segmented-control>
  17. </view>
  18. <!-- 职位推荐 -->
  19. <RecommendPage v-if="current === 0" :jobList="jobList" :navbarHeight="navbarHeight" />
  20. <!-- 条件筛选 -->
  21. <ConditionPage v-else :navbarHeight="navbarHeight" />
  22. </view>
  23. </view>
  24. </layout-page>
  25. </view>
  26. </template>
  27. <script setup>
  28. import { ref, watch, onMounted } from 'vue'
  29. import { onShow } from '@dcloudio/uni-app'
  30. import layoutPage from '@/layout'
  31. import Navbar from '@/components/Navbar'
  32. import { getAccessToken } from '@/utils/request'
  33. import { showAuthModal } from '@/hooks/useModal'
  34. import { getJobAdvertised } from '@/api/search'
  35. import { userStore } from '@/store/user'
  36. import { formatName } from '@/utils/getText'
  37. import RecommendPage from './components/recommend.vue'
  38. import ConditionPage from './components/condition.vue'
  39. const navbarHeight = ref(0)
  40. onMounted(async () => {
  41. try {
  42. const res = await new Promise((resolve, reject) => {
  43. uni.getStorage({
  44. key: 'navbarHeight',
  45. success: (result) => resolve(result),
  46. fail: (err) => reject(err)
  47. })
  48. })
  49. navbarHeight.value = res.data
  50. console.log(navbarHeight.value, '职位列表-导航栏高度')
  51. } catch (error) {
  52. console.error('读取本地缓存出错:', error)
  53. }
  54. })
  55. const current = ref(0)
  56. const tabList = ['人才推荐', '条件筛选']
  57. const useUserStore = userStore()
  58. // 职位列表
  59. const jobList = ref([])
  60. const getJobList = async () => {
  61. // 仅企业登录并且有刷新token时获取;注册(个人令牌)不获取
  62. if (!useUserStore.refreshToken) {
  63. return
  64. }
  65. // 双保险:优先使用 store 标志,兼容本地缓存未及时写入
  66. if (useUserStore.isPersonal || uni.getStorageSync('isPersonalToken')) {
  67. return
  68. }
  69. const { data } = await getJobAdvertised({ status: 0, exTime: 0 })
  70. if (data.length) {
  71. jobList.value = data.map(e => {
  72. return { text: `${formatName(e.name)}_${e.areaName ? e.area?.str : '全国'}`, value: e.id }
  73. })
  74. }
  75. }
  76. watch(() => [useUserStore.refreshToken, useUserStore.isPersonal], ([refreshToken, isPersonal]) => {
  77. if (!refreshToken) return
  78. if (isPersonal) return
  79. getJobList()
  80. }, { immediate: true })
  81. onShow(() => {
  82. // 设置自定义tabbar选中值
  83. const currentPage = getCurrentPages()[0] // 获取当前页面实例
  84. const currentTabBar = currentPage?.getTabBar?.()
  85. // 设置当前tab页的下标index
  86. currentTabBar?.setData({ selected: 0 })
  87. if (!getAccessToken()) return showAuthModal()
  88. if (uni.getStorageSync('isPersonalToken')) return
  89. getJobList()
  90. })
  91. const changeControl = (e) =>{
  92. current.value = e.currentIndex
  93. }
  94. </script>
  95. <style scoped lang="scss">
  96. :deep {
  97. .uni-select__selector-item {
  98. display: block !important;
  99. text-align: left !important;
  100. max-width: 100% !important;
  101. white-space: nowrap !important;
  102. text-overflow: ellipsis !important;
  103. overflow: hidden !important;
  104. }
  105. .uni-select {
  106. background-color: #fff !important;
  107. }
  108. }
  109. // .stick {
  110. // z-index: 1;
  111. // position: sticky;
  112. // background-color: #fff;
  113. // }
  114. </style>