pdf.vue 28 KB

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