number.js 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  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. ydata.push(records[i].value)
  134. }
  135. this.oneComponent = this.selectComponent('#mychart');
  136. this.init_one(xdata, ydata)
  137. },
  138. setChart1: function () {
  139. console.log(2333)
  140. var records = [], xdata = [], ydata = [];
  141. records = this.data.analyse.days7_casci_zhuanfa;
  142. if (records.length <= 0) {
  143. return;
  144. }
  145. for (let i = 0; i < records.length; i++) {
  146. xdata.push(records[i].name)
  147. ydata.push(records[i].value)
  148. }
  149. this.oneComponent1 = this.selectComponent('#mychart1');
  150. this.init_two(xdata, ydata)
  151. },
  152. setChart2: function () {
  153. var records = [], xdata = [], ydata = [];
  154. if (this.data.page == 0) {
  155. records = this.data.info.days7_casci_read;
  156. } else if (this.data.page == 0) {
  157. records = this.data.info.days7_casci_zan;
  158. }else{
  159. records = this.data.info.days7_casci_zhuanfa;
  160. }
  161. records = this.data.analyse.days7_casci_zhuanfa;
  162. if (records.length <= 0) {
  163. return;
  164. }
  165. for (let i = 0; i < records.length; i++) {
  166. xdata.push(records[i].name)
  167. ydata.push(records[i].value)
  168. }
  169. this.oneComponent2 = this.selectComponent('#mychart2');
  170. this.init_three(xdata, ydata)
  171. },
  172. init_one: function (xdata, ydata) { //初始化第一个图表
  173. this.oneComponent.init((canvas, width, height, dpr) => {
  174. const chart = echarts.init(canvas, null, {
  175. width: width,
  176. height: height,
  177. devicePixelRatio: dpr
  178. });
  179. setOption(chart, xdata, ydata)
  180. this.chart = chart;
  181. return chart;
  182. });
  183. },
  184. init_two: function (xdata, ydata) { //初始化第一个图表
  185. this.oneComponent1.init((canvas, width, height, dpr) => {
  186. const chart = echarts.init(canvas, null, {
  187. width: width,
  188. height: height,
  189. devicePixelRatio: dpr
  190. });
  191. setOption(chart, xdata, ydata)
  192. this.chart = chart;
  193. return chart;
  194. });
  195. },
  196. init_three: function (xdata, ydata) { //初始化第一个图表
  197. this.oneComponent2.init((canvas, width, height, dpr) => {
  198. const chart = echarts.init(canvas, null, {
  199. width: width,
  200. height: height,
  201. devicePixelRatio: dpr
  202. });
  203. setOption(chart, xdata, ydata)
  204. this.chart = chart;
  205. return chart;
  206. });
  207. },
  208. weixin: function () {
  209. if (this.data.info.qrcode || this.data.info.wxcode) {
  210. this.setData({
  211. show: true
  212. })
  213. } else {
  214. wx.showToast({
  215. title: '该期刊暂无公众号',
  216. })
  217. }
  218. },
  219. close: function () {
  220. this.setData({
  221. show: false
  222. })
  223. },
  224. view: function () {
  225. wx.previewImage({
  226. urls: [this.data.info.qrcode],
  227. current: this.data.info.qrcode
  228. })
  229. },
  230. /**
  231. * 生命周期函数--监听页面初次渲染完成
  232. */
  233. onReady: function () {
  234. },
  235. /**
  236. * 生命周期函数--监听页面显示
  237. */
  238. onShow: function () {
  239. },
  240. /**
  241. * 生命周期函数--监听页面隐藏
  242. */
  243. onHide: function () {
  244. },
  245. /**
  246. * 生命周期函数--监听页面卸载
  247. */
  248. onUnload: function () {
  249. },
  250. /**
  251. * 页面相关事件处理函数--监听用户下拉动作
  252. */
  253. onPullDownRefresh: function () {
  254. },
  255. /**
  256. * 页面上拉触底事件的处理函数
  257. */
  258. onReachBottom: function () {
  259. },
  260. /**
  261. * 用户点击右上角分享
  262. */
  263. onShareAppMessage: function () {
  264. }
  265. })
  266. function setOption(chart, xdata, ydata) {
  267. var option = {
  268. legend: {
  269. show: false
  270. },
  271. backgroundColor:'#F1F4F6',
  272. grid: {
  273. x: 50,
  274. y: 30,
  275. x2: 10,
  276. y2: 35
  277. },
  278. tooltip: {
  279. show: true,
  280. trigger: 'axis',
  281. formatter: '{b0}: {c0}'
  282. },
  283. xAxis: {
  284. type: 'category',
  285. data: xdata,
  286. axisLabel: {
  287. interval: 0,
  288. // rotate: 40,
  289. color: '#999999'
  290. }
  291. },
  292. yAxis: {
  293. axisLine: {
  294. show: true
  295. },
  296. type: 'value',
  297. name: '',
  298. axisLabel: {
  299. formatter: function (value, index) {//隐藏 0
  300. let texts = [];
  301. texts.push(value)
  302. return texts;
  303. },
  304. show: true
  305. },
  306. },
  307. series: [{
  308. name: 'A',
  309. type: 'line',
  310. smooth: true,
  311. symbolSize: 8,
  312. lineStyle: {
  313. color: '#FF9F2E'
  314. // color: new echarts.graphic.LinearGradient(1, 0, 0, 0, [{
  315. // offset: 0,
  316. // color: '#FF2D68'
  317. // }, {
  318. // offset: 1,
  319. // color: '#4C4BFF'
  320. // }]),
  321. },
  322. areaStyle: {
  323. color: {
  324. //线性渐变
  325. type: 'linear',
  326. x:0,
  327. y:0,
  328. x2:0,
  329. y2:1,
  330. colorStops: [{
  331. offset: 0, color: 'rgba(255, 159, 46, .5)', // 0% 处的颜色
  332. }, {
  333. offset: 1, color: 'rgba(255, 159, 46, .2)', // 100% 处的颜色
  334. }],
  335. global: false, // 缺省为 false
  336. },
  337. },
  338. itemStyle: {
  339. borderWidth: 5,
  340. borderColor: '#FFAD52',
  341. color: '#FFAD52'
  342. },
  343. data: ydata
  344. }]
  345. };
  346. chart.setOption(option)
  347. }