pdf.vue 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713
  1. <template>
  2. <view class="page-wrappe">
  3. <cus-header title=' ' bgColor="transparent"></cus-header>
  4. <view id="pdfContainer" class="pdf-container" :style="{'transform':'scale('+scale+')', 'height': containerScaledHeight + 'px'}">
  5. <!-- 封面 -->
  6. <view class="cd_box fm2 adffc" style="margin-top: 20px;height: 868px;">
  7. <img class="fm2-logo" src="https://gitee.com/hw_0302/chuang-heng-wechat-images/raw/master/versionTwo/fm_logo.png">
  8. <img class="fm2-perill" src="https://gitee.com/hw_0302/chuang-heng-wechat-images/raw/master/versionTwo/fm_perill.png">
  9. <view class="fm2-line"></view>
  10. <view class="fm2-p">团队发展动态评估报告(基础版)</view>
  11. <view class="fm2-texts adf">
  12. <view class="fm2-texts-pre"><span style="letter-spacing: 6px;">客户公司:</span>{{ '甜梦(中国)巧克力有限公司' }}</view>
  13. <view class="fm2-texts-pre"><span style="letter-spacing: 6px;">团队名称:</span>{{ '团队结构类型:' }}</view>
  14. <view class="fm2-texts-pre"><span style="letter-spacing: 2.5px;">评估发起人:</span>{{ '团队职能类型:' }}</view>
  15. <view class="fm2-texts-pre"><span>报告生成时间:</span>{{ '2025-11-25' }}</view>
  16. </view>
  17. </view>
  18. <!-- 介绍 -->
  19. <view class="cd_box">
  20. <view class="v2-top adfacjb" :style="{'background-image':'url(https://gitee.com/hw_0302/chuang-heng-wechat-images/raw/master/versionTwo/intro_title_bg.png)'}">
  21. <view class="vt-left">介绍<span>PERILL模型简介</span></view>
  22. <view class="vt-right">团队发展动态评估报告(基础版)</view>
  23. </view>
  24. <view class="v2-box">
  25. <img class="vb-img1" :src="'https://gitee.com/hw_0302/chuang-heng-wechat-images/raw/master/versionTwo/'+'intro'+'_box_img1.png'">
  26. <img class="vb-img2" :src="'https://gitee.com/hw_0302/chuang-heng-wechat-images/raw/master/versionTwo/'+'intro'+'_box_img2.png'">
  27. <view class="v2-p">PERILL团队发展动态评估源于团队教练辅导领域的先驱、管理思维与团队绩效领域的权威、全球顶尖团队教练David Clutterbuck教授及其团队通过深入研究,提炼出影响团队绩效的140多个基于实证的因素,整合而成的团队诊断和提升工具-PERILL模型。</view>
  28. <view class="v2-p" style="margin-top: 8px;">创衡国际基于10多年来在全球与200多家具有前瞻性的国际公司以及国内具有行业代表性公司的合作经验,结合CCMI的PERILL评估工具,在中国推出的团队发展动态评估系统,旨在帮助团队更全面、更有效地从六个维度评估团队的发展现状,为支持团队成为高价值团队提供全景式的客观诊断。</view>
  29. <view class="v2-p" style="margin-top: 8px;">PERILL团队发展动态评估的主体内容由<span>36</span>个关于团队的描述组成。</view>
  30. </view>
  31. <view class="v2-six">
  32. <view class="vsix-title">PERILL六大纬度</view>
  33. <view class="vsix-p">PERILL诊断提供了一个复杂的团队系统概览,它并非针对孤立的问题,也不是简单的优缺点,而是着眼于团队系统的复杂性。它 通过6个影响因素(如下所述)提出问题,以揭示团队系统各要素之间的联系,以及这些联系如何影响团队的高效运作能力。</view>
  34. <view class="vsix-boxs">
  35. <view class="vsb adfac" v-for="(item,index) in sixWd" :key="index">
  36. <img class="vsb-img" :src="item.image"/>
  37. <view class="vsb-right">
  38. <view class="vsbr-top adfac">
  39. <view class="vsbrt-type" :style="{'background':item.color}">{{ item.type }}</view>
  40. <view class="vsbrt-title" :style="{'color':item.color}">{{ item.title }}</view>
  41. </view>
  42. <view class="vsbr-desc">{{ item.desc }}</view>
  43. </view>
  44. </view>
  45. </view>
  46. </view>
  47. </view>
  48. <!-- 总体诊断分析 -->
  49. <view class="cd_box adffc">
  50. <view class="v2-top adfacjb" :style="{'background-image':'url(https://gitee.com/hw_0302/chuang-heng-wechat-images/raw/master/versionTwo/'+'intro'+'_top_title_bg2.png)'}">
  51. <view class="vt-left">总体诊断分析</view>
  52. <view class="vt-right">团队发展动态评估报告(基础版)</view>
  53. </view>
  54. <view class="v2-box" @click="downloadZtzdfxImg">
  55. <img class="vb-img1" :src="'https://gitee.com/hw_0302/chuang-heng-wechat-images/raw/master/versionTwo/'+'intro'+'_box_img1.png'">
  56. <img class="vb-img2" :src="'https://gitee.com/hw_0302/chuang-heng-wechat-images/raw/master/versionTwo/'+'intro'+'_box_img2.png'">
  57. <view class="v2-p2">报告的核心是PERILL诊断分析下的整体团队表现。这包括团队在PERILL模型每个关键要素上的综合得分,通过结合得分和置信指数,我们能够展示出高功能领域和低功能域。</view>
  58. <view class="v2-p2" style="margin-top: 16px;">下面的条形图上的位置标记显示了团队在各个支柱上的总分。</view>
  59. <view style="width:100%;height:200px;" class="pdfEchart">
  60. <l-echart ref="ztzdfxRef" :canvas2d="true" @finished="initZtzdfxChart"></l-echart>
  61. </view>
  62. </view>
  63. <view class="v2-data">
  64. <view class="vd-title" :style="{'background-image':'url(https://gitee.com/hw_0302/chuang-heng-wechat-images/raw/master/versionTwo/'+'intro'+'_title_bg1.png)'}">诊断结果</view>
  65. <view class="v2-p" v-html="'后端返回数据后端返回数据 后端返回数据 '"></view>
  66. </view>
  67. <view class="v2-data" style="flex: 1;margin-top: 20px;">
  68. <view class="vd-title vt2" :style="{'background-image':'url(https://gitee.com/hw_0302/chuang-heng-wechat-images/raw/master/versionTwo/'+'intro'+'_title_bg2.png)'}">团队提升&教练建议</view>
  69. <view class="v2-p" v-html="'后端返回数据后端返回数据 后端返回数据 '"></view>
  70. </view>
  71. </view>
  72. <!-- 多维度 -->
  73. <canvas type="2d" canvas-id="score-canvas" id="score-canvas" class="offscreen-canvas"></canvas>
  74. <template v-if="reportData&&reportData.dimensionAnalysis&&reportData.dimensionAnalysis.length">
  75. <view class="cd_box adffc" style="border: none;" v-for="(item,index) in reportData.dimensionAnalysis" :key="index">
  76. <view class="v2-top adfacjb" :style="{'background-image':'url('+'https://gitee.com/hw_0302/chuang-heng-wechat-images/raw/master/versionTwo/'+typeDict[item.title]+'_title_bg.png)'}">
  77. <view class="vt-left" :class="{'black':item.title==='目的与动机'}">{{ item.title }}</view>
  78. <view class="vt-right">团队发展动态评估报告(基础版)</view>
  79. </view>
  80. <view class="v2-box" :style="{'border':'1px solid '+item.bcolor}">
  81. <img class="vb-img1" :src="'https://gitee.com/hw_0302/chuang-heng-wechat-images/raw/master/versionTwo/'+typeDict[item.title]+'_box_img1.png'">
  82. <img class="vb-img2" :src="'https://gitee.com/hw_0302/chuang-heng-wechat-images/raw/master/versionTwo/'+typeDict[item.title]+'_box_img2.png'">
  83. <view class="v2-p2">{{ item.desc }}</view>
  84. <view class="v2-p2" style="margin-top: 16px;">评分总体分布</view>
  85. <view class="vb-table" :style="{'border':'1px solid '+item.bcolor}">
  86. <!-- 将 v-for="i in 5" 修改为遍历真实的 scoreData -->
  87. <view class="vbt-pre adfac" v-for="(scoreItem, scoreIndex) in scoreData" :key="scoreIndex">
  88. <view class="vbtp-left adfacjc" :class="{'black':item.title==='目的与动机'}" :style="{'background':item.titlecolor}">{{ scoreItem.title }}</view>
  89. <view class="vbtp-right" :style="{'border':'1px solid '+item.bcolor}">
  90. <view class="vbtpr-title">{{ scoreItem.desc }}</view>
  91. <view class="vbtpr-jd">
  92. <!-- 分数和宽度动态化 -->
  93. <view class="vj_num" :style="{'width':(scoreItem.score/5*100)+'%','background':item.pfztfb}"></view>
  94. <view class="vj-val" :style="{'border':'1px solid '+item.bcolor,'left':'calc('+(scoreItem.score/5*100)+'% - 12px)','box-shadow':'0px 2px 6px 0px '+item.bcolor}">{{ scoreItem.score }}</view>
  95. </view>
  96. </view>
  97. </view>
  98. </view>
  99. </view>
  100. <view class="v2-data" :style="{'border':'1px solid '+item.bcolor}">
  101. <view class="vd-title vt3" :class="{'black':item.title==='目的与动机'}" :style="{'background-image':'url(https://gitee.com/hw_0302/chuang-heng-wechat-images/raw/master/versionTwo/'+typeDict[item.title]+'_title_bg1.png)'}">诊断结果</view>
  102. <view class="v2-p3">纬度得分</view>
  103. <view class="vd-wd adfac" :style="{'background':item.wddf}">
  104. <view class="vdwd-pre">维度加权总分:<span>{{ 34 }}</span></view>
  105. <view class="vdwd-pre vp">维度同意度总分(未加权):<span>{{ 34 }}</span></view>
  106. <view class="vdwd-pre">维度权重:<span>{{ 34 }}</span></view>
  107. </view>
  108. <view class="v2-p3" style="margin-top: 16px;">团队维度诊断结果</view>
  109. <view class="v2-p" style="margin-top: 8px;" v-html="'后端返回数据 后端返回数据 后端返回数据 后端返回数据 后端返回数据 后端返回数据 '"></view>
  110. </view>
  111. <view class="v2-data" :style="{'border':'1px solid '+item.bcolor}" style="flex: 1;margin-top: 15px;">
  112. <view class="vd-title vt3" :class="{'black':item.title==='目的与动机'}" :style="{'background-image':'url(https://gitee.com/hw_0302/chuang-heng-wechat-images/raw/master/versionTwo/'+typeDict[item.title]+'_title_bg1.png)'}">诊断建议</view>
  113. <view class="v2-p" v-html="'后端返回数据 后端返回数据 后端返回数据 后端返回数据 后端返回数据 后端返回数据 '"></view>
  114. </view>
  115. </view>
  116. </template>
  117. </view>
  118. <view class="pdf_btn" @click="createPdf">生成PDF</view>
  119. </view>
  120. </template>
  121. <script name="">
  122. import { BaseApi } from '@/http/baseApi.js';
  123. import * as echarts from '@/pagesHome/components/lime-echart/static/echarts.min.js'
  124. import lEchart from '@/pagesHome/components/lime-echart/components/l-echart/l-echart.vue'
  125. export default {
  126. name: 'ZtzdfxChart',
  127. // props: {
  128. // reportData: {
  129. // type: Object,
  130. // default: null
  131. // }
  132. // },
  133. components:{ lEchart },
  134. data() {
  135. return {
  136. scoreData: [
  137. {
  138. title: "宗旨共融,同心共识",
  139. desc: "团队成员能够共同阐述其共享目的,并且在团队使命上保持高度一致。",
  140. score: 4
  141. },
  142. {
  143. title: "价值引领,行践合一",
  144. desc: "团队经常根据其愿景、使命、目的和价值观来评估它们所做的事情及自身的行为。",
  145. score: 3
  146. },
  147. {
  148. title: "使命驱动,热忱贡献",
  149. desc: "团队对它们为实现宗旨和愿景所面临的挑战与目标充满热情,并相信它们的工作为世界带来积极的贡献。",
  150. score: 4.8
  151. },
  152. {
  153. title: "团队优先,人尽其才",
  154. desc: "团队成员(包括领导者)将团队优先事项置于个人优先事务之上,并在分配工作任务时充分发挥每个人的优势。",
  155. score: 2
  156. },
  157. {
  158. title: "审时度势,与时俱进",
  159. desc: "团队定期(每隔数月)审视目标与优先事项,以确保它们能够适应外部环境的变化。",
  160. score: 3
  161. },
  162. {
  163. title: "快乐工作,具成就感",
  164. desc: "团队成员(包括领导者)对所做的工作以及与同事共事感到快乐并从中获得成就感。",
  165. score: 4
  166. }
  167. ],
  168. reportData: null,
  169. isChartReady: false,
  170. scale:1,
  171. originalContainerHeight: 0,
  172. containerScaledHeight: 'auto',
  173. typeDict: {
  174. '目的与动机': 'zzdj',
  175. '外部流程及系统与架构': 'wbjg',
  176. '人际关系': 'rjgx',
  177. '内部流程及系统与架构': 'nbjg',
  178. '学习': 'xx',
  179. '领导力': 'ldl'
  180. },
  181. sixWd: [
  182. {
  183. image: 'https://gitee.com/hw_0302/chuang-heng-wechat-images/raw/master/versionTwo/intro_img_p.png',
  184. type: 'P',
  185. title: '宗旨与动机',
  186. desc: '指团队共享的目的和存在的意义, 包含对共同的愿景,目标和优先级的清晰度。',
  187. color: '#833479'
  188. },
  189. {
  190. image: 'https://gitee.com/hw_0302/chuang-heng-wechat-images/raw/master/versionTwo/intro_img_e.png',
  191. type: 'E',
  192. title: '外部流程、系统与结构',
  193. desc: '指团队与其外部利益相关者 - 客户,供应商,股东,组织内的其他团队等的互动关联。',
  194. color: '#199C9C'
  195. },
  196. {
  197. image: 'https://gitee.com/hw_0302/chuang-heng-wechat-images/raw/master/versionTwo/intro_img_r.png',
  198. type: 'R',
  199. title: '人际关系',
  200. desc: '指团队成员如何共同工作–他们是否相互尊重对方的能力,足够心理安全以能够坦诚相对,真正关心彼此的幸福感。',
  201. color: '#FEDA60'
  202. },
  203. {
  204. image: 'https://gitee.com/hw_0302/chuang-heng-wechat-images/raw/master/versionTwo/intro_img_i.png',
  205. type: 'I',
  206. title: '内部流程、系统与结构',
  207. desc: '指团队如何管理工作流程,互相支持和高质量的沟通和决策(包括工作任务和团队感情)。',
  208. color: '#7AABED'
  209. },
  210. {
  211. image: 'https://gitee.com/hw_0302/chuang-heng-wechat-images/raw/master/versionTwo/intro_img_l.png',
  212. type: 'L',
  213. title: '学习',
  214. desc: '指团队应对多变的环境和保持持续的进步和成长的能力。团队如何提高绩效(如何完成今天的任务)、能力(如何提高技能和资源以处理明天的任务)和容量(长期的愿景, 如何用更少的资源做更多的事情)',
  215. color: '#8093A3'
  216. },
  217. {
  218. image: 'https://gitee.com/hw_0302/chuang-heng-wechat-images/raw/master/versionTwo/intro_img_l2.png',
  219. type: 'L',
  220. title: '领导力',
  221. desc: '指团队认为需要怎样的领导行为能够让他们,作为个人或者团队做到最好。团队可以和他们的领导者讨论他们的责任,以帮助领导者成为他们需要的领导者。',
  222. color: '#0096D8'
  223. }
  224. ],
  225. pdfImages:[],
  226. };
  227. },
  228. mounted() {
  229. // reportData.value = props.reportData;
  230. this.reportData = {
  231. dimensionAnalysis: [
  232. {title:'目的与动机',bcolor:'#FFE796',titlecolor:'#FFE796',wddf:'linear-gradient( 90deg, rgba(255,215,80,0.34) 0%, rgba(251,225,130,0.09) 100%)',
  233. pfztfb:'linear-gradient( 90deg, #FEDA60 0%, #FBE182 100%)',
  234. desc:`「宗旨与动机」维度,我们旨在探究是否存在一个清晰的存在理由和明确的方向,能够激发团队成员的动力并吸引他们的想象力,以及个人与集体的身份认同是否围绕共同的目标,并达成一致。`},
  235. {title:'外部流程及系统与架构',bcolor:'#E4D2E1',titlecolor:'#BA8EB4',wddf:'linear-gradient( 90deg, #F5EFF5 0%, #FAF2F9 100%)',
  236. pfztfb:'linear-gradient( 90deg, #833479 0%, #9F6196 100%)',
  237. desc:`「外部流程、系统与结构」维度,我们旨在探究团队如何与各种利益相关者互动,他们与团队的利益相关方各自如何寻求了解对方,以及现有系统和流程的有效性,以帮助管理不同的期望和需求。`},
  238. {title:'人际关系',bcolor:'#B3DEDE',titlecolor:'#66BDBD',wddf:'linear-gradient( 90deg, #E8F5F5 0%, #F0F8F8 100%)',
  239. pfztfb:'linear-gradient( 90deg, #189B9B 0%, #64BBBB 100%)',
  240. desc:`「人际关系」维度,我们旨在探究团队成员如何相互交流、信任程度、尊重和关心的程度,以及团队成员之间的关系如何促进(或破坏)协作。`},
  241. {title:'内部流程及系统与架构',bcolor:'#C7DCF8',titlecolor:'#95BDF1',wddf:'linear-gradient( 90deg, #E3ECF8 0%, #F2F5F9 100%)',
  242. pfztfb:'linear-gradient( 90deg, #7AABED 0%, #AFCDF5 100%)',
  243. desc:`「内部流程、系统与结构」维度,我们旨在探究团队如何在平衡责任与自主权方面进行协作。我们关注团队的敏捷程度、沟通方式以及决策过程的有效性。`},
  244. {title:'学习',bcolor:'#E6EAED',titlecolor:'#8093A3',wddf:'linear-gradient( 90deg, #EDF0F2 0%, #F2F4F6 100%)',
  245. pfztfb:'linear-gradient( 90deg, #4D697E 0%, #8093A3 100%)',
  246. desc:`「学习」维度,我们旨在探究团队如何提高其绩效、技能和资源以应对当前和未来的任务。我们还希望了解团队如何管理能力和提高效率。`},
  247. {title:'领导力',bcolor:'#D4EDF8',titlecolor:'#3BB6D9',wddf:'linear-gradient( 90deg, #E6F5FB 0%, #F3FCFB 100%)',
  248. pfztfb:'linear-gradient( 90deg, #0096D8 0%, #5CC9DA 100%)',
  249. desc:`「领导力」维度,我们旨在探究领导素质和行为如何对团队功能和其他因素产生调节影响,以及这是积极的还是消极的。`}
  250. ]
  251. };
  252. this.calculateScaleAndPosition();
  253. uni.onWindowResize(() => {
  254. this.calculateScaleAndPosition();
  255. });
  256. },
  257. methods: {
  258. // async createPdf(){
  259. // uni.showLoading({
  260. // title:'正在生成PDF所需的图片...'
  261. // })
  262. // const imgUrl = await this.downloadZtzdfxImg();
  263. // this.pdfImages.push(imgUrl);
  264. // for(const d of this.reportData.dimensionAnalysis){
  265. // const fileurl = await this.generateScoreImage(d);
  266. // this.pdfImages.push(fileurl)
  267. // }
  268. // this.$showToast(`生成成功,共计${this.pdfImages.length}张`);
  269. // uni.hideLoading();
  270. // console.log(this.pdfImages);
  271. // },
  272. // Promise.all方法,性能更高
  273. async createPdf(){
  274. uni.showLoading({
  275. title:'正在生成PDF所需的图片...'
  276. })
  277. try {
  278. const ztzdfxImgPromise = this.downloadZtzdfxImg();
  279. const dimensionImagePromises = this.reportData.dimensionAnalysis.map(d => {
  280. return this.generateScoreImage(d);
  281. });
  282. const allImageUrls = await Promise.all([
  283. ztzdfxImgPromise,
  284. ...dimensionImagePromises
  285. ]);
  286. this.pdfImages = allImageUrls;
  287. uni.hideLoading();
  288. this.$showToast(`生成成功,共计${this.pdfImages.length}张`);
  289. console.log(this.pdfImages);
  290. } catch (error) {
  291. uni.hideLoading();
  292. console.error('生成图片过程中发生错误:', error);
  293. uni.showToast({ title: '生成图片失败,请重试', icon: 'none' });
  294. }
  295. },
  296. // 绘制主函数
  297. async generateScoreImage(dimensionData) {
  298. return new Promise(resolve=>{
  299. console.log('开始生成图片...');
  300. // --- 1. 定义尺寸和样式 ---
  301. const canvasWidth = 588; // .v2-box 的宽度大约是 630 - 20*2(padding) - 1*2(border) = 588
  302. const itemHeight = 49; // 每个评估项的高度
  303. const totalHeight = itemHeight * this.scoreData.length;
  304. // 调整为整数,避免边框模糊
  305. const canvasHeight = totalHeight;
  306. // --- 2. 获取 Canvas 节点 ---
  307. // 使用 ID 选择器更精确
  308. const query = uni.createSelectorQuery().in(this);
  309. query.select('#score-canvas')
  310. .fields({ node: true, size: true })
  311. .exec(async (res) => {
  312. // 【重要】增加健壮性检查
  313. if (!res || !res[0] || !res[0].node) {
  314. console.error('获取 Canvas 节点失败,请检查 canvas-id 和 type="2d" 是否正确设置。');
  315. uni.showToast({ title: '组件初始化失败', icon: 'none' });
  316. return;
  317. }
  318. const canvasNode = res[0].node;
  319. const context = canvasNode.getContext('2d');
  320. const dpr = uni.getSystemInfoSync().pixelRatio;
  321. // --- 3. 设置画布尺寸和缩放以适应高分屏 ---
  322. canvasNode.width = canvasWidth * dpr;
  323. canvasNode.height = canvasHeight * dpr;
  324. context.scale(dpr, dpr);
  325. // --- 4. 开始绘制 ---
  326. // 绘制大背景
  327. context.fillStyle = '#FFFFFF';
  328. context.fillRect(0, 0, canvasWidth, canvasHeight);
  329. // --- 5. 循环绘制每一项 ---
  330. for (let i = 0; i < this.scoreData.length; i++) {
  331. const item = this.scoreData[i];
  332. const yPos = i * itemHeight;
  333. // 注意:这里不再需要 await,因为 canvas 2d 绘图是同步的
  334. this.drawScoreItem(context, item, yPos, canvasWidth, itemHeight, dimensionData);
  335. }
  336. // 【补充】绘制最外层的上下边框,避免被循环内的矩形覆盖
  337. context.strokeStyle = dimensionData.bcolor;
  338. context.lineWidth = 1;
  339. context.strokeRect(0, 0, canvasWidth, canvasHeight);
  340. // --- 6. 生成图片 ---
  341. uni.hideLoading();
  342. uni.canvasToTempFilePath({
  343. canvas: canvasNode,
  344. x: 0,
  345. y: 0,
  346. width: canvasWidth,
  347. height: canvasHeight,
  348. destWidth: canvasWidth * dpr,
  349. destHeight: canvasHeight * dpr,
  350. success: async (result) => {
  351. console.log('图片生成成功!', result.tempFilePath);
  352. const fileurl = await this.uploadFilePromise(result.tempFilePath);
  353. console.log(fileurl, 'fileurl');
  354. resolve(fileurl)
  355. },
  356. fail: (err) => {
  357. console.error('图片生成失败', err);
  358. uni.showToast({ title: '图片生成失败', icon: 'none' });
  359. }
  360. }, this);
  361. });
  362. })
  363. },
  364. // 辅助函数:计算自动换行文字的总高度
  365. calculateWrappedTextHeight(ctx, text, lineHeight, maxWidth) {
  366. let words = text.split('');
  367. let line = '';
  368. let height = lineHeight; // 至少有一行
  369. for (let n = 0; n < words.length; n++) {
  370. let testLine = line + words[n];
  371. let metrics = ctx.measureText(testLine);
  372. let testWidth = metrics.width;
  373. if (testWidth > maxWidth && n > 0) {
  374. line = words[n];
  375. height += lineHeight;
  376. } else {
  377. line = testLine;
  378. }
  379. }
  380. return height;
  381. },
  382. // 辅助函数:绘制单个评估项
  383. drawScoreItem(ctx, scoreItem, y, width, height, dimensionData) {
  384. const leftBoxWidth = 110;
  385. const rightBoxX = leftBoxWidth;
  386. const rightBoxWidth = width - leftBoxWidth;
  387. const rightPadding = 10; // 右侧内容的通用内边距
  388. // 1. --- 绘制左侧部分 ---
  389. ctx.fillStyle = dimensionData.titlecolor;
  390. ctx.fillRect(0, y, leftBoxWidth, height);
  391. // 绘制白色下边框
  392. if (y + height < ctx.canvas.height / (uni.getSystemInfoSync().pixelRatio)) {
  393. ctx.strokeStyle = '#FFFFFF';
  394. ctx.lineWidth = 1;
  395. ctx.beginPath();
  396. ctx.moveTo(0, y + height - 1);
  397. ctx.lineTo(leftBoxWidth, y + height - 1);
  398. ctx.stroke();
  399. }
  400. // 绘制左侧标题文字 (要求 1)
  401. ctx.fillStyle = '#002846';
  402. ctx.font = '10px sans-serif';
  403. ctx.textAlign = 'center';
  404. ctx.textBaseline = 'middle';
  405. this.drawWrappedText(ctx, scoreItem.title, leftBoxWidth / 2, y + height / 2, 20, leftBoxWidth - 20); // 左右留10px边距
  406. // 2. --- 绘制右侧部分 ---
  407. // 绘制右侧外边框
  408. ctx.strokeStyle = dimensionData.bcolor;
  409. ctx.lineWidth = 1;
  410. ctx.strokeRect(rightBoxX, y, rightBoxWidth, height);
  411. // --- 计算右侧内容垂直居中需要的参数 (要求 2) ---
  412. const descLineHeight = 16;
  413. const descMaxWidth = rightBoxWidth - rightPadding * 2;
  414. ctx.font = '9px sans-serif'; // 设置好字体用于计算
  415. const descHeight = this.calculateWrappedTextHeight(ctx, scoreItem.desc, descLineHeight, descMaxWidth);
  416. const spacing = 7; // 文字与进度条间距 (要求 4)
  417. const progressBarHeight = 6; // 进度条高度 (要求 3)
  418. // 计算右侧所有内容的总高度
  419. const totalContentHeight = descHeight + spacing + progressBarHeight;
  420. // 计算内容块的起始 Y 坐标,使其在右侧框内垂直居中
  421. const contentStartY = y + (height - totalContentHeight) / 2;
  422. // --- 开始绘制右侧内容 ---
  423. // 绘制右侧描述文字 (要求 2)
  424. ctx.fillStyle = '#193D59';
  425. ctx.font = '9px sans-serif';
  426. ctx.textAlign = 'left';
  427. ctx.textBaseline = 'top'; // 基线设为 top 方便计算
  428. this.drawWrappedText(ctx, scoreItem.desc, rightBoxX + rightPadding, contentStartY, descLineHeight, descMaxWidth);
  429. // 绘制进度条 (要求 3)
  430. const progressBarY = contentStartY + descHeight + spacing;
  431. const progressBarWidth = rightBoxWidth - rightPadding * 2;
  432. const scoreWidth = (scoreItem.score / 5) * progressBarWidth;
  433. const barRadius = 3;
  434. // 绘制灰色背景
  435. ctx.fillStyle = '#F0F2F8';
  436. ctx.beginPath();
  437. ctx.moveTo(rightBoxX + rightPadding + barRadius, progressBarY);
  438. ctx.arcTo(rightBoxX + rightPadding + progressBarWidth, progressBarY, rightBoxX + rightPadding + progressBarWidth, progressBarY + progressBarHeight, barRadius);
  439. ctx.arcTo(rightBoxX + rightPadding + progressBarWidth, progressBarY + progressBarHeight, rightBoxX + rightPadding, progressBarY + progressBarHeight, barRadius);
  440. ctx.arcTo(rightBoxX + rightPadding, progressBarY + progressBarHeight, rightBoxX + rightPadding, progressBarY, barRadius);
  441. ctx.arcTo(rightBoxX + rightPadding, progressBarY, rightBoxX + rightPadding + progressBarWidth, progressBarY, barRadius);
  442. ctx.closePath();
  443. ctx.fill();
  444. // 绘制实际得分的渐变色进度条
  445. const gradient = ctx.createLinearGradient(rightBoxX + rightPadding, 0, rightBoxX + rightPadding + progressBarWidth, 0);
  446. const gradientColors = this.parseGradient(dimensionData.pfztfb);
  447. gradientColors.forEach(c => gradient.addColorStop(c.stop, c.color));
  448. ctx.fillStyle = gradient;
  449. ctx.save();
  450. ctx.clip(); // 使用上面的圆角矩形路径进行裁剪
  451. ctx.fillRect(rightBoxX + rightPadding, progressBarY, scoreWidth, progressBarHeight);
  452. ctx.restore();
  453. // 绘制分数框 (要求 4)
  454. const scoreFontSize = 12;
  455. const scorePaddingY = 4; // 上下内边距
  456. const scorePaddingX = 7; // 左右内边距
  457. const scoreBoxRadius = 4;
  458. ctx.font = `bold ${scoreFontSize}px sans-serif`;
  459. const scoreTextMetrics = ctx.measureText(scoreItem.score);
  460. const scoreBoxWidth = scoreTextMetrics.width + scorePaddingX * 2;
  461. const scoreBoxHeight = scoreFontSize + scorePaddingY * 2;
  462. // 计算分数框的位置,使其右端对齐在进度条的末端
  463. const scoreBoxX = rightBoxX + rightPadding + scoreWidth - scoreBoxWidth;
  464. // 垂直居中于进度条
  465. const scoreBoxY = progressBarY + (progressBarHeight / 2) - (scoreBoxHeight / 2);
  466. // 绘制阴影
  467. ctx.save();
  468. ctx.shadowColor = dimensionData.bcolor;
  469. ctx.shadowBlur = 6;
  470. ctx.shadowOffsetX = 0;
  471. ctx.shadowOffsetY = 2;
  472. // 绘制分数框背景和边框
  473. ctx.fillStyle = '#FFFFFF';
  474. ctx.strokeStyle = dimensionData.bcolor;
  475. ctx.lineWidth = 1;
  476. ctx.beginPath();
  477. ctx.moveTo(scoreBoxX + scoreBoxRadius, scoreBoxY);
  478. ctx.arcTo(scoreBoxX + scoreBoxWidth, scoreBoxY, scoreBoxX + scoreBoxWidth, scoreBoxY + scoreBoxHeight, scoreBoxRadius);
  479. ctx.arcTo(scoreBoxX + scoreBoxWidth, scoreBoxY + scoreBoxHeight, scoreBoxX, scoreBoxY + scoreBoxHeight, scoreBoxRadius);
  480. ctx.arcTo(scoreBoxX, scoreBoxY + scoreBoxHeight, scoreBoxX, scoreBoxY, scoreBoxRadius);
  481. ctx.arcTo(scoreBoxX, scoreBoxY, scoreBoxX + scoreBoxWidth, scoreBoxY, scoreBoxRadius);
  482. ctx.closePath();
  483. ctx.fill();
  484. ctx.stroke();
  485. ctx.restore();
  486. // 绘制分数文字
  487. ctx.fillStyle = '#002846';
  488. ctx.font = `bold ${scoreFontSize}px sans-serif`;
  489. ctx.textAlign = 'center';
  490. ctx.textBaseline = 'middle';
  491. ctx.fillText(scoreItem.score, scoreBoxX + scoreBoxWidth / 2, scoreBoxY + scoreBoxHeight / 2);
  492. },
  493. // 辅助函数:绘制自动换行的文字
  494. drawWrappedText(ctx, text, x, y, lineHeight, maxWidth) {
  495. let words = text.split('');
  496. let line = '';
  497. for (let n = 0; n < words.length; n++) {
  498. let testLine = line + words[n];
  499. let metrics = ctx.measureText(testLine);
  500. let testWidth = metrics.width;
  501. if (testWidth > maxWidth && n > 0) {
  502. ctx.fillText(line, x, y);
  503. line = words[n];
  504. y += lineHeight;
  505. } else {
  506. line = testLine;
  507. }
  508. }
  509. ctx.fillText(line, x, y);
  510. },
  511. // 辅助函数:解析 CSS linear-gradient 字符串
  512. parseGradient(gradientString) {
  513. const colorStops = [];
  514. // 简化解析,仅适用于 "linear-gradient(90deg, #RRGGBB 0%, #RRGGBB 100%)" 格式
  515. const matches = gradientString.match(/#([a-fA-F0-9]{6}|[a-fA-F0-9]{3})\s+(\d+)%/g);
  516. if (matches) {
  517. matches.forEach(match => {
  518. const parts = match.split(' ');
  519. colorStops.push({ color: parts[0], stop: parseInt(parts[1]) / 100 });
  520. });
  521. }
  522. return colorStops;
  523. },
  524. calculateScaleAndPosition() {
  525. uni.getSystemInfo({
  526. success: (res) => {
  527. const screenWidth = res.windowWidth; // 手机屏幕的宽度
  528. const pcContentWidth = 630; // PC端内容的原始宽度
  529. this.scale = screenWidth / pcContentWidth;
  530. this.$nextTick(() => {
  531. if (this.$refs.ztzdfxRef) {
  532. this.initZtzdfxChart();
  533. }
  534. });
  535. }
  536. });
  537. },
  538. calculatePdfContainerHeight() {
  539. uni.createSelectorQuery().in(this).select('#pdfContainer').boundingClientRect(rect => {
  540. if (rect) {
  541. this.originalContainerHeight = rect.height;
  542. this.containerScaledHeight = this.originalContainerHeight * this.scale;
  543. // console.log('原始高度:', this.originalContainerHeight, '缩放比例:', this.scale, '缩放后高度:', this.containerScaledHeight);
  544. }
  545. }).exec();
  546. },
  547. downloadZtzdfxImg(){
  548. return new Promise(resolve=>{
  549. if (!this.isChartReady) return console.log('图表尚未准备好');
  550. const chartRef = this.$refs.ztzdfxRef;
  551. if (!chartRef) return console.log('无法找到图表组件');
  552. chartRef.canvasToTempFilePath({
  553. success: async (res) => {
  554. const imgUrl = await this.uploadFilePromise(res.tempFilePath);
  555. console.log(imgUrl,'imgUrl');
  556. resolve(imgUrl)
  557. },
  558. fail: (err) => {
  559. console.log('生成图片失败:', err);
  560. }
  561. });
  562. })
  563. },
  564. uploadFilePromise(url) {
  565. return new Promise((resolve, reject) => {
  566. let a = uni.uploadFile({
  567. url: BaseApi+'/uploadFile',
  568. filePath: url,
  569. name: 'file',
  570. success: (res) => {
  571. setTimeout(() => {
  572. let data = JSON.parse(res.data)
  573. if(data&&data.code===0){
  574. resolve(data.data);
  575. }else this.$showToast(data?.msg)
  576. }, 1000);
  577. },
  578. fail: err =>{
  579. resolve('');
  580. }
  581. });
  582. });
  583. },
  584. async initZtzdfxChart() {
  585. let xdata = ['目的与动机', '外部流程及系统与架构', '关系', '内部流程及系统与架构', '学习', '领导力'].reverse();
  586. let yvalue = [40, 25, 30, 35, 33, 47].reverse();
  587. let ycolor = [['#FEDA60', '#FBE182'], ['#833479', '#9F6196'], ['#189B9B', '#64BBBB'], ['#7AABED', '#AFCDF5'], ['#4D697E', '#8093A3'], ['#0096D8', '#5CC9DA']].reverse();
  588. let yData = yvalue.map((v, i) => {
  589. return {
  590. value: v,
  591. itemStyle: {
  592. color: new echarts.graphic.LinearGradient(
  593. 0, 0, 1, 0,
  594. [
  595. { offset: 0, color: ycolor[i][0] },
  596. { offset: 1, color: ycolor[i][1] }
  597. ]
  598. ),
  599. borderRadius: [0, 4, 4, 0]
  600. }
  601. };
  602. });
  603. const chart = await this.$refs.ztzdfxRef.init(echarts);
  604. let option = {
  605. grid: {
  606. left: '2%',
  607. right: '10%',
  608. bottom: '0%',
  609. top: '10%',
  610. containLabel: true
  611. },
  612. xAxis: {
  613. type: 'value',
  614. boundaryGap: [0, 0.01],
  615. axisLabel: {
  616. fontSize: 10
  617. }
  618. },
  619. yAxis: {
  620. type: 'category',
  621. data: xdata,
  622. axisLabel: {
  623. color: '#193D59',
  624. fontSize: 10
  625. }
  626. },
  627. series: [
  628. {
  629. type: 'bar',
  630. barWidth: '8px',
  631. data: yData
  632. }
  633. ]
  634. };
  635. chart.setOption(option);
  636. this.isChartReady = true;
  637. this.$nextTick(() => {
  638. this.calculatePdfContainerHeight();
  639. });
  640. },
  641. }
  642. };
  643. </script>
  644. <style scoped lang="scss">
  645. .offscreen-canvas {
  646. position: fixed;
  647. top: -9999px;
  648. left: -9999px;
  649. }
  650. .pdf_btn{
  651. padding: 15rpx 20rpx;
  652. border-radius: 20rpx;
  653. font-size: 28rpx;
  654. color: #FFFFFF;
  655. background: #189B9B;
  656. position: fixed;
  657. right: 30rpx;
  658. bottom: 100rpx;
  659. z-index: 1000;
  660. }
  661. .page-wrappe{
  662. width: 100%;
  663. background: #FFFFFF;
  664. overflow-x: hidden;
  665. overflow-y: auto;
  666. .pdf-container{
  667. width: 630px;
  668. padding: 0 20rpx;
  669. box-sizing: border-box;
  670. transform-origin: top left;
  671. }
  672. }
  673. @import '../static/pdf.scss';
  674. </style>