Files
JiaZhiQianYan/unpackage/dist/build/mp-weixin/pages/index/stockDetails/stockDetails.js
2025-12-04 17:41:33 +08:00

2 lines
5.4 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"use strict";const t=require("../../../common/vendor.js"),e=require("../../../request/api.js"),o=require("../../../utils/util.js"),a=require("../../../common/assets.js"),i=require("../../../uni_modules/lime-echart/static/echarts.min.js"),s={data:()=>({navH:t.inject("navHeight"),contentTop:"",navTitle:"",type:"",eventId:"",stockCode:"",categoryList:["分时图","日K线"],selectCategory:0,tradeData:null,option:{title:{show:!1},tooltip:{position:function(t,e,o,a,i){var s={top:"10%"};return s[["left","right"][+(t[0]<i.viewSize[0]/2)]]=5,s},trigger:"axis",axisPointer:{type:"cross"},formatter:function(t){return console.log(t),"日期:"+t[0].name+"\n开盘价"+t[0].data[1]+"\n收盘价"+t[0].data[2]+"\n最低价"+t[0].data[3]+"\n最高价"+t[0].data[4]}},legend:{show:!1},grid:{top:"10%",left:"10%",right:"10%",bottom:"15%"},xAxis:{type:"category",data:[],boundaryGap:!1,axisLine:{onZero:!1},splitLine:{show:!1},min:"dataMin",max:""},yAxis:{scale:!0,splitArea:{show:!0}},dataZoom:[{type:"inside",start:50,end:100},{show:!0,type:"slider",top:"90%",start:50,end:100}],series:[{name:"日K",type:"candlestick",data:[],itemStyle:{color:"#ffffff",color0:"#355422",borderColor:"#c00000",borderColor0:"#355422"}}]},option1:{title:{show:!1},tooltip:{position:function(t,e,o,a,i){var s={top:"3%"};return s[["left","right"][+(t[0]<i.viewSize[0]/2)]]=5,s},trigger:"axis",formatter:function(t){return"时间:"+t[0].name+"\n高"+t[0].data[2]+"\n开"+t[0].data[3]+"\n低"+t[0].data[4]+"\n收"+t[0].data[1]+"\n涨幅"+t[0].data[5]+"%"}},grid:{top:"10%",left:"12%",right:"14%",bottom:"10%"},xAxis:{type:"category",scale:!0,axisLabel:{customValues:["09:30","10:00","10:30","11:00","11:30","13:00","13:30","14:00","14:30","15:00"]}},yAxis:{show:!1,scale:!0},dataZoom:[{type:"inside"}],series:{name:"分时图",type:"line",symbol:"none",markLine:{silent:!0,symbol:["none","none"],lineStyle:{type:"solid",width:1,color:"#dedede"},z:1},data:[]},animation:!1},relatedDesc:"",sourceList:[],getLocalDate:o.getLocalDate}),onLoad(e){e.code&&(this.type=e.type,1==e.type?(this.contentTop=this.navH+68/750*t.inject("windowWidth"),this.eventId=e.id,this.stockCode=e.code,this.getStockDetailsData()):(this.contentTop=this.navH,this.navTitle=e.name+"("+e.code+")",this.relatedDesc=e.des))},methods:{async init(){const t=await this.$refs.chartRef.init(i);0==this.selectCategory?t.setOption(this.option1):t.setOption(this.option)},clickCategoryItem(t){this.selectCategory!=t&&(this.selectCategory=t,1==t?this.getStockCandlestickChartData():this.init())},getStockDetailsData(){let a=this.stockCode,i=this.eventId;e.stockDetails(i,a).then((e=>{if(200==e.code){this.navTitle=e.data.basic_info.stock_name+"("+e.data.basic_info.stock_code+")";let t=e.data.minute_chart_data;this.tradeData=e.data.latest_trade;let i=[],s=[],n=t[0].open;for(let e of t){i.push(e.time);let t=o.accMul(o.accDiv(o.accSub(e.close,n),n).toFixed(4),100),a=e.volume;a>1e4&&(a=(a/1e4).toFixed(0)+"万");let r=e.amount;r>1e4&&(r=(r/1e4).toFixed(0)+"万"),s.push([e.time,e.close,e.high,e.open,e.low,t,a,r])}let r=n,l=0;for(let e of s){let t=e[1];parseFloat(t)<r&&(r=parseFloat(t)),parseFloat(t)>l&&(l=parseFloat(t))}let c=(n-r)/3,d=(l-n)/3,h=[];if(c>d){for(var a=3;a>0;a--)h.push(n-a*c);for(a=0;a<4;a++)h.push(n+a*c)}else{for(a=3;a>0;a--)h.push(n-a*d);for(a=0;a<4;a++)h.push(n+a*d)}this.option1.xAxis.data=i,this.option1.yAxis.min=h[0].toFixed(2),this.option1.yAxis.max=h[h.length-1].toFixed(2),this.option1.series.data=s;let p=[],m=e.data.event_info.event_start_time.split("T")[1];m=m.substring(0,5);for(let e of h)p.push({xAxis:m,lineStyle:{type:"solid",width:1,color:"#ffd700"},label:{position:"middle",formatter:"事件发生",color:"#ffd700"}},{yAxis:e,label:{show:!0,position:"start",color:"#333"}},{yAxis:e,label:{show:!0,position:"end",formatter:o.accMul(o.accDiv(o.accSub(e,n),n).toFixed(4),100)+"%",color:"#333"}});this.option1.series.markLine.data=p;let u=e.data.related_desc;u&&(this.relatedDesc=u.relation_desc,u.retrieved_sources&&(this.sourceList=u.retrieved_sources)),this.init()}else t.index.showToast({title:e.message,icon:"none"})})).catch((t=>{}))},getStockCandlestickChartData(){let t=this.stockCode,o={chart_type:"minute"};1==this.selectCategory&&(o.chart_type="daily"),e.stockCandlestickChartData(t,o).then((t=>{let e=t.data,o=[],a=[];for(let i of e)o.push(i.time),a.push([i.open,i.close,i.low,i.high]);this.option.xAxis.data=o,this.option.series[0].data=a,this.init()})).catch((t=>{}))}}};if(!Array){(t.resolveComponent("navBar")+t.resolveComponent("l-echart"))()}Math||((()=>"../../../components/navBar/navBar.js")+(()=>"../../../uni_modules/lime-echart/components/l-echart/l-echart.js"))();const n=t._export_sfc(s,[["render",function(e,o,i,s,n,r){return t.e({a:t.p({leftText:n.navTitle}),b:a._imports_0,c:1==n.type},1==n.type?{d:t.f(n.categoryList,((e,o,a)=>t.e({a:t.t(e),b:n.selectCategory==o},(n.selectCategory,{}),{c:t.n("item relative "+(n.selectCategory==o?"select":"")),d:o,e:t.o((t=>r.clickCategoryItem(o)),o)}))),e:t.s("top:"+n.navH+"px;")}:{},{f:1==n.type&&n.tradeData},1==n.type&&n.tradeData?{g:t.t(n.tradeData.volume),h:t.t(n.tradeData.amount)}:{},{i:1==n.type},1==n.type?{j:t.sr("chartRef","42054871-1")}:{},{k:t.t(n.relatedDesc),l:1==n.type&&n.sourceList.length>0},(1==n.type&&n.sourceList.length,{}),{m:t.f(n.sourceList,((e,o,a)=>({a:t.t(e.sentences),b:t.t(e.report_title),c:t.t(e.author),d:t.t(n.getLocalDate(e.declare_date)),e:o}))),n:t.n("contentC fixed "+(2==n.type?"radius":"")),o:t.s("top:"+n.contentTop+"px;")})}]]);wx.createPage(n);