houzhongjian
2024-07-23 8501060c4f921d1e744c477e4dc08eb47b52693c
提交 | 用户 | 时间
850106 1 <template>
H 2   <el-dialog
3     title="限流策略配置"
4     append-to-body="true"
5     width="30%"
6     :close-on-click-modal="false"
7     :visible.sync="visible">
8     <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="100px">
9       <el-form-item label="限流策略(分)" prop="limitMin">
10         <el-input-number v-model="dataForm.limitMin"
11                          controls-position="right"
12                          :min="0" :max="100000"></el-input-number>
13       </el-form-item>
14       <el-form-item label="限流策略(时)" prop="limitHour">
15         <el-input-number v-model="dataForm.limitHour"
16                          controls-position="right"
17                          :min="0" :max="100000"></el-input-number>
18       </el-form-item>
19       <el-form-item label="限流策略(天)" prop="limitDay">
20         <el-input-number v-model="dataForm.limitDay"
21                          controls-position="right"
22                          :min="0" :max="100000"></el-input-number>
23       </el-form-item>
24     </el-form>
25     <span slot="footer" class="dialog-footer">
26       <el-button @click="visible = false">取消</el-button>
27       <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
28     </span>
29   </el-dialog>
30 </template>
31 <script>
32   export default {
33     data () {
34       return {
35         visible: false,
36         dataForm: {
37           id: '',
38           limitMin: '',
39           limitHour: '',
40           limitDay: ''
41         }
42       }
43     },
44     methods: {
45       init (id) {
46         this.dataForm.id = id || 0
47         this.visible = true
48         this.$nextTick(() => {
49           this.$refs['dataForm'].resetFields()
50           if (this.dataForm.id) {
51             this.$http({
52               url: `/data/api-gateway/authorized/info/${this.dataForm.id}`,
53               method: 'get',
54               params: this.$http.adornParams()
55             }).then(({data}) => {
56               if (data && data.code === 0) {
57                 this.dataForm.limitMin = data.data.limitMin
58                 this.dataForm.limitHour = data.data.limitHour
59                 this.dataForm.limitDay = data.data.limitDay
60               }
61             })
62           }
63         })
64       },
65       // 表单提交
66       dataFormSubmit () {
67         this.$refs['dataForm'].validate((valid) => {
68           if (valid) {
69             this.$http({
70               url: `/data/api-gateway/authorized/${!this.dataForm.id ? 'add' : 'update'}`,
71               method: 'post',
72               data: this.$http.adornData({
73                 'id': this.dataForm.id || undefined,
74                 'limitMin': this.dataForm.limitMin,
75                 'limitHour': this.dataForm.limitHour,
76                 'limitDay': this.dataForm.limitDay
77               })
78             }).then(({data}) => {
79               if (data && data.code === 0) {
80                 this.$message({
81                   message: '操作成功',
82                   type: 'success',
83                   duration: 1500,
84                   onClose: () => {
85                     this.visible = false
86                     this.$emit('refreshDataList')
87                   }
88                 })
89               } else {
90                 this.$message.error(data.msg)
91               }
92             })
93           }
94         })
95       }
96     }
97   }
98 </script>