quanyawei
2024-04-22 bffbddd4a3853a1994c13e42767ceb361cfe74b0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
<template>
<a-form style="margin-top: 8px" :autoFormCreate="(form)=>{this.form = form}">
    <a-modal title="规则配置" destroyOnClose :visible="visible">
        <a-steps style="margin-bottom: 28px" size="small" :current="currentStep">
            <a-step title="基本信息" />
            <a-step title="配置规则属性" />
            <a-step title="设定调度周期" />
        </a-steps>
        <div v-if="currentStep==0">
            <a-form-item key="title" v-bind="formLayout" label="规则名称" fieldDecoratorId="title" :fieldDecoratorOptions="{
                    rules: [{ required: true, message: '请输入规则名称!' }],
                    initialValue: formVals.title,
                }">
                <a-input placeholder="请输入" />
            </a-form-item>,
            <a-form-item key="description" v-bind="formLayout" label="规则描述" fieldDecoratorId="description" :fieldDecoratorOptions="{
                    rules: [{ required: true, message: '请输入至少五个字符的规则描述!', min: 5 }],
                    initialValue: formVals.description,
                }">
                <a-textarea :rows="4" placeholder="请输入至少五个字符" />
            </a-form-item>
        </div>
        <div v-if="currentStep==1">
            <a-form-item key="target" v-bind="formLayout" label="监控对象" fieldDecoratorId="target" :fieldDecoratorOptions="{
                    initialValue: formVals.target,
                }">
                <a-select style="width: 100%">
                    <a-select-option value="0">表一</a-select-option>
                    <a-select-option value="1">表二</a-select-option>
                </a-select>
            </a-form-item>
            <a-form-item key="template" v-bind="formLayout" label="规则模板" fieldDecoratorId="template" :fieldDecoratorOptions="{
                    initialValue: formVals.template,
                }">
                <a-select style="width: 100%">
                    <a-select-option value="0">规则模板一</a-select-option>
                    <a-select-option value="1">规则模板二</a-select-option>
                </a-select>
            </a-form-item>,
            <a-form-item key="type" v-bind="formLayout" label="规则类型" fieldDecoratorId="type" :fieldDecoratorOptions="{
                    initialValue: formVals.type,
                }">
                <a-radio-group>
                    <a-radio value="0">强</a-radio>
                    <a-radio value="1">弱</a-radio>
                </a-radio-group>
            </a-form-item>
        </div>
        <div v-if="currentStep==2">
            <a-form-item key="time" v-bind="formLayout" label="开始时间" fieldDecoratorId="time" :fieldDecoratorOptions="{
                    rules: [{ required: true, message: '请选择开始时间!' }]
                }">
                <a-date-picker style="width: 100%" showTime format="YYYY-MM-DD HH:mm:ss" placeholder="选择开始时间" />
            </a-form-item>
            <a-form-item key="frequency" v-bind="formLayout" label="调度周期" fieldDecoratorId="frequency" :fieldDecoratorOptions="{
                    initialValue: formVals.frequency,
                }">
                <a-select style="width: 100%">
                    <a-select-option value="month">月</a-select-option>
                    <a-select-option value="week">周</a-select-option>
                </a-select>
            </a-form-item>
        </div>
        <template slot="footer" v-if="currentStep==0">
            <a-button key="cancel" @click="handleCancel">
                取消
            </a-button>
            <a-button key="forward" type="primary" @click="handleNext">
                下一步
            </a-button>
        </template>
        <template slot="footer" v-else-if="currentStep==1">
            <a-button key="back" :style="{ float: 'left' }" @click="handleBackward">
                上一步
            </a-button>
            <a-button key="cancel" @click="handleCancel">
                取消
            </a-button>
            <a-button key="forward" type="primary" @click="handleNext">
                下一步
            </a-button>
        </template>
        <template slot="footer" v-else-if="currentStep==2">
            <a-button key="back" :style="{ float: 'left' }" @click="handleBackward">
                上一步
            </a-button>
            <a-button key="cancel" @click="handleCancel">
                取消
            </a-button>
            <a-button key="forward" type="primary" @click="handleOk">
                完成
            </a-button>
        </template>
    </a-modal>
</a-form>
</template>
 
<script lang="ts">
import {
    Component,
    Prop,
    Vue,
    Emit,
    Model,
    Watch,
} from 'vue-property-decorator';
import {
    State,
    Mutation,
    namespace,
} from 'vuex-class';
 
import axios from 'axios';
 
@Component({
    components: {},
})
export default class UpdateTaskForm extends Vue {
 
    @Prop({
        type: Boolean,
        default: false,
    })
    private visible!: boolean;
 
    @Prop({
        type: Object,
        default() {
            return {};
        },
    })
    private record!: any;
 
    private form: any = null;
 
    private formVals: any = {
        target: '0',
        template: '0',
        type: '1',
        time: '',
        frequency: 'month',
    };
 
    private currentStep: number = 0;
 
    private formLayout = {
        labelCol: {
            span: 7,
        },
        wrapperCol: {
            span: 13,
        },
    };
 
    private handleBackward(): void {
        this.currentStep--;
    }
 
    private handleNext(): void {
        this.form.validateFields((err: any, fieldsValue: any) => {
            if (err) {
                return;
            }
            this.formVals = { ...this.formVals, ...fieldsValue };
            this.currentStep++;
        });
    }
 
    private handleCancel(): void {
        this.updateVisible(false);
    }
 
    private handleOk(): void {
 
        this.form.validateFields((err: any, fieldsValue: any) => {
            if (err) {
                return;
            }
            this.formVals = { ...this.formVals, ...fieldsValue };
 
            axios.post('/updateRule', {...this.formVals})
                .then(() => {
                    this.updateVisible(false);
                    this.onOk();
                });
            });
 
    }
 
    @Emit('ok')
    private onOk() {
 
    }
 
    private updateVisible(visible: boolean): void {
        this.$emit('update:visible', visible);
    }
 
    private mounted(): void {
        this.currentStep = 0;
    }
 
    @Watch('record', {
        immediate: true,
        deep: true,
    })
    private recordChange(value: any, oldValue: any): void {
        this.formVals = {
            ...value,
            ...this.formVals,
        };
        this.currentStep = 0;
    }
 
}
</script>