|
@@ -0,0 +1,183 @@
|
|
|
+<!-- 招聘会-分享企业 -->
|
|
|
+<template>
|
|
|
+ <view style="position: relative;">
|
|
|
+ <view v-if="shareUrl" class="d-flex align-center flex-column justify-center" style="height: 100vh;">
|
|
|
+ <image v-if="!!shareUrl" :style="imgStyle" @click="handlePreviewSharePoster" :src="shareUrl" :show-menu-by-longpress="true"></image>
|
|
|
+ <view class="color-999 ss-m-t-20 font-size-14 ss-m-b-50">点击图片预览,长按图片保存</view>
|
|
|
+ </view>
|
|
|
+ <canvas canvas-id="posterCanvas" class="shareCanvas" style="width: 330px; height: 600px;"></canvas>
|
|
|
+ </view>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script setup>
|
|
|
+import { ref, computed } from 'vue'
|
|
|
+import { onLoad } from '@dcloudio/uni-app'
|
|
|
+import { getJobAdvertisedShareQrcode } from '@/api/user'
|
|
|
+import { getJobFair } from '@/api/jobFair'
|
|
|
+// import { getEnterpriseDetails } from '@/api/user'
|
|
|
+// import { getEnterpriseDetails } from '@/api/user'
|
|
|
+ // const positionList = listData.value.length ? JSON.stringify(listData.value.slice(0, 2)) : "0"
|
|
|
+
|
|
|
+const shareUrl = ref('')
|
|
|
+const windowWidth = ref(0)
|
|
|
+let jobFairId = '' // 分享会ID
|
|
|
+let enterpriseId = '' // 企业ID
|
|
|
+let shareImg = '' // 分享背景图片-底图
|
|
|
+// let shareImg = 'https://menduner.citupro.com:3443/dev/4dd7dd3c9ef350d62fcbc814b88c1ac1916f484a3ee8d8531ae7a2698a289670.jpg' // 分享背景图片-底图
|
|
|
+
|
|
|
+onLoad(async (options) => {
|
|
|
+ jobFairId = options.jobFairId
|
|
|
+ enterpriseId = options.enterpriseId
|
|
|
+ await getJobFairDetail()
|
|
|
+ // await getJobFairEntDetail()
|
|
|
+ const windowInfo = wx.getWindowInfo()
|
|
|
+ windowWidth.value = windowInfo.windowWidth
|
|
|
+ console.log(windowWidth.value, '当前机型屏幕宽')
|
|
|
+})
|
|
|
+
|
|
|
+const getJobFairDetail = async () => {
|
|
|
+ if (!jobFairId) return
|
|
|
+ const { data } = await getJobFair(jobFairId)
|
|
|
+ shareImg = data?.contentImg || ''
|
|
|
+ if (shareImg) createPoster()
|
|
|
+}
|
|
|
+
|
|
|
+const getEntPositionList = async () => {
|
|
|
+ if (!query.jobFairId) {
|
|
|
+ uni.showToast({ title: '获取企业岗位失败,请重试!', icon: 'none', duration: 2000 })
|
|
|
+ return
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ const params = { ...query }
|
|
|
+ const positionIdValue = tabIndex.value !== -1 ? tabList.value[tabIndex.value]?.value : []
|
|
|
+ positionIdValue?.length && positionIdValue.forEach((value, index) => {
|
|
|
+ params[`positionId[${index}]`] = value
|
|
|
+ })
|
|
|
+ const res = await getJobFairEntJobPage(params)
|
|
|
+ const list = res?.data?.list || []
|
|
|
+ // list.forEach(e => {
|
|
|
+ // e.job = dealDictObjData({}, e)
|
|
|
+ // e.enterprise = { ...e.enterprise, ...dealDictObjData({}, e.enterprise)}
|
|
|
+ // })
|
|
|
+ // listData.value = listData.value.concat(list)
|
|
|
+ // showShareBtn.value = true
|
|
|
+ // if (listData.value?.length === +res?.data?.total) {
|
|
|
+ // more.value = 'noMore'
|
|
|
+ // return
|
|
|
+ // }
|
|
|
+ } catch (error) {
|
|
|
+ query.pageNo--
|
|
|
+ more.value = 'more'
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+const imgStyle = computed(() => {
|
|
|
+ if (windowWidth.value <= 320) return `width: 259px; height: 460px;`
|
|
|
+ if (windowWidth.value > 320 && windowWidth.value <= 375) return `width: 313px; height: 560px;`
|
|
|
+ if (windowWidth.value > 375) return `width: 328px; height: 600px;`
|
|
|
+})
|
|
|
+
|
|
|
+// 图片预览
|
|
|
+const handlePreviewSharePoster = () => {
|
|
|
+ uni.previewImage({
|
|
|
+ current: 0,
|
|
|
+ longPressActions: {
|
|
|
+ itemList: ['发送给朋友', '保存图片', '收藏']
|
|
|
+ },
|
|
|
+ urls: [shareUrl.value]
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+const getImageTempRatio = (url) => {
|
|
|
+ return new Promise((req, rej)=>{
|
|
|
+ wx.getImageInfo({
|
|
|
+ src:url,
|
|
|
+ success:(res) =>{
|
|
|
+ req(res)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+const getToLocal = (base64data) => {
|
|
|
+ const fsm = wx.getFileSystemManager()
|
|
|
+ const FILE_BASE_NAME = 'tmp_base64src'; //自定义文件名
|
|
|
+ const [, format, bodyData] = /data:image\/(\w+);base64,(.*)/.exec(base64data) || []
|
|
|
+ if (!format) {
|
|
|
+ return (new Error('ERROR_BASE64SRC_PARSE'))
|
|
|
+ }
|
|
|
+ const filePath = `${wx.env.USER_DATA_PATH}/${FILE_BASE_NAME}.${format}`
|
|
|
+ const buffer = wx.base64ToArrayBuffer(bodyData);
|
|
|
+ fsm.writeFile({
|
|
|
+ filePath,
|
|
|
+ data: buffer,
|
|
|
+ encoding: 'binary',
|
|
|
+ success(r) {
|
|
|
+ console.log(filePath,'filePath')
|
|
|
+ qrCode.value = filePath
|
|
|
+ },
|
|
|
+ fail() {
|
|
|
+ return (new Error('ERROR_BASE64SRC_WRITE'))
|
|
|
+ }
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+// 生成分享二维码
|
|
|
+const qrCode = ref()
|
|
|
+const handleShareCode = async () => {
|
|
|
+ const query = {
|
|
|
+ scene: `jobFairId=${jobFairId}&enterpriseId=${enterpriseId}&entName=${entName}`,
|
|
|
+ scene: 'jobFairId=' + jobFairId + '&enterpriseId=' + enterpriseId,
|
|
|
+ path: 'pages/login/index',
|
|
|
+ // path: 'pagesB/jobFair/positionClassification',
|
|
|
+ width: 200,
|
|
|
+ autoColor: false,
|
|
|
+ checkPath: true,
|
|
|
+ hyaline: true
|
|
|
+ }
|
|
|
+ const res = await getJobAdvertisedShareQrcode(query)
|
|
|
+ const data = res?.data ? 'data:image/png;base64,' + res.data : ''
|
|
|
+ getToLocal(data)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+const createPoster = async () => {
|
|
|
+ uni.showLoading({ title: '生成中...', mask: true })
|
|
|
+ await handleShareCode() // 生产分享二维码
|
|
|
+ var context = uni.createCanvasContext('posterCanvas')
|
|
|
+
|
|
|
+ //清空画布
|
|
|
+ context.clearRect(0, 0, 330, 600)
|
|
|
+
|
|
|
+ //背景图片
|
|
|
+ const { path: bgUrl } = await getImageTempRatio(shareImg)
|
|
|
+ context.drawImage(bgUrl, 0, 0, 330, 600) // 路径、x、y、宽、高
|
|
|
+
|
|
|
+ //分享二维码
|
|
|
+ context.drawImage(qrCode.value, 105.5, 380, 120, 120)
|
|
|
+
|
|
|
+ context.draw(false, () =>{
|
|
|
+ wx.canvasToTempFilePath({
|
|
|
+ canvasId: 'posterCanvas',
|
|
|
+ success:(res)=>{
|
|
|
+ shareUrl.value = res.tempFilePath
|
|
|
+ console.log('canvas-success', shareUrl.value)
|
|
|
+ uni.hideLoading({})
|
|
|
+ },
|
|
|
+ fail:(err)=>{
|
|
|
+ uni.hideLoading({})
|
|
|
+ console.log('canvas-fail', err)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ })
|
|
|
+}
|
|
|
+</script>
|
|
|
+
|
|
|
+<style scoped lang="scss">
|
|
|
+.shareCanvas {
|
|
|
+ position: fixed;
|
|
|
+ top: -99999upx;
|
|
|
+ left: -99999upx;
|
|
|
+ z-index: -99999;
|
|
|
+}
|
|
|
+</style>
|