number.js 8.3 KB

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