add.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <template>
  2. <BasicModal v-bind="$attrs" @register="register" @ok="confirm" title="添加xxx">
  3. <BasicForm @register="registerForm" :model="model" />
  4. <!-- <MenuTree /> -->
  5. <div style="display: flex;">
  6. <p class="tree-label">菜单</p>
  7. <Tree :treeData="treeData" :arr="arr" />
  8. </div>
  9. </BasicModal>
  10. </template>
  11. <script lang="ts">
  12. import { defineComponent, ref, } from 'vue';
  13. import { BasicModal, useModalInner } from '/@/components/Modal';
  14. import { BasicForm, FormSchema, useForm } from '/@/components/Form/index';
  15. import { treeData } from './data';
  16. import Tree from './tree.vue'
  17. import { adapt } from '/@/utils/adapt'
  18. export default defineComponent({
  19. components: { BasicModal, BasicForm, Tree },
  20. setup() {
  21. const modelRef = ref({});
  22. const adaptWidth = adapt()
  23. const arr:string[] = ['0-0-0-1', '0-0-0']
  24. const schemas: FormSchema[] = [
  25. {
  26. field: 'name',
  27. component: 'Input',
  28. label: '账户名',
  29. labelWidth: adaptWidth.labelWidth,
  30. colProps: {
  31. span: adaptWidth.elContainer,
  32. }
  33. },
  34. {
  35. field: 'password',
  36. component: 'Input',
  37. label: '密码',
  38. labelWidth: adaptWidth.labelWidth,
  39. colProps: {
  40. span: adaptWidth.elContainer,
  41. },
  42. },
  43. {
  44. field: 'detail',
  45. component: 'Input',
  46. label: '详情',
  47. labelWidth: adaptWidth.labelWidth,
  48. colProps: {
  49. span: adaptWidth.elContainer,
  50. },
  51. },
  52. ];
  53. const [
  54. registerForm,
  55. {
  56. getFieldsValue,
  57. // setProps
  58. },
  59. ] = useForm({
  60. labelWidth: 120,
  61. schemas,
  62. showActionButtonGroup: false,
  63. actionColOptions: {
  64. span: 24,
  65. },
  66. });
  67. const [register, { closeModal } ] = useModalInner((data) => {
  68. // 方式1
  69. // setFieldsValue({
  70. // field2: data.data,
  71. // field1: data.info,
  72. // });
  73. // 方式2
  74. modelRef.value = { name: data.name, password: data.password, detail: data.detail };
  75. // setProps({
  76. // model:{ field2: data.data, field1: data.info }
  77. // })
  78. });
  79. function confirm() {
  80. console.log('确定')
  81. console.log(getFieldsValue()) // 表单数据
  82. closeModal() // 关闭弹窗
  83. }
  84. return {
  85. register,
  86. schemas,
  87. registerForm,
  88. model: modelRef,
  89. confirm,
  90. adaptWidth,
  91. treeData,
  92. arr
  93. };
  94. },
  95. });
  96. </script>
  97. <style lang='less'>
  98. .ant-form-item-label {
  99. text-align: center !important;
  100. }
  101. .tree-label {
  102. width: 20.6%;
  103. margin-top: 8px;
  104. margin-bottom: 1em;
  105. text-align: center;
  106. }
  107. @media (max-width: 639px) {
  108. .ant-form-item-label {
  109. line-height: 2.5715 !important;
  110. text-align: center !important;
  111. }
  112. .tree-label {
  113. width: 33%;
  114. margin-top: 8px;
  115. margin-bottom: 1em;
  116. text-align: center;
  117. }
  118. }
  119. </style>