RefForm.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. <template>
  2. <PageWrapper title="Ref操作示例">
  3. <div class="mb-4">
  4. <a-button @click="setProps({ labelWidth: 150 })" class="mr-2">更改labelWidth</a-button>
  5. <a-button @click="setProps({ labelWidth: 120 })" class="mr-2">还原labelWidth</a-button>
  6. <a-button @click="setProps({ size: 'large' })" class="mr-2">更改Size</a-button>
  7. <a-button @click="setProps({ size: 'default' })" class="mr-2">还原Size</a-button>
  8. <a-button @click="setProps({ disabled: true })" class="mr-2">禁用表单</a-button>
  9. <a-button @click="setProps({ disabled: false })" class="mr-2">解除禁用</a-button>
  10. <a-button @click="setProps({ compact: true })" class="mr-2">紧凑表单</a-button>
  11. <a-button @click="setProps({ compact: false })" class="mr-2">还原正常间距</a-button>
  12. <a-button @click="setProps({ actionColOptions: { span: 8 } })" class="mr-2">
  13. 操作按钮位置
  14. </a-button>
  15. </div>
  16. <div class="mb-4">
  17. <a-button @click="setProps({ showActionButtonGroup: false })" class="mr-2">
  18. 隐藏操作按钮
  19. </a-button>
  20. <a-button @click="setProps({ showActionButtonGroup: true })" class="mr-2">
  21. 显示操作按钮
  22. </a-button>
  23. <a-button @click="setProps({ showResetButton: false })" class="mr-2"> 隐藏重置按钮 </a-button>
  24. <a-button @click="setProps({ showResetButton: true })" class="mr-2"> 显示重置按钮 </a-button>
  25. <a-button @click="setProps({ showSubmitButton: false })" class="mr-2">
  26. 隐藏查询按钮
  27. </a-button>
  28. <a-button @click="setProps({ showSubmitButton: true })" class="mr-2"> 显示查询按钮 </a-button>
  29. <a-button
  30. @click="
  31. setProps({
  32. resetButtonOptions: {
  33. disabled: true,
  34. text: '重置New',
  35. },
  36. })
  37. "
  38. class="mr-2"
  39. >
  40. 修改重置按钮
  41. </a-button>
  42. <a-button
  43. @click="
  44. setProps({
  45. submitButtonOptions: {
  46. disabled: true,
  47. loading: true,
  48. },
  49. })
  50. "
  51. class="mr-2"
  52. >
  53. 修改查询按钮
  54. </a-button>
  55. </div>
  56. <CollapseContainer title="使用ref调用表单内部函数示例">
  57. <BasicForm
  58. :schemas="schemas"
  59. ref="formElRef"
  60. :labelWidth="100"
  61. @submit="handleSubmit"
  62. :actionColOptions="{ span: 24 }"
  63. />
  64. </CollapseContainer>
  65. </PageWrapper>
  66. </template>
  67. <script lang="ts">
  68. import { defineComponent, ref } from 'vue';
  69. import { BasicForm, FormSchema, FormActionType, FormProps } from '/@/components/Form/index';
  70. import { CollapseContainer } from '/@/components/Container/index';
  71. import { useMessage } from '/@/hooks/web/useMessage';
  72. import { PageWrapper } from '/@/components/Page';
  73. const schemas: FormSchema[] = [
  74. {
  75. field: 'field1',
  76. component: 'Input',
  77. label: '字段1',
  78. colProps: {
  79. span: 8,
  80. },
  81. componentProps: {
  82. placeholder: '自定义placeholder',
  83. onChange: (e: any) => {
  84. console.log(e);
  85. },
  86. },
  87. },
  88. {
  89. field: 'field2',
  90. component: 'Input',
  91. label: '字段2',
  92. colProps: {
  93. span: 8,
  94. },
  95. },
  96. {
  97. field: 'field3',
  98. component: 'DatePicker',
  99. label: '字段3',
  100. colProps: {
  101. span: 8,
  102. },
  103. },
  104. {
  105. field: 'field4',
  106. component: 'Select',
  107. label: '字段4',
  108. colProps: {
  109. span: 8,
  110. },
  111. componentProps: {
  112. options: [
  113. {
  114. label: '选项1',
  115. value: '1',
  116. key: '1',
  117. },
  118. {
  119. label: '选项2',
  120. value: '2',
  121. key: '2',
  122. },
  123. ],
  124. },
  125. },
  126. {
  127. field: 'field5',
  128. component: 'CheckboxGroup',
  129. label: '字段5',
  130. colProps: {
  131. span: 8,
  132. },
  133. componentProps: {
  134. options: [
  135. {
  136. label: '选项1',
  137. value: '1',
  138. },
  139. {
  140. label: '选项2',
  141. value: '2',
  142. },
  143. ],
  144. },
  145. },
  146. {
  147. field: 'field7',
  148. component: 'RadioGroup',
  149. label: '字段7',
  150. colProps: {
  151. span: 8,
  152. },
  153. componentProps: {
  154. options: [
  155. {
  156. label: '选项1',
  157. value: '1',
  158. },
  159. {
  160. label: '选项2',
  161. value: '2',
  162. },
  163. ],
  164. },
  165. },
  166. ];
  167. export default defineComponent({
  168. components: { BasicForm, CollapseContainer, PageWrapper },
  169. setup() {
  170. const formElRef = ref<Nullable<FormActionType>>(null);
  171. const { createMessage } = useMessage();
  172. return {
  173. formElRef,
  174. schemas,
  175. handleSubmit: (values: any) => {
  176. createMessage.success('click search,values:' + JSON.stringify(values));
  177. },
  178. setProps(props: FormProps) {
  179. const formEl = formElRef.value;
  180. if (!formEl) return;
  181. formEl.setProps(props);
  182. },
  183. };
  184. },
  185. });
  186. </script>