Workwx.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. <template>
  2. <a-form
  3. :form="form.fc"
  4. v-bind="formItemLayout">
  5. <contact-tips
  6. :before="$t('system.workwx.before')"
  7. :after="$t('system.workwx.after')"
  8. :href="href"
  9. :hrefText="$t('system.detail')" />
  10. <a-form-item :label="$t('system.wecom.corp_id')">
  11. <template v-slot:extra>
  12. <div>{{ $t('system.for_example') }}: ww2c41e47d2d3b13cb</div>
  13. <div class="mb-0">{{ $t('system.wecom.where_to_find_corp_id') }}</div>
  14. </template>
  15. <a-input v-decorator="decorators.corp_id" />
  16. </a-form-item>
  17. <a-form-item label="AgentId">
  18. <template v-slot:extra>
  19. <div>{{ $t('system.for_example') }}: 1000002</div>
  20. <div class="mb-0">{{ $t('system.wecom.where_to_find_agent_id') }}</div>
  21. </template>
  22. <a-input v-decorator="decorators.agent_id" />
  23. </a-form-item>
  24. <a-form-item label="Secret">
  25. <template v-slot:extra>
  26. <div>{{ $t('system.for_example') }}: ZgyVyfr2Mvd0zzy6bE5prfKX25k4Wrgn4-1DSVDYXVo</div>
  27. <div class="mb-0">{{ $t('system.wecom.where_to_find_secret') }}</div>
  28. </template>
  29. <a-input-password v-decorator="decorators.secret" />
  30. </a-form-item>
  31. <a-form-item :wrapper-col="offsetWrapperCol">
  32. <a-button type="primary" @click="handleSubmit" :loading="submiting">{{ $t('common.ok') }}</a-button>
  33. <test-button v-if="false" class="ml-3" :post="testPost" />
  34. </a-form-item>
  35. </a-form>
  36. </template>
  37. <script>
  38. import TestButton from '@/sections/TestButton'
  39. import { DOCS_MAP } from '@/constants/docs'
  40. export default {
  41. name: 'EnterpriseWeChat',
  42. components: {
  43. TestButton,
  44. },
  45. props: {
  46. formItemLayout: {
  47. required: true,
  48. type: Object,
  49. },
  50. offsetWrapperCol: {
  51. required: true,
  52. type: Object,
  53. },
  54. loading: Boolean,
  55. },
  56. data () {
  57. return {
  58. submiting: false,
  59. testLoding: false,
  60. form: {
  61. fc: this.$form.createForm(this),
  62. },
  63. decorators: {
  64. corp_id: [
  65. 'corp_id',
  66. {
  67. rules: [
  68. { required: true, message: '请输入企业ID' },
  69. ],
  70. },
  71. ],
  72. agent_id: [
  73. 'agent_id',
  74. {
  75. rules: [
  76. { required: true, message: '请输入 AgentId' },
  77. ],
  78. },
  79. ],
  80. secret: [
  81. 'secret',
  82. {
  83. rules: [
  84. { required: true, message: '请输入 Secret' },
  85. ],
  86. },
  87. ],
  88. },
  89. contactData: null,
  90. href: DOCS_MAP.mailConfig('workwx'),
  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: 'workwx',
  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: 'workwx',
  130. },
  131. })
  132. } else {
  133. await this.manager.create({
  134. data: {
  135. content: values,
  136. type: 'workwx',
  137. },
  138. })
  139. }
  140. await this.fetchData()
  141. this.$message.success(this.$t('system.text_124', [this.$t('system.wecom.1')]))
  142. } catch (error) {
  143. this.$message.error(this.$t('common_622', [this.$t('system.wecom.1')]))
  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: 'workwx',
  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>