form.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <template>
  2. <div class="form" >
  3. <by-tool :propConfig="toolConfig" @onAdd="onAdd" />
  4. <by-form :propConfig="config" ref="form" />
  5. <el-button type="primary" @click="getFormData">获取数据</el-button>
  6. <el-button type="primary" @click="getFormVali">获取表单验证</el-button>
  7. </div>
  8. </template>
  9. <script lang="ts">
  10. import { Component, Prop, Vue, Watch } from "vue-property-decorator";
  11. @Component
  12. export default class DemoForm extends Vue {
  13. config={
  14. attr:{
  15. size:'small',
  16. height:500,
  17. rules:{
  18. name:[{
  19. required: true, message: '请输入名称', trigger: 'blur'
  20. }]
  21. }
  22. },
  23. columns:[
  24. [{
  25. span:6,
  26. label:'名称',
  27. prop:'name',
  28. // required:true,
  29. // error:'验证出错啦!',
  30. component:'by-input',
  31. compConfig:{
  32. attr:{
  33. placeholder:'请输入名称',
  34. clearable:true
  35. }
  36. }
  37. },{
  38. span:6,
  39. label:'名称2',
  40. prop:'name2',
  41. // required:true,
  42. component:'by-input',
  43. compConfig:{
  44. attr:{
  45. placeholder:'请输入名称',
  46. clearable:true
  47. }
  48. }
  49. }],
  50. [{
  51. span:6,
  52. label:'下拉框',
  53. prop:'select',
  54. rules:[
  55. { required: true, message: '请选择数据', trigger: 'change' }
  56. ],
  57. component:'by-select',
  58. compConfig:{
  59. attr:{
  60. placeholder:'请选择数据',
  61. clearable:true,
  62. data:[{
  63. value: '选项1',
  64. label: '黄金糕'
  65. }, {
  66. value: '选项2',
  67. label: '双皮奶'
  68. }, {
  69. value: '选项3',
  70. label: '蚵仔煎'
  71. }, {
  72. value: '选项4',
  73. label: '龙须面'
  74. }, {
  75. value: '选项5',
  76. label: '北京烤鸭'
  77. }]
  78. }
  79. }
  80. },{
  81. span:6,
  82. label:'时间',
  83. prop:'date',
  84. rules:[
  85. { required: true, message: '请选择时间', trigger: 'change' }
  86. ],
  87. component:'by-date-picker',
  88. compConfig:{
  89. format:'yyyy-MM-dd',
  90. type:'date'
  91. }
  92. }]
  93. ]
  94. }
  95. toolConfig:any={
  96. tools:{
  97. onAdd:true,
  98. onUpdate:true,
  99. onDelete:true,
  100. onExport:true
  101. }
  102. }
  103. onAdd(){
  104. console.log('新增操作')
  105. }
  106. getFormData(){
  107. let data = (this as any).$refs.form.getValue();
  108. console.log('表单数据:',data);
  109. }
  110. getFormVali(){
  111. (this as any).$refs.form.validate().then(()=>{
  112. console.log('验证通过')
  113. }).catch(()=>{
  114. console.log('验证不通过')
  115. });
  116. }
  117. }
  118. </script>
  119. <style lang="scss" scoped>
  120. .form{
  121. width: 100%;
  122. }
  123. </style>