xm-verify-input.vue 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <template>
  2. <a-form-model ref="ruleForm" :model="ruleForm" :rules="rules">
  3. <a-form-model-item prop="formValue" label="默认值">
  4. <a-input v-model="ruleForm.formValue" />
  5. </a-form-model-item>
  6. </a-form-model>
  7. </template>
  8. <script>
  9. import components from './_import-components/xm-verify-input-import'
  10. export default {
  11. name: 'XmVerifyInput',
  12. metaInfo: {
  13. title: 'XmVerifyInput',
  14. },
  15. components,
  16. props: {
  17. value: {
  18. type: [String, Number],
  19. default: undefined,
  20. },
  21. regex: {
  22. type: RegExp,
  23. default: '',
  24. },
  25. },
  26. data() {
  27. const validatePass = (rule, value, callback) => {
  28. if (value && !this.regex.test(value)) {
  29. callback(new Error('格式有误!'))
  30. } else {
  31. this.$emit('input', value)
  32. callback()
  33. }
  34. }
  35. return {
  36. ruleForm: {
  37. formValue: this.value,
  38. },
  39. rules: {
  40. formValue: [{ validator: validatePass, trigger: 'blur' }],
  41. },
  42. }
  43. },
  44. methods: {},
  45. }
  46. </script>
  47. <style module lang="scss">
  48. @use '@/common/design' as *;
  49. </style>