list.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. const app = getApp()
  2. import * as echarts from '../../../commpents/ec-canvas/echarts'
  3. Page({
  4. data: {
  5. frameStyle: { useTop: true, name: '授课情况', leftArrow: true, useBar: false },
  6. // xdata: []
  7. },
  8. // 返回
  9. back(e) {
  10. wx.navigateBack({ delta: 1 })
  11. },
  12. /**
  13. * 生命周期函数--监听页面加载
  14. */
  15. onLoad: function (options) {
  16. },
  17. // 监听用户是否登录
  18. watchLogin: async function () {
  19. const that = this;
  20. wx.getStorage({
  21. key: 'user',
  22. success: async res => {
  23. that.setData({ ec: { onInit: that.initChart } })
  24. that.data.xdata = [
  25. { value: 2, name: '1月' },
  26. { value: 10, name: '2月' },
  27. { value: 19, name: '3月' },
  28. { value: 20, name: '4月' },
  29. { value: 70, name: '5月' },
  30. { value: 9, name: '6月' },
  31. { value: 12, name: '7月' },
  32. { value: 41, name: '8月' },
  33. { value: 31, name: '9月' },
  34. { value: 13, name: '10月' },
  35. { value: 16, name: '11月' },
  36. { value: 10, name: '12月' }
  37. ];
  38. },
  39. fail: async res => {
  40. wx.redirectTo({ url: '/pages/index/index' })
  41. }
  42. })
  43. },
  44. // 饼图
  45. initChart(canvas, width, height, dpr) {
  46. let that = this;
  47. var xdata = that.data.xdata;
  48. const chart = echarts.init(canvas, null, { width: width, height: height, devicePixelRatio: dpr });
  49. canvas.setChart(chart);
  50. var option = {
  51. tooltip: { trigger: 'item' },
  52. legend: {
  53. orient: 'vertical',
  54. height: 40,
  55. padding: 50
  56. },
  57. series: [
  58. {
  59. name: '课时',
  60. type: 'pie',
  61. radius: '50%',
  62. data: xdata,
  63. emphasis: {
  64. itemStyle: { shadowBlur: 10, shadowOffsetX: 0, shadowColor: 'rgba(0, 0, 0, 0.5)' }
  65. }
  66. }
  67. ]
  68. };
  69. chart.setOption(option, true);
  70. return chart;
  71. },
  72. /**
  73. * 生命周期函数--监听页面初次渲染完成
  74. */
  75. onReady: function () { },
  76. /**
  77. * 生命周期函数--监听页面显示
  78. */
  79. onShow: function () {
  80. const that = this;
  81. // 监听用户是否登录
  82. that.watchLogin();
  83. },
  84. /**
  85. * 页面上拉触底事件的处理函数
  86. */
  87. /**
  88. * 生命周期函数--监听页面隐藏
  89. */
  90. onHide: function () {
  91. },
  92. /**
  93. * 生命周期函数--监听页面卸载
  94. */
  95. onUnload: function () {
  96. },
  97. /**
  98. * 页面相关事件处理函数--监听用户下拉动作
  99. */
  100. onPullDownRefresh: function () {
  101. },
  102. /**
  103. * 用户点击右上角分享
  104. */
  105. onShareAppMessage: function (res) {
  106. },
  107. })