enterprises.vue 9.0 KB

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