var $url="/plugins/install",$urlActionsDownload=$url+"/actions/download",$urlActionsUpdate=$url+"/actions/update",$urlActionsRestart=$url+"/actions/restart",data=utils.init({pluginIds:_.split(utils.getQueryString("pluginIds"),","),pageType:utils.getQueryBoolean("isUpdate")?"升级":"安装",active:0,success:!1,cmsVersion:null,pluginPathDict:null,percentage:0,listPackages:[],listPackageIds:[],listIndex:0,currentPackage:{},currentPackages:[],currentDownloadingId:0,currentDownloadIds:[],currentUpdatingId:0,currentUpdatedIds:[]}),methods={apiGet:function(){var t=this;setInterval(function(){t.percentage>95||(t.percentage+=1)},1e3),$api.get($url,{params:{pluginIds:utils.getQueryString("pluginIds")}}).then(function(i){var e=i.data;t.cmsVersion=e.cmsVersion,t.pluginPathDict=e.pluginPathDict,t.getPackages()}).catch(function(t){utils.error(t)}).then(function(){utils.loading(t,!1)})},apiDownload:function(t,i){var e=this,a=this.pluginPathDict[t];$api.post($urlActionsDownload,{pluginId:t,version:i,path:a}).then(function(a){a.data.value?(e.currentDownloadingId=0,e.currentDownloadIds.push(t),e.download()):setTimeout(function(){e.apiDownload(t,i)},1e3)}).catch(function(t){utils.error(t)})},apiUpdate:function(t,i,e){var a=this;$api.post($urlActionsUpdate,{pluginId:t,version:i,packageType:e}).then(function(i){i.data;a.currentUpdatingId=0,a.currentUpdatedIds.push(t),a.update()}).catch(function(t){utils.error(t)})},apiRestart:function(t){var i=this;$api.post($urlActionsRestart,{isDisablePlugins:!!t}).then(function(e){setTimeout(function(){t?t():(i.percentage=100,utils.alertSuccess({title:"插件"+i.pageType+"成功",text:"插件"+i.pageType+"成功，系统需要重载页面",callback:function(){window.top.location.reload(!0)}}))},3e4)}).catch(function(t){utils.error(t)})},getPackages:function(){var t=this;cloud.getUpdates(t.cmsVersion,t.pluginIds).then(function(i){for(var e=i.data.releases,a=0;a<e.length;a++){var n=e[a],s=n.userName+"."+n.name;-1===t.listPackageIds.indexOf(s)&&(t.listPackageIds.push(s),t.listPackages.push({id:s,version:n.version,packageType:"Plugin"}))}t.apiRestart(function(){setTimeout(function(){t.installListPackage()},1e4)})}).catch(function(t){utils.error(t)})},installListPackage:function(){this.listIndex!==this.listPackages.length?(this.package=this.listPackages[this.listIndex],this.currentPackages.push(this.package),this.download()):this.apiRestart()},download:function(){for(var t=0;t<this.currentPackages.length;t++){var i=this.currentPackages[t];if(-1==this.currentDownloadIds.indexOf(i.id))return this.currentDownloadingId=i.id,void this.apiDownload(i.id,i.version)}this.update()},update:function(){this.active=1;for(var t=0;t<this.currentPackages.length;t++){var i=this.currentPackages[t];if(-1==this.currentUpdatedIds.indexOf(i.id))return this.currentUpdatingId=i.id,void this.apiUpdate(i.id,i.version,i.packageType)}this.updateSuccess()},updateSuccess:function(){this.listIndex++,this.active=0,this.currentPackage={},this.currentPackages=[],this.currentDownloadingId=0,this.currentDownloadIds=[],this.currentUpdatingId=0,this.currentUpdatedIds=[],this.installListPackage()},format:function(t){return 100===t?"插件"+this.pageType+"成功！":utils.getQueryBoolean("isUpdate")?"插件升级中，升级过程可能需要持续几分钟，请勿关闭此页面":"插件安装中..."}},$vue=new Vue({el:"#main",data:data,methods:methods,created:function(){this.apiGet()}});