Kaynağa Gözat

feat(api): save

gemercheung 3 yıl önce
ebeveyn
işleme
c00b4ffbc9

+ 4 - 0
src/api/system/model/systemModel.ts

@@ -12,6 +12,10 @@ export type RoleParams = {
 
 export type RolePageParams = BasicPageParams & RoleParams;
 
+export type CheckUserParams = {
+  phone?: string;
+};
+
 export type DeptParams = {
   deptName?: string;
   status?: string;

+ 12 - 2
src/api/system/system.ts

@@ -4,6 +4,7 @@ import {
   MenuParams,
   RoleParams,
   RolePageParams,
+  CheckUserParams,
   MenuListGetResultModel,
   DeptListGetResultModel,
   AccountListGetResultModel,
@@ -31,8 +32,9 @@ enum Api {
   GetAllRoleList = '/basic-api/system/getAllRoleList',
   roleSelectList = '/zfb-api/zfb/shop/sys/role/select',
 
-  DeptList = '/zfb-api/zfb/shop/sys/company/list',
-  // DeptTree = 'sys/dept/list',
+  DeptList = '/zfb-api/zfb/shop/sys/dept/list',
+
+  checkUser = '/zfb-api/zfb/user/checkUserExists',
 }
 
 export const getAccountList = (params: AccountParams) =>
@@ -46,6 +48,7 @@ export const getMenuList = (params?: MenuParams) =>
     url: Api.MenuList,
     params: params,
   });
+//menu
 export const saveMenuApi = (params?: MenuParams) =>
   defHttp.post<MenuListGetResultModel>({ url: Api.saveMenu, params });
 
@@ -55,12 +58,16 @@ export const updateMenuApi = (params?: MenuParams) =>
 export const deleteMenuApi = (params?: (string | number)[]) =>
   defHttp.post<MenuListGetResultModel>({ url: Api.deleteMenu, params });
 
+//roles
 export const getRoleListByPage = (params?: RolePageParams) =>
   defHttp.post<RolePageListGetResultModel>({ url: Api.RolePageList, params });
 
 export const getAllRoleList = (params?: RoleParams) =>
   defHttp.post<RoleListGetResultModel>({ url: Api.GetAllRoleList, params });
 
+export const roleSelectListApi = (params?: RoleParams) =>
+  defHttp.post<RoleListGetResultModel>({ url: Api.roleSelectList, params });
+
 export const setRoleStatus = (id: number, status: string) =>
   defHttp.post({ url: Api.setRoleStatus, params: { id, status } });
 
@@ -69,3 +76,6 @@ export const isAccountExist = (account: string) =>
 
 export const deptListApi = (params?: RolePageParams) =>
   defHttp.post<RolePageListGetResultModel>({ url: Api.DeptList, params });
+
+export const checkUserApi = (params?: CheckUserParams) =>
+  defHttp.post<RolePageListGetResultModel>({ url: Api.checkUser, params });

+ 3 - 0
src/components/Form/src/BasicForm.vue

@@ -241,6 +241,9 @@
       function setFormModel(key: string, value: any) {
         formModel[key] = value;
         const { validateTrigger } = unref(getBindValue);
+        console.log(' unref(getBindValue)', unref(getBindValue));
+
+        console.log('validateTrigger', validateTrigger, formModel);
         if (!validateTrigger || validateTrigger === 'change') {
           validateFields([key]).catch((_) => {});
         }

+ 17 - 14
src/views/dashboard/system/account/AccountModal.vue

@@ -8,7 +8,8 @@
   import { BasicModal, useModalInner } from '/@/components/Modal';
   import { BasicForm, useForm } from '/@/components/Form/index';
   import { accountFormSchema } from './account.data';
-  import { getDeptList } from '/@/api/system/system';
+  // import { getDeptList } from '/@/api/system/system';
+  // import { makeMenuTree, TreeMenuNode } from '/@/utils/treeUtils';
 
   export default defineComponent({
     name: 'AccountModal',
@@ -17,8 +18,8 @@
     setup(_, { emit }) {
       const isUpdate = ref(true);
       const rowId = ref('');
-
-      const [registerForm, { setFieldsValue, updateSchema, resetFields, validate }] = useForm({
+      // updateSchema
+      const [registerForm, { setFieldsValue, resetFields, validate }] = useForm({
         labelWidth: 100,
         schemas: accountFormSchema,
         showActionButtonGroup: false,
@@ -39,17 +40,19 @@
           });
         }
 
-        const treeData = await getDeptList();
-        updateSchema([
-          {
-            field: 'pwd',
-            show: !unref(isUpdate),
-          },
-          {
-            field: 'dept',
-            componentProps: { treeData },
-          },
-        ]);
+        // const treeData = await roleSelectListApi();
+        // const tData = (await getDeptList()) as any as TreeMenuNode[];
+        // const treeData = makeMenuTree(tData);
+        // updateSchema([
+        //   {
+        //     field: 'pwd',
+        //     show: !unref(isUpdate),
+        //   },
+        //   {
+        //     field: 'dept',
+        //     componentProps: { treeData },
+        //   },
+        // ]);
       });
 
       const getTitle = computed(() => (!unref(isUpdate) ? '新增账号' : '编辑账号'));

+ 59 - 28
src/views/dashboard/system/account/account.data.ts

@@ -1,5 +1,5 @@
 // isAccountExist
-import { getAllRoleList } from '/@/api/system/system';
+import { roleSelectListApi, checkUserApi } from '/@/api/system/system';
 import { BasicColumn } from '/@/components/Table';
 import { FormSchema } from '/@/components/Table';
 import { h } from 'vue';
@@ -61,7 +61,7 @@ export const searchFormSchema: FormSchema[] = [
 
 export const accountFormSchema: FormSchema[] = [
   {
-    field: 'account',
+    field: 'userName',
     label: '用户名',
     component: 'Input',
     // helpMessage: ['本字段演示异步验证', '不能输入带有admin的用户名'],
@@ -83,52 +83,83 @@ export const accountFormSchema: FormSchema[] = [
     //   },
     // ],
   },
-  {
-    field: 'pwd',
-    label: '密码',
-    component: 'InputPassword',
-    required: true,
-    ifShow: false,
-  },
+  // {
+  //   field: 'pwd',
+  //   label: '密码',
+  //   component: 'InputPassword',
+  //   required: true,
+  //   ifShow: false,
+  // },
   {
     label: '角色',
     field: 'role',
     component: 'ApiSelect',
     componentProps: {
-      api: getAllRoleList,
+      api: roleSelectListApi,
       labelField: 'roleName',
-      valueField: 'roleValue',
-    },
-    required: true,
-  },
-  {
-    field: 'dept',
-    label: '所属部门',
-    component: 'TreeSelect',
-    componentProps: {
-      fieldNames: {
-        label: 'deptName',
-        key: 'id',
-        value: 'id',
-      },
-      getPopupContainer: () => document.body,
+      valueField: 'roleId',
     },
     required: true,
   },
+  // {
+  //   field: 'dept',
+  //   label: '所属部门',
+  //   component: 'TreeSelect',
+  //   componentProps: {
+  //     fieldNames: {
+  //       label: 'deptName',
+  //       key: 'id',
+  //       value: 'id',
+  //     },
+  //     getPopupContainer: () => document.body,
+  //   },
+  //   required: true,
+  // },
   {
-    field: 'nickname',
+    field: 'nickName',
     label: '昵称',
     component: 'Input',
     required: true,
   },
 
   {
-    label: '邮箱',
-    field: 'email',
+    field: 'phoneNum',
+    label: '手机号',
     component: 'Input',
     required: true,
+    helpMessage: ['验证提示', '手机号需在指房宝APP注册后才可新增'],
+
+    itemProps: {
+      validateTrigger: 'blur',
+    },
+    rules: [
+      {
+        required: true,
+        message: '请输入手机号',
+      },
+      {
+        validator(_, value) {
+          return new Promise((resolve, reject) => {
+            checkUserApi({
+              phone: value,
+            })
+              .then(() => resolve())
+              .catch((err) => {
+                reject(err.message || '验证失败');
+              });
+          });
+        },
+      },
+    ],
   },
 
+  // {
+  //   label: '邮箱',
+  //   field: 'email',
+  //   component: 'Input',
+  //   required: true,
+  // },
+
   {
     label: '备注',
     field: 'remark',