diff --git a/CHANGELOG.md b/CHANGELOG.md
index 0bff6a6b..dc327d24 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,9 @@
# ChangeLog
+## [1.2.12]
+
+- fix: 修复股票搜索,支持中英文
+
## [1.2.11]
- chore: 优化界面样式
diff --git a/demo/pzgznew.js b/demo/pzgznew.js
new file mode 100644
index 00000000..4ccf9375
--- /dev/null
+++ b/demo/pzgznew.js
@@ -0,0 +1 @@
+var apiHost="//api.fund.eastmoney.com/";window.loadtip=new Loading;var apiParm={sort:"",type:"",orderType:"",canbuy:"0",pageIndex:1,pageSize:200};String.prototype.trim=function(){return this.replace(/^\s\s*/,"").replace(/\s\s*$/,"")};var $j=jQuery;var Inittable=function(){$j("html").scrollTop(300);var url=apiHost+"FundGuZhi/GetFundGZList?type="+apiParm.type+"&sort="+apiParm.sort+"&orderType="+apiParm.orderType+"&canbuy="+apiParm.canbuy+"&pageIndex="+apiParm.pageIndex+"&pageSize="+apiParm.pageSize+"&callback=?";loadtip.show();$j.getJSON(url,function(result){if(result&&result.ErrCode==0){var data={data:result.Data,pageIndex:result.PageIndex,pageSize:result.PageSize};var guzhiList_html=template("guzhiList",data);$j("#newdate").html(result.Data.gxrq);$j("#gsdata").html(result.Data.gxrq+" 估算数据");$j("#gbdata").html(result.Data.gxrq+" 公布数据");$j("#dwjzdata").html(result.Data.gzrq);$j("#tableContent").html(guzhiList_html);InitPager(result.TotalCount,result.PageSize,result.PageIndex);loadtip.clear()}})};function alljjspan(){var e=document.getElementById("rdDXJJN");if(e.checked){document.getElementById("rdDXJJN").checked=false}else{document.getElementById("rdDXJJN").checked=true}apiParm.pageIndex=1;apiParm.canbuy="0";Inittable()}function canbuyjjspan(){var e=document.getElementById("rdDXJJY");if(e.checked){document.getElementById("rdDXJJY").checked=false}else{document.getElementById("rdDXJJY").checked=true}apiParm.pageIndex=1;apiParm.canbuy="1";Inittable()}function InitPager(total,pagesize,pageindex){$j("#pager").ttjjPage({total:total,pagesize:pagesize,pageindex:pageindex,cache:false,selectpage:function(edata){apiParm.pageIndex=edata.pageIndex;Inittable()}})}$j(function(){$j(".titleItems").click(function(){var type=$j(this).data("type");$j(".titleItems").removeClass("titleItemActive");$j(this).addClass("titleItemActive");apiParm.type=type;apiParm.pageIndex=1;if(type=="9"){$j("#btnContent").css("display","none");$j("#typeContent").css("display","")}else{$j("#btnContent").css("display","");$j("#typeContent").css("display","none")}Inittable()});$j(".tableContent").on("click"," table thead th a",function(){var orderType=$j(this).data("ordertype");var sort=$j(this).data("sort");$j("table thead th a img").remove();apiParm.sort=sort;apiParm.orderType=orderType;if(orderType=="desc"){$j(this).append("");$j(this).data("ordertype","asc")}else{$j(this).append("");$j(this).data("ordertype","desc")}Inittable()});$j("input[name='dxjj']").click(function(){apiParm.pageIndex=1;apiParm.canbuy=$j(this).val();Inittable()});pageLoad()});function pageInit(){var hidTime=3e4;setTimeout("document.getElementById('poplay1').style.display = 'none'",hidTime);setTimeout("document.getElementById('poplay2').style.display = 'none'",hidTime);lastScrollY=0;suspendcode12="
";suspendcode14=" ";document.write(suspendcode12);document.write(suspendcode14);window.setInterval("heartBeat()",1);var cookieName="Eastmoney_Fund_Attent";try{var tmpcode=$rC(cookieName);if(tmpcode!=null&&tmpcode!=""){$wC(cookieName,tmpcode,"/","fund.eastmoney.com",365,1)}if($rC(cookieName)!=""){var vCodeStr=$rC(cookieName);var c=document.getElementById("tableContent");for(a=2;a0)percent=Math.ceil(percent);else percent=Math.floor(percent);document.getElementById("lovexin12").style.top=parseInt(document.getElementById("lovexin12").style.top)+percent+"px";document.getElementById("lovexin14").style.top=parseInt(document.getElementById("lovexin12").style.top)+percent+"px";document.getElementById("lovexin14").style.left=(eval("document.body.clientWidth")-1e3)/2+1+"px";lastScrollY=lastScrollY+percent}function getCurRowNum(elm,n){var a=elm.parentNode.parentNode.rowIndex;var b=document.getElementById("tableContent").rows[a-1];var h;b.style.backgroundColor==""?b.style.backgroundColor="#D2E2FF":b.style.backgroundColor="";elm.checked==true?h=1:h=0;EM.Fund.Cookies.WC("Eastmoney_Fund_Attent",b.cells[n].innerHTML.trim(),"/","fund.eastmoney.com",1,h)}function noPagingClick(e){if(e.checked){apiParm.pageIndex=1;apiParm.pageSize=2e4;location.hash="splittable_1"}else{apiParm.pageIndex=1;apiParm.pageSize=200;location.hash="splittable_0"}Inittable()}function nopagingspan(){var e=document.getElementById("cbNoPaging");if(e.checked){document.getElementById("cbNoPaging").checked=false}else{document.getElementById("cbNoPaging").checked=true}noPagingClick(e)}function Loading(){this.bordercolor="#cccccc";this.bgcolor="#FFF8C1";this.MsgAlign="left";this.width="230";this.height="50";this.bgObj=null;this.msgObj=null;this.show=function(){if($("bgObj")&&$("msgObj")){$("bgObj").style.display="block";$("msgObj").style.display="block"}else{var iWidth=document.documentElement.clientWidth||document.body.clientWidth;var iHeight=(document.documentElement.clientHeight||document.body.clientHeight)+(document.documentElement.scrollTop||document.body.scrollTop)*2;this.bgObj=document.createElement("div");this.bgObj.id="bgObj";this.bgObj.style.cssText="position:absolute;left:0px;top:0px;width:"+iWidth+"px;height:"+Math.max(document.body.clientHeight,iHeight)+"px;filter:Alpha(Opacity=30);opacity:0.3;Alpha(opacity=10,finishOpacity=0,style=0);background-color:#ffffff;z-index:100000;";document.body.appendChild(this.bgObj);this.msgObj=document.createElement("div");this.msgObj.id="msgObj";this.msgObj.style.cssText="position:absolute; top:"+(iHeight-this.height)/2+"px;left:"+(iWidth-this.width)/2+"px;width:"+this.width+"px;height:"+this.height+"px; text-align:left; border:1px solid "+this.bordercolor+";background-color:"+this.bgcolor+"; color:#686868;z-index:100001;";document.body.appendChild(this.msgObj);this.msgObj.innerHTML='数据加载中'}};this.clear=function(){if($("bgObj")&&$("msgObj")){$("bgObj").style.display="none";$("msgObj").style.display="none"}}}function pageLoad(){var href=location.href;if(href.indexOf("#")!=-1){var array=href.split("#");if(array.length>=2){var page=array[1].split("_")[1];if(page=="1"){document.getElementById("cbNoPaging").checked=true;apiParm.pageIndex=1;apiParm.pageSize=2e4;Inittable()}}}}
\ No newline at end of file
diff --git a/package.json b/package.json
index c0646850..14d80dab 100644
--- a/package.json
+++ b/package.json
@@ -2,7 +2,7 @@
"name": "leek-fund",
"displayName": "韭菜盒子",
"description": "韭菜盒子,VSCode 里也可以看股票 & 基金实时数据,做最好用的养基插件",
- "version": "1.2.11",
+ "version": "1.2.12",
"author": "giscafer ",
"repository": {
"type": "git",
diff --git a/src/service.ts b/src/service.ts
index 93241169..569c1497 100644
--- a/src/service.ts
+++ b/src/service.ts
@@ -9,6 +9,7 @@ export class FundService {
private _fundList: Array = [];
private context: ExtensionContext;
szItem: any;
+ searchStockKeyMap: any = {}; // 标记搜索不到记录,避免死循环
constructor(context: ExtensionContext) {
this.context = context;
}
@@ -92,11 +93,13 @@ export class FundService {
});
}
- async getStockSuggestList(searchText = ''): Promise {
+ async getStockSuggestList(searchText = '', type = '2'): Promise {
if (!searchText) {
- return [{ label: '请输入关键词查询,如:0000001' }];
+ return [{ label: '请输入关键词查询,如:0000001 或 上证指数' }];
}
- const url = `http://suggest3.sinajs.cn/suggest/type=&key=${encodeURIComponent(searchText)}`;
+ const url = `http://suggest3.sinajs.cn/suggest/type=${type}&key=${encodeURIComponent(
+ searchText
+ )}`;
try {
console.log('getStockSuggestList: getting...');
const response = await axios.get(url, {
@@ -110,6 +113,12 @@ export class FundService {
headers: randHeader(),
});
const text = response.data.slice(18, -1);
+ if (text.length <= 1 && !this.searchStockKeyMap[searchText]) {
+ this.searchStockKeyMap[searchText] = true;
+ // 兼容一些查询不到的股票,如sz123044
+ return this.getStockSuggestList(searchText, '');
+ }
+ this.searchStockKeyMap = {};
const tempArr = text.split(';');
const result: QuickPickItem[] = [];
tempArr.forEach((item: string) => {
@@ -169,7 +178,9 @@ export class FundService {
var stockList: Array = [];
if (/FAILED/.test(resp.data)) {
if (codes.length === 1) {
- window.showErrorMessage(`fail: error Stock code in ${codes}, please delete error Stock code`);
+ window.showErrorMessage(
+ `fail: error Stock code in ${codes}, please delete error Stock code`
+ );
return [
{
id: codes[0],
@@ -258,7 +269,8 @@ export class FundService {
stockItem.symbol = symbol;
stockItem.updown = formatNumber(+price - +yestclose, 2, false);
stockItem.percent =
- (stockItem.updown >= 0 ? '+' : '-') + formatNumber((Math.abs(stockItem.updown) / +yestclose) * 100, 2, false);
+ (stockItem.updown >= 0 ? '+' : '-') +
+ formatNumber((Math.abs(stockItem.updown) / +yestclose) * 100, 2, false);
if (code === 'sh000001') {
sz = new LeekTreeItem(stockItem, this.context);
}
diff --git a/src/utils.ts b/src/utils.ts
index cbb640a7..ae1c6b09 100644
--- a/src/utils.ts
+++ b/src/utils.ts
@@ -62,7 +62,7 @@ export const sortData = (data: LeekTreeItem[] = [], order = SortType.NORMAL) =>
export const formatTreeText = (text = '', num = 10) => {
const str = text + '';
const lenx = num - str.length;
- console.log(str + ' '.repeat(lenx), lenx);
+ // console.log(str + ' '.repeat(lenx), lenx);
return str + ' '.repeat(lenx);
};