EmailCallback.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <template>
  2. <a-form
  3. :form="form.fc"
  4. v-bind="formItemLayout">
  5. <a-alert type="warning" :message="$t('system.text_274')" class="mb-2" />
  6. <a-form-item :label="$t('system.text_275')">
  7. <a-input v-decorator="decorators.address" />
  8. </a-form-item>
  9. <a-form-item :wrapper-col="offsetWrapperCol">
  10. <a-button type="primary" @click="handleSubmit" :loading="submiting">{{ $t('common.ok') }}</a-button>
  11. </a-form-item>
  12. </a-form>
  13. </template>
  14. <script>
  15. export default {
  16. name: 'EmailCallbackConfig',
  17. props: {
  18. formItemLayout: {
  19. required: true,
  20. type: Object,
  21. },
  22. offsetWrapperCol: {
  23. required: true,
  24. type: Object,
  25. },
  26. loading: Boolean,
  27. },
  28. data () {
  29. return {
  30. submiting: false,
  31. mailCallbackId: null,
  32. form: {
  33. fc: this.$form.createForm(this),
  34. },
  35. decorators: {
  36. address: [
  37. 'address',
  38. {
  39. rules: [
  40. { required: true, message: this.$t('system.text_276') },
  41. ],
  42. },
  43. ],
  44. },
  45. }
  46. },
  47. destroyed () {
  48. this.manager = null
  49. },
  50. created () {
  51. this.manager = new this.$Manager('parameters', 'v1')
  52. this.fetchData()
  53. },
  54. methods: {
  55. async fetchData () {
  56. this.$emit('update:loading', true)
  57. try {
  58. const response = await this.manager.get({
  59. id: 'mail-call-back-address',
  60. params: {
  61. service: 'itsm',
  62. scope: this.$store.getters.scope,
  63. },
  64. })
  65. this.mailCallbackId = response.data && response.data.id
  66. this.$nextTick(() => {
  67. this.form.fc.setFieldsValue({
  68. ...response.data.value || {},
  69. })
  70. })
  71. } catch (error) {
  72. throw error
  73. } finally {
  74. this.$emit('update:loading', false)
  75. }
  76. },
  77. async handleSubmit () {
  78. this.submiting = true
  79. try {
  80. const values = await this.form.fc.validateFields()
  81. if (this.mailCallbackId) {
  82. await this.manager.update({
  83. id: this.mailCallbackId,
  84. data: {
  85. service: 'itsm',
  86. value: values,
  87. },
  88. })
  89. } else {
  90. await this.manager.create({
  91. data: {
  92. service: 'itsm',
  93. name: 'mail-call-back-address',
  94. value: values,
  95. },
  96. })
  97. }
  98. this.$message.success(this.$t('system.text_277'))
  99. } catch (error) {
  100. throw error
  101. } finally {
  102. this.submiting = false
  103. }
  104. },
  105. },
  106. }
  107. </script>