【Laya2.1BUG】 给view设置runtime后,类型是any

typescript项目,加载模式,新建一个Aview,把Aview拖到其他view中,设置Aview的runtime和var,发现生成的UI代码中Aview对应变量的类型是any

企业微信截图_20190531120033.png

 
 
---------------------------------------------------------------------------------------------
 
下面是我修改2.1.0的源码resources\app\out\vs\layaEditor\h5\layabuilder.max.js
 
修改下面五个地方,即可解决上面的问题:
 
1,替换两个函数:
        CodeManager.createTsSamePackageCode=function(packages,packageDic,preCode){
var tPackage;
var i=0,len=0;
len=packages.length;
var packageCodes;
packageCodes=;
for(i=0;i<len;i++){
CodeManager.createTsSamePackageOne(packageCodes,packageDic[packages[i]]);
}
packageCodes.splice(0,0,preCode);
return packageCodes.join("\n");
}

CodeManager.createTsSamePackageOne=function(packageCodes,codeList){
var packageStart;
var packageEnd;
var tCode;
tCode=codeList[0];
var i=0,len=0;
len=codeList.length;
var tCodeLines;
var rstCodeList;
rstCodeList=;
var tStr;
var preStr="";
for(i=0;i<len;i++){
tCode=codeList<em>;
tCodeLines=tCode.split("\n");
tStr=tCodeLines.shift();
while(tStr.indexOf("export module")<0){
tStr=StringTool.trimSide(tStr);
if(preStr.indexOf(tStr)<0){
preStr+=tStr+"\n";
}
tStr=tCodeLines.shift();
}
if(i==0){
tCodeLines.splice(0,0,tStr);
}
if(i!=len-1){
tStr=tCodeLines.pop();
while(tStr.indexOf("}")<0){
tStr=tCodeLines.pop();
}
}
rstCodeList.push(tCodeLines.join("\n"));
}
preStr=StringTool.trimSide(preStr);
if(preStr!=""){
packageCodes.splice(0,0,preStr);
}
packageCodes.push(rstCodeList.join("\n"));
}
2,修改CodeManager.objToUI函数:
if(ProjectSetting.codeType==0){
imports+=" import "+lib+";\n";
}
改成:
if(ProjectSetting.codeType==0){
imports+=" import "+lib+";\n";
}else if(this.projectSetting.codeType==1&&lib.lastIndexOf(".ts")==lib.length-3){
libName=lib.substring(lib.lastIndexOf("/")+1,lib.length);
if(libName.lastIndexOf(".")>=0){
libName=libName.substring(0,libName.lastIndexOf("."));
}
imports+=" import "+libName+" from '../"+lib.substring(0,lib.lastIndexOf("."))+"';\n";
}
3,修改CodeManager.createTSVarByObj函数
var libName=lib.substring(lib.lastIndexOf(".")+1,lib.length);
if(lib.lastIndexOf(".ts")==lib.length-3){
lib="any";
}
str+=" public "+a[0]+":"+lib+";\n";
改成:
var libName=lib.substring(lib.lastIndexOf("/")+1,lib.length);
libName=libName.replace(/(\.ts)|(\.js)$/,"");
str+=" public "+a[0]+":"+libName+";\n";
4,修改CodeTplManager.getCodeTpl函数
case 1:
tplStr=CodeTplManager.tsCodeTpl;
if(isEfc){
tplStr=CodeTplManager.tsCodeTplEfc;
}
else
if(isPreset){
tplStr=CodeTplManager.tsCodeTplPst;
}
break ;
改成:
   case 1:
tplStr=CodeTplManager.tsCodeTpl;
if(isEfc){
tplStr=CodeTplManager.tsCodeTplEfc;
}
else
if(isPreset){
tplStr=CodeTplManager.tsCodeTplPst;
}
tplStr="{!imports!}\n"+tplStr;
break ;
5,搜索__proto.objToUI,找到这个函数
        if(this.projectSetting.codeType==0){
imports+=" import "+lib+";\n";
}
改成:
        if(this.projectSetting.codeType==0){
imports+=" import "+lib+";\n";
}else if(this.projectSetting.codeType==1&&lib.lastIndexOf(".ts")==lib.length-3){
libName=lib.substring(lib.lastIndexOf("/")+1,lib.length);
if(libName.lastIndexOf(".")>=0){
libName=libName.substring(0,libName.lastIndexOf("."));
}
imports+=" import "+libName+" from '../"+lib.substring(0,lib.lastIndexOf("."))+"';\n";
}
[i] [/i]
已邀请:

Laya_Aaron

赞同来自:

这个any不影响的,任何类型都可以,而且最终是js运行,没有类型的。实际中出现什么问题了吗?

要回复问题请先

商务合作
商务合作