study.js 10 KB

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