popup.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. <template>
  2. <BasicModal v-bind="$attrs" @register="register" @ok="confirm" :title="title">
  3. <BasicForm @register="registerForm" :model="model" />
  4. <!-- <MenuTree /> -->
  5. </BasicModal>
  6. </template>
  7. <script lang="ts">
  8. import { Tree } from 'ant-design-vue';
  9. import { defineComponent, PropType, reactive, ref, toRefs } from 'vue';
  10. import { BasicModal, useModalInner } from '/@/components/Modal';
  11. import { BasicForm, FormSchema, useForm } from '/@/components/Form/index';
  12. import { adapt } from '/@/utils/adapt';
  13. import { groupTree } from './data';
  14. interface popupData {
  15. title: string;
  16. }
  17. interface Role {
  18. id: string | number;
  19. treeData: object[];
  20. }
  21. export default defineComponent({
  22. components: { BasicModal, BasicForm, [Tree.name]: Tree },
  23. props: {
  24. popupData: {
  25. type: Object as PropType<PopupData>,
  26. default: {},
  27. },
  28. },
  29. setup(props, { emit }) {
  30. const role = reactive<Role>({
  31. id: 0,
  32. });
  33. const popupData: PopupData = props.popupData;
  34. const modelRef = ref({});
  35. const adaptWidth = adapt();
  36. const schemas: FormSchema[] = [
  37. {
  38. field: 'groups',
  39. label: '所属组别',
  40. component: 'MultipleTreeSelect',
  41. componentProps: {
  42. replaceFields: {
  43. title: 'name',
  44. key: 'groups',
  45. value: 'id',
  46. },
  47. getPopupContainer: () => document.body,
  48. },
  49. labelWidth: adaptWidth.labelWidth,
  50. colProps: {
  51. span: adaptWidth.elContainer,
  52. },
  53. },
  54. {
  55. field: 'username',
  56. component: 'Input',
  57. label: '用户名',
  58. labelWidth: adaptWidth.labelWidth,
  59. colProps: {
  60. span: adaptWidth.elContainer,
  61. },
  62. required: true,
  63. },
  64. {
  65. field: 'nickname',
  66. component: 'Input',
  67. label: '昵称',
  68. labelWidth: adaptWidth.labelWidth,
  69. colProps: {
  70. span: adaptWidth.elContainer,
  71. },
  72. required: true,
  73. },
  74. {
  75. field: 'email',
  76. component: 'Input',
  77. label: 'Email',
  78. labelWidth: adaptWidth.labelWidth,
  79. colProps: {
  80. span: adaptWidth.elContainer,
  81. },
  82. },
  83. {
  84. field: 'password',
  85. component: 'InputPassword',
  86. label: '密码',
  87. labelWidth: adaptWidth.labelWidth,
  88. colProps: {
  89. span: adaptWidth.elContainer,
  90. },
  91. required: true,
  92. },
  93. {
  94. field: 'loginfailure',
  95. component: 'Input',
  96. label: '失败次数',
  97. labelWidth: adaptWidth.labelWidth,
  98. defaultValue: 0,
  99. colProps: {
  100. span: adaptWidth.elContainer,
  101. },
  102. },
  103. {
  104. field: 'status',
  105. label: '状态',
  106. component: 'RadioButtonGroup',
  107. componentProps: {
  108. options: [
  109. { label: '启用', value: 'normal' },
  110. { label: '停用', value: 'locked' },
  111. ],
  112. },
  113. labelWidth: adaptWidth.labelWidth,
  114. colProps: {
  115. span: adaptWidth.elContainer,
  116. },
  117. },
  118. ];
  119. const [registerForm, { getFieldsValue, updateSchema, setFieldsValue, resetFields }] = useForm(
  120. {
  121. labelWidth: 120,
  122. schemas,
  123. showActionButtonGroup: false,
  124. actionColOptions: {
  125. span: 24,
  126. },
  127. }
  128. );
  129. // const [register, { closeModal }] = useModalInner((data) => {
  130. // modelRef.value = data;
  131. //
  132. // });
  133. const [register, { closeModal }] = useModalInner((data) => {
  134. resetFields();
  135. // if (unref(isUpdate)) {
  136. // setFieldsValue(data);
  137. // }
  138. setFieldsValue(data);
  139. role.id = data.id;
  140. updateSchema({
  141. field: 'groups',
  142. componentProps: { treeData: popupData.treeData },
  143. });
  144. });
  145. function confirm() {
  146. const data = getFieldsValue();
  147. console.log(`确定`, data);
  148. if (role.id) {
  149. data.id = role.id;
  150. }
  151. const popupData = { closeModal, data };
  152. emit('saveData', popupData);
  153. // closeModal(); // 关闭弹窗
  154. }
  155. return {
  156. register,
  157. schemas,
  158. registerForm,
  159. model: modelRef,
  160. confirm,
  161. adaptWidth,
  162. ...toRefs(popupData),
  163. };
  164. },
  165. });
  166. </script>
  167. <style lang="less">
  168. .ant-form-item-label {
  169. text-align: center !important;
  170. }
  171. .tree-label {
  172. width: 20.6%;
  173. margin-top: 8px;
  174. margin-bottom: 1em;
  175. text-align: center;
  176. }
  177. @media (max-width: 639px) {
  178. .ant-form-item-label {
  179. line-height: 2.5715 !important;
  180. text-align: center !important;
  181. }
  182. .tree-label {
  183. width: 33%;
  184. margin-top: 8px;
  185. margin-bottom: 1em;
  186. text-align: center;
  187. }
  188. }
  189. </style>