增加消息管理

This commit is contained in:
GoEdgeLab
2020-10-20 20:18:12 +08:00
parent 957b5b620c
commit 10faba32ea
15 changed files with 274 additions and 3 deletions

View File

@@ -0,0 +1,38 @@
Vue.component("message-row", {
props: ["v-message"],
data: function () {
let paramsJSON = this.vMessage.params
let params = null
if (paramsJSON != null && paramsJSON.length > 0) {
params = JSON.parse(paramsJSON)
}
return {
message: this.vMessage,
params: params
}
},
template: `<div>
<table class="ui table selectable">
<tr :class="{error: message.level == 'error'}">
<td>
<strong>{{message.datetime}}</strong>
<span v-if="message.cluster != null && message.cluster.id != null">
<span> | </span>
<a :href="'/clusters/cluster?clusterId=' + message.cluster.id">集群:{{message.cluster.name}}</a>
</span>
</td>
</tr>
<tr :class="{error: message.level == 'error'}">
<td>
{{message.body}}
<div v-if="message.type == 'HealthCheckFail'" style="margin-top: 0.8em">
<a :href="'/clusters/cluster/node?clusterId=' + message.cluster.id + '&nodeId=' + param.node.id" v-for="param in params" class="ui label tiny">{{param.node.name}}</a>
</div>
</td>
</tr>
</table>
<div class="margin"></div>
</div>`
})

View File

@@ -28,7 +28,7 @@
<div class="right menu">
<a href="" class="item" v-if="globalChangedClusters.length > 0" @click.prevent="syncClustersConfigs()"><i class="icon refresh"></i>{{globalChangedClusters.length}}个集群服务已变更,点此同步</a>
<a href="/monitor/messages" class="item" v-if="teaBadge > 0"><span :class="{'blink':teaBadge > 0}"><i class="icon bell"></i>告警({{teaBadge}}) </span></a>
<a href="/messages" class="item" :class="{active:teaMenu == 'message'}"><span :class="{'blink':globalMessageBadge > 0}"><i class="icon bell"></i>消息({{globalMessageBadge}}) </span></a>
<a href="/settings/profile" class="item" :class="{active: teaMenu == 'settings'}">
<i class="icon user" v-if="teaUserAvatar.length == 0"></i>
<img class="avatar" alt="" :src="teaUserAvatar" v-if="teaUserAvatar.length > 0"/>

View File

@@ -1,6 +1,7 @@
Tea.context(function () {
this.moreOptionsVisible = false
this.globalChangedClusters = []
this.globalMessageBadge = 0
this.teaDemoEnabled = false
if (typeof this.leftMenuItemIsDisabled == "undefined") {
@@ -14,6 +15,9 @@ Tea.context(function () {
// 检查变更
this.checkClusterChanges()
// 检查消息
this.checkMessages()
})
/**
@@ -58,7 +62,27 @@ Tea.context(function () {
this.checkClusterChanges()
}, delay)
})
};
}
/**
* 检查消息
*/
this.checkMessages = function () {
this.$post("/messages/badge")
.params({})
.success(function (resp) {
this.globalMessageBadge = resp.data.count
})
.done(function () {
let delay = 6000
if (this.globalMessageBadge > 0) {
delay = 30000
}
this.$delay(function () {
this.checkMessages()
}, delay)
})
}
/**
* 同步集群配置

View File

@@ -0,0 +1,13 @@
{$layout}
<first-menu v-if="messages.length > 0">
<a href="" class="item" @click.prevent="updatePageRead()">[设置当前页为已读]</a>
<a href="" class="item" @click.prevent="updateAllRead()">[设置全部为已读]</a>
</first-menu>
<div class="margin"></div>
<p class="comment" v-if="messages.length == 0">暂时还没有消息。</p>
<message-row v-for="message in messages" :v-message="message" :key="message.id"></message-row>
<div class="page" v-html="page"></div>

View File

@@ -0,0 +1,26 @@
Tea.context(function () {
this.updateAllRead = function () {
let that = this
teaweb.confirm("确定要设置所有的未读消息为已读吗?", function () {
that.$post("/messages/readAll")
.success(function () {
window.location = "/messages"
})
})
}
this.updatePageRead = function () {
let that = this
teaweb.confirm("确定要设置当前页的未读消息为已读吗?", function () {
let messageIds = []
that.messages.forEach(function (v) {
messageIds.push(v.id)
})
that.$post("/messages/readPage")
.params({
messageIds: messageIds
})
.refresh()
})
}
})