record-index.ts 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import * as echarts from '../ec-canvas/echarts.min';
  2. import { healthIndexReportMethod } from './request';
  3. // module/health/pages/record-index/record-index.ts
  4. Component({
  5. lifetimes: {
  6. attached() {
  7. this._initRect();
  8. this._getData();
  9. }
  10. },
  11. properties: {
  12. },
  13. data: {
  14. gap: 0,
  15. scale: 1,
  16. rect: { width: 0, height: 0 },
  17. charts: [] as string[],
  18. },
  19. methods: {
  20. _initRect() {
  21. const { windowWidth, pixelRatio } = wx.getWindowInfo()
  22. const { right } = wx.getMenuButtonBoundingClientRect();
  23. const gap = windowWidth - right;
  24. const width = windowWidth - gap * 2;
  25. const height = Math.floor(width * 3 / 4);
  26. this.setData({
  27. rect: { width, height, },
  28. scale: pixelRatio, gap
  29. })
  30. },
  31. async _getData() {
  32. const charts = await healthIndexReportMethod();
  33. this.setData({
  34. charts: charts.map((option: any) => {
  35. return {
  36. id: option.id,
  37. onInit(canvas: any, width: number, height: number, dpr: number) {
  38. const ec = echarts.init(canvas, null, {
  39. width: width,
  40. height: height,
  41. devicePixelRatio: dpr
  42. });
  43. canvas.setChart(ec);
  44. ec.setOption(option);
  45. return ec;
  46. }
  47. }
  48. })
  49. });
  50. },
  51. }
  52. })