RefForm.vue 4.9 KB

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