popup.vue 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <template>
  2. <BasicModal width="800px" v-bind="$attrs" @register="register" @ok="confirm" :title="title">
  3. <BasicForm @register="registerForm" :model="model" />
  4. </BasicModal>
  5. </template>
  6. <script lang="ts">
  7. import { defineComponent, PropType, reactive, ref, toRefs } from 'vue';
  8. import { BasicModal, useModalInner } from '/@/components/Modal';
  9. import { BasicForm, useForm } from '/@/components/Form/index';
  10. // import {
  11. // getPersonList,
  12. // addPerson,
  13. // deleteBatchesPerson,
  14. // // getPerson,
  15. // } from '/@/api/sys/member';
  16. import { schemas } from './data';
  17. import moment from 'moment';
  18. interface PopupData {
  19. title: string;
  20. }
  21. interface Role {
  22. id: string | number;
  23. }
  24. export default defineComponent({
  25. components: { BasicModal, BasicForm },
  26. props: {
  27. popupData: {
  28. type: Object as PropType<PopupData>,
  29. default: () => {},
  30. },
  31. },
  32. emits: ['saveData'],
  33. setup(props, { emit }) {
  34. const popupData = props.popupData as PopupData;
  35. const modelRef = ref({});
  36. const role = reactive<Role>({
  37. id: 0,
  38. });
  39. const [registerForm, { setFieldsValue, resetFields, validate }] = useForm({
  40. labelWidth: 120,
  41. schemas,
  42. showActionButtonGroup: false,
  43. actionColOptions: {
  44. span: 24,
  45. },
  46. });
  47. // const [register, { closeModal }] = useModalInner((data) => {
  48. // modelRef.value = data;
  49. //
  50. // });
  51. const [register, { closeModal }] = useModalInner((data) => {
  52. resetFields();
  53. console.log(`data ----id?`, data.id);
  54. if (data.id) {
  55. role.id = data.id;
  56. }
  57. setFieldsValue(data);
  58. });
  59. async function confirm() {
  60. const data = await validate();
  61. console.log(`确定`, data);
  62. data.id = role.id;
  63. data.birthday = moment(data.birthday).format('YYYY-MM-DD');
  64. const popupData = { closeModal, data };
  65. emit('saveData', popupData);
  66. // closeModal(); // 关闭弹窗
  67. }
  68. return {
  69. register,
  70. schemas,
  71. registerForm,
  72. model: modelRef,
  73. confirm,
  74. ...toRefs(popupData),
  75. };
  76. },
  77. });
  78. </script>
  79. <style lang="less">
  80. .ant-form-item-label {
  81. overflow: hidden;
  82. text-align: center !important;
  83. // white-space: pre-wrap !important;
  84. text-overflow: ellipsis;
  85. white-space: nowrap;
  86. }
  87. @media (max-width: 639px) {
  88. .ant-form-item-label {
  89. line-height: 2.5715 !important;
  90. text-align: center !important;
  91. }
  92. }
  93. </style>