Message.vue 4.2 KB

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