Initial commit (code only without large binaries)
This commit is contained in:
@@ -0,0 +1,176 @@
|
||||
Vue.component("ad-instance-objects-box", {
|
||||
props: ["v-objects", "v-user-id"],
|
||||
mounted: function () {
|
||||
this.getUserServers(1)
|
||||
},
|
||||
data: function () {
|
||||
let objects = this.vObjects
|
||||
if (objects == null) {
|
||||
objects = []
|
||||
}
|
||||
|
||||
let objectCodes = []
|
||||
objects.forEach(function (v) {
|
||||
objectCodes.push(v.code)
|
||||
})
|
||||
|
||||
return {
|
||||
userId: this.vUserId,
|
||||
objects: objects,
|
||||
objectCodes: objectCodes,
|
||||
isAdding: true,
|
||||
|
||||
servers: [],
|
||||
serversIsLoading: false
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
add: function () {
|
||||
this.isAdding = true
|
||||
},
|
||||
cancel: function () {
|
||||
this.isAdding = false
|
||||
},
|
||||
remove: function (index) {
|
||||
let that = this
|
||||
teaweb.confirm("确定要删除此防护对象吗?", function () {
|
||||
that.objects.$remove(index)
|
||||
that.notifyChange()
|
||||
})
|
||||
},
|
||||
removeObjectCode: function (objectCode) {
|
||||
let index = -1
|
||||
this.objectCodes.forEach(function (v, k) {
|
||||
if (objectCode == v) {
|
||||
index = k
|
||||
}
|
||||
})
|
||||
if (index >= 0) {
|
||||
this.objects.$remove(index)
|
||||
this.notifyChange()
|
||||
}
|
||||
},
|
||||
getUserServers: function (page) {
|
||||
if (Tea.Vue == null) {
|
||||
let that = this
|
||||
setTimeout(function () {
|
||||
that.getUserServers(page)
|
||||
}, 100)
|
||||
return
|
||||
}
|
||||
|
||||
let that = this
|
||||
this.serversIsLoading = true
|
||||
Tea.Vue.$post(".userServers")
|
||||
.params({
|
||||
userId: this.userId,
|
||||
page: page,
|
||||
pageSize: 5
|
||||
})
|
||||
.success(function (resp) {
|
||||
that.servers = resp.data.servers
|
||||
|
||||
that.$refs.serverPage.updateMax(resp.data.page.max)
|
||||
that.serversIsLoading = false
|
||||
})
|
||||
.error(function () {
|
||||
that.serversIsLoading = false
|
||||
})
|
||||
},
|
||||
changeServerPage: function (page) {
|
||||
this.getUserServers(page)
|
||||
},
|
||||
selectServerObject: function (server) {
|
||||
if (this.existObjectCode("server:" + server.id)) {
|
||||
return
|
||||
}
|
||||
|
||||
this.objects.push({
|
||||
"type": "server",
|
||||
"code": "server:" + server.id,
|
||||
|
||||
"id": server.id,
|
||||
"name": server.name
|
||||
})
|
||||
this.notifyChange()
|
||||
},
|
||||
notifyChange: function () {
|
||||
let objectCodes = []
|
||||
this.objects.forEach(function (v) {
|
||||
objectCodes.push(v.code)
|
||||
})
|
||||
this.objectCodes = objectCodes
|
||||
},
|
||||
existObjectCode: function (objectCode) {
|
||||
let found = false
|
||||
this.objects.forEach(function (v) {
|
||||
if (v.code == objectCode) {
|
||||
found = true
|
||||
}
|
||||
})
|
||||
return found
|
||||
}
|
||||
},
|
||||
template: `<div>
|
||||
<input type="hidden" name="objectCodesJSON" :value="JSON.stringify(objectCodes)"/>
|
||||
|
||||
<!-- 已有对象 -->
|
||||
<div>
|
||||
<div v-if="objects.length == 0"><span class="grey">暂时还没有设置任何防护对象。</span></div>
|
||||
<div v-if="objects.length > 0">
|
||||
<table class="ui table">
|
||||
<tr>
|
||||
<td class="title">已选中防护对象</td>
|
||||
<td>
|
||||
<div v-for="(object, index) in objects" class="ui label basic small" style="margin-bottom: 0.5em">
|
||||
<span v-if="object.type == 'server'">网站:{{object.name}}</span>
|
||||
<a href="" title="删除" @click.prevent="remove(index)"><i class="icon remove small"></i></a>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
<div class="margin"></div>
|
||||
|
||||
<!-- 添加表单 -->
|
||||
<div v-if="isAdding">
|
||||
<table class="ui table celled">
|
||||
<tr>
|
||||
<td class="title">对象类型</td>
|
||||
<td>网站</td>
|
||||
</tr>
|
||||
<!-- 网站列表 -->
|
||||
<tr>
|
||||
<td>网站列表</td>
|
||||
<td>
|
||||
<span v-if="serversIsLoading">加载中...</span>
|
||||
<div v-if="!serversIsLoading && servers.length == 0">暂时还没有可选的网站。</div>
|
||||
<table class="ui table" v-show="!serversIsLoading && servers.length > 0">
|
||||
<thead class="full-width">
|
||||
<tr>
|
||||
<th>网站名称</th>
|
||||
<th class="one op">操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tr v-for="server in servers">
|
||||
<td style="background: white">{{server.name}}</td>
|
||||
<td>
|
||||
<a href="" @click.prevent="selectServerObject(server)" v-if="!existObjectCode('server:' + server.id)">选中</a>
|
||||
<a href="" @click.prevent="removeObjectCode('server:' + server.id)" v-else><span class="red">取消</span></a>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<js-page ref="serverPage" @change="changeServerPage"></js-page>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<!-- 添加按钮 -->
|
||||
<div v-if="!isAdding">
|
||||
<button class="ui button tiny" type="button" @click.prevent="add">+</button>
|
||||
</div>
|
||||
</div>`
|
||||
})
|
||||
Reference in New Issue
Block a user