123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- <template>
- <BasicModal v-bind="$attrs" @register="register" @ok="confirm" title="添加xxx">
- <BasicForm @register="registerForm" :model="model" />
- <!-- <MenuTree /> -->
- <div style="display: flex;">
- <p class="tree-label">菜单</p>
- <Tree :treeData="treeData" :arr="arr" />
- </div>
- </BasicModal>
- </template>
- <script lang="ts">
- import { defineComponent, ref, } from 'vue';
- import { BasicModal, useModalInner } from '/@/components/Modal';
- import { BasicForm, FormSchema, useForm } from '/@/components/Form/index';
- import { treeData } from './data';
- import Tree from './tree.vue'
- import { adapt } from '/@/utils/adapt'
- export default defineComponent({
- components: { BasicModal, BasicForm, Tree },
- setup() {
- const modelRef = ref({});
- const adaptWidth = adapt()
- const arr:string[] = ['0-0-0-1', '0-0-0']
- const schemas: FormSchema[] = [
- {
- field: 'name',
- component: 'Input',
- label: '账户名',
- labelWidth: adaptWidth.labelWidth,
- colProps: {
- span: adaptWidth.elContainer,
- }
- },
- {
- field: 'password',
- component: 'Input',
- label: '密码',
- labelWidth: adaptWidth.labelWidth,
- colProps: {
- span: adaptWidth.elContainer,
- },
- },
- {
- field: 'detail',
- component: 'Input',
- label: '详情',
- labelWidth: adaptWidth.labelWidth,
- colProps: {
- span: adaptWidth.elContainer,
- },
- },
- ];
- const [
- registerForm,
- {
- getFieldsValue,
- // setProps
- },
- ] = useForm({
- labelWidth: 120,
- schemas,
- showActionButtonGroup: false,
- actionColOptions: {
- span: 24,
- },
- });
- const [register, { closeModal } ] = useModalInner((data) => {
- // 方式1
- // setFieldsValue({
- // field2: data.data,
- // field1: data.info,
- // });
- // 方式2
- modelRef.value = { name: data.name, password: data.password, detail: data.detail };
- // setProps({
- // model:{ field2: data.data, field1: data.info }
- // })
- });
- function confirm() {
- console.log('确定')
- console.log(getFieldsValue()) // 表单数据
- closeModal() // 关闭弹窗
- }
- return {
- register,
- schemas,
- registerForm,
- model: modelRef,
- confirm,
- adaptWidth,
- treeData,
- arr
- };
- },
- });
- </script>
- <style lang='less'>
- .ant-form-item-label {
- text-align: center !important;
- }
- .tree-label {
- width: 20.6%;
- margin-top: 8px;
- margin-bottom: 1em;
- text-align: center;
- }
- @media (max-width: 639px) {
- .ant-form-item-label {
- line-height: 2.5715 !important;
- text-align: center !important;
- }
- .tree-label {
- width: 33%;
- margin-top: 8px;
- margin-bottom: 1em;
- text-align: center;
- }
- }
- </style>
|