From b766a0f23ca10a7e79e8aa33809d7617152efa58 Mon Sep 17 00:00:00 2001 From: GoEdgeLab Date: Sun, 10 Oct 2021 10:35:14 +0800 Subject: [PATCH] =?UTF-8?q?=E7=89=B9=E6=AE=8A=E9=A1=B5=E9=9D=A2=E5=8F=AF?= =?UTF-8?q?=E4=BB=A5=E7=9B=B4=E6=8E=A5=E4=BD=BF=E7=94=A8HTML?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/settings/pages/createPopup.go | 28 +++++++++-- .../server/settings/pages/updatePopup.go | 28 +++++++++-- .../server/http-pages-and-shutdown-box.js | 49 +++++++++++++++++-- .../server/settings/pages/createPopup.html | 17 ++++++- .../server/settings/pages/createPopup.js | 21 ++++++++ .../server/settings/pages/updatePopup.html | 17 ++++++- .../server/settings/pages/updatePopup.js | 20 ++++++++ 7 files changed, 164 insertions(+), 16 deletions(-) create mode 100644 web/views/@default/servers/server/settings/pages/createPopup.js diff --git a/internal/web/actions/default/servers/server/settings/pages/createPopup.go b/internal/web/actions/default/servers/server/settings/pages/createPopup.go index b480484c..9ee59043 100644 --- a/internal/web/actions/default/servers/server/settings/pages/createPopup.go +++ b/internal/web/actions/default/servers/server/settings/pages/createPopup.go @@ -6,6 +6,7 @@ import ( "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs" + "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared" "github.com/iwind/TeaGo/actions" "github.com/iwind/TeaGo/types" ) @@ -19,12 +20,18 @@ func (this *CreatePopupAction) Init() { } func (this *CreatePopupAction) RunGet(params struct{}) { + this.Data["bodyTypes"] = shared.FindAllBodyTypes() + this.Show() } func (this *CreatePopupAction) RunPost(params struct { - Status string - URL string `alias:"url"` + Status string + BodyType string + + URL string `alias:"url"` + Body string + NewStatus int Must *actions.Must }) { @@ -32,13 +39,24 @@ func (this *CreatePopupAction) RunPost(params struct { params.Must. Field("status", params.Status). - Require("请输入响应状态码"). - Field("url", params.URL). - Require("请输入要显示的URL") + Require("请输入响应状态码") + + switch params.BodyType { + case shared.BodyTypeURL: + params.Must. + Field("url", params.URL). + Require("请输入要显示的URL") + case shared.BodyTypeHTML: + params.Must. + Field("body", params.Body). + Require("请输入要显示的HTML内容") + } createResp, err := this.RPC().HTTPPageRPC().CreateHTTPPage(this.AdminContext(), &pb.CreateHTTPPageRequest{ StatusList: []string{params.Status}, + BodyType: params.BodyType, Url: params.URL, + Body: params.Body, NewStatus: types.Int32(params.NewStatus), }) if err != nil { diff --git a/internal/web/actions/default/servers/server/settings/pages/updatePopup.go b/internal/web/actions/default/servers/server/settings/pages/updatePopup.go index 15764f33..84e7ece7 100644 --- a/internal/web/actions/default/servers/server/settings/pages/updatePopup.go +++ b/internal/web/actions/default/servers/server/settings/pages/updatePopup.go @@ -6,6 +6,7 @@ import ( "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs" + "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared" "github.com/iwind/TeaGo/actions" "github.com/iwind/TeaGo/types" ) @@ -21,6 +22,8 @@ func (this *UpdatePopupAction) Init() { func (this *UpdatePopupAction) RunGet(params struct { PageId int64 }) { + this.Data["bodyTypes"] = shared.FindAllBodyTypes() + configResp, err := this.RPC().HTTPPageRPC().FindEnabledHTTPPageConfig(this.AdminContext(), &pb.FindEnabledHTTPPageConfigRequest{PageId: params.PageId}) if err != nil { this.ErrorPage(err) @@ -41,8 +44,12 @@ func (this *UpdatePopupAction) RunGet(params struct { func (this *UpdatePopupAction) RunPost(params struct { PageId int64 - Status string - URL string `alias:"url"` + Status string + + BodyType string + URL string `alias:"url"` + Body string + NewStatus int Must *actions.Must @@ -52,14 +59,25 @@ func (this *UpdatePopupAction) RunPost(params struct { params.Must. Field("status", params.Status). - Require("请输入响应状态码"). - Field("url", params.URL). - Require("请输入要显示的URL") + Require("请输入响应状态码") + + switch params.BodyType { + case shared.BodyTypeURL: + params.Must. + Field("url", params.URL). + Require("请输入要显示的URL") + case shared.BodyTypeHTML: + params.Must. + Field("body", params.Body). + Require("请输入要显示的HTML内容") + } _, err := this.RPC().HTTPPageRPC().UpdateHTTPPage(this.AdminContext(), &pb.UpdateHTTPPageRequest{ PageId: params.PageId, StatusList: []string{params.Status}, + BodyType: params.BodyType, Url: params.URL, + Body: params.Body, NewStatus: types.Int32(params.NewStatus), }) if err != nil { diff --git a/web/public/js/components/server/http-pages-and-shutdown-box.js b/web/public/js/components/server/http-pages-and-shutdown-box.js index 545b21b7..dc213058 100644 --- a/web/public/js/components/server/http-pages-and-shutdown-box.js +++ b/web/public/js/components/server/http-pages-and-shutdown-box.js @@ -8,10 +8,18 @@ Vue.component("http-pages-and-shutdown-box", { let shutdownConfig = { isPrior: false, isOn: false, + bodyType: "url", url: "", + body: "", status: 0 } if (this.vShutdownConfig != null) { + if (this.vShutdownConfig.body == null) { + this.vShutdownConfig.body = "" + } + if (this.vShutdownConfig.bodyType == null) { + this.vShutdownConfig.bodyType = "url" + } shutdownConfig = this.vShutdownConfig } @@ -40,7 +48,7 @@ Vue.component("http-pages-and-shutdown-box", { addPage: function () { let that = this teaweb.popup("/servers/server/settings/pages/createPopup", { - height: "22em", + height: "26em", callback: function (resp) { that.pages.push(resp.data.page) } @@ -49,7 +57,7 @@ Vue.component("http-pages-and-shutdown-box", { updatePage: function (pageIndex, pageId) { let that = this teaweb.popup("/servers/server/settings/pages/updatePopup?pageId=" + pageId, { - height: "22em", + height: "26em", callback: function (resp) { Vue.set(that.pages, pageIndex, resp.data.page) } @@ -60,6 +68,23 @@ Vue.component("http-pages-and-shutdown-box", { teaweb.confirm("确定要移除此页面吗?", function () { that.pages.$remove(pageIndex) }) + }, + addShutdownHTMLTemplate: function () { + this.shutdownConfig.body = ` + + +\t升级中 +\t + + + +

网站升级中

+

为了给您提供更好的服务,我们正在升级网站,请稍后重新访问。

+ + + + +` } }, template: `
@@ -71,7 +96,7 @@ Vue.component("http-pages-and-shutdown-box", {
- {{page.status}} -> {{page.url}} + {{page.status}} -> {{page.url}}[HTML内容]
@@ -100,12 +125,28 @@ Vue.component("http-pages-and-shutdown-box", { - 页面URL + 内容类型 * + + + + + + 页面URL *

页面文件是相对于节点安装目录的页面文件比如pages/40x.html,或者一个完整的URL。

+ + HTML * + + +

[使用模板]。填写页面的HTML内容,支持请求变量。

+ + 状态码 diff --git a/web/views/@default/servers/server/settings/pages/createPopup.html b/web/views/@default/servers/server/settings/pages/createPopup.html index 45a04823..a0f7daa6 100644 --- a/web/views/@default/servers/server/settings/pages/createPopup.html +++ b/web/views/@default/servers/server/settings/pages/createPopup.html @@ -9,13 +9,28 @@

比如404,或者50x。

- + + 内容类型 * + + + + + URL *

页面文件是相对于节点安装目录的页面文件比如web/pages/40x.html,或者一个完整的URL。

+ + HTML * + + +

[使用模板]。填写页面的HTML内容,支持请求变量。

+ + 新状态码 diff --git a/web/views/@default/servers/server/settings/pages/createPopup.js b/web/views/@default/servers/server/settings/pages/createPopup.js new file mode 100644 index 00000000..4323aec1 --- /dev/null +++ b/web/views/@default/servers/server/settings/pages/createPopup.js @@ -0,0 +1,21 @@ +Tea.context(function () { + this.bodyType = this.bodyTypes[0].code + + this.addHTMLTemplate = function () { + this.$refs.htmlBody.value = ` + + +\t页面标题 +\t + + + +

内容标题

+

内容

+ +
Powered by GoEdge.
+ + +` + } +}) \ No newline at end of file diff --git a/web/views/@default/servers/server/settings/pages/updatePopup.html b/web/views/@default/servers/server/settings/pages/updatePopup.html index cc18e2c3..b6517331 100644 --- a/web/views/@default/servers/server/settings/pages/updatePopup.html +++ b/web/views/@default/servers/server/settings/pages/updatePopup.html @@ -10,13 +10,28 @@

比如404,或者50x。

- + + 内容类型 * + + + + + URL *

页面文件是相对于节点安装目录的页面文件比如web/pages/40x.html,或者一个完整的URL。

+ + HTML * + + +

[使用模板]。填写页面的HTML内容,支持请求变量。

+ + 新状态码 diff --git a/web/views/@default/servers/server/settings/pages/updatePopup.js b/web/views/@default/servers/server/settings/pages/updatePopup.js index c064bd22..e07fa9e5 100644 --- a/web/views/@default/servers/server/settings/pages/updatePopup.js +++ b/web/views/@default/servers/server/settings/pages/updatePopup.js @@ -1,8 +1,28 @@ Tea.context(function () { this.success = NotifyPopup + this.bodyType = this.pageConfig.bodyType + this.newStatus = "" if (this.pageConfig.newStatus > 0) { this.newStatus = this.pageConfig.newStatus } + + this.addHTMLTemplate = function () { + this.$refs.htmlBody.value = ` + + +\t页面标题 +\t + + + +

内容标题

+

内容

+ + + + +` + } }) \ No newline at end of file