index.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  1. <template>
  2. <view>
  3. <m-nav-bar fixed title="本次考试成绩"></m-nav-bar>
  4. <view class="top">
  5. <view class="score">
  6. <view class="circle">
  7. <canvas
  8. id="circle1"
  9. class="circle-canvas"
  10. canvas-id="circle1"
  11. width="340"
  12. height="300"
  13. type="2d"
  14. ></canvas>
  15. <view style="border: none" class="wxad">
  16. <ad
  17. :ad-intervals="100"
  18. ad-type="banner"
  19. unit-id="adunit-8eb44bbd7e3147d4"
  20. ></ad>
  21. </view>
  22. </view>
  23. </view>
  24. </view>
  25. <view class="split"> </view>
  26. <view class="history">
  27. <view class="title">
  28. <view class="title-left">考试情况</view>
  29. <view class="title-right"
  30. >历史成绩<van-icon name="arrow" size="26rpx"
  31. /></view>
  32. </view>
  33. <view class="content">
  34. <ec-canvas
  35. class="uni-ec-canvas"
  36. :ec="ec"
  37. :init-chart="initChart"
  38. canvasId="line-canvas1"
  39. ></ec-canvas>
  40. <!-- <view style="width: 100%; height: 250rpx"></view> -->
  41. </view>
  42. <view style="width: 100%; height: 150rpx"></view>
  43. </view>
  44. </view>
  45. </template>
  46. <script>
  47. import ecCanvas from "./../components/ec-canvas/index";
  48. import * as echarts from "./../components/ec-canvas/echarts";
  49. import api from "@/api";
  50. export default {
  51. data() {
  52. return {
  53. query: {
  54. score: 90,
  55. },
  56. ec: {},
  57. };
  58. },
  59. onLoad(query) {
  60. this.query = {
  61. ...query,
  62. score: Number(query.score || 0),
  63. };
  64. //登记成绩
  65. // api.exam.studentScoreInfo({
  66. // type: "三力测试",
  67. // score: Number(query.score),
  68. // });
  69. },
  70. onReady() {
  71. let that = this;
  72. const query = wx.createSelectorQuery();
  73. query
  74. .select("#circle1")
  75. .fields({ node: true, size: true })
  76. .exec((res) => {
  77. console.log(res);
  78. const canvas = res[0].node;
  79. const ctx = canvas.getContext("2d");
  80. const dpr = wx.getSystemInfoSync().pixelRatio;
  81. canvas.width = res[0].width * dpr;
  82. canvas.height = res[0].height * dpr;
  83. ctx.dpr = dpr;
  84. ctx.scale(dpr, dpr);
  85. that.drawHalfCircleAndScore(ctx);
  86. // ctx.fillRect(0, 0, 100, 100);
  87. });
  88. },
  89. methods: {
  90. initChart: async function (canvas, width, height, dpr) {
  91. let that = this;
  92. const chart = echarts.init(canvas, null, {
  93. width: width,
  94. height: height,
  95. devicePixelRatio: dpr, // new
  96. });
  97. canvas.setChart(chart);
  98. let res = await api.exam.studentScoreInfoList({
  99. type: "三力测试",
  100. });
  101. let optionSeriesData0 = res.rows.map((item) => {
  102. return item.score;
  103. });
  104. optionSeriesData0.reverse();
  105. console.log(res);
  106. var option = {
  107. color: ["#01C18D", "#00DDFF", "#37A2FF", "#FF0087", "#FFBF00"],
  108. title: {
  109. text: "",
  110. },
  111. toolbox: {
  112. left: "center",
  113. itemSize: 0,
  114. top: 0,
  115. feature: {
  116. dataZoom: {
  117. type: "inside",
  118. xAxisIndex: 0,
  119. start: 0,
  120. end: 100,
  121. },
  122. },
  123. },
  124. tooltip: {
  125. trigger: "axis",
  126. axisPointer: {
  127. type: "cross",
  128. label: {
  129. backgroundColor: "#6a7985",
  130. },
  131. },
  132. },
  133. legend: {
  134. data: [],
  135. },
  136. grid: {
  137. left: "3%",
  138. right: "4%",
  139. bottom: "3%",
  140. containLabel: true,
  141. },
  142. xAxis: [
  143. {
  144. type: "category",
  145. boundaryGap: true,
  146. axisLine: {
  147. lineStyle: {
  148. color: "#F0F0F0",
  149. },
  150. },
  151. },
  152. ],
  153. yAxis: [
  154. {
  155. type: "value",
  156. max: 100,
  157. minInterval: 30,
  158. },
  159. ],
  160. series: [
  161. {
  162. name: "Line 1",
  163. type: "line",
  164. stack: "Total",
  165. smooth: false,
  166. lineStyle: {
  167. width: 2,
  168. },
  169. markLine: {
  170. data: [
  171. [
  172. {
  173. name: "及格线",
  174. yAxis: 90,
  175. x: "10%",
  176. label: {
  177. color: "#01C18D",
  178. },
  179. },
  180. {
  181. name: "及格线",
  182. yAxis: 90,
  183. x: "85%",
  184. },
  185. ],
  186. ],
  187. },
  188. showSymbol: true,
  189. areaStyle: {
  190. opacity: 0.8,
  191. color: new echarts.graphic.LinearGradient(1, 0, 1, 1, [
  192. {
  193. offset: 0,
  194. color: "#E1F8F1",
  195. },
  196. {
  197. offset: 1,
  198. color: "#FEFEFE",
  199. },
  200. ]),
  201. },
  202. emphasis: {
  203. focus: "series",
  204. },
  205. data: optionSeriesData0,
  206. },
  207. ],
  208. };
  209. chart.setOption(option);
  210. return chart;
  211. },
  212. /**
  213. * @function 绘制半圆和分数
  214. * @param ctx {WechatMiniprogram.CanvasContext}
  215. */
  216. drawHalfCircleAndScore(ctx) {
  217. let x1 = ctx.canvas.width / ctx.dpr / 2;
  218. let y1 = 100;
  219. let r1 = 70;
  220. let that = this;
  221. //绘制白环
  222. ctx.moveTo(x1, y1);
  223. ctx.lineCap = "round";
  224. ctx.lineWidth = 40;
  225. ctx.strokeStyle = "#ffffff";
  226. ctx.beginPath();
  227. ctx.arc(x1, y1, r1, Math.PI, 0, false);
  228. ctx.stroke();
  229. //绘制灰环
  230. ctx.moveTo(x1, y1);
  231. ctx.lineCap = "round";
  232. ctx.lineWidth = 20;
  233. ctx.strokeStyle = "#d8d8d8";
  234. ctx.beginPath();
  235. ctx.arc(x1, y1, r1, Math.PI, 0, false);
  236. ctx.stroke();
  237. // ctx.draw()
  238. //绘制渐变环
  239. ctx.moveTo(x1, y1);
  240. let scoreColor1 = that.query.score >= 90 ? "#01C18D" : "#FF6D4E";
  241. let scoreColor2 = that.query.score >= 90 ? "#3ED2AA" : "#FE3B2B";
  242. var arcColor = ctx.createLinearGradient(15, 125, 155, 125);
  243. arcColor.addColorStop(0, scoreColor1);
  244. arcColor.addColorStop(1, scoreColor2);
  245. ctx.strokeStyle = arcColor;
  246. ctx.lineCap = "round";
  247. ctx.lineWidth = 20;
  248. ctx.beginPath();
  249. ctx.arc(
  250. x1,
  251. y1,
  252. r1,
  253. Math.PI,
  254. Math.PI * (1 + that.query.score / 100),
  255. false
  256. );
  257. ctx.stroke();
  258. console.log(ctx);
  259. // ctx.draw()
  260. //绘制文字
  261. ctx.moveTo(x1, y1);
  262. ctx.textAlign = "right";
  263. ctx.lineWidth = 1;
  264. ctx.font = "30px sans-serif";
  265. let score = that.query.score;
  266. console.log(scoreWidth);
  267. ctx.beginPath();
  268. ctx.fillStyle = scoreColor1;
  269. ctx.fillText(String(that.query.score), x1 + 10, y1);
  270. ctx.textAlign = "right";
  271. ctx.font = "14px sans-serif";
  272. let scoreWidth = ctx.measureText(String(score)).actualBoundingBoxRight;
  273. console.log(scoreWidth);
  274. ctx.fillText("分", x1 + scoreWidth + 30, y1);
  275. ctx.textAlign = "center";
  276. ctx.font = "14px sans-serif";
  277. ctx.fillStyle = "#333333";
  278. ctx.fillText(
  279. that.query.score >= 90 ? "恭喜你,成绩合格!" : "很遗憾,考试不合格!",
  280. x1,
  281. y1 + 40
  282. );
  283. },
  284. },
  285. components: { ecCanvas },
  286. };
  287. </script>
  288. <style lang="less" scoped>
  289. .vh100 {
  290. height: 100vh;
  291. }
  292. .top {
  293. width: 750rpx;
  294. height: 726rpx;
  295. background-image: url("https://ndata.zzxcx.net/ctjk/mp-wx/threeExamScore/topBg.png");
  296. background-size: 100%;
  297. padding: 0 30rpx;
  298. overflow-x: hidden;
  299. .score {
  300. background: #fff;
  301. width: 100%;
  302. height: 472rpx;
  303. margin-top: 150rpx;
  304. border-radius: 20rpx 20rpx 20rpx 20rpx;
  305. .circle {
  306. .circle-canvas {
  307. width: 340rpx;
  308. height: 300rpx;
  309. margin: 0 auto;
  310. transform: translateY(-15%);
  311. }
  312. }
  313. }
  314. }
  315. .split {
  316. width: 100%;
  317. height: 20rpx;
  318. border-bottom: 2rpx dashed #888;
  319. }
  320. .history {
  321. background: #fff;
  322. .title {
  323. display: flex;
  324. justify-content: space-between;
  325. padding-top: 40rpx;
  326. padding-left: 30rpx;
  327. padding-right: 30rpx;
  328. font-size: 26rpx;
  329. .title-left {
  330. font-size: 34rpx;
  331. color: #0a1a33;
  332. font-weight: bold;
  333. }
  334. .title-right {
  335. color: #8a9099;
  336. }
  337. }
  338. .content {
  339. width: 750rpx;
  340. height: 500rpx;
  341. padding: 15rpx;
  342. }
  343. .uni-ec-canvas {
  344. width: 100%;
  345. height: 100%;
  346. display: block;
  347. }
  348. }
  349. </style>