Fixiaobai
2023-11-13 cf96e8bb930b970c715a7cfd7224389f277e9578
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
<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible"
  >
    <el-form
      :model="dataForm"
      :rules="dataRule"
      ref="dataForm"
      label-width="80px"
      class="l-mes"
    >
      <el-form-item label="请求地址" prop="url">
        <el-input v-model="dataForm.url" placeholder="请求地址"></el-input>
      </el-form-item>
      <el-form-item label="方法名称" prop="procedureName">
        <el-input
          v-model="dataForm.procedureName"
          placeholder="方法名称"
        ></el-input>
      </el-form-item>
      <el-form-item label="是否禁用" prop="state">
        <el-switch v-model="dataForm.state"> </el-switch>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button
        type="primary"
        :disabled="isSubmit"
        v-thinclick="`dataFormSubmit`"
        >确定</el-button
      >
    </span>
  </el-dialog>
</template>
 
<script>
import { getObj, addObj, putObj } from '@/api/admin/ifsconfiguration'
 
export default {
  components: {},
  data() {
    return {
      visible: false,
      dataForm: {
        id: 0,
        url: '',
        procedureName: '',
        state: false
      },
      dataRule: {
        url: [{ required: true, message: '请求地址不能为空', trigger: 'blur' }],
        procedureName: [
          { required: true, message: '方法名称不能为空', trigger: 'blur' }
        ]
      },
      isSubmit: false
    }
  },
  methods: {
    init(id) {
      this.dataForm.id = id || 0
      this.visible = true
      this.$nextTick(() => {
        this.$refs.dataForm.resetFields()
        if (this.dataForm.id) {
          getObj(this.dataForm.id).then((response) => {
            this.dataForm = response.data.data
          })
        }
      })
    },
    // 表单提交
    dataFormSubmit() {
      this.isSubmit = true
      this.$refs.dataForm.validate((valid) => {
        if (valid) {
          if (this.dataForm.id) {
            putObj(this.dataForm)
              .then((data) => {
                this.$message.success('修改成功')
                this.visible = false
                this.isSubmit = false
                this.$emit('refreshDataList')
              })
              .catch(() => {
                this.isSubmit = false
              })
          } else {
            addObj(this.dataForm)
              .then((data) => {
                this.$message.success('新增成功')
                this.visible = false
                this.isSubmit = false
                this.$emit('refreshDataList')
              })
              .catch(() => {
                this.isSubmit = false
              })
          }
        } else {
          this.isSubmit = false
        }
      })
    }
  }
}
</script>