record-index.ts 1.5 KB

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