enterprises.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. <!-- 企业 -->
  2. <template>
  3. <div class="position-relative">
  4. <!-- 招聘会分享按钮 -->
  5. <div v-if="jobFair?.shareImg" class="position-fixed" style="right: 24px; top: 20px; z-index: 999;">
  6. <div class="cursor-pointer pa-2 white-bgc" style="border-radius: 8px;" @click.stop="handleShare">
  7. <v-icon color="primary" size="50">mdi-share</v-icon>
  8. </div>
  9. </div>
  10. <div ref="observedElement">
  11. <!-- 轮播 -->
  12. <v-carousel
  13. v-if="jobFair?.pcHeadImg && jobFair?.pcHeadImg.length > 0"
  14. :show-arrows="jobFair?.pcHeadImg.length > 1 ? 'hover' : false"
  15. cycle :hide-delimiters="true"
  16. style="height: auto;"
  17. :style="{'max-height': isMobile ? '200px' : '553px'}"
  18. >
  19. <v-carousel-item v-for="(k, i) in jobFair?.pcHeadImg" :key="i">
  20. <img :src="k" :lazy-src="k" style="width: 100%; height:100%;">
  21. </v-carousel-item>
  22. </v-carousel>
  23. </div>
  24. <div
  25. :style="{
  26. 'background-color': jobFair.backgroundColour || '#fff',
  27. 'min-height': jobFair?.pcHeadImg && jobFair?.pcHeadImg.length > 0 ? `calc(100vh - ${carouselHeight}px)` : '100vh'
  28. }">
  29. <div :class="{'default-width': !isMobile}">
  30. <SearchBar class="py-5" v-model="query.keyword" :isMobile="isMobile" placeholder="搜索关键字" @handleSearch="handleSearch" />
  31. <!-- 类别展示 -->
  32. <!-- <div class="d-flex align-center" v-if="jobFair?.tag && jobFair.tag.length" style="overflow-x: auto;">
  33. <div
  34. v-for="(val, index) in jobFair.tag"
  35. :key="index"
  36. class="tag-item"
  37. :class="[{'tag-active-bg': index === tab && jobFair.backgroundColour}, {'mx-5': isMobile}, {'tag-active': index === tab && !jobFair.backgroundColour}]"
  38. :style="{'width': `calc(100% / ${jobFair.tag.length} )`, 'color': jobFair.backgroundColour ? '#fff' : 'var(--v-primary-base)'}"
  39. @click.stop="handleTabClick(index)"
  40. >
  41. {{ val.title }}
  42. </div>
  43. </div> -->
  44. <v-tabs v-model="tab" align-tabs="center" v-if="jobFair?.tag && jobFair.tag.length">
  45. <v-tab v-for="(k, i) in jobFair.tag" class="tab-item" :key="i" :value="k.value" @click="handleTabClick(i)">{{ k.title }}</v-tab>
  46. </v-tabs>
  47. <div
  48. v-if="!items.length"
  49. class="text-center"
  50. :style="{
  51. 'color': jobFair.backgroundColour ? '#fff' : 'var(--v-primary-base)',
  52. 'height': `calc(100vh - ${carouselHeight}px)`,
  53. 'line-height': `calc(100vh - ${carouselHeight}px)`
  54. }"
  55. >
  56. {{ loadingType === 1 ? loadingText[loadingType] : '暂无数据,去看看其他吧~' }}
  57. </div>
  58. <template v-else>
  59. <EntCard v-if="jobFair?.category === '0'" :jobFairId="jobFair?.id" :list="items" :isMobile="isMobile" class="mt-5" />
  60. <JobCard v-if="jobFair?.category === '1'" :jobFairId="jobFair?.id" :list="items" :isMobile="isMobile" class="mt-5" />
  61. <div
  62. :class="['loading', {'cursor-pointer': !loadingType}]"
  63. :style="{'color': !jobFair?.tag || !jobFair.tag.length ? 'var(--v-primary-base)' : '#fff'}"
  64. class="py-5"
  65. @click="handleChangePage"
  66. >
  67. {{ loadingText[loadingType] }}
  68. </div>
  69. </template>
  70. </div>
  71. </div>
  72. <div class="hideCanvasView">
  73. <canvas ref="shareCanvas" :width="canvasWidth" :height="canvasHeight"></canvas>
  74. </div>
  75. </div>
  76. <Loading :visible="loading" />
  77. <PreviewImage v-if="showPreview" :urlList="[previewSrc]" :fileName="jobFair?.title?.replace(/<\/?p[^>]*>/gi, '')" @close="showPreview = !showPreview" />
  78. </template>
  79. <script setup>
  80. defineOptions({name: 'jobFair-enterprises'})
  81. import { ref, reactive, onMounted, onUnmounted } from 'vue'
  82. import { getJobFairEnterprisePage, getJobFair, getJobFairEntJobPage, saveShareQuery } from '@/api/recruit/personal/jobFair'
  83. import EntCard from './components/entCard1.vue'
  84. import JobCard from './components/jobCard1.vue'
  85. import { useRoute } from 'vue-router'; const route = useRoute();
  86. import { dealDictArrayData, dealDictObjData } from '@/utils/position'
  87. import { getJobAdvertisedShareQrcode } from '@/api/position'
  88. import SearchBar from '../components/searchBar.vue'
  89. const tab = ref(0)
  90. const loading = ref(false)
  91. const query = reactive({
  92. pageNo: 1,
  93. pageSize: 20,
  94. jobFairId: route.params.id,
  95. keyword: ''
  96. })
  97. const showPreview = ref(false)
  98. const shareCanvas = ref(null)
  99. const previewSrc = ref('')
  100. const canvasWidth = 500
  101. const canvasHeight = 900
  102. const observedElement = ref(null)
  103. let resizeObserver
  104. const carouselHeight = ref(0)
  105. const handleResize = (entries) => {
  106. for (let entry of entries) {
  107. if (entry.target === observedElement.value) {
  108. carouselHeight.value = entry.contentRect.height
  109. }
  110. }
  111. }
  112. const isMobile = ref(false)
  113. onMounted(() => {
  114. const userAgent = navigator.userAgent
  115. isMobile.value = /(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i.test(userAgent)
  116. if (observedElement.value) {
  117. resizeObserver = new ResizeObserver(handleResize)
  118. resizeObserver.observe(observedElement.value)
  119. }
  120. })
  121. onUnmounted(() => {
  122. if (resizeObserver && observedElement.value instanceof Element) {
  123. resizeObserver.unobserve(observedElement.value)
  124. }
  125. resizeObserver.disconnect()
  126. })
  127. const items = ref([])
  128. const loadingText = ['点击加载更多', '加载中...', '']
  129. const loadingType = ref(0)
  130. // 参与招聘会的企业
  131. const getList = async () => {
  132. loadingType.value = 1
  133. // 有类别的添加筛选条件
  134. if (jobFair.value?.tag && jobFair.value?.tag.length) {
  135. const key = jobFair.value.tag[tab.value].key
  136. const value = jobFair.value.tag[tab.value].content.map(e => e.value)
  137. query[key] = value
  138. }
  139. try {
  140. const result = jobFair.value?.category === '0' ? await getJobFairEnterprisePage(query) : await getJobFairEntJobPage(query)
  141. const list = result?.list || []
  142. if (list.length) {
  143. if (jobFair.value?.category === '1') {
  144. items.value.push(...list.map(e => {
  145. e.enterprise = dealDictObjData({}, e.enterprise)
  146. e = dealDictObjData({}, e)
  147. return e
  148. }))
  149. }
  150. else items.value = items.value.concat(dealDictArrayData([], list))
  151. loadingType.value = items.value.length === result.total ? 2 : 0
  152. } else {
  153. loadingType.value = 2
  154. }
  155. } catch {}
  156. }
  157. // 搜索
  158. const handleSearch = (val) => {
  159. items.value = []
  160. query.pageNo = 1
  161. query.keyword = val
  162. getList()
  163. }
  164. // 招聘会详情
  165. const jobFair = ref([])
  166. const getJobFairDetail = async () => {
  167. const data = await getJobFair(route?.params?.id)
  168. if (!data) return
  169. jobFair.value = data
  170. document.title = data.title.replace(/<\/?p[^>]*>/gi, '')
  171. getList()
  172. }
  173. getJobFairDetail()
  174. // tab项点击
  175. const handleTabClick = (index) => {
  176. items.value = []
  177. query.pageNo = 1
  178. tab.value = index
  179. getList()
  180. }
  181. const handleChangePage = () => {
  182. if (loadingType.value) return // 没有更多数据了
  183. // 加载更多
  184. query.pageNo++
  185. getList()
  186. }
  187. const handleShare = () => {
  188. loading.value = true
  189. const canvas = shareCanvas.value
  190. const ctx = canvas.getContext('2d')
  191. const img = new Image()
  192. img.crossOrigin = 'anonymous'
  193. img.onload = async () => {
  194. //清空画布
  195. ctx.clearRect(0, 0, canvasWidth, canvasHeight)
  196. // 设置背景图片
  197. ctx.drawImage(img, 0, 0, canvasWidth, canvasHeight)
  198. // 分享二维码
  199. const secondImg = new Image()
  200. secondImg.crossOrigin = 'anonymous'
  201. secondImg.onload = () => {
  202. // 计算第二张图片的位置和大小(这里以示例为准,您可以根据需要调整)
  203. const secondImgWidth = Math.min(secondImg.width, canvas.width / 4)
  204. const secondImgHeight = (secondImgWidth / secondImg.width) * secondImg.height // 保持宽高比
  205. const x = (canvas.width - secondImgWidth) / 2 // 水平居中
  206. const y = canvas.height - secondImgHeight - 190 // 垂直放置在 Canvas 底部上方 170 像素处
  207. // 绘制第二张图片到 Canvas 上的指定位置和大小
  208. ctx.drawImage(secondImg, x, y, secondImgWidth, secondImgHeight)
  209. ctx.font = 'bold 16px Arial'
  210. ctx.fillStyle = '#10325d'
  211. const text = '扫码投递'
  212. const textWidth = ctx.measureText(text).width
  213. const textX = x + (secondImgWidth - textWidth) / 2
  214. const textY = y + secondImgHeight + 30
  215. ctx.fillText(text, textX, textY)
  216. previewSrc.value = canvas.toDataURL()
  217. loading.value = false
  218. showPreview.value = true
  219. }
  220. // 保存分享参数
  221. const result = await saveShareQuery({ jobFairId: route.params.id })
  222. const query = {
  223. scene: 'id=' + result,
  224. path: `pagesB/jobFair/${Number(jobFair.value?.category) ? 'positionClassification' : 'enterprisesClassification'}`,
  225. width: 200,
  226. autoColor: false,
  227. checkPath: true,
  228. hyaline: false
  229. }
  230. const data = await getJobAdvertisedShareQrcode(query)
  231. secondImg.src = 'data:image/png;base64,' + data
  232. }
  233. img.onerror = (error) => {
  234. console.error('Failed to load image:', error)
  235. loading.value = false
  236. }
  237. img.src = jobFair.value?.shareImg
  238. }
  239. </script>
  240. <style scoped lang="scss">
  241. .tab-item {
  242. font-weight: 700;
  243. font-size: 1.5rem;
  244. color: #fff;
  245. padding: 10px 25px;
  246. }
  247. :deep(.v-tab__slider) {
  248. height: 4px;
  249. border-radius: 2px;
  250. }
  251. .tag-item {
  252. font-weight: 700;
  253. font-size: 24px;
  254. text-align: center;
  255. height: 74px;
  256. line-height: 74px;
  257. opacity: .8;
  258. cursor: pointer;
  259. text-wrap: nowrap;
  260. }
  261. .tag-active-bg {
  262. opacity: 1;
  263. position: relative;
  264. &::before {
  265. display: block;
  266. content: '';
  267. width: 34px;
  268. height: 4px;
  269. background-color: #fff;
  270. position: absolute;
  271. top: 62px;
  272. left: 50%;
  273. border-radius: 2px;
  274. transform: translateX(-50%);
  275. }
  276. }
  277. .tag-active {
  278. opacity: 1;
  279. position: relative;
  280. &::before {
  281. display: block;
  282. content: '';
  283. width: 34px;
  284. height: 4px;
  285. background-color: var(--v-primary-base);
  286. position: absolute;
  287. top: 62px;
  288. left: 50%;
  289. border-radius: 2px;
  290. transform: translateX(-50%);
  291. }
  292. }
  293. .loading {
  294. margin-top: 8px;
  295. text-align: center;
  296. font-size: 18px;
  297. }
  298. .hideCanvasView {
  299. position: fixed;
  300. top: -99999px;
  301. left: -99999px;
  302. z-index: -99999;
  303. }
  304. ::-webkit-scrollbar {
  305. width: 0;
  306. height: 0;
  307. }
  308. ::-webkit-scrollbar-thumb, .temporaryAdd ::-webkit-scrollbar-thumb, .details_edit ::-webkit-scrollbar-thumb {
  309. // 滚动条-颜色
  310. background: #c3c3c379;
  311. }
  312. ::-webkit-scrollbar-track, .temporaryAdd ::-webkit-scrollbar-track, .details_edit ::-webkit-scrollbar-track {
  313. // 滚动条-底色
  314. background: #e5e5e58f;
  315. }
  316. </style>