增加表单提交防抖

master
liaoanqi 4 years ago
parent 6aa41a4ea5
commit 66ff235b4a

@ -22,74 +22,76 @@
</template> </template>
<script> <script>
export default { import { Debounce } from '@/utils/debounce'
data () {
return { export default {
visible: false, data () {
dataForm: { return {
id: 0, visible: false,
paramKey: '', dataForm: {
paramValue: '', id: 0,
remark: '' paramKey: '',
}, paramValue: '',
dataRule: { remark: ''
paramKey: [ },
dataRule: {
paramKey: [
{ required: true, message: '参数名不能为空', trigger: 'blur' }, { required: true, message: '参数名不能为空', trigger: 'blur' },
{ pattern: /\s\S+|S+\s|\S/, message: '请输入正确的参数名', trigger: 'blur' } { pattern: /\s\S+|S+\s|\S/, message: '请输入正确的参数名', trigger: 'blur' }
], ],
paramValue: [ paramValue: [
{ required: true, message: '参数值不能为空', trigger: 'blur' }, { required: true, message: '参数值不能为空', trigger: 'blur' },
{ pattern: /\s\S+|S+\s|\S/, message: '请输入正确的参数值', trigger: 'blur' } { pattern: /\s\S+|S+\s|\S/, message: '请输入正确的参数值', trigger: 'blur' }
] ]
}
} }
}
},
methods: {
init (id) {
this.dataForm.id = id || 0
this.visible = true
this.$nextTick(() => {
this.$refs['dataForm'].resetFields()
if (this.dataForm.id) {
this.$http({
url: this.$http.adornUrl(`/sys/config/info/${this.dataForm.id}`),
method: 'get',
params: this.$http.adornParams()
}).then(({data}) => {
this.dataForm.paramKey = data.paramKey
this.dataForm.paramValue = data.paramValue
this.dataForm.remark = data.remark
})
}
})
}, },
methods: {
init (id) {
this.dataForm.id = id || 0
this.visible = true
this.$nextTick(() => {
this.$refs['dataForm'].resetFields()
if (this.dataForm.id) {
this.$http({
url: this.$http.adornUrl(`/sys/config/info/${this.dataForm.id}`),
method: 'get',
params: this.$http.adornParams()
}).then(({data}) => {
this.dataForm.paramKey = data.paramKey
this.dataForm.paramValue = data.paramValue
this.dataForm.remark = data.remark
})
}
})
},
// //
dataFormSubmit () { dataFormSubmit: Debounce(function () {
this.$refs['dataForm'].validate((valid) => { this.$refs['dataForm'].validate((valid) => {
if (valid) { if (valid) {
this.$http({ this.$http({
url: this.$http.adornUrl(`/sys/config`), url: this.$http.adornUrl(`/sys/config`),
method: this.dataForm.id ? 'put' : 'post', method: this.dataForm.id ? 'put' : 'post',
data: this.$http.adornData({ data: this.$http.adornData({
'id': this.dataForm.id || undefined, 'id': this.dataForm.id || undefined,
'paramKey': this.dataForm.paramKey, 'paramKey': this.dataForm.paramKey,
'paramValue': this.dataForm.paramValue, 'paramValue': this.dataForm.paramValue,
'remark': this.dataForm.remark 'remark': this.dataForm.remark
})
}).then(({data}) => {
this.$message({
message: '操作成功',
type: 'success',
duration: 1500,
onClose: () => {
this.visible = false
this.$emit('refreshDataList')
}
})
}) })
} }).then(({data}) => {
}) this.$message({
} message: '操作成功',
} type: 'success',
duration: 1500,
onClose: () => {
this.visible = false
this.$emit('refreshDataList')
}
})
})
}
})
})
} }
}
</script> </script>

Loading…
Cancel
Save