index.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  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.setData({
  243. currentTab: e.target.dataset.current
  244. })
  245. }
  246. },
  247. //初始化图表
  248. init_echarts: function () {
  249. this.echartsComponnet.init((canvas, width, height) => {
  250. // 初始化图表
  251. const Chart = echarts.init(canvas, null, {
  252. width: width,
  253. height: height
  254. });
  255. this.setOption(Chart)
  256. // 注意这里一定要返回 chart 实例,否则会影响事件处理等
  257. return Chart
  258. });
  259. },
  260. setOption: function (Chart) {
  261. Chart.clear(); // 清除
  262. Chart.setOption(this.getOption()); //获取新数据
  263. },
  264. // 图表配置项
  265. getOption() {
  266. var self = this;
  267. var option = {
  268. title: {//标题
  269. text: '',
  270. left: 'center'
  271. },
  272. renderAsImage: true, //支持渲染为图片模式
  273. color: ["#DF3E3E", "#1AFA29"],//图例图标颜色
  274. legend: {
  275. show: true,
  276. itemGap: 25,//每个图例间的间隔
  277. top: 30,
  278. x: 30,//水平安放位置,离容器左侧的距离 'left'
  279. z: 100,
  280. textStyle: {
  281. color: '#383838'
  282. },
  283. data: [//图例具体内容
  284. {
  285. name: '实际',
  286. textStyle: {
  287. fontSize: 13,
  288. color: 'white'
  289. },
  290. icon: 'roundRect'
  291. },
  292. {
  293. name: '预测',
  294. textStyle: {
  295. fontSize: 13,
  296. color: 'white'
  297. },
  298. icon: 'roundRect'
  299. }
  300. ]
  301. },
  302. grid: {//网格
  303. left: 30,
  304. top:100,
  305. containLabel: true,//grid 区域是否包含坐标轴的刻度标签
  306. },
  307. xAxis: {//横坐标
  308. type: 'category',
  309. name: '区间',//横坐标名称
  310. nameTextStyle: {//在name值存在下,设置name的样式
  311. color: 'white',
  312. fontStyle: 'normal'
  313. },
  314. nameLocation:'end',
  315. splitLine: {//坐标轴在 grid 区域中的分隔线。
  316. show: true,
  317. lineStyle: {
  318. type: 'dashed'
  319. }
  320. },
  321. boundaryGap: false,//1.true 数据点在2个刻度直接 2.fals 数据点在分割线上,即刻度值上
  322. data: ['10', '11', '12', '13', '14', '15', '16'],
  323. axisLabel: {
  324. textStyle: {
  325. fontSize: 13,
  326. color: '#5D5D5D'
  327. }
  328. }
  329. },
  330. yAxis: {//纵坐标
  331. type: 'value',
  332. position:'right',
  333. name: '股票值',//纵坐标名称
  334. nameTextStyle:{//在name值存在下,设置name的样式
  335. color:'red',
  336. fontStyle:'normal'
  337. },
  338. splitNumber: 5,//坐标轴的分割段数
  339. splitLine: {//坐标轴在 grid 区域中的分隔线。
  340. show: true,
  341. lineStyle: {
  342. type: 'dashed'
  343. }
  344. },
  345. axisLabel: {//坐标轴刻度标签
  346. formatter: function (value) {
  347. var xLable = [];
  348. if (value == 20) {
  349. xLable.push('25,883');
  350. }
  351. if (value == 40) {
  352. xLable.push('26,035');
  353. }
  354. if (value == 60) {
  355. xLable.push('26,187');
  356. }
  357. if (value == 80) {
  358. xLable.push('26,339');
  359. }
  360. return xLable
  361. },
  362. textStyle: {
  363. fontSize: 13,
  364. color: '#5D5D5D',
  365. }
  366. },
  367. min: 0,
  368. max: 100,
  369. },
  370. series: [{
  371. name: '实际',
  372. type: 'line',
  373. smooth:true,
  374. data: [18, 36, 65, 30, 78, 40, 33],
  375. symbol: 'none',
  376. itemStyle: {
  377. normal: {
  378. lineStyle: {
  379. color: '#DF3E3E'
  380. }
  381. }
  382. }
  383. }, {
  384. name: '预测',
  385. type: 'line',
  386. data: [10, 30, 31, 50, 40, 20, 10],
  387. symbol: 'none',
  388. itemStyle: {
  389. normal: {
  390. lineStyle: {
  391. color: '#1AFA29'
  392. }
  393. }
  394. }
  395. }],
  396. }
  397. return option;
  398. },
  399. getUserInfo: function(e) {
  400. console.log(e)
  401. app.globalData.userInfo = e.detail.userInfo
  402. this.setData({
  403. userInfo: e.detail.userInfo,
  404. hasUserInfo: true
  405. })
  406. }
  407. })