实现URL跳转功能

This commit is contained in:
刘祥超
2021-01-10 17:34:30 +08:00
parent 0940fce743
commit e70ba457b2
12 changed files with 293 additions and 9 deletions
Vendored Executable → Regular
+2 -8
View File
File diff suppressed because one or more lines are too long
Executable → Regular
+1 -1
View File
File diff suppressed because one or more lines are too long
@@ -0,0 +1,61 @@
Vue.component("http-host-redirect-box", {
props: ["v-redirects"],
data: function () {
let redirects = this.vRedirects
if (redirects == null) {
redirects = []
}
return {
redirects: redirects,
statusOptions: [
{"code": 301, "text": "Moved Permanently"},
{"code": 308, "text": "Permanent Redirect"},
{"code": 302, "text": "Found"},
{"code": 303, "text": "See Other"},
{"code": 307, "text": "Temporary Redirect"}
]
}
},
methods: {
add: function () {
let that = this
window.UPDATING_REDIRECT = null
teaweb.popup("/servers/server/settings/redirects/createPopup", {
height: "22em",
callback: function (resp) {
that.redirects.push(resp.data.redirect)
}
})
},
update: function (index, redirect) {
let that = this
window.UPDATING_REDIRECT = redirect
teaweb.popup("/servers/server/settings/redirects/createPopup", {
height: "22em",
callback: function (resp) {
Vue.set(that.redirects, index, resp.data.redirect)
}
})
},
remove: function (index) {
this.redirects.$remove(index)
}
},
template: `<div>
<input type="hidden" name="hostRedirectsJSON" :value="JSON.stringify(redirects)"/>
<!-- TODO 将来支持排序,并支持isOn切换 -->
<div v-if="redirects.length > 0">
<div v-for="(redirect, index) in redirects" class="ui label basic small" style="margin-bottom: 0.5em;margin-top: 0.5em">
<span v-if="redirect.status > 0">[{{redirect.status}}]</span> {{redirect.beforeURL}} -&gt; {{redirect.afterURL}} <a href="" @click.prevent="update(index, redirect)" title="修改"><i class="icon pencil small"></i></a> &nbsp; <a href="" @click.prevent="remove(index)" title="删除"><i class="icon remove"></i></a>
</div>
<div class="ui divider"></div>
</div>
<div>
<button type="button" class="ui button tiny" @click.prevent="add">+</button>
</div>
</div>`
})
@@ -0,0 +1,36 @@
{$layout "layout_popup"}
<h3 v-if="isCreating">添加URL跳转</h3>
<h3 v-if="!isCreating">修改URL跳转</h3>
<form class="ui form" data-tea-success="success" data-tea-action="$">
<csrf-token></csrf-token>
<table class="ui table definition selectable">
<tr>
<td>跳转前URL *</td>
<td>
<input type="text" name="beforeURL" placeholder="比如 http://www.url1.com" v-model="redirect.beforeURL" ref="focus"/>
<p class="comment">需要填写完整的URL,包括<code-label>http://</code-label>或者<code-label>https://</code-label>,如果有非默认端口,也需要带上端口号。</p>
</td>
</tr>
<tr>
<td>跳转后URL *</td>
<td>
<input type="text" name="afterURL" placeholder="比如 https://www.url2.cn" v-model="redirect.afterURL"/>
<p class="comment">需要填写完整的URL,包括<code-label>http://</code-label>或者<code-label>https://</code-label>,如果有非默认端口,也需要带上端口号。</p>
</td>
</tr>
<tr>
<td class="title">跳转状态码</td>
<td>
<select class="ui dropdown auto-width" name="status" v-model="redirect.status">
<option value="0">[默认]</option>
<option v-for="status in statusList" :value="status.code">{{status.code}} - {{status.text}}</option>
</select>
</td>
</tr>
</table>
<submit-btn></submit-btn>
</form>
@@ -0,0 +1,13 @@
Tea.context(function () {
this.isCreating = true
if (window.parent.UPDATING_REDIRECT != null) {
this.isCreating = false
this.redirect = window.parent.UPDATING_REDIRECT
} else {
this.redirect = {
status: 0,
beforeURL: "",
afterURL: ""
}
}
})
@@ -0,0 +1,17 @@
{$layout}
{$template "/left_menu"}
<div class="right-box">
<form class="ui form" method="post" data-tea-action="$" data-tea-success="success">
<input type="hidden" name="webId" :value="webId"/>
<table class="ui table selectable definition">
<tr>
<td class="title">URL跳转设置</td>
<td>
<http-host-redirect-box :v-redirects="redirects"></http-host-redirect-box>
</td>
</tr>
</table>
<submit-btn></submit-btn>
</form>
</div>
@@ -0,0 +1,3 @@
Tea.context(function () {
this.success = NotifyReloadSuccess("保存成功")
})