@acedatacloud/nexior 3.291.2 → 3.291.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (154) hide show
  1. package/dist/assets/{ApiCodeButton-hgfDFjNu.js → ApiCodeButton-B1hoxMD_.js} +1 -1
  2. package/dist/assets/{AskUserQuestionCard-C3Btm_Ci.js → AskUserQuestionCard-C5bJLOUN.js} +1 -1
  3. package/dist/assets/{Auth-CIlVLddV.js → Auth-WQZdO9JO.js} +1 -1
  4. package/dist/assets/{Bare-CyW2fFRD.js → Bare-B1mjt5Us.js} +1 -1
  5. package/dist/assets/{BotPlaceholder-DbazdyYE.js → BotPlaceholder-CxWOpeAr.js} +1 -1
  6. package/dist/assets/{BottomFooter-CnzsO-Iq.js → BottomFooter-CiNzdkMF.js} +1 -1
  7. package/dist/assets/{Callback-DJ-fmz72.js → Callback-DDrf1TKC.js} +1 -1
  8. package/dist/assets/{CodeSnippet-CA0UH8sX.js → CodeSnippet-D9-BGgIe.js} +1 -1
  9. package/dist/assets/{Console-Dwah-TY7.js → Console-YEZzvTlY.js} +1 -1
  10. package/dist/assets/{Consumption-DXuQfgv7.js → Consumption-rs4kWSdc.js} +1 -1
  11. package/dist/assets/{Conversation-DlPlPIRm.js → Conversation-D_KVYcZ8.js} +1 -1
  12. package/dist/assets/{CopyToClipboard-BDrnVqbi.js → CopyToClipboard-B-DcRyL3.js} +1 -1
  13. package/dist/assets/{Detail-BhPB8C9v.js → Detail-b8YTFgMx.js} +2 -2
  14. package/dist/assets/{Extra-Dy2VemtX.js → Extra-D5EVThOG.js} +1 -1
  15. package/dist/assets/{FilePreview-ixZvAtig.js → FilePreview-CIHQd26a.js} +1 -1
  16. package/dist/assets/{Hailuo-BN4N4CBj.js → Hailuo-BAPZvzc1.js} +1 -1
  17. package/dist/assets/{History-DSm9yehj.js → History-DumpndfA.js} +1 -1
  18. package/dist/assets/{ImagePreview-Bj-bj4gk.js → ImagePreview-CbkV1ul0.js} +1 -1
  19. package/dist/assets/{ImageWrapper-SGPsMbSn.js → ImageWrapper-BXkJewIG.js} +1 -1
  20. package/dist/assets/{Index-2v9hujQh.js → Index-B2Ht8_aW.js} +1 -1
  21. package/dist/assets/{Index-DK-Un7yF.js → Index-B7FjhuKC.js} +1 -1
  22. package/dist/assets/{Index-B1xmyXDu.js → Index-B7O86_An.js} +1 -1
  23. package/dist/assets/{Index-nHlJ-m0L.js → Index-Bck-wsQz.js} +1 -1
  24. package/dist/assets/{Index-BzGN-1I9.js → Index-BkgXzIfE.js} +1 -1
  25. package/dist/assets/{Index-DKFlBPw-.js → Index-Bqsk_7Qo.js} +1 -1
  26. package/dist/assets/{Index-DUd181tL.js → Index-ByJBnHHJ.js} +1 -1
  27. package/dist/assets/{Index-3LF_eKs8.js → Index-C18M9iA9.js} +1 -1
  28. package/dist/assets/{Index-B9U1Cxao.js → Index-C1kHnVDQ.js} +1 -1
  29. package/dist/assets/{Index-DeLdlabG.js → Index-CBma9aze.js} +1 -1
  30. package/dist/assets/{Index-BUwor1Av.js → Index-CSABJlfQ.js} +1 -1
  31. package/dist/assets/{Index-D0bPRLHq.js → Index-CZJRS7qa.js} +1 -1
  32. package/dist/assets/{Index-BZLoMH0c.js → Index-CbV4TKEn.js} +1 -1
  33. package/dist/assets/{Index-Ber9sjkt.js → Index-Cbgc-BPo.js} +1 -1
  34. package/dist/assets/{Index-DwV8QhLb.js → Index-CgkGApsj.js} +1 -1
  35. package/dist/assets/{Index-1kaDsspv.js → Index-ClKizqex.js} +1 -1
  36. package/dist/assets/{Index-BnZ3Sb2x.js → Index-DAs6ppgL.js} +1 -1
  37. package/dist/assets/{Index-zvG3E0V3.js → Index-DFUKttVb.js} +1 -1
  38. package/dist/assets/{Index-DaZymUd4.js → Index-DUjx_tM4.js} +1 -1
  39. package/dist/assets/{Index-BDGw8YMU.js → Index-Dfuqcga2.js} +1 -1
  40. package/dist/assets/{Index-C2DzSuF9.js → Index-Dhg9ynen.js} +1 -1
  41. package/dist/assets/{Index-C_bLBJ1n.js → Index-DtW_2ilE.js} +1 -1
  42. package/dist/assets/{Index-BDEvEBHG.js → Index-H1CxgPGj.js} +1 -1
  43. package/dist/assets/{Index-DYKOaWxJ.js → Index-H6QI5MXw.js} +1 -1
  44. package/dist/assets/{Index-G3n6Z5IU.js → Index-Op6cE1Di.js} +1 -1
  45. package/dist/assets/{Index-BndKuhwE.js → Index-XLC_tCFQ.js} +1 -1
  46. package/dist/assets/{Index-BydPD1zH.js → Index-a1Pep7Si.js} +1 -1
  47. package/dist/assets/{Index-7zSOGnmL.js → Index-ipMUu9x4.js} +1 -1
  48. package/dist/assets/{Invitees-opKpgUj6.js → Invitees-D652maGI.js} +1 -1
  49. package/dist/assets/{List-DgwuIwm4.js → List--vgcwLOU.js} +1 -1
  50. package/dist/assets/{List-Qt_c4wHD.js → List-MOpV7TFb.js} +1 -1
  51. package/dist/assets/{List-D4sCKVem.js → List-N5dJfqe9.js} +1 -1
  52. package/dist/assets/{Main-DVQ_AILV.js → Main-DEVdw-hl.js} +1 -1
  53. package/dist/assets/{Model-M-qAMaPx.js → Model-Df-usU_r.js} +1 -1
  54. package/dist/assets/{Navigator-CqqFre8U.js → Navigator-vMeUibUF.js} +1 -1
  55. package/dist/assets/{NoTasks-CQ86FPLl.js → NoTasks-CtAoFh9-.js} +1 -1
  56. package/dist/assets/{NotFound-DJm2MNJI.js → NotFound-CWmCw4EM.js} +1 -1
  57. package/dist/assets/{Pagination-YHZ8EQyy.js → Pagination-BZvLWtVy.js} +1 -1
  58. package/dist/assets/{Pay-0c9F_lcQ.js → Pay-CkzF22as.js} +1 -1
  59. package/dist/assets/{Player-AC7eIJ6Y.js → Player-C1SArojf.js} +1 -1
  60. package/dist/assets/{PromptTextarea-DgwkuWsn.js → PromptTextarea-D3Z1pjK1.js} +1 -1
  61. package/dist/assets/{RealtimeCall-BsQk3Ipr.js → RealtimeCall-B6OaLm9G.js} +1 -1
  62. package/dist/assets/ScheduledTasks-DG4GneFy.css +1 -0
  63. package/dist/assets/ScheduledTasks-XQzllLGK.js +2 -0
  64. package/dist/assets/{Status-DUWd7Jf9.js → Status-DYuOXZyK.js} +1 -1
  65. package/dist/assets/{Subscribe-LyuIgnd9.js → Subscribe-qYxGsl41.js} +1 -1
  66. package/dist/assets/{TabSwitcher-BeDnFcKf.js → TabSwitcher-DvQvtn75.js} +1 -1
  67. package/dist/assets/{Tts-BeiCOFxi.js → Tts-CqGh2Fks.js} +1 -1
  68. package/dist/assets/{VideoPlayer-CxxanuXH.js → VideoPlayer-DEduD1xz.js} +1 -1
  69. package/dist/assets/{avatar-CUVm0jdm.js → avatar-CianzGwH.js} +1 -1
  70. package/dist/assets/{basic-C2tkb5ZS.js → basic-BaNGHrhD.js} +1 -1
  71. package/dist/assets/{chat-CHKGitig.js → chat-BjUOaxCa.js} +1 -1
  72. package/dist/assets/{chat-np6Yvjh_.js → chat-C05rqB3S.js} +1 -1
  73. package/dist/assets/{chat-Cd_JNn2R.js → chat-CDJKQXc5.js} +1 -1
  74. package/dist/assets/{chat-DUx-O8my.js → chat-CHi2xszy.js} +1 -1
  75. package/dist/assets/{chat-BkKtyoOh.js → chat-CTJ1pNb2.js} +1 -1
  76. package/dist/assets/{chat-CpCGuM3Z.js → chat-CkAUIDZB.js} +1 -1
  77. package/dist/assets/{chat-Cvfb0EjB.js → chat-D25QMCb4.js} +1 -1
  78. package/dist/assets/{chat-DRrWmA9d.js → chat-DG5D-oEf.js} +1 -1
  79. package/dist/assets/{chat-DXziUQkd.js → chat-DN6IuTqi.js} +1 -1
  80. package/dist/assets/{chat-76Yo-7fp.js → chat-Dd8NWDCG.js} +1 -1
  81. package/dist/assets/{chat-DNYrAVZU.js → chat-DlV8trN7.js} +1 -1
  82. package/dist/assets/{chat-B-UnhUFe.js → chat-HGb_jEq8.js} +1 -1
  83. package/dist/assets/{chat-BNGXJBUU.js → chat-IUqkQT8j.js} +1 -1
  84. package/dist/assets/{chat-SHvPxSUw.js → chat-JWt1P9wI.js} +1 -1
  85. package/dist/assets/{chat-DmnkPVEL.js → chat-KyrIn9z5.js} +1 -1
  86. package/dist/assets/{chat-CM8UIT0Q.js → chat-Og64m4jF.js} +1 -1
  87. package/dist/assets/{chat-DOfunx40.js → chat-uuNgW780.js} +1 -1
  88. package/dist/assets/{chat-CgIIGEPn.js → chat-vPFp9Zvj.js} +1 -1
  89. package/dist/assets/{chat-BI9SBuBD.js → chat-yoPuM3jt.js} +1 -1
  90. package/dist/assets/{codingBridge-BDRXdXO6.js → codingBridge-D-QE_E-V.js} +1 -1
  91. package/dist/assets/{codingBridgeNotify-Pct5abOe.js → codingBridgeNotify-4tymAvxz.js} +2 -2
  92. package/dist/assets/{collapse-DkqDcPWQ.js → collapse-DZLlhQOY.js} +1 -1
  93. package/dist/assets/{constants-RDUJTh3D.js → constants-HhUTei7L.js} +1 -1
  94. package/dist/assets/{createTaskActions-DEzPHhF8.js → createTaskActions-OjzHCDdW.js} +1 -1
  95. package/dist/assets/{date-picker-CRIxhOXx.js → date-picker-Dc-4ebse.js} +1 -1
  96. package/dist/assets/{digitalhuman-DIVclA5K.js → digitalhuman-I-L5fs_5.js} +1 -1
  97. package/dist/assets/{dropdown-BdMNgqet.js → dropdown-BMpGHP_0.js} +1 -1
  98. package/dist/assets/{esm-CSE8uGEp.js → esm-C7ESax8S.js} +3 -3
  99. package/dist/assets/{esm-zn7I8ujJ.js → esm-C9RH2kQj.js} +1 -1
  100. package/dist/assets/{esm-C0c_aiIg.js → esm-CAz980EX.js} +2 -2
  101. package/dist/assets/esm-CCohGild.js +1 -0
  102. package/dist/assets/{esm-Cs_ipdys.js → esm-C_ZCTpJ0.js} +1 -1
  103. package/dist/assets/{esm-CMne3zKM.js → esm-Cuc2vOKT.js} +1 -1
  104. package/dist/assets/{esm-D7UeKPez.js → esm-zTUs9f8-.js} +2 -2
  105. package/dist/assets/{fish-DiFw1SnO.js → fish-D1qx4mQl.js} +1 -1
  106. package/dist/assets/{flux-C68WLFyu.js → flux-BwqbIRbw.js} +1 -1
  107. package/dist/assets/{grokvideo-irAmKCdR.js → grokvideo-DfwmIMKj.js} +1 -1
  108. package/dist/assets/{hailuo-BRVzCB8z.js → hailuo-FskKXgsI.js} +1 -1
  109. package/dist/assets/{headshots-CB4XhhHM.js → headshots-Cu_c5wi_.js} +1 -1
  110. package/dist/assets/{image-BHSCm3en.js → image-B-0AtpMP.js} +1 -1
  111. package/dist/assets/{index-Bm66Z2-R.js → index-DPve7EH6.js} +4 -4
  112. package/dist/assets/{index.browser.esm-iFdCC3Ny.js → index.browser.esm-HhPUjOR2.js} +1 -1
  113. package/dist/assets/{index.es-ktQaPrdW.js → index.es-ChPsc2I6.js} +1 -1
  114. package/dist/assets/{input-number-Cuac16np.js → input-number-DBzhzM31.js} +1 -1
  115. package/dist/assets/{kling-erSRp-4k.js → kling-NWaYsmsA.js} +1 -1
  116. package/dist/assets/{luma-DtTNHriu.js → luma-AFKplBM8.js} +1 -1
  117. package/dist/assets/{maestro-CjFC7A1K.js → maestro-Ud0lQmvR.js} +1 -1
  118. package/dist/assets/{midjourney-CPelGjwM.js → midjourney-BVy9N8Ac.js} +1 -1
  119. package/dist/assets/{nanobanana-QYuBswGd.js → nanobanana-B4tdJw32.js} +1 -1
  120. package/dist/assets/{openaiimage-B-XoAUyB.js → openaiimage-ChJkAnOv.js} +1 -1
  121. package/dist/assets/{pagination-kIm3sLkY.js → pagination-C_evzXg5.js} +1 -1
  122. package/dist/assets/{sora-yLY3H3_2.js → pika-CBHPAO6j.js} +1 -1
  123. package/dist/assets/{pixverse-DpFiZX2t.js → pixverse-BUq31EWR.js} +1 -1
  124. package/dist/assets/{popover-CX0ok0mJ.js → popover-BkRBcMBE.js} +1 -1
  125. package/dist/assets/{producer-CmkYfnfW.js → producer-DCJMHwTU.js} +1 -1
  126. package/dist/assets/{qrart-XHuqltgM.js → qrart-DomCVLv2.js} +1 -1
  127. package/dist/assets/{realtime-7p7pMtuj.js → realtime-BQRrHdIs.js} +1 -1
  128. package/dist/assets/{row-B1qA_KsB.js → row-COldDsV6.js} +1 -1
  129. package/dist/assets/{seedance-D5n7I8tJ.js → seedance-CiVc8oaE.js} +1 -1
  130. package/dist/assets/{seedream-Bty6iQMU.js → seedream-DsJb7Bkb.js} +1 -1
  131. package/dist/assets/{select-VY4i3iMR.js → select-DooKN8lb.js} +1 -1
  132. package/dist/assets/{serp-DWFgwMJJ.js → serp-DRCafKst.js} +1 -1
  133. package/dist/assets/{slider-BfZYrRVX.js → slider-CJuKS4t0.js} +1 -1
  134. package/dist/assets/{solana-wallets-CTJEg34j.js → solana-wallets-C2DjfS_9.js} +2 -2
  135. package/dist/assets/{solana-wallets-vue-Bwrq4rbp.js → solana-wallets-vue-Cnub6MHB.js} +1 -1
  136. package/dist/assets/{pika-DaNWcnBO.js → sora-GiqNRtSo.js} +1 -1
  137. package/dist/assets/{suno-B6Mohsrn.js → suno-9kGn6nnA.js} +1 -1
  138. package/dist/assets/{switch-BgIktbEW.js → switch-CWjdffRF.js} +1 -1
  139. package/dist/assets/{tabs-CZiMXYOx.js → tabs-DmrdWXQG.js} +1 -1
  140. package/dist/assets/{time-picker-9FPzcpyC.js → time-picker-DNBlerI0.js} +1 -1
  141. package/dist/assets/{upload-BHEVKf-6.js → upload-Djeg64kR.js} +1 -1
  142. package/dist/assets/{veo-B__u3-ED.js → veo-BOoVP0q0.js} +1 -1
  143. package/dist/assets/{wan-BHNcmgWv.js → wan-fY1hzyFm.js} +1 -1
  144. package/dist/assets/{web-bAMeCbrh.js → web-BWrBPFOq.js} +1 -1
  145. package/dist/assets/{web-DFmzvjvw.js → web-B_dvT1tX.js} +1 -1
  146. package/dist/assets/{web-CoCzG3F8.js → web-C9qmcLhH.js} +1 -1
  147. package/dist/assets/{web-hkBNc0gQ.js → web-CeTUJ74Z.js} +1 -1
  148. package/dist/assets/{web-CmslLWy9.js → web-Z_88ywvA.js} +1 -1
  149. package/dist/assets/{webextrator-DuTyCwG-.js → webextrator-B65qq-L6.js} +1 -1
  150. package/dist/index.html +2 -2
  151. package/package.json +1 -1
  152. package/dist/assets/ScheduledTasks-BtLIH6TM.css +0 -1
  153. package/dist/assets/ScheduledTasks-CnYCTKtb.js +0 -2
  154. package/dist/assets/esm-DunWK3l_.js +0 -1
