diff --git a/web/controller/inbound.go b/web/controller/inbound.go index a7410b04..471a693b 100644 --- a/web/controller/inbound.go +++ b/web/controller/inbound.go @@ -56,8 +56,8 @@ func (a *InboundController) initRouter(g *gin.RouterGroup) { } type CopyInboundClientsRequest struct { - SourceInboundID int `json:"sourceInboundId"` - ClientEmails []string `json:"clientEmails"` + SourceInboundID int `form:"sourceInboundId" json:"sourceInboundId"` + ClientEmails []string `form:"clientEmails" json:"clientEmails"` } // getInbounds retrieves the list of inbounds for the logged-in user. @@ -275,7 +275,7 @@ func (a *InboundController) copyInboundClients(c *gin.Context) { } req := &CopyInboundClientsRequest{} - err = c.ShouldBindJSON(req) + err = c.ShouldBind(req) if err != nil { jsonMsg(c, I18nWeb(c, "somethingWentWrong"), err) return diff --git a/web/html/inbounds.html b/web/html/inbounds.html index 966cc90f..d3e423a2 100644 --- a/web/html/inbounds.html +++ b/web/html/inbounds.html @@ -788,8 +788,10 @@ ok-text='{{ i18n "pages.client.copySelected" }}' cancel-text='{{ i18n "close" }}' :class="themeSwitcher.currentTheme" - @ok="copyClientsModal.ok" - @cancel="copyClientsModal.close" + :closable="true" + :mask-closable="false" + @ok="() => copyClientsModal.ok()" + @cancel="() => copyClientsModal.close()" width="900px">
@@ -797,7 +799,7 @@ + @change="id => copyClientsModal.onSourceChange(id)"> @@ -805,10 +807,10 @@
-
+
- {{ i18n "pages.client.selectAll" }} - {{ i18n "pages.client.clearAll" }} + {{ i18n "pages.client.selectAll" }} + {{ i18n "pages.client.clearAll" }} row.id === sourceInboundId); + copyClientsModal.selectedEmails = []; + const sourceInbound = app.dbInbounds.find(row => row.id === Number(sourceInboundId)); if (!sourceInbound) { - this.sourceClients = []; - this.selectedEmails = []; + copyClientsModal.sourceClients = []; return; } const sourceClients = app.getInboundClients(sourceInbound) || []; - this.sourceClients = sourceClients.map(client => { + copyClientsModal.sourceClients = sourceClients.map(client => { const stats = app.getClientStats(sourceInbound, client.email); - const used = stats ? (stats.up + stats.down) : 0; + const used = stats ? ((stats.up || 0) + (stats.down || 0)) : 0; + let expiryLabel = '{{ i18n "unlimited" }}'; + if (client.expiryTime > 0) { + expiryLabel = IntlUtil.formatDate(client.expiryTime); + } else if (client.expiryTime < 0) { + expiryLabel = `${-client.expiryTime / 86400000}d`; + } return { email: client.email, trafficLabel: SizeFormatter.sizeFormat(used), - expiryLabel: client.expiryTime > 0 ? IntlUtil.formatDate(client.expiryTime) : '{{ i18n "unlimited" }}', + expiryLabel, }; }); - this.selectedEmails = []; }, toggleEmail(email, checked) { - const selected = this.selectedEmails.slice(); + const selected = copyClientsModal.selectedEmails.slice(); if (checked) { if (!selected.includes(email)) selected.push(email); } else { const idx = selected.indexOf(email); if (idx >= 0) selected.splice(idx, 1); } - this.selectedEmails = selected; + copyClientsModal.selectedEmails = selected; }, selectAll() { - this.selectedEmails = this.sourceClients.map(item => item.email); + copyClientsModal.selectedEmails = copyClientsModal.sourceClients.map(item => item.email); }, clearAll() { - this.selectedEmails = []; + copyClientsModal.selectedEmails = []; }, async ok() { if (!copyClientsModal.sourceInboundId) { @@ -918,16 +925,19 @@ sourceInboundId: copyClientsModal.sourceInboundId, clientEmails: copyClientsModal.selectedEmails, }; - const msg = await HttpUtil.post(`/panel/api/inbounds/${copyClientsModal.targetInboundId}/copyClients`, payload); - copyClientsModal.confirmLoading = false; - if (!msg.success) return; - const obj = msg.obj || {}; - const addedCount = (obj.added || []).length; - const skippedCount = (obj.skipped || []).length; - const errorCount = (obj.errors || []).length; - app.$message.success(`{{ i18n "pages.client.copyResult" }}: +${addedCount}, ~${skippedCount}, !${errorCount}`); - copyClientsModal.close(); - await app.getDBInbounds(); + try { + const msg = await HttpUtil.post(`/panel/api/inbounds/${copyClientsModal.targetInboundId}/copyClients`, payload); + if (!msg || !msg.success) return; + const obj = msg.obj || {}; + const addedCount = (obj.added || []).length; + const skippedCount = (obj.skipped || []).length; + const errorCount = (obj.errors || []).length; + app.$message.success(`{{ i18n "pages.client.copyResult" }}: +${addedCount}, ~${skippedCount}, !${errorCount}`); + copyClientsModal.close(); + await app.getDBInbounds(); + } finally { + copyClientsModal.confirmLoading = false; + } }, };