index.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  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. this.echartsComponnet = this.selectComponent('#mychart');
  151. console.log(this.echartsComponnet);
  152. //如果是第一次绘制
  153. if (!Chart) {
  154. this.init_echarts(); //初始化图表
  155. } else {
  156. this.setOption(Chart); //更新数据
  157. }
  158. // this.computeScrollViewHeight();
  159. // if (app.globalData.userInfo) {
  160. // this.setData({
  161. // userInfo: app.globalData.userInfo,
  162. // hasUserInfo: true
  163. // })
  164. // } else if (this.data.canIUse){
  165. // // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
  166. // // 所以此处加入 callback 以防止这种情况
  167. // app.userInfoReadyCallback = res => {
  168. // this.setData({
  169. // userInfo: res.userInfo,
  170. // hasUserInfo: true
  171. // })
  172. // }
  173. // } else {
  174. // // 在没有 open-type=getUserInfo 版本的兼容处理
  175. // wx.getUserInfo({
  176. // success: res => {
  177. // app.globalData.userInfo = res.userInfo
  178. // this.setData({
  179. // userInfo: res.userInfo,
  180. // hasUserInfo: true
  181. // })
  182. // }
  183. // })
  184. // }
  185. },
  186. computeScrollViewHeight() {
  187. var that = this
  188. let query = wx.createSelectorQuery().in(that)
  189. query.select('.swiper-tab').boundingClientRect()
  190. query.select('.chart').boundingClientRect()
  191. query.select('.news').boundingClientRect()
  192. query.exec(res => {
  193. let topHeight = res[0].height
  194. let searchHeight = res[1].height
  195. let titleHeight = res[2].height
  196. let windowHeight = wx.getSystemInfoSync().windowHeight
  197. let windowWidth = wx.getSystemInfoSync().windowWidth
  198. let height = windowHeight - topHeight - searchHeight - titleHeight
  199. let ratio = 750 / windowWidth
  200. let scrollHeight = height * ratio + 20
  201. that.setData({ scrollHeight: scrollHeight})
  202. })
  203. },
  204. imageLoad: function (e) {
  205. var imageSize = imageUtil.imageUtil(e)
  206. this.setData({
  207. imagewidth: imageSize.imageWidth,
  208. imageheight: imageSize.imageHeight
  209. })
  210. this.computeScrollViewHeight();
  211. },
  212. onFold:function(e){
  213. console.log( e.currentTarget.dataset.id);
  214. wx.navigateTo({
  215. url:"../news/news"
  216. });
  217. },
  218. choose:function(e){
  219. wx.navigateTo({
  220. url:"../news/news"
  221. })
  222. },
  223. swichNav: function(e) {
  224. var that = this;
  225. if (this.data.currentTab === e.target.dataset.current) {
  226. return false;
  227. } else {
  228. that.setData({
  229. currentTab: e.target.dataset.current
  230. })
  231. }
  232. },
  233. //初始化图表
  234. init_echarts: function () {
  235. this.echartsComponnet.init((canvas, width, height) => {
  236. // 初始化图表
  237. const Chart = echarts.init(canvas, null, {
  238. width: width,
  239. height: height
  240. });
  241. this.setOption(Chart)
  242. // 注意这里一定要返回 chart 实例,否则会影响事件处理等
  243. return Chart
  244. });
  245. },
  246. setOption: function (Chart) {
  247. Chart.clear(); // 清除
  248. Chart.setOption(this.getOption()); //获取新数据
  249. },
  250. // 图表配置项
  251. getOption() {
  252. var self = this;
  253. var option = {
  254. title: {//标题
  255. text: '',
  256. left: 'center'
  257. },
  258. renderAsImage: true, //支持渲染为图片模式
  259. color: ["#DF3E3E", "#1AFA29"],//图例图标颜色
  260. legend: {
  261. show: true,
  262. itemGap: 25,//每个图例间的间隔
  263. top: 30,
  264. x: 30,//水平安放位置,离容器左侧的距离 'left'
  265. z: 100,
  266. textStyle: {
  267. color: '#383838'
  268. },
  269. data: [//图例具体内容
  270. {
  271. name: '实际',
  272. textStyle: {
  273. fontSize: 13,
  274. color: 'white'
  275. },
  276. icon: 'roundRect'
  277. },
  278. {
  279. name: '预测',
  280. textStyle: {
  281. fontSize: 13,
  282. color: 'white'
  283. },
  284. icon: 'roundRect'
  285. }
  286. ]
  287. },
  288. grid: {//网格
  289. left: 30,
  290. top:100,
  291. containLabel: true,//grid 区域是否包含坐标轴的刻度标签
  292. },
  293. xAxis: {//横坐标
  294. type: 'category',
  295. name: '区间',//横坐标名称
  296. nameTextStyle: {//在name值存在下,设置name的样式
  297. color: 'white',
  298. fontStyle: 'normal'
  299. },
  300. nameLocation:'end',
  301. splitLine: {//坐标轴在 grid 区域中的分隔线。
  302. show: true,
  303. lineStyle: {
  304. type: 'dashed'
  305. }
  306. },
  307. boundaryGap: false,//1.true 数据点在2个刻度直接 2.fals 数据点在分割线上,即刻度值上
  308. data: ['10', '11', '12', '13', '14', '15', '16'],
  309. axisLabel: {
  310. textStyle: {
  311. fontSize: 13,
  312. color: '#5D5D5D'
  313. }
  314. }
  315. },
  316. yAxis: {//纵坐标
  317. type: 'value',
  318. position:'right',
  319. name: '股票值',//纵坐标名称
  320. nameTextStyle:{//在name值存在下,设置name的样式
  321. color:'red',
  322. fontStyle:'normal'
  323. },
  324. splitNumber: 5,//坐标轴的分割段数
  325. splitLine: {//坐标轴在 grid 区域中的分隔线。
  326. show: true,
  327. lineStyle: {
  328. type: 'dashed'
  329. }
  330. },
  331. axisLabel: {//坐标轴刻度标签
  332. formatter: function (value) {
  333. var xLable = [];
  334. if (value == 20) {
  335. xLable.push('25,883');
  336. }
  337. if (value == 40) {
  338. xLable.push('26,035');
  339. }
  340. if (value == 60) {
  341. xLable.push('26,187');
  342. }
  343. if (value == 80) {
  344. xLable.push('26,339');
  345. }
  346. return xLable
  347. },
  348. textStyle: {
  349. fontSize: 13,
  350. color: '#5D5D5D',
  351. }
  352. },
  353. min: 0,
  354. max: 100,
  355. },
  356. series: [{
  357. name: '实际',
  358. type: 'line',
  359. smooth:true,
  360. data: [18, 36, 65, 30, 78, 40, 33],
  361. symbol: 'none',
  362. itemStyle: {
  363. normal: {
  364. lineStyle: {
  365. color: '#DF3E3E'
  366. }
  367. }
  368. }
  369. }, {
  370. name: '预测',
  371. type: 'line',
  372. data: [10, 30, 31, 50, 40, 20, 10],
  373. symbol: 'none',
  374. itemStyle: {
  375. normal: {
  376. lineStyle: {
  377. color: '#1AFA29'
  378. }
  379. }
  380. }
  381. }],
  382. }
  383. return option;
  384. },
  385. getUserInfo: function(e) {
  386. console.log(e)
  387. app.globalData.userInfo = e.detail.userInfo
  388. this.setData({
  389. userInfo: e.detail.userInfo,
  390. hasUserInfo: true
  391. })
  392. }
  393. })