@@ -1 +1 @@
1
- import"./rolldown-runtime--c01j_DQ.js";import{$ as e,A as t,D as n,F as r,N as i,O as a,P as o,S as s,Wt as c,Z as l,a as u,c as d,dt as f,i as ee,k as p,n as m,nt as h,o as g,r as _,s as v,t as y,tt as b,ut as x,v as S}from"./vendor-chart-BJCvKk8-.js";import{t as C}from"./button-BydTr5nV.js";import{r as w,t as T}from"./select-VY4i3iMR.js";import{n as E,t as D}from"./table-BJr3w4hQ.js";import{n as O,t as k}from"./tabs-CZiMXYOx.js";import{t as A}from"./card-DjyfNde2.js";import{n as j,r as M}from"./radio-3Hz7h3DR.js";import{t as N}from"./date-picker-CRIxhOXx.js";import{n as P,t as F}from"./row-B1qA_KsB.js";import{t as I}from"./Pagination-YHZ8EQyy.js";import{n as L,t as R}from"./skeleton-BwNBivMN.js";import{E as z,Fn as B,Gr as V,Nn as H,Or as U,Pn as W,Ur as G,br as K,xr as q,zn as J}from"./index-Bm66Z2-R.js";import{t as Y}from"./index.es-ktQaPrdW.js";import{t as X}from"./CopyToClipboard-BDrnVqbi.js";ee.register(_,u,m,v,d,g);var Z=r({name:`ConsoleUsageList`,components:{Pagination:I,ElTag:V,ElDatePicker:N,ElTable:D,ElSelect:w,ElOption:T,CopyToClipboard:X,ElRow:F,ElCol:P,ElTableColumn:E,ElCard:A,ElRadioButton:j,ElRadioGroup:M,ElSkeleton:R,ElSkeletonItem:L,ElDialog:G,ElTabs:O,ElTabPane:k,ElButton:C,FontAwesomeIcon:Y,BarChart:y},data(){return{applicationIds:this.$route.query.application_id?.toString()?this.$route.query.application_id?.toString().split(`,`):[],apiIds:this.$route.query.api_id?.toString()?this.$route.query.api_id?.toString().split(`,`):[],applications:[],apis:[],apisLoading:!1,credentialType:K,serviceType:q,apiUsages:[],proxyUsages:[],createdAtRange:(()=>{let e=this.$route.query.created_at_to?.toString(),t=this.$route.query.created_at_from?.toString();if(t&&e)return[new Date(t),new Date(e)];let n=new Date,r=new Date;return r.setDate(1),r.setHours(0,0,0,0),[r,n]})(),shortcuts:[{text:this.$t(`usage.shortcuts.thisMonth`),value:()=>{let e=new Date,t=new Date;return t.setDate(1),t.setHours(0,0,0,0),[t,e]}},{text:this.$t(`usage.shortcuts.today`),value:()=>{let e=new Date,t=new Date;return t.setHours(0,0,0,0),[t,e]}},{text:this.$t(`usage.shortcuts.last1Day`),value:()=>{let e=new Date,t=new Date;return t.setDate(t.getDate()-1),[t,e]}},{text:this.$t(`usage.shortcuts.last3Days`),value:()=>{let e=new Date,t=new Date;return t.setDate(t.getDate()-3),[t,e]}},{text:this.$t(`usage.shortcuts.last7Days`),value:()=>{let e=new Date,t=new Date;return t.setDate(t.getDate()-7),[t,e]}},{text:this.$t(`usage.shortcuts.last1Month`),value:()=>{let e=new Date,t=new Date;return t.setMonth(t.getMonth()-1),[t,e]}}],type:this.$route.query.type?.toString()||q.API,loading:!1,total:void 0,limit:15,totalUsed:0,barChartLabels:[],barChartSeries:[],aggLoading:!1,detailDialogVisible:!1,detailRow:null,detailActiveTab:`request`,detailLoading:!1,exporting:!1,statusCodeFilter:this.$route.query.status_code?.toString()||``,statusCodeOptions:[],statusCodeOptionsLoading:!1}},computed:{redirect(){return this.$route.query?.redirect},page(){return parseInt(this.$route.query.page?.toString()||`1`)},totalUsedString(){return`${(this.totalUsed||0).toFixed(2)}`},barChartData(){return{labels:this.barChartLabels,datasets:this.barChartSeries.map(e=>({label:e.label,data:e.data,backgroundColor:e.color}))}},barChartOptions(){return{responsive:!0,plugins:{legend:{position:`top`,onClick:(e,t,n)=>{let r=n?.chart;if(!r||t?.datasetIndex===void 0)return;let i=t.datasetIndex,a=r.data?.datasets||[];a.some((e,t)=>t!==i&&r.isDatasetVisible(t))?a.forEach((e,t)=>r.setDatasetVisibility(t,t===i)):a.forEach((e,t)=>r.setDatasetVisibility(t,!0)),r.update()}},title:{display:!0,text:this.$t(`usage.title.usageTrend`)}},scales:{x:{stacked:!0},y:{stacked:!0,beginAtZero:!0}}}}},watch:{page:{handler(){this.onFetchUsages()}},type:{handler(){this.applicationIds=[],this.apiIds=[],this.onApplicationsChange(this.applicationIds),this.onFetchApplications(),this.onFetchApis(),this.onFetchUsages(),this.onFetchAggregate(),this.onFetchStatusCodeOptions()}}},mounted(){this.onFetchApplications(),this.onFetchApis(),this.onFetchUsages(),this.onFetchAggregate(),this.onFetchStatusCodeOptions()},methods:{async onFetchUsages(){this.type===q.API?this.onFetchApiUsages():this.type===q.Proxy&&this.onFetchProxyUsages()},async onApiChange(e){await this.$router.push({name:this.$route.name?.toString(),query:{...this.$route.query,api_id:e}}),this.onFetchApiUsages(),this.onFetchAggregate()},async onApisChange(e){await this.$router.push({name:this.$route.name?.toString(),query:{...this.$route.query,api_id:e&&e.length?e.join(`,`):``}}),this.onFetchApiUsages(),this.onFetchAggregate()},async onTimeRangeChanged(){console.log(`onTimeRangeChanged`,this.createdAtRange),await this.$router.push({name:this.$route.name?.toString(),query:{...this.$route.query,created_at_from:this.createdAtRange?this.$dayjs.format(this.createdAtRange[0].toString(),`YYYY-MM-DDTHH:mm:ss.SSSSSSZ`):``,created_at_to:this.createdAtRange?this.$dayjs.format(this.createdAtRange[1].toString(),`YYYY-MM-DDTHH:mm:ss.SSSSSSZ`):``}}),this.onFetchUsages(),this.onFetchAggregate(),this.onFetchStatusCodeOptions()},async onApplicationChange(e){await this.$router.push({name:this.$route.name?.toString(),query:{...this.$route.query,application_id:e}}),this.onFetchUsages(),this.onFetchAggregate()},async onApplicationsChange(e){await this.$router.push({name:this.$route.name?.toString(),query:{...this.$route.query,application_id:e&&e.length?e.join(`,`):``}}),this.onFetchUsages(),this.onFetchAggregate()},onPageChange(e){this.$router.push({name:this.$route.name?.toString(),query:{...this.$route.query,page:e}})},getRemainingAmount(e){if(e.remaining_amount===void 0||e.remaining_amount===null)return``;let t=this.$t(`service.unit.${e?.service?.unit||`credit`}s`);return`${e.remaining_amount?.toFixed(6)} ${t}`},getUsedAmount(e){if(e.used_amount===void 0||e.used_amount===null)return``;let t=this.$t(`service.unit.${e?.service?.unit||`credit`}s`);return`${e.used_amount?.toFixed(6)} ${t}`},getDeductedAmount(e){if(e?.deducted_amount===void 0||e?.deducted_amount===null)return``;let t=this.$t(`service.unit.${e?.service?.unit||`credit`}s`);return`${e.deducted_amount?.toFixed(6)} ${t}`},getOriginalAmount(e){if(e?.original_amount===void 0||e?.original_amount===null)return``;let t=this.$t(`service.unit.${e?.service?.unit||`credit`}s`);return`${e.original_amount?.toFixed(6)} ${t}`},onStatusCodeChange(e){let t={...this.$route.query},n=(e||``).trim();n?t.status_code=n:delete t.status_code,delete t.status_code_filter,this.$router.push({name:this.$route.name?.toString(),query:t}),this.onFetchUsages(),this.onFetchAggregate()},async onFetchStatusCodeOptions(){this.statusCodeOptionsLoading=!0;try{let{data:e}=await W.getStatusCodes({user_id:this.$store.getters.user.id,...this.applicationIds&&this.applicationIds.length?{application_id:this.applicationIds}:{},...this.apiIds&&this.apiIds.length?{api_id:this.apiIds}:{},...this.createdAtRange?.[0]?{created_at_from:this.createdAtRange[0]}:{},...this.createdAtRange?.[1]?{created_at_to:this.createdAtRange[1]}:{}});this.statusCodeOptions=(e?.items||[]).slice().sort((e,t)=>e-t)}catch{this.statusCodeOptions=[]}finally{this.statusCodeOptionsLoading=!1}},formatElapsed(e){return e==null||Number.isNaN(e)?`-`:e<1?`${Math.round(e*1e3)} ms`:`${e.toFixed(2)} s`},getSimpleMetadata(e){if(!e)return{};let t={};for(let[n,r]of Object.entries(e))n===`request`||n===`response`||typeof r==`object`&&r||(t[n]=r);return t},onShowDetail(e){this.detailRow={...e,metadata:void 0},this.detailActiveTab=`request`,this.detailDialogVisible=!0,this.detailLoading=!0,e.id&&W.get(e.id).then(e=>{this.detailRow=e.data}).finally(()=>{this.detailLoading=!1})},formatJson(e){try{return JSON.stringify(e,null,2)}catch{return String(e)}},onFetchApplications(){J.getAll({limit:100,offset:0,user_id:this.$store.getters.user.id,ordering:`-created_at`,type:U.USAGE}).then(({data:e})=>{this.applications=e.items.filter(e=>e?.service?.type===this.type)}).catch(()=>{})},onFetchApis(){this.apisLoading=!0,H.getAll({limit:100,offset:0,ordering:`-created_at`}).then(({data:e})=>{this.apis=e.items}).catch(()=>{}).finally(()=>{this.apisLoading=!1})},onFetchApiUsages(){console.log(`onFetchApiUsages`,this.createdAtRange),this.loading=!0,W.getAll({limit:this.limit,offset:(this.page-1)*this.limit,user_id:this.$store.getters.user.id,ordering:`-created_at`,...this.createdAtRange?.[0]?{created_at_from:this.createdAtRange[0]}:{},...this.createdAtRange?.[1]?{created_at_to:this.createdAtRange[1]}:{},...this.applicationIds&&this.applicationIds.length?{application_id:this.applicationIds}:{},...this.apiIds&&this.apiIds.length?{api_id:this.apiIds}:{},...this.statusCodeFilter?{status_code:this.statusCodeFilter}:{}}).then(({data:e})=>{this.apiUsages=e.items,this.loading=!1,this.total=e.count}).catch(()=>{this.loading=!1})},onFetchProxyUsages(){this.loading=!0,B.getAll({limit:this.limit,offset:(this.page-1)*this.limit,user_id:this.$store.getters.user.id,ordering:`-created_at`,...this.applicationIds&&this.applicationIds.length?{application_id:this.applicationIds}:{}}).then(({data:e})=>{this.proxyUsages=e.items,this.loading=!1,this.total=e.count}).catch(()=>{this.loading=!1})},onExport(){this.exporting=!0,W.exportCsv({user_id:this.$store.getters.user.id,...this.createdAtRange?.[0]?{created_at_from:this.createdAtRange[0]}:{},...this.createdAtRange?.[1]?{created_at_to:this.createdAtRange[1]}:{},...this.applicationIds&&this.applicationIds.length?{application_id:this.applicationIds}:{},...this.apiIds&&this.apiIds.length?{api_id:this.apiIds}:{},...this.statusCodeFilter?{status_code:this.statusCodeFilter}:{}}).then(({data:e})=>{let t=window.URL.createObjectURL(e),n=document.createElement(`a`);n.href=t,n.download=`usages.csv`,n.click(),window.URL.revokeObjectURL(t)}).catch(()=>{}).finally(()=>{this.exporting=!1})},async onFetchAggregate(){if(this.aggLoading=!0,this.type!==this.serviceType.API)return;let e={user_id:this.$store.getters.user.id,...this.applicationIds&&this.applicationIds.length?{application_id:this.applicationIds}:{},...this.apiIds&&this.apiIds.length?{api_id:this.apiIds}:{},...this.createdAtRange?.[0]?{created_at_from:this.createdAtRange[0]}:{},...this.createdAtRange?.[1]?{created_at_to:this.createdAtRange[1]}:{}};try{let{data:t}=await W.getAggregate(e);this.totalUsed=t.total||0;let n=Array.from(new Set((t.items||[]).map(e=>e.date))).sort(),r=Array.from(new Set((t.items||[]).map(e=>e.api_id))),i=e=>`hsl(${e*57%360}, 70%, 60%)`,a=r.map((e,r)=>{let a=t.apis?.[e]?.title||e,o={};return(t.items||[]).filter(t=>t.api_id===e).forEach(e=>{o[e.date]=e.amount||0}),{key:e,label:a,data:n.map(e=>o[e]||0),color:i(r)}});this.barChartLabels=n,this.barChartSeries=a}finally{this.aggLoading=!1}}}}),Q={class:`text-[26px] font-bold mb-5 text-[var(--el-text-color-primary)]`},$={class:`inline-block w-9`},te={class:`inline-block`},ne={key:1,class:`summary-card`},re={class:`icon-wrapper`},ie={class:`text-left`},ae={class:`description`},oe={class:`value`},se={class:`chart-wrapper`},ce={key:0},le={key:1},ue={class:`flex flex-wrap gap-2`},de={class:`key`},fe={key:0,class:`cursor-pointer`},pe={class:`created-at`},me={class:`created-at`},he={key:1,class:`detail-json`},ge={key:2,class:`text-gray-400`},_e={key:1,class:`detail-json`},ve={key:2,class:`text-gray-400`},ye={class:`float-right`};function be(r,u,d,ee,m,g){let _=b(`el-col`),v=b(`el-row`),y=b(`el-radio-button`),C=b(`el-radio-group`),w=b(`el-option`),T=b(`el-select`),E=b(`el-skeleton-item`),D=b(`el-skeleton`),O=b(`el-date-picker`),k=b(`font-awesome-icon`),A=b(`el-button`),j=b(`el-card`),M=b(`bar-chart`),N=b(`el-table-column`),P=b(`el-tag`),F=b(`copy-to-clipboard`),I=b(`el-table`),L=b(`el-tab-pane`),R=b(`el-tabs`),z=b(`el-dialog`),B=b(`pagination`),V=h(`loading`);return l(),a(v,null,{default:x(()=>[o(_,{span:24},{default:x(()=>[o(v,null,{default:x(()=>[o(_,{span:24},{default:x(()=>[n(`h2`,Q,c(r.$t(`common.title.allUsages`)),1)]),_:1})]),_:1}),o(v,null,{default:x(()=>[o(_,{md:4,xs:24,class:`mb-5 flex px-2 gap-2 items-center`},{default:x(()=>[n(`span`,null,c(r.$t(`application.field.type`)),1),o(C,{modelValue:r.type,"onUpdate:modelValue":u[0]||=e=>r.type=e},{default:x(()=>[o(y,{value:r.serviceType.API,label:r.$t(`application.field.api`)},null,8,[`value`,`label`]),o(y,{value:r.serviceType.Proxy,label:r.$t(`application.field.proxy`)},null,8,[`value`,`label`])]),_:1},8,[`modelValue`])]),_:1}),f(o(_,{md:6,xs:24,class:`mb-5 flex px-2 gap-2 items-center`},{default:x(()=>[n(`span`,$,c(r.$t(`usage.field.application`)),1),o(T,{modelValue:r.applicationIds,"onUpdate:modelValue":u[1]||=e=>r.applicationIds=e,placeholder:r.$t(`usage.field.application`),clearable:``,multiple:``,"collapse-tags":``,"collapse-tags-tooltip":``,class:`w-full`,onChange:r.onApplicationsChange},{default:x(()=>[(l(!0),t(s,null,e(r.applications,e=>(l(),a(w,{key:e.id,label:e.service?.title,value:e?.id},null,8,[`label`,`value`]))),128))]),_:1},8,[`modelValue`,`placeholder`,`onChange`])]),_:1},512),[[S,!1]]),r.type===r.serviceType.API?(l(),a(_,{key:0,md:6,xs:24,class:`mb-5 flex px-2 gap-2 items-center`},{default:x(()=>[n(`span`,te,c(r.$t(`usage.field.api`)),1),r.apisLoading?(l(),a(D,{key:0,animated:``,class:`w-full`},{template:x(()=>[o(E,{variant:`rect`,style:{height:`32px`,"border-radius":`4px`}})]),_:1})):(l(),a(T,{key:1,modelValue:r.apiIds,"onUpdate:modelValue":u[2]||=e=>r.apiIds=e,placeholder:r.$t(`usage.field.api`),clearable:``,filterable:``,multiple:``,"collapse-tags":``,"collapse-tags-tooltip":``,class:`w-full`,onChange:r.onApisChange},{default:x(()=>[(l(!0),t(s,null,e(r.apis,e=>(l(),a(w,{key:e?.id,label:e?.title,value:e?.id},null,8,[`label`,`value`]))),128))]),_:1},8,[`modelValue`,`placeholder`,`onChange`]))]),_:1})):p(``,!0),r.type===r.serviceType.API?(l(),a(_,{key:1,md:8,xs:24,class:`mb-5 flex px-2 gap-2 items-center`},{default:x(()=>[o(O,{modelValue:r.createdAtRange,"onUpdate:modelValue":u[3]||=e=>r.createdAtRange=e,type:`datetimerange`,class:`w-full`,shortcuts:r.shortcuts,"range-separator":r.$t(`usage.placeholder.to`),"start-placeholder":r.$t(`usage.placeholder.startDate`),"end-placeholder":r.$t(`usage.placeholder.endDate`),onChange:r.onTimeRangeChanged},null,8,[`modelValue`,`shortcuts`,`range-separator`,`start-placeholder`,`end-placeholder`,`onChange`])]),_:1})):p(``,!0),r.type===r.serviceType.API?(l(),a(_,{key:2,md:3,xs:24,class:`mb-5 flex px-2 gap-2 items-center`},{default:x(()=>[o(T,{modelValue:r.statusCodeFilter,"onUpdate:modelValue":u[4]||=e=>r.statusCodeFilter=e,placeholder:r.$t(`usage.option.statusCodeAll`),class:`w-full`,clearable:``,filterable:``,"allow-create":``,"default-first-option":``,loading:r.statusCodeOptionsLoading,onChange:r.onStatusCodeChange},{default:x(()=>[(l(!0),t(s,null,e(r.statusCodeOptions,e=>(l(),a(w,{key:e,label:String(e),value:String(e)},null,8,[`label`,`value`]))),128))]),_:1},8,[`modelValue`,`placeholder`,`loading`,`onChange`])]),_:1})):p(``,!0),r.type===r.serviceType.API?(l(),a(_,{key:3,md:3,xs:24,class:`mb-5 flex px-2 gap-2 items-center justify-end`},{default:x(()=>[o(A,{type:`primary`,plain:``,loading:r.exporting,class:`w-full whitespace-nowrap`,onClick:r.onExport},{default:x(()=>[o(k,{icon:`fa-solid fa-file-export`,class:`mr-1`}),i(` `+c(r.$t(`usage.button.export`)),1)]),_:1},8,[`loading`,`onClick`])]),_:1})):p(``,!0)]),_:1}),o(v,null,{default:x(()=>[o(_,{span:24},{default:x(()=>[r.type===r.serviceType.API?(l(),a(v,{key:0,gutter:24,class:`mb-5`},{default:x(()=>[o(_,{md:6,xs:24},{default:x(()=>[o(j,{shadow:`hover`,class:`h-full`},{default:x(()=>[r.aggLoading?(l(),a(D,{key:0})):(l(),t(`div`,ne,[n(`div`,re,[o(k,{icon:`fa-solid fa-cubes`,class:`icon`})]),n(`div`,ie,[n(`p`,ae,c(r.$t(`usage.title.totalUsed`)),1),n(`p`,oe,c(r.totalUsedString),1)])]))]),_:1})]),_:1}),o(_,{md:18,xs:24},{default:x(()=>[o(j,{shadow:`hover`,class:`h-full`},{default:x(()=>[n(`div`,se,[r.aggLoading?(l(),a(D,{key:0,class:`w-full`})):(l(),a(M,{key:1,data:r.barChartData,options:r.barChartOptions,class:`chart`},null,8,[`data`,`options`]))])]),_:1})]),_:1})]),_:1})):p(``,!0),o(j,{shadow:`hover`},{default:x(()=>[r.type===r.serviceType.API?f((l(),a(I,{key:0,data:r.apiUsages,stripe:``,"table-layout":`fixed`,"empty-text":r.$t(`common.message.noData`),class:`min-h-[calc(100vh-350px)] mb-5`},{default:x(()=>[o(N,{label:r.$t(`application.field.name`),width:`160px`},{default:x(e=>[n(`span`,null,c(e.row?.api?.title),1)]),_:1},8,[`label`]),o(N,{label:r.$t(`usage.field.statusCode`),width:`120px`},{default:x(e=>[n(`span`,null,c(e.row.status_code),1)]),_:1},8,[`label`]),o(N,{label:r.$t(`usage.field.elapsed`),width:`120px`},{default:x(e=>[n(`span`,null,c(r.formatElapsed(e.row.elapsed)),1)]),_:1},8,[`label`]),o(N,{prop:`deducted_amount`,label:r.$t(`usage.field.deductedAmount`),width:`150px`,"class-name":`text-center`},{default:x(e=>[r.getDeductedAmount(e.row)===r.getOriginalAmount(e.row)?(l(),t(`div`,ce,[n(`span`,null,c(r.getDeductedAmount(e.row)),1)])):(l(),t(`div`,le,[u[7]||=n(`p`,null,null,-1),n(`p`,null,[n(`span`,null,c(r.getDeductedAmount(e.row)),1)]),n(`p`,null,[n(`del`,null,c(r.getOriginalAmount(e.row)),1)])]))]),_:1},8,[`label`]),o(N,{prop:`remaining_amount`,label:r.$t(`usage.field.balanceAfter`),width:`160px`,"class-name":`text-center`},{default:x(e=>[n(`span`,null,c(r.getRemainingAmount(e.row)),1)]),_:1},8,[`label`]),o(N,{prop:`metadata`,label:r.$t(`usage.field.metadata`),width:`260px`,"class-name":`text-center`},{default:x(o=>[n(`div`,ue,[o.row.original_amount>o.row.deducted_amount&&o.row.original_amount>0?(l(),a(P,{key:0,type:`success`,style:{textWrap:`wrap`,height:`fit-content`,lineHeight:`20px`,borderRadius:`10px`}},{default:x(()=>[i(c(((o.row.original_amount-o.row.deducted_amount)*100/o.row.original_amount).toFixed(0)+`% OFF`),1)]),_:2},1024)):p(``,!0),(l(!0),t(s,null,e(r.getSimpleMetadata(o.row.metadata),(e,t)=>(l(),a(P,{key:t,style:{textWrap:`wrap`,height:`fit-content`,lineHeight:`20px`,borderRadius:`10px`}},{default:x(()=>[i(c(t)+`: `+c(e),1)]),_:2},1024))),128))])]),_:1},8,[`label`]),o(N,{label:r.$t(`usage.button.viewDetail`),width:`120px`,"class-name":`text-center`},{default:x(e=>[e.row.id?(l(),a(A,{key:0,type:`primary`,plain:``,size:`small`,class:`!px-2 !py-1 !text-xs !h-auto !min-h-0`,onClick:t=>r.onShowDetail(e.row)},{default:x(()=>[i(c(r.$t(`usage.button.viewDetail`)),1)]),_:1},8,[`onClick`])):p(``,!0)]),_:1},8,[`label`]),o(N,{prop:`trace_id`,label:r.$t(`application.field.traceId`),width:`200px`,"class-name":`text-center`},{default:x(e=>[n(`span`,de,c(e.row.trace_id),1),e.row.trace_id?(l(),t(`span`,fe,[o(F,{content:e.row.trace_id,class:`inline-block`},null,8,[`content`])])):p(``,!0)]),_:1},8,[`label`]),o(N,{label:r.$t(`usage.field.createdAt`),width:`200px`},{default:x(e=>[n(`span`,pe,c(r.$dayjs.format(e.row.created_at)),1)]),_:1},8,[`label`])]),_:1},8,[`data`,`empty-text`])),[[V,r.loading]]):p(``,!0),r.type===r.serviceType.Proxy?f((l(),a(I,{key:1,data:r.proxyUsages,stripe:``,"table-layout":`fixed`,"empty-text":r.$t(`common.message.noData`),class:`min-h-[calc(100vh-350px)] mb-5`},{default:x(()=>[o(N,{label:r.$t(`application.field.name`),width:`160px`},{default:x(e=>[n(`span`,null,c(e.row?.service?.title),1)]),_:1},8,[`label`]),o(N,{prop:`remaining_amount`,label:r.$t(`usage.field.remainingAmount`),width:`160px`,"class-name":`text-center`},{default:x(e=>[n(`span`,null,c(r.getRemainingAmount(e.row)),1),n(`span`,null,c(r.getOriginalAmount(e.row)),1)]),_:1},8,[`label`]),o(N,{prop:`deducted_amount`,label:r.$t(`usage.field.deductedAmount`),width:`150px`,"class-name":`text-center`},{default:x(e=>[n(`span`,null,c(r.getDeductedAmount(e.row)),1)]),_:1},8,[`label`]),o(N,{label:r.$t(`usage.field.balanceAfter`),width:`160px`,"class-name":`text-center`},{default:x(e=>[n(`span`,null,c(r.getRemainingAmount(e.row)),1)]),_:1},8,[`label`]),o(N,{prop:`metadata`,label:r.$t(`usage.field.metadata`),width:`200px`,"class-name":`text-center`},{default:x(n=>[(l(!0),t(s,null,e(n.row.metadata,(e,t)=>(l(),a(P,{key:t,class:`mb-2`},{default:x(()=>[i(c(t)+`: `+c(e),1)]),_:2},1024))),128))]),_:1},8,[`label`]),o(N,{label:r.$t(`usage.field.createdAt`),width:`200px`},{default:x(e=>[n(`span`,me,c(r.$dayjs.format(e.row.created_at)),1)]),_:1},8,[`label`])]),_:1},8,[`data`,`empty-text`])),[[V,r.loading]]):p(``,!0)]),_:1})]),_:1})]),_:1}),o(z,{modelValue:r.detailDialogVisible,"onUpdate:modelValue":u[6]||=e=>r.detailDialogVisible=e,title:r.$t(`usage.dialog.detailTitle`),width:`70%`,top:`5vh`,"destroy-on-close":``},{default:x(()=>[o(R,{modelValue:r.detailActiveTab,"onUpdate:modelValue":u[5]||=e=>r.detailActiveTab=e},{default:x(()=>[o(L,{label:r.$t(`usage.dialog.request`),name:`request`},{default:x(()=>[r.detailLoading?(l(),a(D,{key:0,rows:6,animated:``})):r.detailRow?.metadata?.request?(l(),t(`pre`,he,c(r.formatJson(r.detailRow.metadata.request)),1)):(l(),t(`p`,ge,c(r.$t(`usage.dialog.noData`)),1))]),_:1},8,[`label`]),o(L,{label:r.$t(`usage.dialog.response`),name:`response`},{default:x(()=>[r.detailLoading?(l(),a(D,{key:0,rows:6,animated:``})):r.detailRow?.metadata?.response?(l(),t(`pre`,_e,c(r.formatJson(r.detailRow.metadata.response)),1)):(l(),t(`p`,ve,c(r.$t(`usage.dialog.noData`)),1))]),_:1},8,[`label`])]),_:1},8,[`modelValue`])]),_:1},8,[`modelValue`,`title`]),o(v,null,{default:x(()=>[o(_,{span:10,offset:14},{default:x(()=>[n(`div`,ye,[o(B,{"current-page":r.page,"page-size":r.limit,total:r.total,onChange:r.onPageChange},null,8,[`current-page`,`page-size`,`total`,`onChange`])])]),_:1})]),_:1})]),_:1})]),_:1})}var xe=z(Z,[[`render`,be],[`__scopeId`,`data-v-38f1845c`]]);export{xe as default};
1
+ import"./rolldown-runtime--c01j_DQ.js";import{$ as e,A as t,D as n,F as r,N as i,O as a,P as o,S as s,Wt as c,Z as l,a as u,c as d,dt as f,i as ee,k as p,n as m,nt as h,o as g,r as _,s as v,t as y,tt as b,ut as x,v as S}from"./vendor-chart-BJCvKk8-.js";import{t as C}from"./button-BydTr5nV.js";import{r as w,t as T}from"./select-DooKN8lb.js";import{n as E,t as D}from"./table-BJr3w4hQ.js";import{n as O,t as k}from"./tabs-DmrdWXQG.js";import{t as A}from"./card-DjyfNde2.js";import{n as j,r as M}from"./radio-3Hz7h3DR.js";import{t as N}from"./date-picker-Dc-4ebse.js";import{n as P,t as F}from"./row-COldDsV6.js";import{t as I}from"./Pagination-BZvLWtVy.js";import{n as L,t as R}from"./skeleton-BwNBivMN.js";import{E as z,Fn as B,Gr as V,Nn as H,Or as U,Pn as W,Ur as G,br as K,xr as q,zn as J}from"./index-DPve7EH6.js";import{t as Y}from"./index.es-ChPsc2I6.js";import{t as X}from"./CopyToClipboard-B-DcRyL3.js";ee.register(_,u,m,v,d,g);var Z=r({name:`ConsoleUsageList`,components:{Pagination:I,ElTag:V,ElDatePicker:N,ElTable:D,ElSelect:w,ElOption:T,CopyToClipboard:X,ElRow:F,ElCol:P,ElTableColumn:E,ElCard:A,ElRadioButton:j,ElRadioGroup:M,ElSkeleton:R,ElSkeletonItem:L,ElDialog:G,ElTabs:O,ElTabPane:k,ElButton:C,FontAwesomeIcon:Y,BarChart:y},data(){return{applicationIds:this.$route.query.application_id?.toString()?this.$route.query.application_id?.toString().split(`,`):[],apiIds:this.$route.query.api_id?.toString()?this.$route.query.api_id?.toString().split(`,`):[],applications:[],apis:[],apisLoading:!1,credentialType:K,serviceType:q,apiUsages:[],proxyUsages:[],createdAtRange:(()=>{let e=this.$route.query.created_at_to?.toString(),t=this.$route.query.created_at_from?.toString();if(t&&e)return[new Date(t),new Date(e)];let n=new Date,r=new Date;return r.setDate(1),r.setHours(0,0,0,0),[r,n]})(),shortcuts:[{text:this.$t(`usage.shortcuts.thisMonth`),value:()=>{let e=new Date,t=new Date;return t.setDate(1),t.setHours(0,0,0,0),[t,e]}},{text:this.$t(`usage.shortcuts.today`),value:()=>{let e=new Date,t=new Date;return t.setHours(0,0,0,0),[t,e]}},{text:this.$t(`usage.shortcuts.last1Day`),value:()=>{let e=new Date,t=new Date;return t.setDate(t.getDate()-1),[t,e]}},{text:this.$t(`usage.shortcuts.last3Days`),value:()=>{let e=new Date,t=new Date;return t.setDate(t.getDate()-3),[t,e]}},{text:this.$t(`usage.shortcuts.last7Days`),value:()=>{let e=new Date,t=new Date;return t.setDate(t.getDate()-7),[t,e]}},{text:this.$t(`usage.shortcuts.last1Month`),value:()=>{let e=new Date,t=new Date;return t.setMonth(t.getMonth()-1),[t,e]}}],type:this.$route.query.type?.toString()||q.API,loading:!1,total:void 0,limit:15,totalUsed:0,barChartLabels:[],barChartSeries:[],aggLoading:!1,detailDialogVisible:!1,detailRow:null,detailActiveTab:`request`,detailLoading:!1,exporting:!1,statusCodeFilter:this.$route.query.status_code?.toString()||``,statusCodeOptions:[],statusCodeOptionsLoading:!1}},computed:{redirect(){return this.$route.query?.redirect},page(){return parseInt(this.$route.query.page?.toString()||`1`)},totalUsedString(){return`${(this.totalUsed||0).toFixed(2)}`},barChartData(){return{labels:this.barChartLabels,datasets:this.barChartSeries.map(e=>({label:e.label,data:e.data,backgroundColor:e.color}))}},barChartOptions(){return{responsive:!0,plugins:{legend:{position:`top`,onClick:(e,t,n)=>{let r=n?.chart;if(!r||t?.datasetIndex===void 0)return;let i=t.datasetIndex,a=r.data?.datasets||[];a.some((e,t)=>t!==i&&r.isDatasetVisible(t))?a.forEach((e,t)=>r.setDatasetVisibility(t,t===i)):a.forEach((e,t)=>r.setDatasetVisibility(t,!0)),r.update()}},title:{display:!0,text:this.$t(`usage.title.usageTrend`)}},scales:{x:{stacked:!0},y:{stacked:!0,beginAtZero:!0}}}}},watch:{page:{handler(){this.onFetchUsages()}},type:{handler(){this.applicationIds=[],this.apiIds=[],this.onApplicationsChange(this.applicationIds),this.onFetchApplications(),this.onFetchApis(),this.onFetchUsages(),this.onFetchAggregate(),this.onFetchStatusCodeOptions()}}},mounted(){this.onFetchApplications(),this.onFetchApis(),this.onFetchUsages(),this.onFetchAggregate(),this.onFetchStatusCodeOptions()},methods:{async onFetchUsages(){this.type===q.API?this.onFetchApiUsages():this.type===q.Proxy&&this.onFetchProxyUsages()},async onApiChange(e){await this.$router.push({name:this.$route.name?.toString(),query:{...this.$route.query,api_id:e}}),this.onFetchApiUsages(),this.onFetchAggregate()},async onApisChange(e){await this.$router.push({name:this.$route.name?.toString(),query:{...this.$route.query,api_id:e&&e.length?e.join(`,`):``}}),this.onFetchApiUsages(),this.onFetchAggregate()},async onTimeRangeChanged(){console.log(`onTimeRangeChanged`,this.createdAtRange),await this.$router.push({name:this.$route.name?.toString(),query:{...this.$route.query,created_at_from:this.createdAtRange?this.$dayjs.format(this.createdAtRange[0].toString(),`YYYY-MM-DDTHH:mm:ss.SSSSSSZ`):``,created_at_to:this.createdAtRange?this.$dayjs.format(this.createdAtRange[1].toString(),`YYYY-MM-DDTHH:mm:ss.SSSSSSZ`):``}}),this.onFetchUsages(),this.onFetchAggregate(),this.onFetchStatusCodeOptions()},async onApplicationChange(e){await this.$router.push({name:this.$route.name?.toString(),query:{...this.$route.query,application_id:e}}),this.onFetchUsages(),this.onFetchAggregate()},async onApplicationsChange(e){await this.$router.push({name:this.$route.name?.toString(),query:{...this.$route.query,application_id:e&&e.length?e.join(`,`):``}}),this.onFetchUsages(),this.onFetchAggregate()},onPageChange(e){this.$router.push({name:this.$route.name?.toString(),query:{...this.$route.query,page:e}})},getRemainingAmount(e){if(e.remaining_amount===void 0||e.remaining_amount===null)return``;let t=this.$t(`service.unit.${e?.service?.unit||`credit`}s`);return`${e.remaining_amount?.toFixed(6)} ${t}`},getUsedAmount(e){if(e.used_amount===void 0||e.used_amount===null)return``;let t=this.$t(`service.unit.${e?.service?.unit||`credit`}s`);return`${e.used_amount?.toFixed(6)} ${t}`},getDeductedAmount(e){if(e?.deducted_amount===void 0||e?.deducted_amount===null)return``;let t=this.$t(`service.unit.${e?.service?.unit||`credit`}s`);return`${e.deducted_amount?.toFixed(6)} ${t}`},getOriginalAmount(e){if(e?.original_amount===void 0||e?.original_amount===null)return``;let t=this.$t(`service.unit.${e?.service?.unit||`credit`}s`);return`${e.original_amount?.toFixed(6)} ${t}`},onStatusCodeChange(e){let t={...this.$route.query},n=(e||``).trim();n?t.status_code=n:delete t.status_code,delete t.status_code_filter,this.$router.push({name:this.$route.name?.toString(),query:t}),this.onFetchUsages(),this.onFetchAggregate()},async onFetchStatusCodeOptions(){this.statusCodeOptionsLoading=!0;try{let{data:e}=await W.getStatusCodes({user_id:this.$store.getters.user.id,...this.applicationIds&&this.applicationIds.length?{application_id:this.applicationIds}:{},...this.apiIds&&this.apiIds.length?{api_id:this.apiIds}:{},...this.createdAtRange?.[0]?{created_at_from:this.createdAtRange[0]}:{},...this.createdAtRange?.[1]?{created_at_to:this.createdAtRange[1]}:{}});this.statusCodeOptions=(e?.items||[]).slice().sort((e,t)=>e-t)}catch{this.statusCodeOptions=[]}finally{this.statusCodeOptionsLoading=!1}},formatElapsed(e){return e==null||Number.isNaN(e)?`-`:e<1?`${Math.round(e*1e3)} ms`:`${e.toFixed(2)} s`},getSimpleMetadata(e){if(!e)return{};let t={};for(let[n,r]of Object.entries(e))n===`request`||n===`response`||typeof r==`object`&&r||(t[n]=r);return t},onShowDetail(e){this.detailRow={...e,metadata:void 0},this.detailActiveTab=`request`,this.detailDialogVisible=!0,this.detailLoading=!0,e.id&&W.get(e.id).then(e=>{this.detailRow=e.data}).finally(()=>{this.detailLoading=!1})},formatJson(e){try{return JSON.stringify(e,null,2)}catch{return String(e)}},onFetchApplications(){J.getAll({limit:100,offset:0,user_id:this.$store.getters.user.id,ordering:`-created_at`,type:U.USAGE}).then(({data:e})=>{this.applications=e.items.filter(e=>e?.service?.type===this.type)}).catch(()=>{})},onFetchApis(){this.apisLoading=!0,H.getAll({limit:100,offset:0,ordering:`-created_at`}).then(({data:e})=>{this.apis=e.items}).catch(()=>{}).finally(()=>{this.apisLoading=!1})},onFetchApiUsages(){console.log(`onFetchApiUsages`,this.createdAtRange),this.loading=!0,W.getAll({limit:this.limit,offset:(this.page-1)*this.limit,user_id:this.$store.getters.user.id,ordering:`-created_at`,...this.createdAtRange?.[0]?{created_at_from:this.createdAtRange[0]}:{},...this.createdAtRange?.[1]?{created_at_to:this.createdAtRange[1]}:{},...this.applicationIds&&this.applicationIds.length?{application_id:this.applicationIds}:{},...this.apiIds&&this.apiIds.length?{api_id:this.apiIds}:{},...this.statusCodeFilter?{status_code:this.statusCodeFilter}:{}}).then(({data:e})=>{this.apiUsages=e.items,this.loading=!1,this.total=e.count}).catch(()=>{this.loading=!1})},onFetchProxyUsages(){this.loading=!0,B.getAll({limit:this.limit,offset:(this.page-1)*this.limit,user_id:this.$store.getters.user.id,ordering:`-created_at`,...this.applicationIds&&this.applicationIds.length?{application_id:this.applicationIds}:{}}).then(({data:e})=>{this.proxyUsages=e.items,this.loading=!1,this.total=e.count}).catch(()=>{this.loading=!1})},onExport(){this.exporting=!0,W.exportCsv({user_id:this.$store.getters.user.id,...this.createdAtRange?.[0]?{created_at_from:this.createdAtRange[0]}:{},...this.createdAtRange?.[1]?{created_at_to:this.createdAtRange[1]}:{},...this.applicationIds&&this.applicationIds.length?{application_id:this.applicationIds}:{},...this.apiIds&&this.apiIds.length?{api_id:this.apiIds}:{},...this.statusCodeFilter?{status_code:this.statusCodeFilter}:{}}).then(({data:e})=>{let t=window.URL.createObjectURL(e),n=document.createElement(`a`);n.href=t,n.download=`usages.csv`,n.click(),window.URL.revokeObjectURL(t)}).catch(()=>{}).finally(()=>{this.exporting=!1})},async onFetchAggregate(){if(this.aggLoading=!0,this.type!==this.serviceType.API)return;let e={user_id:this.$store.getters.user.id,...this.applicationIds&&this.applicationIds.length?{application_id:this.applicationIds}:{},...this.apiIds&&this.apiIds.length?{api_id:this.apiIds}:{},...this.createdAtRange?.[0]?{created_at_from:this.createdAtRange[0]}:{},...this.createdAtRange?.[1]?{created_at_to:this.createdAtRange[1]}:{}};try{let{data:t}=await W.getAggregate(e);this.totalUsed=t.total||0;let n=Array.from(new Set((t.items||[]).map(e=>e.date))).sort(),r=Array.from(new Set((t.items||[]).map(e=>e.api_id))),i=e=>`hsl(${e*57%360}, 70%, 60%)`,a=r.map((e,r)=>{let a=t.apis?.[e]?.title||e,o={};return(t.items||[]).filter(t=>t.api_id===e).forEach(e=>{o[e.date]=e.amount||0}),{key:e,label:a,data:n.map(e=>o[e]||0),color:i(r)}});this.barChartLabels=n,this.barChartSeries=a}finally{this.aggLoading=!1}}}}),Q={class:`text-[26px] font-bold mb-5 text-[var(--el-text-color-primary)]`},$={class:`inline-block w-9`},te={class:`inline-block`},ne={key:1,class:`summary-card`},re={class:`icon-wrapper`},ie={class:`text-left`},ae={class:`description`},oe={class:`value`},se={class:`chart-wrapper`},ce={key:0},le={key:1},ue={class:`flex flex-wrap gap-2`},de={class:`key`},fe={key:0,class:`cursor-pointer`},pe={class:`created-at`},me={class:`created-at`},he={key:1,class:`detail-json`},ge={key:2,class:`text-gray-400`},_e={key:1,class:`detail-json`},ve={key:2,class:`text-gray-400`},ye={class:`float-right`};function be(r,u,d,ee,m,g){let _=b(`el-col`),v=b(`el-row`),y=b(`el-radio-button`),C=b(`el-radio-group`),w=b(`el-option`),T=b(`el-select`),E=b(`el-skeleton-item`),D=b(`el-skeleton`),O=b(`el-date-picker`),k=b(`font-awesome-icon`),A=b(`el-button`),j=b(`el-card`),M=b(`bar-chart`),N=b(`el-table-column`),P=b(`el-tag`),F=b(`copy-to-clipboard`),I=b(`el-table`),L=b(`el-tab-pane`),R=b(`el-tabs`),z=b(`el-dialog`),B=b(`pagination`),V=h(`loading`);return l(),a(v,null,{default:x(()=>[o(_,{span:24},{default:x(()=>[o(v,null,{default:x(()=>[o(_,{span:24},{default:x(()=>[n(`h2`,Q,c(r.$t(`common.title.allUsages`)),1)]),_:1})]),_:1}),o(v,null,{default:x(()=>[o(_,{md:4,xs:24,class:`mb-5 flex px-2 gap-2 items-center`},{default:x(()=>[n(`span`,null,c(r.$t(`application.field.type`)),1),o(C,{modelValue:r.type,"onUpdate:modelValue":u[0]||=e=>r.type=e},{default:x(()=>[o(y,{value:r.serviceType.API,label:r.$t(`application.field.api`)},null,8,[`value`,`label`]),o(y,{value:r.serviceType.Proxy,label:r.$t(`application.field.proxy`)},null,8,[`value`,`label`])]),_:1},8,[`modelValue`])]),_:1}),f(o(_,{md:6,xs:24,class:`mb-5 flex px-2 gap-2 items-center`},{default:x(()=>[n(`span`,$,c(r.$t(`usage.field.application`)),1),o(T,{modelValue:r.applicationIds,"onUpdate:modelValue":u[1]||=e=>r.applicationIds=e,placeholder:r.$t(`usage.field.application`),clearable:``,multiple:``,"collapse-tags":``,"collapse-tags-tooltip":``,class:`w-full`,onChange:r.onApplicationsChange},{default:x(()=>[(l(!0),t(s,null,e(r.applications,e=>(l(),a(w,{key:e.id,label:e.service?.title,value:e?.id},null,8,[`label`,`value`]))),128))]),_:1},8,[`modelValue`,`placeholder`,`onChange`])]),_:1},512),[[S,!1]]),r.type===r.serviceType.API?(l(),a(_,{key:0,md:6,xs:24,class:`mb-5 flex px-2 gap-2 items-center`},{default:x(()=>[n(`span`,te,c(r.$t(`usage.field.api`)),1),r.apisLoading?(l(),a(D,{key:0,animated:``,class:`w-full`},{template:x(()=>[o(E,{variant:`rect`,style:{height:`32px`,"border-radius":`4px`}})]),_:1})):(l(),a(T,{key:1,modelValue:r.apiIds,"onUpdate:modelValue":u[2]||=e=>r.apiIds=e,placeholder:r.$t(`usage.field.api`),clearable:``,filterable:``,multiple:``,"collapse-tags":``,"collapse-tags-tooltip":``,class:`w-full`,onChange:r.onApisChange},{default:x(()=>[(l(!0),t(s,null,e(r.apis,e=>(l(),a(w,{key:e?.id,label:e?.title,value:e?.id},null,8,[`label`,`value`]))),128))]),_:1},8,[`modelValue`,`placeholder`,`onChange`]))]),_:1})):p(``,!0),r.type===r.serviceType.API?(l(),a(_,{key:1,md:8,xs:24,class:`mb-5 flex px-2 gap-2 items-center`},{default:x(()=>[o(O,{modelValue:r.createdAtRange,"onUpdate:modelValue":u[3]||=e=>r.createdAtRange=e,type:`datetimerange`,class:`w-full`,shortcuts:r.shortcuts,"range-separator":r.$t(`usage.placeholder.to`),"start-placeholder":r.$t(`usage.placeholder.startDate`),"end-placeholder":r.$t(`usage.placeholder.endDate`),onChange:r.onTimeRangeChanged},null,8,[`modelValue`,`shortcuts`,`range-separator`,`start-placeholder`,`end-placeholder`,`onChange`])]),_:1})):p(``,!0),r.type===r.serviceType.API?(l(),a(_,{key:2,md:3,xs:24,class:`mb-5 flex px-2 gap-2 items-center`},{default:x(()=>[o(T,{modelValue:r.statusCodeFilter,"onUpdate:modelValue":u[4]||=e=>r.statusCodeFilter=e,placeholder:r.$t(`usage.option.statusCodeAll`),class:`w-full`,clearable:``,filterable:``,"allow-create":``,"default-first-option":``,loading:r.statusCodeOptionsLoading,onChange:r.onStatusCodeChange},{default:x(()=>[(l(!0),t(s,null,e(r.statusCodeOptions,e=>(l(),a(w,{key:e,label:String(e),value:String(e)},null,8,[`label`,`value`]))),128))]),_:1},8,[`modelValue`,`placeholder`,`loading`,`onChange`])]),_:1})):p(``,!0),r.type===r.serviceType.API?(l(),a(_,{key:3,md:3,xs:24,class:`mb-5 flex px-2 gap-2 items-center justify-end`},{default:x(()=>[o(A,{type:`primary`,plain:``,loading:r.exporting,class:`w-full whitespace-nowrap`,onClick:r.onExport},{default:x(()=>[o(k,{icon:`fa-solid fa-file-export`,class:`mr-1`}),i(` `+c(r.$t(`usage.button.export`)),1)]),_:1},8,[`loading`,`onClick`])]),_:1})):p(``,!0)]),_:1}),o(v,null,{default:x(()=>[o(_,{span:24},{default:x(()=>[r.type===r.serviceType.API?(l(),a(v,{key:0,gutter:24,class:`mb-5`},{default:x(()=>[o(_,{md:6,xs:24},{default:x(()=>[o(j,{shadow:`hover`,class:`h-full`},{default:x(()=>[r.aggLoading?(l(),a(D,{key:0})):(l(),t(`div`,ne,[n(`div`,re,[o(k,{icon:`fa-solid fa-cubes`,class:`icon`})]),n(`div`,ie,[n(`p`,ae,c(r.$t(`usage.title.totalUsed`)),1),n(`p`,oe,c(r.totalUsedString),1)])]))]),_:1})]),_:1}),o(_,{md:18,xs:24},{default:x(()=>[o(j,{shadow:`hover`,class:`h-full`},{default:x(()=>[n(`div`,se,[r.aggLoading?(l(),a(D,{key:0,class:`w-full`})):(l(),a(M,{key:1,data:r.barChartData,options:r.barChartOptions,class:`chart`},null,8,[`data`,`options`]))])]),_:1})]),_:1})]),_:1})):p(``,!0),o(j,{shadow:`hover`},{default:x(()=>[r.type===r.serviceType.API?f((l(),a(I,{key:0,data:r.apiUsages,stripe:``,"table-layout":`fixed`,"empty-text":r.$t(`common.message.noData`),class:`min-h-[calc(100vh-350px)] mb-5`},{default:x(()=>[o(N,{label:r.$t(`application.field.name`),width:`160px`},{default:x(e=>[n(`span`,null,c(e.row?.api?.title),1)]),_:1},8,[`label`]),o(N,{label:r.$t(`usage.field.statusCode`),width:`120px`},{default:x(e=>[n(`span`,null,c(e.row.status_code),1)]),_:1},8,[`label`]),o(N,{label:r.$t(`usage.field.elapsed`),width:`120px`},{default:x(e=>[n(`span`,null,c(r.formatElapsed(e.row.elapsed)),1)]),_:1},8,[`label`]),o(N,{prop:`deducted_amount`,label:r.$t(`usage.field.deductedAmount`),width:`150px`,"class-name":`text-center`},{default:x(e=>[r.getDeductedAmount(e.row)===r.getOriginalAmount(e.row)?(l(),t(`div`,ce,[n(`span`,null,c(r.getDeductedAmount(e.row)),1)])):(l(),t(`div`,le,[u[7]||=n(`p`,null,null,-1),n(`p`,null,[n(`span`,null,c(r.getDeductedAmount(e.row)),1)]),n(`p`,null,[n(`del`,null,c(r.getOriginalAmount(e.row)),1)])]))]),_:1},8,[`label`]),o(N,{prop:`remaining_amount`,label:r.$t(`usage.field.balanceAfter`),width:`160px`,"class-name":`text-center`},{default:x(e=>[n(`span`,null,c(r.getRemainingAmount(e.row)),1)]),_:1},8,[`label`]),o(N,{prop:`metadata`,label:r.$t(`usage.field.metadata`),width:`260px`,"class-name":`text-center`},{default:x(o=>[n(`div`,ue,[o.row.original_amount>o.row.deducted_amount&&o.row.original_amount>0?(l(),a(P,{key:0,type:`success`,style:{textWrap:`wrap`,height:`fit-content`,lineHeight:`20px`,borderRadius:`10px`}},{default:x(()=>[i(c(((o.row.original_amount-o.row.deducted_amount)*100/o.row.original_amount).toFixed(0)+`% OFF`),1)]),_:2},1024)):p(``,!0),(l(!0),t(s,null,e(r.getSimpleMetadata(o.row.metadata),(e,t)=>(l(),a(P,{key:t,style:{textWrap:`wrap`,height:`fit-content`,lineHeight:`20px`,borderRadius:`10px`}},{default:x(()=>[i(c(t)+`: `+c(e),1)]),_:2},1024))),128))])]),_:1},8,[`label`]),o(N,{label:r.$t(`usage.button.viewDetail`),width:`120px`,"class-name":`text-center`},{default:x(e=>[e.row.id?(l(),a(A,{key:0,type:`primary`,plain:``,size:`small`,class:`!px-2 !py-1 !text-xs !h-auto !min-h-0`,onClick:t=>r.onShowDetail(e.row)},{default:x(()=>[i(c(r.$t(`usage.button.viewDetail`)),1)]),_:1},8,[`onClick`])):p(``,!0)]),_:1},8,[`label`]),o(N,{prop:`trace_id`,label:r.$t(`application.field.traceId`),width:`200px`,"class-name":`text-center`},{default:x(e=>[n(`span`,de,c(e.row.trace_id),1),e.row.trace_id?(l(),t(`span`,fe,[o(F,{content:e.row.trace_id,class:`inline-block`},null,8,[`content`])])):p(``,!0)]),_:1},8,[`label`]),o(N,{label:r.$t(`usage.field.createdAt`),width:`200px`},{default:x(e=>[n(`span`,pe,c(r.$dayjs.format(e.row.created_at)),1)]),_:1},8,[`label`])]),_:1},8,[`data`,`empty-text`])),[[V,r.loading]]):p(``,!0),r.type===r.serviceType.Proxy?f((l(),a(I,{key:1,data:r.proxyUsages,stripe:``,"table-layout":`fixed`,"empty-text":r.$t(`common.message.noData`),class:`min-h-[calc(100vh-350px)] mb-5`},{default:x(()=>[o(N,{label:r.$t(`application.field.name`),width:`160px`},{default:x(e=>[n(`span`,null,c(e.row?.service?.title),1)]),_:1},8,[`label`]),o(N,{prop:`remaining_amount`,label:r.$t(`usage.field.remainingAmount`),width:`160px`,"class-name":`text-center`},{default:x(e=>[n(`span`,null,c(r.getRemainingAmount(e.row)),1),n(`span`,null,c(r.getOriginalAmount(e.row)),1)]),_:1},8,[`label`]),o(N,{prop:`deducted_amount`,label:r.$t(`usage.field.deductedAmount`),width:`150px`,"class-name":`text-center`},{default:x(e=>[n(`span`,null,c(r.getDeductedAmount(e.row)),1)]),_:1},8,[`label`]),o(N,{label:r.$t(`usage.field.balanceAfter`),width:`160px`,"class-name":`text-center`},{default:x(e=>[n(`span`,null,c(r.getRemainingAmount(e.row)),1)]),_:1},8,[`label`]),o(N,{prop:`metadata`,label:r.$t(`usage.field.metadata`),width:`200px`,"class-name":`text-center`},{default:x(n=>[(l(!0),t(s,null,e(n.row.metadata,(e,t)=>(l(),a(P,{key:t,class:`mb-2`},{default:x(()=>[i(c(t)+`: `+c(e),1)]),_:2},1024))),128))]),_:1},8,[`label`]),o(N,{label:r.$t(`usage.field.createdAt`),width:`200px`},{default:x(e=>[n(`span`,me,c(r.$dayjs.format(e.row.created_at)),1)]),_:1},8,[`label`])]),_:1},8,[`data`,`empty-text`])),[[V,r.loading]]):p(``,!0)]),_:1})]),_:1})]),_:1}),o(z,{modelValue:r.detailDialogVisible,"onUpdate:modelValue":u[6]||=e=>r.detailDialogVisible=e,title:r.$t(`usage.dialog.detailTitle`),width:`70%`,top:`5vh`,"destroy-on-close":``},{default:x(()=>[o(R,{modelValue:r.detailActiveTab,"onUpdate:modelValue":u[5]||=e=>r.detailActiveTab=e},{default:x(()=>[o(L,{label:r.$t(`usage.dialog.request`),name:`request`},{default:x(()=>[r.detailLoading?(l(),a(D,{key:0,rows:6,animated:``})):r.detailRow?.metadata?.request?(l(),t(`pre`,he,c(r.formatJson(r.detailRow.metadata.request)),1)):(l(),t(`p`,ge,c(r.$t(`usage.dialog.noData`)),1))]),_:1},8,[`label`]),o(L,{label:r.$t(`usage.dialog.response`),name:`response`},{default:x(()=>[r.detailLoading?(l(),a(D,{key:0,rows:6,animated:``})):r.detailRow?.metadata?.response?(l(),t(`pre`,_e,c(r.formatJson(r.detailRow.metadata.response)),1)):(l(),t(`p`,ve,c(r.$t(`usage.dialog.noData`)),1))]),_:1},8,[`label`])]),_:1},8,[`modelValue`])]),_:1},8,[`modelValue`,`title`]),o(v,null,{default:x(()=>[o(_,{span:10,offset:14},{default:x(()=>[n(`div`,ye,[o(B,{"current-page":r.page,"page-size":r.limit,total:r.total,onChange:r.onPageChange},null,8,[`current-page`,`page-size`,`total`,`onChange`])])]),_:1})]),_:1})]),_:1})]),_:1})}var xe=z(Z,[[`render`,be],[`__scopeId`,`data-v-38f1845c`]]);export{xe as default};
@@ -1 +1 @@
1
- import"./rolldown-runtime--c01j_DQ.js";import{$ as e,A as t,D as n,F as r,N as i,O as a,P as o,S as s,Wt as c,Z as l,dt as u,nt as d,tt as f,ut as p}from"./vendor-chart-BJCvKk8-.js";import{t as m}from"./button-BydTr5nV.js";import{r as h,t as g}from"./select-VY4i3iMR.js";import{n as _,t as v}from"./table-BJr3w4hQ.js";import{t as y}from"./card-DjyfNde2.js";import{t as b}from"./date-picker-CRIxhOXx.js";import{n as x,t as S}from"./row-B1qA_KsB.js";import{t as C}from"./Pagination-YHZ8EQyy.js";import{t as w}from"./skeleton-BwNBivMN.js";import{Bt as T,E,Gr as D,Mn as O,Sr as k}from"./index-Bm66Z2-R.js";import{t as A}from"./index.es-ktQaPrdW.js";import{t as j}from"./CopyToClipboard-BDrnVqbi.js";var M={total_count:0,total_spent:0,state_counts:{}},N=r({name:`ConsoleOrderList`,components:{Pagination:C,CopyToClipboard:j,ElRow:S,ElCol:x,ElTable:v,ElTableColumn:_,ElButton:m,ElTag:D,ElCard:y,ElSelect:h,ElOption:g,ElDatePicker:b,ElSkeleton:w,FontAwesomeIcon:A},data(){return{OrderState:k,orders:[],loading:!1,total:void 0,limit:10,filterState:this.$route.query.state?.toString()||``,filterPayWay:this.$route.query.pay_way?.toString()||``,createdAtRange:(()=>{let e=this.$route.query.created_at_from?.toString(),t=this.$route.query.created_at_to?.toString();if(e&&t)return[new Date(e),new Date(t)]})(),summary:{...M},summaryLoading:!1,exporting:!1,shortcuts:[{text:this.$t(`usage.shortcuts.today`),value:()=>{let e=new Date,t=new Date;return t.setHours(0,0,0,0),[t,e]}},{text:this.$t(`usage.shortcuts.last7Days`),value:()=>{let e=new Date,t=new Date;return t.setDate(t.getDate()-7),[t,e]}},{text:this.$t(`usage.shortcuts.last1Month`),value:()=>{let e=new Date,t=new Date;return t.setMonth(t.getMonth()-1),[t,e]}}]}},computed:{page(){return parseInt(this.$route.query.page?.toString()||`1`)},stateOptions(){return[{value:k.PENDING,label:this.$t(`order.state.pending`)},{value:k.FINISHED,label:this.$t(`order.state.finished`)},{value:k.PAID,label:this.$t(`order.state.paid`)},{value:k.EXPIRED,label:this.$t(`order.state.expired`)},{value:k.FAILED,label:this.$t(`order.state.failed`)},{value:k.REFUNDED,label:this.$t(`order.state.refunded`)}]},payWayOptions(){return[{value:`WechatPay`,label:this.$t(`order.title.wechatPay`)},{value:`Stripe`,label:this.$t(`order.title.stripe`)},{value:`AliPay`,label:this.$t(`order.title.aliPay`)},{value:`X402`,label:this.$t(`order.title.x402`)},{value:`PayPal`,label:this.$t(`order.title.paypal`)}]},filterQuery(){let e={user_id:this.$store.getters.user?.id};return this.filterState&&(e.state=this.filterState),this.filterPayWay&&(e.pay_way=this.filterPayWay),this.createdAtRange?.[0]&&(e.created_at_from=this.createdAtRange[0]),this.createdAtRange?.[1]&&(e.created_at_to=this.createdAtRange[1]),e}},watch:{page:{handler(){this.onFetchData()}}},mounted(){this.onFetchData(),this.onFetchSummary()},methods:{getPriceString:T,stateTagType(e){return e===k.FINISHED||e===k.PAID?`success`:e===k.EXPIRED||e===k.FAILED?`danger`:e===k.REFUNDED?`warning`:`info`},stateLabel(e){return{[k.PENDING]:this.$t(`order.state.pending`),[k.PAID]:this.$t(`order.state.paid`),[k.FINISHED]:this.$t(`order.state.finished`),[k.EXPIRED]:this.$t(`order.state.expired`),[k.FAILED]:this.$t(`order.state.failed`),[k.REFUNDED]:this.$t(`order.state.refunded`)}[e]||e},isPendingAction(e){return e!==k.PAID&&e!==k.FINISHED&&e!==k.EXPIRED&&e!==k.FAILED&&e!==k.REFUNDED},goToDetail(e){this.$router.push({name:`console-order-detail`,params:{id:e}})},async onFilterChange(){await this.$router.push({name:this.$route.name?.toString(),query:{page:1,...this.filterState?{state:this.filterState}:{},...this.filterPayWay?{pay_way:this.filterPayWay}:{},...this.createdAtRange?.[0]?{created_at_from:this.createdAtRange[0].toISOString()}:{},...this.createdAtRange?.[1]?{created_at_to:this.createdAtRange[1].toISOString()}:{}}}),this.onFetchData(),this.onFetchSummary()},onPageChange(e){this.$router.push({name:this.$route.name?.toString(),query:{...this.$route.query,page:e}})},onFetchData(){this.loading=!0,O.getAll({ordering:`-created_at`,limit:this.limit,offset:(this.page-1)*this.limit,...this.filterQuery}).then(({data:e})=>{this.orders=e.items,this.total=e.count}).catch(()=>{}).finally(()=>{this.loading=!1})},onFetchSummary(){this.summaryLoading=!0,O.getSummary(this.filterQuery).then(({data:e})=>{this.summary=e}).catch(()=>{this.summary={...M}}).finally(()=>{this.summaryLoading=!1})},onExport(){this.exporting=!0,O.exportCsv(this.filterQuery).then(({data:e})=>{let t=window.URL.createObjectURL(e),n=document.createElement(`a`);n.href=t,n.download=`orders.csv`,n.click(),window.URL.revokeObjectURL(t)}).catch(()=>{}).finally(()=>{this.exporting=!1})}}}),P={class:`title`},F={key:1,class:`card-content`},I={class:`icon-wrapper`},L={class:`description`},R={class:`value`},z={key:1,class:`card-content`},B={class:`icon-wrapper`},V={class:`description`},H={class:`value`},U={key:1,class:`card-content`},W={class:`icon-wrapper`},ee={class:`description`},G={class:`value`},K={key:1,class:`card-content`},q={class:`icon-wrapper`},J={class:`description`},Y={class:`value`},X={class:`filter-row mb-3`},Z={class:`key`},Q={class:`cursor-pointer`},$={class:`price`},te={class:`description`},ne={class:`text-gray-500`},re={class:`created-at`},ie={class:`flex items-center justify-center flex-wrap`},ae={class:`float-right`};function oe(r,m,h,g,_,v){let y=f(`el-col`),b=f(`el-row`),x=f(`el-skeleton`),S=f(`font-awesome-icon`),C=f(`el-card`),w=f(`el-option`),T=f(`el-select`),E=f(`el-date-picker`),D=f(`el-button`),O=f(`copy-to-clipboard`),k=f(`el-table-column`),A=f(`el-tag`),j=f(`el-table`),M=f(`pagination`),N=d(`loading`);return l(),a(b,{class:`panel`},{default:p(()=>[o(y,{span:24},{default:p(()=>[o(b,null,{default:p(()=>[o(y,{span:24},{default:p(()=>[n(`h2`,P,c(r.$t(`common.title.allOrders`)),1)]),_:1})]),_:1}),o(b,{gutter:16},{default:p(()=>[o(y,{md:6,sm:12,xs:24},{default:p(()=>[o(C,{shadow:`hover`,class:`item-mini mb-3`},{default:p(()=>[r.summaryLoading?(l(),a(x,{key:0})):(l(),t(`div`,F,[n(`div`,I,[o(S,{icon:`fa-solid fa-receipt`,class:`icon`})]),n(`p`,L,c(r.$t(`order.title.totalOrders`)),1),n(`p`,R,c(r.summary.total_count),1)]))]),_:1})]),_:1}),o(y,{md:6,sm:12,xs:24},{default:p(()=>[o(C,{shadow:`hover`,class:`item-mini mb-3`},{default:p(()=>[r.summaryLoading?(l(),a(x,{key:0})):(l(),t(`div`,z,[n(`div`,B,[o(S,{icon:`fa-solid fa-dollar-sign`,class:`icon`})]),n(`p`,V,c(r.$t(`order.title.totalSpent`)),1),n(`p`,H,c(r.getPriceString({value:r.summary.total_spent})),1)]))]),_:1})]),_:1}),o(y,{md:6,sm:12,xs:24},{default:p(()=>[o(C,{shadow:`hover`,class:`item-mini mb-3`},{default:p(()=>[r.summaryLoading?(l(),a(x,{key:0})):(l(),t(`div`,U,[n(`div`,W,[o(S,{icon:`fa-solid fa-check-circle`,class:`icon`})]),n(`p`,ee,c(r.$t(`order.title.finishedOrders`)),1),n(`p`,G,c(r.summary.state_counts?.Finished||0),1)]))]),_:1})]),_:1}),o(y,{md:6,sm:12,xs:24},{default:p(()=>[o(C,{shadow:`hover`,class:`item-mini mb-3`},{default:p(()=>[r.summaryLoading?(l(),a(x,{key:0})):(l(),t(`div`,K,[n(`div`,q,[o(S,{icon:`fa-solid fa-clock`,class:`icon`})]),n(`p`,J,c(r.$t(`order.title.pendingOrders`)),1),n(`p`,Y,c(r.summary.state_counts?.Pending||0),1)]))]),_:1})]),_:1})]),_:1}),n(`div`,X,[o(T,{modelValue:r.filterState,"onUpdate:modelValue":m[0]||=e=>r.filterState=e,clearable:``,placeholder:r.$t(`order.field.allStates`),class:`filter-select`,onChange:r.onFilterChange},{default:p(()=>[(l(!0),t(s,null,e(r.stateOptions,e=>(l(),a(w,{key:e.value,label:e.label,value:e.value},null,8,[`label`,`value`]))),128))]),_:1},8,[`modelValue`,`placeholder`,`onChange`]),o(T,{modelValue:r.filterPayWay,"onUpdate:modelValue":m[1]||=e=>r.filterPayWay=e,clearable:``,placeholder:r.$t(`order.field.allPayWays`),class:`filter-select`,onChange:r.onFilterChange},{default:p(()=>[(l(!0),t(s,null,e(r.payWayOptions,e=>(l(),a(w,{key:e.value,label:e.label,value:e.value},null,8,[`label`,`value`]))),128))]),_:1},8,[`modelValue`,`placeholder`,`onChange`]),o(E,{modelValue:r.createdAtRange,"onUpdate:modelValue":m[2]||=e=>r.createdAtRange=e,type:`datetimerange`,shortcuts:r.shortcuts,"range-separator":r.$t(`usage.placeholder.to`),"start-placeholder":r.$t(`usage.placeholder.startDate`),"end-placeholder":r.$t(`usage.placeholder.endDate`),onChange:r.onFilterChange},null,8,[`modelValue`,`shortcuts`,`range-separator`,`start-placeholder`,`end-placeholder`,`onChange`]),o(D,{type:`primary`,plain:``,loading:r.exporting,onClick:r.onExport},{default:p(()=>[o(S,{icon:`fa-solid fa-file-export`,class:`mr-1`}),i(` `+c(r.$t(`order.button.export`)),1)]),_:1},8,[`loading`,`onClick`])]),o(b,null,{default:p(()=>[o(y,{span:24},{default:p(()=>[o(C,{shadow:`hover`},{default:p(()=>[u((l(),a(j,{data:r.orders,stripe:``,"empty-text":r.$t(`common.message.noData`),class:`min-h-[calc(100vh-450px)] mb-[20px]`},{default:p(()=>[o(k,{prop:`id`,label:r.$t(`order.field.id`),"class-name":`text-center`,width:`200px`},{default:p(e=>[n(`span`,Z,c(e.row.id),1),n(`span`,Q,[o(O,{content:e.row.id,class:`inline-block`},null,8,[`content`])])]),_:1},8,[`label`]),o(k,{label:r.$t(`order.field.price`),width:`110px`,align:`center`},{default:p(e=>[n(`span`,$,c(r.getPriceString({value:e.row?.price})),1)]),_:1},8,[`label`]),o(k,{label:r.$t(`order.field.description`),"min-width":`220px`,"class-name":`hidden md:table-cell`,"label-class-name":`hidden md:table-cell`},{default:p(e=>[n(`span`,te,c(e.row.description),1)]),_:1},8,[`label`]),o(k,{prop:`state`,label:r.$t(`order.field.state`),width:`130px`,align:`center`},{default:p(e=>[o(A,{type:r.stateTagType(e.row.state),class:`mx-1`,effect:`dark`,round:``,size:`small`},{default:p(()=>[i(c(r.stateLabel(e.row.state)),1)]),_:2},1032,[`type`])]),_:1},8,[`label`]),o(k,{label:r.$t(`order.field.payWay`),width:`120px`,align:`center`,"class-name":`hidden md:table-cell`,"label-class-name":`hidden md:table-cell`},{default:p(e=>[n(`span`,ne,c(e.row.pay_way||`-`),1)]),_:1},8,[`label`]),o(k,{label:r.$t(`order.field.createdAt`),width:`200px`,"class-name":`hidden sm:table-cell`,"label-class-name":`hidden sm:table-cell`},{default:p(e=>[n(`span`,re,c(r.$dayjs.format(e.row.created_at)),1)]),_:1},8,[`label`]),o(k,{"min-width":`130px`,fixed:`right`},{default:p(e=>[n(`div`,ie,[r.isPendingAction(e.row.state)?(l(),a(D,{key:0,type:`primary`,size:`small`,onClick:t=>r.goToDetail(e.row.id)},{default:p(()=>[i(c(r.$t(`order.button.continuePay`)),1)]),_:1},8,[`onClick`])):(l(),a(D,{key:1,size:`small`,onClick:t=>r.goToDetail(e.row.id)},{default:p(()=>[i(c(r.$t(`order.button.checkDetail`)),1)]),_:1},8,[`onClick`]))])]),_:1})]),_:1},8,[`data`,`empty-text`])),[[N,r.loading]])]),_:1})]),_:1})]),_:1}),o(b,null,{default:p(()=>[o(y,{span:10,offset:14},{default:p(()=>[n(`div`,ae,[o(M,{"current-page":r.page,"page-size":r.limit,total:r.total,onChange:r.onPageChange},null,8,[`current-page`,`page-size`,`total`,`onChange`])])]),_:1})]),_:1})]),_:1})]),_:1})}var se=E(N,[[`render`,oe],[`__scopeId`,`data-v-350ab467`]]);export{se as default};
1
+ import"./rolldown-runtime--c01j_DQ.js";import{$ as e,A as t,D as n,F as r,N as i,O as a,P as o,S as s,Wt as c,Z as l,dt as u,nt as d,tt as f,ut as p}from"./vendor-chart-BJCvKk8-.js";import{t as m}from"./button-BydTr5nV.js";import{r as h,t as g}from"./select-DooKN8lb.js";import{n as _,t as v}from"./table-BJr3w4hQ.js";import{t as y}from"./card-DjyfNde2.js";import{t as b}from"./date-picker-Dc-4ebse.js";import{n as x,t as S}from"./row-COldDsV6.js";import{t as C}from"./Pagination-BZvLWtVy.js";import{t as w}from"./skeleton-BwNBivMN.js";import{Bt as T,E,Gr as D,Mn as O,Sr as k}from"./index-DPve7EH6.js";import{t as A}from"./index.es-ChPsc2I6.js";import{t as j}from"./CopyToClipboard-B-DcRyL3.js";var M={total_count:0,total_spent:0,state_counts:{}},N=r({name:`ConsoleOrderList`,components:{Pagination:C,CopyToClipboard:j,ElRow:S,ElCol:x,ElTable:v,ElTableColumn:_,ElButton:m,ElTag:D,ElCard:y,ElSelect:h,ElOption:g,ElDatePicker:b,ElSkeleton:w,FontAwesomeIcon:A},data(){return{OrderState:k,orders:[],loading:!1,total:void 0,limit:10,filterState:this.$route.query.state?.toString()||``,filterPayWay:this.$route.query.pay_way?.toString()||``,createdAtRange:(()=>{let e=this.$route.query.created_at_from?.toString(),t=this.$route.query.created_at_to?.toString();if(e&&t)return[new Date(e),new Date(t)]})(),summary:{...M},summaryLoading:!1,exporting:!1,shortcuts:[{text:this.$t(`usage.shortcuts.today`),value:()=>{let e=new Date,t=new Date;return t.setHours(0,0,0,0),[t,e]}},{text:this.$t(`usage.shortcuts.last7Days`),value:()=>{let e=new Date,t=new Date;return t.setDate(t.getDate()-7),[t,e]}},{text:this.$t(`usage.shortcuts.last1Month`),value:()=>{let e=new Date,t=new Date;return t.setMonth(t.getMonth()-1),[t,e]}}]}},computed:{page(){return parseInt(this.$route.query.page?.toString()||`1`)},stateOptions(){return[{value:k.PENDING,label:this.$t(`order.state.pending`)},{value:k.FINISHED,label:this.$t(`order.state.finished`)},{value:k.PAID,label:this.$t(`order.state.paid`)},{value:k.EXPIRED,label:this.$t(`order.state.expired`)},{value:k.FAILED,label:this.$t(`order.state.failed`)},{value:k.REFUNDED,label:this.$t(`order.state.refunded`)}]},payWayOptions(){return[{value:`WechatPay`,label:this.$t(`order.title.wechatPay`)},{value:`Stripe`,label:this.$t(`order.title.stripe`)},{value:`AliPay`,label:this.$t(`order.title.aliPay`)},{value:`X402`,label:this.$t(`order.title.x402`)},{value:`PayPal`,label:this.$t(`order.title.paypal`)}]},filterQuery(){let e={user_id:this.$store.getters.user?.id};return this.filterState&&(e.state=this.filterState),this.filterPayWay&&(e.pay_way=this.filterPayWay),this.createdAtRange?.[0]&&(e.created_at_from=this.createdAtRange[0]),this.createdAtRange?.[1]&&(e.created_at_to=this.createdAtRange[1]),e}},watch:{page:{handler(){this.onFetchData()}}},mounted(){this.onFetchData(),this.onFetchSummary()},methods:{getPriceString:T,stateTagType(e){return e===k.FINISHED||e===k.PAID?`success`:e===k.EXPIRED||e===k.FAILED?`danger`:e===k.REFUNDED?`warning`:`info`},stateLabel(e){return{[k.PENDING]:this.$t(`order.state.pending`),[k.PAID]:this.$t(`order.state.paid`),[k.FINISHED]:this.$t(`order.state.finished`),[k.EXPIRED]:this.$t(`order.state.expired`),[k.FAILED]:this.$t(`order.state.failed`),[k.REFUNDED]:this.$t(`order.state.refunded`)}[e]||e},isPendingAction(e){return e!==k.PAID&&e!==k.FINISHED&&e!==k.EXPIRED&&e!==k.FAILED&&e!==k.REFUNDED},goToDetail(e){this.$router.push({name:`console-order-detail`,params:{id:e}})},async onFilterChange(){await this.$router.push({name:this.$route.name?.toString(),query:{page:1,...this.filterState?{state:this.filterState}:{},...this.filterPayWay?{pay_way:this.filterPayWay}:{},...this.createdAtRange?.[0]?{created_at_from:this.createdAtRange[0].toISOString()}:{},...this.createdAtRange?.[1]?{created_at_to:this.createdAtRange[1].toISOString()}:{}}}),this.onFetchData(),this.onFetchSummary()},onPageChange(e){this.$router.push({name:this.$route.name?.toString(),query:{...this.$route.query,page:e}})},onFetchData(){this.loading=!0,O.getAll({ordering:`-created_at`,limit:this.limit,offset:(this.page-1)*this.limit,...this.filterQuery}).then(({data:e})=>{this.orders=e.items,this.total=e.count}).catch(()=>{}).finally(()=>{this.loading=!1})},onFetchSummary(){this.summaryLoading=!0,O.getSummary(this.filterQuery).then(({data:e})=>{this.summary=e}).catch(()=>{this.summary={...M}}).finally(()=>{this.summaryLoading=!1})},onExport(){this.exporting=!0,O.exportCsv(this.filterQuery).then(({data:e})=>{let t=window.URL.createObjectURL(e),n=document.createElement(`a`);n.href=t,n.download=`orders.csv`,n.click(),window.URL.revokeObjectURL(t)}).catch(()=>{}).finally(()=>{this.exporting=!1})}}}),P={class:`title`},F={key:1,class:`card-content`},I={class:`icon-wrapper`},L={class:`description`},R={class:`value`},z={key:1,class:`card-content`},B={class:`icon-wrapper`},V={class:`description`},H={class:`value`},U={key:1,class:`card-content`},W={class:`icon-wrapper`},ee={class:`description`},G={class:`value`},K={key:1,class:`card-content`},q={class:`icon-wrapper`},J={class:`description`},Y={class:`value`},X={class:`filter-row mb-3`},Z={class:`key`},Q={class:`cursor-pointer`},$={class:`price`},te={class:`description`},ne={class:`text-gray-500`},re={class:`created-at`},ie={class:`flex items-center justify-center flex-wrap`},ae={class:`float-right`};function oe(r,m,h,g,_,v){let y=f(`el-col`),b=f(`el-row`),x=f(`el-skeleton`),S=f(`font-awesome-icon`),C=f(`el-card`),w=f(`el-option`),T=f(`el-select`),E=f(`el-date-picker`),D=f(`el-button`),O=f(`copy-to-clipboard`),k=f(`el-table-column`),A=f(`el-tag`),j=f(`el-table`),M=f(`pagination`),N=d(`loading`);return l(),a(b,{class:`panel`},{default:p(()=>[o(y,{span:24},{default:p(()=>[o(b,null,{default:p(()=>[o(y,{span:24},{default:p(()=>[n(`h2`,P,c(r.$t(`common.title.allOrders`)),1)]),_:1})]),_:1}),o(b,{gutter:16},{default:p(()=>[o(y,{md:6,sm:12,xs:24},{default:p(()=>[o(C,{shadow:`hover`,class:`item-mini mb-3`},{default:p(()=>[r.summaryLoading?(l(),a(x,{key:0})):(l(),t(`div`,F,[n(`div`,I,[o(S,{icon:`fa-solid fa-receipt`,class:`icon`})]),n(`p`,L,c(r.$t(`order.title.totalOrders`)),1),n(`p`,R,c(r.summary.total_count),1)]))]),_:1})]),_:1}),o(y,{md:6,sm:12,xs:24},{default:p(()=>[o(C,{shadow:`hover`,class:`item-mini mb-3`},{default:p(()=>[r.summaryLoading?(l(),a(x,{key:0})):(l(),t(`div`,z,[n(`div`,B,[o(S,{icon:`fa-solid fa-dollar-sign`,class:`icon`})]),n(`p`,V,c(r.$t(`order.title.totalSpent`)),1),n(`p`,H,c(r.getPriceString({value:r.summary.total_spent})),1)]))]),_:1})]),_:1}),o(y,{md:6,sm:12,xs:24},{default:p(()=>[o(C,{shadow:`hover`,class:`item-mini mb-3`},{default:p(()=>[r.summaryLoading?(l(),a(x,{key:0})):(l(),t(`div`,U,[n(`div`,W,[o(S,{icon:`fa-solid fa-check-circle`,class:`icon`})]),n(`p`,ee,c(r.$t(`order.title.finishedOrders`)),1),n(`p`,G,c(r.summary.state_counts?.Finished||0),1)]))]),_:1})]),_:1}),o(y,{md:6,sm:12,xs:24},{default:p(()=>[o(C,{shadow:`hover`,class:`item-mini mb-3`},{default:p(()=>[r.summaryLoading?(l(),a(x,{key:0})):(l(),t(`div`,K,[n(`div`,q,[o(S,{icon:`fa-solid fa-clock`,class:`icon`})]),n(`p`,J,c(r.$t(`order.title.pendingOrders`)),1),n(`p`,Y,c(r.summary.state_counts?.Pending||0),1)]))]),_:1})]),_:1})]),_:1}),n(`div`,X,[o(T,{modelValue:r.filterState,"onUpdate:modelValue":m[0]||=e=>r.filterState=e,clearable:``,placeholder:r.$t(`order.field.allStates`),class:`filter-select`,onChange:r.onFilterChange},{default:p(()=>[(l(!0),t(s,null,e(r.stateOptions,e=>(l(),a(w,{key:e.value,label:e.label,value:e.value},null,8,[`label`,`value`]))),128))]),_:1},8,[`modelValue`,`placeholder`,`onChange`]),o(T,{modelValue:r.filterPayWay,"onUpdate:modelValue":m[1]||=e=>r.filterPayWay=e,clearable:``,placeholder:r.$t(`order.field.allPayWays`),class:`filter-select`,onChange:r.onFilterChange},{default:p(()=>[(l(!0),t(s,null,e(r.payWayOptions,e=>(l(),a(w,{key:e.value,label:e.label,value:e.value},null,8,[`label`,`value`]))),128))]),_:1},8,[`modelValue`,`placeholder`,`onChange`]),o(E,{modelValue:r.createdAtRange,"onUpdate:modelValue":m[2]||=e=>r.createdAtRange=e,type:`datetimerange`,shortcuts:r.shortcuts,"range-separator":r.$t(`usage.placeholder.to`),"start-placeholder":r.$t(`usage.placeholder.startDate`),"end-placeholder":r.$t(`usage.placeholder.endDate`),onChange:r.onFilterChange},null,8,[`modelValue`,`shortcuts`,`range-separator`,`start-placeholder`,`end-placeholder`,`onChange`]),o(D,{type:`primary`,plain:``,loading:r.exporting,onClick:r.onExport},{default:p(()=>[o(S,{icon:`fa-solid fa-file-export`,class:`mr-1`}),i(` `+c(r.$t(`order.button.export`)),1)]),_:1},8,[`loading`,`onClick`])]),o(b,null,{default:p(()=>[o(y,{span:24},{default:p(()=>[o(C,{shadow:`hover`},{default:p(()=>[u((l(),a(j,{data:r.orders,stripe:``,"empty-text":r.$t(`common.message.noData`),class:`min-h-[calc(100vh-450px)] mb-[20px]`},{default:p(()=>[o(k,{prop:`id`,label:r.$t(`order.field.id`),"class-name":`text-center`,width:`200px`},{default:p(e=>[n(`span`,Z,c(e.row.id),1),n(`span`,Q,[o(O,{content:e.row.id,class:`inline-block`},null,8,[`content`])])]),_:1},8,[`label`]),o(k,{label:r.$t(`order.field.price`),width:`110px`,align:`center`},{default:p(e=>[n(`span`,$,c(r.getPriceString({value:e.row?.price})),1)]),_:1},8,[`label`]),o(k,{label:r.$t(`order.field.description`),"min-width":`220px`,"class-name":`hidden md:table-cell`,"label-class-name":`hidden md:table-cell`},{default:p(e=>[n(`span`,te,c(e.row.description),1)]),_:1},8,[`label`]),o(k,{prop:`state`,label:r.$t(`order.field.state`),width:`130px`,align:`center`},{default:p(e=>[o(A,{type:r.stateTagType(e.row.state),class:`mx-1`,effect:`dark`,round:``,size:`small`},{default:p(()=>[i(c(r.stateLabel(e.row.state)),1)]),_:2},1032,[`type`])]),_:1},8,[`label`]),o(k,{label:r.$t(`order.field.payWay`),width:`120px`,align:`center`,"class-name":`hidden md:table-cell`,"label-class-name":`hidden md:table-cell`},{default:p(e=>[n(`span`,ne,c(e.row.pay_way||`-`),1)]),_:1},8,[`label`]),o(k,{label:r.$t(`order.field.createdAt`),width:`200px`,"class-name":`hidden sm:table-cell`,"label-class-name":`hidden sm:table-cell`},{default:p(e=>[n(`span`,re,c(r.$dayjs.format(e.row.created_at)),1)]),_:1},8,[`label`]),o(k,{"min-width":`130px`,fixed:`right`},{default:p(e=>[n(`div`,ie,[r.isPendingAction(e.row.state)?(l(),a(D,{key:0,type:`primary`,size:`small`,onClick:t=>r.goToDetail(e.row.id)},{default:p(()=>[i(c(r.$t(`order.button.continuePay`)),1)]),_:1},8,[`onClick`])):(l(),a(D,{key:1,size:`small`,onClick:t=>r.goToDetail(e.row.id)},{default:p(()=>[i(c(r.$t(`order.button.checkDetail`)),1)]),_:1},8,[`onClick`]))])]),_:1})]),_:1},8,[`data`,`empty-text`])),[[N,r.loading]])]),_:1})]),_:1})]),_:1}),o(b,null,{default:p(()=>[o(y,{span:10,offset:14},{default:p(()=>[n(`div`,ae,[o(M,{"current-page":r.page,"page-size":r.limit,total:r.total,onChange:r.onPageChange},null,8,[`current-page`,`page-size`,`total`,`onChange`])])]),_:1})]),_:1})]),_:1})]),_:1})}var se=E(N,[[`render`,oe],[`__scopeId`,`data-v-350ab467`]]);export{se as default};
@@ -1 +1 @@
1
- import"./rolldown-runtime--c01j_DQ.js";import{A as e,D as t,E as n,F as r,N as i,O as a,P as o,Wt as s,Z as c,k as l,tt as u,ut as d}from"./vendor-chart-BJCvKk8-.js";import{t as f}from"./button-BydTr5nV.js";import{t as p}from"./Navigator-CqqFre8U.js";import{t as m}from"./checkbox-BC1X4B2U.js";import{t as h}from"./divider-LA__Fty9.js";import"./constants-RDUJTh3D.js";import{Ar as g,Br as _,Dr as v,E as y,Nr as b,Or as x,Rt as S,Ur as C,zn as w}from"./index-Bm66Z2-R.js";import{t as T}from"./Status-DUWd7Jf9.js";var E=r({name:`ApplicationConfirm`,components:{ElDialog:C,ElDivider:h,ElCheckbox:m,ElButton:f},props:{visible:{type:Boolean,required:!1,default:!1}},emits:[`update:visible`,`apply`],data(){return{checked:!0}},watch:{},methods:{getBaseUrlPlatform:b,onApply(){if(!this.checked){_.error(this.$t(`application.message.notAgreePolicy`));return}this.$emit(`apply`)}}}),D={class:`content py-[10px] px-[40px]`},O={class:`my-4`},k={class:`policy mb-[10px]`},A={class:`policy-title text-[12px] relative -bottom-[3px]`},j=[`href`];function M(e,n,r,l,f,p){let m=u(`el-divider`),h=u(`el-checkbox`),g=u(`el-button`),_=u(`el-dialog`);return c(),a(_,{"model-value":e.visible,width:`500px`,title:e.$t(`application.message.welcome`),center:``,onClose:n[1]||=t=>e.$emit(`update:visible`,!1)},{default:d(()=>[t(`div`,D,[t(`p`,O,s(e.$t(`application.message.notApplied`)),1),o(m,{class:`my-2`}),t(`div`,k,[o(h,{modelValue:e.checked,"onUpdate:modelValue":n[0]||=t=>e.checked=t,size:`large`,class:`policy-checkbox mr-[10px]`},null,8,[`modelValue`]),t(`span`,A,s(e.$t(`application.message.readPolicy`)),1),t(`a`,{class:`policy-title text-[12px] relative -bottom-[3px] text-[var(--el-color-primary)] cursor-pointer no-underline`,target:`_blank`,href:e.getBaseUrlPlatform()+`/terms`},` \xA0`+s(e.$t(`application.message.policy`)),9,j)]),o(g,{round:``,type:`primary`,onClick:e.onApply},{default:d(()=>[i(s(e.$t(`common.button.start`)),1)]),_:1},8,[`onClick`])])]),_:1},8,[`model-value`,`title`])}var N=y(E,[[`render`,M]]),P=15e3,F=r({name:`LayoutMain`,components:{Navigator:p,ApplicationStatus:T,ApplicationConfirm:N},provide(){return{initialized:n(()=>this.initialized)}},data(){return{initialized:!1,applying:!1,mobile:typeof window<`u`&&window.innerWidth<768,initializeRunId:0,balanceTimer:0}},computed:{appName(){return this.$route.meta.appName},application(){return this.$store.state[this.appName]?.application},applications(){let e=this.$store.state[this.appName]?.applications??[];console.debug(`individualApplications`,e);let t=this.$store.state.applications??[];return console.debug(`globalApplications`,t),t.concat(e)},loading(){return this.$store.state[this.appName]?.status?.getApplications===g.Request},service(){return this.$store.state[this.appName]?.service},userId(){return this.$store.state.user?.id}},watch:{appName(){this.initialize()},userId(e,t){e&&e!==t&&this.initialize()}},mounted(){this.initialize(),window.addEventListener(`resize`,this.onResize),this.balanceTimer=window.setInterval(this.refreshBalances,P),document.addEventListener(`visibilitychange`,this.onVisibility)},beforeUnmount(){window.removeEventListener(`resize`,this.onResize),window.clearInterval(this.balanceTimer),document.removeEventListener(`visibilitychange`,this.onVisibility)},methods:{onResize(){this.mobile=window.innerWidth<768},onVisibility(){typeof document<`u`&&!document.hidden&&this.refreshBalances()},async refreshBalances(){if(!this.appName||!this.$store.state.token?.access||typeof document<`u`&&document.hidden||this.loading)return;await Promise.allSettled([this.$store.dispatch(`getApplications`),this.$store.dispatch(`${this.appName}/getApplications`)]);let e=this.$store.state[this.appName]?.application;if(!e)return;let t=this.applications?.find(t=>t.id===e.id);t&&t!==e&&this.$store.commit(`${this.appName}/setApplication`,t)},async initialize(){let e=++this.initializeRunId;if(this.initialized=!1,console.debug(`Fetching all individual and global applications for`,this.appName),await Promise.allSettled([this.$store.dispatch(`getApplications`),this.$store.dispatch(`${this.appName}/getApplications`)]),e!==this.initializeRunId)return;console.debug(`Fetched all applications`,this.applications),this.$store.state.applications?.length===0&&await this.onAutoApply();let t=this.$store.state[this.appName]?.application;console.debug(`current application`,t);let n=S(this.applications,t);console.debug(`final application`,n),n&&(console.debug(`set final application`,n,n?.type),await this.$store.dispatch(`${this.appName}/setApplication`,n)),console.debug(`finished initialization`),this.initialized=!0},onApply(){this.onAutoApply()},async onAutoApply(){try{await w.create({type:x.USAGE,scope:v.GLOBAL,user_id:this.$store.getters.user.id}),this.applying=!1,await this.$store.dispatch(`getApplications`),this.showWelcomeToast()}catch(e){e?.response?.data?.code===`duplication`?await this.$store.dispatch(`getApplications`):_.error(this.$t(`application.message.applyFailed`))}},showWelcomeToast(){let e=this.$store.state.applications?.[0],t=Math.floor(e?.remaining_amount??0);_({message:t>0?this.$t(`application.message.welcomeWithCredits`,{credits:t}):this.$t(`application.message.welcomeNoCredits`),type:`success`,duration:6e3,showClose:!0})}}}),I={class:`wrapper`};function L(t,n,r,i,s,d){let f=u(`router-view`),p=u(`navigator`),m=u(`application-status`),h=u(`application-confirm`);return c(),e(`div`,I,[o(f,{class:`main`}),o(p,{class:`navigator`,direction:t.mobile?`row`:`column`},null,8,[`direction`]),t.application?(c(),a(m,{key:0,class:`status-floating fixed right-2 z-[200]`,application:t.application,applications:t.applications,"show-price":!1,authenticated:!!t.$store.state.token.access,service:t.service,onSelect:n[0]||=e=>t.$store.dispatch(`${t.appName}/setApplication`,e)},null,8,[`application`,`applications`,`authenticated`,`service`])):l(``,!0),o(h,{modelValue:t.applying,"onUpdate:modelValue":n[1]||=e=>t.applying=e,modelModifiers:{visible:!0},onApply:t.onApply},null,8,[`modelValue`,`onApply`])])}var R=y(F,[[`render`,L],[`__scopeId`,`data-v-f14707c1`]]);export{R as default};
1
+ import"./rolldown-runtime--c01j_DQ.js";import{A as e,D as t,E as n,F as r,N as i,O as a,P as o,Wt as s,Z as c,k as l,tt as u,ut as d}from"./vendor-chart-BJCvKk8-.js";import{t as f}from"./button-BydTr5nV.js";import{t as p}from"./Navigator-vMeUibUF.js";import{t as m}from"./checkbox-BC1X4B2U.js";import{t as h}from"./divider-LA__Fty9.js";import"./constants-HhUTei7L.js";import{Ar as g,Br as _,Dr as v,E as y,Nr as b,Or as x,Rt as S,Ur as C,zn as w}from"./index-DPve7EH6.js";import{t as T}from"./Status-DYuOXZyK.js";var E=r({name:`ApplicationConfirm`,components:{ElDialog:C,ElDivider:h,ElCheckbox:m,ElButton:f},props:{visible:{type:Boolean,required:!1,default:!1}},emits:[`update:visible`,`apply`],data(){return{checked:!0}},watch:{},methods:{getBaseUrlPlatform:b,onApply(){if(!this.checked){_.error(this.$t(`application.message.notAgreePolicy`));return}this.$emit(`apply`)}}}),D={class:`content py-[10px] px-[40px]`},O={class:`my-4`},k={class:`policy mb-[10px]`},A={class:`policy-title text-[12px] relative -bottom-[3px]`},j=[`href`];function M(e,n,r,l,f,p){let m=u(`el-divider`),h=u(`el-checkbox`),g=u(`el-button`),_=u(`el-dialog`);return c(),a(_,{"model-value":e.visible,width:`500px`,title:e.$t(`application.message.welcome`),center:``,onClose:n[1]||=t=>e.$emit(`update:visible`,!1)},{default:d(()=>[t(`div`,D,[t(`p`,O,s(e.$t(`application.message.notApplied`)),1),o(m,{class:`my-2`}),t(`div`,k,[o(h,{modelValue:e.checked,"onUpdate:modelValue":n[0]||=t=>e.checked=t,size:`large`,class:`policy-checkbox mr-[10px]`},null,8,[`modelValue`]),t(`span`,A,s(e.$t(`application.message.readPolicy`)),1),t(`a`,{class:`policy-title text-[12px] relative -bottom-[3px] text-[var(--el-color-primary)] cursor-pointer no-underline`,target:`_blank`,href:e.getBaseUrlPlatform()+`/terms`},` \xA0`+s(e.$t(`application.message.policy`)),9,j)]),o(g,{round:``,type:`primary`,onClick:e.onApply},{default:d(()=>[i(s(e.$t(`common.button.start`)),1)]),_:1},8,[`onClick`])])]),_:1},8,[`model-value`,`title`])}var N=y(E,[[`render`,M]]),P=15e3,F=r({name:`LayoutMain`,components:{Navigator:p,ApplicationStatus:T,ApplicationConfirm:N},provide(){return{initialized:n(()=>this.initialized)}},data(){return{initialized:!1,applying:!1,mobile:typeof window<`u`&&window.innerWidth<768,initializeRunId:0,balanceTimer:0}},computed:{appName(){return this.$route.meta.appName},application(){return this.$store.state[this.appName]?.application},applications(){let e=this.$store.state[this.appName]?.applications??[];console.debug(`individualApplications`,e);let t=this.$store.state.applications??[];return console.debug(`globalApplications`,t),t.concat(e)},loading(){return this.$store.state[this.appName]?.status?.getApplications===g.Request},service(){return this.$store.state[this.appName]?.service},userId(){return this.$store.state.user?.id}},watch:{appName(){this.initialize()},userId(e,t){e&&e!==t&&this.initialize()}},mounted(){this.initialize(),window.addEventListener(`resize`,this.onResize),this.balanceTimer=window.setInterval(this.refreshBalances,P),document.addEventListener(`visibilitychange`,this.onVisibility)},beforeUnmount(){window.removeEventListener(`resize`,this.onResize),window.clearInterval(this.balanceTimer),document.removeEventListener(`visibilitychange`,this.onVisibility)},methods:{onResize(){this.mobile=window.innerWidth<768},onVisibility(){typeof document<`u`&&!document.hidden&&this.refreshBalances()},async refreshBalances(){if(!this.appName||!this.$store.state.token?.access||typeof document<`u`&&document.hidden||this.loading)return;await Promise.allSettled([this.$store.dispatch(`getApplications`),this.$store.dispatch(`${this.appName}/getApplications`)]);let e=this.$store.state[this.appName]?.application;if(!e)return;let t=this.applications?.find(t=>t.id===e.id);t&&t!==e&&this.$store.commit(`${this.appName}/setApplication`,t)},async initialize(){let e=++this.initializeRunId;if(this.initialized=!1,console.debug(`Fetching all individual and global applications for`,this.appName),await Promise.allSettled([this.$store.dispatch(`getApplications`),this.$store.dispatch(`${this.appName}/getApplications`)]),e!==this.initializeRunId)return;console.debug(`Fetched all applications`,this.applications),this.$store.state.applications?.length===0&&await this.onAutoApply();let t=this.$store.state[this.appName]?.application;console.debug(`current application`,t);let n=S(this.applications,t);console.debug(`final application`,n),n&&(console.debug(`set final application`,n,n?.type),await this.$store.dispatch(`${this.appName}/setApplication`,n)),console.debug(`finished initialization`),this.initialized=!0},onApply(){this.onAutoApply()},async onAutoApply(){try{await w.create({type:x.USAGE,scope:v.GLOBAL,user_id:this.$store.getters.user.id}),this.applying=!1,await this.$store.dispatch(`getApplications`),this.showWelcomeToast()}catch(e){e?.response?.data?.code===`duplication`?await this.$store.dispatch(`getApplications`):_.error(this.$t(`application.message.applyFailed`))}},showWelcomeToast(){let e=this.$store.state.applications?.[0],t=Math.floor(e?.remaining_amount??0);_({message:t>0?this.$t(`application.message.welcomeWithCredits`,{credits:t}):this.$t(`application.message.welcomeNoCredits`),type:`success`,duration:6e3,showClose:!0})}}}),I={class:`wrapper`};function L(t,n,r,i,s,d){let f=u(`router-view`),p=u(`navigator`),m=u(`application-status`),h=u(`application-confirm`);return c(),e(`div`,I,[o(f,{class:`main`}),o(p,{class:`navigator`,direction:t.mobile?`row`:`column`},null,8,[`direction`]),t.application?(c(),a(m,{key:0,class:`status-floating fixed right-2 z-[200]`,application:t.application,applications:t.applications,"show-price":!1,authenticated:!!t.$store.state.token.access,service:t.service,onSelect:n[0]||=e=>t.$store.dispatch(`${t.appName}/setApplication`,e)},null,8,[`application`,`applications`,`authenticated`,`service`])):l(``,!0),o(h,{modelValue:t.applying,"onUpdate:modelValue":n[1]||=e=>t.applying=e,modelModifiers:{visible:!0},onApply:t.onApply},null,8,[`modelValue`,`onApply`])])}var R=y(F,[[`render`,L],[`__scopeId`,`data-v-f14707c1`]]);export{R as default};
@@ -1 +1 @@
1
- import"./rolldown-runtime--c01j_DQ.js";import{$ as e,A as t,D as n,F as r,N as i,O as a,P as o,S as s,Vt as c,Wt as l,Z as u,b as d,k as f,tt as p,ut as m}from"./vendor-chart-BJCvKk8-.js";import{t as h}from"./button-BydTr5nV.js";import{t as g}from"./upload-BHEVKf-6.js";import{t as _}from"./image-BHSCm3en.js";import{t as v}from"./alert-CuX4SjQB.js";import{n as y,r as b}from"./radio-3Hz7h3DR.js";import{t as x}from"./switch-BgIktbEW.js";import{t as S}from"./vendor-axios-Ck2ffRoh.js";import"./constants-RDUJTh3D.js";import{Br as C,E as w,Ft as T,Nr as E,Z as ee,en as te,qr as D}from"./index-Bm66Z2-R.js";import{t as O}from"./index.es-ktQaPrdW.js";import{t as k}from"./CopyToClipboard-BDrnVqbi.js";import{t as A}from"./BotPlaceholder-DbazdyYE.js";import{t as j}from"./Hailuo-BN4N4CBj.js";import{t as M}from"./TabSwitcher-BeDnFcKf.js";var N=4,P=90,F=r({name:`FishRecorder`,components:{ElButton:h,FontAwesomeIcon:O},emits:[`done`,`cancel`,`update:script`],data(){return{state:`idle`,scriptIndex:0,seconds:0,timerId:0,maxTimerId:0,mediaRecorder:null,stream:null,chunks:[],recordedBlob:null,recordedUrl:``,uploading:!1}},computed:{formattedTime(){let e=Math.floor(this.seconds/60),t=this.seconds%60;return`${e.toString().padStart(2,`0`)}:${t.toString().padStart(2,`0`)}`},currentScript(){let e=`fish.script.passage${this.scriptIndex%N+1}`;return this.$t(e)}},beforeUnmount(){this.cleanup()},mounted(){this.$emit(`update:script`,this.currentScript)},methods:{nextScript(){this.scriptIndex=(this.scriptIndex+1)%N,this.$emit(`update:script`,this.currentScript)},async startRecord(){if(!navigator.mediaDevices?.getUserMedia||typeof MediaRecorder>`u`){C.error(this.$t(`fish.message.recorderUnsupported`));return}try{this.stream=await navigator.mediaDevices.getUserMedia({audio:!0})}catch(e){let t=e?.name===`NotAllowedError`||e?.name===`PermissionDeniedError`;C.error(this.$t(t?`fish.message.micDenied`:`fish.message.micError`));return}this.chunks=[];let e=this.pickMimeType();try{this.mediaRecorder=e?new MediaRecorder(this.stream,{mimeType:e}):new MediaRecorder(this.stream)}catch{this.mediaRecorder=new MediaRecorder(this.stream)}this.mediaRecorder.ondataavailable=e=>{e.data&&e.data.size>0&&this.chunks.push(e.data)},this.mediaRecorder.onstop=()=>{let e=new Blob(this.chunks,{type:this.mediaRecorder?.mimeType||`audio/webm`});this.recordedBlob=e,this.recordedUrl=URL.createObjectURL(e),this.state=`recorded`,this.releaseStream()},this.mediaRecorder.start(),this.state=`recording`,this.seconds=0,this.timerId=window.setInterval(()=>{this.seconds++},1e3),this.maxTimerId=window.setTimeout(()=>{this.state===`recording`&&this.stopRecord()},P*1e3)},stopRecord(){this.mediaRecorder&&this.mediaRecorder.state!==`inactive`&&this.mediaRecorder.stop(),window.clearInterval(this.timerId),window.clearTimeout(this.maxTimerId)},reset(){this.recordedUrl&&URL.revokeObjectURL(this.recordedUrl),this.recordedUrl=``,this.recordedBlob=null,this.state=`idle`,this.seconds=0},onCancel(){this.cleanup(),this.$emit(`cancel`)},cleanup(){this.stopRecord(),this.releaseStream(),this.recordedUrl&&URL.revokeObjectURL(this.recordedUrl)},releaseStream(){this.stream?.getTracks().forEach(e=>e.stop()),this.stream=null},pickMimeType(){for(let e of[`audio/webm;codecs=opus`,`audio/webm`,`audio/mp4`,`audio/ogg`])if(typeof MediaRecorder<`u`&&MediaRecorder.isTypeSupported?.(e))return e},extensionForMime(e){return e.includes(`webm`)?`webm`:e.includes(`mp4`)?`m4a`:e.includes(`ogg`)?`ogg`:e.includes(`wav`)?`wav`:`mp3`},async useRecording(){if(this.recordedBlob){if(this.seconds<3){C.warning(this.$t(`fish.message.recordingTooShort`));return}this.uploading=!0;try{let e=this.$store.state.token?.access,t=this.extensionForMime(this.recordedBlob.type||``),n=new File([this.recordedBlob],`recording-${Date.now()}.${t}`,{type:this.recordedBlob.type||`audio/webm`}),r=new FormData;r.append(`file`,n);let{data:i}=await S.post(`${E()}/api/v1/files/`,r,{headers:{Authorization:`Bearer ${e}`}}),a=i?.file_url;if(!a){C.error(this.$t(`fish.message.uploadError`));return}this.$emit(`done`,{url:a,text:this.currentScript})}catch(e){C.error(this.$t(`fish.message.uploadError`)),console.error(`recorder upload failed`,e)}finally{this.uploading=!1}}}}}),I={class:`recorder`},L={key:0,class:`script`},R={class:`script-header`},z={class:`label`},B={class:`script-text`},V={class:`controls`},H={class:`status`},U={class:`hint`},W={key:1,class:`preview`},G=[`src`],K={class:`preview-actions`},q={class:`footer`};function J(e,r,s,d,h,g){let _=p(`font-awesome-icon`),v=p(`el-button`);return u(),t(`div`,I,[e.state===`recorded`?f(``,!0):(u(),t(`div`,L,[n(`div`,R,[o(_,{icon:`fa-solid fa-book-open`,class:`icon mr-1`}),n(`span`,z,l(e.$t(`fish.description.readScript`)),1),o(v,{link:``,size:`small`,class:`ml-auto`,disabled:e.state===`recording`,onClick:e.nextScript},{default:m(()=>[o(_,{icon:`fa-solid fa-shuffle`,class:`mr-1`}),i(` `+l(e.$t(`fish.button.nextScript`)),1)]),_:1},8,[`disabled`,`onClick`])]),n(`p`,B,l(e.currentScript),1)])),n(`div`,V,[e.state===`idle`?(u(),a(v,{key:0,type:`danger`,circle:``,size:`large`,title:e.$t(`fish.button.startRecord`),onClick:e.startRecord},{default:m(()=>[o(_,{icon:`fa-solid fa-microphone`})]),_:1},8,[`title`,`onClick`])):e.state===`recording`?(u(),a(v,{key:1,type:`warning`,circle:``,size:`large`,title:e.$t(`fish.button.stopRecord`),onClick:e.stopRecord},{default:m(()=>[o(_,{icon:`fa-solid fa-stop`})]),_:1},8,[`title`,`onClick`])):f(``,!0),n(`div`,H,[n(`span`,{class:c([`timer`,e.state===`recording`?`live`:``])},l(e.formattedTime),3),n(`span`,U,l(e.state===`idle`?e.$t(`fish.description.recorderIdle`):e.state===`recording`?e.$t(`fish.description.recorderRecording`):e.$t(`fish.description.recorderRecorded`)),1)])]),e.state===`recorded`&&e.recordedUrl?(u(),t(`div`,W,[n(`audio`,{src:e.recordedUrl,controls:``,preload:`metadata`,class:`w-full`},null,8,G),n(`div`,K,[o(v,{size:`small`,disabled:e.uploading,onClick:e.reset},{default:m(()=>[o(_,{icon:`fa-solid fa-rotate-left`,class:`mr-1`}),i(` `+l(e.$t(`fish.button.reRecord`)),1)]),_:1},8,[`disabled`,`onClick`]),o(v,{size:`small`,type:`primary`,loading:e.uploading,onClick:e.useRecording},{default:m(()=>[o(_,{icon:`fa-solid fa-check`,class:`mr-1`}),i(` `+l(e.$t(`fish.button.useRecording`)),1)]),_:1},8,[`loading`,`onClick`])])])):f(``,!0),n(`div`,q,[o(v,{link:``,size:`small`,disabled:e.uploading||e.state===`recording`,onClick:e.onCancel},{default:m(()=>[i(l(e.$t(`fish.button.cancel`)),1)]),_:1},8,[`disabled`,`onClick`])])])}var Y=w(F,[[`render`,J],[`__scopeId`,`data-v-1958e4a1`]]),X=50*1024*1024,Z=()=>({title:``,description:``,texts:``,voicesUrl:``,visibility:`unlist`,trainMode:`fast`,enhanceAudio:!0,generateSample:!1}),Q=r({name:`FishModelConfigPanel`,components:{ElButton:h,ElInput:D,ElRadioButton:y,ElRadioGroup:b,ElSwitch:x,ElUpload:g,FontAwesomeIcon:O,Recorder:Y},mixins:[T],emits:[`create`],data(){return{form:Z(),fileList:[],uploading:!1,creating:!1,recording:!1,textsAuto:!0}},computed:{uploadUrl(){return E()+`/api/v1/files/`},uploadHeaders(){return{Authorization:`Bearer ${this.$store.state.token?.access}`}},canCreate(){return!!this.form.title.trim()&&!!this.form.voicesUrl&&!this.uploading&&!this.creating},supportsRecorder(){return!!(typeof navigator<`u`?navigator.mediaDevices:void 0)?.getUserMedia&&typeof MediaRecorder<`u`}},methods:{onBeforeUpload(e){return e.size>X?(C.warning(this.$t(`fish.message.audioSizeExceed`)),!1):(this.uploading=!0,!0)},onExceed(){C.warning(this.$t(`fish.message.audioOnlyOne`))},onUploadError(){this.uploading=!1,C.error(this.$t(`fish.message.uploadError`))},onUploadSuccess(e,t,n){this.uploading=!1;let r=e?.file_url;if(!r){C.error(this.$t(`fish.message.uploadError`)),this.fileList=[];return}this.form.voicesUrl=r,this.fileList=n},onRecorded(e){this.form.voicesUrl=e.url,this.recording=!1,e.text&&this.textsAuto&&(this.form.texts=e.text)},onStartRecord(){this.recording=!0,this.textsAuto=!this.form.texts.trim()},onScriptChange(e){this.textsAuto&&this.recording&&(this.form.texts=e)},onTextsInput(){this.textsAuto=!1},clearAudio(){this.form.voicesUrl=``,this.fileList=[]},onCreate(){let e=this.form.title.trim();if(!e){C.warning(this.$t(`fish.message.titleRequired`));return}if(!this.form.voicesUrl){C.warning(this.$t(`fish.message.audioRequired`));return}let t={title:e,voices:this.form.voicesUrl,visibility:this.form.visibility,train_mode:this.form.trainMode,enhance_audio_quality:this.form.enhanceAudio,generate_sample:this.form.generateSample};this.form.description.trim()&&(t.description=this.form.description.trim()),this.form.texts.trim()&&(t.texts=[this.form.texts.trim()]),this.creating=!0,this.$emit(`create`,t),setTimeout(()=>{this.creating=!1,this.form=Z(),this.fileList=[]},600)}}}),ne={class:`flex flex-col h-full`},re={class:`flex-1 overflow-y-auto p-5`},ie={class:`field-block mb-4`},ae={class:`title font-bold`},oe={class:`field-block mb-4`},se={class:`flex items-baseline justify-between mb-1`},ce={class:`title font-bold`},le={key:0,class:`muted`},ue={class:`hint`},de={key:0,class:`audio-actions`},fe={key:1,class:`hint warn`},pe={key:3,class:`mt-2`},me=[`src`],he={class:`ready-actions`},ge={class:`field-block mb-4`},_e={class:`title font-bold`},ve={class:`hint`},ye={class:`field-block mb-4`},be={class:`title font-bold`},xe={class:`field-block mb-4`},Se={class:`title font-bold`},Ce={class:`field-block mb-4`},we={class:`title font-bold`},Te={class:`field-block mb-3`},Ee={class:`field-row`},De={class:`title font-bold`},Oe={class:`hint mt-0 mb-0`},ke={class:`field-block mb-2`},Ae={class:`field-row`},je={class:`title font-bold`},Me={class:`hint mt-0 mb-0`},Ne={class:`flex flex-col items-center justify-center px-5 pb-5`};function Pe(e,r,s,c,d,h){let g=p(`el-input`),_=p(`font-awesome-icon`),v=p(`el-button`),y=p(`el-upload`),b=p(`recorder`),x=p(`el-radio-button`),S=p(`el-radio-group`),C=p(`el-switch`);return u(),t(`div`,ne,[n(`div`,re,[n(`div`,ie,[n(`h2`,ae,[i(l(e.$t(`fish.name.voiceTitle`))+` `,1),r[9]||=n(`span`,{class:`required`},`*`,-1)]),o(g,{modelValue:e.form.title,"onUpdate:modelValue":r[0]||=t=>e.form.title=t,placeholder:e.$t(`fish.placeholder.voiceTitle`),maxlength:`60`},null,8,[`modelValue`,`placeholder`])]),n(`div`,oe,[n(`div`,se,[n(`h2`,ce,[i(l(e.$t(`fish.name.referenceAudio`))+` `,1),r[10]||=n(`span`,{class:`required`},`*`,-1)]),!e.form.voicesUrl&&!e.recording?(u(),t(`span`,le,l(e.$t(`fish.description.audioRequired`)),1)):f(``,!0)]),n(`p`,ue,l(e.$t(`fish.description.uploadAudio`)),1),!e.form.voicesUrl&&!e.recording?(u(),t(`div`,de,[o(y,{"file-list":e.fileList,"onUpdate:fileList":r[1]||=t=>e.fileList=t,name:`file`,limit:1,class:`upload-wrapper`,action:e.uploadUrl,accept:`.mp3,.wav,.m4a,.ogg,.webm,audio/*`,"show-file-list":!1,"on-exceed":e.onExceed,"on-error":e.onUploadError,"on-success":e.onUploadSuccess,"before-upload":e.onBeforeUpload,headers:e.uploadHeaders},{default:m(()=>[o(v,{type:`primary`,plain:``,round:``,loading:e.uploading},{default:m(()=>[o(_,{icon:`fa-solid fa-upload`,class:`icon mr-1`}),i(` `+l(e.$t(`fish.button.uploadAudio`)),1)]),_:1},8,[`loading`])]),_:1},8,[`file-list`,`action`,`on-exceed`,`on-error`,`on-success`,`before-upload`,`headers`]),o(v,{type:`primary`,round:``,disabled:!e.supportsRecorder,onClick:e.onStartRecord},{default:m(()=>[o(_,{icon:`fa-solid fa-microphone`,class:`icon mr-1`}),i(` `+l(e.$t(`fish.button.recordAudio`)),1)]),_:1},8,[`disabled`,`onClick`])])):f(``,!0),!e.supportsRecorder&&!e.form.voicesUrl&&!e.recording?(u(),t(`p`,fe,l(e.$t(`fish.message.recorderUnsupported`)),1)):f(``,!0),e.recording?(u(),a(b,{key:2,class:`mt-2`,onDone:e.onRecorded,onCancel:r[2]||=t=>e.recording=!1,"onUpdate:script":e.onScriptChange},null,8,[`onDone`,`onUpdate:script`])):f(``,!0),e.form.voicesUrl&&!e.recording?(u(),t(`div`,pe,[n(`audio`,{src:e.form.voicesUrl,controls:``,preload:`metadata`,class:`w-full`},null,8,me),n(`div`,he,[o(v,{link:``,size:`small`,onClick:e.clearAudio},{default:m(()=>[o(_,{icon:`fa-solid fa-rotate-left`,class:`mr-1`}),i(` `+l(e.$t(`fish.button.replaceAudio`)),1)]),_:1},8,[`onClick`])])])):f(``,!0)]),n(`div`,ge,[n(`h2`,_e,l(e.$t(`fish.name.audioTexts`)),1),n(`p`,ve,l(e.$t(`fish.description.audioTexts`)),1),o(g,{modelValue:e.form.texts,"onUpdate:modelValue":r[3]||=t=>e.form.texts=t,type:`textarea`,rows:2,placeholder:e.$t(`fish.placeholder.audioTexts`),maxlength:`500`,onInput:e.onTextsInput},null,8,[`modelValue`,`placeholder`,`onInput`])]),n(`div`,ye,[n(`h2`,be,l(e.$t(`fish.name.voiceDescription`)),1),o(g,{modelValue:e.form.description,"onUpdate:modelValue":r[4]||=t=>e.form.description=t,type:`textarea`,rows:2,placeholder:e.$t(`fish.placeholder.voiceDescription`),maxlength:`500`},null,8,[`modelValue`,`placeholder`])]),n(`div`,xe,[n(`h2`,Se,l(e.$t(`fish.name.visibility`)),1),o(S,{modelValue:e.form.visibility,"onUpdate:modelValue":r[5]||=t=>e.form.visibility=t,size:`small`},{default:m(()=>[o(x,{label:`private`,value:`private`},{default:m(()=>[i(l(e.$t(`fish.value.private`)),1)]),_:1}),o(x,{label:`unlist`,value:`unlist`},{default:m(()=>[i(l(e.$t(`fish.value.unlist`)),1)]),_:1}),o(x,{label:`public`,value:`public`},{default:m(()=>[i(l(e.$t(`fish.value.public`)),1)]),_:1})]),_:1},8,[`modelValue`])]),n(`div`,Ce,[n(`h2`,we,l(e.$t(`fish.name.trainMode`)),1),o(S,{modelValue:e.form.trainMode,"onUpdate:modelValue":r[6]||=t=>e.form.trainMode=t,size:`small`},{default:m(()=>[o(x,{label:`fast`,value:`fast`},{default:m(()=>[i(l(e.$t(`fish.value.trainModeFast`)),1)]),_:1}),o(x,{label:`precise`,value:`precise`},{default:m(()=>[i(l(e.$t(`fish.value.trainModePrecise`)),1)]),_:1})]),_:1},8,[`modelValue`])]),n(`div`,Te,[n(`div`,Ee,[n(`h2`,De,l(e.$t(`fish.name.enhanceAudio`)),1),o(C,{modelValue:e.form.enhanceAudio,"onUpdate:modelValue":r[7]||=t=>e.form.enhanceAudio=t},null,8,[`modelValue`])]),n(`p`,Oe,l(e.$t(`fish.description.enhanceAudio`)),1)]),n(`div`,ke,[n(`div`,Ae,[n(`h2`,je,l(e.$t(`fish.name.generateSample`)),1),o(C,{modelValue:e.form.generateSample,"onUpdate:modelValue":r[8]||=t=>e.form.generateSample=t},null,8,[`modelValue`])]),n(`p`,Me,l(e.$t(`fish.description.generateSample`)),1)])]),n(`div`,Ne,[o(v,{type:`primary`,class:`btn w-full`,round:``,disabled:!e.canCreate||e.creating,loading:e.creating,onClick:e.onCreate},{default:m(()=>[o(_,{icon:`fa-solid fa-magic`,class:`mr-2`}),i(` `+l(e.$t(`fish.button.createModel`)),1)]),_:1},8,[`disabled`,`loading`,`onClick`])])])}var Fe=w(Q,[[`render`,Pe],[`__scopeId`,`data-v-d8fc0e55`]]),Ie=r({name:`FishVoiceCard`,components:{ElAlert:v,ElButton:h,ElImage:_,CopyToClipboard:k,FontAwesomeIcon:O},props:{modelValue:{type:Object,required:!0}},computed:{sampleAudioUrl(){let e=this.modelValue?.samples;if(e?.length)return e[0]?.audio},voiceId(){let e=this.modelValue;return(e?.id||e?._id||e?.reference_id||``).toString()},coverSrc(){let e=this.modelValue?.cover_image;return e&&typeof e==`string`?e:void 0},createdAtLabel(){let e=this.modelValue?.created_at;if(e==null||e===``)return null;let t=typeof e==`number`?e:parseFloat(String(e));return!Number.isFinite(t)||t<=0?null:this.$dayjs.format(``+new Date(t*1e3))}},methods:{onUseVoice(){let e=this.voiceId;e&&(this.$store.commit(`fish/setConfig`,{...this.$store.state.fish?.config,reference_id:e}),this.$router.push({name:ee}))}}}),Le={class:`card`},Re={class:`left`},ze={class:`main`},Be={class:`header`},Ve={class:`title`},He={key:0,class:`datetime`},Ue={key:0,class:`description`},We={key:1,class:`sample mt-2`},Ge=[`src`],Ke={key:0,class:`text-[var(--el-text-color-regular)] text-xs mb-2`},qe={key:1,class:`text-[var(--el-text-color-regular)] text-xs mb-0`},Je={class:`operations mt-2`};function Ye(e,r,s,c,h,g){let _=p(`el-image`),v=p(`font-awesome-icon`),y=p(`copy-to-clipboard`),b=p(`el-alert`),x=p(`el-button`);return u(),t(`div`,Le,[n(`div`,Re,[e.coverSrc?(u(),a(_,{key:0,src:e.coverSrc,class:`cover`,fit:`cover`},{error:m(()=>[o(_,{src:`https://cdn.acedata.cloud/e40fccc727.png`,class:`cover fallback`,fit:`cover`})]),placeholder:m(()=>[...r[0]||=[n(`div`,{class:`cover placeholder`},null,-1)]]),_:1},8,[`src`])):(u(),a(_,{key:1,src:`https://cdn.acedata.cloud/e40fccc727.png`,class:`cover fallback`,fit:`cover`}))]),n(`div`,ze,[n(`div`,Be,[n(`span`,Ve,l(e.modelValue?.title||e.$t(`fish.name.untitledVoice`)),1),e.createdAtLabel?(u(),t(`span`,He,l(e.createdAtLabel),1)):f(``,!0)]),e.modelValue?.description?(u(),t(`p`,Ue,l(e.modelValue?.description),1)):f(``,!0),e.sampleAudioUrl?(u(),t(`div`,We,[n(`audio`,{src:e.sampleAudioUrl,controls:``,preload:`metadata`,class:`w-full`},null,8,Ge)])):f(``,!0),o(b,{closable:!1,class:`mt-2 success`},{default:m(()=>[e.voiceId?(u(),t(`p`,Ke,[o(v,{icon:`fa-solid fa-microphone`,class:`mr-1`}),i(` `+l(e.$t(`fish.name.referenceId`))+`: `+l(e.voiceId)+` `,1),o(y,{content:e.voiceId},null,8,[`content`])])):f(``,!0),e.modelValue?.visibility?(u(),t(`p`,qe,[o(v,{icon:`fa-solid fa-eye`,class:`mr-1`}),i(` `+l(e.$t(`fish.name.visibility`))+`: `+l(e.modelValue?.visibility),1)])):f(``,!0)]),_:1}),n(`div`,Je,[o(x,{type:`primary`,size:`small`,plain:``,disabled:!e.voiceId,onClick:d(e.onUseVoice,[`stop`])},{default:m(()=>[o(v,{icon:`fa-solid fa-volume-high`,class:`mr-1`}),i(` `+l(e.$t(`fish.button.useVoice`)),1)]),_:1},8,[`disabled`,`onClick`])])])])}var Xe=r({name:`FishModelListPanel`,components:{VoiceCard:w(Ie,[[`render`,Ye],[`__scopeId`,`data-v-629e2d04`]]),BotPlaceholder:A,FontAwesomeIcon:O},props:{loading:{type:Boolean,default:!1}},computed:{voices(){return this.$store.state.fish?.voices}}}),Ze={class:`model-list-panel flex flex-col h-full`},Qe={class:`header`},$e={class:`title`},et={key:0,class:`count`},tt={class:`body flex-1 min-h-0`},$={key:0,class:`h-full`},nt={key:1,class:`w-full h-full flex flex-col items-center justify-center text-center px-6`},rt={class:`empty-title`},it={class:`empty-hint`},at={key:2,class:`w-full h-full overflow-y-auto pr-1`};function ot(r,i,c,d,m,h){let g=p(`bot-placeholder`),_=p(`font-awesome-icon`),v=p(`voice-card`);return u(),t(`div`,Ze,[n(`header`,Qe,[n(`h2`,$e,l(r.$t(`fish.title.myVoices`)),1),r.voices?.length?(u(),t(`span`,et,l(r.voices?.length),1)):f(``,!0)]),n(`div`,tt,[r.voices===void 0?(u(),t(`div`,$,[o(g)])):r.voices.length===0?(u(),t(`div`,nt,[o(_,{icon:`fa-solid fa-microphone-lines`,class:`empty-icon`}),n(`p`,rt,l(r.$t(`fish.title.noVoicesYet`)),1),n(`p`,it,l(r.$t(`fish.description.noVoicesYet`)),1)])):(u(),t(`div`,at,[(u(!0),t(s,null,e(r.voices,e=>(u(),a(v,{key:e.id,"model-value":e},null,8,[`model-value`]))),128))]))])])}var st=r({name:`FishModelIndex`,components:{ModelConfigPanel:Fe,Layout:j,ModelListPanel:w(Xe,[[`render`,ot],[`__scopeId`,`data-v-4aab2294`]]),TabSwitcher:M},inject:[`initialized`],data(){return{loading:!1}},computed:{credential(){return this.$store.state.fish?.credential}},watch:{initialized:{async handler(e){e&&await this.onGetVoices()},immediate:!0}},async mounted(){await this.onGetService()},methods:{async onGetService(){await this.$store.dispatch(`fish/getService`)},async onGetVoices(){await this.$store.dispatch(`fish/getVoices`)},async onCreate(e){let t=this.credential?.token;if(!t){console.error(`no token specified`);return}this.loading=!0,C.info(this.$t(`fish.message.creatingModel`));try{await te.createModel(e,{token:t}),C.success(this.$t(`fish.message.createModelSuccess`)),await this.onGetVoices()}catch(e){let t=e?.response?.data;t?.error?.code===`used_up`?C.error(this.$t(`fish.message.usedUp`)):C.error(t?.error?.message||this.$t(`fish.message.createModelFailed`))}finally{this.loading=!1}}}}),ct={class:`flex flex-col h-full`},lt={class:`flex-1 min-h-0`};function ut(e,t,r,i,s,c){let l=p(`tab-switcher`),d=p(`model-config-panel`),f=p(`model-list-panel`),h=p(`layout`);return u(),a(h,null,{config:m(()=>[n(`div`,ct,[o(l),n(`div`,lt,[o(d,{onCreate:e.onCreate},null,8,[`onCreate`])])])]),result:m(()=>[o(f,{loading:e.loading},null,8,[`loading`])]),_:1})}var dt=w(st,[[`render`,ut]]);export{dt as default};
1
+ import"./rolldown-runtime--c01j_DQ.js";import{$ as e,A as t,D as n,F as r,N as i,O as a,P as o,S as s,Vt as c,Wt as l,Z as u,b as d,k as f,tt as p,ut as m}from"./vendor-chart-BJCvKk8-.js";import{t as h}from"./button-BydTr5nV.js";import{t as g}from"./upload-Djeg64kR.js";import{t as _}from"./image-B-0AtpMP.js";import{t as v}from"./alert-CuX4SjQB.js";import{n as y,r as b}from"./radio-3Hz7h3DR.js";import{t as x}from"./switch-CWjdffRF.js";import{t as S}from"./vendor-axios-Ck2ffRoh.js";import"./constants-HhUTei7L.js";import{Br as C,E as w,Ft as T,Nr as E,Z as ee,en as te,qr as D}from"./index-DPve7EH6.js";import{t as O}from"./index.es-ChPsc2I6.js";import{t as k}from"./CopyToClipboard-B-DcRyL3.js";import{t as A}from"./BotPlaceholder-CxWOpeAr.js";import{t as j}from"./Hailuo-BAPZvzc1.js";import{t as M}from"./TabSwitcher-DvQvtn75.js";var N=4,P=90,F=r({name:`FishRecorder`,components:{ElButton:h,FontAwesomeIcon:O},emits:[`done`,`cancel`,`update:script`],data(){return{state:`idle`,scriptIndex:0,seconds:0,timerId:0,maxTimerId:0,mediaRecorder:null,stream:null,chunks:[],recordedBlob:null,recordedUrl:``,uploading:!1}},computed:{formattedTime(){let e=Math.floor(this.seconds/60),t=this.seconds%60;return`${e.toString().padStart(2,`0`)}:${t.toString().padStart(2,`0`)}`},currentScript(){let e=`fish.script.passage${this.scriptIndex%N+1}`;return this.$t(e)}},beforeUnmount(){this.cleanup()},mounted(){this.$emit(`update:script`,this.currentScript)},methods:{nextScript(){this.scriptIndex=(this.scriptIndex+1)%N,this.$emit(`update:script`,this.currentScript)},async startRecord(){if(!navigator.mediaDevices?.getUserMedia||typeof MediaRecorder>`u`){C.error(this.$t(`fish.message.recorderUnsupported`));return}try{this.stream=await navigator.mediaDevices.getUserMedia({audio:!0})}catch(e){let t=e?.name===`NotAllowedError`||e?.name===`PermissionDeniedError`;C.error(this.$t(t?`fish.message.micDenied`:`fish.message.micError`));return}this.chunks=[];let e=this.pickMimeType();try{this.mediaRecorder=e?new MediaRecorder(this.stream,{mimeType:e}):new MediaRecorder(this.stream)}catch{this.mediaRecorder=new MediaRecorder(this.stream)}this.mediaRecorder.ondataavailable=e=>{e.data&&e.data.size>0&&this.chunks.push(e.data)},this.mediaRecorder.onstop=()=>{let e=new Blob(this.chunks,{type:this.mediaRecorder?.mimeType||`audio/webm`});this.recordedBlob=e,this.recordedUrl=URL.createObjectURL(e),this.state=`recorded`,this.releaseStream()},this.mediaRecorder.start(),this.state=`recording`,this.seconds=0,this.timerId=window.setInterval(()=>{this.seconds++},1e3),this.maxTimerId=window.setTimeout(()=>{this.state===`recording`&&this.stopRecord()},P*1e3)},stopRecord(){this.mediaRecorder&&this.mediaRecorder.state!==`inactive`&&this.mediaRecorder.stop(),window.clearInterval(this.timerId),window.clearTimeout(this.maxTimerId)},reset(){this.recordedUrl&&URL.revokeObjectURL(this.recordedUrl),this.recordedUrl=``,this.recordedBlob=null,this.state=`idle`,this.seconds=0},onCancel(){this.cleanup(),this.$emit(`cancel`)},cleanup(){this.stopRecord(),this.releaseStream(),this.recordedUrl&&URL.revokeObjectURL(this.recordedUrl)},releaseStream(){this.stream?.getTracks().forEach(e=>e.stop()),this.stream=null},pickMimeType(){for(let e of[`audio/webm;codecs=opus`,`audio/webm`,`audio/mp4`,`audio/ogg`])if(typeof MediaRecorder<`u`&&MediaRecorder.isTypeSupported?.(e))return e},extensionForMime(e){return e.includes(`webm`)?`webm`:e.includes(`mp4`)?`m4a`:e.includes(`ogg`)?`ogg`:e.includes(`wav`)?`wav`:`mp3`},async useRecording(){if(this.recordedBlob){if(this.seconds<3){C.warning(this.$t(`fish.message.recordingTooShort`));return}this.uploading=!0;try{let e=this.$store.state.token?.access,t=this.extensionForMime(this.recordedBlob.type||``),n=new File([this.recordedBlob],`recording-${Date.now()}.${t}`,{type:this.recordedBlob.type||`audio/webm`}),r=new FormData;r.append(`file`,n);let{data:i}=await S.post(`${E()}/api/v1/files/`,r,{headers:{Authorization:`Bearer ${e}`}}),a=i?.file_url;if(!a){C.error(this.$t(`fish.message.uploadError`));return}this.$emit(`done`,{url:a,text:this.currentScript})}catch(e){C.error(this.$t(`fish.message.uploadError`)),console.error(`recorder upload failed`,e)}finally{this.uploading=!1}}}}}),I={class:`recorder`},L={key:0,class:`script`},R={class:`script-header`},z={class:`label`},B={class:`script-text`},V={class:`controls`},H={class:`status`},U={class:`hint`},W={key:1,class:`preview`},G=[`src`],K={class:`preview-actions`},q={class:`footer`};function J(e,r,s,d,h,g){let _=p(`font-awesome-icon`),v=p(`el-button`);return u(),t(`div`,I,[e.state===`recorded`?f(``,!0):(u(),t(`div`,L,[n(`div`,R,[o(_,{icon:`fa-solid fa-book-open`,class:`icon mr-1`}),n(`span`,z,l(e.$t(`fish.description.readScript`)),1),o(v,{link:``,size:`small`,class:`ml-auto`,disabled:e.state===`recording`,onClick:e.nextScript},{default:m(()=>[o(_,{icon:`fa-solid fa-shuffle`,class:`mr-1`}),i(` `+l(e.$t(`fish.button.nextScript`)),1)]),_:1},8,[`disabled`,`onClick`])]),n(`p`,B,l(e.currentScript),1)])),n(`div`,V,[e.state===`idle`?(u(),a(v,{key:0,type:`danger`,circle:``,size:`large`,title:e.$t(`fish.button.startRecord`),onClick:e.startRecord},{default:m(()=>[o(_,{icon:`fa-solid fa-microphone`})]),_:1},8,[`title`,`onClick`])):e.state===`recording`?(u(),a(v,{key:1,type:`warning`,circle:``,size:`large`,title:e.$t(`fish.button.stopRecord`),onClick:e.stopRecord},{default:m(()=>[o(_,{icon:`fa-solid fa-stop`})]),_:1},8,[`title`,`onClick`])):f(``,!0),n(`div`,H,[n(`span`,{class:c([`timer`,e.state===`recording`?`live`:``])},l(e.formattedTime),3),n(`span`,U,l(e.state===`idle`?e.$t(`fish.description.recorderIdle`):e.state===`recording`?e.$t(`fish.description.recorderRecording`):e.$t(`fish.description.recorderRecorded`)),1)])]),e.state===`recorded`&&e.recordedUrl?(u(),t(`div`,W,[n(`audio`,{src:e.recordedUrl,controls:``,preload:`metadata`,class:`w-full`},null,8,G),n(`div`,K,[o(v,{size:`small`,disabled:e.uploading,onClick:e.reset},{default:m(()=>[o(_,{icon:`fa-solid fa-rotate-left`,class:`mr-1`}),i(` `+l(e.$t(`fish.button.reRecord`)),1)]),_:1},8,[`disabled`,`onClick`]),o(v,{size:`small`,type:`primary`,loading:e.uploading,onClick:e.useRecording},{default:m(()=>[o(_,{icon:`fa-solid fa-check`,class:`mr-1`}),i(` `+l(e.$t(`fish.button.useRecording`)),1)]),_:1},8,[`loading`,`onClick`])])])):f(``,!0),n(`div`,q,[o(v,{link:``,size:`small`,disabled:e.uploading||e.state===`recording`,onClick:e.onCancel},{default:m(()=>[i(l(e.$t(`fish.button.cancel`)),1)]),_:1},8,[`disabled`,`onClick`])])])}var Y=w(F,[[`render`,J],[`__scopeId`,`data-v-1958e4a1`]]),X=50*1024*1024,Z=()=>({title:``,description:``,texts:``,voicesUrl:``,visibility:`unlist`,trainMode:`fast`,enhanceAudio:!0,generateSample:!1}),Q=r({name:`FishModelConfigPanel`,components:{ElButton:h,ElInput:D,ElRadioButton:y,ElRadioGroup:b,ElSwitch:x,ElUpload:g,FontAwesomeIcon:O,Recorder:Y},mixins:[T],emits:[`create`],data(){return{form:Z(),fileList:[],uploading:!1,creating:!1,recording:!1,textsAuto:!0}},computed:{uploadUrl(){return E()+`/api/v1/files/`},uploadHeaders(){return{Authorization:`Bearer ${this.$store.state.token?.access}`}},canCreate(){return!!this.form.title.trim()&&!!this.form.voicesUrl&&!this.uploading&&!this.creating},supportsRecorder(){return!!(typeof navigator<`u`?navigator.mediaDevices:void 0)?.getUserMedia&&typeof MediaRecorder<`u`}},methods:{onBeforeUpload(e){return e.size>X?(C.warning(this.$t(`fish.message.audioSizeExceed`)),!1):(this.uploading=!0,!0)},onExceed(){C.warning(this.$t(`fish.message.audioOnlyOne`))},onUploadError(){this.uploading=!1,C.error(this.$t(`fish.message.uploadError`))},onUploadSuccess(e,t,n){this.uploading=!1;let r=e?.file_url;if(!r){C.error(this.$t(`fish.message.uploadError`)),this.fileList=[];return}this.form.voicesUrl=r,this.fileList=n},onRecorded(e){this.form.voicesUrl=e.url,this.recording=!1,e.text&&this.textsAuto&&(this.form.texts=e.text)},onStartRecord(){this.recording=!0,this.textsAuto=!this.form.texts.trim()},onScriptChange(e){this.textsAuto&&this.recording&&(this.form.texts=e)},onTextsInput(){this.textsAuto=!1},clearAudio(){this.form.voicesUrl=``,this.fileList=[]},onCreate(){let e=this.form.title.trim();if(!e){C.warning(this.$t(`fish.message.titleRequired`));return}if(!this.form.voicesUrl){C.warning(this.$t(`fish.message.audioRequired`));return}let t={title:e,voices:this.form.voicesUrl,visibility:this.form.visibility,train_mode:this.form.trainMode,enhance_audio_quality:this.form.enhanceAudio,generate_sample:this.form.generateSample};this.form.description.trim()&&(t.description=this.form.description.trim()),this.form.texts.trim()&&(t.texts=[this.form.texts.trim()]),this.creating=!0,this.$emit(`create`,t),setTimeout(()=>{this.creating=!1,this.form=Z(),this.fileList=[]},600)}}}),ne={class:`flex flex-col h-full`},re={class:`flex-1 overflow-y-auto p-5`},ie={class:`field-block mb-4`},ae={class:`title font-bold`},oe={class:`field-block mb-4`},se={class:`flex items-baseline justify-between mb-1`},ce={class:`title font-bold`},le={key:0,class:`muted`},ue={class:`hint`},de={key:0,class:`audio-actions`},fe={key:1,class:`hint warn`},pe={key:3,class:`mt-2`},me=[`src`],he={class:`ready-actions`},ge={class:`field-block mb-4`},_e={class:`title font-bold`},ve={class:`hint`},ye={class:`field-block mb-4`},be={class:`title font-bold`},xe={class:`field-block mb-4`},Se={class:`title font-bold`},Ce={class:`field-block mb-4`},we={class:`title font-bold`},Te={class:`field-block mb-3`},Ee={class:`field-row`},De={class:`title font-bold`},Oe={class:`hint mt-0 mb-0`},ke={class:`field-block mb-2`},Ae={class:`field-row`},je={class:`title font-bold`},Me={class:`hint mt-0 mb-0`},Ne={class:`flex flex-col items-center justify-center px-5 pb-5`};function Pe(e,r,s,c,d,h){let g=p(`el-input`),_=p(`font-awesome-icon`),v=p(`el-button`),y=p(`el-upload`),b=p(`recorder`),x=p(`el-radio-button`),S=p(`el-radio-group`),C=p(`el-switch`);return u(),t(`div`,ne,[n(`div`,re,[n(`div`,ie,[n(`h2`,ae,[i(l(e.$t(`fish.name.voiceTitle`))+` `,1),r[9]||=n(`span`,{class:`required`},`*`,-1)]),o(g,{modelValue:e.form.title,"onUpdate:modelValue":r[0]||=t=>e.form.title=t,placeholder:e.$t(`fish.placeholder.voiceTitle`),maxlength:`60`},null,8,[`modelValue`,`placeholder`])]),n(`div`,oe,[n(`div`,se,[n(`h2`,ce,[i(l(e.$t(`fish.name.referenceAudio`))+` `,1),r[10]||=n(`span`,{class:`required`},`*`,-1)]),!e.form.voicesUrl&&!e.recording?(u(),t(`span`,le,l(e.$t(`fish.description.audioRequired`)),1)):f(``,!0)]),n(`p`,ue,l(e.$t(`fish.description.uploadAudio`)),1),!e.form.voicesUrl&&!e.recording?(u(),t(`div`,de,[o(y,{"file-list":e.fileList,"onUpdate:fileList":r[1]||=t=>e.fileList=t,name:`file`,limit:1,class:`upload-wrapper`,action:e.uploadUrl,accept:`.mp3,.wav,.m4a,.ogg,.webm,audio/*`,"show-file-list":!1,"on-exceed":e.onExceed,"on-error":e.onUploadError,"on-success":e.onUploadSuccess,"before-upload":e.onBeforeUpload,headers:e.uploadHeaders},{default:m(()=>[o(v,{type:`primary`,plain:``,round:``,loading:e.uploading},{default:m(()=>[o(_,{icon:`fa-solid fa-upload`,class:`icon mr-1`}),i(` `+l(e.$t(`fish.button.uploadAudio`)),1)]),_:1},8,[`loading`])]),_:1},8,[`file-list`,`action`,`on-exceed`,`on-error`,`on-success`,`before-upload`,`headers`]),o(v,{type:`primary`,round:``,disabled:!e.supportsRecorder,onClick:e.onStartRecord},{default:m(()=>[o(_,{icon:`fa-solid fa-microphone`,class:`icon mr-1`}),i(` `+l(e.$t(`fish.button.recordAudio`)),1)]),_:1},8,[`disabled`,`onClick`])])):f(``,!0),!e.supportsRecorder&&!e.form.voicesUrl&&!e.recording?(u(),t(`p`,fe,l(e.$t(`fish.message.recorderUnsupported`)),1)):f(``,!0),e.recording?(u(),a(b,{key:2,class:`mt-2`,onDone:e.onRecorded,onCancel:r[2]||=t=>e.recording=!1,"onUpdate:script":e.onScriptChange},null,8,[`onDone`,`onUpdate:script`])):f(``,!0),e.form.voicesUrl&&!e.recording?(u(),t(`div`,pe,[n(`audio`,{src:e.form.voicesUrl,controls:``,preload:`metadata`,class:`w-full`},null,8,me),n(`div`,he,[o(v,{link:``,size:`small`,onClick:e.clearAudio},{default:m(()=>[o(_,{icon:`fa-solid fa-rotate-left`,class:`mr-1`}),i(` `+l(e.$t(`fish.button.replaceAudio`)),1)]),_:1},8,[`onClick`])])])):f(``,!0)]),n(`div`,ge,[n(`h2`,_e,l(e.$t(`fish.name.audioTexts`)),1),n(`p`,ve,l(e.$t(`fish.description.audioTexts`)),1),o(g,{modelValue:e.form.texts,"onUpdate:modelValue":r[3]||=t=>e.form.texts=t,type:`textarea`,rows:2,placeholder:e.$t(`fish.placeholder.audioTexts`),maxlength:`500`,onInput:e.onTextsInput},null,8,[`modelValue`,`placeholder`,`onInput`])]),n(`div`,ye,[n(`h2`,be,l(e.$t(`fish.name.voiceDescription`)),1),o(g,{modelValue:e.form.description,"onUpdate:modelValue":r[4]||=t=>e.form.description=t,type:`textarea`,rows:2,placeholder:e.$t(`fish.placeholder.voiceDescription`),maxlength:`500`},null,8,[`modelValue`,`placeholder`])]),n(`div`,xe,[n(`h2`,Se,l(e.$t(`fish.name.visibility`)),1),o(S,{modelValue:e.form.visibility,"onUpdate:modelValue":r[5]||=t=>e.form.visibility=t,size:`small`},{default:m(()=>[o(x,{label:`private`,value:`private`},{default:m(()=>[i(l(e.$t(`fish.value.private`)),1)]),_:1}),o(x,{label:`unlist`,value:`unlist`},{default:m(()=>[i(l(e.$t(`fish.value.unlist`)),1)]),_:1}),o(x,{label:`public`,value:`public`},{default:m(()=>[i(l(e.$t(`fish.value.public`)),1)]),_:1})]),_:1},8,[`modelValue`])]),n(`div`,Ce,[n(`h2`,we,l(e.$t(`fish.name.trainMode`)),1),o(S,{modelValue:e.form.trainMode,"onUpdate:modelValue":r[6]||=t=>e.form.trainMode=t,size:`small`},{default:m(()=>[o(x,{label:`fast`,value:`fast`},{default:m(()=>[i(l(e.$t(`fish.value.trainModeFast`)),1)]),_:1}),o(x,{label:`precise`,value:`precise`},{default:m(()=>[i(l(e.$t(`fish.value.trainModePrecise`)),1)]),_:1})]),_:1},8,[`modelValue`])]),n(`div`,Te,[n(`div`,Ee,[n(`h2`,De,l(e.$t(`fish.name.enhanceAudio`)),1),o(C,{modelValue:e.form.enhanceAudio,"onUpdate:modelValue":r[7]||=t=>e.form.enhanceAudio=t},null,8,[`modelValue`])]),n(`p`,Oe,l(e.$t(`fish.description.enhanceAudio`)),1)]),n(`div`,ke,[n(`div`,Ae,[n(`h2`,je,l(e.$t(`fish.name.generateSample`)),1),o(C,{modelValue:e.form.generateSample,"onUpdate:modelValue":r[8]||=t=>e.form.generateSample=t},null,8,[`modelValue`])]),n(`p`,Me,l(e.$t(`fish.description.generateSample`)),1)])]),n(`div`,Ne,[o(v,{type:`primary`,class:`btn w-full`,round:``,disabled:!e.canCreate||e.creating,loading:e.creating,onClick:e.onCreate},{default:m(()=>[o(_,{icon:`fa-solid fa-magic`,class:`mr-2`}),i(` `+l(e.$t(`fish.button.createModel`)),1)]),_:1},8,[`disabled`,`loading`,`onClick`])])])}var Fe=w(Q,[[`render`,Pe],[`__scopeId`,`data-v-d8fc0e55`]]),Ie=r({name:`FishVoiceCard`,components:{ElAlert:v,ElButton:h,ElImage:_,CopyToClipboard:k,FontAwesomeIcon:O},props:{modelValue:{type:Object,required:!0}},computed:{sampleAudioUrl(){let e=this.modelValue?.samples;if(e?.length)return e[0]?.audio},voiceId(){let e=this.modelValue;return(e?.id||e?._id||e?.reference_id||``).toString()},coverSrc(){let e=this.modelValue?.cover_image;return e&&typeof e==`string`?e:void 0},createdAtLabel(){let e=this.modelValue?.created_at;if(e==null||e===``)return null;let t=typeof e==`number`?e:parseFloat(String(e));return!Number.isFinite(t)||t<=0?null:this.$dayjs.format(``+new Date(t*1e3))}},methods:{onUseVoice(){let e=this.voiceId;e&&(this.$store.commit(`fish/setConfig`,{...this.$store.state.fish?.config,reference_id:e}),this.$router.push({name:ee}))}}}),Le={class:`card`},Re={class:`left`},ze={class:`main`},Be={class:`header`},Ve={class:`title`},He={key:0,class:`datetime`},Ue={key:0,class:`description`},We={key:1,class:`sample mt-2`},Ge=[`src`],Ke={key:0,class:`text-[var(--el-text-color-regular)] text-xs mb-2`},qe={key:1,class:`text-[var(--el-text-color-regular)] text-xs mb-0`},Je={class:`operations mt-2`};function Ye(e,r,s,c,h,g){let _=p(`el-image`),v=p(`font-awesome-icon`),y=p(`copy-to-clipboard`),b=p(`el-alert`),x=p(`el-button`);return u(),t(`div`,Le,[n(`div`,Re,[e.coverSrc?(u(),a(_,{key:0,src:e.coverSrc,class:`cover`,fit:`cover`},{error:m(()=>[o(_,{src:`https://cdn.acedata.cloud/e40fccc727.png`,class:`cover fallback`,fit:`cover`})]),placeholder:m(()=>[...r[0]||=[n(`div`,{class:`cover placeholder`},null,-1)]]),_:1},8,[`src`])):(u(),a(_,{key:1,src:`https://cdn.acedata.cloud/e40fccc727.png`,class:`cover fallback`,fit:`cover`}))]),n(`div`,ze,[n(`div`,Be,[n(`span`,Ve,l(e.modelValue?.title||e.$t(`fish.name.untitledVoice`)),1),e.createdAtLabel?(u(),t(`span`,He,l(e.createdAtLabel),1)):f(``,!0)]),e.modelValue?.description?(u(),t(`p`,Ue,l(e.modelValue?.description),1)):f(``,!0),e.sampleAudioUrl?(u(),t(`div`,We,[n(`audio`,{src:e.sampleAudioUrl,controls:``,preload:`metadata`,class:`w-full`},null,8,Ge)])):f(``,!0),o(b,{closable:!1,class:`mt-2 success`},{default:m(()=>[e.voiceId?(u(),t(`p`,Ke,[o(v,{icon:`fa-solid fa-microphone`,class:`mr-1`}),i(` `+l(e.$t(`fish.name.referenceId`))+`: `+l(e.voiceId)+` `,1),o(y,{content:e.voiceId},null,8,[`content`])])):f(``,!0),e.modelValue?.visibility?(u(),t(`p`,qe,[o(v,{icon:`fa-solid fa-eye`,class:`mr-1`}),i(` `+l(e.$t(`fish.name.visibility`))+`: `+l(e.modelValue?.visibility),1)])):f(``,!0)]),_:1}),n(`div`,Je,[o(x,{type:`primary`,size:`small`,plain:``,disabled:!e.voiceId,onClick:d(e.onUseVoice,[`stop`])},{default:m(()=>[o(v,{icon:`fa-solid fa-volume-high`,class:`mr-1`}),i(` `+l(e.$t(`fish.button.useVoice`)),1)]),_:1},8,[`disabled`,`onClick`])])])])}var Xe=r({name:`FishModelListPanel`,components:{VoiceCard:w(Ie,[[`render`,Ye],[`__scopeId`,`data-v-629e2d04`]]),BotPlaceholder:A,FontAwesomeIcon:O},props:{loading:{type:Boolean,default:!1}},computed:{voices(){return this.$store.state.fish?.voices}}}),Ze={class:`model-list-panel flex flex-col h-full`},Qe={class:`header`},$e={class:`title`},et={key:0,class:`count`},tt={class:`body flex-1 min-h-0`},$={key:0,class:`h-full`},nt={key:1,class:`w-full h-full flex flex-col items-center justify-center text-center px-6`},rt={class:`empty-title`},it={class:`empty-hint`},at={key:2,class:`w-full h-full overflow-y-auto pr-1`};function ot(r,i,c,d,m,h){let g=p(`bot-placeholder`),_=p(`font-awesome-icon`),v=p(`voice-card`);return u(),t(`div`,Ze,[n(`header`,Qe,[n(`h2`,$e,l(r.$t(`fish.title.myVoices`)),1),r.voices?.length?(u(),t(`span`,et,l(r.voices?.length),1)):f(``,!0)]),n(`div`,tt,[r.voices===void 0?(u(),t(`div`,$,[o(g)])):r.voices.length===0?(u(),t(`div`,nt,[o(_,{icon:`fa-solid fa-microphone-lines`,class:`empty-icon`}),n(`p`,rt,l(r.$t(`fish.title.noVoicesYet`)),1),n(`p`,it,l(r.$t(`fish.description.noVoicesYet`)),1)])):(u(),t(`div`,at,[(u(!0),t(s,null,e(r.voices,e=>(u(),a(v,{key:e.id,"model-value":e},null,8,[`model-value`]))),128))]))])])}var st=r({name:`FishModelIndex`,components:{ModelConfigPanel:Fe,Layout:j,ModelListPanel:w(Xe,[[`render`,ot],[`__scopeId`,`data-v-4aab2294`]]),TabSwitcher:M},inject:[`initialized`],data(){return{loading:!1}},computed:{credential(){return this.$store.state.fish?.credential}},watch:{initialized:{async handler(e){e&&await this.onGetVoices()},immediate:!0}},async mounted(){await this.onGetService()},methods:{async onGetService(){await this.$store.dispatch(`fish/getService`)},async onGetVoices(){await this.$store.dispatch(`fish/getVoices`)},async onCreate(e){let t=this.credential?.token;if(!t){console.error(`no token specified`);return}this.loading=!0,C.info(this.$t(`fish.message.creatingModel`));try{await te.createModel(e,{token:t}),C.success(this.$t(`fish.message.createModelSuccess`)),await this.onGetVoices()}catch(e){let t=e?.response?.data;t?.error?.code===`used_up`?C.error(this.$t(`fish.message.usedUp`)):C.error(t?.error?.message||this.$t(`fish.message.createModelFailed`))}finally{this.loading=!1}}}}),ct={class:`flex flex-col h-full`},lt={class:`flex-1 min-h-0`};function ut(e,t,r,i,s,c){let l=p(`tab-switcher`),d=p(`model-config-panel`),f=p(`model-list-panel`),h=p(`layout`);return u(),a(h,null,{config:m(()=>[n(`div`,ct,[o(l),n(`div`,lt,[o(d,{onCreate:e.onCreate},null,8,[`onCreate`])])])]),result:m(()=>[o(f,{loading:e.loading},null,8,[`loading`])]),_:1})}var dt=w(st,[[`render`,ut]]);export{dt as default};