SetupNotifyChannel.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <template>
  2. <base-dialog @cancel="cancelDialog">
  3. <div slot="header">{{ $t('system.management_notify_channels') }}</div>
  4. <div slot="body">
  5. <dialog-selected-tips :count="params.data.length" :action="$t('system.text_142')" :name="$t('system.text_317')" />
  6. <dialog-table :data="params.data" :columns="params.columns.slice(0, 5)" />
  7. <a-form :form="form" v-bind="formItemLayout">
  8. <a-form-item>
  9. <span slot="label">
  10. {{ $t('common_599') }}
  11. <a-tooltip effect="dark" placement="top">
  12. <a-icon type="info-circle" />
  13. <div slot="title">{{$t('system.contact')}}</div>
  14. </a-tooltip>
  15. </span>
  16. <a-checkbox-group
  17. v-decorator="decorators.enabled_contact_types">
  18. <a-checkbox
  19. v-for="(v, index) in contactArrOpts"
  20. :key="index"
  21. :value="v.value"
  22. :disabled="v.disabled">
  23. {{ v.label }}
  24. </a-checkbox>
  25. </a-checkbox-group>
  26. </a-form-item>
  27. </a-form>
  28. </div>
  29. <div slot="footer">
  30. <a-button type="primary" @click="handleConfirm" :loading="loading">{{ $t('dialog.ok') }}</a-button>
  31. <a-button @click="cancelDialog">{{ $t('dialog.cancel') }}</a-button>
  32. </div>
  33. </base-dialog>
  34. </template>
  35. <script>
  36. import * as R from 'ramda'
  37. import { contactMap } from '@/constants'
  38. import DialogMixin from '@/mixins/dialog'
  39. import WindowsMixin from '@/mixins/windows'
  40. export default {
  41. name: 'SetupNotifyChannelsDialog',
  42. mixins: [DialogMixin, WindowsMixin],
  43. data () {
  44. const initialValue = {
  45. enabled_contact_types: ['webconsole'],
  46. }
  47. return {
  48. form: this.$form.createForm(this),
  49. contactArrOpts: [],
  50. decorators: {
  51. enabled_contact_types: [
  52. 'enabled_contact_types',
  53. {
  54. initialValue: initialValue.enabled_contact_types,
  55. },
  56. ],
  57. },
  58. formItemLayout: {
  59. wrapperCol: {
  60. span: 18,
  61. },
  62. labelCol: {
  63. span: 6,
  64. },
  65. },
  66. }
  67. },
  68. created () {
  69. this.generateContactArrOpts()
  70. },
  71. methods: {
  72. fetchConfig () {
  73. return new Promise((resolve, reject) => {
  74. new this.$Manager('receivers', 'v1').performClassAction({ action: 'get-types', data: {} }).then((res) => {
  75. const { types } = res.data
  76. resolve(types)
  77. }).catch((err) => {
  78. reject(err)
  79. })
  80. })
  81. },
  82. async generateContactArrOpts () {
  83. let config_contact_types = []
  84. try {
  85. config_contact_types = await this.fetchConfig()
  86. } catch (error) {
  87. throw error
  88. }
  89. const contactArrOpts = config_contact_types.filter((item) => {
  90. return !item.includes('robot')
  91. }).map((item) => {
  92. return {
  93. label: contactMap[item].label || item,
  94. value: item,
  95. disabled: item === 'webconsole',
  96. }
  97. })
  98. this.contactArrOpts = contactArrOpts
  99. },
  100. async handleConfirm () {
  101. this.loading = true
  102. try {
  103. const data = await this.form.validateFields()
  104. const ids = this.params.data.map((item) => { return item.id })
  105. await this.params.onManager('batchUpdate', {
  106. id: ids,
  107. managerArgs: { data: data },
  108. })
  109. this.loading = false
  110. if (this.params.success && R.is(Function, this.params.success)) {
  111. this.params.success()
  112. }
  113. this.cancelDialog()
  114. } catch (e) {
  115. this.loading = false
  116. throw e
  117. }
  118. },
  119. },
  120. }
  121. </script>
  122. <style scoped>
  123. </style>