mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-11-07 23:30:26 +08:00
优化代码
This commit is contained in:
@@ -4,7 +4,6 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
"github.com/iwind/TeaGo/lists"
|
|
||||||
timeutil "github.com/iwind/TeaGo/utils/time"
|
timeutil "github.com/iwind/TeaGo/utils/time"
|
||||||
"github.com/tealeg/xlsx/v3"
|
"github.com/tealeg/xlsx/v3"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -69,17 +68,13 @@ func (this *ExportExcelAction) RunGet(params struct {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if regionResp.IpRegion != nil {
|
if regionResp.IpRegion != nil {
|
||||||
pieces := []string{}
|
regionName = regionResp.IpRegion.Summary
|
||||||
if len(regionResp.IpRegion.Country) > 0 {
|
|
||||||
pieces = append(pieces, regionResp.IpRegion.Country)
|
// remove isp from regionName
|
||||||
|
var index = strings.LastIndex(regionName, "|")
|
||||||
|
if index > 0 {
|
||||||
|
regionName = regionName[:index]
|
||||||
}
|
}
|
||||||
if len(regionResp.IpRegion.Province) > 0 && !lists.ContainsString(pieces, regionResp.IpRegion.Province) {
|
|
||||||
pieces = append(pieces, regionResp.IpRegion.Province)
|
|
||||||
}
|
|
||||||
if len(regionResp.IpRegion.City) > 0 && !lists.ContainsString(pieces, regionResp.IpRegion.City) && !lists.ContainsString(pieces, strings.TrimSuffix(regionResp.IpRegion.Province, "市")) {
|
|
||||||
pieces = append(pieces, regionResp.IpRegion.City)
|
|
||||||
}
|
|
||||||
regionName = strings.Join(pieces, " ")
|
|
||||||
|
|
||||||
if len(regionResp.IpRegion.Isp) > 0 {
|
if len(regionResp.IpRegion.Isp) > 0 {
|
||||||
ispName = regionResp.IpRegion.Isp
|
ispName = regionResp.IpRegion.Isp
|
||||||
|
|||||||
@@ -4,10 +4,8 @@ import (
|
|||||||
"github.com/TeaOSLab/EdgeAdmin/internal/configloaders"
|
"github.com/TeaOSLab/EdgeAdmin/internal/configloaders"
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
"github.com/iwind/TeaGo/lists"
|
|
||||||
"github.com/iwind/TeaGo/maps"
|
"github.com/iwind/TeaGo/maps"
|
||||||
timeutil "github.com/iwind/TeaGo/utils/time"
|
timeutil "github.com/iwind/TeaGo/utils/time"
|
||||||
"strings"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type IndexAction struct {
|
type IndexAction struct {
|
||||||
@@ -72,11 +70,7 @@ func (this *IndexAction) RunGet(params struct {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if regionResp.IpRegion != nil {
|
if regionResp.IpRegion != nil {
|
||||||
pieces := []string{regionResp.IpRegion.Summary}
|
regionName = regionResp.IpRegion.Summary
|
||||||
if len(regionResp.IpRegion.Isp) > 0 && !lists.ContainsString(pieces, regionResp.IpRegion.Isp) {
|
|
||||||
pieces = append(pieces, "| "+regionResp.IpRegion.Isp)
|
|
||||||
}
|
|
||||||
regionName = strings.Join(pieces, " ")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
logMaps = append(logMaps, maps.Map{
|
logMaps = append(logMaps, maps.Map{
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import (
|
|||||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
"github.com/iwind/TeaGo/maps"
|
"github.com/iwind/TeaGo/maps"
|
||||||
timeutil "github.com/iwind/TeaGo/utils/time"
|
timeutil "github.com/iwind/TeaGo/utils/time"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -30,7 +31,14 @@ func (this *IndexAction) RunGet(params struct {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if regionResp.IpRegion != nil {
|
if regionResp.IpRegion != nil {
|
||||||
this.Data["regions"] = regionResp.IpRegion.Summary
|
var regionName = regionResp.IpRegion.Summary
|
||||||
|
|
||||||
|
// remove isp from regionName
|
||||||
|
var index = strings.LastIndex(regionName, "|")
|
||||||
|
if index > 0 {
|
||||||
|
regionName = regionName[:index]
|
||||||
|
}
|
||||||
|
this.Data["regions"] = regionName
|
||||||
} else {
|
} else {
|
||||||
this.Data["regions"] = ""
|
this.Data["regions"] = ""
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/firewallconfigs"
|
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/firewallconfigs"
|
||||||
"github.com/iwind/TeaGo/maps"
|
"github.com/iwind/TeaGo/maps"
|
||||||
timeutil "github.com/iwind/TeaGo/utils/time"
|
timeutil "github.com/iwind/TeaGo/utils/time"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -165,6 +166,13 @@ func (this *IndexAction) RunGet(params struct {
|
|||||||
var ipRegion = regionResp.IpRegion
|
var ipRegion = regionResp.IpRegion
|
||||||
if ipRegion != nil {
|
if ipRegion != nil {
|
||||||
region = ipRegion.Summary
|
region = ipRegion.Summary
|
||||||
|
|
||||||
|
// remove isp from regionName
|
||||||
|
var index = strings.LastIndex(region, "|")
|
||||||
|
if index > 0 {
|
||||||
|
region = region[:index]
|
||||||
|
}
|
||||||
|
|
||||||
isp = ipRegion.Isp
|
isp = ipRegion.Isp
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/firewallconfigs"
|
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/firewallconfigs"
|
||||||
"github.com/iwind/TeaGo/maps"
|
"github.com/iwind/TeaGo/maps"
|
||||||
timeutil "github.com/iwind/TeaGo/utils/time"
|
timeutil "github.com/iwind/TeaGo/utils/time"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -116,6 +117,13 @@ func (this *ItemsAction) RunGet(params struct {
|
|||||||
var ipRegion = regionResp.IpRegion
|
var ipRegion = regionResp.IpRegion
|
||||||
if ipRegion != nil {
|
if ipRegion != nil {
|
||||||
region = ipRegion.Summary
|
region = ipRegion.Summary
|
||||||
|
|
||||||
|
// remove isp from regionName
|
||||||
|
var index = strings.LastIndex(region, "|")
|
||||||
|
if index > 0 {
|
||||||
|
region = region[:index]
|
||||||
|
}
|
||||||
|
|
||||||
isp = ipRegion.Isp
|
isp = ipRegion.Isp
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -93,8 +93,16 @@ func (this *ViewPopupAction) RunGet(params struct {
|
|||||||
}
|
}
|
||||||
region := regionResp.IpRegion
|
region := regionResp.IpRegion
|
||||||
if region != nil {
|
if region != nil {
|
||||||
|
var regionName = region.Summary
|
||||||
|
|
||||||
|
// remove isp from regionName
|
||||||
|
var index = strings.LastIndex(regionName, "|")
|
||||||
|
if index > 0 {
|
||||||
|
regionName = regionName[:index]
|
||||||
|
}
|
||||||
|
|
||||||
regionMap = maps.Map{
|
regionMap = maps.Map{
|
||||||
"full": region.Summary,
|
"full": regionName,
|
||||||
"isp": region.Isp,
|
"isp": region.Isp,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4325,7 +4325,7 @@ Vue.component("traffic-map-box",{props:["v-stats","v-is-attack"],mounted:functio
|
|||||||
<tr>
|
<tr>
|
||||||
<td colspan="2"><a href="" @click.prevent="show()"><span v-if="!isVisible">更多选项</span><span v-if="isVisible">收起选项</span><i class="icon angle" :class="{down:!isVisible, up:isVisible}"></i></a></td>
|
<td colspan="2"><a href="" @click.prevent="show()"><span v-if="!isVisible">更多选项</span><span v-if="isVisible">收起选项</span><i class="icon angle" :class="{down:!isVisible, up:isVisible}"></i></a></td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>`}),Vue.component("download-link",{props:["v-element","v-file","v-value"],created:function(){let e=this;setTimeout(function(){e.url=e.composeURL()},1e3)},data:function(){let e=this.vFile;return{file:e=null!=e&&0!=e.length?e:"unknown-file",url:this.composeURL()}},methods:{composeURL:function(){let e="";if(null!=this.vValue)e=this.vValue;else{var t=document.getElementById(this.vElement);if(null==t)return void teaweb.warn("找不到要下载的内容");null==(e=t.innerText)&&(e=t.textContent)}return Tea.url("/ui/download",{file:this.file,text:e})}},template:'<a :href="url" target="_blank" style="font-weight: normal"><slot></slot></a>'}),Vue.component("values-box",{props:["values","v-values","size","maxlength","name","placeholder"],data:function(){let e=this.values;return null==e&&(e=[]),{realValues:e=null!=this.vValues&&"object"==typeof this.vValues?this.vValues:e,isUpdating:!1,isAdding:!1,index:0,value:"",isEditing:!1}},methods:{create:function(){this.isAdding=!0;var e=this;setTimeout(function(){e.$refs.value.focus()},200)},update:function(e){this.cancel(),this.isUpdating=!0,this.index=e,this.value=this.realValues[e];var t=this;setTimeout(function(){t.$refs.value.focus()},200)},confirm:function(){0!=this.value.length&&(this.isUpdating?Vue.set(this.realValues,this.index,this.value):this.realValues.push(this.value),this.cancel(),this.$emit("change",this.realValues))},remove:function(e){this.realValues.$remove(e),this.$emit("change",this.realValues)},cancel:function(){this.isUpdating=!1,this.isAdding=!1,this.value=""},updateAll:function(e){this.realValues=e},addValue:function(e){this.realValues.push(e)},startEditing:function(){this.isEditing=!this.isEditing}},template:`<div>
|
</tbody>`}),Vue.component("download-link",{props:["v-element","v-file","v-value"],created:function(){let e=this;setTimeout(function(){e.url=e.composeURL()},1e3)},data:function(){let e=this.vFile;return{file:e=null!=e&&0!=e.length?e:"unknown-file",url:this.composeURL()}},methods:{composeURL:function(){let e="";if(null!=this.vValue)e=this.vValue;else{var t=document.getElementById(this.vElement);if(null==t)return void teaweb.warn("找不到要下载的内容");null==(e=t.innerText)&&(e=t.textContent)}return Tea.url("/ui/download",{file:this.file,text:e})}},template:'<a :href="url" target="_blank" style="font-weight: normal"><slot></slot></a>'}),Vue.component("values-box",{props:["values","v-values","size","maxlength","name","placeholder"],data:function(){let e=this.values;return null==e&&(e=[]),{realValues:e=null!=this.vValues&&"object"==typeof this.vValues?this.vValues:e,isUpdating:!1,isAdding:!1,index:0,value:"",isEditing:!1}},methods:{create:function(){this.isAdding=!0;var e=this;setTimeout(function(){e.$refs.value.focus()},200)},update:function(e){this.cancel(),this.isUpdating=!0,this.index=e,this.value=this.realValues[e];var t=this;setTimeout(function(){t.$refs.value.focus()},200)},confirm:function(){0!=this.value.length&&(this.isUpdating?Vue.set(this.realValues,this.index,this.value):this.realValues.push(this.value),this.cancel(),this.$emit("change",this.realValues))},remove:function(e){this.realValues.$remove(e),this.$emit("change",this.realValues)},cancel:function(){this.isUpdating=!1,this.isAdding=!1,this.value=""},updateAll:function(e){this.realValues=e},addValue:function(e){this.realValues.push(e)},startEditing:function(){this.isEditing=!this.isEditing},allValues:function(){return this.realValues}},template:`<div>
|
||||||
<div v-show="!isEditing && realValues.length > 0">
|
<div v-show="!isEditing && realValues.length > 0">
|
||||||
<div class="ui label tiny basic" v-for="(value, index) in realValues" style="margin-top:0.4em;margin-bottom:0.4em">{{value}}</div>
|
<div class="ui label tiny basic" v-for="(value, index) in realValues" style="margin-top:0.4em;margin-bottom:0.4em">{{value}}</div>
|
||||||
<a href="" @click.prevent="startEditing" style="font-size: 0.8em; margin-left: 0.2em">[修改]</a>
|
<a href="" @click.prevent="startEditing" style="font-size: 0.8em; margin-left: 0.2em">[修改]</a>
|
||||||
|
|||||||
@@ -12764,6 +12764,9 @@ Vue.component("values-box", {
|
|||||||
|
|
||||||
startEditing: function () {
|
startEditing: function () {
|
||||||
this.isEditing = !this.isEditing
|
this.isEditing = !this.isEditing
|
||||||
|
},
|
||||||
|
allValues: function () {
|
||||||
|
return this.realValues
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
template: `<div>
|
template: `<div>
|
||||||
|
|||||||
@@ -68,6 +68,9 @@ Vue.component("values-box", {
|
|||||||
|
|
||||||
startEditing: function () {
|
startEditing: function () {
|
||||||
this.isEditing = !this.isEditing
|
this.isEditing = !this.isEditing
|
||||||
|
},
|
||||||
|
allValues: function () {
|
||||||
|
return this.realValues
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
template: `<div>
|
template: `<div>
|
||||||
|
|||||||
Reference in New Issue
Block a user