index.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617
  1. //index.js
  2. //获取应用实例
  3. import * as echarts from '../../ec-canvas/echarts';
  4. var imageUtil = require('../../utils/window.js');
  5. const apiServer = require('../../api/request');
  6. var Chart = null;
  7. const app = getApp()
  8. var timeData = [
  9. '2020/6/1', '2009/6/2', '2009/6/3', '2009/6/4', '2009/6/5', '2009/6/6', '2009/6/7', '2009/6/8', '2009/6/9', '2009/6/10',
  10. ];
  11. timeData = timeData.map(function (str) {
  12. return str.replace('2009/', '');
  13. });
  14. function initChart(canvas, width, height, dpr, data) {
  15. const chart = echarts.init(canvas, null, {
  16. width: width,
  17. height: height,
  18. devicePixelRatio: dpr // new
  19. });
  20. canvas.setChart(chart);
  21. var option = {
  22. title: {//标题
  23. text: '',
  24. left: 'center'
  25. },
  26. renderAsImage: true, //支持渲染为图片模式
  27. color: ["#DF3E3E", "#80CDF8"],//图例图标颜色
  28. legend: {
  29. show: true,
  30. itemGap: 25,//每个图例间的间隔
  31. top: 30,
  32. x: 30,//水平安放位置,离容器左侧的距离 'left'
  33. z: 100,
  34. textStyle: {
  35. color: '#383838'
  36. },
  37. },
  38. grid: {//网格
  39. // left: 30,
  40. // top:100,
  41. containLabel: true,//grid 区域是否包含坐标轴的刻度标签
  42. },
  43. xAxis: {//横坐标
  44. type: 'category',
  45. // nameTextStyle: {//在name值存在下,设置name的样式
  46. // color: 'white',
  47. // fontStyle: 'normal'
  48. // },
  49. nameLocation:'end',
  50. splitLine: {//坐标轴在 grid 区域中的分隔线。
  51. show: true,
  52. lineStyle: {
  53. type: 'dashed',
  54. color: ['#2B2B2B']
  55. }
  56. },
  57. boundaryGap: false,//1.true 数据点在2个刻度直接 2.fals 数据点在分割线上,即刻度值上
  58. data: data.timeData,
  59. axisLine: {onZero: true},
  60. axisLabel: {
  61. textStyle: {
  62. fontSize: 13,
  63. color: '#5D5D5D'
  64. }
  65. }
  66. },
  67. dataZoom: [
  68. {
  69. type: 'slider',
  70. xAxisIndex: 0,
  71. filterMode: 'empty'
  72. },
  73. ],
  74. yAxis: {//纵坐标
  75. type: 'value',
  76. position:'right',
  77. // nameTextStyle:{//在name值存在下,设置name的样式
  78. // color:'red',
  79. // fontStyle:'normal'
  80. // },
  81. splitNumber: 5,//坐标轴的分割段数
  82. splitLine: {//坐标轴在 grid 区域中的分隔线。
  83. show: true,
  84. lineStyle: {
  85. type: 'dashed',
  86. color: ['#2B2B2B']
  87. }
  88. },
  89. axisLabel: {//坐标轴刻度标签
  90. // formatter: function (value) {
  91. // var xLable = [];
  92. // if (value == 20) {
  93. // xLable.push('25,883');
  94. // }
  95. // if (value == 40) {
  96. // xLable.push('26,035');
  97. // }
  98. // if (value == 60) {
  99. // xLable.push('26,187');
  100. // }
  101. // if (value == 80) {
  102. // xLable.push('26,339');
  103. // }
  104. // return xLable
  105. // },
  106. textStyle: {
  107. fontSize: 13,
  108. color: '#5D5D5D',
  109. }
  110. },
  111. // min: 0,
  112. // max: 100,
  113. },
  114. series: [{
  115. name: '实际',
  116. type: 'line',
  117. // smooth:true,
  118. data:data.actual,
  119. symbol: 'none',
  120. areaStyle: {
  121. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
  122. offset: 0,
  123. color: '#DF3E3E'
  124. }, {
  125. offset: 1,
  126. color: '#1C1C1C'
  127. }])
  128. },
  129. itemStyle: {
  130. normal: {
  131. lineStyle: {
  132. color: '#DF3E3E'
  133. }
  134. }
  135. }
  136. }, {
  137. name: '预测',
  138. type: 'line',
  139. data: data.prediction,
  140. symbol: 'none',
  141. itemStyle: {
  142. normal: {
  143. lineStyle: {
  144. color: '#80CDF8'
  145. }
  146. }
  147. }
  148. }],
  149. };
  150. chart.setOption(option);
  151. return chart;
  152. }
  153. Page({
  154. data: {
  155. url:'../../images/timg.jpg',
  156. motto: '',
  157. currentTab: 0,
  158. userInfo: {},
  159. hasUserInfo: false,
  160. canIUse: wx.canIUse('button.open-type.getUserInfo'),
  161. imagewidth: 0,//缩放后的宽
  162. imageheight: 0,//缩放后的高
  163. chartData:{
  164. actual:[552,586,3555,4454,552,556,4455],
  165. prediction:[552,546,3585,4424,542,546,35,44,524,56,355,444,2224,421],
  166. timeData : [
  167. '2020/6/1', '2020/6/2', '2020/6/3', '2020/6/4', '2020/6/5', '2020/6/6', '2020/6/7', '2020/6/8', '2020/6/9', '2020/6/10','2020/6/11',
  168. '2020/6/12','2020/6/13','2020/6/14',
  169. ]
  170. },
  171. chartDatas:{
  172. actual:[572,556,3555,4744,552,576,3555],
  173. prediction:[352,246,385,2424,542,546,255],
  174. timeData : [
  175. '2020/6/1', '2020/6/2', '2020/6/3', '2020/6/4', '2020/6/5', '2020/6/6', '2020/6/7'
  176. ]
  177. },
  178. ec: {
  179. onInit: initChart
  180. },
  181. // ec: {
  182. // onInit: function (canvas, width, height) {
  183. // chart = echarts.init(canvas, null, {
  184. // width: width,
  185. // height: height
  186. // });
  187. // canvas.setChart(chart);
  188. // return chart;
  189. // },
  190. // lazyLoad: true // 延迟加载
  191. // },
  192. aa:[
  193. {
  194. id:'0',
  195. from:"Investing.com 中文",
  196. nickName:"买入波音(BA.US)好时机?两个问题没解决之前劝你住手",
  197. reward:"今年迄今,美股航空板块受到公共卫生事件的冲击.....",
  198. time:"6天前"
  199. },
  200. {
  201. id:'1',
  202. from:"chinese.aljazeera.net",
  203. nickName: "波音裁员超1.2万人与警惕最坏时刻尚未到来",
  204. reward: "波音公司当地时间27日宣布,将在美国裁减超1...",
  205. time:"6天前"
  206. },
  207. {
  208. id:'2',
  209. from:"Investing.com 中文",
  210. nickName: "美股异动|波音737MAX客机恢复生产,盘前涨逾5%",
  211. reward: "Reuters.美股异动|波音(BA.US)737MAX客...",
  212. time:"5天前"
  213. },
  214. {
  215. id:'3',
  216. from:"Investing.com 中文",
  217. nickName:"买入波音(BA.US)好时机?两个问题没解决之前劝你住手",
  218. reward:"今年迄今,美股航空板块受到公共卫生事件的冲击.....",
  219. time:"6天前"
  220. },
  221. {
  222. id:'4',
  223. from:"chinese.aljazeera.net",
  224. nickName: "波音裁员超1.2万人与警惕最坏时刻尚未到来",
  225. reward: "波音公司当地时间27日宣布,将在美国裁减超1...",
  226. time:"6天前"
  227. },
  228. {
  229. id:'5',
  230. from:"Investing.com 中文",
  231. nickName: "美股异动|波音737MAX客机恢复生产,盘前涨逾5%",
  232. reward: "Reuters.美股异动|波音(BA.US)737MAX客...",
  233. time:"5天前"
  234. },
  235. {
  236. id:'6',
  237. from:"Investing.com 中文",
  238. nickName:"买入波音(BA.US)好时机?两个问题没解决之前劝你住手",
  239. reward:"今年迄今,美股航空板块受到公共卫生事件的冲击.....",
  240. time:"6天前"
  241. },
  242. {
  243. id:'7',
  244. from:"chinese.aljazeera.net",
  245. nickName: "波音裁员超1.2万人与警惕最坏时刻尚未到来",
  246. reward: "波音公司当地时间27日宣布,将在美国裁减超1...",
  247. time:"6天前"
  248. },
  249. {
  250. id:'8',
  251. from:"Investing.com 中文",
  252. nickName: "美股异动|波音737MAX客机恢复生产,盘前涨逾5%",
  253. reward: "Reuters.美股异动|波音(BA.US)737MAX客...",
  254. time:"5天前"
  255. },
  256. {
  257. id:'9',
  258. from:"Investing.com 中文",
  259. nickName:"买入波音(BA.US)好时机?两个问题没解决之前劝你住手",
  260. reward:"今年迄今,美股航空板块受到公共卫生事件的冲击.....",
  261. time:"6天前"
  262. },
  263. {
  264. id:'10',
  265. from:"chinese.aljazeera.net",
  266. nickName: "波音裁员超1.2万人与警惕最坏时刻尚未到来",
  267. reward: "波音公司当地时间27日宣布,将在美国裁减超1...",
  268. time:"6天前"
  269. },
  270. {
  271. id:'11',
  272. from:"Investing.com 中文",
  273. nickName: "美股异动|波音737MAX客机恢复生产,盘前涨逾5%",
  274. reward: "Reuters.美股异动|波音(BA.US)737MAX客...",
  275. time:"5天前"
  276. },
  277. {
  278. id:'12',
  279. from:"Investing.com 中文",
  280. nickName:"买入波音(BA.US)好时机?两个问题没解决之前劝你住手",
  281. reward:"今年迄今,美股航空板块受到公共卫生事件的冲击.....",
  282. time:"6天前"
  283. },
  284. {
  285. id:'13',
  286. from:"chinese.aljazeera.net",
  287. nickName: "波音裁员超1.2万人与警惕最坏时刻尚未到来",
  288. reward: "波音公司当地时间27日宣布,将在美国裁减超1...",
  289. time:"6天前"
  290. },
  291. {
  292. id:'14',
  293. from:"Investing.com 中文",
  294. nickName: "美股异动|波音737MAX客机恢复生产,盘前涨逾5%",
  295. reward: "Reuters.美股异动|波音(BA.US)737MAX客...",
  296. time:"5天前"
  297. },
  298. ],
  299. },
  300. //获取新闻列表
  301. getNewsList:function(){
  302. apiServer.getNewsList().then((res)=>{
  303. if(res.statusCode == 200){
  304. this.setData({
  305. aa:res.data.data
  306. })
  307. }
  308. })
  309. },
  310. //事件处理函数
  311. bindViewTap: function() {
  312. wx.navigateTo({
  313. url: '../logs/logs'
  314. })
  315. },
  316. onReady: function (e) {
  317. this.computeScrollViewHeight();
  318. // var query = wx.createSelectorQuery()
  319. // query.select('#test').boundingClientRect(function (res) {
  320. // console.log(res.top);
  321. // }).exec();
  322. },
  323. onLoad: function () {
  324. this.getNewsList();
  325. let sysinfo = wx.getSystemInfoSync(),
  326. windowHeight = sysinfo.windowHeight,
  327. statusHeight = sysinfo.statusBarHeight,
  328. isiOS = sysinfo.system.indexOf('iOS') > -1,
  329. navHeight;
  330. if (!isiOS) {
  331. navHeight = 48;
  332. } else {
  333. navHeight = 44;
  334. }
  335. let height = windowHeight-statusHeight-navHeight;
  336. this.setData({
  337. height:height
  338. })
  339. // this.echartsComponnet = this.selectComponent('#mychart');
  340. // console.log(this.echartsComponnet);
  341. // //如果是第一次绘制
  342. // if (!Chart) {
  343. // this.init_echarts(); //初始化图表
  344. // } else {
  345. // this.setOption(Chart); //更新数据
  346. // }
  347. // this.computeScrollViewHeight();
  348. // if (app.globalData.userInfo) {
  349. // this.setData({
  350. // userInfo: app.globalData.userInfo,
  351. // hasUserInfo: true
  352. // })
  353. // } else if (this.data.canIUse){
  354. // // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
  355. // // 所以此处加入 callback 以防止这种情况
  356. // app.userInfoReadyCallback = res => {
  357. // this.setData({
  358. // userInfo: res.userInfo,
  359. // hasUserInfo: true
  360. // })
  361. // }
  362. // } else {
  363. // // 在没有 open-type=getUserInfo 版本的兼容处理
  364. // wx.getUserInfo({
  365. // success: res => {
  366. // app.globalData.userInfo = res.userInfo
  367. // this.setData({
  368. // userInfo: res.userInfo,
  369. // hasUserInfo: true
  370. // })
  371. // }
  372. // })
  373. // }
  374. },
  375. computeScrollViewHeight() {
  376. var that = this
  377. let query = wx.createSelectorQuery().in(that)
  378. query.select('.swiper-tab').boundingClientRect()
  379. query.select('.chart').boundingClientRect()
  380. query.select('.news').boundingClientRect()
  381. query.exec(res => {
  382. let topHeight = res[0].height
  383. let searchHeight = res[1].height
  384. let titleHeight = res[2].height
  385. let windowHeight = wx.getSystemInfoSync().windowHeight
  386. let windowWidth = wx.getSystemInfoSync().windowWidth
  387. let height = windowHeight - topHeight - searchHeight - titleHeight
  388. let ratio = 750 / windowWidth
  389. let scrollHeight = height * ratio
  390. that.setData({ scrollHeight: scrollHeight})
  391. })
  392. },
  393. imageLoad: function (e) {
  394. var imageSize = imageUtil.imageUtil(e)
  395. this.setData({
  396. imagewidth: imageSize.imageWidth,
  397. imageheight: imageSize.imageHeight
  398. })
  399. this.computeScrollViewHeight();
  400. },
  401. onFold:function(e){
  402. wx.navigateTo({
  403. url:'../news/news?newsId='+e.currentTarget.dataset.id
  404. });
  405. },
  406. choose:function(e){
  407. wx.navigateTo({
  408. url:"../filter/filter"
  409. })
  410. },
  411. swichNav: function(e) {
  412. var that = this;
  413. if (this.data.currentTab === e.target.dataset.current) {
  414. return false;
  415. } else {
  416. that.setData({
  417. currentTab: e.target.dataset.current
  418. })
  419. }
  420. },
  421. // 滑动切换tab
  422. bindChange: function(e) {
  423. var that = this;
  424. that.setData({
  425. currentTab: e.detail.current
  426. });
  427. },
  428. catchTouchMove:function(res){
  429. return false
  430. },
  431. //初始化图表
  432. init_echarts: function () {
  433. this.echartsComponnet.init((canvas, width, height) => {
  434. // 初始化图表
  435. const Chart = echarts.init(canvas, null, {
  436. width: width,
  437. height: height
  438. });
  439. this.setOption(Chart)
  440. // 注意这里一定要返回 chart 实例,否则会影响事件处理等
  441. return Chart
  442. });
  443. },
  444. setOption: function (Chart) {
  445. Chart.clear(); // 清除
  446. Chart.setOption(this.getOption()); //获取新数据
  447. },
  448. // 图表配置项
  449. getOption() {
  450. var self = this;
  451. var option = {
  452. title: {//标题
  453. text: '',
  454. left: 'center'
  455. },
  456. renderAsImage: true, //支持渲染为图片模式
  457. color: ["#DF3E3E", "#80CDF8"],//图例图标颜色
  458. legend: {
  459. // left:'right',
  460. show: true,
  461. itemGap: 25,//每个图例间的间隔
  462. top: 20,
  463. right:20,
  464. x: 100,//水平安放位置,离容器左侧的距离 'left'
  465. z: 100,
  466. textStyle: {
  467. color: '#383838'
  468. },
  469. data: [//图例具体内容
  470. {
  471. name: '实际',
  472. textStyle: {
  473. fontSize: 13,
  474. color: 'white'
  475. },
  476. icon: 'line'
  477. },
  478. {
  479. name: '预测',
  480. textStyle: {
  481. fontSize: 13,
  482. color: 'white'
  483. },
  484. icon: 'line',
  485. }
  486. ]
  487. },
  488. grid: {//网格
  489. // left: 50,
  490. // top:100,
  491. containLabel: true,//grid 区域是否包含坐标轴的刻度标签
  492. },
  493. xAxis: {//横坐标
  494. type: 'category',
  495. // name: '区间',//横坐标名称
  496. nameTextStyle: {//在name值存在下,设置name的样式
  497. color: 'white',
  498. fontStyle: 'normal'
  499. },
  500. nameLocation:'end',
  501. splitLine: {//坐标轴在 grid 区域中的分隔线。
  502. show: true,
  503. lineStyle: {
  504. type: 'dashed',
  505. color: ['#2B2B2B']
  506. }
  507. },
  508. boundaryGap: false,//1.true 数据点在2个刻度直接 2.fals 数据点在分割线上,即刻度值上
  509. data: ['2020/6/29', '2020/6/30', '2020/7/1', '2020/7/2', '2020/7/3'],
  510. axisLine: {onZero: true},
  511. axisLabel: {
  512. textStyle: {
  513. fontSize: 13,
  514. color: '#5D5D5D'
  515. }
  516. }
  517. },
  518. yAxis: {//纵坐标
  519. type: 'value',
  520. position:'right',
  521. name: '股票值',//纵坐标名称
  522. nameTextStyle:{//在name值存在下,设置name的样式
  523. color:'red',
  524. fontStyle:'normal'
  525. },
  526. splitNumber: 5,//坐标轴的分割段数
  527. splitLine: {//坐标轴在 grid 区域中的分隔线。
  528. show: true,
  529. lineStyle: {
  530. type: 'dashed',
  531. color: ['#2B2B2B']
  532. }
  533. },
  534. axisLabel: {//坐标轴刻度标签
  535. // formatter: function (value) {
  536. // var xLable = [];
  537. // if (value == 20) {
  538. // xLable.push('1000');
  539. // }
  540. // if (value == 40) {
  541. // xLable.push('2000');
  542. // }
  543. // if (value == 60) {
  544. // xLable.push('4000');
  545. // }
  546. // if (value == 80) {
  547. // xLable.push('6000');
  548. // }
  549. // return xLable
  550. // },
  551. textStyle: {
  552. fontSize: 13,
  553. color: '#5D5D5D',
  554. }
  555. },
  556. // min: 0,
  557. // max: 100,
  558. },
  559. series: [{
  560. name: '实际',
  561. type: 'line',
  562. // smooth:true,
  563. data: [1888, 3666, 6555, 3000, 7888, 4000, 3333],
  564. symbol: 'none',
  565. areaStyle: {
  566. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
  567. {
  568. offset: 0,
  569. color: '#DF3E3E'
  570. },
  571. {
  572. offset: 1,
  573. color: '#1C1C1C'
  574. }
  575. ])
  576. },
  577. itemStyle: {
  578. normal: {
  579. lineStyle: {
  580. color: '#DF3E3E'
  581. }
  582. }
  583. }
  584. }, {
  585. name: '预测',
  586. type: 'line',
  587. data: [1000, 3000, 3111, 5000, 4000, 2000, 1000],
  588. symbol: 'none',
  589. itemStyle: {
  590. normal: {
  591. lineStyle: {
  592. color: '#80CDF8'
  593. }
  594. }
  595. }
  596. }],
  597. }
  598. return option;
  599. },
  600. getUserInfo: function(e) {
  601. console.log(e)
  602. app.globalData.userInfo = e.detail.userInfo
  603. this.setData({
  604. userInfo: e.detail.userInfo,
  605. hasUserInfo: true
  606. })
  607. }
  608. })