Files
JiaZhiQianYan/unpackage/dist/build/mp-weixin/pages/ztfx/ztfx.js

2 lines
7.2 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 e=require("../../common/vendor.js"),t=require("../../request/http.js"),a=require("../../request/api.js"),o=require("../../common/assets.js"),i=require("../../uni_modules/lime-echart/static/echarts.min.js"),s={categories:[{name:"板块"},{name:"概念"},{name:"个股"}],nodes:[{name:"科技板块",symbolSize:50,category:0},{name:"人工智能",symbolSize:30,category:1},{name:"大数据",symbolSize:25,category:1},{name:"科大讯飞",symbolSize:20,category:2},{name:"百度",symbolSize:20,category:2},{name:"金融板块",symbolSize:50,category:0},{name:"数字货币",symbolSize:30,category:1},{name:"招商银行",symbolSize:20,category:2},{name:"平安银行",symbolSize:20,category:2}],links:[{source:"科技板块",target:"人工智能",value:10},{source:"科技板块",target:"大数据",value:8},{source:"人工智能",target:"科大讯飞",value:6},{source:"人工智能",target:"百度",value:6},{source:"金融板块",target:"数字货币",value:9},{source:"数字货币",target:"招商银行",value:5},{source:"数字货币",target:"平安银行",value:5}]},r={components:{WordCloud:()=>"../../components/WordCloud/WordCloud2.js"},data:()=>({navH:e.inject("navHeight"),contentTop:"",selectedYearMonth:"",selectedFullDate:"",selectedItem:null,tabTypes:[{data:"",change:0,title:"当前日期"},{data:"",change:3,title:"涨停家数"},{data:"22%",change:0,title:"炸板率"}],wordData:[],bkList:[],number_limit_stocks:"",HEAT_LEVELS:[{threshold:.7,color:"#EF4444",level:"高热度"},{threshold:.4,color:"#F97316",level:"中热度"},{threshold:.2,color:"#F3B800",level:"低热度"},{threshold:0,color:"#01AB5D",level:"无热度"}],bkTypes:["板块关联图","板块分布","热门概念词云"],activeType:0,pieOption:{tooltip:{trigger:"item"},animation:!1,legend:{top:"5%",left:"center",show:!1},series:[{name:"Access From",type:"pie",radius:["40%","70%"],avoidLabelOverlap:!1,padAngle:2,itemStyle:{borderRadius:8},emphasis:{label:{show:!0,fontSize:10}},labelLine:{length:1,length2:5},data:[]}]},graphOption:{tooltip:{},legend:[],series:[{name:"板块关联",type:"graph",layout:"none",data:[],links:[],categories:[],roam:!0,label:{show:!0,position:"right",formatter:"{b}"},labelLayout:{hideOverlap:!0},scaleLimit:{min:.4,max:2},lineStyle:{color:"source",curveness:.3}}]}}),onLoad(t){this.activeIndex=t.index,this.contentTop=this.navH+20/750*e.inject("windowWidth")},onReady(){this.fetchData(),this.initGraphChart()},methods:{getHeatColor(e,t){if(0===t)return"#01AB5D";const a=e/t,o=this.HEAT_LEVELS.find((e=>a>e.threshold));return o?o.color:"#01AB5D"},async switchTab(e){switch(this.activeType=e,e){case 0:this.$refs.graphChartRef&&this.initGraphChart();break;case 1:this.$refs.chartRef&&this.initPieChart();break;case 2:this.initWordCloud()}},getPreviousDayDate(e){if(!/^\d{4}-\d{2}-\d{2}$/.test(e))return console.error("日期格式错误,请传入 YYYY-MM-DD 格式的日期"),"";const[t,a,o]=e.split("-").map(Number),i=new Date(t,a-1,o);i.setDate(i.getDate()-2);return`${i.getFullYear()}${String(i.getMonth()+1).padStart(2,"0")}${String(i.getDate()).padStart(2,"0")}`},async fetchData(){try{const a=(new Date).getTime(),o=this.getPreviousDayDate(this.selectedFullDate),i=`${t.getBaseURL1()}/data/zt/daily/${o}.json?t=${a}`;console.log("请求URL",i);const s=await e.index.request({url:i,method:"GET"});if(200===s.statusCode&&s.data){this.originData=s.data;const e=this.originData.chart_data||{},t=e.labels||[],a=e.counts||[],o=a.length>0?Math.max(...a):0;let i=[];const r=Math.min(t.length,a.length);for(let s=0;s<r;s++){const e=t[s],r=a[s]||0,n=this.getHeatColor(r,o),l=0===o?0:(r/o*100).toFixed(2);i.push({title:e,count:r,bgColor:n,ratio:l})}this.bkList=i.slice(0,16),this.initPieChart()}else e.index.showToast({title:"数据请求失败",icon:"none"})}catch(a){console.error("请求异常:",a),e.index.showToast({title:"网络异常",icon:"none"})}},async initGraphChart(){const e=await this.$refs.graphChartRef.init(i);this.graphOption.legend=[{data:s.categories.map((e=>e.name))}],this.graphOption.series[0].data=s.nodes,this.graphOption.series[0].links=s.links,this.graphOption.series[0].categories=s.categories,e.setOption(this.graphOption)},async initPieChart(){try{let e=[];const t=this.originData.chart_data||{},a=t.labels||[],o=t.counts||[],s=Math.min(a.length,o.length);for(let i=0;i<s;i++)e.push({name:a[i],value:o[i]});if(this.pieOption.series[0].data=e.length>0?e:[{value:10,name:"科技板块"},{value:8,name:"人脑工程"},{value:9,name:"商业航天"}],this.$refs.chartRef){const e=await this.$refs.chartRef.init(i);console.log("Piechart实例创建成功",e),e.setOption(this.pieOption)}}catch(e){console.error("饼图初始化失败:",e)}},initWordCloud(){this.originData.word_freq_data&&Array.isArray(this.originData.word_freq_data)?(this.wordData=this.originData.word_freq_data,console.log("词云数据赋值完成",this.wordData)):this.wordData=[{name:"脑机",value:1e4},{name:"航天",value:3428}]},handleDateChange(e){var t,a,o,i;if(console.log("从日历组件接收的参数:",{currentZtCount:null==(t=e.item)?void 0:t.zt_count,prevZtCount:null==(a=e.prevItem)?void 0:a.zt_count}),this.selectedYearMonth=e.yearMonth,this.selectedFullDate=e.fullDate,this.selectedItem=e.item,e.fullDate){const[t,a,o]=e.fullDate.split("-").map(Number);this.tabTypes[0].data=`${a}${o}`}const s=(null==(o=e.item)?void 0:o.zt_count)??0;this.tabTypes[1].data=s.toString(),this.number_limit_stocks=s.toString();const r=(null==(i=e.prevItem)?void 0:i.zt_count)??0,n=0===s||0===r?0:s-r;this.tabTypes[1].change=n,this.fetchData()},analyseHighStocks(){let e={date:this.getPreviousDayDate(this.selectedFullDate)};a.analyseHighStocks(e).then((e=>{})).catch((e=>{}))},bkydAction(t){e.index.navigateTo({url:`/pagesStock/stockCenterDetails/bkydmx?index=${t}`})}}};if(!Array){(e.resolveComponent("navBar")+e.resolveComponent("LCCalendar")+e.resolveComponent("l-echart")+e.resolveComponent("WordCloud"))()}Math||((()=>"../../components/navBar/navBar.js")+(()=>"../../components/LCCalendar/LCCalendar.js")+(()=>"../../uni_modules/lime-echart/components/l-echart/l-echart.js")+(()=>"../../components/WordCloud/WordCloud2.js"))();const n=e._export_sfc(r,[["render",function(t,a,i,s,r,n){return{a:e.p({leftText:"涨停分析",hideNavBg:!0,hideBack:!0}),b:o._imports_0,c:o._imports_1$10,d:o._imports_2$8,e:e.f(r.tabTypes,((t,a,o)=>e.e({a:e.t(t.data),b:0!==t.change},0!==t.change?{c:e.t(t.change>0?"+"+t.change:t.change),d:e.s({marginLeft:"10rpx",borderRadius:"5rpx",color:"white",padding:"0 5rpx",fontSize:"24rpx",fontWeight:"bold"}),e:e.s(t.change>0?{backgroundColor:"#F59B38"}:{backgroundColor:"#EF4444"})}:{},{f:e.t(t.title),g:a}))),f:e.o(n.handleDateChange),g:o._imports_3$8,h:e.t(r.bkList.length),i:e.t(r.number_limit_stocks),j:e.f(r.bkList,((t,a,o)=>({a:e.t(t.title),b:e.t(t.count),c:a,d:e.o((e=>n.bkydAction(a)),a),e:t.bgColor}))),k:e.f(r.bkTypes,((t,a,o)=>({a:e.t(t),b:e.o((e=>n.switchTab(a))),c:r.activeType==a?"#BB8520":"#999999",d:"1rpx solid "+(r.activeType==a?"#F2C369":"#D2D2D2"),e:r.activeType==a?"#FFFAF1":"#FFF"}))),l:e.sr("graphChartRef","06b829a4-2"),m:0===r.activeType,n:e.sr("chartRef","06b829a4-3"),o:1===r.activeType,p:2===r.activeType,q:e.p({wordData:r.wordData,width:330,height:330}),r:o._imports_3$8,s:e.f(10,((e,t,a)=>({a:t}))),t:o._imports_1$11,v:o._imports_5$4,w:o._imports_5$4,x:e.s("top:"+r.contentTop+"px;")}}]]);wx.createPage(n);