index.js 18 KB

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