inleft
2022-02-15 91dc6cdda0548ff7f6e473a81933fa206d912cef
commit | author | age
9bcb19 1 <template>
I 2   <a-modal
3     title="新增定时任务"
4     :width="900"
5     :visible="visible"
6     :confirmLoading="confirmLoading"
7     @ok="handleSubmit"
8     @cancel="handleCancel"
9   >
10     <a-spin :spinning="formLoading">
11       <a-form :form="form">
12         <a-form-item
13           label="任务名称"
14           :labelCol="labelCol"
15           :wrapperCol="wrapperCol"
16           has-feedback
17         >
18           <a-input placeholder="请输入任务名称" v-decorator="['timerName', {rules: [{required: true, message: '请输入任务名称!'}]}]" />
19         </a-form-item>
20
21         <a-form-item
22           label="任务class类名"
23           :labelCol="labelCol"
24           :wrapperCol="wrapperCol"
25           has-feedback
26         >
27           <a-select style="width: 100%" placeholder="请选择任务class类名" v-decorator="['actionClass', {rules: [{ required: true, message: '请选择任务class类名!' }]}]" >
28             <a-select-option v-for="(item,index) in actionClassData" :key="index" :value="item" >{{ item }}</a-select-option>
29           </a-select>
30         </a-form-item>
31
32         <a-form-item
33           :labelCol="labelCol"
34           :wrapperCol="wrapperCol"
35           label="任务表达式"
36         >
37           <a-input placeholder="请输入任务表达式" v-decorator="['cron', {rules: [{required: true, message: '请输入任务表达式!'}]}]" />
38         </a-form-item>
39
40         <a-form-item
41           label="备注"
42           :labelCol="labelCol"
43           :wrapperCol="wrapperCol"
44           has-feedback
45         >
46           <a-textarea :rows="4" placeholder="请输入备注" v-decorator="['remark']"></a-textarea>
47         </a-form-item>
48
49       </a-form>
50
51     </a-spin>
52   </a-modal>
53 </template>
54
55 <script>
56   import { sysTimersAdd, sysTimersGetActionClasses } from '@/api/modular/system/timersManage'
57   export default {
58     data () {
59       return {
60         labelCol: {
61           xs: { span: 24 },
62           sm: { span: 5 }
63         },
64         wrapperCol: {
65           xs: { span: 24 },
66           sm: { span: 15 }
67         },
68         visible: false,
69         confirmLoading: false,
70         actionClassData: [],
71         formLoading: false,
72         form: this.$form.createForm(this)
73       }
74     },
75     methods: {
76       // 初始化方法
77       add (record) {
78         this.visible = true
79         this.formLoading = true
80         this.getActionClass()
81       },
82
83       /**
84        * 获取选择器下拉框数据
85        */
86       getActionClass () {
87         sysTimersGetActionClasses().then((res) => {
88            this.formLoading = false
89            if (res.success) {
90              this.actionClassData = res.data
91            } else {
92              this.$message.error('获取选择器下拉框数据')
93            }
94         })
95       },
96
97       handleSubmit () {
98         const { form: { validateFields } } = this
99         this.confirmLoading = true
100         validateFields((errors, values) => {
101           if (!errors) {
102             sysTimersAdd(values).then((res) => {
103               if (res.success) {
104                 this.$message.success('新增成功')
105                 this.visible = false
106                 this.confirmLoading = false
107                 this.$emit('ok', values)
108                 this.form.resetFields()
109               } else {
110                 this.$message.error('新增失败:' + res.message)
111               }
112             }).finally((res) => {
113               this.confirmLoading = false
114             })
115           } else {
116             this.confirmLoading = false
117           }
118         })
119       },
120       handleCancel () {
121         this.form.resetFields()
122         this.visible = false
123       }
124     }
125   }
126 </script>