鸿宇研学生前端代码
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

2 months ago
3 days ago
2 days ago
3 days ago
2 days ago
3 days ago
2 days ago
3 days ago
2 days ago
3 days ago
2 days ago
3 days ago
2 days ago
3 days ago
2 days ago
3 days ago
2 days ago
2 months ago
3 days ago
2 days ago
3 days ago
2 days ago
3 days ago
2 days ago
3 days ago
2 days ago
3 days ago
2 days ago
3 days ago
2 days ago
3 days ago
2 days ago
3 days ago
2 months ago
3 days ago
2 months ago
3 days ago
2 months ago
2 months ago
3 days ago
3 days ago
2 months ago
3 days ago
2 days ago
3 days ago
2 months ago
3 days ago
2 months ago
3 days ago
2 months ago
3 days ago
2 days ago
2 months ago
3 days ago
2 months ago
2 days ago
2 months ago
3 days ago
2 months ago
3 days ago
2 months ago
2 months ago
2 days ago
3 days ago
2 months ago
3 days ago
3 days ago
3 days ago
3 days ago
  1. <template>
  2. <div id="app" class="page__view">
  3. <div class="card">
  4. <div class="report" :style="style">
  5. <!-- 01 -->
  6. <view class="export">
  7. <img class="img fg" :src="configList.report_page_01" crossorigin=anonymous />
  8. </view>
  9. <!-- 02 -->
  10. <view class="export">
  11. <img class="img fg" :src="configList.report_page_02" crossorigin=anonymous />
  12. </view>
  13. <!-- 03 -->
  14. <view class="export">
  15. <img class="img" :src="configList.report_page_03" crossorigin=anonymous />
  16. <img class="img fg" style="top: 122rpx; left: 144rpx; width: 132rpx; height: 165rpx;" src="@/static/image/temp-14.png" crossorigin=anonymous />
  17. <div class="text" style="top: 128rpx; left: 330rpx;">姓名</div>
  18. <div class="text" style="top: 128rpx; left: 476rpx;">性别</div>
  19. <div class="text" style="top: 192rpx; left: 330rpx;">年龄</div>
  20. <div class="text" style="top: 192rpx; left: 476rpx;">学段</div>
  21. <div class="text" style="top: 256rpx; left: 330rpx;">学校</div>
  22. <div class="text" style="top: 300rpx; left: 190rpx;">城市</div>
  23. <div class="text" style="top: 344rpx; left: 220rpx;">出勤情况</div>
  24. </view>
  25. <!-- 04 -->
  26. <view class="export">
  27. <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 />
  28. <img class="img fg" :src="configList.report_page_04" crossorigin=anonymous />
  29. </view>
  30. <!-- 05 -->
  31. <view class="export">
  32. <img class="img fg" style="top: 344rpx; left: 100rpx; width: 96rpx; height: 96rpx; transform: rotate(14deg);" src="@/static/image/temp-20.png" crossorigin=anonymous />
  33. <img class="img fg" style="top: 278rpx; left: 20rpx; width: 96rpx; height: 96rpx; transform: rotate(-7deg);" src="@/static/image/temp-14.png" crossorigin=anonymous />
  34. <img class="img fg" style="top: 49rpx; left: 92rpx; width: 118rpx; height: 118rpx; transform: rotate(15deg);" src="@/static/image/temp-20.png" crossorigin=anonymous />
  35. <img class="img fg" style="top: 134rpx; left: 138rpx; width: 118rpx; height: 118rpx; transform: rotate(-6deg);" src="@/static/image/temp-14.png" crossorigin=anonymous />
  36. <img class="img fg" style="top: 194rpx; left: 316rpx; width: 134rpx; height: 134rpx; transform: rotate(-14deg);" src="@/static/image/temp-20.png" crossorigin=anonymous />
  37. <img class="img fg" style="top: 280rpx; left: 430rpx; width: 134rpx; height: 134rpx; transform: rotate(14deg);" src="@/static/image/temp-14.png" crossorigin=anonymous />
  38. <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 />
  39. <img class="img fg" :src="configList.report_page_05" crossorigin=anonymous />
  40. </view>
  41. <!-- 06 -->
  42. <view class="export">
  43. <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 />
  44. <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 />
  45. <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 />
  46. <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 />
  47. <img class="img fg" :src="configList.report_page_06" crossorigin=anonymous />
  48. </view>
  49. <!-- 07 -->
  50. <view class="export">
  51. <img class="img fg" style="top: 86rpx; left: 168rpx; width: 154rpx; height: 118rpx;" src="@/static/image/temp-20.png" crossorigin=anonymous />
  52. <img class="img fg" style="top: 86rpx; left: 326rpx; width: 154rpx; height: 118rpx;" src="@/static/image/temp-14.png" crossorigin=anonymous />
  53. <img class="img fg" style="top: 86rpx; left: 478rpx; width: 154rpx; height: 118rpx;" src="@/static/image/temp-20.png" crossorigin=anonymous />
  54. <img class="img fg" style="top: 244rpx; left: 138rpx; width: 226rpx; height: 154rpx;" src="@/static/image/temp-20.png" crossorigin=anonymous />
  55. <img class="img fg" style="top: 244rpx; left: 402rpx; width: 226rpx; height: 154rpx;" src="@/static/image/temp-14.png" crossorigin=anonymous />
  56. <img class="img fg" :src="configList.report_page_07" crossorigin=anonymous />
  57. </view>
  58. <!-- 08 -->
  59. <view class="export">
  60. <img class="img fg" style="top: 76rpx; left: 112rpx; width: 110rpx; height: 110rpx;" src="@/static/image/temp-20.png" crossorigin=anonymous />
  61. <img class="img fg" style="top: 194rpx; left: 112rpx; width: 110rpx; height: 110rpx;" src="@/static/image/temp-14.png" crossorigin=anonymous />
  62. <img class="img fg" style="top: 76rpx; left: 242rpx; width: 110rpx; height: 110rpx;" src="@/static/image/temp-14.png" crossorigin=anonymous />
  63. <img class="img fg" style="top: 194rpx; left: 242rpx; width: 110rpx; height: 110rpx;" src="@/static/image/temp-20.png" crossorigin=anonymous />
  64. <img class="img fg" style="top: 312rpx; left: 242rpx; width: 110rpx; height: 110rpx;" src="@/static/image/temp-14.png" crossorigin=anonymous />
  65. <img class="img fg" style="top: 138rpx; left: 372rpx; width: 110rpx; height: 110rpx;" src="@/static/image/temp-14.png" crossorigin=anonymous />
  66. <img class="img fg" style="top: 258rpx; left: 372rpx; width: 110rpx; height: 110rpx;" src="@/static/image/temp-20.png" crossorigin=anonymous />
  67. <img class="img fg" style="top: 194rpx; left: 504rpx; width: 110rpx; height: 110rpx;" src="@/static/image/temp-20.png" crossorigin=anonymous />
  68. <img class="img fg" style="top: 312rpx; left: 504rpx; width: 110rpx; height: 110rpx;" src="@/static/image/temp-14.png" crossorigin=anonymous />
  69. <img class="img fg" :src="configList.report_page_08" crossorigin=anonymous />
  70. </view>
  71. <!-- 09 -->
  72. <view class="export">
  73. <img class="img fg" style="top: 0; left: unset; right: 0; width: auto; height: 100%;" src="@/static/image/temp-20.png" crossorigin=anonymous />
  74. <img class="img fg" style="width: 260rpx; height: 180rpx;" src="@/static/image/temp-14.png" crossorigin=anonymous />
  75. <img class="img img-08 fg" :src="configList.report_page_09" crossorigin=anonymous />
  76. </view>
  77. <!-- 10 -->
  78. <view class="export">
  79. <img class="img fg" style="top: 126rpx; left: 106rpx; width: 158rpx; height: 106rpx;" src="@/static/image/temp-20.png" crossorigin=anonymous />
  80. <img class="img fg" style="top: 132rpx; left: 450rpx; width: 148rpx; height: 100rpx;" src="@/static/image/temp-20.png" crossorigin=anonymous />
  81. <img class="img fg" style="top: 132rpx; left: 604rpx; width: 90rpx; height: 100rpx;" src="@/static/image/temp-14.png" crossorigin=anonymous />
  82. <img class="img fg" style="top: 238rpx; left: 54rpx; width: 210rpx; height: 140rpx;" src="@/static/image/temp-14.png" crossorigin=anonymous />
  83. <img class="img fg" style="top: 242rpx; left: 450rpx; width: 122rpx; height: 80rpx;" src="@/static/image/temp-14.png" crossorigin=anonymous />
  84. <img class="img fg" style="top: 242rpx; left: 576rpx; width: 120rpx; height: 200rpx;" src="@/static/image/temp-20.png" crossorigin=anonymous />
  85. <img class="img fg" style="top: 326rpx; left: 270rpx; width: 156rpx; height: 106rpx;" src="@/static/image/temp-20.png" crossorigin=anonymous />
  86. <img class="img fg" style="top: 68rpx; left: 274rpx; width: 170rpx; height: 256rpx;" src="@/static/image/temp-20.png" crossorigin=anonymous />
  87. <img class="img fg" :src="configList.report_page_10" crossorigin=anonymous />
  88. </view>
  89. <!-- 11 -->
  90. <view class="export">
  91. <img class="img fg" style="top: unset; bottom: 268rpx; left: 54rpx; width: 118rpx; height: 80rpx;" src="@/static/image/temp-14.png" crossorigin=anonymous />
  92. <img class="img fg" style="top: unset; bottom: 268rpx; left: 180rpx; width: 78rpx; height: 110rpx;" src="@/static/image/temp-20.png" crossorigin=anonymous />
  93. <img class="img fg" style="top: unset; bottom: 268rpx; left: 262rpx; width: 210rpx; height: 160rpx;" src="@/static/image/temp-14.png" crossorigin=anonymous />
  94. <img class="img fg" style="top: 240rpx; left: 54rpx; width: 170rpx; height: 142rpx;" src="@/static/image/temp-20.png" crossorigin=anonymous />
  95. <img class="img fg" style="top: 240rpx; left: 380rpx; width: 118rpx; height: 80rpx;" src="@/static/image/temp-20.png" crossorigin=anonymous />
  96. <img class="img fg" :src="configList.report_page_11" crossorigin=anonymous />
  97. </view>
  98. <!-- 12 -->
  99. <view class="export">
  100. <img class="img fg" style="top: 130rpx; left: 122rpx; width: 80rpx; height: 100rpx;" src="@/static/image/temp-20.png" crossorigin=anonymous />
  101. <img class="img fg" style="top: 130rpx; left: 224rpx; width: 80rpx; height: 100rpx;" src="@/static/image/temp-14.png" crossorigin=anonymous />
  102. <img class="img fg" style="top: 130rpx; left: 328rpx; width: 80rpx; height: 100rpx;" src="@/static/image/temp-20.png" crossorigin=anonymous />
  103. <img class="img fg" style="top: 130rpx; left: 432rpx; width: 80rpx; height: 100rpx;" src="@/static/image/temp-14.png" crossorigin=anonymous />
  104. <img class="img fg" style="top: 130rpx; left: 536rpx; width: 80rpx; height: 100rpx;" src="@/static/image/temp-20.png" crossorigin=anonymous />
  105. <img class="img fg" style="top: 264rpx; left: 122rpx; width: 80rpx; height: 100rpx;" src="@/static/image/temp-14.png" crossorigin=anonymous />
  106. <img class="img fg" style="top: 264rpx; left: 224rpx; width: 80rpx; height: 100rpx;" src="@/static/image/temp-20.png" crossorigin=anonymous />
  107. <img class="img fg" style="top: 264rpx; left: 328rpx; width: 80rpx; height: 100rpx;" src="@/static/image/temp-14.png" crossorigin=anonymous />
  108. <img class="img fg" style="top: 264rpx; left: 432rpx; width: 80rpx; height: 100rpx;" src="@/static/image/temp-20.png" crossorigin=anonymous />
  109. <img class="img fg" style="top: 264rpx; left: 536rpx; width: 80rpx; height: 100rpx;" src="@/static/image/temp-14.png" crossorigin=anonymous />
  110. <img class="img fg" :src="configList.report_page_12" crossorigin=anonymous />
  111. </view>
  112. <!-- 13 -->
  113. <view class="export">
  114. <img class="img" :src="configList.report_page_13" crossorigin=anonymous />
  115. <div class="text text-12" style="top: 134rpx; left: 160rpx;">技能01</div>
  116. <div class="text text-12" style="top: 134rpx; left: 260rpx;">技能01描述</div>
  117. <div class="text text-12" style="top: 182rpx; left: 160rpx;">技能02</div>
  118. <div class="text text-12" style="top: 182rpx; left: 260rpx;">技能02描述</div>
  119. <div class="text text-12" style="top: 232rpx; left: 160rpx;">技能03</div>
  120. <div class="text text-12" style="top: 232rpx; left: 260rpx;">技能03描述</div>
  121. <div class="text text-12" style="top: 282rpx; left: 160rpx;">技能04</div>
  122. <div class="text text-12" style="top: 282rpx; left: 260rpx;">技能04描述</div>
  123. <div class="text text-12" style="top: 330rpx; left: 160rpx;">技能05</div>
  124. <div class="text text-12" style="top: 330rpx; left: 260rpx;">技能05描述</div>
  125. </view>
  126. <!-- 14 -->
  127. <view class="export">
  128. <img class="img fg" :src="configList.report_page_14" crossorigin=anonymous />
  129. <div class="text text-13" style="top: 150rpx; left: 116rpx;">同学寄语同学寄语同学寄语同学寄语同学寄语同学寄语同学寄语同学寄语</div>
  130. <div class="text text-13" style="top: 260rpx; left: 400rpx;">导师寄语导师寄语导师寄语导师寄语导师寄语导师寄语导师寄语导师寄语导师寄语</div>
  131. </view>
  132. <!-- 15 -->
  133. <view class="export">
  134. <img class="img fg" style="top: 46rpx; left: unset; right: 30rpx; width: 506rpx; height: 390rpx;" src="@/static/image/temp-20.png" crossorigin=anonymous />
  135. <img class="img fg" :src="configList.report_page_15" crossorigin=anonymous />
  136. </view>
  137. <!-- 00 -->
  138. <view class="export">
  139. <img class="img fg" :src="configList.report_page_00" crossorigin=anonymous />
  140. </view>
  141. </div>
  142. </div>
  143. <img v-if="current > 0" class="img turn left" src="@/static/image/icon-left.png" @click="prev" />
  144. <img v-if="current < 15" class="img turn right" src="@/static/image/icon-right.png" @click="next" />
  145. <div class="flex bottom">
  146. <div class="flex btns">
  147. <button class="btn" @click="createPdf">生成pdf</button>
  148. </div>
  149. </div>
  150. </div>
  151. </template>
  152. <script>
  153. import html2canvas from 'html2canvas'
  154. import { jsPDF } from "jspdf";
  155. export default {
  156. data() {
  157. return {
  158. id: null,
  159. details: {},
  160. current: 0,
  161. }
  162. },
  163. computed: {
  164. style() {
  165. return `transform: translateX(calc(-${this.current}*(100vw - 24rpx * 2)))`
  166. },
  167. },
  168. onLoad(arg) {
  169. document.addEventListener('UniAppJSBridgeReady', function() {
  170. console.log('UniAppJSBridgeReady', uni)
  171. uni.getEnv(function(res) {
  172. console.log('当前环境:' + JSON.stringify(res));
  173. });
  174. })
  175. const { id, token } = arg
  176. token && uni.setStorageSync('token', token)
  177. this.id = id
  178. },
  179. mounted() {
  180. this.getData(this.id)
  181. },
  182. methods: {
  183. getData(id) {
  184. // todo
  185. },
  186. prev() {
  187. this.current -= 1
  188. },
  189. next() {
  190. this.current += 1
  191. },
  192. createPdf() {
  193. uni.showLoading({
  194. title: '生成中...'
  195. })
  196. console.log('createPdf')
  197. const fillPage = () => {
  198. // 设置背景色
  199. PDF.setFillColor(251, 254, 255); // 例如,红色背景
  200. // 绘制一个填充的矩形覆盖整个页面
  201. PDF.rect(0, 0, PDF.internal.pageSize.getWidth(), PDF.internal.pageSize.getHeight(), 'F'); // 'F'表示填充
  202. }
  203. let PDF = new jsPDF('l', 'pt', 'a4')
  204. console.log('PDF', PDF)
  205. console.log('size', PDF.internal.pageSize.getWidth(), PDF.internal.pageSize.getHeight())
  206. const WIDTH = PDF.internal.pageSize.getWidth() // 841.89
  207. const HEIGHT = PDF.internal.pageSize.getHeight() // 595.28
  208. let request = []
  209. let nodeList = document.querySelectorAll('.export')
  210. for(let i = 0; i < nodeList.length; i++) {
  211. request.push(html2canvas(nodeList[i], { allowTaint: true, useCORS: true, }))
  212. }
  213. return Promise.allSettled(request).then(res => {
  214. console.log('res', res)
  215. fillPage()
  216. res.forEach((item, index) => {
  217. if (index > 0) {
  218. PDF.addPage()
  219. fillPage()
  220. }
  221. const canvas = item.value
  222. const contentWidth = canvas.width
  223. const contentHeight = canvas.height
  224. // let imgHeight = (WIDTH / contentWidth) * contentHeight // 根据a4纸比例,计算出图片的高度
  225. let pageData = canvas.toDataURL('image/jpeg', 1.0)
  226. PDF.addImage(pageData, 'JPEG', 0, 0, WIDTH, HEIGHT)
  227. return
  228. // 分页剩余高度
  229. let leftHeight = imgHeight
  230. // 分页偏移位置
  231. let position = 0
  232. // 如果图片高度大于a4纸高度,则需要分页
  233. if (imgHeight > HEIGHT) {
  234. while (leftHeight > 0) {
  235. // 第三个参数图片x轴位置,第四个参数图片y轴位置,第五个参数图片宽度,第六个参数图片高度
  236. PDF.addImage(pageData, 'JPEG', 0, position, WIDTH, imgHeight)
  237. leftHeight = leftHeight - HEIGHT
  238. position -= HEIGHT
  239. if (leftHeight > 0) {
  240. PDF.addPage()
  241. fillPage()
  242. }
  243. }
  244. } else {
  245. PDF.addImage(pageData, 'JPEG', 0, 0, WIDTH, imgHeight)
  246. // const marginY = (HEIGHT - imgHeight) / 2 // 计算出图片的上下边距
  247. // // 第三个参数图片x轴位置,第四个参数图片y轴位置,第五个参数图片宽度,第六个参数图片高度
  248. // PDF.addImage(pageData, 'JPEG', 0, marginY > 0 ? marginY : 0, a4Width, imgHeight)
  249. }
  250. })
  251. // #ifdef H5
  252. PDF.save('测试生成pdf' + '.pdf'); //h5在这就可以保存pdf
  253. // #endif
  254. return
  255. uni.postMessage({
  256. data: {
  257. imageData: PDF.output("datauristring"),
  258. }
  259. });
  260. // uni.navigateBack()
  261. uni.redirectTo({
  262. url: `/pages_order/thesis/createPdf?id=${this.id}`
  263. })
  264. }).catch(err => {
  265. console.log('err', err)
  266. }).finally(() => {
  267. uni.hideLoading()
  268. })
  269. },
  270. }
  271. }
  272. </script>
  273. <style lang="scss" scoped>
  274. $pages: 16;
  275. $w: calc(100vw - 24rpx * 2);
  276. $h: calc(#{$w} / 841.89 * 595.28);
  277. .page__view {
  278. width: 100vw;
  279. min-height: 100vh;
  280. background: #F7F8FA;
  281. position: relative;
  282. box-sizing: border-box;
  283. font-family: PingFang SC;
  284. font-weight: 400;
  285. line-height: 1.4;
  286. }
  287. .card {
  288. position: absolute;
  289. top: 50vh;
  290. transform: translateY(-50%);
  291. width: $w;
  292. margin: 0 24rpx;
  293. padding: 250rpx 0;
  294. overflow: hidden;
  295. background: #FFFFFF;
  296. }
  297. .report {
  298. width: calc(#{$pages}*#{$w});
  299. height: auto;
  300. overflow-x: visible;
  301. }
  302. .export {
  303. position: relative;
  304. display: inline-block;
  305. width: $w;
  306. min-height: $h;
  307. overflow: hidden;
  308. }
  309. .fg {
  310. position: absolute;
  311. top: 0;
  312. left: 0;
  313. }
  314. .img {
  315. display: block;
  316. width: $w;
  317. height: auto;
  318. &-08 {
  319. width: auto;
  320. height: $h;
  321. }
  322. }
  323. .text {
  324. position: absolute;
  325. font-size: 20rpx;
  326. font-weight: 600;
  327. color: #FFFFFF;
  328. &-12 {
  329. font-size: 14rpx;
  330. color: #000000;
  331. }
  332. &-13 {
  333. width: 206rpx;
  334. white-space: pre-wrap;
  335. font-size: 14rpx;
  336. color: #000000;
  337. }
  338. }
  339. // .export__view {
  340. // position: fixed;
  341. // top: 100vh;
  342. // }
  343. .turn {
  344. width: 80rpx;
  345. height: 80rpx;
  346. position: fixed;
  347. top: 50vh;
  348. transform: translateY(-50%);
  349. &.left {
  350. left: 0;
  351. }
  352. &.right {
  353. right: 0;
  354. }
  355. }
  356. .bottom {
  357. position: fixed;
  358. left: 0;
  359. bottom: 0;
  360. width: 100vw;
  361. height: 55px;
  362. padding: 0 25px;
  363. box-sizing: border-box;
  364. background: #FFFFFF;
  365. box-shadow: 0px 3px 6px 0px rgba(0,0,0,0.16);
  366. .btns {
  367. width: 100%;
  368. // justify-content: space-between;
  369. }
  370. .btn {
  371. padding: 10px 45px;
  372. font-size: 14px;
  373. color: #FFFFFF;
  374. background: #4883F9;
  375. border-radius: 21px;
  376. border: none;
  377. }
  378. }
  379. </style>