index.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611
  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. bindViewTap: function() {
  302. wx.navigateTo({
  303. url: '../logs/logs'
  304. })
  305. },
  306. onReady: function (e) {
  307. this.computeScrollViewHeight();
  308. // var query = wx.createSelectorQuery()
  309. // query.select('#test').boundingClientRect(function (res) {
  310. // console.log(res.top);
  311. // }).exec();
  312. },
  313. onLoad: function () {
  314. // this.getNewsList();
  315. let sysinfo = wx.getSystemInfoSync(),
  316. windowHeight = sysinfo.windowHeight,
  317. statusHeight = sysinfo.statusBarHeight,
  318. isiOS = sysinfo.system.indexOf('iOS') > -1,
  319. navHeight;
  320. if (!isiOS) {
  321. navHeight = 48;
  322. } else {
  323. navHeight = 44;
  324. }
  325. let height = windowHeight-statusHeight-navHeight;
  326. this.setData({
  327. height:height
  328. })
  329. // this.echartsComponnet = this.selectComponent('#mychart');
  330. // console.log(this.echartsComponnet);
  331. // //如果是第一次绘制
  332. // if (!Chart) {
  333. // this.init_echarts(); //初始化图表
  334. // } else {
  335. // this.setOption(Chart); //更新数据
  336. // }
  337. // this.computeScrollViewHeight();
  338. // if (app.globalData.userInfo) {
  339. // this.setData({
  340. // userInfo: app.globalData.userInfo,
  341. // hasUserInfo: true
  342. // })
  343. // } else if (this.data.canIUse){
  344. // // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
  345. // // 所以此处加入 callback 以防止这种情况
  346. // app.userInfoReadyCallback = res => {
  347. // this.setData({
  348. // userInfo: res.userInfo,
  349. // hasUserInfo: true
  350. // })
  351. // }
  352. // } else {
  353. // // 在没有 open-type=getUserInfo 版本的兼容处理
  354. // wx.getUserInfo({
  355. // success: res => {
  356. // app.globalData.userInfo = res.userInfo
  357. // this.setData({
  358. // userInfo: res.userInfo,
  359. // hasUserInfo: true
  360. // })
  361. // }
  362. // })
  363. // }
  364. },
  365. computeScrollViewHeight() {
  366. var that = this
  367. let query = wx.createSelectorQuery().in(that)
  368. query.select('.swiper-tab').boundingClientRect()
  369. query.select('.chart').boundingClientRect()
  370. query.select('.news').boundingClientRect()
  371. query.exec(res => {
  372. let topHeight = res[0].height
  373. let searchHeight = res[1].height
  374. let titleHeight = res[2].height
  375. let windowHeight = wx.getSystemInfoSync().windowHeight
  376. let windowWidth = wx.getSystemInfoSync().windowWidth
  377. let height = windowHeight - topHeight - searchHeight - titleHeight
  378. let ratio = 750 / windowWidth
  379. let scrollHeight = height * ratio
  380. that.setData({ scrollHeight: scrollHeight})
  381. })
  382. },
  383. imageLoad: function (e) {
  384. var imageSize = imageUtil.imageUtil(e)
  385. this.setData({
  386. imagewidth: imageSize.imageWidth,
  387. imageheight: imageSize.imageHeight
  388. })
  389. this.computeScrollViewHeight();
  390. },
  391. onFold:function(e){
  392. console.log( e.currentTarget.dataset.id);
  393. wx.navigateTo({
  394. url:"../news/news"
  395. });
  396. },
  397. choose:function(e){
  398. wx.navigateTo({
  399. url:"../filter/filter"
  400. })
  401. },
  402. swichNav: function(e) {
  403. var that = this;
  404. if (this.data.currentTab === e.target.dataset.current) {
  405. return false;
  406. } else {
  407. that.setData({
  408. currentTab: e.target.dataset.current
  409. })
  410. }
  411. },
  412. // 滑动切换tab
  413. bindChange: function(e) {
  414. var that = this;
  415. that.setData({
  416. currentTab: e.detail.current
  417. });
  418. },
  419. catchTouchMove:function(res){
  420. return false
  421. },
  422. getNewsList:function(){
  423. apiServer.getNewsList().then((res)=>{
  424. console.log(res);
  425. })
  426. },
  427. //初始化图表
  428. init_echarts: function () {
  429. this.echartsComponnet.init((canvas, width, height) => {
  430. // 初始化图表
  431. const Chart = echarts.init(canvas, null, {
  432. width: width,
  433. height: height
  434. });
  435. this.setOption(Chart)
  436. // 注意这里一定要返回 chart 实例,否则会影响事件处理等
  437. return Chart
  438. });
  439. },
  440. setOption: function (Chart) {
  441. Chart.clear(); // 清除
  442. Chart.setOption(this.getOption()); //获取新数据
  443. },
  444. // 图表配置项
  445. getOption() {
  446. var self = this;
  447. var option = {
  448. title: {//标题
  449. text: '',
  450. left: 'center'
  451. },
  452. renderAsImage: true, //支持渲染为图片模式
  453. color: ["#DF3E3E", "#80CDF8"],//图例图标颜色
  454. legend: {
  455. // left:'right',
  456. show: true,
  457. itemGap: 25,//每个图例间的间隔
  458. top: 20,
  459. right:20,
  460. x: 100,//水平安放位置,离容器左侧的距离 'left'
  461. z: 100,
  462. textStyle: {
  463. color: '#383838'
  464. },
  465. data: [//图例具体内容
  466. {
  467. name: '实际',
  468. textStyle: {
  469. fontSize: 13,
  470. color: 'white'
  471. },
  472. icon: 'line'
  473. },
  474. {
  475. name: '预测',
  476. textStyle: {
  477. fontSize: 13,
  478. color: 'white'
  479. },
  480. icon: 'line',
  481. }
  482. ]
  483. },
  484. grid: {//网格
  485. // left: 50,
  486. // top:100,
  487. containLabel: true,//grid 区域是否包含坐标轴的刻度标签
  488. },
  489. xAxis: {//横坐标
  490. type: 'category',
  491. // name: '区间',//横坐标名称
  492. nameTextStyle: {//在name值存在下,设置name的样式
  493. color: 'white',
  494. fontStyle: 'normal'
  495. },
  496. nameLocation:'end',
  497. splitLine: {//坐标轴在 grid 区域中的分隔线。
  498. show: true,
  499. lineStyle: {
  500. type: 'dashed',
  501. color: ['#2B2B2B']
  502. }
  503. },
  504. boundaryGap: false,//1.true 数据点在2个刻度直接 2.fals 数据点在分割线上,即刻度值上
  505. data: ['2020/6/29', '2020/6/30', '2020/7/1', '2020/7/2', '2020/7/3'],
  506. axisLine: {onZero: true},
  507. axisLabel: {
  508. textStyle: {
  509. fontSize: 13,
  510. color: '#5D5D5D'
  511. }
  512. }
  513. },
  514. yAxis: {//纵坐标
  515. type: 'value',
  516. position:'right',
  517. name: '股票值',//纵坐标名称
  518. nameTextStyle:{//在name值存在下,设置name的样式
  519. color:'red',
  520. fontStyle:'normal'
  521. },
  522. splitNumber: 5,//坐标轴的分割段数
  523. splitLine: {//坐标轴在 grid 区域中的分隔线。
  524. show: true,
  525. lineStyle: {
  526. type: 'dashed',
  527. color: ['#2B2B2B']
  528. }
  529. },
  530. axisLabel: {//坐标轴刻度标签
  531. // formatter: function (value) {
  532. // var xLable = [];
  533. // if (value == 20) {
  534. // xLable.push('1000');
  535. // }
  536. // if (value == 40) {
  537. // xLable.push('2000');
  538. // }
  539. // if (value == 60) {
  540. // xLable.push('4000');
  541. // }
  542. // if (value == 80) {
  543. // xLable.push('6000');
  544. // }
  545. // return xLable
  546. // },
  547. textStyle: {
  548. fontSize: 13,
  549. color: '#5D5D5D',
  550. }
  551. },
  552. // min: 0,
  553. // max: 100,
  554. },
  555. series: [{
  556. name: '实际',
  557. type: 'line',
  558. // smooth:true,
  559. data: [1888, 3666, 6555, 3000, 7888, 4000, 3333],
  560. symbol: 'none',
  561. areaStyle: {
  562. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
  563. {
  564. offset: 0,
  565. color: '#DF3E3E'
  566. },
  567. {
  568. offset: 1,
  569. color: '#1C1C1C'
  570. }
  571. ])
  572. },
  573. itemStyle: {
  574. normal: {
  575. lineStyle: {
  576. color: '#DF3E3E'
  577. }
  578. }
  579. }
  580. }, {
  581. name: '预测',
  582. type: 'line',
  583. data: [1000, 3000, 3111, 5000, 4000, 2000, 1000],
  584. symbol: 'none',
  585. itemStyle: {
  586. normal: {
  587. lineStyle: {
  588. color: '#80CDF8'
  589. }
  590. }
  591. }
  592. }],
  593. }
  594. return option;
  595. },
  596. getUserInfo: function(e) {
  597. console.log(e)
  598. app.globalData.userInfo = e.detail.userInfo
  599. this.setData({
  600. userInfo: e.detail.userInfo,
  601. hasUserInfo: true
  602. })
  603. }
  604. })