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

303 lines
8.0 KiB

2 months 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
2 months ago
3 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
3 days ago
2 months ago
3 days ago
2 months 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
2 months ago
3 days ago
3 days ago
3 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
  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="fg" style="display: block;" :src="configList.report_page_01" crossorigin=anonymous />
  8. </view>
  9. <!-- 02 -->
  10. <view class="export">
  11. <!-- <img class="fg" style="display: block;" :src="configList.report_page_02" crossorigin=anonymous /> -->
  12. <img class="fg" style="display: block; position: relative;" src="@/static/image/page-02.png" crossorigin=anonymous />
  13. <img style="display: block; position: absolute; top: 122rpx; left: 144rpx; width: 132rpx; height: 165rpx;" src="@/static/image/temp-14.png" crossorigin=anonymous />
  14. </view>
  15. <!-- 03 -->
  16. <view class="export">
  17. <img class="fg" style="display: block;" :src="configList.report_page_03" crossorigin=anonymous />
  18. </view>
  19. <!-- 04 -->
  20. <view class="export">
  21. <!-- <img class="fg" style="display: block;" :src="configList.report_page_04" crossorigin=anonymous /> -->
  22. <img class="fg" style="display: block;" src="@/static/image/page-04.png" crossorigin=anonymous />
  23. </view>
  24. <!-- 05 -->
  25. <view class="export">
  26. <!-- <img class="fg" style="display: block;" :src="configList.report_page_05" crossorigin=anonymous /> -->
  27. <img class="fg" style="display: block;" src="@/static/image/page-05.png" crossorigin=anonymous />
  28. </view>
  29. <!-- 06 -->
  30. <view class="export">
  31. <!-- <img class="fg" style="display: block;" :src="configList.report_page_06" crossorigin=anonymous /> -->
  32. <img class="fg" style="display: block;" src="@/static/image/page-06.png" crossorigin=anonymous />
  33. </view>
  34. <!-- 07 -->
  35. <view class="export">
  36. <img class="fg" style="display: block;" :src="configList.report_page_07" crossorigin=anonymous />
  37. </view>
  38. <!-- 08 -->
  39. <view class="export">
  40. <img class="fg fg-08" style="display: block;" :src="configList.report_page_08" crossorigin=anonymous />
  41. </view>
  42. <!-- 09 -->
  43. <view class="export">
  44. <img class="fg" style="display: block;" :src="configList.report_page_09" crossorigin=anonymous />
  45. </view>
  46. <!-- 10 -->
  47. <view class="export">
  48. <!-- <img class="fg" style="display: block;" :src="configList.report_page_10" crossorigin=anonymous /> -->
  49. <img class="fg" style="display: block;" src="@/static/image/page-10.png" crossorigin=anonymous />
  50. </view>
  51. <!-- 11 -->
  52. <view class="export">
  53. <img class="fg" style="display: block;" :src="configList.report_page_11" crossorigin=anonymous />
  54. </view>
  55. <!-- 12 -->
  56. <view class="export">
  57. <img class="fg" style="display: block;" :src="configList.report_page_12" crossorigin=anonymous />
  58. </view>
  59. <!-- 13 -->
  60. <view class="export">
  61. <!-- <img class="fg" style="display: block;" :src="configList.report_page_13" crossorigin=anonymous /> -->
  62. <img class="fg" style="display: block;" src="@/static/image/page-13.png" crossorigin=anonymous />
  63. </view>
  64. <!-- 14 -->
  65. <view class="export">
  66. <img class="fg" style="display: block;" :src="configList.report_page_14" crossorigin=anonymous />
  67. </view>
  68. </div>
  69. </div>
  70. <img v-if="current > 0" class="turn left" style="display: block;" src="@/static/image/icon-left.png" @click="prev" />
  71. <img v-if="current < 13" class="turn right" style="display: block;" src="@/static/image/icon-right.png" @click="next" />
  72. <div class="flex bottom">
  73. <button class="btn" @click="createPdf">生成pdf</button>
  74. </div>
  75. </div>
  76. </template>
  77. <script>
  78. import html2canvas from 'html2canvas'
  79. import { jsPDF } from "jspdf";
  80. export default {
  81. data() {
  82. return {
  83. id: null,
  84. details: {},
  85. current: 0,
  86. }
  87. },
  88. computed: {
  89. style() {
  90. return `transform: translateX(calc(-${this.current}*(100vw - 24rpx * 2)))`
  91. },
  92. },
  93. onLoad(arg) {
  94. document.addEventListener('UniAppJSBridgeReady', function() {
  95. console.log('UniAppJSBridgeReady', uni)
  96. uni.getEnv(function(res) {
  97. console.log('当前环境:' + JSON.stringify(res));
  98. });
  99. })
  100. const { id, token } = arg
  101. token && uni.setStorageSync('token', token)
  102. this.id = id
  103. },
  104. mounted() {
  105. this.getData(this.id)
  106. },
  107. methods: {
  108. getData(id) {
  109. // todo
  110. },
  111. prev() {
  112. this.current -= 1
  113. },
  114. next() {
  115. this.current += 1
  116. },
  117. createPdf() {
  118. uni.showLoading({
  119. title: '生成中...'
  120. })
  121. console.log('createPdf')
  122. const fillPage = () => {
  123. // 设置背景色
  124. PDF.setFillColor(251, 254, 255); // 例如,红色背景
  125. // 绘制一个填充的矩形覆盖整个页面
  126. PDF.rect(0, 0, PDF.internal.pageSize.getWidth(), PDF.internal.pageSize.getHeight(), 'F'); // 'F'表示填充
  127. }
  128. let PDF = new jsPDF('l', 'pt', 'a4')
  129. console.log('PDF', PDF)
  130. console.log('size', PDF.internal.pageSize.getWidth(), PDF.internal.pageSize.getHeight())
  131. const WIDTH = PDF.internal.pageSize.getWidth() // 841.89
  132. const HEIGHT = PDF.internal.pageSize.getHeight() // 595.28
  133. let request = []
  134. let nodeList = document.querySelectorAll('.export')
  135. for(let i = 0; i < nodeList.length; i++) {
  136. request.push(html2canvas(nodeList[i], { allowTaint: true, useCORS: true, }))
  137. }
  138. return Promise.allSettled(request).then(res => {
  139. console.log('res', res)
  140. fillPage()
  141. res.forEach((item, index) => {
  142. if (index > 0) {
  143. PDF.addPage()
  144. fillPage()
  145. }
  146. const canvas = item.value
  147. let pageData = canvas.toDataURL('image/jpeg', 1.0)
  148. PDF.addImage(pageData, 'JPEG', 0, 0, WIDTH, HEIGHT)
  149. })
  150. // #ifdef H5
  151. console.log('env: h5')
  152. PDF.save('测试生成pdf' + '.pdf'); //h5在这就可以保存pdf
  153. // #endif
  154. return
  155. uni.postMessage({
  156. data: {
  157. imageData: PDF.output("datauristring"),
  158. }
  159. });
  160. // uni.navigateBack()
  161. uni.redirectTo({
  162. url: `/pages_order/thesis/createPdf?id=${this.id}`
  163. })
  164. }).catch(err => {
  165. console.log('err', err)
  166. }).finally(() => {
  167. uni.hideLoading()
  168. })
  169. },
  170. }
  171. }
  172. </script>
  173. <style lang="scss" scoped>
  174. $pages: 14;
  175. $w: calc(100vw - 24rpx * 2);
  176. $h: calc(#{$w} / 841.89 * 595.28);
  177. .page__view {
  178. width: 100vw;
  179. min-height: 100vh;
  180. background: #F7F8FA;
  181. position: relative;
  182. // padding-top: 137rpx;
  183. box-sizing: border-box;
  184. font-family: PingFang SC;
  185. font-weight: 400;
  186. line-height: 1.4;
  187. }
  188. .card {
  189. position: absolute;
  190. top: 50vh;
  191. transform: translateY(-50%);
  192. width: $w;
  193. margin: 0 24rpx;
  194. padding: 250rpx 0;
  195. overflow: hidden;
  196. background: #FFFFFF;
  197. }
  198. .report {
  199. width: calc(#{$pages}*#{$w});
  200. height: auto;
  201. overflow-x: visible;
  202. }
  203. .export {
  204. position: relative;
  205. display: inline-block;
  206. width: $w;
  207. min-height: $h;
  208. }
  209. .fg {
  210. position: absolute;
  211. top: 0;
  212. left: 0;
  213. width: $w;
  214. height: auto;
  215. &-08 {
  216. width: auto;
  217. height: $h;
  218. }
  219. }
  220. // .export__view {
  221. // position: fixed;
  222. // top: 100vh;
  223. // }
  224. .turn {
  225. width: 80rpx;
  226. height: 80rpx;
  227. position: fixed;
  228. top: 50vh;
  229. transform: translateY(-50%);
  230. &.left {
  231. left: 0;
  232. }
  233. &.right {
  234. right: 0;
  235. }
  236. }
  237. .bottom {
  238. position: fixed;
  239. left: 0;
  240. bottom: 0;
  241. width: 100vw;
  242. background: #FFFFFF;
  243. box-sizing: border-box;
  244. padding: 32rpx 40rpx;
  245. padding-bottom: calc(env(safe-area-inset-bottom) + 32rpx);
  246. box-sizing: border-box;
  247. .btn {
  248. width: 100%;
  249. padding: 14rpx 0;
  250. font-family: PingFang SC;
  251. font-weight: 500;
  252. font-size: 36rpx;
  253. line-height: 1.4;
  254. color: #FFFFFF;
  255. background: linear-gradient(to right, #21FEEC, #019AF9);
  256. border: 2rpx solid #00A9FF;
  257. border-radius: 41rpx;
  258. }
  259. }
  260. </style>