OkkiShowlistBlogForm.vue 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <template>
  2. <BasicForm @register="registerForm"/>
  3. </template>
  4. <script lang="ts">
  5. import {defineComponent} from 'vue';
  6. import {BasicForm, useForm} from '/@/components/Form/index';
  7. import {okkiShowlistBlogFormSchema} from '../OkkiShowlist.data';
  8. import {defHttp} from '/@/utils/http/axios';
  9. import { VALIDATE_FAILED } from '/@/utils/common/vxeUtils'
  10. export default defineComponent({
  11. name:"OkkiShowlistBlogForm",
  12. components: {BasicForm},
  13. emits:['register'],
  14. props:{
  15. disabled: {
  16. type: Boolean,
  17. default: false
  18. }
  19. },
  20. setup(props,{emit}) {
  21. const [registerForm, {setProps, resetFields, setFieldsValue,getFieldsValue,validate}] = useForm({
  22. //labelWidth: 150,
  23. schemas: okkiShowlistBlogFormSchema,
  24. showActionButtonGroup: false,
  25. baseColProps: {span: 24}
  26. });
  27. /**
  28. *初始化加载数据
  29. */
  30. function initFormData(url,id){
  31. if(id){
  32. defHttp.get({url,params:{id}},{isTransformResponse:false}).then(res=>{
  33. res.success && setFieldsValue({...res.result[0]});
  34. })
  35. }
  36. setProps({disabled: props.disabled})
  37. }
  38. /**
  39. *获取表单数据
  40. */
  41. function getFormData(){
  42. let formData = getFieldsValue();
  43. Object.keys(formData).map(k=>{
  44. if(formData[k] instanceof Array){
  45. formData[k] = formData[k].join(',')
  46. }
  47. });
  48. return [formData];
  49. }
  50. /**
  51. *表单校验
  52. */
  53. function validateForm(index){
  54. return new Promise((resolve, reject) => {
  55. // 验证子表表单
  56. validate().then(()=>{
  57. return resolve()
  58. }).catch(()=> {
  59. return reject({ error: VALIDATE_FAILED ,index})
  60. })
  61. })
  62. }
  63. return {
  64. registerForm,
  65. resetFields,
  66. initFormData,
  67. getFormData,
  68. validateForm
  69. }
  70. }
  71. })
  72. </script>