houzhongjian
2024-07-23 8501060c4f921d1e744c477e4dc08eb47b52693c
提交 | 用户 | 时间
850106 1 <template>
H 2   <el-dialog
3     :title="!dataForm.id ? '新增' : '修改'"
4     :close-on-click-modal="false"
5     :visible.sync="visible">
6     <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
7       <el-row :gutter="20">
8         <el-col :span="12">
9           <el-form-item label="类型" prop="sourcetype">
10             <el-input v-model="dataForm.sourcetype" placeholder="类型" maxlength="50" clearable></el-input>
11           </el-form-item>
12         </el-col>
13         <el-col :span="12">
14           <el-form-item label="名称" prop="sourcename">
15             <el-input v-model="dataForm.sourcename" placeholder="类型名称" maxlength="50" clearable></el-input>
16           </el-form-item>
17         </el-col>
18       </el-row>
19       <el-row :gutter="20">
20         <el-form-item label="地址" prop="sourceaddress">
21           <el-col :span="24">
22             <el-input v-model="dataForm.sourceaddress" placeholder="地址" maxlength="100" clearable></el-input>
23           </el-col>
24         </el-form-item>
25       </el-row>
26     </el-form>
27     <span slot="footer" class="dialog-footer">
28       <el-button @click="visible = false">取消</el-button>
29       <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
30     </span>
31   </el-dialog>
32 </template>
33
34 <script>
35   import DictSelectTag from '@/components/dict/dict-select-tag'
36   export default {
37     components: {
38       DictSelectTag
39     },
40     data () {
41       return {
42         visible: false,
43         noDisabled: false,
44         roleList: [],
45         readonly: true,
46         dataForm: {
47           id: 0,
48           sourcename: '',
49           sourcetype: '',
50           sourceaddress: '',
51           username: '',
52           password: ''
53         },
54         dataRule: {
55           sourcename: [
56             { required: true, message: '名称不能为空', trigger: 'blur' }
57           ],
58           sourcetype: [
59             { required: true, message: '类型不能为空', trigger: 'blur' }
60           ],
61           sourceaddress: [
62             { required: true, message: '地址不能为空', trigger: 'blur' }
63           ]
64         }
65       }
66     },
67     methods: {
68       init (id) {
69         this.dataForm.id = id || 0
70         this.visible = true
71         this.$nextTick(() => {
72           this.$refs['dataForm'].resetFields()
73         })
74         if (id) {
75           this.$http({
76             url: `/data/data/data-source/info/${this.dataForm.id}`,
77             method: 'get',
78             params: this.$http.adornParams()
79           }).then(({data}) => {
80             if (data && data.code === 0) {
81               this.dataForm.sourcename = data.dataSource.sourcename
82               this.dataForm.sourcetype = data.dataSource.sourcetype
83               this.dataForm.sourceaddress = data.dataSource.sourceaddress
84               this.dataForm.username = data.dataSource.username
85               this.dataForm.password = data.dataSource.password
86             }
87           })
88         }
89       },
90       // 表单提交
91       dataFormSubmit () {
92         this.$refs['dataForm'].validate((valid) => {
93           if (valid) {
94             this.$http['post'](`/data/data/data-source/${!this.dataForm.id ? 'save' : 'update'}`, this.dataForm).then(({ data: res }) => {
95               if (res.code !== 0) {
96                 return this.$message.error(res.msg)
97               }
98               this.$message({
99                 message: this.$t('prompt.success'),
100                 type: 'success',
101                 duration: 500,
102                 onClose: () => {
103                   this.visible = false
104                   this.$emit('refreshDataList')
105                 }
106               })
107             }).catch(() => {})
108           }
109         })
110       }
111     }
112   }
113 </script>
114 <style>
115   .el-select {
116     width:100%
117   }
118   .el-input-group__append {
119     padding: 0 5px 0 5px
120   }
121   .el-input-group__prepend {
122     padding: 0 5px 0 5px
123   }
124 </style>