| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- <template>
- <a-form
- :form="form.fc"
- v-bind="formItemLayout">
- <!-- <a-alert type="warning" :message="$t('system.text_256')" class="mb-2" /> -->
- <contact-tips
- :before="$t('system.dingding.before')"
- :after="$t('system.dingding.after')"
- :href="href"
- :hrefText="$t('system.detail')" />
- <a-form-item label="AgentId">
- <template v-slot:extra>
- <div>{{$t('system.text_257')}}</div>
- <div class="mb-0">{{$t('system.text_568')}}</div>
- </template>
- <a-input v-decorator="decorators.agent_id" />
- </a-form-item>
- <a-form-item label="AppKey">
- <template v-slot:extra>
- <div>{{$t('system.text_259')}}</div>
- <div class="mb-0">{{$t('system.text_569')}}</div>
- </template>
- <a-input v-decorator="decorators.app_key" />
- </a-form-item>
- <a-form-item label="AppSecret">
- <template v-slot:extra>
- <div>{{$t('system.text_260')}}</div>
- <div class="mb-0">{{$t('system.text_569')}}</div>
- </template>
- <a-input-password v-decorator="decorators.app_secret" />
- </a-form-item>
- <a-form-item :wrapper-col="offsetWrapperCol">
- <a-button type="primary" @click="handleSubmit" :loading="submiting">{{ $t('common.ok') }}</a-button>
- <test-button v-if="false" class="ml-3" :post="testPost" />
- </a-form-item>
- </a-form>
- </template>
- <script>
- import TestButton from '@/sections/TestButton'
- import { DOCS_MAP } from '@/constants/docs'
- export default {
- name: 'DingTalkConfig',
- components: {
- TestButton,
- },
- props: {
- formItemLayout: {
- required: true,
- type: Object,
- },
- offsetWrapperCol: {
- required: true,
- type: Object,
- },
- loading: Boolean,
- },
- data () {
- return {
- submiting: false,
- form: {
- fc: this.$form.createForm(this),
- },
- decorators: {
- agent_id: [
- 'agent_id',
- {
- rules: [
- { required: true, message: this.$t('system.text_261') },
- ],
- },
- ],
- app_key: [
- 'app_key',
- {
- rules: [
- { required: true, message: this.$t('system.text_262') },
- ],
- },
- ],
- app_secret: [
- 'app_secret',
- {
- rules: [
- { required: true, message: this.$t('system.text_263') },
- ],
- },
- ],
- },
- contactData: null,
- href: DOCS_MAP.mailConfig('dingtalk'),
- }
- },
- destroyed () {
- this.manager = null
- },
- created () {
- this.manager = new this.$Manager('notifyconfigs', 'v1')
- this.fetchData()
- },
- methods: {
- async fetchData () {
- this.$emit('update:loading', true)
- try {
- const response = await this.manager.list({
- params: {
- type: 'dingtalk',
- },
- })
- const data = response.data.data[0] || {}
- this.contactData = data
- this.$nextTick(() => {
- this.form.fc.setFieldsValue(data.content)
- })
- } catch (error) {
- throw error
- } finally {
- this.$emit('update:loading', false)
- }
- },
- async handleSubmit () {
- this.submiting = true
- try {
- const values = await this.form.fc.validateFields()
- if (this.contactData && this.contactData.id) {
- await this.manager.update({
- id: this.contactData.id,
- data: {
- content: values,
- type: 'dingtalk',
- },
- })
- } else {
- await this.manager.create({
- data: {
- content: values,
- type: 'dingtalk',
- },
- })
- }
- await this.fetchData()
- this.$message.success(this.$t('system.text_264'))
- } catch (error) {
- this.$message.error(this.$t('common_622', [this.$t('system.text_136')]))
- throw error
- } finally {
- this.submiting = false
- }
- },
- async testPost () {
- try {
- const values = await this.form.fc.validateFields()
- await new this.$Manager('notifyconfigs', 'v1').performClassAction({
- action: 'validate',
- data: {
- content: values,
- type: 'dingtalk',
- },
- })
- } catch (error) {
- this.$message.error(this.$t('common_623', [this.$t('common_269')]))
- throw error
- }
- },
- },
- }
- </script>
|