Email.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. <template>
  2. <a-form
  3. :form="form.fc"
  4. v-bind="formItemLayout">
  5. <a-form-item :label="$t('system.text_269')">
  6. <a-input v-decorator="decorators.hostname" />
  7. </a-form-item>
  8. <a-form-item label="SSL">
  9. <a-switch :checkedChildren="$t('system.text_134')" :unCheckedChildren="$t('system.text_135')" v-decorator="decorators.ssl_global" />
  10. </a-form-item>
  11. <a-form-item :label="$t('system.text_270')">
  12. <a-input-number v-decorator="decorators.hostport" :min="1" :max="65535" />
  13. </a-form-item>
  14. <a-form-item :label="$t('system.text_126')">
  15. <a-input v-decorator="decorators.username" />
  16. </a-form-item>
  17. <a-form-item :label="$t('system.text_221')">
  18. <a-input-password v-decorator="decorators.password" />
  19. </a-form-item>
  20. <a-form-item :wrapper-col="offsetWrapperCol">
  21. <a-button type="primary" @click="handleSubmit" :loading="submiting">{{ $t('common.ok') }}</a-button>
  22. <test-button v-if="false" class="ml-3" :post="testPost" />
  23. </a-form-item>
  24. </a-form>
  25. </template>
  26. <script>
  27. import TestButton from '@/sections/TestButton'
  28. export default {
  29. name: 'EmailConfig',
  30. components: {
  31. TestButton,
  32. },
  33. props: {
  34. formItemLayout: {
  35. required: true,
  36. type: Object,
  37. },
  38. offsetWrapperCol: {
  39. required: true,
  40. type: Object,
  41. },
  42. loading: Boolean,
  43. },
  44. data () {
  45. return {
  46. submiting: false,
  47. form: {
  48. fc: this.$form.createForm(this),
  49. },
  50. decorators: {
  51. hostname: [
  52. 'hostname',
  53. {
  54. rules: [
  55. { required: true, message: this.$t('system.text_271') },
  56. ],
  57. },
  58. ],
  59. ssl_global: [
  60. 'ssl_global',
  61. {
  62. valuePropName: 'checked',
  63. },
  64. ],
  65. hostport: [
  66. 'hostport',
  67. {
  68. rules: [
  69. { required: true, message: this.$t('system.text_272') },
  70. ],
  71. },
  72. ],
  73. username: [
  74. 'username',
  75. {
  76. rules: [
  77. { required: true, message: this.$t('system.text_238') },
  78. ],
  79. },
  80. ],
  81. password: [
  82. 'password',
  83. {
  84. rules: [
  85. { required: true, message: this.$t('system.text_239') },
  86. ],
  87. },
  88. ],
  89. },
  90. contactData: null,
  91. }
  92. },
  93. destroyed () {
  94. this.manager = null
  95. },
  96. created () {
  97. this.manager = new this.$Manager('notifyconfigs', 'v1')
  98. this.fetchData()
  99. },
  100. methods: {
  101. async fetchData () {
  102. this.$emit('update:loading', true)
  103. try {
  104. const response = await this.manager.list({
  105. params: {
  106. type: 'email',
  107. },
  108. })
  109. const data = response.data.data[0] || {}
  110. this.contactData = data
  111. this.$nextTick(() => {
  112. this.form.fc.setFieldsValue(data.content)
  113. })
  114. } catch (error) {
  115. throw error
  116. } finally {
  117. this.$emit('update:loading', false)
  118. }
  119. },
  120. async handleSubmit () {
  121. const values = await this.form.fc.validateFields()
  122. try {
  123. this.submiting = true
  124. if (this.contactData && this.contactData.id) {
  125. await this.manager.update({
  126. id: this.contactData.id,
  127. data: {
  128. content: values,
  129. type: 'email',
  130. },
  131. })
  132. } else {
  133. await this.manager.create({
  134. data: {
  135. content: values,
  136. type: 'email',
  137. },
  138. })
  139. }
  140. await this.fetchData()
  141. this.$message.success(this.$t('system.text_124', [this.$t('system.text_302')]))
  142. } catch (error) {
  143. this.$message.error(this.$t('common_622', [this.$t('system.text_302')]))
  144. throw error
  145. } finally {
  146. this.submiting = false
  147. }
  148. },
  149. async testPost () {
  150. try {
  151. const values = await this.form.fc.validateFields()
  152. await new this.$Manager('notifyconfigs', 'v1').performClassAction({
  153. action: 'validate',
  154. data: {
  155. content: values,
  156. type: 'email',
  157. },
  158. })
  159. } catch (error) {
  160. this.$message.error(this.$t('common_623', [this.$t('common_269')]))
  161. throw error
  162. }
  163. },
  164. },
  165. }
  166. </script>