list.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  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 = [30, 15, 17, 70, 18, 40, 13, 18, 16, 65, 30, 78];
  41. that.data.data2 = [12, 50, 51, 35, 70, 30, 20, 12, 15, 51, 35, 70];
  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. axisLabel: {
  159. formatter: '{value}小时'
  160. }
  161. }
  162. ],
  163. series: [
  164. {
  165. name: '签到数',
  166. type: 'line',
  167. stack: '总量',
  168. areaStyle: {},
  169. itemStyle: {
  170. normal: {
  171. color: "#25DEDB",//折线点的颜色
  172. lineStyle: {
  173. color: "#25DEDB"//折线的颜色
  174. }
  175. }
  176. },
  177. areaStyle: { // 该属性设置可以使这下图区域颜色达到渐变的效果
  178. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
  179. offset: 0,
  180. color: '#25DEDB'
  181. }, {
  182. offset: 1,
  183. color: '#ffe'
  184. }])
  185. },
  186. data: data1
  187. },
  188. {
  189. name: '时长',
  190. type: 'line',
  191. stack: '总量',
  192. areaStyle: {},
  193. itemStyle: {
  194. normal: {
  195. color: "#E96C44",//折线点的颜色
  196. lineStyle: {
  197. color: "#E96C44"//折线的颜色
  198. }
  199. }
  200. },
  201. areaStyle: { // 该属性设置可以使这下图区域颜色达到渐变的效果
  202. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
  203. offset: 0,
  204. color: '#E96C44'
  205. }, {
  206. offset: 1,
  207. color: '#ffe'
  208. }])
  209. },
  210. data: data2
  211. }
  212. ]
  213. };
  214. chart.setOption(option, true);
  215. return chart;
  216. }
  217. }, 100)
  218. },
  219. /**
  220. * 生命周期函数--监听页面初次渲染完成
  221. */
  222. onReady: function () { },
  223. /**
  224. * 生命周期函数--监听页面显示
  225. */
  226. onShow: function () {
  227. const that = this;
  228. // 监听用户是否登录
  229. that.watchLogin();
  230. },
  231. /**
  232. * 页面上拉触底事件的处理函数
  233. */
  234. /**
  235. * 生命周期函数--监听页面隐藏
  236. */
  237. onHide: function () {
  238. },
  239. /**
  240. * 生命周期函数--监听页面卸载
  241. */
  242. onUnload: function () {
  243. },
  244. /**
  245. * 页面相关事件处理函数--监听用户下拉动作
  246. */
  247. onPullDownRefresh: function () {
  248. },
  249. /**
  250. * 用户点击右上角分享
  251. */
  252. onShareAppMessage: function (res) {
  253. },
  254. })