鸿宇研学生前端代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

428 lines
18 KiB

<template>
<div id="app" class="page__view">
<div class="card">
<div class="report" :style="style">
<!-- 01 -->
<view class="export">
<img class="img fg" :src="configList.report_page_01" crossorigin=anonymous />
</view>
<!-- 02 -->
<view class="export">
<img class="img fg" :src="configList.report_page_02" crossorigin=anonymous />
</view>
<!-- 03 -->
<view class="export">
<img class="img" :src="configList.report_page_03" crossorigin=anonymous />
<img class="img fg" style="top: 122rpx; left: 144rpx; width: 132rpx; height: 165rpx;" src="@/static/image/temp-14.png" crossorigin=anonymous />
<div class="text" style="top: 128rpx; left: 330rpx;">姓名</div>
<div class="text" style="top: 128rpx; left: 476rpx;">性别</div>
<div class="text" style="top: 192rpx; left: 330rpx;">年龄</div>
<div class="text" style="top: 192rpx; left: 476rpx;">学段</div>
<div class="text" style="top: 256rpx; left: 330rpx;">学校</div>
<div class="text" style="top: 300rpx; left: 190rpx;">城市</div>
<div class="text" style="top: 344rpx; left: 220rpx;">出勤情况</div>
</view>
<!-- 04 -->
<view class="export">
<img class="img fg" style="top: 112rpx; left: 193rpx; width: 414rpx; height: 246rpx; border-radius: 12rpx; overflow: hidden;" src="@/static/image/temp-20.png" crossorigin=anonymous />
<img class="img fg" :src="configList.report_page_04" crossorigin=anonymous />
</view>
<!-- 05 -->
<view class="export">
<img class="img fg" style="top: 344rpx; left: 100rpx; width: 96rpx; height: 96rpx; transform: rotate(14deg);" src="@/static/image/temp-20.png" crossorigin=anonymous />
<img class="img fg" style="top: 278rpx; left: 20rpx; width: 96rpx; height: 96rpx; transform: rotate(-7deg);" src="@/static/image/temp-14.png" crossorigin=anonymous />
<img class="img fg" style="top: 49rpx; left: 92rpx; width: 118rpx; height: 118rpx; transform: rotate(15deg);" src="@/static/image/temp-20.png" crossorigin=anonymous />
<img class="img fg" style="top: 134rpx; left: 138rpx; width: 118rpx; height: 118rpx; transform: rotate(-6deg);" src="@/static/image/temp-14.png" crossorigin=anonymous />
<img class="img fg" style="top: 194rpx; left: 316rpx; width: 134rpx; height: 134rpx; transform: rotate(-14deg);" src="@/static/image/temp-20.png" crossorigin=anonymous />
<img class="img fg" style="top: 280rpx; left: 430rpx; width: 134rpx; height: 134rpx; transform: rotate(14deg);" src="@/static/image/temp-14.png" crossorigin=anonymous />
<img class="img fg" style="top: 40rpx; left: unset; right: -38rpx; width: 213rpx; height: 213rpx; transform: rotate(14deg);" src="@/static/image/temp-20.png" crossorigin=anonymous />
<img class="img fg" :src="configList.report_page_05" crossorigin=anonymous />
</view>
<!-- 06 -->
<view class="export">
<img class="img fg" style="top: 190rpx; left: 146rpx; width: 126rpx; height: 80rpx; transform: skew(50deg, -34deg);" src="@/static/image/temp-20.png" crossorigin=anonymous />
<img class="img fg" style="top: 176rpx; left: 390rpx; width: 110rpx; height: 96rpx; transform: skew(50deg, 317deg);" src="@/static/image/temp-20.png" crossorigin=anonymous />
<img class="img fg" style="top: 120rpx; left: 276rpx; width: 110rpx; height: 74rpx; transform: skew(50deg, -34deg);" src="@/static/image/temp-14.png" crossorigin=anonymous />
<img class="img fg" style="top: 280rpx; left: 260rpx; width: 148rpx; height: 96rpx; transform: skew(54deg, 324deg);" src="@/static/image/temp-14.png" crossorigin=anonymous />
<img class="img fg" :src="configList.report_page_06" crossorigin=anonymous />
</view>
<!-- 07 -->
<view class="export">
<img class="img fg" style="top: 86rpx; left: 168rpx; width: 154rpx; height: 118rpx;" src="@/static/image/temp-20.png" crossorigin=anonymous />
<img class="img fg" style="top: 86rpx; left: 326rpx; width: 154rpx; height: 118rpx;" src="@/static/image/temp-14.png" crossorigin=anonymous />
<img class="img fg" style="top: 86rpx; left: 478rpx; width: 154rpx; height: 118rpx;" src="@/static/image/temp-20.png" crossorigin=anonymous />
<img class="img fg" style="top: 244rpx; left: 138rpx; width: 226rpx; height: 154rpx;" src="@/static/image/temp-20.png" crossorigin=anonymous />
<img class="img fg" style="top: 244rpx; left: 402rpx; width: 226rpx; height: 154rpx;" src="@/static/image/temp-14.png" crossorigin=anonymous />
<img class="img fg" :src="configList.report_page_07" crossorigin=anonymous />
</view>
<!-- 08 -->
<view class="export">
<img class="img fg" style="top: 76rpx; left: 112rpx; width: 110rpx; height: 110rpx;" src="@/static/image/temp-20.png" crossorigin=anonymous />
<img class="img fg" style="top: 194rpx; left: 112rpx; width: 110rpx; height: 110rpx;" src="@/static/image/temp-14.png" crossorigin=anonymous />
<img class="img fg" style="top: 76rpx; left: 242rpx; width: 110rpx; height: 110rpx;" src="@/static/image/temp-14.png" crossorigin=anonymous />
<img class="img fg" style="top: 194rpx; left: 242rpx; width: 110rpx; height: 110rpx;" src="@/static/image/temp-20.png" crossorigin=anonymous />
<img class="img fg" style="top: 312rpx; left: 242rpx; width: 110rpx; height: 110rpx;" src="@/static/image/temp-14.png" crossorigin=anonymous />
<img class="img fg" style="top: 138rpx; left: 372rpx; width: 110rpx; height: 110rpx;" src="@/static/image/temp-14.png" crossorigin=anonymous />
<img class="img fg" style="top: 258rpx; left: 372rpx; width: 110rpx; height: 110rpx;" src="@/static/image/temp-20.png" crossorigin=anonymous />
<img class="img fg" style="top: 194rpx; left: 504rpx; width: 110rpx; height: 110rpx;" src="@/static/image/temp-20.png" crossorigin=anonymous />
<img class="img fg" style="top: 312rpx; left: 504rpx; width: 110rpx; height: 110rpx;" src="@/static/image/temp-14.png" crossorigin=anonymous />
<img class="img fg" :src="configList.report_page_08" crossorigin=anonymous />
</view>
<!-- 09 -->
<view class="export">
<img class="img fg" style="top: 0; left: unset; right: 0; width: auto; height: 100%;" src="@/static/image/temp-20.png" crossorigin=anonymous />
<img class="img fg" style="width: 260rpx; height: 180rpx;" src="@/static/image/temp-14.png" crossorigin=anonymous />
<img class="img img-08 fg" :src="configList.report_page_09" crossorigin=anonymous />
</view>
<!-- 10 -->
<view class="export">
<img class="img fg" style="top: 126rpx; left: 106rpx; width: 158rpx; height: 106rpx;" src="@/static/image/temp-20.png" crossorigin=anonymous />
<img class="img fg" style="top: 132rpx; left: 450rpx; width: 148rpx; height: 100rpx;" src="@/static/image/temp-20.png" crossorigin=anonymous />
<img class="img fg" style="top: 132rpx; left: 604rpx; width: 90rpx; height: 100rpx;" src="@/static/image/temp-14.png" crossorigin=anonymous />
<img class="img fg" style="top: 238rpx; left: 54rpx; width: 210rpx; height: 140rpx;" src="@/static/image/temp-14.png" crossorigin=anonymous />
<img class="img fg" style="top: 242rpx; left: 450rpx; width: 122rpx; height: 80rpx;" src="@/static/image/temp-14.png" crossorigin=anonymous />
<img class="img fg" style="top: 242rpx; left: 576rpx; width: 120rpx; height: 200rpx;" src="@/static/image/temp-20.png" crossorigin=anonymous />
<img class="img fg" style="top: 326rpx; left: 270rpx; width: 156rpx; height: 106rpx;" src="@/static/image/temp-20.png" crossorigin=anonymous />
<img class="img fg" style="top: 68rpx; left: 274rpx; width: 170rpx; height: 256rpx;" src="@/static/image/temp-20.png" crossorigin=anonymous />
<img class="img fg" :src="configList.report_page_10" crossorigin=anonymous />
</view>
<!-- 11 -->
<view class="export">
<img class="img fg" style="top: unset; bottom: 268rpx; left: 54rpx; width: 118rpx; height: 80rpx;" src="@/static/image/temp-14.png" crossorigin=anonymous />
<img class="img fg" style="top: unset; bottom: 268rpx; left: 180rpx; width: 78rpx; height: 110rpx;" src="@/static/image/temp-20.png" crossorigin=anonymous />
<img class="img fg" style="top: unset; bottom: 268rpx; left: 262rpx; width: 210rpx; height: 160rpx;" src="@/static/image/temp-14.png" crossorigin=anonymous />
<img class="img fg" style="top: 240rpx; left: 54rpx; width: 170rpx; height: 142rpx;" src="@/static/image/temp-20.png" crossorigin=anonymous />
<img class="img fg" style="top: 240rpx; left: 380rpx; width: 118rpx; height: 80rpx;" src="@/static/image/temp-20.png" crossorigin=anonymous />
<img class="img fg" :src="configList.report_page_11" crossorigin=anonymous />
</view>
<!-- 12 -->
<view class="export">
<img class="img fg" style="top: 130rpx; left: 122rpx; width: 80rpx; height: 100rpx;" src="@/static/image/temp-20.png" crossorigin=anonymous />
<img class="img fg" style="top: 130rpx; left: 224rpx; width: 80rpx; height: 100rpx;" src="@/static/image/temp-14.png" crossorigin=anonymous />
<img class="img fg" style="top: 130rpx; left: 328rpx; width: 80rpx; height: 100rpx;" src="@/static/image/temp-20.png" crossorigin=anonymous />
<img class="img fg" style="top: 130rpx; left: 432rpx; width: 80rpx; height: 100rpx;" src="@/static/image/temp-14.png" crossorigin=anonymous />
<img class="img fg" style="top: 130rpx; left: 536rpx; width: 80rpx; height: 100rpx;" src="@/static/image/temp-20.png" crossorigin=anonymous />
<img class="img fg" style="top: 264rpx; left: 122rpx; width: 80rpx; height: 100rpx;" src="@/static/image/temp-14.png" crossorigin=anonymous />
<img class="img fg" style="top: 264rpx; left: 224rpx; width: 80rpx; height: 100rpx;" src="@/static/image/temp-20.png" crossorigin=anonymous />
<img class="img fg" style="top: 264rpx; left: 328rpx; width: 80rpx; height: 100rpx;" src="@/static/image/temp-14.png" crossorigin=anonymous />
<img class="img fg" style="top: 264rpx; left: 432rpx; width: 80rpx; height: 100rpx;" src="@/static/image/temp-20.png" crossorigin=anonymous />
<img class="img fg" style="top: 264rpx; left: 536rpx; width: 80rpx; height: 100rpx;" src="@/static/image/temp-14.png" crossorigin=anonymous />
<img class="img fg" :src="configList.report_page_12" crossorigin=anonymous />
</view>
<!-- 13 -->
<view class="export">
<img class="img" :src="configList.report_page_13" crossorigin=anonymous />
<div class="text text-12" style="top: 134rpx; left: 160rpx;">技能01</div>
<div class="text text-12" style="top: 134rpx; left: 260rpx;">技能01描述</div>
<div class="text text-12" style="top: 182rpx; left: 160rpx;">技能02</div>
<div class="text text-12" style="top: 182rpx; left: 260rpx;">技能02描述</div>
<div class="text text-12" style="top: 232rpx; left: 160rpx;">技能03</div>
<div class="text text-12" style="top: 232rpx; left: 260rpx;">技能03描述</div>
<div class="text text-12" style="top: 282rpx; left: 160rpx;">技能04</div>
<div class="text text-12" style="top: 282rpx; left: 260rpx;">技能04描述</div>
<div class="text text-12" style="top: 330rpx; left: 160rpx;">技能05</div>
<div class="text text-12" style="top: 330rpx; left: 260rpx;">技能05描述</div>
</view>
<!-- 14 -->
<view class="export">
<img class="img fg" :src="configList.report_page_14" crossorigin=anonymous />
<div class="text text-13" style="top: 150rpx; left: 116rpx;">同学寄语同学寄语同学寄语同学寄语同学寄语同学寄语同学寄语同学寄语</div>
<div class="text text-13" style="top: 260rpx; left: 400rpx;">导师寄语导师寄语导师寄语导师寄语导师寄语导师寄语导师寄语导师寄语导师寄语</div>
</view>
<!-- 15 -->
<view class="export">
<img class="img fg" style="top: 46rpx; left: unset; right: 30rpx; width: 506rpx; height: 390rpx;" src="@/static/image/temp-20.png" crossorigin=anonymous />
<img class="img fg" :src="configList.report_page_15" crossorigin=anonymous />
</view>
<!-- 00 -->
<view class="export">
<img class="img fg" :src="configList.report_page_00" crossorigin=anonymous />
</view>
</div>
</div>
<img v-if="current > 0" class="img turn left" src="@/static/image/icon-left.png" @click="prev" />
<img v-if="current < 15" class="img turn right" src="@/static/image/icon-right.png" @click="next" />
<div class="flex bottom">
<div class="flex btns">
<button class="btn" @click="createPdf">生成pdf</button>
</div>
</div>
</div>
</template>
<script>
import html2canvas from 'html2canvas'
import { jsPDF } from "jspdf";
export default {
data() {
return {
id: null,
details: {},
current: 0,
}
},
computed: {
style() {
return `transform: translateX(calc(-${this.current}*(100vw - 24rpx * 2)))`
},
},
onLoad(arg) {
document.addEventListener('UniAppJSBridgeReady', function() {
console.log('UniAppJSBridgeReady', uni)
uni.getEnv(function(res) {
console.log('当前环境:' + JSON.stringify(res));
});
})
const { id, token } = arg
token && uni.setStorageSync('token', token)
this.id = id
},
mounted() {
this.getData(this.id)
},
methods: {
getData(id) {
// todo
},
prev() {
this.current -= 1
},
next() {
this.current += 1
},
createPdf() {
uni.showLoading({
title: '生成中...'
})
console.log('createPdf')
const fillPage = () => {
// 设置背景色
PDF.setFillColor(251, 254, 255); // 例如,红色背景
// 绘制一个填充的矩形覆盖整个页面
PDF.rect(0, 0, PDF.internal.pageSize.getWidth(), PDF.internal.pageSize.getHeight(), 'F'); // 'F'表示填充
}
let PDF = new jsPDF('l', 'pt', 'a4')
console.log('PDF', PDF)
console.log('size', PDF.internal.pageSize.getWidth(), PDF.internal.pageSize.getHeight())
const WIDTH = PDF.internal.pageSize.getWidth() // 841.89
const HEIGHT = PDF.internal.pageSize.getHeight() // 595.28
let request = []
let nodeList = document.querySelectorAll('.export')
for(let i = 0; i < nodeList.length; i++) {
request.push(html2canvas(nodeList[i], { allowTaint: true, useCORS: true, }))
}
return Promise.allSettled(request).then(res => {
console.log('res', res)
fillPage()
res.forEach((item, index) => {
if (index > 0) {
PDF.addPage()
fillPage()
}
const canvas = item.value
const contentWidth = canvas.width
const contentHeight = canvas.height
// let imgHeight = (WIDTH / contentWidth) * contentHeight // 根据a4纸比例,计算出图片的高度
let pageData = canvas.toDataURL('image/jpeg', 1.0)
PDF.addImage(pageData, 'JPEG', 0, 0, WIDTH, HEIGHT)
return
// 分页剩余高度
let leftHeight = imgHeight
// 分页偏移位置
let position = 0
// 如果图片高度大于a4纸高度,则需要分页
if (imgHeight > HEIGHT) {
while (leftHeight > 0) {
// 第三个参数图片x轴位置,第四个参数图片y轴位置,第五个参数图片宽度,第六个参数图片高度
PDF.addImage(pageData, 'JPEG', 0, position, WIDTH, imgHeight)
leftHeight = leftHeight - HEIGHT
position -= HEIGHT
if (leftHeight > 0) {
PDF.addPage()
fillPage()
}
}
} else {
PDF.addImage(pageData, 'JPEG', 0, 0, WIDTH, imgHeight)
// const marginY = (HEIGHT - imgHeight) / 2 // 计算出图片的上下边距
// // 第三个参数图片x轴位置,第四个参数图片y轴位置,第五个参数图片宽度,第六个参数图片高度
// PDF.addImage(pageData, 'JPEG', 0, marginY > 0 ? marginY : 0, a4Width, imgHeight)
}
})
// #ifdef H5
PDF.save('测试生成pdf' + '.pdf'); //h5在这就可以保存pdf
// #endif
return
uni.postMessage({
data: {
imageData: PDF.output("datauristring"),
}
});
// uni.navigateBack()
uni.redirectTo({
url: `/pages_order/thesis/createPdf?id=${this.id}`
})
}).catch(err => {
console.log('err', err)
}).finally(() => {
uni.hideLoading()
})
},
}
}
</script>
<style lang="scss" scoped>
$pages: 16;
$w: calc(100vw - 24rpx * 2);
$h: calc(#{$w} / 841.89 * 595.28);
.page__view {
width: 100vw;
min-height: 100vh;
background: #F7F8FA;
position: relative;
box-sizing: border-box;
font-family: PingFang SC;
font-weight: 400;
line-height: 1.4;
}
.card {
position: absolute;
top: 50vh;
transform: translateY(-50%);
width: $w;
margin: 0 24rpx;
padding: 250rpx 0;
overflow: hidden;
background: #FFFFFF;
}
.report {
width: calc(#{$pages}*#{$w});
height: auto;
overflow-x: visible;
}
.export {
position: relative;
display: inline-block;
width: $w;
min-height: $h;
overflow: hidden;
}
.fg {
position: absolute;
top: 0;
left: 0;
}
.img {
display: block;
width: $w;
height: auto;
&-08 {
width: auto;
height: $h;
}
}
.text {
position: absolute;
font-size: 20rpx;
font-weight: 600;
color: #FFFFFF;
&-12 {
font-size: 14rpx;
color: #000000;
}
&-13 {
width: 206rpx;
white-space: pre-wrap;
font-size: 14rpx;
color: #000000;
}
}
// .export__view {
// position: fixed;
// top: 100vh;
// }
.turn {
width: 80rpx;
height: 80rpx;
position: fixed;
top: 50vh;
transform: translateY(-50%);
&.left {
left: 0;
}
&.right {
right: 0;
}
}
.bottom {
position: fixed;
left: 0;
bottom: 0;
width: 100vw;
height: 55px;
padding: 0 25px;
box-sizing: border-box;
background: #FFFFFF;
box-shadow: 0px 3px 6px 0px rgba(0,0,0,0.16);
.btns {
width: 100%;
// justify-content: space-between;
}
.btn {
padding: 10px 45px;
font-size: 14px;
color: #FFFFFF;
background: #4883F9;
border-radius: 21px;
border: none;
}
}
</style>