mirror of
				https://github.com/TeaOSLab/EdgeAdmin.git
				synced 2025-11-04 05:00:25 +08:00 
			
		
		
		
	自定义页面增加“跳转URL”功能
This commit is contained in:
		@@ -6,7 +6,6 @@ import (
 | 
			
		||||
	"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
 | 
			
		||||
	"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"
 | 
			
		||||
)
 | 
			
		||||
@@ -20,7 +19,7 @@ func (this *CreatePopupAction) Init() {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (this *CreatePopupAction) RunGet(params struct{}) {
 | 
			
		||||
	this.Data["bodyTypes"] = shared.FindAllBodyTypes()
 | 
			
		||||
	this.Data["bodyTypes"] = serverconfigs.FindAllHTTPPageBodyTypes()
 | 
			
		||||
 | 
			
		||||
	this.Show()
 | 
			
		||||
}
 | 
			
		||||
@@ -42,12 +41,17 @@ func (this *CreatePopupAction) RunPost(params struct {
 | 
			
		||||
		Require("请输入响应状态码")
 | 
			
		||||
 | 
			
		||||
	switch params.BodyType {
 | 
			
		||||
	case shared.BodyTypeURL:
 | 
			
		||||
	case serverconfigs.HTTPPageBodyTypeURL:
 | 
			
		||||
		params.Must.
 | 
			
		||||
			Field("url", params.URL).
 | 
			
		||||
			Require("请输入要显示的URL").
 | 
			
		||||
			Match(	`^(?i)(http|https)://`, "请输入正确的URL")
 | 
			
		||||
	case shared.BodyTypeHTML:
 | 
			
		||||
	case serverconfigs.HTTPPageBodyTypeRedirectURL:
 | 
			
		||||
		params.Must.
 | 
			
		||||
			Field("url", params.URL).
 | 
			
		||||
			Require("请输入要跳转的URL").
 | 
			
		||||
			Match(	`^(?i)(http|https)://`, "请输入正确的URL")
 | 
			
		||||
	case serverconfigs.HTTPPageBodyTypeHTML:
 | 
			
		||||
		params.Must.
 | 
			
		||||
			Field("body", params.Body).
 | 
			
		||||
			Require("请输入要显示的HTML内容")
 | 
			
		||||
 
 | 
			
		||||
@@ -7,7 +7,6 @@ import (
 | 
			
		||||
	"github.com/TeaOSLab/EdgeCommon/pkg/rpc/dao"
 | 
			
		||||
	"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"
 | 
			
		||||
	"regexp"
 | 
			
		||||
@@ -77,7 +76,11 @@ func (this *IndexAction) RunPost(params struct {
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			// check url
 | 
			
		||||
			if page.BodyType == shared.BodyTypeURL && !urlReg.MatchString(page.URL) {
 | 
			
		||||
			if page.BodyType == serverconfigs.HTTPPageBodyTypeURL && !urlReg.MatchString(page.URL) {
 | 
			
		||||
				this.Fail("自定义页面中 '" + page.URL + "' 不是一个正确的URL,请进行修改")
 | 
			
		||||
				return
 | 
			
		||||
			}
 | 
			
		||||
			if page.BodyType == serverconfigs.HTTPPageBodyTypeRedirectURL && !urlReg.MatchString(page.URL) {
 | 
			
		||||
				this.Fail("自定义页面中 '" + page.URL + "' 不是一个正确的URL,请进行修改")
 | 
			
		||||
				return
 | 
			
		||||
			}
 | 
			
		||||
@@ -99,7 +102,7 @@ func (this *IndexAction) RunPost(params struct {
 | 
			
		||||
			return
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if shutdownConfig.BodyType == shared.BodyTypeURL {
 | 
			
		||||
		if shutdownConfig.BodyType == serverconfigs.HTTPPageBodyTypeURL {
 | 
			
		||||
			if len(shutdownConfig.URL) > 512 {
 | 
			
		||||
				this.Fail("临时关闭页面中URL过长,不能超过512字节")
 | 
			
		||||
				return
 | 
			
		||||
@@ -109,7 +112,17 @@ func (this *IndexAction) RunPost(params struct {
 | 
			
		||||
				this.Fail("临时关闭页面中 '" + shutdownConfig.URL + "' 不是一个正确的URL,请进行修改")
 | 
			
		||||
				return
 | 
			
		||||
			}
 | 
			
		||||
		} else if shutdownConfig.Body == shared.BodyTypeHTML {
 | 
			
		||||
		} else if shutdownConfig.BodyType == serverconfigs.HTTPPageBodyTypeRedirectURL {
 | 
			
		||||
			if len(shutdownConfig.URL) > 512 {
 | 
			
		||||
				this.Fail("临时关闭页面中URL过长,不能超过512字节")
 | 
			
		||||
				return
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			if shutdownConfig.IsOn /** 只有启用的时候才校验 **/ && !urlReg.MatchString(shutdownConfig.URL) {
 | 
			
		||||
				this.Fail("临时关闭页面中 '" + shutdownConfig.URL + "' 不是一个正确的URL,请进行修改")
 | 
			
		||||
				return
 | 
			
		||||
			}
 | 
			
		||||
		} else if shutdownConfig.Body == serverconfigs.HTTPPageBodyTypeHTML {
 | 
			
		||||
			if len(shutdownConfig.Body) > 32*1024 {
 | 
			
		||||
				this.Fail("临时关闭页面中HTML内容长度不能超过32K")
 | 
			
		||||
				return
 | 
			
		||||
 
 | 
			
		||||
@@ -6,7 +6,6 @@ import (
 | 
			
		||||
	"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
 | 
			
		||||
	"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"
 | 
			
		||||
)
 | 
			
		||||
@@ -22,7 +21,7 @@ func (this *UpdatePopupAction) Init() {
 | 
			
		||||
func (this *UpdatePopupAction) RunGet(params struct {
 | 
			
		||||
	PageId int64
 | 
			
		||||
}) {
 | 
			
		||||
	this.Data["bodyTypes"] = shared.FindAllBodyTypes()
 | 
			
		||||
	this.Data["bodyTypes"] = serverconfigs.FindAllHTTPPageBodyTypes()
 | 
			
		||||
 | 
			
		||||
	configResp, err := this.RPC().HTTPPageRPC().FindEnabledHTTPPageConfig(this.AdminContext(), &pb.FindEnabledHTTPPageConfigRequest{HttpPageId: params.PageId})
 | 
			
		||||
	if err != nil {
 | 
			
		||||
@@ -62,12 +61,17 @@ func (this *UpdatePopupAction) RunPost(params struct {
 | 
			
		||||
		Require("请输入响应状态码")
 | 
			
		||||
 | 
			
		||||
	switch params.BodyType {
 | 
			
		||||
	case shared.BodyTypeURL:
 | 
			
		||||
	case serverconfigs.HTTPPageBodyTypeURL:
 | 
			
		||||
		params.Must.
 | 
			
		||||
			Field("url", params.URL).
 | 
			
		||||
			Require("请输入要显示的URL").
 | 
			
		||||
			Match(	`^(?i)(http|https)://`, "请输入正确的URL")
 | 
			
		||||
	case shared.BodyTypeHTML:
 | 
			
		||||
			Match(`^(?i)(http|https)://`, "请输入正确的URL")
 | 
			
		||||
	case serverconfigs.HTTPPageBodyTypeRedirectURL:
 | 
			
		||||
		params.Must.
 | 
			
		||||
			Field("url", params.URL).
 | 
			
		||||
			Require("请输入要跳转的URL").
 | 
			
		||||
			Match(`^(?i)(http|https)://`, "请输入正确的URL")
 | 
			
		||||
	case serverconfigs.HTTPPageBodyTypeHTML:
 | 
			
		||||
		params.Must.
 | 
			
		||||
			Field("body", params.Body).
 | 
			
		||||
			Require("请输入要显示的HTML内容")
 | 
			
		||||
 
 | 
			
		||||
@@ -132,7 +132,28 @@ Vue.component("http-pages-and-shutdown-box", {
 | 
			
		||||
				<span v-if="page.status != null && page.status.length == 1">{{page.status[0]}}</span>
 | 
			
		||||
				<span v-else>{{page.status}}</span>
 | 
			
		||||
			</td>
 | 
			
		||||
			<td style="word-break: break-all"><span v-if="page.bodyType == 'url'">{{page.url}}</span><span v-if="page.bodyType == 'html'">[HTML内容]</span></td>
 | 
			
		||||
			<td style="word-break: break-all">
 | 
			
		||||
				<div v-if="page.bodyType == 'url'">
 | 
			
		||||
					{{page.url}}
 | 
			
		||||
					<div>
 | 
			
		||||
						<grey-label>读取</grey-label>
 | 
			
		||||
						<grey-label v-if="page.newStatus > 0">{{page.newStatus}}</grey-label>	
 | 
			
		||||
					</div>
 | 
			
		||||
				</div>
 | 
			
		||||
				<div v-if="page.bodyType == 'redirectURL'">
 | 
			
		||||
					{{page.url}}
 | 
			
		||||
					<div>
 | 
			
		||||
						<grey-label>跳转</grey-label>	
 | 
			
		||||
						<grey-label v-if="page.newStatus > 0">{{page.newStatus}}</grey-label>
 | 
			
		||||
					</div>
 | 
			
		||||
				</div>
 | 
			
		||||
				<div v-if="page.bodyType == 'html'">
 | 
			
		||||
					[HTML内容]
 | 
			
		||||
					<div>
 | 
			
		||||
						<grey-label v-if="page.newStatus > 0">{{page.newStatus}}</grey-label>
 | 
			
		||||
					</div>
 | 
			
		||||
				</div>
 | 
			
		||||
			</td>
 | 
			
		||||
			<td>
 | 
			
		||||
				<a href="" title="修改" @click.prevent="updatePage(index, page.id)">修改</a>   
 | 
			
		||||
				<a href="" title="删除" @click.prevent="removePage(index)">删除</a>
 | 
			
		||||
@@ -168,16 +189,24 @@ Vue.component("http-pages-and-shutdown-box", {
 | 
			
		||||
					<select class="ui dropdown auto-width" v-model="shutdownConfig.bodyType">
 | 
			
		||||
						<option value="html">HTML</option>
 | 
			
		||||
						<option value="url">读取URL</option>
 | 
			
		||||
						<option value="redirectURL">跳转URL</option>
 | 
			
		||||
					</select>
 | 
			
		||||
				</td>
 | 
			
		||||
			</tr>
 | 
			
		||||
			<tr v-show="shutdownConfig.bodyType == 'url'">
 | 
			
		||||
			<tr v-if="shutdownConfig.bodyType == 'url'">
 | 
			
		||||
				<td class="title">显示页面URL *</td>
 | 
			
		||||
				<td>
 | 
			
		||||
					<input type="text" v-model="shutdownConfig.url" placeholder="类似于 https://example.com/page.html"/>
 | 
			
		||||
					<p class="comment">将从此URL中读取内容。</p>
 | 
			
		||||
				</td>
 | 
			
		||||
			</tr>
 | 
			
		||||
			<tr v-if="shutdownConfig.bodyType == 'redirectURL'">
 | 
			
		||||
				<td class="title">跳转到URL *</td>
 | 
			
		||||
				<td>
 | 
			
		||||
					<input type="text" v-model="shutdownConfig.url" placeholder="类似于 https://example.com/page.html"/>
 | 
			
		||||
					 <p class="comment">将会跳转到此URL。</p>
 | 
			
		||||
				</td>
 | 
			
		||||
			</tr>
 | 
			
		||||
			<tr v-show="shutdownConfig.bodyType == 'html'">
 | 
			
		||||
				<td>显示页面HTML *</td>
 | 
			
		||||
				<td>
 | 
			
		||||
 
 | 
			
		||||
@@ -73,7 +73,28 @@ Vue.component("http-pages-box", {
 | 
			
		||||
				<span v-if="page.status != null && page.status.length == 1">{{page.status[0]}}</span>
 | 
			
		||||
				<span v-else>{{page.status}}</span>
 | 
			
		||||
			</td>
 | 
			
		||||
			<td style="word-break: break-all"><span v-if="page.bodyType == 'url'">{{page.url}}</span><span v-if="page.bodyType == 'html'">[HTML内容]</span></td>
 | 
			
		||||
			<td style="word-break: break-all">
 | 
			
		||||
				<div v-if="page.bodyType == 'url'">
 | 
			
		||||
					{{page.url}}
 | 
			
		||||
					<div>
 | 
			
		||||
						<grey-label>读取</grey-label>	
 | 
			
		||||
						<grey-label v-if="page.newStatus > 0">{{page.newStatus}}</grey-label>
 | 
			
		||||
					</div>
 | 
			
		||||
				</div>
 | 
			
		||||
				<div v-if="page.bodyType == 'redirectURL'">
 | 
			
		||||
					{{page.url}}
 | 
			
		||||
					<div>
 | 
			
		||||
						<grey-label>跳转</grey-label>	
 | 
			
		||||
						<grey-label v-if="page.newStatus > 0">{{page.newStatus}}</grey-label>
 | 
			
		||||
					</div>
 | 
			
		||||
				</div>
 | 
			
		||||
				<div v-if="page.bodyType == 'html'">
 | 
			
		||||
					[HTML内容]
 | 
			
		||||
					<div>
 | 
			
		||||
						<grey-label v-if="page.newStatus > 0">{{page.newStatus}}</grey-label>
 | 
			
		||||
					</div>
 | 
			
		||||
				</div>
 | 
			
		||||
			</td>
 | 
			
		||||
			<td>
 | 
			
		||||
				<a href="" title="修改" @click.prevent="updatePage(index, page.id)">修改</a>   
 | 
			
		||||
				<a href="" title="删除" @click.prevent="removePage(index)">删除</a>
 | 
			
		||||
 
 | 
			
		||||
@@ -17,19 +17,26 @@
 | 
			
		||||
                </select>
 | 
			
		||||
            </td>
 | 
			
		||||
        </tr>
 | 
			
		||||
		<tr v-show="bodyType == 'url'">
 | 
			
		||||
			<td>显示页面URL *</td>
 | 
			
		||||
			<td>
 | 
			
		||||
				<input type="text" name="url" maxlength="500" placeholder="类似于 https://example.com/page.html"/>
 | 
			
		||||
                <p class="comment">将从此URL中读取内容。</p>
 | 
			
		||||
			</td>
 | 
			
		||||
		</tr>
 | 
			
		||||
        <tr v-show="bodyType == 'html'">
 | 
			
		||||
            <td>显示页面HTML *</td>
 | 
			
		||||
            <td>
 | 
			
		||||
                <textarea name="body" ref="htmlBody"></textarea>
 | 
			
		||||
                <p class="comment"><a href="" @click.prevent="addHTMLTemplate">[使用模板]</a>。填写页面的HTML内容,支持请求变量。</p>
 | 
			
		||||
            </td>
 | 
			
		||||
        </tr>
 | 
			
		||||
        <tr v-if="bodyType == 'url'">
 | 
			
		||||
            <td>显示页面URL *</td>
 | 
			
		||||
            <td>
 | 
			
		||||
                <input type="text" name="url" maxlength="500" placeholder="类似于 https://example.com/page.html"/>
 | 
			
		||||
                <p class="comment">将从此URL中读取内容。</p>
 | 
			
		||||
            </td>
 | 
			
		||||
        </tr>
 | 
			
		||||
        <tr v-if="bodyType == 'redirectURL'">
 | 
			
		||||
            <td>跳转到URL *</td>
 | 
			
		||||
            <td>
 | 
			
		||||
                <input type="text" name="url" maxlength="500" placeholder="类似于 https://example.com/page.html"/>
 | 
			
		||||
                <p class="comment">将会跳转到此URL。</p>
 | 
			
		||||
            </td>
 | 
			
		||||
        </tr>
 | 
			
		||||
		<tr>
 | 
			
		||||
			<td>新状态码</td>
 | 
			
		||||
 
 | 
			
		||||
@@ -18,19 +18,26 @@
 | 
			
		||||
                </select>
 | 
			
		||||
            </td>
 | 
			
		||||
        </tr>
 | 
			
		||||
		<tr v-show="bodyType == 'url'">
 | 
			
		||||
			<td>显示页面URL *</td>
 | 
			
		||||
			<td>
 | 
			
		||||
				<input type="text" name="url" maxlength="500" placeholder="类似于 https://example.com/page.html" v-model="pageConfig.url"/>
 | 
			
		||||
                <p class="comment">将从此URL中读取内容。</p>
 | 
			
		||||
			</td>
 | 
			
		||||
		</tr>
 | 
			
		||||
        <tr v-show="bodyType == 'html'">
 | 
			
		||||
            <td>显示页面HTML *</td>
 | 
			
		||||
            <td>
 | 
			
		||||
                <textarea name="body" ref="htmlBody" v-model="pageConfig.body"></textarea>
 | 
			
		||||
                <p class="comment"><a href="" @click.prevent="addHTMLTemplate">[使用模板]</a>。填写页面的HTML内容,支持请求变量。</p>
 | 
			
		||||
            </td>
 | 
			
		||||
        </tr>
 | 
			
		||||
        <tr v-if="bodyType == 'url'">
 | 
			
		||||
            <td>显示页面URL *</td>
 | 
			
		||||
            <td>
 | 
			
		||||
                <input type="text" name="url" maxlength="500" placeholder="类似于 https://example.com/page.html" v-model="pageConfig.url"/>
 | 
			
		||||
                <p class="comment">将从此URL中读取内容。</p>
 | 
			
		||||
            </td>
 | 
			
		||||
        </tr>
 | 
			
		||||
        <tr v-if="bodyType == 'redirectURL'">
 | 
			
		||||
            <td>跳转到URL *</td>
 | 
			
		||||
            <td>
 | 
			
		||||
                <input type="text" name="url" maxlength="500" placeholder="类似于 https://example.com/page.html" v-model="pageConfig.url"/>
 | 
			
		||||
                <p class="comment">将会跳转到此URL。</p>
 | 
			
		||||
            </td>
 | 
			
		||||
        </tr>
 | 
			
		||||
		<tr>
 | 
			
		||||
			<td>新状态码</td>
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user