123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383 |
- // pages/number/number.js
- import * as echarts from '../../ec-canvas/echarts';
- const app = getApp()
- var host = app.globalData.host;
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- info:{},
- analyse:{},
- day:'',
- ec: {
- // onInit: initChart
- lazyLoad: true
- },
- page:0,
- casci:0,
- act:0,
- list:[],
- show:0
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- var y = new Date().getFullYear(), m = (new Date().getMonth() + 1), d = new Date().getDate();
- m = m > 9 ? m : '0' + m;
- d = d > 9 ? d : '0' + d;
- this.setData({
- day: y + '-' + m + '-' + (d-1)
- })
- // options.id=2;
- wx.showNavigationBarLoading()
- wx.request({
- url: host + '/api/casci/detail',
- method: 'GET',
- data: {
- id: options.id
- },
- success: res => {
- wx.hideNavigationBarLoading()
- if (res.data.code == 0) {
- this.setData({
- info:res.data.data
- })
- this.setChart()
- }
- }
- })
- wx.request({
- url: host + '/api/casci/analyse',
- method: 'GET',
- data: {
- id: options.id
- },
- success: res => {
- wx.hideNavigationBarLoading()
- if (res.data.code == 0) {
- var data = res.data.data
- data.read_num1 = parseInt(data.read_num/7)
- data.zhuanfa_num1 = parseInt(data.zhuanfa_num / 7)
- this.setData({
- analyse: data
- })
-
- }
- }
- })
- this.getData(options.id)
- },
- getData: function (id) {
- wx.showNavigationBarLoading()
- const _list = this.data.list;
- var index = this.data.index;
- wx.request({
- url: host + '/api/article/list',
- method: 'GET',
- data: {
- journal_id:id,
- page_size:9999
- // order_by: this.data.val[index],
- // keyword: this.data.keyword,
- // page: this.data.page
- },
- success: res => {
- wx.hideNavigationBarLoading()
- if (res.data.code == 0) {
- const list = res.data.data.list;
- for (let i = 0; i < list.length; i++) {
- _list.push(list[i])
- }
- this.setData({
- list: _list,
- total: res.data.data.total
- })
- }
- }
- })
- },
- checkpage:function(e){
- this.setData({
- act: e.target.dataset.id
- })
- if (e.target.dataset.id == 0){
- this.setChart()
- }
- if (e.target.dataset.id == 1) {
- this.setChart1()
- this.setChart2()
- }
- },
- check:function(e){
- this.setData({
- casci:e.target.dataset.id
- })
- this.setChart()
-
- },
- checknum: function (e) {
- this.setData({
- page: e.target.dataset.id
- })
- this.setChart2()
- },
- setChart:function(){
- var records = [], xdata = [], ydata = [];
- if (this.data.casci == 0) {
- records = this.data.info.days7_casci;
- } else {
- records = this.data.info.days30_casci;
- }
- if (records.length <= 0) {
- return;
- }
- for (let i = 0; i < records.length; i++) {
- // xdata.push(records[i].name)
- let date = records[i].name.split('-');
- xdata.push(date[1] + '/' + date[2])
- ydata.push(records[i].value)
- }
- this.oneComponent = this.selectComponent('#mychart');
- this.init_one(xdata, ydata)
- },
- setChart1: function () {
- var records = [], xdata = [], ydata = [];
- records = this.data.analyse.days7_rank;
- if (records.length <= 0) {
- return;
- }
- for (let i = 0; i < records.length; i++) {
- // xdata.push(records[i].name)
- let date = records[i].name.split('-');
- xdata.push(date[1] + '/' + date[2])
- ydata.push(records[i].value)
- }
- this.oneComponent1 = this.selectComponent('#mychart1');
- this.init_two(xdata, ydata)
- },
- setChart2: function () {
- var records = [], xdata = [], ydata = [];
- if (this.data.page == 0) {
- records = this.data.info.days7_casci_read;
- } else if (this.data.page == 0) {
- records = this.data.info.days7_casci_zan;
- }else{
- records = this.data.info.days7_casci_zhuanfa;
- }
- records = this.data.analyse.days7_casci_zhuanfa;
- if (records.length <= 0) {
- return;
- }
- for (let i = 0; i < records.length; i++) {
- let date = records[i].name.split('-');
- xdata.push(date[1] + '/' + date[2])
- // xdata.push(records[i].name)
- ydata.push(records[i].value)
- }
- this.oneComponent2 = this.selectComponent('#mychart2');
- this.init_three(xdata, ydata)
- },
- init_one: function (xdata, ydata) { //初始化第一个图表
- this.oneComponent.init((canvas, width, height, dpr) => {
- const chart = echarts.init(canvas, null, {
- width: width,
- height: height,
- devicePixelRatio: dpr
- });
- setOption(chart, xdata, ydata)
- this.chart = chart;
- return chart;
- });
- },
- init_two: function (xdata, ydata) { //初始化第一个图表
- this.oneComponent1.init((canvas, width, height, dpr) => {
- const chart = echarts.init(canvas, null, {
- width: width,
- height: height,
- devicePixelRatio: dpr
- });
- setOption(chart, xdata, ydata)
- this.chart = chart;
- return chart;
- });
- },
- init_three: function (xdata, ydata) { //初始化第一个图表
- this.oneComponent2.init((canvas, width, height, dpr) => {
- const chart = echarts.init(canvas, null, {
- width: width,
- height: height,
- devicePixelRatio: dpr
- });
- setOption(chart, xdata, ydata)
- this.chart = chart;
- return chart;
- });
- },
- weixin: function () {
- if (this.data.info.qrcode || this.data.info.wxcode) {
- this.setData({
- show: true
- })
- } else {
- wx.showToast({
- title: '该期刊暂无公众号',
- })
- }
- },
- close: function () {
- this.setData({
- show: false
- })
- },
- view: function () {
- wx.previewImage({
- urls: [this.data.info.qrcode],
- current: this.data.info.qrcode
- })
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- }
- })
- function setOption(chart, xdata, ydata) {
- xdata = xdata.reverse()
- ydata = ydata.reverse()
- let interval=0
- if (xdata.length>10){
- interval=2
- }
- var option = {
- legend: {
- show: false
- },
- backgroundColor:'#F1F4F6',
- grid: {
- x: 50,
- y: 30,
- x2: 10,
- y2: 35
- },
- tooltip: {
- show: true,
- trigger: 'axis',
- formatter: '{b0}: {c0}'
- },
- xAxis: {
- type: 'category',
- data: xdata,
- axisLabel: {
- rotate: 45,
- interval: interval,
- color: '#999999'
- }
- },
- yAxis: {
- axisLine: {
- show: true
- },
- type: 'value',
- name: '',
- axisLabel: {
- formatter: function (value, index) {//隐藏 0
- let texts = [];
- texts.push(value)
- return texts;
- },
- show: true
- },
- },
- series: [{
- name: 'A',
- type: 'line',
- smooth: true,
- symbolSize: 8,
- lineStyle: {
- color: '#FF9F2E'
- // color: new echarts.graphic.LinearGradient(1, 0, 0, 0, [{
- // offset: 0,
- // color: '#FF2D68'
- // }, {
- // offset: 1,
- // color: '#4C4BFF'
- // }]),
- },
- areaStyle: {
- color: {
- //线性渐变
- type: 'linear',
- x:0,
- y:0,
- x2:0,
- y2:1,
- colorStops: [{
- offset: 0, color: 'rgba(255, 159, 46, .5)', // 0% 处的颜色
- }, {
- offset: 1, color: 'rgba(255, 159, 46, .2)', // 100% 处的颜色
- }],
- global: false, // 缺省为 false
- },
- },
- itemStyle: {
- borderWidth: 5,
- borderColor: '#FFAD52',
- color: '#FFAD52'
- },
- data: ydata
- }]
- };
- chart.setOption(option)
- }
|