import{y as _,u as g,c,f as N,j as i,S as C,r as D}from"./index-BQ5jItLS.js";import{a as v,z as y,L as M}from"./vue-Ce7h5hs3.js";import{u}from"./index-C9pWMHjm.js";import{u as w,t as P}from"./terminal-q4retXry.js";const e=v({loading:{buy:!1,table:!0,common:!1,install:!1,goodsInfo:!1},dialog:{buy:!1,pay:!1,common:!1,goodsInfo:!1,baAccount:!1},table:{remark:"",modules:[],modulesEbak:[],category:[],onlyLocal:!1,indexLoaded:!1,params:{quickSearch:"",activeTab:"all"}},payInfo:{},goodsInfo:{},buy:{info:{},renew:!1,agreement:!0},common:{uid:"",moduleState:0,quickClose:!1,type:"loading",dialogTitle:"",fileConflict:[],dependConflict:[],loadingTitle:"init",loadingComponentKey:_(),waitInstallDepend:[],dependInstallState:"none",disableConflictFile:[],disableDependConflict:[],disableParams:{},payType:"wx",update:!1,versions:[]},sysVersion:"",nuxtVersion:"",installedModule:[],installedModuleUids:[],installedModuleVersions:[]});var s=(o=>(o[o.UNINSTALLED=0]="UNINSTALLED",o[o.INSTALLED=1]="INSTALLED",o[o.WAIT_INSTALL=2]="WAIT_INSTALL",o[o.CONFLICT_PENDING=3]="CONFLICT_PENDING",o[o.DEPENDENT_WAIT_INSTALL=4]="DEPENDENT_WAIT_INSTALL",o[o.DIRECTORY_OCCUPIED=5]="DIRECTORY_OCCUPIED",o[o.DISABLE=6]="DISABLE",o))(s||{});const h="/api/v7.store/",m="/admin/module/";function U(o={}){return c({url:m+"index",method:"get",params:o})}function V(o={}){const a=g();return c({url:a.apiUrl+h+"modules",method:"get",params:o})}function O(o){const a=u(),n=g();return c({url:n.apiUrl+h+"info",method:"get",params:o},{anotherToken:a.getToken("auth")})}function B(o={}){const a=u(),n=g();return c({url:n.apiUrl+h+"order",method:"post",params:o},{anotherToken:a.getToken("auth")})}function F(o,a){const n=u(),t=g();return c({url:t.apiUrl+h+"pay",method:"post",params:{order_id:o,pay_type:a}},{anotherToken:n.getToken("auth"),showSuccessMessage:!0})}function R(o){const a=u(),n=g();return c({url:n.apiUrl+"/api/pay/check",method:"get",params:{sn:o}},{anotherToken:a.getToken("auth"),showCodeMessage:!1})}function W(o){const a=u(),n=g();return c({url:n.apiUrl+h+"preDownload",method:"POST",data:o},{anotherToken:a.getToken("auth")})}function z(o){return c({url:m+"state",method:"get",params:{uid:o}})}function q(o,a,n,t,d={}){const l=u();return c({url:m+"install",method:"POST",data:{uid:o,update:t,version:n,orderId:a,token:l.getToken("auth"),extend:d},timeout:3e3*10},{showCodeMessage:!1})}function J(o){return c({url:m+"uninstall",method:"post",params:{uid:o}},{showSuccessMessage:!0})}function k(o){return c({url:m+"changeState",method:"post",data:o},{showCodeMessage:!1})}function Q(o){return c({url:m+"dependentInstallComplete",method:"post",params:{uid:o}})}function ee(o){const a=u();return c({url:m+"upload",method:"post",params:{file:o,token:a.getToken("auth")}})}const Y=()=>{e.loading.table=!0,e.table.indexLoaded?A():G().then(()=>{A()})},f=()=>{e.table.indexLoaded=!1;for(const o in e.table.modulesEbak)e.table.modulesEbak[o]=void 0;Y()},G=()=>U().then(o=>{e.table.indexLoaded=!0,e.sysVersion=o.data.sysVersion,e.nuxtVersion=o.data.nuxtVersion,e.installedModule=o.data.installed;const a=[],n=[];o.data.installed&&(e.installedModule.forEach(t=>{a.push(t.uid),n.push({uid:t.uid,version:t.version})}),e.installedModuleUids=a,e.installedModuleVersions=n)}),A=()=>{if(typeof e.table.modulesEbak[e.table.params.activeTab]<"u"){e.table.modules[e.table.params.activeTab]=S(e.table.modulesEbak[e.table.params.activeTab]),e.loading.table=!1;return}const o={};for(const n in e.table.params)e.table.params[n]!=""&&(o[n]=e.table.params[n]);const a=[];o.installed=e.installedModuleVersions,o.sysVersion=e.sysVersion,V(o).then(n=>{o.activeTab=="all"&&(n.data.rows.forEach(t=>{a.push(t.uid)}),e.installedModule.forEach(t=>{a.indexOf(t.uid)===-1&&(e.table.params.quickSearch?t.title.includes(e.table.params.quickSearch)&&n.data.rows.push(t):n.data.rows.push(t))})),e.table.remark=n.data.remark,e.table.modulesEbak[o.activeTab]=n.data.rows.map(t=>{const d=e.installedModuleUids.indexOf(t.uid);return d!==-1?(t.state=e.installedModule[d].state,t.title=e.installedModule[d].title,t.version=e.installedModule[d].version,t.website=e.installedModule[d].website,t.stateTag=K(t.state),M(t.tags)||(t.tags=[]),t.tags.push({name:`${i.global.t("module.installed")} v${e.installedModule[d].version}`,type:"primary"})):t.state=0,t.new_version&&t.tags&&t.tags.push({name:i.global.t("module.New version"),type:"danger"}),t}),e.table.modules[o.activeTab]=S(e.table.modulesEbak[o.activeTab]),e.table.category=n.data.category}).finally(()=>{e.loading.table=!1})},E=o=>{e.dialog.goodsInfo=!0,e.loading.goodsInfo=!0;const a=e.installedModule.find(n=>n.uid==o);O({uid:o,localVersion:a==null?void 0:a.version,sysVersion:e.sysVersion}).then(n=>{a?(n.data.info.type=="local"?(n.data.info=a,n.data.info.images=[N("/static/images/local-module-logo.png")],n.data.info.type="local"):(n.data.info.type="online",n.data.info.state=a.state,n.data.info.version=a.version),n.data.info.enable=a.state!==s.DISABLE):(n.data.info.state=0,n.data.info.type="online"),e.goodsInfo=n.data.info}).catch(n=>{I(n)&&(e.dialog.goodsInfo=!1)}).finally(()=>{e.loading.goodsInfo=!1})},oe=(o=!1)=>{e.dialog.buy=!0,e.loading.buy=!0,B({goods_id:e.goodsInfo.id}).then(a=>{e.loading.buy=!1,e.buy.renew=o,e.buy.info=a.data.info}).catch(a=>{e.dialog.buy=!1,e.loading.buy=!1,I(a)})},ae=o=>{e.common.payType=o,e.loading.common=!0,F(e.buy.info.id,o).then(a=>{if(e.dialog.buy=!1,e.dialog.goodsInfo=!1,o=="wx"||o=="zfb"){e.dialog.pay=!0,e.payInfo=a.data;const n=setInterval(()=>{R(e.payInfo.info.sn).then(()=>{e.payInfo.pay.status="success",clearInterval(n),e.buy.renew?E(a.data.info.uid):L(a.data.info.uid,a.data.info.id,!0),e.dialog.pay=!1}).catch(()=>{})},3e3)}else e.buy.renew?E(a.data.info.uid):L(a.data.info.uid,a.data.info.id,!0)}).catch(a=>{I(a)}).finally(()=>{e.loading.common=!1})},T=o=>{e.common.type="loading",e.common.loadingTitle=o,e.common.loadingComponentKey=_()},L=(o,a,n,t=!1)=>{e.dialog.common=!0,T("init"),e.common.dialogTitle=i.global.t("module.Install");const d=l=>{n?(T("getInstallableVersion"),W({uid:o,orderId:a,sysVersion:e.sysVersion,nuxtVersion:e.nuxtVersion,installed:e.installedModuleUids}).then(r=>{e.common.uid=o,e.common.update=t,e.common.type="selectVersion",e.common.dialogTitle=i.global.t("module.Select Version"),e.common.versions=r.data.versions,e.dialog.baAccount=!1,e.dialog.buy=!1,e.dialog.goodsInfo=!1}).catch(r=>{I(r)||(e.dialog.common=!1)})):(T(l===s.UNINSTALLED?"download":"install"),x(o,a,"",t),e.dialog.baAccount=!1,e.dialog.buy=!1,e.dialog.goodsInfo=!1)};t?d(s.DISABLE):z(o).then(l=>{if(l.data.state===s.INSTALLED||l.data.state===s.DISABLE||l.data.state===s.DIRECTORY_OCCUPIED){y({type:"error",message:l.data.state===s.INSTALLED||l.data.state===s.DISABLE?i.global.t("module.Installation cancelled because module already exists!"):i.global.t("module.Installation cancelled because the directory required by the module is occupied!")}),e.dialog.common=!1;return}d(l.data.state)})},x=(o,a,n="",t=!1,d={})=>{q(o,a,n,t,d).then(()=>{e.common.dialogTitle=i.global.t("module.Installation complete"),e.common.moduleState=s.INSTALLED,e.common.type="done",f()}).catch(l=>{if(!I(l))if(l.code==-1)e.common.uid=l.data.uid,e.common.type="installConflict",e.common.dialogTitle=i.global.t("module.A conflict is found Please handle it manually"),e.common.fileConflict=l.data.fileConflict,e.common.dependConflict=l.data.dependConflict;else if(l.code==-2){e.common.type="done",e.common.uid=l.data.uid,e.common.dialogTitle=i.global.t("module.Wait for dependent installation"),e.common.moduleState=s.DEPENDENT_WAIT_INSTALL,e.common.waitInstallDepend=l.data.wait_install,e.common.dependInstallState="executing";const r=w();l.data.wait_install.includes("npm_dependent_wait_install")&&r.addTaskPM("web-install",!0,"module-install:"+l.data.uid,p=>{b(p,"npm_dependent_wait_install")}),l.data.wait_install.includes("nuxt_npm_dependent_wait_install")&&r.addTaskPM("nuxt-install",!0,"module-install:"+l.data.uid,p=>{b(p,"nuxt_npm_dependent_wait_install")}),l.data.wait_install.includes("composer_dependent_wait_install")&&r.addTask("composer.update",!0,"module-install:"+l.data.uid,p=>{b(p,"composer_dependent_wait_install")})}else l.code==0&&(y({type:"error",message:l.msg,zIndex:C}),e.dialog.common=!1,f())}).finally(()=>{e.loading.common=!1})},b=(o,a)=>{o==P.Success?(e.common.waitInstallDepend=e.common.waitInstallDepend.filter(n=>n!=a),e.common.waitInstallDepend.length==0&&(e.common.dependInstallState="success",D.currentRoute.value.name==="moduleStore/moduleStore"&&f())):(w().toggle(!0),e.common.dependInstallState="fail",D.currentRoute.value.name==="moduleStore/moduleStore"&&f()),D.currentRoute.value.name},ne=(o=!1)=>{if(e.loading.common=!0,o){const a={};for(const n in e.common.disableDependConflict)e.common.disableDependConflict[n].solution=="delete"&&(typeof a[e.common.disableDependConflict[n].env]>"u"&&(a[e.common.disableDependConflict[n].env]=[]),a[e.common.disableDependConflict[n].env].push(e.common.disableDependConflict[n].depend));e.common.disableParams.confirmConflict=1,e.common.disableParams.dependConflictSolution=a}k(e.common.disableParams).then(()=>{y({type:"success",message:i.global.t("module.The operation succeeds Please clear the system cache and refresh the browser ~"),zIndex:C}),e.dialog.common=!1,f()}).catch(a=>{if(a.code==-1){if(e.dialog.common=!0,e.common.dialogTitle=i.global.t("module.Deal with conflict"),e.common.type="disableConfirmConflict",e.common.disableDependConflict=a.data.dependConflict,a.data.conflictFile&&a.data.conflictFile.length){const n=[];for(const t in a.data.conflictFile)n.push({file:a.data.conflictFile[t]});e.common.disableConflictFile=n}}else if(a.code==-2){e.dialog.common=!0;const n={commands:a.data.wait_install};e.common.uid=e.goodsInfo.uid,j(n)}else a.code==-3?L(e.goodsInfo.uid,e.goodsInfo.purchased,!0,!0):(y({type:"error",message:a.msg,zIndex:C}),e.common.disableParams&&e.common.disableParams.uid?E(e.common.disableParams.uid):f())}).finally(()=>{e.loading.common=!1})},te=o=>{e.loading.common=!0,k({uid:o,state:1}).then(()=>{e.dialog.common=!0,T("init"),e.common.dialogTitle=i.global.t("Enable"),x(o,0),e.dialog.goodsInfo=!1}).catch(a=>{y({type:"error",message:a.msg,zIndex:C}),e.loading.common=!1})},I=o=>{const a=u();return o.code==301||o.code==408?(a.removeToken(),e.dialog.baAccount=!0,!0):!1},S=o=>e.table.onlyLocal?o.filter(a=>a.installed):o,j=o=>{{e.dialog.common=!0,e.common.type="done",e.common.dialogTitle=i.global.t("module.Wait for dependent installation"),e.common.moduleState=s.DISABLE,e.common.dependInstallState="executing";const a=w();o.commands.forEach(n=>{e.common.waitInstallDepend.push(n.type),n.pm?(n.command=="web-install",a.addTaskPM(n.command,!0,"",t=>{b(t,n.type),n.command=="web-install"})):a.addTask(n.command,!0,"",t=>{b(t,n.type)})})}},le=o=>o.nickname+"("+(o.email||o.mobile||"ID:"+o.id)+")",ie=(o,a)=>typeof o>"u"||typeof a>"u"?"-":a==0?parseInt(o.toString())+i.global.t("Integral"):"¥"+o,K=o=>{switch(o){case s.INSTALLED:return{type:"",text:i.global.t("module.installed")};case s.WAIT_INSTALL:return{type:"success",text:i.global.t("module.Wait for installation")};case s.CONFLICT_PENDING:return{type:"danger",text:i.global.t("module.Conflict pending")};case s.DEPENDENT_WAIT_INSTALL:return{type:"warning",text:i.global.t("module.Dependency to be installed")};case s.DISABLE:return{type:"warning",text:i.global.t("Disable")};default:return{type:"info",text:i.global.t("Unknown")}}};export{le as a,L as b,ie as c,Q as d,f as e,oe as f,T as g,x as h,ne as i,E as j,te as k,z as l,s as m,Y as n,ae as o,J as p,e as s,ee as u};