dataStatisticsReport.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655
  1. <!-- 毕业教育考试数据统计报告 -->
  2. <template>
  3. <view class="dataStatisticsReport-addPage" v-if="visible" @tap="onOverlayTap">
  4. <!-- 弹窗容器 -->
  5. <view class="report-wrap" @tap.stop="stopProp">
  6. <!-- 关闭按钮 -->
  7. <!-- <view class="close-btn" @tap="handleClose">✕</view> -->
  8. <scroll-view scroll-y class="report-scroll">
  9. <view class="report-wrap-big-box">
  10. <view class="report-wrap-min-box">
  11. <!-- logo -->
  12. <view class="logo-box">
  13. <image :src="logUrl" mode="widthFix" />
  14. </view>
  15. <!-- 标题 -->
  16. <text class="title-p">实验室安全教育成绩报告</text>
  17. <!-- 用户信息 -->
  18. <view class="user-box">
  19. <view class="user-min-box">
  20. <view>
  21. <text class="label">姓名:</text>
  22. <text>{{newData.userName}}</text>
  23. </view>
  24. <view>
  25. <text class="label">学号:</text>
  26. <text>{{newData.account}}</text>
  27. </view>
  28. </view>
  29. <view class="user-min-box">
  30. <view>
  31. <text class="label">学院:</text>
  32. <text>{{newData.deptName}}</text>
  33. </view>
  34. <view>
  35. <text class="label">年级:</text>
  36. <text>{{newData.grade}}</text>
  37. </view>
  38. </view>
  39. <view class="user-min-box">
  40. <view>
  41. <text class="label">用户类型:</text>
  42. <text>{{newData.educationTypeName}}</text>
  43. </view>
  44. </view>
  45. </view>
  46. <!-- 学年学时 -->
  47. <view class="study-hours-max-big-box" v-if="newData.studyHoursList && newData.studyHoursList[0]">
  48. <view class="study-hours-title-box">
  49. <view class="title-bar"></view>
  50. <text class="title-text">学年学时完成情况</text>
  51. </view>
  52. <view class="study-hours-text-title-box">
  53. <text>学年</text>
  54. <text>完成学时</text>
  55. <text>要求学时</text>
  56. </view>
  57. <view class="study-hours-for-box" v-for="(item, index) in newData.studyHoursList" :key="index">
  58. <text>{{item.academicYear}}</text>
  59. <text>{{item.completedStudyHours}}</text>
  60. <text>{{item.studyHoursRequirement}}</text>
  61. </view>
  62. <view class="study-hours-bottom-box">
  63. <text class="sum-label">累计</text>
  64. <text class="sum-value">{{newData.totalStudyHours}} 学时</text>
  65. </view>
  66. </view>
  67. <!-- 考试通过记录 -->
  68. <view class="study-hours-max-big-box-2" v-if="newData.examPassRecords && newData.examPassRecords[0]">
  69. <view class="study-hours-title-box">
  70. <view class="title-bar"></view>
  71. <text class="title-text">考试通过记录</text>
  72. </view>
  73. <view class="study-hours-text-title-box">
  74. <text>学年</text>
  75. <text>考试类型</text>
  76. <text>成绩</text>
  77. </view>
  78. <view class="study-hours-for-box" v-for="(item, index) in newData.examPassRecords" :key="index">
  79. <text>{{item.academicYear}}</text>
  80. <text>{{item.examTypeName}}</text>
  81. <text>{{item.score}}</text>
  82. </view>
  83. </view>
  84. <!-- 描述信息 -->
  85. <text class="study-text-p">  该同学在校期间认真完成实验室安全教育各项学习任务,累计完成 <text class="bold-text">{{newData.totalStudyHours}}</text> 学时安全培训,通过全部年度安全考核,具备良好的实验室安全意识和规范操作能力,特此证明。</text>
  86. <!-- 落款 -->
  87. <view class="signature-box">
  88. <text>{{newData.issuingUnit}}</text>
  89. <text>{{newData.issuingTime}}</text>
  90. </view>
  91. </view>
  92. </view>
  93. </scroll-view>
  94. <!-- 底部操作栏 -->
  95. <view class="action-bar">
  96. <view class="btn-close" @tap="handleClose">关闭</view>
  97. <view class="btn-save" @tap="saveAsImage">保存图片</view>
  98. </view>
  99. </view>
  100. <!-- 用于截图的离屏 canvas -->
  101. <canvas canvas-id="reportCanvas" class="report-canvas"></canvas>
  102. </view>
  103. </template>
  104. <script>
  105. export default {
  106. name: 'dataStatisticsReport',
  107. props: {
  108. visible: {
  109. type: Boolean,
  110. default: false
  111. },
  112. dataStatisticsReportPropsData: {
  113. type: Object,
  114. default: () => ({})
  115. }
  116. },
  117. data() {
  118. return {
  119. logUrl: uni.getStorageSync('rectangleLogo'),
  120. // logUrl: 'https://gzu.zjznai.com/statics/2026/06/17/00df3205-5321-4b46-aae3-0ffe4451ee51.png',
  121. newData: {
  122. userName: '',
  123. account: '',
  124. deptName: '',
  125. grade: '',
  126. educationTypeName: '',
  127. totalStudyHours: '',
  128. studyHoursList: [],
  129. examPassRecords: [],
  130. issuingUnit: '',
  131. issuingTime: '',
  132. },
  133. }
  134. },
  135. watch: {
  136. dataStatisticsReportPropsData: {
  137. immediate: true,
  138. handler(val) {
  139. if (val && Object.keys(val).length) {
  140. this.$set(this, 'newData', val);
  141. }
  142. }
  143. }
  144. },
  145. methods: {
  146. stopProp(e) {
  147. e.stopPropagation && e.stopPropagation();
  148. },
  149. handleClose() {
  150. this.$emit('close');
  151. },
  152. onOverlayTap() {
  153. this.$emit('close');
  154. },
  155. saveAsImage() {
  156. uni.showLoading({ title: '生成中...' });
  157. const d = this.newData;
  158. const W = 680;
  159. const lineH = 36;
  160. const pad = 48;
  161. const tableW = W - pad * 2;
  162. // 预估高度
  163. const studyRows = (d.studyHoursList || []).length;
  164. const examRows = (d.examPassRecords || []).length;
  165. const H = 120 + 100 + 60 + (studyRows > 0 ? 80 + studyRows * 32 + 32 : 0) + (examRows > 0 ? 80 + examRows * 32 : 0) + 120 + 160;
  166. const ctx = uni.createCanvasContext('reportCanvas', this);
  167. // 背景
  168. ctx.setFillStyle('#fffdf5');
  169. ctx.fillRect(0, 0, W, H);
  170. // 外边框
  171. ctx.setStrokeStyle('#c9a84c');
  172. ctx.setLineWidth(1);
  173. ctx.strokeRect(2, 2, W - 4, H - 4);
  174. ctx.strokeRect(6, 6, W - 12, H - 12);
  175. let y = 40;
  176. // logo 背景块
  177. ctx.setFillStyle('#77161B');
  178. ctx.fillRect(pad, y, 578, 88);
  179. y += 88 + 16;
  180. // 标题
  181. ctx.setFontSize(20);
  182. ctx.setFillStyle('#8b452f');
  183. ctx.setTextAlign('center');
  184. ctx.fillText('实验室安全教育成绩报告', W / 2, y + 20);
  185. y += 56;
  186. // 用户信息背景
  187. ctx.setFillStyle('#faf6ec');
  188. ctx.fillRect(pad, y, tableW, 80);
  189. ctx.setStrokeStyle('#e8dcc8');
  190. ctx.strokeRect(pad, y, tableW, 80);
  191. ctx.setFontSize(14);
  192. ctx.setFillStyle('#4a3c2a');
  193. ctx.setTextAlign('left');
  194. const col1 = pad + 12;
  195. const col2 = pad + tableW / 2 + 12;
  196. ctx.fillText('姓名:' + (d.userName || ''), col1, y + 22);
  197. ctx.fillText('学号:' + (d.account || ''), col2, y + 22);
  198. ctx.fillText('学院:' + (d.deptName || ''), col1, y + 46);
  199. ctx.fillText('年级:' + (d.grade || ''), col2, y + 46);
  200. ctx.fillText('用户类型:' + (d.educationTypeName || ''), col1, y + 70);
  201. y += 80 + 20;
  202. // 学年学时表
  203. if (studyRows > 0) {
  204. // 小标题
  205. ctx.setFillStyle('#c9a84c');
  206. ctx.fillRect(pad, y, 3, 20);
  207. ctx.setFontSize(14);
  208. ctx.setFillStyle('#8b4513');
  209. ctx.setTextAlign('left');
  210. ctx.fillText('学年学时完成情况', pad + 10, y + 16);
  211. y += 26;
  212. // 表头
  213. ctx.setFillStyle('#f5edd8');
  214. ctx.fillRect(pad, y, tableW, 34);
  215. ctx.setStrokeStyle('#d4c5a0');
  216. ctx.strokeRect(pad, y, tableW, 34);
  217. ctx.setFontSize(12);
  218. ctx.setFillStyle('#5a4320');
  219. ctx.setTextAlign('center');
  220. const cw = tableW / 3;
  221. ctx.fillText('学年', pad + cw * 0.5, y + 22);
  222. ctx.fillText('完成学时', pad + cw * 1.5, y + 22);
  223. ctx.fillText('要求学时', pad + cw * 2.5, y + 22);
  224. y += 34;
  225. // 数据行
  226. for (let i = 0; i < studyRows; i++) {
  227. const row = d.studyHoursList[i];
  228. ctx.setFillStyle(i % 2 === 0 ? '#fffdf5' : '#faf6ec');
  229. ctx.fillRect(pad, y, tableW, 32);
  230. ctx.setStrokeStyle('#ebe3d0');
  231. ctx.strokeRect(pad, y, tableW, 32);
  232. ctx.setFontSize(12);
  233. ctx.setFillStyle('#4a3c2a');
  234. ctx.setTextAlign('center');
  235. ctx.fillText(String(row.academicYear || ''), pad + cw * 0.5, y + 20);
  236. ctx.fillText(String(row.completedStudyHours || ''), pad + cw * 1.5, y + 20);
  237. ctx.fillText(String(row.studyHoursRequirement || ''), pad + cw * 2.5, y + 20);
  238. y += 32;
  239. }
  240. // 累计行
  241. ctx.setFillStyle('#faf6ec');
  242. ctx.fillRect(pad, y, tableW, 32);
  243. ctx.setStrokeStyle('#ebe3d0');
  244. ctx.strokeRect(pad, y, tableW, 32);
  245. ctx.setFontSize(12);
  246. ctx.setFillStyle('#4a3c2a');
  247. ctx.setTextAlign('center');
  248. ctx.fillText('累计', pad + cw * 0.5, y + 20);
  249. ctx.fillText((d.totalStudyHours || '') + ' 学时', pad + cw * 1.5, y + 20);
  250. y += 32 + 20;
  251. }
  252. // 考试通过记录表
  253. if (examRows > 0) {
  254. ctx.setFillStyle('#c9a84c');
  255. ctx.fillRect(pad, y, 3, 20);
  256. ctx.setFontSize(14);
  257. ctx.setFillStyle('#8b4513');
  258. ctx.setTextAlign('left');
  259. ctx.fillText('考试通过记录', pad + 10, y + 16);
  260. y += 26;
  261. ctx.setFillStyle('#f5edd8');
  262. ctx.fillRect(pad, y, tableW, 34);
  263. ctx.setStrokeStyle('#d4c5a0');
  264. ctx.strokeRect(pad, y, tableW, 34);
  265. ctx.setFontSize(12);
  266. ctx.setFillStyle('#5a4320');
  267. ctx.setTextAlign('center');
  268. const cw2 = tableW / 3;
  269. ctx.fillText('学年', pad + cw2 * 0.5, y + 22);
  270. ctx.fillText('考试类型', pad + cw2 * 1.5, y + 22);
  271. ctx.fillText('成绩', pad + cw2 * 2.5, y + 22);
  272. y += 34;
  273. for (let i = 0; i < examRows; i++) {
  274. const row = d.examPassRecords[i];
  275. ctx.setFillStyle(i % 2 === 0 ? '#fffdf5' : '#faf6ec');
  276. ctx.fillRect(pad, y, tableW, 32);
  277. ctx.setStrokeStyle('#ebe3d0');
  278. ctx.strokeRect(pad, y, tableW, 32);
  279. ctx.setFontSize(12);
  280. ctx.setFillStyle('#4a3c2a');
  281. ctx.setTextAlign('center');
  282. ctx.fillText(String(row.academicYear || ''), pad + cw2 * 0.5, y + 20);
  283. ctx.fillText(String(row.examTypeName || ''), pad + cw2 * 1.5, y + 20);
  284. ctx.fillText(String(row.score || ''), pad + cw2 * 2.5, y + 20);
  285. y += 32;
  286. }
  287. y += 20;
  288. }
  289. // 描述文字
  290. ctx.setFontSize(14);
  291. ctx.setFillStyle('#4a3c2a');
  292. ctx.setTextAlign('left');
  293. const desc = ` 该同学在校期间认真完成实验室安全教育各项学习任务,累计完成 ${d.totalStudyHours || ''} 学时安全培训,通过全部年度安全考核,具备良好的实验室安全意识和规范操作能力,特此证明。`;
  294. // 简单换行处理
  295. const maxWidth = tableW;
  296. const words = desc.split('');
  297. let line = '';
  298. for (let i = 0; i < words.length; i++) {
  299. const testLine = line + words[i];
  300. const metrics = ctx.measureText(testLine);
  301. if (metrics.width > maxWidth && line !== '') {
  302. ctx.fillText(line, pad, y);
  303. y += lineH;
  304. line = words[i];
  305. } else {
  306. line = testLine;
  307. }
  308. }
  309. if (line) { ctx.fillText(line, pad, y); y += lineH; }
  310. y += 40;
  311. // 落款
  312. ctx.setFontSize(14);
  313. ctx.setFillStyle('#4a3c2a');
  314. ctx.setTextAlign('right');
  315. ctx.fillText(d.issuingUnit || '', W - pad, y);
  316. y += 28;
  317. ctx.fillText(d.issuingTime || '', W - pad, y);
  318. ctx.draw(false, () => {
  319. wx.canvasToTempFilePath({
  320. canvasId: 'reportCanvas',
  321. x: 0,
  322. y: 0,
  323. width: W,
  324. height: H,
  325. destWidth: W * 2,
  326. destHeight: H * 2,
  327. fileType: 'jpg',
  328. quality: 1,
  329. success: (res) => {
  330. uni.hideLoading();
  331. uni.saveImageToPhotosAlbum({
  332. filePath: res.tempFilePath,
  333. success: () => {
  334. uni.showToast({ title: '已保存到相册', icon: 'success' });
  335. },
  336. fail: (err) => {
  337. if (err.errMsg && err.errMsg.indexOf('auth deny') !== -1) {
  338. uni.showModal({
  339. title: '需要授权',
  340. content: '请在设置中允许访问相册',
  341. showCancel: false,
  342. });
  343. } else {
  344. uni.showToast({ title: '保存失败,请重试', icon: 'none' });
  345. }
  346. }
  347. });
  348. },
  349. fail: () => {
  350. uni.hideLoading();
  351. uni.showToast({ title: '图片生成失败', icon: 'none' });
  352. }
  353. }, this);
  354. });
  355. },
  356. }
  357. }
  358. </script>
  359. <style scoped lang="scss">
  360. .dataStatisticsReport-addPage {
  361. position: fixed;
  362. top: 0;
  363. left: 0;
  364. right: 0;
  365. bottom: 0;
  366. z-index: 999;
  367. background: rgba(0, 0, 0, 0.5);
  368. display: flex;
  369. align-items: center;
  370. justify-content: center;
  371. .report-wrap {
  372. position: relative;
  373. width: 90%;
  374. max-height: 80vh;
  375. background: #fffdf5;
  376. border-radius: 8rpx;
  377. display: flex;
  378. flex-direction: column;
  379. .close-btn {
  380. position: absolute;
  381. top: 16rpx;
  382. right: 24rpx;
  383. z-index: 10;
  384. font-size: 36rpx;
  385. color: #8b452f;
  386. line-height: 1;
  387. padding: 8rpx;
  388. }
  389. .report-scroll {
  390. flex: 1;
  391. max-height: 80vh;
  392. }
  393. .report-wrap-big-box {
  394. margin: 20rpx;
  395. border: 1rpx solid #c9a84c;
  396. border-radius: 4rpx;
  397. background-color: #fffdf5;
  398. .report-wrap-min-box {
  399. display: flex;
  400. flex-direction: column;
  401. border: 1rpx solid #c9a84c;
  402. border-radius: 4rpx;
  403. margin: 1rpx;
  404. // logo
  405. .logo-box {
  406. width: 578rpx;
  407. height: 88rpx;
  408. border-radius: 6rpx;
  409. // background-color: #1a6e3a;
  410. background-color: #77161B;
  411. margin: 40rpx 0 0 24rpx;
  412. overflow: hidden;
  413. image {
  414. width: 350rpx;
  415. margin: 6rpx auto;
  416. display: block;
  417. }
  418. }
  419. // 标题
  420. .title-p {
  421. line-height: 56rpx;
  422. color: #8b452f;
  423. text-align: center;
  424. font-size: 20rpx;
  425. letter-spacing: 6rpx;
  426. display: block;
  427. }
  428. // 用户信息
  429. .user-box {
  430. width: 578rpx;
  431. background-color: #faf6ec;
  432. border: 1rpx solid #e8dcc8;
  433. margin: 9rpx 0 0 24rpx;
  434. border-radius: 4rpx;
  435. padding: 10rpx 20rpx;
  436. box-sizing: border-box;
  437. .user-min-box {
  438. display: flex;
  439. view {
  440. flex: 1;
  441. display: flex;
  442. .label {
  443. line-height: 26rpx;
  444. font-size: 14rpx;
  445. color: #4a3c2a;
  446. font-weight: 700;
  447. }
  448. text:not(.label) {
  449. line-height: 26rpx;
  450. font-size: 14rpx;
  451. color: #4a3c2a;
  452. }
  453. }
  454. }
  455. }
  456. // 学年学时列表
  457. .study-hours-max-big-box {
  458. margin: 20rpx 24rpx 0 24rpx;
  459. .study-hours-title-box {
  460. display: flex;
  461. align-items: center;
  462. .title-bar {
  463. height: 20rpx;
  464. width: 3rpx;
  465. background-color: #c9a84c;
  466. }
  467. .title-text {
  468. line-height: 20rpx;
  469. font-size: 12rpx;
  470. flex: 1;
  471. color: #8b4513;
  472. margin-left: 8rpx;
  473. font-weight: 700;
  474. }
  475. }
  476. .study-hours-text-title-box {
  477. display: flex;
  478. background-color: #f5edd8;
  479. border-bottom: 1rpx solid #d4c5a0;
  480. margin-top: 10rpx;
  481. text {
  482. line-height: 34rpx;
  483. font-size: 12rpx;
  484. color: #5a4320;
  485. flex: 1;
  486. text-align: center;
  487. font-weight: 700;
  488. }
  489. }
  490. .study-hours-for-box {
  491. display: flex;
  492. border-bottom: 1rpx solid #ebe3d0;
  493. text {
  494. line-height: 32rpx;
  495. font-size: 12rpx;
  496. color: #4a3c2a;
  497. flex: 1;
  498. text-align: center;
  499. }
  500. }
  501. .study-hours-bottom-box {
  502. display: flex;
  503. background-color: #faf6ec;
  504. border-bottom: 1rpx solid #ebe3d0;
  505. .sum-label {
  506. width: 216rpx;
  507. line-height: 32rpx;
  508. font-size: 12rpx;
  509. color: #4a3c2a;
  510. font-weight: 700;
  511. text-align: center;
  512. }
  513. .sum-value {
  514. flex: 1;
  515. line-height: 32rpx;
  516. font-size: 12rpx;
  517. color: #4a3c2a;
  518. font-weight: 700;
  519. text-align: center;
  520. }
  521. }
  522. }
  523. // 考试通过记录列表
  524. .study-hours-max-big-box-2 {
  525. margin: 20rpx 24rpx 0 24rpx;
  526. .study-hours-title-box {
  527. display: flex;
  528. align-items: center;
  529. .title-bar {
  530. height: 20rpx;
  531. width: 3rpx;
  532. background-color: #c9a84c;
  533. }
  534. .title-text {
  535. line-height: 20rpx;
  536. font-size: 12rpx;
  537. flex: 1;
  538. color: #8b4513;
  539. margin-left: 8rpx;
  540. font-weight: 700;
  541. }
  542. }
  543. .study-hours-text-title-box {
  544. display: flex;
  545. background-color: #f5edd8;
  546. border-bottom: 1rpx solid #d4c5a0;
  547. margin-top: 10rpx;
  548. text {
  549. line-height: 34rpx;
  550. font-size: 12rpx;
  551. color: #5a4320;
  552. flex: 1;
  553. text-align: center;
  554. font-weight: 700;
  555. }
  556. }
  557. .study-hours-for-box {
  558. display: flex;
  559. border-bottom: 1rpx solid #ebe3d0;
  560. text {
  561. line-height: 32rpx;
  562. font-size: 12rpx;
  563. color: #4a3c2a;
  564. flex: 1;
  565. text-align: center;
  566. }
  567. }
  568. }
  569. // 描述信息
  570. .study-text-p {
  571. margin: 25rpx 48rpx 0 48rpx;
  572. line-height: 24rpx;
  573. font-size: 14rpx;
  574. color: #4a3c2a;
  575. display: block;
  576. .bold-text {
  577. font-weight: 700;
  578. }
  579. }
  580. // 落款
  581. .signature-box {
  582. margin: 103rpx 180rpx 80rpx 48rpx;
  583. text {
  584. height: 24rpx;
  585. display: block;
  586. text-align: right;
  587. font-size: 14rpx;
  588. color: #4a3c2a;
  589. line-height: 24rpx;
  590. }
  591. }
  592. }
  593. }
  594. }
  595. }
  596. </style>