list.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  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. },
  7. // 返回
  8. back(e) {
  9. wx.navigateBack({ delta: 1 })
  10. },
  11. /**
  12. * 生命周期函数--监听页面加载
  13. */
  14. onLoad: function (options) {
  15. },
  16. // 监听用户是否登录
  17. watchLogin: async function () {
  18. const that = this;
  19. wx.getStorage({
  20. key: 'user',
  21. success: async res => {
  22. that.setData({
  23. ec: {
  24. onInit: that.initChart
  25. }
  26. })
  27. // 模拟请求
  28. var times = setTimeout(async function () {
  29. const student = await app.$get(`/lessonStudent`, { student_id: res.data.info.id, is_pay: '1' })
  30. if (student.errcode == '0') {
  31. for (const val of student.data) {
  32. const lesson = await app.$get(`/lesson/${val.lesson_id}`)
  33. val.lessonname = lesson.data.title
  34. }
  35. var schooldata = student.data.map((item) => { return item.lessonname; });
  36. }
  37. // 数据
  38. that.data.schooldata = schooldata;
  39. that.data.xdata = ['1月份', '2月份', '3月份', '4月份', '5月份', '6月份', '7月份', '8月份', '9月份', '10月份', '11月份', '12月份'];
  40. that.data.data1 = [230, 150, 178, 70, 178, 340, 133, 118, 136, 165, 130, 178];
  41. that.data.data2 = [112, 150, 151, 135, 170, 130, 200, 112, 150, 151, 135, 170];
  42. clearTimeout(times);
  43. }, 1000)
  44. },
  45. fail: async res => {
  46. wx.redirectTo({ url: '/pages/index/index' })
  47. }
  48. })
  49. },
  50. // 折线图
  51. initChart(canvas, width, height, dpr) {
  52. let that = this;
  53. // 由于请求数据有延迟所以写一个时间函数,当数据存在的时候再执行绘制
  54. var times = setInterval(function () {
  55. var xdata = that.data.xdata;
  56. var schooldata = that.data.schooldata;
  57. var data1 = that.data.data1;
  58. var data2 = that.data.data2;
  59. if (xdata && data1 && data2 && schooldata) {
  60. clearInterval(times)
  61. const chart = echarts.init(canvas, null, {
  62. width: width,
  63. height: height,
  64. devicePixelRatio: dpr // new
  65. });
  66. canvas.setChart(chart);
  67. var option = {
  68. tooltip: {
  69. trigger: 'axis',
  70. axisPointer: {
  71. type: 'cross',
  72. label: {
  73. backgroundColor: '#6a7985'
  74. }
  75. }
  76. ,
  77. formatter: function (params) {
  78. let html = params[0].name + "<br>";
  79. for (let i = 0; i < params.length; i++) {
  80. html += '<span style="display:inline-block;margin-right:5px;border-radius:10px;width:10px;height:10px;background-color:' + params[i].color + ';"></span>'
  81. if (params[i].seriesName == "签到数") {
  82. html += params[i].seriesName + ":" + params[i].value + "%<br>";
  83. }
  84. if (params[i].seriesName == "时长") {
  85. html += params[i].seriesName + ":" + params[i].value + "小时<br>";
  86. }
  87. }
  88. return html;
  89. }
  90. },
  91. legend: {
  92. textStyle: { color: '#4CA6A3' },
  93. x: 'right',
  94. data: [{ name: '签到数', icon: 'rect' }, { name: '时长', icon: 'rect' }]
  95. },
  96. grid: {
  97. left: '2%',
  98. right: '2%',
  99. bottom: '3%',
  100. containLabel: true
  101. },
  102. xAxis: [
  103. {
  104. type: 'category',
  105. boundaryGap: false,
  106. // 设置x轴线的属性
  107. axisLabel: {
  108. //x轴文字的配置
  109. show: true,
  110. interval: 0,//使x轴文字显示全
  111. },
  112. axisLine: {
  113. lineStyle: {
  114. color: '#4CA6A3', // 设置x轴字体颜色
  115. width: 2, // 设置x轴字体宽度
  116. }
  117. },
  118. data: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月']
  119. }
  120. ],
  121. yAxis: [
  122. {
  123. type: 'value',
  124. name: '时长',
  125. position: 'left',
  126. alignTicks: true,
  127. axisLine: {
  128. show: true,
  129. lineStyle: {
  130. fontSize: 16,
  131. color: '#293C55'
  132. }
  133. },
  134. axisLabel: {
  135. formatter: '{value} 小时'
  136. }
  137. },
  138. {
  139. type: 'value',
  140. alignTicks: true,
  141. nameGap: 10,
  142. nameRotate: 0,
  143. nameTextStyle: {
  144. fontSize: 16,
  145. color: '#293C55'
  146. },
  147. splitLine: { show: false },//去除网格线
  148. min: 0,
  149. max: 100,
  150. interval: 10,
  151. // 设置轴线的属性
  152. axisLine: {
  153. show: true,
  154. lineStyle: {
  155. color: '#293C55',
  156. }
  157. }
  158. }
  159. ],
  160. series: [
  161. {
  162. name: '签到数',
  163. type: 'line',
  164. stack: '总量',
  165. areaStyle: {},
  166. itemStyle: {
  167. normal: {
  168. color: "#25DEDB",//折线点的颜色
  169. lineStyle: {
  170. color: "#25DEDB"//折线的颜色
  171. }
  172. }
  173. },
  174. areaStyle: { // 该属性设置可以使这下图区域颜色达到渐变的效果
  175. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
  176. offset: 0,
  177. color: '#25DEDB'
  178. }, {
  179. offset: 1,
  180. color: '#ffe'
  181. }])
  182. },
  183. data: data1
  184. },
  185. {
  186. name: '时长',
  187. type: 'line',
  188. stack: '总量',
  189. areaStyle: {},
  190. itemStyle: {
  191. normal: {
  192. color: "#E96C44",//折线点的颜色
  193. lineStyle: {
  194. color: "#E96C44"//折线的颜色
  195. }
  196. }
  197. },
  198. areaStyle: { // 该属性设置可以使这下图区域颜色达到渐变的效果
  199. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
  200. offset: 0,
  201. color: '#E96C44'
  202. }, {
  203. offset: 1,
  204. color: '#ffe'
  205. }])
  206. },
  207. data: data2
  208. }
  209. ]
  210. };
  211. chart.setOption(option, true);
  212. return chart;
  213. }
  214. }, 100)
  215. },
  216. /**
  217. * 生命周期函数--监听页面初次渲染完成
  218. */
  219. onReady: function () { },
  220. /**
  221. * 生命周期函数--监听页面显示
  222. */
  223. onShow: function () {
  224. const that = this;
  225. // 监听用户是否登录
  226. that.watchLogin();
  227. },
  228. /**
  229. * 页面上拉触底事件的处理函数
  230. */
  231. /**
  232. * 生命周期函数--监听页面隐藏
  233. */
  234. onHide: function () {
  235. },
  236. /**
  237. * 生命周期函数--监听页面卸载
  238. */
  239. onUnload: function () {
  240. },
  241. /**
  242. * 页面相关事件处理函数--监听用户下拉动作
  243. */
  244. onPullDownRefresh: function () {
  245. },
  246. /**
  247. * 用户点击右上角分享
  248. */
  249. onShareAppMessage: function (res) {
  250. },
  251. })