实现发送消息到媒介

This commit is contained in:
刘祥超
2021-04-12 19:19:59 +08:00
parent 7ffff890a8
commit a637783249
18 changed files with 425 additions and 24 deletions

View File

@@ -0,0 +1,58 @@
// 消息接收人设置
Vue.component("message-receivers-box", {
props: ["v-node-cluster-id"],
mounted: function () {
let that = this
Tea.action("/clusters/cluster/settings/message/selectedReceivers")
.params({
clusterId: this.clusterId
})
.post()
.success(function (resp) {
that.receivers = resp.data.receivers
})
},
data: function () {
let clusterId = this.vNodeClusterId
if (clusterId == null) {
clusterId = 0
}
return {
clusterId: clusterId,
receivers: []
}
},
methods: {
addReceiver: function () {
let that = this
let recipientIdStrings = []
let groupIdStrings = []
this.receivers.forEach(function (v) {
if (v.type == "recipient") {
recipientIdStrings.push(v.id.toString())
} else if (v.type == "group") {
groupIdStrings.push(v.id.toString())
}
})
teaweb.popup("/clusters/cluster/settings/message/selectReceiverPopup?recipientIds=" + recipientIdStrings.join(",") + "&groupIds=" + groupIdStrings.join(","), {
callback: function (resp) {
that.receivers.push(resp.data)
}
})
},
removeReceiver: function (index) {
this.receivers.$remove(index)
}
},
template: `<div>
<input type="hidden" name="receiversJSON" :value="JSON.stringify(receivers)"/>
<div v-if="receivers.length > 0">
<div v-for="(receiver, index) in receivers" class="ui label basic small">
<span v-if="receiver.type == 'group'">分组:</span>{{receiver.name}} <span class="grey small" v-if="receiver.subName != null && receiver.subName.length > 0">({{receiver.subName}})</span> &nbsp; <a href="" title="删除" @click.prevent="removeReceiver(index)"><i class="icon remove"></i></a>
</div>
<div class="ui divider"></div>
</div>
<button type="button" class="ui button tiny" @click.prevent="addReceiver">+</button>
</div>`
})

View File

@@ -181,6 +181,11 @@ window.teaweb = {
var hash = window.location.hash;
return hash != null && hash.startsWith("#popup");
},
closePopup: function () {
if (this.isPopup()) {
window.parent.Swal.close();
}
},
Swal: function () {
return this.isPopup() ? window.parent.Swal : window.Swal;
},

View File

@@ -10,6 +10,7 @@
<table class="ui table selectable celled" v-if="instances.length > 0">
<thead>
<tr>
<th>媒介名称</th>
<th class="three wide">媒介类型</th>
<th>备注</th>
<th class="two wide">状态</th>
@@ -17,6 +18,7 @@
</tr>
</thead>
<tr v-for="instance in instances">
<td>{{instance.name}}</td>
<td>{{instance.media.name}}</td>
<td>
<span v-if="instance.description.length > 0">{{instance.description}}</span>

View File

@@ -5,11 +5,11 @@
<div v-if="logs.length > 0">
<div class="margin"></div>
<table class="ui table selectable definition" v-for="log in logs" :class="{red: !log.isOk}">
<table class="ui table selectable definition" v-for="log in logs" :class="{red: !log.isOk, green: log.isOk}">
<tr>
<td class="title">简介</td>
<td>接收人:{{log.task.user}} <span class="disabled">&nbsp; | &nbsp;</span> 媒介:{{log.task.instance.name}}<link-icon :href="'/admins/recipients/instances/instance?instanceId=' + log.task.instance.id"></link-icon>
<span class="disabled">&nbsp; | &nbsp;</span> 时间:{{log.createdTime}}
<span class="disabled">&nbsp; | &nbsp;</span> 时间:{{log.createdTime}} &nbsp;|&nbsp; <span class="ui green basic label tiny" v-if="log.isOk">成功</span><span class="ui red basic label tiny" v-if="!log.isOk">失败</span>
</td>
</tr>
<tr v-if="log.task.subject.length > 0">

View File

@@ -0,0 +1,20 @@
{$layout}
{$template "/left_menu"}
<div class="right-box">
<form class="ui form" data-tea-action="$" data-tea-success="success">
<csrf-token></csrf-token>
<input type="hidden" name="clusterId" :value="clusterId"/>
<table class="ui table selectable definition">
<tr>
<td class="title">消息接收人</td>
<td>
<message-receivers-box :v-node-cluster-id="clusterId"></message-receivers-box>
</td>
</tr>
</table>
<submit-btn></submit-btn>
</form>
</div>

View File

@@ -0,0 +1,3 @@
Tea.context(function () {
this.success = NotifyReloadSuccess("保存成功")
})

View File

@@ -0,0 +1,36 @@
{$layout "layout_popup"}
<h3>选择接收人</h3>
<form class="ui form">
<table class="ui table definition">
<tr>
<td class="title">选择接收人</td>
<td>
<div v-if="recipients.length == 0">
<span class="disabled">暂时没有接收人。</span>
</div>
<div v-else>
<a class="ui label small basic" :class="{blue: selectedRecipient != null && recipient.id == selectedRecipient.id}" v-for="recipient in recipients" @click.prevent="selectRecipient(recipient)">
{{recipient.name}} &nbsp; <span class="small grey">({{recipient.instanceName}})</span>
</a>
</div>
</td>
</tr>
<tr>
<td>选择接收人分组</td>
<td>
<div v-if="groups.length == 0">
<span class="disabled">暂时没有接收人分组。</span>
</div>
<div v-else>
<a class="ui label small basic" :class="{blue: selectedGroup != null && group.id == selectedGroup.id}" v-for="group in groups" @click.prevent="selectGroup(group)">
分组:{{group.name}}
</a>
</div>
</td>
</tr>
</table>
<button type="button" class="ui button primary" @click.prevent="confirm">确定</button>
</form>

View File

@@ -0,0 +1,40 @@
Tea.context(function () {
this.selectedRecipient = null
this.selectedGroup = null
this.selectRecipient = function (recipient) {
this.selectedRecipient = recipient
this.selectedGroup = null
}
this.selectGroup = function (group) {
this.selectedRecipient = null
this.selectedGroup = group
}
this.confirm = function () {
if (this.selectedRecipient != null) {
NotifyPopup({
code: 200,
data: {
id: this.selectedRecipient.id,
name: this.selectedRecipient.name,
subName: this.selectedRecipient.instanceName,
type: "recipient"
}
})
} else if (this.selectedGroup != null) {
NotifyPopup({
code: 200,
data: {
id: this.selectedGroup.id,
name: this.selectedGroup.name,
type: "group"
}
})
} else {
teaweb.closePopup()
}
}
})