number.js 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  1. // pages/number/number.js
  2. import * as echarts from '../../ec-canvas/echarts';
  3. const app = getApp()
  4. var host = app.globalData.host;
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. info:{},
  11. analyse:{},
  12. day:'',
  13. ec: {
  14. // onInit: initChart
  15. lazyLoad: true
  16. },
  17. page:0,
  18. casci:0,
  19. act:0,
  20. list:[],
  21. show:0
  22. },
  23. /**
  24. * 生命周期函数--监听页面加载
  25. */
  26. onLoad: function (options) {
  27. var y = new Date().getFullYear(), m = (new Date().getMonth() + 1), d = new Date().getDate();
  28. m = m > 9 ? m : '0' + m;
  29. d = d > 9 ? d : '0' + d;
  30. this.setData({
  31. day: y + '-' + m + '-' + (d-1)
  32. })
  33. // options.id=2;
  34. wx.showNavigationBarLoading()
  35. wx.request({
  36. url: host + '/api/casci/detail',
  37. method: 'GET',
  38. data: {
  39. id: options.id
  40. },
  41. success: res => {
  42. wx.hideNavigationBarLoading()
  43. if (res.data.code == 0) {
  44. this.setData({
  45. info:res.data.data
  46. })
  47. this.setChart()
  48. }
  49. }
  50. })
  51. wx.request({
  52. url: host + '/api/casci/analyse',
  53. method: 'GET',
  54. data: {
  55. id: options.id
  56. },
  57. success: res => {
  58. wx.hideNavigationBarLoading()
  59. if (res.data.code == 0) {
  60. this.setData({
  61. analyse: res.data.data
  62. })
  63. }
  64. }
  65. })
  66. this.getData(options.id)
  67. },
  68. getData: function (id) {
  69. wx.showNavigationBarLoading()
  70. const _list = this.data.list;
  71. var index = this.data.index;
  72. wx.request({
  73. url: host + '/api/article/list',
  74. method: 'GET',
  75. data: {
  76. journal_id:id,
  77. page_size:9999
  78. // order_by: this.data.val[index],
  79. // keyword: this.data.keyword,
  80. // page: this.data.page
  81. },
  82. success: res => {
  83. wx.hideNavigationBarLoading()
  84. if (res.data.code == 0) {
  85. const list = res.data.data.list;
  86. for (let i = 0; i < list.length; i++) {
  87. _list.push(list[i])
  88. }
  89. this.setData({
  90. list: _list,
  91. total: res.data.data.total
  92. })
  93. }
  94. }
  95. })
  96. },
  97. checkpage:function(e){
  98. this.setData({
  99. act: e.target.dataset.id
  100. })
  101. if (e.target.dataset.id == 0){
  102. this.setChart()
  103. }
  104. if (e.target.dataset.id == 1) {
  105. this.setChart1()
  106. this.setChart2()
  107. }
  108. },
  109. check:function(e){
  110. this.setData({
  111. casci:e.target.dataset.id
  112. })
  113. this.setChart()
  114. },
  115. checknum: function (e) {
  116. this.setData({
  117. page: e.target.dataset.id
  118. })
  119. this.setChart2()
  120. },
  121. setChart:function(){
  122. var records = [], xdata = [], ydata = [];
  123. if (this.data.casci == 0) {
  124. records = this.data.info.days7_casci;
  125. } else {
  126. records = this.data.info.days30_casci;
  127. }
  128. if (records.length <= 0) {
  129. return;
  130. }
  131. for (let i = 0; i < records.length; i++) {
  132. // xdata.push(records[i].name)
  133. let date = records[i].name.split('-');
  134. xdata.push(date[1] + '/' + date[2])
  135. ydata.push(records[i].value)
  136. }
  137. this.oneComponent = this.selectComponent('#mychart');
  138. this.init_one(xdata, ydata)
  139. },
  140. setChart1: function () {
  141. var records = [], xdata = [], ydata = [];
  142. records = this.data.analyse.days7_rank;
  143. if (records.length <= 0) {
  144. return;
  145. }
  146. for (let i = 0; i < records.length; i++) {
  147. // xdata.push(records[i].name)
  148. let date = records[i].name.split('-');
  149. xdata.push(date[1] + '/' + date[2])
  150. ydata.push(records[i].value)
  151. }
  152. this.oneComponent1 = this.selectComponent('#mychart1');
  153. this.init_two(xdata, ydata)
  154. },
  155. setChart2: function () {
  156. var records = [], xdata = [], ydata = [];
  157. if (this.data.page == 0) {
  158. records = this.data.info.days7_casci_read;
  159. } else if (this.data.page == 0) {
  160. records = this.data.info.days7_casci_zan;
  161. }else{
  162. records = this.data.info.days7_casci_zhuanfa;
  163. }
  164. records = this.data.analyse.days7_casci_zhuanfa;
  165. if (records.length <= 0) {
  166. return;
  167. }
  168. for (let i = 0; i < records.length; i++) {
  169. let date = records[i].name.split('-');
  170. xdata.push(date[1] + '/' + date[2])
  171. // xdata.push(records[i].name)
  172. ydata.push(records[i].value)
  173. }
  174. this.oneComponent2 = this.selectComponent('#mychart2');
  175. this.init_three(xdata, ydata)
  176. },
  177. init_one: function (xdata, ydata) { //初始化第一个图表
  178. this.oneComponent.init((canvas, width, height, dpr) => {
  179. const chart = echarts.init(canvas, null, {
  180. width: width,
  181. height: height,
  182. devicePixelRatio: dpr
  183. });
  184. setOption(chart, xdata, ydata)
  185. this.chart = chart;
  186. return chart;
  187. });
  188. },
  189. init_two: function (xdata, ydata) { //初始化第一个图表
  190. this.oneComponent1.init((canvas, width, height, dpr) => {
  191. const chart = echarts.init(canvas, null, {
  192. width: width,
  193. height: height,
  194. devicePixelRatio: dpr
  195. });
  196. setOption(chart, xdata, ydata)
  197. this.chart = chart;
  198. return chart;
  199. });
  200. },
  201. init_three: function (xdata, ydata) { //初始化第一个图表
  202. this.oneComponent2.init((canvas, width, height, dpr) => {
  203. const chart = echarts.init(canvas, null, {
  204. width: width,
  205. height: height,
  206. devicePixelRatio: dpr
  207. });
  208. setOption(chart, xdata, ydata)
  209. this.chart = chart;
  210. return chart;
  211. });
  212. },
  213. weixin: function () {
  214. if (this.data.info.qrcode || this.data.info.wxcode) {
  215. this.setData({
  216. show: true
  217. })
  218. } else {
  219. wx.showToast({
  220. title: '该期刊暂无公众号',
  221. })
  222. }
  223. },
  224. close: function () {
  225. this.setData({
  226. show: false
  227. })
  228. },
  229. view: function () {
  230. wx.previewImage({
  231. urls: [this.data.info.qrcode],
  232. current: this.data.info.qrcode
  233. })
  234. },
  235. /**
  236. * 生命周期函数--监听页面初次渲染完成
  237. */
  238. onReady: function () {
  239. },
  240. /**
  241. * 生命周期函数--监听页面显示
  242. */
  243. onShow: function () {
  244. },
  245. /**
  246. * 生命周期函数--监听页面隐藏
  247. */
  248. onHide: function () {
  249. },
  250. /**
  251. * 生命周期函数--监听页面卸载
  252. */
  253. onUnload: function () {
  254. },
  255. /**
  256. * 页面相关事件处理函数--监听用户下拉动作
  257. */
  258. onPullDownRefresh: function () {
  259. },
  260. /**
  261. * 页面上拉触底事件的处理函数
  262. */
  263. onReachBottom: function () {
  264. },
  265. /**
  266. * 用户点击右上角分享
  267. */
  268. onShareAppMessage: function () {
  269. }
  270. })
  271. function setOption(chart, xdata, ydata) {
  272. xdata = xdata.reverse()
  273. ydata = ydata.reverse()
  274. let interval=0
  275. if (xdata.length>10){
  276. interval=2
  277. }
  278. var option = {
  279. legend: {
  280. show: false
  281. },
  282. backgroundColor:'#F1F4F6',
  283. grid: {
  284. x: 50,
  285. y: 30,
  286. x2: 10,
  287. y2: 35
  288. },
  289. tooltip: {
  290. show: true,
  291. trigger: 'axis',
  292. formatter: '{b0}: {c0}'
  293. },
  294. xAxis: {
  295. type: 'category',
  296. data: xdata,
  297. axisLabel: {
  298. rotate: 45,
  299. interval: interval,
  300. color: '#999999'
  301. }
  302. },
  303. yAxis: {
  304. axisLine: {
  305. show: true
  306. },
  307. type: 'value',
  308. name: '',
  309. axisLabel: {
  310. formatter: function (value, index) {//隐藏 0
  311. let texts = [];
  312. texts.push(value)
  313. return texts;
  314. },
  315. show: true
  316. },
  317. },
  318. series: [{
  319. name: 'A',
  320. type: 'line',
  321. smooth: true,
  322. symbolSize: 8,
  323. lineStyle: {
  324. color: '#FF9F2E'
  325. // color: new echarts.graphic.LinearGradient(1, 0, 0, 0, [{
  326. // offset: 0,
  327. // color: '#FF2D68'
  328. // }, {
  329. // offset: 1,
  330. // color: '#4C4BFF'
  331. // }]),
  332. },
  333. areaStyle: {
  334. color: {
  335. //线性渐变
  336. type: 'linear',
  337. x:0,
  338. y:0,
  339. x2:0,
  340. y2:1,
  341. colorStops: [{
  342. offset: 0, color: 'rgba(255, 159, 46, .5)', // 0% 处的颜色
  343. }, {
  344. offset: 1, color: 'rgba(255, 159, 46, .2)', // 100% 处的颜色
  345. }],
  346. global: false, // 缺省为 false
  347. },
  348. },
  349. itemStyle: {
  350. borderWidth: 5,
  351. borderColor: '#FFAD52',
  352. color: '#FFAD52'
  353. },
  354. data: ydata
  355. }]
  356. };
  357. chart.setOption(option)
  358. }