form-build2.html 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>表单设计器kcz</title>
  5. <meta charset="UTF-8">
  6. <link rel="stylesheet" href="//unpkg.com/k-form-design/lib/k-form-design.css">
  7. </head>
  8. <body>
  9. <div id="app">
  10. <k-form-build ref="kfb" :value="jsonData"></k-form-build>
  11. <button @click="handleChange">修改数据</button>
  12. <button @click="handleReset">重置表单</button>
  13. </div>
  14. <script src="//cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
  15. <!-- <script src="http://cdn.kcz66.com/vue.min.js"></script> -->
  16. <script src="//unpkg.com/k-form-design/lib/k-form-design.umd.min.js"></script>
  17. <!-- <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.24.0/moment.min.js"></script> -->
  18. <script>
  19. let jsonData = {
  20. list: [
  21. {
  22. type: 'input',
  23. label: '单行文本',
  24. options: {
  25. width: '100%',
  26. defaultValue: '',
  27. placeholder: '请输入',
  28. disabled: false
  29. },
  30. model: 'input_1577875678405',
  31. key: 'input_1577875678405',
  32. rules: [{ required: true, message: '必填项' }]
  33. },
  34. {
  35. type: 'date',
  36. label: '日期选择器',
  37. options: {
  38. width: '100%',
  39. defaultValue: '',
  40. range: false,
  41. showTime: false,
  42. disabled: false,
  43. clearable: false,
  44. placeholder: '请选择',
  45. rangePlaceholder: ['开始时间', '结束时间'],
  46. format: 'YYYY-MM-DD'
  47. },
  48. model: 'date_1577877450971',
  49. key: 'date_1577877450971',
  50. rules: [{ required: true, message: '必填项' }]
  51. },
  52. {
  53. type: 'textarea',
  54. label: '多行文本',
  55. options: {
  56. width: '100%',
  57. minRows: 4,
  58. maxRows: 6,
  59. defaultValue: '',
  60. disabled: false,
  61. placeholder: '请输入'
  62. },
  63. model: 'textarea_1577877446659',
  64. key: 'textarea_1577877446659',
  65. rules: [{ required: true, message: '必填项' }]
  66. },
  67. {
  68. type: 'rate',
  69. label: '评分',
  70. options: {
  71. defaultValue: 0,
  72. max: 5,
  73. disabled: false,
  74. allowHalf: false
  75. },
  76. model: 'rate_1577877468717',
  77. key: 'rate_1577877468717',
  78. rules: [{ required: true, message: '必填项' }]
  79. }
  80. ],
  81. config: {
  82. layout: 'horizontal',
  83. labelCol: { span: 4 },
  84. wrapperCol: { span: 18 },
  85. hideRequiredMark: false,
  86. customStyle: ''
  87. }
  88. }
  89. let vm = new Vue({
  90. el: '#app',
  91. data: {
  92. jsonData
  93. },
  94. methods: {
  95. handleChange () {
  96. // 使用k-form-design组件的form属性修改表单数据
  97. this.$refs.kfb.form.setFieldsValue({
  98. input_1577875678405: '设置input值',
  99. date_1577877450971: '2019-11-12',
  100. textarea_1577877446659: '设置textarea值',
  101. rate_1577877468717: 3
  102. })
  103. },
  104. handleReset(){
  105. // 重置表单
  106. this.$refs.kfb.reset()
  107. }
  108. }
  109. })
  110. </script>
  111. </body>
  112. </html>