inleft
2022-02-15 91dc6cdda0548ff7f6e473a81933fa206d912cef
commit | author | age
9bcb19 1 <template>
I 2   <a-modal
3     title="新增应用"
4     :width="500"
5     :visible="visible"
6     :confirmLoading="confirmLoading"
7     @ok="handleSubmit"
8     @cancel="handleCancel"
9   >
10     <a-spin :spinning="confirmLoading">
11       <a-form :form="form">
12         <a-form-item
13           style="display: none;"
14           :labelCol="labelCol"
15           :wrapperCol="wrapperCol"
16         >
17           <a-input v-decorator="['active']" />
18         </a-form-item>
19         <a-form-item
20           label="应用名称"
21           :labelCol="labelCol"
22           :wrapperCol="wrapperCol"
23           has-feedback
24         >
25           <a-input placeholder="请输入应用名称" v-decorator="['name', {rules: [{required: true, message: '请输入应用名称!'}]}]" />
26         </a-form-item>
27         <a-form-item
28           label="唯一编码"
29           :labelCol="labelCol"
30           :wrapperCol="wrapperCol"
31           has-feedback
32         >
33           <a-input placeholder="请输入唯一编码" v-decorator="['code', {rules: [{required: true, message: '请输入唯一编码!'}]}]" />
34         </a-form-item>
35       </a-form>
36     </a-spin>
37   </a-modal>
38 </template>
39 <script>
40   import { sysAppAdd } from '@/api/modular/system/appManage'
41   export default {
42     data () {
43       return {
44         labelCol: {
45           xs: { span: 24 },
46           sm: { span: 5 }
47         },
48         wrapperCol: {
49           xs: { span: 24 },
50           sm: { span: 18 }
51         },
52         visible: false,
53         confirmLoading: false,
54         form: this.$form.createForm(this)
55       }
56     },
57     methods: {
58       // 初始化方法
59       add () {
60         this.visible = true
61         this.form.getFieldDecorator('active', { initialValue: 'N' })
62       },
63       handleSubmit () {
64         const { form: { validateFields } } = this
65         this.confirmLoading = true
66         validateFields((errors, values) => {
67           if (!errors) {
68             sysAppAdd(values).then((res) => {
69               this.confirmLoading = false
70               if (res.success) {
71                 this.$message.success('新增成功')
72                 this.handleCancel()
73                 this.$emit('ok', values)
74               } else {
75                 this.$message.error('新增失败:' + res.message)
76               }
77             }).finally((res) => {
78               this.confirmLoading = false
79             })
80           } else {
81             this.confirmLoading = false
82           }
83         })
84       },
85       handleCancel () {
86         this.form.resetFields()
87         this.visible = false
88       }
89     }
90   }
91 </script>