123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198 |
- <template>
- <BasicModal v-bind="$attrs" @register="register" @ok="confirm" :title="title">
- <BasicForm @register="registerForm" :model="model" />
- <!-- <MenuTree /> -->
- </BasicModal>
- </template>
- <script lang="ts">
- import { Tree } from 'ant-design-vue';
- import { defineComponent, PropType, reactive, ref, toRefs } from 'vue';
- import { BasicModal, useModalInner } from '/@/components/Modal';
- import { BasicForm, FormSchema, useForm } from '/@/components/Form/index';
- import { adapt } from '/@/utils/adapt';
- import { groupTree } from './data';
- interface popupData {
- title: string;
- }
- interface Role {
- id: string | number;
- treeData: object[];
- }
- export default defineComponent({
- components: { BasicModal, BasicForm, [Tree.name]: Tree },
- props: {
- popupData: {
- type: Object as PropType<PopupData>,
- default: {},
- },
- },
- setup(props, { emit }) {
- const role = reactive<Role>({
- id: 0,
- });
- const popupData: PopupData = props.popupData;
- const modelRef = ref({});
- const adaptWidth = adapt();
- const schemas: FormSchema[] = [
- {
- field: 'groups',
- label: '所属组别',
- component: 'MultipleTreeSelect',
- componentProps: {
- replaceFields: {
- title: 'name',
- key: 'groups',
- value: 'id',
- },
- getPopupContainer: () => document.body,
- },
- labelWidth: adaptWidth.labelWidth,
- colProps: {
- span: adaptWidth.elContainer,
- },
- },
- {
- field: 'username',
- component: 'Input',
- label: '用户名',
- labelWidth: adaptWidth.labelWidth,
- colProps: {
- span: adaptWidth.elContainer,
- },
- required: true,
- },
- {
- field: 'nickname',
- component: 'Input',
- label: '昵称',
- labelWidth: adaptWidth.labelWidth,
- colProps: {
- span: adaptWidth.elContainer,
- },
- required: true,
- },
- {
- field: 'email',
- component: 'Input',
- label: 'Email',
- labelWidth: adaptWidth.labelWidth,
- colProps: {
- span: adaptWidth.elContainer,
- },
- },
- {
- field: 'password',
- component: 'InputPassword',
- label: '密码',
- labelWidth: adaptWidth.labelWidth,
- colProps: {
- span: adaptWidth.elContainer,
- },
- required: true,
- },
- {
- field: 'loginfailure',
- component: 'Input',
- label: '失败次数',
- labelWidth: adaptWidth.labelWidth,
- defaultValue: 0,
- colProps: {
- span: adaptWidth.elContainer,
- },
- },
- {
- field: 'status',
- label: '状态',
- component: 'RadioButtonGroup',
- componentProps: {
- options: [
- { label: '启用', value: 'normal' },
- { label: '停用', value: 'locked' },
- ],
- },
- labelWidth: adaptWidth.labelWidth,
- colProps: {
- span: adaptWidth.elContainer,
- },
- },
- ];
- const [registerForm, { getFieldsValue, updateSchema, setFieldsValue, resetFields }] = useForm(
- {
- labelWidth: 120,
- schemas,
- showActionButtonGroup: false,
- actionColOptions: {
- span: 24,
- },
- }
- );
- // const [register, { closeModal }] = useModalInner((data) => {
- // modelRef.value = data;
- //
- // });
- const [register, { closeModal }] = useModalInner((data) => {
- resetFields();
- // if (unref(isUpdate)) {
- // setFieldsValue(data);
- // }
- setFieldsValue(data);
- role.id = data.id;
- updateSchema({
- field: 'groups',
- componentProps: { treeData: popupData.treeData },
- });
- });
- function confirm() {
- const data = getFieldsValue();
- console.log(`确定`, data);
- if (role.id) {
- data.id = role.id;
- }
- const popupData = { closeModal, data };
- emit('saveData', popupData);
- // closeModal(); // 关闭弹窗
- }
- return {
- register,
- schemas,
- registerForm,
- model: modelRef,
- confirm,
- adaptWidth,
- ...toRefs(popupData),
- };
- },
- });
- </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>
|