Files
EdgeAdmin/web/public/js/components/server/http-pages-and-shutdown-box.js

163 lines
5.1 KiB
JavaScript
Raw Normal View History

2020-09-20 11:56:49 +08:00
Vue.component("http-pages-and-shutdown-box", {
2020-09-26 08:07:18 +08:00
props: ["v-pages", "v-shutdown-config", "v-is-location"],
2020-09-20 08:58:48 +08:00
data: function () {
let pages = []
if (this.vPages != null) {
pages = this.vPages
}
let shutdownConfig = {
2020-09-26 08:07:18 +08:00
isPrior: false,
2020-09-20 08:58:48 +08:00
isOn: false,
2021-10-10 10:35:14 +08:00
bodyType: "url",
2020-09-20 08:58:48 +08:00
url: "",
2021-10-10 10:35:14 +08:00
body: "",
2020-09-20 08:58:48 +08:00
status: 0
}
if (this.vShutdownConfig != null) {
2021-10-10 10:35:14 +08:00
if (this.vShutdownConfig.body == null) {
this.vShutdownConfig.body = ""
}
if (this.vShutdownConfig.bodyType == null) {
this.vShutdownConfig.bodyType = "url"
}
2020-09-20 08:58:48 +08:00
shutdownConfig = this.vShutdownConfig
}
let shutdownStatus = ""
if (shutdownConfig.status > 0) {
shutdownStatus = shutdownConfig.status.toString()
}
return {
pages: pages,
shutdownConfig: shutdownConfig,
shutdownStatus: shutdownStatus
}
},
watch: {
shutdownStatus: function (status) {
let statusInt = parseInt(status)
if (!isNaN(statusInt) && statusInt > 0 && statusInt < 1000) {
this.shutdownConfig.status = statusInt
} else {
this.shutdownConfig.status = 0
}
}
},
methods: {
addPage: function () {
let that = this
teaweb.popup("/servers/server/settings/pages/createPopup", {
2021-10-10 10:35:14 +08:00
height: "26em",
2020-09-20 08:58:48 +08:00
callback: function (resp) {
that.pages.push(resp.data.page)
}
})
},
updatePage: function (pageIndex, pageId) {
let that = this
teaweb.popup("/servers/server/settings/pages/updatePopup?pageId=" + pageId, {
2021-10-10 10:35:14 +08:00
height: "26em",
2020-09-20 08:58:48 +08:00
callback: function (resp) {
Vue.set(that.pages, pageIndex, resp.data.page)
}
})
},
removePage: function (pageIndex) {
let that = this
teaweb.confirm("确定要移除此页面吗?", function () {
that.pages.$remove(pageIndex)
})
2021-10-10 10:35:14 +08:00
},
addShutdownHTMLTemplate: function () {
this.shutdownConfig.body = `<!DOCTYPE html>
<html>
<head>
\t<title>升级中</title>
\t<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
</head>
<body>
2021-12-02 14:45:51 +08:00
<h1>网站升级中</h1>
2021-10-10 10:35:14 +08:00
<p>为了给您提供更好的服务我们正在升级网站请稍后重新访问</p>
2021-12-02 14:45:51 +08:00
<address>Request ID: \${requestId}, Powered by GoEdge.</address>
2021-10-10 10:35:14 +08:00
</body>
</html>`
2020-09-20 08:58:48 +08:00
}
},
template: `<div>
<input type="hidden" name="pagesJSON" :value="JSON.stringify(pages)"/>
<input type="hidden" name="shutdownJSON" :value="JSON.stringify(shutdownConfig)"/>
<table class="ui table selectable definition">
<tr>
<td class="title">特殊页面</td>
<td>
<div v-if="pages.length > 0">
2020-11-21 15:53:04 +08:00
<div class="ui label small basic" v-for="(page,index) in pages">
2021-10-10 10:35:14 +08:00
{{page.status}} -&gt; <span v-if="page.bodyType == 'url'">{{page.url}}</span><span v-if="page.bodyType == 'html'">[HTML]</span> <a href="" title="" @click.prevent="updatePage(index, page.id)"><i class="icon pencil small"></i></a> <a href="" title="" @click.prevent="removePage(index)"><i class="icon remove"></i></a>
2020-09-20 08:58:48 +08:00
</div>
<div class="ui divider"></div>
</div>
<div>
<button class="ui button small" type="button" @click.prevent="addPage()">+</button>
</div>
<p class="comment">根据响应状态码返回一些特殊页面比如404500等错误页面</p>
</td>
</tr>
<tr>
<td>临时关闭页面</td>
<td>
<div>
2020-09-26 08:07:18 +08:00
<table class="ui table selectable definition">
<prior-checkbox :v-config="shutdownConfig" v-if="vIsLocation"></prior-checkbox>
<tbody v-show="!vIsLocation || shutdownConfig.isPrior">
<tr>
<td class="title">是否开启</td>
<td>
<div class="ui checkbox">
<input type="checkbox" value="1" v-model="shutdownConfig.isOn" />
<label></label>
</div>
</td>
</tr>
</tbody>
<tbody v-show="(!vIsLocation || shutdownConfig.isPrior) && shutdownConfig.isOn">
2020-09-20 08:58:48 +08:00
<tr>
2021-10-10 10:35:14 +08:00
<td>内容类型 *</td>
<td>
<select class="ui dropdown auto-width" v-model="shutdownConfig.bodyType">
<option value="url">读取URL</option>
<option value="html">HTML</option>
</select>
</td>
</tr>
<tr v-show="shutdownConfig.bodyType == 'url'">
<td class="title">页面URL *</td>
2020-09-20 08:58:48 +08:00
<td>
<input type="text" v-model="shutdownConfig.url" placeholder="页面文件路径或一个完整URL"/>
2020-09-26 08:07:18 +08:00
<p class="comment">页面文件是相对于节点安装目录的页面文件比如pages/40x.html或者一个完整的URL</p>
2020-09-20 08:58:48 +08:00
</td>
</tr>
2021-10-10 10:35:14 +08:00
<tr v-show="shutdownConfig.bodyType == 'html'">
<td>HTML *</td>
<td>
<textarea name="body" ref="shutdownHTMLBody" v-model="shutdownConfig.body"></textarea>
<p class="comment"><a href="" @click.prevent="addShutdownHTMLTemplate">[使用模板]</a>HTML</p>
</td>
</tr>
2020-09-20 08:58:48 +08:00
<tr>
<td>状态码</td>
<td><input type="text" size="3" maxlength="3" name="shutdownStatus" style="width:5.2em" placeholder="状态码" v-model="shutdownStatus"/></td>
</tr>
2020-09-26 08:07:18 +08:00
</tbody>
</table>
<p class="comment">开启临时关闭页面时所有请求都会直接显示此页面可用于临时升级网站或者禁止用户访问某个网页</p>
2020-09-20 08:58:48 +08:00
</div>
</td>
</tr>
</table>
<div class="ui margin"></div>
</div>`
})