index.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618
  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. console.log( e.currentTarget.dataset.id);
  403. wx.navigateTo({
  404. url:"../news/news"
  405. });
  406. },
  407. choose:function(e){
  408. wx.navigateTo({
  409. url:"../filter/filter"
  410. })
  411. },
  412. swichNav: function(e) {
  413. var that = this;
  414. if (this.data.currentTab === e.target.dataset.current) {
  415. return false;
  416. } else {
  417. that.setData({
  418. currentTab: e.target.dataset.current
  419. })
  420. }
  421. },
  422. // 滑动切换tab
  423. bindChange: function(e) {
  424. var that = this;
  425. that.setData({
  426. currentTab: e.detail.current
  427. });
  428. },
  429. catchTouchMove:function(res){
  430. return false
  431. },
  432. //初始化图表
  433. init_echarts: function () {
  434. this.echartsComponnet.init((canvas, width, height) => {
  435. // 初始化图表
  436. const Chart = echarts.init(canvas, null, {
  437. width: width,
  438. height: height
  439. });
  440. this.setOption(Chart)
  441. // 注意这里一定要返回 chart 实例,否则会影响事件处理等
  442. return Chart
  443. });
  444. },
  445. setOption: function (Chart) {
  446. Chart.clear(); // 清除
  447. Chart.setOption(this.getOption()); //获取新数据
  448. },
  449. // 图表配置项
  450. getOption() {
  451. var self = this;
  452. var option = {
  453. title: {//标题
  454. text: '',
  455. left: 'center'
  456. },
  457. renderAsImage: true, //支持渲染为图片模式
  458. color: ["#DF3E3E", "#80CDF8"],//图例图标颜色
  459. legend: {
  460. // left:'right',
  461. show: true,
  462. itemGap: 25,//每个图例间的间隔
  463. top: 20,
  464. right:20,
  465. x: 100,//水平安放位置,离容器左侧的距离 'left'
  466. z: 100,
  467. textStyle: {
  468. color: '#383838'
  469. },
  470. data: [//图例具体内容
  471. {
  472. name: '实际',
  473. textStyle: {
  474. fontSize: 13,
  475. color: 'white'
  476. },
  477. icon: 'line'
  478. },
  479. {
  480. name: '预测',
  481. textStyle: {
  482. fontSize: 13,
  483. color: 'white'
  484. },
  485. icon: 'line',
  486. }
  487. ]
  488. },
  489. grid: {//网格
  490. // left: 50,
  491. // top:100,
  492. containLabel: true,//grid 区域是否包含坐标轴的刻度标签
  493. },
  494. xAxis: {//横坐标
  495. type: 'category',
  496. // name: '区间',//横坐标名称
  497. nameTextStyle: {//在name值存在下,设置name的样式
  498. color: 'white',
  499. fontStyle: 'normal'
  500. },
  501. nameLocation:'end',
  502. splitLine: {//坐标轴在 grid 区域中的分隔线。
  503. show: true,
  504. lineStyle: {
  505. type: 'dashed',
  506. color: ['#2B2B2B']
  507. }
  508. },
  509. boundaryGap: false,//1.true 数据点在2个刻度直接 2.fals 数据点在分割线上,即刻度值上
  510. data: ['2020/6/29', '2020/6/30', '2020/7/1', '2020/7/2', '2020/7/3'],
  511. axisLine: {onZero: true},
  512. axisLabel: {
  513. textStyle: {
  514. fontSize: 13,
  515. color: '#5D5D5D'
  516. }
  517. }
  518. },
  519. yAxis: {//纵坐标
  520. type: 'value',
  521. position:'right',
  522. name: '股票值',//纵坐标名称
  523. nameTextStyle:{//在name值存在下,设置name的样式
  524. color:'red',
  525. fontStyle:'normal'
  526. },
  527. splitNumber: 5,//坐标轴的分割段数
  528. splitLine: {//坐标轴在 grid 区域中的分隔线。
  529. show: true,
  530. lineStyle: {
  531. type: 'dashed',
  532. color: ['#2B2B2B']
  533. }
  534. },
  535. axisLabel: {//坐标轴刻度标签
  536. // formatter: function (value) {
  537. // var xLable = [];
  538. // if (value == 20) {
  539. // xLable.push('1000');
  540. // }
  541. // if (value == 40) {
  542. // xLable.push('2000');
  543. // }
  544. // if (value == 60) {
  545. // xLable.push('4000');
  546. // }
  547. // if (value == 80) {
  548. // xLable.push('6000');
  549. // }
  550. // return xLable
  551. // },
  552. textStyle: {
  553. fontSize: 13,
  554. color: '#5D5D5D',
  555. }
  556. },
  557. // min: 0,
  558. // max: 100,
  559. },
  560. series: [{
  561. name: '实际',
  562. type: 'line',
  563. // smooth:true,
  564. data: [1888, 3666, 6555, 3000, 7888, 4000, 3333],
  565. symbol: 'none',
  566. areaStyle: {
  567. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
  568. {
  569. offset: 0,
  570. color: '#DF3E3E'
  571. },
  572. {
  573. offset: 1,
  574. color: '#1C1C1C'
  575. }
  576. ])
  577. },
  578. itemStyle: {
  579. normal: {
  580. lineStyle: {
  581. color: '#DF3E3E'
  582. }
  583. }
  584. }
  585. }, {
  586. name: '预测',
  587. type: 'line',
  588. data: [1000, 3000, 3111, 5000, 4000, 2000, 1000],
  589. symbol: 'none',
  590. itemStyle: {
  591. normal: {
  592. lineStyle: {
  593. color: '#80CDF8'
  594. }
  595. }
  596. }
  597. }],
  598. }
  599. return option;
  600. },
  601. getUserInfo: function(e) {
  602. console.log(e)
  603. app.globalData.userInfo = e.detail.userInfo
  604. this.setData({
  605. userInfo: e.detail.userInfo,
  606. hasUserInfo: true
  607. })
  608. }
  609. })