vocation-posts.vue 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. <template>
  2. <scroll-view scroll-y :scroll-top="scrollTop" class="tabs-swiper-content" @scroll="handleScroll">
  3. <uv-tabs :current="current" :list="posts" v-bind="tabOptions">
  4. <template #default="{item, index}">
  5. <view class="bg-white mx-card fx-col fx-cen-cen px-20 py-10 text-content text-2xs"
  6. :class="{'active-post': index==current}" @click="current=index">
  7. <text>{{ item.name }}</text>
  8. <text>{{ `${item.salaryMin}-${item.salaryMax}/月` }}</text>
  9. </view>
  10. </template>
  11. </uv-tabs>
  12. <view class="bg-white">
  13. <view class="fx-row fx-bet-cen p-20">
  14. <view class="text-main text-lg font-bold">薪资情况</view>
  15. <mx-subsection v-model="currentChart" :list="chatTypes" width="120px"/>
  16. </view>
  17. <mx-echarts v-if="currentChart==0" :option="trendChartData" canvas-id="trend-chart"/>
  18. <mx-echarts v-else :option="distributeChartData" canvas-id="distribute-chart"/>
  19. </view>
  20. <view class="mt-20 bg-white">
  21. <view class="fx-row fx-bet-cen p-20">
  22. <view class="text-main text-lg font-bold">收入排行</view>
  23. <mx-subsection v-model="currentView" :list="viewTypes" width="120px"/>
  24. </view>
  25. <view v-show="currentView==0" class="fx-col gap-20 p-20 text-content">
  26. <view v-for="s in postDetail.industrySalary" class="fx-row fx-bet-cen gap-20">
  27. <view class="keep-all">{{ s.name }}</view>
  28. <uv-line dashed/>
  29. <view class="keep-all">¥{{ s.salary }}</view>
  30. </view>
  31. </view>
  32. <view v-show="currentView==1" class="fx-col gap-20 p-20 text-content">
  33. <view v-for="s in postDetail.citySalary" class="fx-row fx-bet-cen gap-20">
  34. <view class="keep-all">{{ s.city }}</view>
  35. <uv-line dashed/>
  36. <view class="keep-all">¥{{ s.salary }}</view>
  37. </view>
  38. </view>
  39. </view>
  40. <view class="mt-20 bg-white">
  41. <view class="fx-row fx-bet-cen p-20">
  42. <view class="text-main text-lg font-bold">就业情况</view>
  43. <mx-subsection v-model="currentPie" :list="pieTypes" width="120px"/>
  44. </view>
  45. <mx-echarts v-if="currentPie==0" :option="eduPieData" canvas-id="edu-chart"/>
  46. <mx-echarts v-else :option="expPieData" canvas-id="exp-chart"/>
  47. </view>
  48. <view class="mt-20 bg-white">
  49. <view class="fx-row fx-bet-cen p-20">
  50. <view class="text-main text-lg font-bold">招聘需求量</view>
  51. </view>
  52. <view class="fx-col gap-20 p-20 text-content">
  53. <view v-for="s in postDetail.demand" class="fx-row fx-bet-cen gap-20">
  54. <view class="keep-all">{{ s.city }}</view>
  55. <uv-line dashed/>
  56. <view class="keep-all">{{ s.count }}
  57. <text class="text-tips text-xs">个职位</text>
  58. </view>
  59. </view>
  60. </view>
  61. </view>
  62. <view class="mt-20 bg-white">
  63. <view class="fx-row p-20">
  64. <uv-icon name="question-circle" label-size="14" label="数据来源说明:"/>
  65. </view>
  66. <view class="text-tips text-2xs p-20">
  67. <view>{{ postDetail.vocationalSource }}</view>
  68. <view>{{ postDetail.salarySource }}</view>
  69. </view>
  70. </view>
  71. <uv-gap height="20"/>
  72. </scroll-view>
  73. </template>
  74. <script setup>
  75. import {ref, computed, watch} from 'vue';
  76. import {useInjectVocationDetailService} from "@/pages/vocation-library/detail/components/useVocationDetailInjection";
  77. import {sleep} from "@/uni_modules/uv-ui-tools/libs/function";
  78. import {useCacheStore} from "@/hooks/useCacheStore";
  79. import {vocationalPostsDetail} from "@/api/webApi/collegemajor";
  80. const {posts, scrollTop, currentPostName} = useInjectVocationDetailService()
  81. const {dispatchCache} = useCacheStore()
  82. const current = ref(0)
  83. const postDetail = ref({})
  84. watch(currentPostName, async name => {
  85. await sleep(500)
  86. const idx = posts.value.findIndex(p => p.name == name)
  87. if (idx > -1) current.value = idx
  88. else current.value = 0
  89. }, {immediate: true})
  90. watch(current, async i => {
  91. // detail要以current为准,因为currentPostName有匹配不上的情况
  92. const currentPost = posts.value[i]
  93. const {name} = currentPost || {}
  94. if (!name) return
  95. const payload = {postName: name}
  96. const res = await dispatchCache(vocationalPostsDetail, payload)
  97. postDetail.value = res.data
  98. }, {immediate: true})
  99. const tabOptions = {
  100. scrollable: true,
  101. keyName: 'seq',
  102. lineHeight: 0.5,
  103. lineWidth: 80,
  104. lineColor: 'white',
  105. itemStyle: {height: '60px'}
  106. }
  107. const createPieData = (pieData) => {
  108. // https://echarts.apache.org/examples/zh/editor.html?c=pie-simple
  109. return {
  110. title: {
  111. text: '',
  112. subtext: '',
  113. left: 'center'
  114. },
  115. tooltip: {
  116. trigger: 'item',
  117. formatter: '{b}: {d}%'
  118. },
  119. legend: {
  120. show: false
  121. },
  122. series: [
  123. {
  124. name: '',
  125. type: 'pie',
  126. radius: ['40%', '70%'],
  127. data: pieData,
  128. label: {
  129. show: true, // 启用标签
  130. formatter: '{b}: {d}%' // 格式化标签
  131. },
  132. emphasis: {
  133. itemStyle: {
  134. shadowBlur: 10,
  135. shadowOffsetX: 0,
  136. shadowColor: 'rgba(0, 0, 0, 0.5)'
  137. }
  138. }
  139. }
  140. ]
  141. }
  142. }
  143. const currentChart = ref(0)
  144. const chatTypes = ['按趋势', '按分布']
  145. const trendChartData = computed(() => {
  146. // https://echarts.apache.org/examples/zh/editor.html?c=area-basic
  147. if (!postDetail.value?.experience?.length) return null
  148. const exp = postDetail.value.experience
  149. const cols = exp.map(e => e.year)
  150. const rows = exp.map(e => e.salary)
  151. return {
  152. grid: {
  153. top: '5%',
  154. bottom: '12%',
  155. left: '12%'
  156. },
  157. xAxis: {
  158. type: 'category',
  159. boundaryGap: false,
  160. data: cols
  161. },
  162. yAxis: {
  163. type: 'value',
  164. axisLabel: {
  165. rotate: 45
  166. }
  167. },
  168. series: [
  169. {
  170. data: rows,
  171. type: 'line',
  172. smooth: true, // 设置为平滑曲线
  173. areaStyle: {}
  174. }
  175. ]
  176. }
  177. })
  178. const distributeChartData = computed(() => {
  179. if (!postDetail.value?.salary?.length) return null
  180. const pieData = postDetail.value.salary.map(item => {
  181. return {
  182. value: item.ratio,
  183. name: `${item.min}-${item.max}元/月`,
  184. }
  185. })
  186. return createPieData(pieData)
  187. })
  188. const currentView = ref(0)
  189. const viewTypes = ['按行业', '按地区']
  190. // view 没有用报表
  191. const currentPie = ref(0)
  192. const pieTypes = ['按学历', '按经验']
  193. const eduPieData = computed(() => {
  194. if (!postDetail.value?.edu?.length) return null
  195. const pieData = postDetail.value.edu.map(item => {
  196. return {
  197. value: item.ratio,
  198. name: `${item.edu}${item.ratio}%`,
  199. }
  200. })
  201. return createPieData(pieData)
  202. })
  203. const expPieData = computed(() => {
  204. if (!postDetail.value?.exp?.length) return null
  205. const pieData = postDetail.value.exp.map(item => {
  206. return {
  207. value: item.ratio,
  208. name: `${item.exp}${item.ratio}%`,
  209. }
  210. })
  211. return createPieData(pieData)
  212. })
  213. const handleScroll = (e) => {
  214. scrollTop.value = e.detail.scrollTop
  215. }
  216. </script>
  217. <style scoped lang="scss">
  218. .active-post {
  219. background-color: var(--primary-color) !important;
  220. color: white !important;
  221. }
  222. ::v-deep(.uv-tabs) {
  223. .uv-tabs__wrapper__nav {
  224. /* 不能设置__nav的间隔相关属性,会导致uv-tabs内部无法准确计算位置 */
  225. /* 重写__item的样式是没有关系的 */
  226. &__item {
  227. padding: 8px 4px;
  228. box-sizing: border-box;
  229. &:first-child {
  230. padding-left: 8px;
  231. }
  232. &:nth-last-child(2) {
  233. padding-right: 8px;
  234. }
  235. }
  236. }
  237. }
  238. </style>