index.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  1. //index.js
  2. //获取应用实例
  3. import * as echarts from '../../ec-canvas/echarts';
  4. var imageUtil = require('../../utils/window.js');
  5. var Chart=null;
  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. imagewidth: 0,//缩放后的宽
  16. imageheight: 0,//缩放后的高
  17. ec: {
  18. onInit: function (canvas, width, height) {
  19. chart = echarts.init(canvas, null, {
  20. width: width,
  21. height: height
  22. });
  23. canvas.setChart(chart);
  24. return chart;
  25. },
  26. lazyLoad: true // 延迟加载
  27. },
  28. aa:[
  29. {
  30. id:'0',
  31. from:"Investing.com 中文",
  32. nickName:"买入波音(BA.US)好时机?两个问题没解决之前劝你住手",
  33. reward:"今年迄今,美股航空板块受到公共卫生事件的冲击.....",
  34. time:"6天前"
  35. },
  36. {
  37. id:'1',
  38. from:"chinese.aljazeera.net",
  39. nickName: "波音裁员超1.2万人与警惕最坏时刻尚未到来",
  40. reward: "波音公司当地时间27日宣布,将在美国裁减超1...",
  41. time:"6天前"
  42. },
  43. {
  44. id:'2',
  45. from:"Investing.com 中文",
  46. nickName: "美股异动|波音737MAX客机恢复生产,盘前涨逾5%",
  47. reward: "Reuters.美股异动|波音(BA.US)737MAX客...",
  48. time:"5天前"
  49. },
  50. {
  51. id:'3',
  52. from:"Investing.com 中文",
  53. nickName:"买入波音(BA.US)好时机?两个问题没解决之前劝你住手",
  54. reward:"今年迄今,美股航空板块受到公共卫生事件的冲击.....",
  55. time:"6天前"
  56. },
  57. {
  58. id:'4',
  59. from:"chinese.aljazeera.net",
  60. nickName: "波音裁员超1.2万人与警惕最坏时刻尚未到来",
  61. reward: "波音公司当地时间27日宣布,将在美国裁减超1...",
  62. time:"6天前"
  63. },
  64. {
  65. id:'5',
  66. from:"Investing.com 中文",
  67. nickName: "美股异动|波音737MAX客机恢复生产,盘前涨逾5%",
  68. reward: "Reuters.美股异动|波音(BA.US)737MAX客...",
  69. time:"5天前"
  70. },
  71. {
  72. id:'6',
  73. from:"Investing.com 中文",
  74. nickName:"买入波音(BA.US)好时机?两个问题没解决之前劝你住手",
  75. reward:"今年迄今,美股航空板块受到公共卫生事件的冲击.....",
  76. time:"6天前"
  77. },
  78. {
  79. id:'7',
  80. from:"chinese.aljazeera.net",
  81. nickName: "波音裁员超1.2万人与警惕最坏时刻尚未到来",
  82. reward: "波音公司当地时间27日宣布,将在美国裁减超1...",
  83. time:"6天前"
  84. },
  85. {
  86. id:'8',
  87. from:"Investing.com 中文",
  88. nickName: "美股异动|波音737MAX客机恢复生产,盘前涨逾5%",
  89. reward: "Reuters.美股异动|波音(BA.US)737MAX客...",
  90. time:"5天前"
  91. },
  92. {
  93. id:'9',
  94. from:"Investing.com 中文",
  95. nickName:"买入波音(BA.US)好时机?两个问题没解决之前劝你住手",
  96. reward:"今年迄今,美股航空板块受到公共卫生事件的冲击.....",
  97. time:"6天前"
  98. },
  99. {
  100. id:'10',
  101. from:"chinese.aljazeera.net",
  102. nickName: "波音裁员超1.2万人与警惕最坏时刻尚未到来",
  103. reward: "波音公司当地时间27日宣布,将在美国裁减超1...",
  104. time:"6天前"
  105. },
  106. {
  107. id:'11',
  108. from:"Investing.com 中文",
  109. nickName: "美股异动|波音737MAX客机恢复生产,盘前涨逾5%",
  110. reward: "Reuters.美股异动|波音(BA.US)737MAX客...",
  111. time:"5天前"
  112. },
  113. {
  114. id:'12',
  115. from:"Investing.com 中文",
  116. nickName:"买入波音(BA.US)好时机?两个问题没解决之前劝你住手",
  117. reward:"今年迄今,美股航空板块受到公共卫生事件的冲击.....",
  118. time:"6天前"
  119. },
  120. {
  121. id:'13',
  122. from:"chinese.aljazeera.net",
  123. nickName: "波音裁员超1.2万人与警惕最坏时刻尚未到来",
  124. reward: "波音公司当地时间27日宣布,将在美国裁减超1...",
  125. time:"6天前"
  126. },
  127. {
  128. id:'14',
  129. from:"Investing.com 中文",
  130. nickName: "美股异动|波音737MAX客机恢复生产,盘前涨逾5%",
  131. reward: "Reuters.美股异动|波音(BA.US)737MAX客...",
  132. time:"5天前"
  133. },
  134. ],
  135. },
  136. //事件处理函数
  137. bindViewTap: function() {
  138. wx.navigateTo({
  139. url: '../logs/logs'
  140. })
  141. },
  142. onReady: function (e) {
  143. this.computeScrollViewHeight();
  144. // var query = wx.createSelectorQuery()
  145. // query.select('#test').boundingClientRect(function (res) {
  146. // console.log(res.top);
  147. // }).exec();
  148. },
  149. onLoad: function () {
  150. let sysinfo = wx.getSystemInfoSync(),
  151. windowHeight = sysinfo.windowHeight,
  152. statusHeight = sysinfo.statusBarHeight,
  153. isiOS = sysinfo.system.indexOf('iOS') > -1,
  154. navHeight;
  155. if (!isiOS) {
  156. navHeight = 48;
  157. } else {
  158. navHeight = 44;
  159. }
  160. let height = windowHeight-statusHeight-navHeight;
  161. this.setData({
  162. height:height
  163. })
  164. this.echartsComponnet = this.selectComponent('#mychart');
  165. console.log(this.echartsComponnet);
  166. //如果是第一次绘制
  167. if (!Chart) {
  168. this.init_echarts(); //初始化图表
  169. } else {
  170. this.setOption(Chart); //更新数据
  171. }
  172. // this.computeScrollViewHeight();
  173. // if (app.globalData.userInfo) {
  174. // this.setData({
  175. // userInfo: app.globalData.userInfo,
  176. // hasUserInfo: true
  177. // })
  178. // } else if (this.data.canIUse){
  179. // // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
  180. // // 所以此处加入 callback 以防止这种情况
  181. // app.userInfoReadyCallback = res => {
  182. // this.setData({
  183. // userInfo: res.userInfo,
  184. // hasUserInfo: true
  185. // })
  186. // }
  187. // } else {
  188. // // 在没有 open-type=getUserInfo 版本的兼容处理
  189. // wx.getUserInfo({
  190. // success: res => {
  191. // app.globalData.userInfo = res.userInfo
  192. // this.setData({
  193. // userInfo: res.userInfo,
  194. // hasUserInfo: true
  195. // })
  196. // }
  197. // })
  198. // }
  199. },
  200. computeScrollViewHeight() {
  201. var that = this
  202. let query = wx.createSelectorQuery().in(that)
  203. query.select('.swiper-tab').boundingClientRect()
  204. query.select('.chart').boundingClientRect()
  205. query.select('.news').boundingClientRect()
  206. query.exec(res => {
  207. let topHeight = res[0].height
  208. let searchHeight = res[1].height
  209. let titleHeight = res[2].height
  210. let windowHeight = wx.getSystemInfoSync().windowHeight
  211. let windowWidth = wx.getSystemInfoSync().windowWidth
  212. let height = windowHeight - topHeight - searchHeight - titleHeight
  213. let ratio = 750 / windowWidth
  214. let scrollHeight = height * ratio
  215. that.setData({ scrollHeight: scrollHeight})
  216. })
  217. },
  218. imageLoad: function (e) {
  219. var imageSize = imageUtil.imageUtil(e)
  220. this.setData({
  221. imagewidth: imageSize.imageWidth,
  222. imageheight: imageSize.imageHeight
  223. })
  224. this.computeScrollViewHeight();
  225. },
  226. onFold:function(e){
  227. console.log( e.currentTarget.dataset.id);
  228. wx.navigateTo({
  229. url:"../news/news"
  230. });
  231. },
  232. choose:function(e){
  233. wx.navigateTo({
  234. url:"../filter/filter"
  235. })
  236. },
  237. swichNav: function(e) {
  238. var that = this;
  239. if (this.data.currentTab === e.target.dataset.current) {
  240. return false;
  241. } else {
  242. that.init_echarts();
  243. that.setData({
  244. currentTab: e.target.dataset.current
  245. })
  246. }
  247. },
  248. //初始化图表
  249. init_echarts: function () {
  250. this.echartsComponnet.init((canvas, width, height) => {
  251. // 初始化图表
  252. const Chart = echarts.init(canvas, null, {
  253. width: width,
  254. height: height
  255. });
  256. this.setOption(Chart)
  257. // 注意这里一定要返回 chart 实例,否则会影响事件处理等
  258. return Chart
  259. });
  260. },
  261. setOption: function (Chart) {
  262. Chart.clear(); // 清除
  263. Chart.setOption(this.getOption()); //获取新数据
  264. },
  265. // 图表配置项
  266. getOption() {
  267. var self = this;
  268. var option = {
  269. title: {//标题
  270. text: '',
  271. left: 'center'
  272. },
  273. renderAsImage: true, //支持渲染为图片模式
  274. color: ["#DF3E3E", "#80CDF8"],//图例图标颜色
  275. legend: {
  276. // left:'right',
  277. show: true,
  278. itemGap: 25,//每个图例间的间隔
  279. top: 20,
  280. right:20,
  281. x: 100,//水平安放位置,离容器左侧的距离 'left'
  282. z: 100,
  283. textStyle: {
  284. color: '#383838'
  285. },
  286. data: [//图例具体内容
  287. {
  288. name: '实际',
  289. textStyle: {
  290. fontSize: 13,
  291. color: 'white'
  292. },
  293. icon: 'line'
  294. },
  295. {
  296. name: '预测',
  297. textStyle: {
  298. fontSize: 13,
  299. color: 'white'
  300. },
  301. icon: 'line',
  302. }
  303. ]
  304. },
  305. grid: {//网格
  306. left: 30,
  307. top:100,
  308. containLabel: true,//grid 区域是否包含坐标轴的刻度标签
  309. },
  310. xAxis: {//横坐标
  311. type: 'category',
  312. name: '区间',//横坐标名称
  313. nameTextStyle: {//在name值存在下,设置name的样式
  314. color: 'white',
  315. fontStyle: 'normal'
  316. },
  317. nameLocation:'end',
  318. splitLine: {//坐标轴在 grid 区域中的分隔线。
  319. show: true,
  320. lineStyle: {
  321. type: 'dashed'
  322. }
  323. },
  324. boundaryGap: false,//1.true 数据点在2个刻度直接 2.fals 数据点在分割线上,即刻度值上
  325. data: ['10', '11', '12', '13', '14', '15', '16'],
  326. axisLabel: {
  327. textStyle: {
  328. fontSize: 13,
  329. color: '#5D5D5D'
  330. }
  331. }
  332. },
  333. yAxis: {//纵坐标
  334. type: 'value',
  335. position:'right',
  336. name: '股票值',//纵坐标名称
  337. nameTextStyle:{//在name值存在下,设置name的样式
  338. color:'red',
  339. fontStyle:'normal'
  340. },
  341. splitNumber: 5,//坐标轴的分割段数
  342. splitLine: {//坐标轴在 grid 区域中的分隔线。
  343. show: true,
  344. lineStyle: {
  345. type: 'dashed'
  346. }
  347. },
  348. axisLabel: {//坐标轴刻度标签
  349. formatter: function (value) {
  350. var xLable = [];
  351. if (value == 20) {
  352. xLable.push('25,883');
  353. }
  354. if (value == 40) {
  355. xLable.push('26,035');
  356. }
  357. if (value == 60) {
  358. xLable.push('26,187');
  359. }
  360. if (value == 80) {
  361. xLable.push('26,339');
  362. }
  363. return xLable
  364. },
  365. textStyle: {
  366. fontSize: 13,
  367. color: '#5D5D5D',
  368. }
  369. },
  370. min: 0,
  371. max: 100,
  372. },
  373. series: [{
  374. name: '实际',
  375. type: 'line',
  376. // smooth:true,
  377. data: [18, 36, 65, 30, 78, 40, 33],
  378. symbol: 'none',
  379. areaStyle: {
  380. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
  381. {
  382. offset: 0,
  383. color: '#DF3E3E'
  384. },
  385. {
  386. offset: 1,
  387. color: '#1C1C1C'
  388. }
  389. ])
  390. },
  391. itemStyle: {
  392. normal: {
  393. lineStyle: {
  394. color: '#DF3E3E'
  395. }
  396. }
  397. }
  398. }, {
  399. name: '预测',
  400. type: 'line',
  401. data: [10, 30, 31, 50, 40, 20, 10],
  402. symbol: 'none',
  403. itemStyle: {
  404. normal: {
  405. lineStyle: {
  406. color: '#80CDF8'
  407. }
  408. }
  409. }
  410. }],
  411. }
  412. return option;
  413. },
  414. getUserInfo: function(e) {
  415. console.log(e)
  416. app.globalData.userInfo = e.detail.userInfo
  417. this.setData({
  418. userInfo: e.detail.userInfo,
  419. hasUserInfo: true
  420. })
  421. }
  422. })