feat: 系统消息订阅页面

This commit is contained in:
xinwen
2021-06-01 17:48:36 +08:00
parent c7c6f5ac82
commit e8335d9c73
3 changed files with 32 additions and 29 deletions

View File

@@ -64,7 +64,7 @@ export default {
const selectedUsers = this.selectedUsers.map(item => { const selectedUsers = this.selectedUsers.map(item => {
return { return {
id: item.id, id: item.id,
label: `${item.name}(${item.username})` label: item.name
} }
}) })
setTimeout(() => { setTimeout(() => {

View File

@@ -67,7 +67,7 @@ export default {
} }
this.$axios.patch( this.$axios.patch(
`/api/v1/notifications/system/subscriptions/${sub.id}/`, `/api/v1/notifications/system-msg-subscription/${sub.id}/`,
{ receive_backends: backends } { receive_backends: backends }
).catch(err => { ).catch(err => {
this.$log.error(err) this.$log.error(err)
@@ -78,11 +78,10 @@ export default {
onDialogSelectSubmit(userIds) { onDialogSelectSubmit(userIds) {
this.dialogVisible = false this.dialogVisible = false
this.$axios.patch( this.$axios.patch(
`/api/v1/notifications/system/subscriptions/${this.currentEditSub.id}/`, `/api/v1/notifications/system-msg-subscription/${this.currentEditSub.id}/`,
{ users: userIds } { users: userIds }
).then(newSub => { ).then(newSub => {
const msgType = this.idMessageTypeMapper[newSub.id] const msgType = this.idMessageTypeMapper[newSub.message_type]
msgType.users = newSub.users
msgType.receivers = newSub.receivers msgType.receivers = newSub.receivers
}).catch(err => { }).catch(err => {
console.log(err) console.log(err)
@@ -97,40 +96,37 @@ export default {
this.receiveBackends = await this.$axios.get('/api/v1/notifications/backends/') this.receiveBackends = await this.$axios.get('/api/v1/notifications/backends/')
}, },
async initSubscriptions() { async initSubscriptions() {
const subscriptions = await this.$axios.get('/api/v1/notifications/system/subscriptions/') const subscriptions = await this.$axios.get('/api/v1/notifications/system-msg-subscription/')
// 根据 app 分组 const trans_subscriptions = []
const appMessageTypesMapper = {}
subscriptions.forEach(sub => { for (const category of subscriptions) {
if (!(sub.message_category in appMessageTypesMapper)) { const children = []
appMessageTypesMapper[sub.message_category] = { trans_subscriptions.push({
id: sub.message_category, id: category.category,
value: sub.message_category_label, value: category.category_label,
children: [sub] children: children
}
} else {
appMessageTypesMapper[sub.message_category].children.push(sub)
}
}) })
// sub 改成需要的数据结构 for (const sub of category.children) {
for (const app of Object.values(appMessageTypesMapper)) {
app.children = app.children.map(sub => {
const backendsChecked = {} const backendsChecked = {}
this.receiveBackends.forEach(backend => { this.receiveBackends.forEach(backend => {
backendsChecked[backend.name] = sub.receive_backends.indexOf(backend.name) > -1 backendsChecked[backend.name] = sub.receive_backends.indexOf(backend.name) > -1
}) })
const subObj = {
id: sub.id, const trans_sub = {
value: sub.message_label, id: sub.message_type,
value: sub.message_type_label,
receivers: sub.receivers, receivers: sub.receivers,
receive_backends: backendsChecked receive_backends: backendsChecked
} }
this.idMessageTypeMapper[sub.id] = subObj children.push(trans_sub)
return subObj
}) this.idMessageTypeMapper[trans_sub.id] = trans_sub
} }
this.tableData = Object.values(appMessageTypesMapper) }
this.tableData = trans_subscriptions
} }
} }
} }

View File

@@ -69,6 +69,10 @@ export default {
title: this.$t('setting.DingTalk'), title: this.$t('setting.DingTalk'),
name: 'DingTalk' name: 'DingTalk'
}, },
{
title: this.$t('setting.SystemMessageSubscription'),
name: 'SystemMessageSubscription'
},
{ {
title: this.$t('setting.Terminal'), title: this.$t('setting.Terminal'),
name: 'Terminal' name: 'Terminal'
@@ -119,6 +123,9 @@ export default {
case 'License': case 'License':
this.activeMenu = 'License' this.activeMenu = 'License'
break break
case 'SystemMessageSubscription':
this.activeMenu = 'SystemMessageSubscription'
break
default: default:
this.activeMenu = 'Basic' this.activeMenu = 'Basic'
break break