DingTalk.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. <template>
  2. <a-form
  3. :form="form.fc"
  4. v-bind="formItemLayout">
  5. <!-- <a-alert type="warning" :message="$t('system.text_256')" class="mb-2" /> -->
  6. <contact-tips
  7. :before="$t('system.dingding.before')"
  8. :after="$t('system.dingding.after')"
  9. :href="href"
  10. :hrefText="$t('system.detail')" />
  11. <a-form-item label="AgentId">
  12. <template v-slot:extra>
  13. <div>{{$t('system.text_257')}}</div>
  14. <div class="mb-0">{{$t('system.text_568')}}</div>
  15. </template>
  16. <a-input v-decorator="decorators.agent_id" />
  17. </a-form-item>
  18. <a-form-item label="AppKey">
  19. <template v-slot:extra>
  20. <div>{{$t('system.text_259')}}</div>
  21. <div class="mb-0">{{$t('system.text_569')}}</div>
  22. </template>
  23. <a-input v-decorator="decorators.app_key" />
  24. </a-form-item>
  25. <a-form-item label="AppSecret">
  26. <template v-slot:extra>
  27. <div>{{$t('system.text_260')}}</div>
  28. <div class="mb-0">{{$t('system.text_569')}}</div>
  29. </template>
  30. <a-input-password v-decorator="decorators.app_secret" />
  31. </a-form-item>
  32. <a-form-item :wrapper-col="offsetWrapperCol">
  33. <a-button type="primary" @click="handleSubmit" :loading="submiting">{{ $t('common.ok') }}</a-button>
  34. <test-button v-if="false" class="ml-3" :post="testPost" />
  35. </a-form-item>
  36. </a-form>
  37. </template>
  38. <script>
  39. import TestButton from '@/sections/TestButton'
  40. import { DOCS_MAP } from '@/constants/docs'
  41. export default {
  42. name: 'DingTalkConfig',
  43. components: {
  44. TestButton,
  45. },
  46. props: {
  47. formItemLayout: {
  48. required: true,
  49. type: Object,
  50. },
  51. offsetWrapperCol: {
  52. required: true,
  53. type: Object,
  54. },
  55. loading: Boolean,
  56. },
  57. data () {
  58. return {
  59. submiting: false,
  60. form: {
  61. fc: this.$form.createForm(this),
  62. },
  63. decorators: {
  64. agent_id: [
  65. 'agent_id',
  66. {
  67. rules: [
  68. { required: true, message: this.$t('system.text_261') },
  69. ],
  70. },
  71. ],
  72. app_key: [
  73. 'app_key',
  74. {
  75. rules: [
  76. { required: true, message: this.$t('system.text_262') },
  77. ],
  78. },
  79. ],
  80. app_secret: [
  81. 'app_secret',
  82. {
  83. rules: [
  84. { required: true, message: this.$t('system.text_263') },
  85. ],
  86. },
  87. ],
  88. },
  89. contactData: null,
  90. href: DOCS_MAP.mailConfig('dingtalk'),
  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: 'dingtalk',
  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. this.submiting = true
  122. try {
  123. const values = await this.form.fc.validateFields()
  124. if (this.contactData && this.contactData.id) {
  125. await this.manager.update({
  126. id: this.contactData.id,
  127. data: {
  128. content: values,
  129. type: 'dingtalk',
  130. },
  131. })
  132. } else {
  133. await this.manager.create({
  134. data: {
  135. content: values,
  136. type: 'dingtalk',
  137. },
  138. })
  139. }
  140. await this.fetchData()
  141. this.$message.success(this.$t('system.text_264'))
  142. } catch (error) {
  143. this.$message.error(this.$t('common_622', [this.$t('system.text_136')]))
  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: 'dingtalk',
  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>