FlyBook.vue 3.9 KB

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