houzhongjian
2024-07-23 8501060c4f921d1e744c477e4dc08eb47b52693c
提交 | 用户 | 时间
850106 1 <template>
H 2   <el-dialog :visible.sync="visible" title="接口详情" :close-on-click-modal="false"
3              :close-on-press-escape="false"
4              :append-to-body="true">
5     <el-form :model="dataForm" :rules="dataRule" ref="dataForm" label-width="120px">
6       <el-form-item prop="modelCode" label="模型编码">
7         <el-input v-model="dataForm.modelCode" :disabled="true"></el-input>
8       </el-form-item>
9       <el-form-item prop="modelName" label="模型名称">
10         <el-input v-model="dataForm.modelName" :disabled="true"></el-input>
11       </el-form-item>
12       <el-form-item prop="url" label="url">
13         <el-input v-model="dataForm.url" placeholder=""></el-input>
14       </el-form-item>
15       <el-form-item prop="method" label="方法">
16         <el-input v-model="dataForm.method" placeholder=""></el-input>
17       </el-form-item>
18       <el-form-item prop="params" label="输入参数">
19         <el-input v-model="dataForm.params" placeholder="" rows="4" type="textarea"></el-input>
20       </el-form-item>
21       <el-form-item prop="paramsExample" label="参数示例">
22         <el-input v-model="dataForm.paramsExample" placeholder="" rows="6" type="textarea"></el-input>
23       </el-form-item>
24       <el-form-item prop="result" label="输出结果">
25         <el-input v-model="dataForm.result" placeholder="" rows="4" type="textarea"></el-input>
26       </el-form-item>
27       <el-form-item prop="resultExample" label="结果示例">
28         <el-input v-model="dataForm.resultExample" placeholder="" rows="4" type="textarea"></el-input>
29       </el-form-item>
30     </el-form>
31     <template slot="footer">
32       <el-button @click="visible = false">{{ $t('cancel') }}</el-button>
33       <el-button type="primary" @click="dataFormSubmitHandle()">{{ $t('confirm') }}</el-button>
34     </template>
35   </el-dialog>
36 </template>
37 <script>
38   import debounce from "lodash/debounce";
39
40   export default {
41     data() {
42       return {
43         visible: false,
44         dataForm: {
45           id: '',
46           modelId: '',
47           modelName: '',
48           modelCode: '',
49           url: '',
50           method: '',
51           params: '',
52           paramsExample: '',
53           result: '',
54           resultExample: '',
55         },
56         labelStyle: {
57           'font-weight': '600',
58           'height': '40px',
59           'min-width': '100px',
60           'word-break': 'keep-all'
61         }
62       }
63     },
64     computed: {
65       dataRule() {
66         return {
67           url: [
68             {required: true, message: 'url不能为空', trigger: 'blur'}
69           ],
70           method: [
71             {required: true, message: '方法不能为空', trigger: 'blur'}
72           ],
73           params: [
74             {required: true, message: '参数不能为空', trigger: 'blur'}
75           ]
76         }
77       }
78     },
79     methods: {
80       init(row) {
81         this.visible = true
82         this.$nextTick(() => {
83           this.dataForm.id = ''
84           this.$refs['dataForm'].resetFields()
85           this.dataForm.modelId = row.id
86           this.dataForm.modelCode = row.modelCode
87           this.dataForm.modelName = row.modelName
88           if (this.dataForm.modelId) {
89             this.getInfo()
90           }
91         })
92       },
93       getInfo() {
94         this.$http.get(`/iailab-ntt-model/mcs/st-model-doc/${this.dataForm.modelId}`).then(({data: res}) => {
95           if (res.code !== 0) {
96             return this.$message.error(res.msg)
97           }
98           this.dataForm = {
99             ...this.dataForm,
100             ...res.data
101           }
102
103         }).catch(() => {
104         })
105       },
106       // 表单提交
107       dataFormSubmitHandle: debounce(function () {
108         this.$refs['dataForm'].validate((valid) => {
109           if (!valid) {
110             return false
111           }
112           this.loading = true
113           this.$http[!this.dataForm.id ? 'post' : 'put']('/iailab-ntt-model/mcs/st-model-doc/', this.dataForm).then(({data: res}) => {
114             this.loading = false
115             if (res.code !== 0) {
116               return this.$message.error(res.msg)
117             }
118             this.$message({
119               message: this.$t('prompt.success'),
120               type: 'success',
121               duration: 500,
122               onClose: () => {
123                 this.visible = false
124                 this.$emit('refreshDataList')
125               }
126             })
127           }).catch(() => {
128           })
129         })
130       }, 1000, {'leading': true, 'trailing': false}),
131     }
132   }
133 </script>