index.js 18 KB

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