import axios from 'axios'; import play from 'play'; const proxyAxios = axios.create({ baseURL: 'https://futsseapi.eastmoney.com/', // 代理服务器地址 }); function sleep(time){ return new Promise(function (resolve){ setTimeout(resolve, time); }) } function playTishi(){ return new Promise(function (resolve){ play.sound('tishi.mp3', resolve); }) } async function init(){ await sleep(4000) const res=await proxyAxios.get("/list/variety/115/22?callback=aaa_callback&orderBy=zdf&sort=desc&pageSize=20&pageIndex=0&callbackName=aaa_callback&token=58b2fa8f54638b60b87d69b31969089c&field=dm%2Csc%2Cname%2Cp%2Czsjd%2Czde%2Czdf%2Cf152%2Co%2Ch%2Cl%2Czjsj%2Cvol%2Ccje%2Cwp%2Cnp%2Cccl&blockName=callback&_=1722837502030") const func=new Function('aaa_callback','return '+res.data) const data=func(function(item){return item}) console.log(data) const map={} data.list.forEach(function({dm,p}){ map[dm]=p }) console.log(map['SA409'],map['SA501']) if(map['SA409']<map['SA501']){ // 播放音频文件 await playTishi() } } //是否在开盘时间 const time=new Date().getHours()*60+new Date().getMinutes() //9:00-11:30,13:30-15:00,21:00-23:00 const timeDur='9:00-11:30,13:30-15:00,21:00-23:00' const list=timeDur.split(',').map((str)=>str.split('-').map((str2)=>{ const arr=str2.split(":").map((d)=>parseInt(d)||0); return arr[0]*60+arr[1] })) let isOk=false for(let i=0;i<list.length;i++){ const [left,right]=list[i] if(time>left&&time<right){ isOk=true break } } if(isOk){ init() }else{ console.log('不在开盘时间') }
标签:function,map,resolve,const,提示音,callback,return,监听,纯碱 From: https://www.cnblogs.com/caoke/p/18344266