From e8335d9c7366a79de9b2f93cd3e63076d059014e Mon Sep 17 00:00:00 2001 From: xinwen Date: Tue, 1 Jun 2021 17:48:36 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=B3=BB=E7=BB=9F=E6=B6=88=E6=81=AF?= =?UTF-8?q?=E8=AE=A2=E9=98=85=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SelectDialog.vue | 2 +- .../Subscription.vue | 52 +++++++++---------- src/views/settings/index.vue | 7 +++ 3 files changed, 32 insertions(+), 29 deletions(-) diff --git a/src/views/settings/SystemMessageSubscription/SelectDialog.vue b/src/views/settings/SystemMessageSubscription/SelectDialog.vue index 49f4f8c86..fa3ab34f9 100644 --- a/src/views/settings/SystemMessageSubscription/SelectDialog.vue +++ b/src/views/settings/SystemMessageSubscription/SelectDialog.vue @@ -64,7 +64,7 @@ export default { const selectedUsers = this.selectedUsers.map(item => { return { id: item.id, - label: `${item.name}(${item.username})` + label: item.name } }) setTimeout(() => { diff --git a/src/views/settings/SystemMessageSubscription/Subscription.vue b/src/views/settings/SystemMessageSubscription/Subscription.vue index c096276be..230669393 100644 --- a/src/views/settings/SystemMessageSubscription/Subscription.vue +++ b/src/views/settings/SystemMessageSubscription/Subscription.vue @@ -67,7 +67,7 @@ export default { } this.$axios.patch( - `/api/v1/notifications/system/subscriptions/${sub.id}/`, + `/api/v1/notifications/system-msg-subscription/${sub.id}/`, { receive_backends: backends } ).catch(err => { this.$log.error(err) @@ -78,11 +78,10 @@ export default { onDialogSelectSubmit(userIds) { this.dialogVisible = false this.$axios.patch( - `/api/v1/notifications/system/subscriptions/${this.currentEditSub.id}/`, + `/api/v1/notifications/system-msg-subscription/${this.currentEditSub.id}/`, { users: userIds } ).then(newSub => { - const msgType = this.idMessageTypeMapper[newSub.id] - msgType.users = newSub.users + const msgType = this.idMessageTypeMapper[newSub.message_type] msgType.receivers = newSub.receivers }).catch(err => { console.log(err) @@ -97,40 +96,37 @@ export default { this.receiveBackends = await this.$axios.get('/api/v1/notifications/backends/') }, 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 appMessageTypesMapper = {} - subscriptions.forEach(sub => { - if (!(sub.message_category in appMessageTypesMapper)) { - appMessageTypesMapper[sub.message_category] = { - id: sub.message_category, - value: sub.message_category_label, - children: [sub] - } - } else { - appMessageTypesMapper[sub.message_category].children.push(sub) - } - }) + const trans_subscriptions = [] - // sub 改成需要的数据结构 - for (const app of Object.values(appMessageTypesMapper)) { - app.children = app.children.map(sub => { + for (const category of subscriptions) { + const children = [] + trans_subscriptions.push({ + id: category.category, + value: category.category_label, + children: children + }) + + for (const sub of category.children) { const backendsChecked = {} this.receiveBackends.forEach(backend => { backendsChecked[backend.name] = sub.receive_backends.indexOf(backend.name) > -1 }) - const subObj = { - id: sub.id, - value: sub.message_label, + + const trans_sub = { + id: sub.message_type, + value: sub.message_type_label, receivers: sub.receivers, receive_backends: backendsChecked } - this.idMessageTypeMapper[sub.id] = subObj - return subObj - }) + children.push(trans_sub) + + this.idMessageTypeMapper[trans_sub.id] = trans_sub + } } - this.tableData = Object.values(appMessageTypesMapper) + + this.tableData = trans_subscriptions } } } diff --git a/src/views/settings/index.vue b/src/views/settings/index.vue index c03ae1ad5..73db1939b 100644 --- a/src/views/settings/index.vue +++ b/src/views/settings/index.vue @@ -69,6 +69,10 @@ export default { title: this.$t('setting.DingTalk'), name: 'DingTalk' }, + { + title: this.$t('setting.SystemMessageSubscription'), + name: 'SystemMessageSubscription' + }, { title: this.$t('setting.Terminal'), name: 'Terminal' @@ -119,6 +123,9 @@ export default { case 'License': this.activeMenu = 'License' break + case 'SystemMessageSubscription': + this.activeMenu = 'SystemMessageSubscription' + break default: this.activeMenu = 'Basic' break