mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-11-07 23:30:26 +08:00
支持批量添加域名、域名修改
This commit is contained in:
@@ -4,6 +4,8 @@ import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type AddServerNamePopupAction struct {
|
||||
@@ -19,17 +21,43 @@ func (this *AddServerNamePopupAction) RunGet(params struct{}) {
|
||||
}
|
||||
|
||||
func (this *AddServerNamePopupAction) RunPost(params struct {
|
||||
Mode string
|
||||
|
||||
ServerName string
|
||||
ServerNames string
|
||||
|
||||
Must *actions.Must
|
||||
}) {
|
||||
if params.Mode == "single" {
|
||||
params.Must.
|
||||
Field("serverName", params.ServerName).
|
||||
Require("请输入域名")
|
||||
|
||||
this.Data["serverName"] = maps.Map{
|
||||
"name": params.ServerName,
|
||||
"type": "full",
|
||||
}
|
||||
} else if params.Mode == "multiple" {
|
||||
if len(params.ServerNames) == 0 {
|
||||
this.FailField("serverNames", "请输入至少域名")
|
||||
}
|
||||
|
||||
serverNames := []string{}
|
||||
for _, line := range strings.Split(params.ServerNames, "\n") {
|
||||
line := strings.TrimSpace(line)
|
||||
line = regexp.MustCompile(`\s+`).ReplaceAllString(line, "")
|
||||
if len(line) == 0 {
|
||||
continue
|
||||
}
|
||||
serverNames = append(serverNames, line)
|
||||
}
|
||||
this.Data["serverName"] = maps.Map{
|
||||
"name": "",
|
||||
"type": "full",
|
||||
"subNames": serverNames,
|
||||
}
|
||||
} else {
|
||||
this.Fail("错误的mode参数")
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ Vue.component("server-name-box", {
|
||||
},
|
||||
methods: {
|
||||
addServerName: function () {
|
||||
window.UPDATING_SERVER_NAME = null
|
||||
let that = this
|
||||
teaweb.popup("/servers/addServerNamePopup", {
|
||||
callback: function (resp) {
|
||||
@@ -22,13 +23,27 @@ Vue.component("server-name-box", {
|
||||
|
||||
removeServerName: function (index) {
|
||||
this.serverNames.$remove(index)
|
||||
},
|
||||
|
||||
updateServerName: function (index, serverName) {
|
||||
window.UPDATING_SERVER_NAME = serverName
|
||||
let that = this
|
||||
teaweb.popup("/servers/addServerNamePopup", {
|
||||
callback: function (resp) {
|
||||
var serverName = resp.data.serverName
|
||||
Vue.set(that.serverNames, index, serverName)
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
template: `<div>
|
||||
<input type="hidden" name="serverNames" :value="JSON.stringify(serverNames)"/>
|
||||
<div v-if="serverNames.length > 0">
|
||||
<div v-for="(serverName, index) in serverNames" class="ui label small">
|
||||
<em v-if="serverName.type != 'full'">{{serverName.type}}</em> {{serverName.name}} <a href="" title="删除" @click.prevent="removeServerName(index)"><i class="icon remove"></i></a>
|
||||
<em v-if="serverName.type != 'full'">{{serverName.type}}</em>
|
||||
<span v-if="serverName.subNames == null || serverName.subNames.length == 0">{{serverName.name}}</span>
|
||||
<span v-else>{{serverName.subNames[0]}}等{{serverName.subNames.length}}个域名</span>
|
||||
<a href="" title="修改" @click.prevent="updateServerName(index, serverName)"><i class="icon pencil small"></i></a> <a href="" title="删除" @click.prevent="removeServerName(index)"><i class="icon remove"></i></a>
|
||||
</div>
|
||||
<div class="ui divider"></div>
|
||||
</div>
|
||||
|
||||
@@ -1,14 +1,24 @@
|
||||
{$layout "layout_popup"}
|
||||
|
||||
<h3>添加域名绑定</h3>
|
||||
<h3 v-if="!isUpdating">添加域名绑定</h3>
|
||||
<h3 v-if="isUpdating">修改域名绑定</h3>
|
||||
<form class="ui form" data-tea-action="$" data-tea-success="success">
|
||||
<input type="hidden" name="mode" :value="mode"/>
|
||||
<table class="ui table selectable definition">
|
||||
<tr>
|
||||
<td class="title">域名</td>
|
||||
<tr v-if="mode == 'single'">
|
||||
<td class="title">单个域名</td>
|
||||
<td>
|
||||
<input type="text" name="serverName" ref="focus"/>
|
||||
<input type="text" name="serverName" ref="focus" maxlength="1024" v-model="serverName.name"/>
|
||||
<p class="comment">请输入单个域名。</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr v-if="mode == 'multiple'">
|
||||
<td class="title">多个域名</td>
|
||||
<td>
|
||||
<textarea name="serverNames" ref="serverNames" v-model="multipleServerNames"></textarea>
|
||||
<p class="comment">每行一个域名。</p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<submit-btn></submit-btn>
|
||||
<submit-btn></submit-btn> <a href="" v-if="mode == 'single'" @click.prevent="switchMode('multiple')">批量添加</a><a href="" v-if="mode == 'multiple'" @click.prevent="switchMode('single')">单个添加</a>
|
||||
</form>
|
||||
@@ -1,3 +1,29 @@
|
||||
Tea.context(function () {
|
||||
this.success = NotifyPopup;
|
||||
this.isUpdating = false
|
||||
this.mode = "single" // single|multiple
|
||||
this.serverName = {
|
||||
name: "",
|
||||
subNames: []
|
||||
}
|
||||
this.multipleServerNames = ""
|
||||
if (window.parent.UPDATING_SERVER_NAME != null) {
|
||||
this.isUpdating = true
|
||||
this.serverName = window.parent.UPDATING_SERVER_NAME
|
||||
if (this.serverName.subNames != null && this.serverName.subNames.length > 0) {
|
||||
this.mode = "multiple"
|
||||
this.multipleServerNames = this.serverName.subNames.join("\n")
|
||||
}
|
||||
}
|
||||
|
||||
this.switchMode = function (mode) {
|
||||
this.mode = mode
|
||||
this.$delay(function () {
|
||||
if (mode == "single") {
|
||||
this.$refs.focus.focus()
|
||||
} else {
|
||||
this.$refs.serverNames.focus()
|
||||
}
|
||||
})
|
||||
}
|
||||
});
|
||||
@@ -53,7 +53,8 @@
|
||||
<td>{{server.cluster.name}}</td>
|
||||
<td>
|
||||
<div v-for="serverName in server.serverNames">
|
||||
<tiny-label>{{serverName.name}}</tiny-label>
|
||||
<tiny-label v-if="serverName.subNames == null || serverName.subNames.length == 0">{{serverName.name}}</tiny-label>
|
||||
<tiny-label v-else>{{serverName.subNames[0]}}等{{serverName.subNames.length}}个域名</tiny-label>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
|
||||
Reference in New Issue
Block a user