Files
EdgeAdmin/web/public/js/components/server/http-request-conds-box.js

112 lines
3.8 KiB
JavaScript
Raw Normal View History

2020-10-02 17:22:24 +08:00
Vue.component("http-request-conds-box", {
props: ["v-conds"],
data: function () {
let conds = this.vConds
if (conds == null) {
conds = {
isOn: true,
connector: "or",
groups: []
}
}
2022-09-03 18:14:34 +08:00
if (conds.groups == null) {
conds.groups = []
}
2020-10-02 17:22:24 +08:00
return {
conds: conds,
components: window.REQUEST_COND_COMPONENTS
}
},
methods: {
2020-10-04 20:38:27 +08:00
change: function () {
this.$emit("change", this.conds)
},
2020-10-02 17:22:24 +08:00
addGroup: function () {
2020-10-04 20:38:27 +08:00
window.UPDATING_COND_GROUP = null
2020-10-02 17:22:24 +08:00
let that = this
teaweb.popup("/servers/server/settings/conds/addGroupPopup", {
height: "30em",
callback: function (resp) {
that.conds.groups.push(resp.data.group)
2020-10-04 20:38:27 +08:00
that.change()
2020-10-02 17:22:24 +08:00
}
})
},
updateGroup: function (groupIndex, group) {
window.UPDATING_COND_GROUP = group
let that = this
teaweb.popup("/servers/server/settings/conds/addGroupPopup", {
height: "30em",
callback: function (resp) {
Vue.set(that.conds.groups, groupIndex, resp.data.group)
2020-10-04 20:38:27 +08:00
that.change()
2020-10-02 17:22:24 +08:00
}
})
},
removeGroup: function (groupIndex) {
let that = this
teaweb.confirm("确定要删除这一组条件吗?", function () {
that.conds.groups.$remove(groupIndex)
2020-10-04 20:38:27 +08:00
that.change()
2020-10-02 17:22:24 +08:00
})
},
typeName: function (cond) {
let c = this.components.$find(function (k, v) {
return v.type == cond.type
})
if (c != null) {
return c.name;
}
return cond.param + " " + cond.operator
}
},
template: `<div>
<input type="hidden" name="condsJSON" :value="JSON.stringify(conds)"/>
<div v-if="conds.groups.length > 0">
<table class="ui table">
<tr v-for="(group, groupIndex) in conds.groups">
<td class="title" :class="{'color-border':conds.connector == 'and'}" :style="{'border-bottom':(groupIndex < conds.groups.length-1) ? '1px solid rgba(34,36,38,.15)':''}">分组{{groupIndex+1}}</td>
2022-02-15 14:54:45 +08:00
<td style="background: white; word-break: break-all" :style="{'border-bottom':(groupIndex < conds.groups.length-1) ? '1px solid rgba(34,36,38,.15)':''}">
2020-10-02 17:22:24 +08:00
<var v-for="(cond, index) in group.conds" style="font-style: normal;display: inline-block; margin-bottom:0.5em">
<span class="ui label tiny">
2021-06-09 17:14:31 +08:00
<var v-if="cond.type.length == 0 || cond.type == 'params'" style="font-style: normal">{{cond.param}} <var>{{cond.operator}}</var></var>
<var v-if="cond.type.length > 0 && cond.type != 'params'" style="font-style: normal">{{typeName(cond)}}: </var>
2020-10-02 17:22:24 +08:00
{{cond.value}}
<sup v-if="cond.isCaseInsensitive" title="不区分大小写"><i class="icon info small"></i></sup>
2020-10-02 17:22:24 +08:00
</span>
<var v-if="index < group.conds.length - 1"> {{group.connector}} &nbsp;</var>
</var>
</td>
<td style="width: 5em; background: white" :style="{'border-bottom':(groupIndex < conds.groups.length-1) ? '1px solid rgba(34,36,38,.15)':''}">
<a href="" title="修改分组" @click.prevent="updateGroup(groupIndex, group)"><i class="icon pencil small"></i></a> <a href="" title="" @click.prevent="removeGroup(groupIndex)"><i class="icon remove"></i></a>
2020-10-02 17:22:24 +08:00
</td>
</tr>
</table>
<div class="ui divider"></div>
</div>
<!-- 分组之间关系 -->
<table class="ui table" v-if="conds.groups.length > 1">
<tr>
<td class="title">分组之间关系</td>
<td>
<select class="ui dropdown auto-width" v-model="conds.connector">
<option value="and"></option>
<option value="or"></option>
</select>
<p class="comment">
<span v-if="conds.connector == 'or'">只要满足其中一个条件分组即可</span>
<span v-if="conds.connector == 'and'">需要满足所有条件分组</span>
</p>
</td>
</tr>
</table>
2020-10-02 17:22:24 +08:00
<div>
<button class="ui button tiny" type="button" @click.prevent="addGroup()">+添加分组</button>
2020-10-02 17:22:24 +08:00
</div>
</div>
</div>`
})