form.vue 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <template>
  2. <el-dialog :close-on-click-modal="false" title="新增ip" width="500px" :visible.sync="visible">
  3. <el-form ref="form" :model="form" :rules="rules" size="small" label-width="40px">
  4. <el-form-item label="ip" prop="ip">
  5. <el-input
  6. v-model="form.ip" type="textarea" :autosize="{ minRows: 6, maxRows: 6 }"
  7. placeholder="支持多条批量录入,ip间用英文逗号间隔" maxlength="400"
  8. >
  9. </el-input>
  10. </el-form-item>
  11. </el-form>
  12. <div slot="footer" class="dialog-footer">
  13. <el-button type="text" @click="doCancel">取消</el-button>
  14. <el-button type="primary" @click="doSubmit">确认</el-button>
  15. </div>
  16. </el-dialog>
  17. </template>
  18. <script>
  19. import {
  20. addBlack
  21. } from '@/api/risk'
  22. export default {
  23. name: 'AdForm',
  24. data() {
  25. return {
  26. visible: false,
  27. form: {
  28. ip: '',
  29. type: 1
  30. },
  31. rules: {
  32. ip: [
  33. { required: true, message: '请输入ip', trigger: 'blur' }
  34. ]
  35. }
  36. }
  37. },
  38. methods: {
  39. // 打开弹出窗
  40. show(row) {
  41. this.form = {
  42. ip: '',
  43. type: 1
  44. }
  45. this.visible = true
  46. },
  47. // 取消
  48. doCancel() {
  49. this.visible = false
  50. },
  51. // 提交
  52. doSubmit() {
  53. this.$refs.form.validate((valid) => {
  54. if (valid) {
  55. addBlack(this.form).then((res) => {
  56. this.$message({
  57. message: '新增成功',
  58. type: 'success'
  59. })
  60. this.$emit('reset')
  61. this.visible = false
  62. })
  63. .catch((err) => {
  64. this.visible = false
  65. })
  66. }
  67. })
  68. }
  69. }
  70. }
  71. </script>