自定义页面增加是否“启用系统自定义页面”选项

This commit is contained in:
GoEdgeLab
2024-05-03 09:34:58 +08:00
parent 772ec1ac38
commit 89d70ce121
9 changed files with 99 additions and 24 deletions

View File

@@ -1,6 +1,7 @@
package pages package pages
import ( "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/groups/group/servergrouputils" "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/groups/group/servergrouputils"
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes" "github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/dao" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/dao"
@@ -33,6 +34,7 @@ func (this *IndexAction) RunGet(params struct {
} }
this.Data["webId"] = webConfig.Id this.Data["webId"] = webConfig.Id
this.Data["enableGlobalPages"] = webConfig.EnableGlobalPages
this.Data["pages"] = webConfig.Pages this.Data["pages"] = webConfig.Pages
this.Data["shutdownConfig"] = webConfig.Shutdown this.Data["shutdownConfig"] = webConfig.Shutdown
@@ -40,17 +42,27 @@ func (this *IndexAction) RunGet(params struct {
} }
func (this *IndexAction) RunPost(params struct { func (this *IndexAction) RunPost(params struct {
WebId int64 WebId int64
PagesJSON string EnableGlobalPages bool
ShutdownJSON string PagesJSON string
Must *actions.Must ShutdownJSON string
Must *actions.Must
}) { }) {
// 日志 // 日志
defer this.CreateLogInfo(codes.ServerPage_LogUpdatePages, params.WebId) defer this.CreateLogInfo(codes.ServerPage_LogUpdatePages, params.WebId)
// TODO 检查配置 // TODO 检查配置
_, err := this.RPC().HTTPWebRPC().UpdateHTTPWebPages(this.AdminContext(), &pb.UpdateHTTPWebPagesRequest{ _, err := this.RPC().HTTPWebRPC().UpdateHTTPWebGlobalPagesEnabled(this.AdminContext(), &pb.UpdateHTTPWebGlobalPagesEnabledRequest{
HttpWebId: params.WebId,
IsEnabled: params.EnableGlobalPages,
})
if err != nil {
this.ErrorPage(err)
return
}
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebPages(this.AdminContext(), &pb.UpdateHTTPWebPagesRequest{
HttpWebId: params.WebId, HttpWebId: params.WebId,
PagesJSON: []byte(params.PagesJSON), PagesJSON: []byte(params.PagesJSON),
}) })

View File

@@ -25,6 +25,7 @@ func (this *IndexAction) RunGet(params struct {
} }
this.Data["webId"] = webConfig.Id this.Data["webId"] = webConfig.Id
this.Data["enableGlobalPages"] = webConfig.EnableGlobalPages
this.Data["pages"] = webConfig.Pages this.Data["pages"] = webConfig.Pages
this.Data["shutdownConfig"] = webConfig.Shutdown this.Data["shutdownConfig"] = webConfig.Shutdown
@@ -32,16 +33,26 @@ func (this *IndexAction) RunGet(params struct {
} }
func (this *IndexAction) RunPost(params struct { func (this *IndexAction) RunPost(params struct {
WebId int64 WebId int64
PagesJSON string EnableGlobalPages bool
ShutdownJSON string PagesJSON string
Must *actions.Must ShutdownJSON string
Must *actions.Must
}) { }) {
defer this.CreateLogInfo(codes.ServerPage_LogUpdatePages, params.WebId) defer this.CreateLogInfo(codes.ServerPage_LogUpdatePages, params.WebId)
// TODO 检查配置 // TODO 检查配置
_, err := this.RPC().HTTPWebRPC().UpdateHTTPWebPages(this.AdminContext(), &pb.UpdateHTTPWebPagesRequest{ _, err := this.RPC().HTTPWebRPC().UpdateHTTPWebGlobalPagesEnabled(this.AdminContext(), &pb.UpdateHTTPWebGlobalPagesEnabledRequest{
HttpWebId: params.WebId,
IsEnabled: params.EnableGlobalPages,
})
if err != nil {
this.ErrorPage(err)
return
}
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebPages(this.AdminContext(), &pb.UpdateHTTPWebPagesRequest{
HttpWebId: params.WebId, HttpWebId: params.WebId,
PagesJSON: []byte(params.PagesJSON), PagesJSON: []byte(params.PagesJSON),
}) })

View File

@@ -47,6 +47,7 @@ func (this *IndexAction) RunGet(params struct {
} }
this.Data["webId"] = webConfig.Id this.Data["webId"] = webConfig.Id
this.Data["enableGlobalPages"] = webConfig.EnableGlobalPages
this.Data["pages"] = webConfig.Pages this.Data["pages"] = webConfig.Pages
this.Data["shutdownConfig"] = webConfig.Shutdown this.Data["shutdownConfig"] = webConfig.Shutdown
@@ -54,10 +55,11 @@ func (this *IndexAction) RunGet(params struct {
} }
func (this *IndexAction) RunPost(params struct { func (this *IndexAction) RunPost(params struct {
WebId int64 WebId int64
PagesJSON []byte PagesJSON []byte
ShutdownJSON []byte ShutdownJSON []byte
Must *actions.Must EnableGlobalPages bool
Must *actions.Must
}) { }) {
// 日志 // 日志
defer this.CreateLogInfo(codes.ServerPage_LogUpdatePages, params.WebId) defer this.CreateLogInfo(codes.ServerPage_LogUpdatePages, params.WebId)
@@ -135,7 +137,16 @@ func (this *IndexAction) RunPost(params struct {
} }
} }
_, err := this.RPC().HTTPWebRPC().UpdateHTTPWebPages(this.AdminContext(), &pb.UpdateHTTPWebPagesRequest{ _, err := this.RPC().HTTPWebRPC().UpdateHTTPWebGlobalPagesEnabled(this.AdminContext(), &pb.UpdateHTTPWebGlobalPagesEnabledRequest{
HttpWebId: params.WebId,
IsEnabled: params.EnableGlobalPages,
})
if err != nil {
this.ErrorPage(err)
return
}
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebPages(this.AdminContext(), &pb.UpdateHTTPWebPagesRequest{
HttpWebId: params.WebId, HttpWebId: params.WebId,
PagesJSON: params.PagesJSON, PagesJSON: params.PagesJSON,
}) })

View File

@@ -3808,7 +3808,7 @@ example2.com
<div v-if="cachePolicy == null"> <div v-if="cachePolicy == null">
<span v-if="count > 0"><a href="" @click.prevent="select">[选择已有策略]</a> &nbsp; &nbsp; </span><a href="" @click.prevent="create">[创建新策略]</a> <span v-if="count > 0"><a href="" @click.prevent="select">[选择已有策略]</a> &nbsp; &nbsp; </span><a href="" @click.prevent="create">[创建新策略]</a>
</div> </div>
</div>`}),Vue.component("http-pages-and-shutdown-box",{props:["v-pages","v-shutdown-config","v-is-location"],data:function(){let e=[],t=(null!=this.vPages&&(e=this.vPages),{isPrior:!1,isOn:!1,bodyType:"html",url:"",body:"",status:0}),i=(null!=this.vShutdownConfig&&(null==this.vShutdownConfig.body&&(this.vShutdownConfig.body=""),null==this.vShutdownConfig.bodyType&&(this.vShutdownConfig.bodyType="html"),t=this.vShutdownConfig),"");return 0<t.status&&(i=t.status.toString()),{pages:e,shutdownConfig:t,shutdownStatus:i}},watch:{shutdownStatus:function(e){e=parseInt(e);!isNaN(e)&&0<e&&e<1e3?this.shutdownConfig.status=e:this.shutdownConfig.status=0}},methods:{addPage:function(){let t=this;teaweb.popup("/servers/server/settings/pages/createPopup",{height:"30em",callback:function(e){t.pages.push(e.data.page),t.notifyChange()}})},updatePage:function(t,e){let i=this;teaweb.popup("/servers/server/settings/pages/updatePopup?pageId="+e,{height:"30em",callback:function(e){Vue.set(i.pages,t,e.data.page),i.notifyChange()}})},removePage:function(e){let t=this;teaweb.confirm("确定要删除此自定义页面吗?",function(){t.pages.$remove(e),t.notifyChange()})},addShutdownHTMLTemplate:function(){this.shutdownConfig.body=`<!DOCTYPE html> </div>`}),Vue.component("http-pages-and-shutdown-box",{props:["v-enable-global-pages","v-pages","v-shutdown-config","v-is-location"],data:function(){let e=[],t=(null!=this.vPages&&(e=this.vPages),{isPrior:!1,isOn:!1,bodyType:"html",url:"",body:"",status:0}),i=(null!=this.vShutdownConfig&&(null==this.vShutdownConfig.body&&(this.vShutdownConfig.body=""),null==this.vShutdownConfig.bodyType&&(this.vShutdownConfig.bodyType="html"),t=this.vShutdownConfig),"");return 0<t.status&&(i=t.status.toString()),{pages:e,shutdownConfig:t,shutdownStatus:i,enableGlobalPages:this.vEnableGlobalPages}},watch:{shutdownStatus:function(e){e=parseInt(e);!isNaN(e)&&0<e&&e<1e3?this.shutdownConfig.status=e:this.shutdownConfig.status=0}},methods:{addPage:function(){let t=this;teaweb.popup("/servers/server/settings/pages/createPopup",{height:"30em",callback:function(e){t.pages.push(e.data.page),t.notifyChange()}})},updatePage:function(t,e){let i=this;teaweb.popup("/servers/server/settings/pages/updatePopup?pageId="+e,{height:"30em",callback:function(e){Vue.set(i.pages,t,e.data.page),i.notifyChange()}})},removePage:function(e){let t=this;teaweb.confirm("确定要删除此自定义页面吗?",function(){t.pages.$remove(e),t.notifyChange()})},addShutdownHTMLTemplate:function(){this.shutdownConfig.body=`<!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<title>升级中</title> <title>升级中</title>
@@ -3829,6 +3829,7 @@ example2.com
</html>`},notifyChange:function(){let e=this.$el.parentNode;for(;;){if(null==e)break;if("FORM"==e.tagName)break;e=e.parentNode}null!=e&&setTimeout(function(){Tea.runActionOn(e)},100)}},template:`<div> </html>`},notifyChange:function(){let e=this.$el.parentNode;for(;;){if(null==e)break;if("FORM"==e.tagName)break;e=e.parentNode}null!=e&&setTimeout(function(){Tea.runActionOn(e)},100)}},template:`<div>
<input type="hidden" name="pagesJSON" :value="JSON.stringify(pages)"/> <input type="hidden" name="pagesJSON" :value="JSON.stringify(pages)"/>
<input type="hidden" name="shutdownJSON" :value="JSON.stringify(shutdownConfig)"/> <input type="hidden" name="shutdownJSON" :value="JSON.stringify(shutdownConfig)"/>
<h4 style="margin-bottom: 0.5em">自定义页面</h4> <h4 style="margin-bottom: 0.5em">自定义页面</h4>
<p class="comment" style="padding-top: 0; margin-top: 0">根据响应状态码返回一些自定义页面比如404500等错误页面。</p> <p class="comment" style="padding-top: 0; margin-top: 0">根据响应状态码返回一些自定义页面比如404500等错误页面。</p>
@@ -3958,7 +3959,19 @@ example2.com
</tbody> </tbody>
</table> </table>
</div> </div>
<h4 style="margin-top: 2em;">其他设置</h4>
<table class="ui table definition selectable">
<tr>
<td class="title">启用系统自定义页面</td>
<td>
<checkbox name="enableGlobalPages" v-model="enableGlobalPages"></checkbox>
<p class="comment">选中后,表示如果当前网站没有自定义页面,则尝试使用系统对应的自定义页面。</p>
</td>
</tr>
</table>
<div class="ui margin"></div> <div class="ui margin"></div>
</div>`}),Vue.component("http-firewall-page-options",{props:["v-page-options"],data:function(){return{pageOptions:this.vPageOptions,status:this.vPageOptions.status,body:this.vPageOptions.body,defaultPageBody:`<!DOCTYPE html> </div>`}),Vue.component("http-firewall-page-options",{props:["v-page-options"],data:function(){return{pageOptions:this.vPageOptions,status:this.vPageOptions.status,body:this.vPageOptions.body,defaultPageBody:`<!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>

View File

@@ -10603,7 +10603,7 @@ Vue.component("http-cache-policy-selector", {
}) })
Vue.component("http-pages-and-shutdown-box", { Vue.component("http-pages-and-shutdown-box", {
props: ["v-pages", "v-shutdown-config", "v-is-location"], props: ["v-enable-global-pages", "v-pages", "v-shutdown-config", "v-is-location"],
data: function () { data: function () {
let pages = [] let pages = []
if (this.vPages != null) { if (this.vPages != null) {
@@ -10635,7 +10635,8 @@ Vue.component("http-pages-and-shutdown-box", {
return { return {
pages: pages, pages: pages,
shutdownConfig: shutdownConfig, shutdownConfig: shutdownConfig,
shutdownStatus: shutdownStatus shutdownStatus: shutdownStatus,
enableGlobalPages: this.vEnableGlobalPages
} }
}, },
watch: { watch: {
@@ -10718,6 +10719,7 @@ Vue.component("http-pages-and-shutdown-box", {
template: `<div> template: `<div>
<input type="hidden" name="pagesJSON" :value="JSON.stringify(pages)"/> <input type="hidden" name="pagesJSON" :value="JSON.stringify(pages)"/>
<input type="hidden" name="shutdownJSON" :value="JSON.stringify(shutdownConfig)"/> <input type="hidden" name="shutdownJSON" :value="JSON.stringify(shutdownConfig)"/>
<h4 style="margin-bottom: 0.5em">自定义页面</h4> <h4 style="margin-bottom: 0.5em">自定义页面</h4>
<p class="comment" style="padding-top: 0; margin-top: 0">根据响应状态码返回一些自定义页面比如404500等错误页面。</p> <p class="comment" style="padding-top: 0; margin-top: 0">根据响应状态码返回一些自定义页面比如404500等错误页面。</p>
@@ -10847,7 +10849,19 @@ Vue.component("http-pages-and-shutdown-box", {
</tbody> </tbody>
</table> </table>
</div> </div>
<h4 style="margin-top: 2em;">其他设置</h4>
<table class="ui table definition selectable">
<tr>
<td class="title">启用系统自定义页面</td>
<td>
<checkbox name="enableGlobalPages" v-model="enableGlobalPages"></checkbox>
<p class="comment">选中后,表示如果当前网站没有自定义页面,则尝试使用系统对应的自定义页面。</p>
</td>
</tr>
</table>
<div class="ui margin"></div> <div class="ui margin"></div>
</div>` </div>`
}) })

View File

@@ -1,5 +1,5 @@
Vue.component("http-pages-and-shutdown-box", { Vue.component("http-pages-and-shutdown-box", {
props: ["v-pages", "v-shutdown-config", "v-is-location"], props: ["v-enable-global-pages", "v-pages", "v-shutdown-config", "v-is-location"],
data: function () { data: function () {
let pages = [] let pages = []
if (this.vPages != null) { if (this.vPages != null) {
@@ -31,7 +31,8 @@ Vue.component("http-pages-and-shutdown-box", {
return { return {
pages: pages, pages: pages,
shutdownConfig: shutdownConfig, shutdownConfig: shutdownConfig,
shutdownStatus: shutdownStatus shutdownStatus: shutdownStatus,
enableGlobalPages: this.vEnableGlobalPages
} }
}, },
watch: { watch: {
@@ -114,6 +115,7 @@ Vue.component("http-pages-and-shutdown-box", {
template: `<div> template: `<div>
<input type="hidden" name="pagesJSON" :value="JSON.stringify(pages)"/> <input type="hidden" name="pagesJSON" :value="JSON.stringify(pages)"/>
<input type="hidden" name="shutdownJSON" :value="JSON.stringify(shutdownConfig)"/> <input type="hidden" name="shutdownJSON" :value="JSON.stringify(shutdownConfig)"/>
<h4 style="margin-bottom: 0.5em">自定义页面</h4> <h4 style="margin-bottom: 0.5em">自定义页面</h4>
<p class="comment" style="padding-top: 0; margin-top: 0">根据响应状态码返回一些自定义页面比如404500等错误页面。</p> <p class="comment" style="padding-top: 0; margin-top: 0">根据响应状态码返回一些自定义页面比如404500等错误页面。</p>
@@ -243,6 +245,18 @@ Vue.component("http-pages-and-shutdown-box", {
</tbody> </tbody>
</table> </table>
</div> </div>
<h4 style="margin-top: 2em;">其他设置</h4>
<table class="ui table definition selectable">
<tr>
<td class="title">启用系统自定义页面</td>
<td>
<checkbox name="enableGlobalPages" v-model="enableGlobalPages"></checkbox>
<p class="comment">选中后,表示如果当前网站没有自定义页面,则尝试使用系统对应的自定义页面。</p>
</td>
</tr>
</table>
<div class="ui margin"></div> <div class="ui margin"></div>
</div>` </div>`
}) })

View File

@@ -5,7 +5,7 @@
<div class="right-box without-menu"> <div class="right-box without-menu">
<form method="post" class="ui form" data-tea-action="$" data-tea-success="success"> <form method="post" class="ui form" data-tea-action="$" data-tea-success="success">
<input type="hidden" name="webId" :value="webId"/> <input type="hidden" name="webId" :value="webId"/>
<http-pages-and-shutdown-box :v-pages="pages" :v-shutdown-config="shutdownConfig"></http-pages-and-shutdown-box> <http-pages-and-shutdown-box :v-pages="pages" :v-shutdown-config="shutdownConfig" :v-enable-global-pages="enableGlobalPages"></http-pages-and-shutdown-box>
<submit-btn></submit-btn> <submit-btn></submit-btn>
</form> </form>
</div> </div>

View File

@@ -9,7 +9,7 @@
<div class="right-box tiny"> <div class="right-box tiny">
<form method="post" class="ui form" data-tea-action="$" data-tea-success="success"> <form method="post" class="ui form" data-tea-action="$" data-tea-success="success">
<input type="hidden" name="webId" :value="webId"/> <input type="hidden" name="webId" :value="webId"/>
<http-pages-and-shutdown-box :v-pages="pages" :v-shutdown-config="shutdownConfig" :v-is-location="true"></http-pages-and-shutdown-box> <http-pages-and-shutdown-box :v-pages="pages" :v-shutdown-config="shutdownConfig" :v-is-location="true" :v-enable-global-pages="enableGlobalPages"></http-pages-and-shutdown-box>
<submit-btn></submit-btn> <submit-btn></submit-btn>
</form> </form>
</div> </div>

View File

@@ -11,7 +11,7 @@
<div :class="{'opacity-mask': hasGroupConfig}"> <div :class="{'opacity-mask': hasGroupConfig}">
<form method="post" class="ui form" data-tea-action="$" data-tea-success="success"> <form method="post" class="ui form" data-tea-action="$" data-tea-success="success">
<input type="hidden" name="webId" :value="webId"/> <input type="hidden" name="webId" :value="webId"/>
<http-pages-and-shutdown-box :v-pages="pages" :v-shutdown-config="shutdownConfig"></http-pages-and-shutdown-box> <http-pages-and-shutdown-box :v-pages="pages" :v-shutdown-config="shutdownConfig" :v-enable-global-pages="enableGlobalPages"></http-pages-and-shutdown-box>
<submit-btn></submit-btn> <submit-btn></submit-btn>
</form> </form>
</div> </div>