Просмотр исходного кода

feat(@six/smart-pharmacy): 智慧药事系统第一版用户管理接口对接

cmj 1 месяц назад
Родитель
Сommit
b402497e45

+ 6 - 0
apps/smart-pharmacy/src/api/index.ts

@@ -30,6 +30,12 @@ export const http = createRequestClient({
       code = rawCode === 200 ? 0 : rawCode;
       message = (body.msg ?? body.message ?? '') as string;
       data = (body.data ?? (body.user ? body : void 0)) as Recordable;
+      if (!data && Array.isArray(body.rows)) {
+        data = {
+          total: body.total ?? 0,
+          items: body.rows,
+        };
+      }
       const { code: _c, msg: _m, message: _msg, data: _d, ...r } = body;
       rest = r;
     }

+ 58 - 28
apps/smart-pharmacy/src/api/method/system.ts

@@ -44,10 +44,12 @@ export namespace SystemModel {
     name: string;
     worker?: string;
     mobile?: string;
+    phone?: string;
     roles?: Array<Role | string>;
     sititutionId?: string;
     pid?: string;
     password?: string;
+    remark?: string;
     stateSel?: 0 | 1;
     status?: 0 | 1;
     roleNames?: string;
@@ -127,10 +129,10 @@ export function listRolesMethod(page = 1, size = 20, query?: TransformData) {
 
 export function optionsRoleMethod() {
   return http.get<SystemModel.Role[], TransformData[]>(
-    `/admin/right_RoleMgr/optionselect`,
+    `/manager/system/role/optionselect`,
     {
       transform(data) {
-        return data.map((item) => fromRole(item));
+        return (Array.isArray(data) ? data : []).map((item) => fromRole(item));
       },
     },
   );
@@ -157,13 +159,22 @@ export function listOrganizationsMethodAll() {
     },
   );
 }
-// 获取机构(属树形结构)
+function fromDeptTreeSelect(nodes?: TransformData[]): TransformData[] {
+  return (nodes ?? []).map((node) => ({
+    id: String(node.id ?? ''),
+    pid: String(node.id ?? ''),
+    name: node.label,
+    children: fromDeptTreeSelect(node.children),
+  }));
+}
+
+// 获取部门树(用户表单所属机构)
 export function listUsersInstitutionMethodTree() {
-  return http.Post<SystemModel.User[], TransformData[]>(
-    `/basis/medicalinstitutionsMgr/treeList`,
+  return http.get<TransformData[], TransformData[]>(
+    `/manager/system/user/deptTree`,
     {
       transform(data) {
-        return data.map((item) => fromUser(item));
+        return fromDeptTreeSelect(Array.isArray(data) ? data : []);
       },
     },
   );
@@ -205,14 +216,22 @@ export function deleteRolesMethod(params: Pick<SystemModel.User, 'id'>[]) {
 }
 
 // 获取用户列表
-export function listUsersMethod(page = 1, size = 20, query?: SystemModel.User) {
-  return http.post<TransformList<SystemModel.User>, TransformList>(
-    `/portal/userMgr/listPain`,
-    toUser(query),
+export function listUsersMethod(
+  page = 1,
+  size = 20,
+  query?: Partial<SystemModel.User>,
+) {
+  return http.get<TransformList<SystemModel.User>, TransformList>(
+    `/manager/system/user/list`,
     {
-      params: { page, limit: size },
+      params: { pageNum: page, pageSize: size, ...toUser(query) },
+      cacheFor: 0, // 或 localCache: null,关闭该 GET 的内存缓存
       transform({ items, ...data }) {
-        return { ...data, items: items.map((item) => fromUser(item)) };
+        const rows = items ?? [];
+        return {
+          ...data,
+          items: rows.map((item) => fromUser(item)),
+        };
       },
     },
   );
@@ -227,35 +246,46 @@ export function editProjectMethod(data: Partial<SystemModel.Project>) {
 }
 
 export function editUserMethod(data: Partial<SystemModel.User>) {
-  return http.post(
-    data?.id ? `/portal/userMgr/update` : `/portal/userMgr/Add`,
-    toUser(data),
-  );
+  const body = toUser(data);
+  return data?.id || data?.pid
+    ? http.put(`/manager/system/user`, body)
+    : http.post(`/manager/system/user`, body);
 }
 // 用户状态更改
 export function updateUserStatusMethod(
-  pid: string,
+  userId: string,
   { status }: { status: 0 | 1 },
 ) {
-  return http.Post(`/portal/userMgr/updateState`, { pid, stateSel: status });
+  return http.put(`/manager/system/user/changeStatus`, {
+    userId,
+    status: String(status),
+  });
 }
 export function getUserMethod(id: string) {
-  return http.get<SystemModel.User, TransformData>(`/portal/userMgr/${id}`, {
-    transform(data) {
-      return fromUser(data);
+  return http.get<SystemModel.User, TransformData>(
+    `/manager/system/user/${id}`,
+    {
+      transform(data) {
+        return fromUser(data);
+      },
     },
-  });
+  );
 }
 
-export function deleteUserMethod(data: Pick<SystemModel.User, 'pid'>) {
-  console.warn('data', data);
+export function deleteUserMethod(
+  data: Pick<SystemModel.User, 'id' | 'pid'>,
+) {
   return deleteUsersMethod([data]);
 }
 
-export function deleteUsersMethod(params: Pick<SystemModel.User, 'pid'>[]) {
-  return http.post(`/portal/userMgr/BatchDelete`, void 0, {
-    params: { ids: params.map((item) => item.pid).join(',') },
-  });
+export function deleteUsersMethod(
+  params: Pick<SystemModel.User, 'id' | 'pid'>[],
+) {
+  const userIds = params
+    .map((item) => item.pid ?? item.id)
+    .filter(Boolean)
+    .join(',');
+  return http.delete(`/manager/system/user/${userIds}`);
 }
 // 删除机构
 export function deleteOrganizationMethod(

+ 16 - 5
apps/smart-pharmacy/src/api/model/role.ts

@@ -3,22 +3,33 @@ import type { SystemModel, TransformData } from '#/api';
 import { fromRow } from '#/api/model/index';
 
 export function fromRole(data?: TransformData): SystemModel.Role {
+  const roleId = data?.roleId ?? data?.pid ?? data?.id;
+  const id = roleId === undefined || roleId === null ? '' : String(roleId);
+  const statusRaw = data?.status ?? data?.stateSel;
   return {
-    ...fromRow(data),
-    id: data?.pid,
-    name: data?.rolename,
-    code: data?.rolecode,
+    ...fromRow({ ...data, id }),
+    id,
+    name: data?.roleName ?? data?.rolename,
+    code: data?.roleKey ?? data?.rolecode,
     remark: data?.remark,
-    status: ({ '0': 1, '1': 0 } as const)[<string>data?.stateSel ?? 1] ?? 1,
+    status:
+      statusRaw === 0 || statusRaw === '0'
+        ? 0
+        : statusRaw === 1 || statusRaw === '1'
+          ? 1
+          : (({ '0': 0, '1': 1 } as const)[<string>data?.stateSel ?? '1'] ?? 1),
     permissions: Array.isArray(data?.menuIds) ? data?.menuIds : [],
   };
 }
 
 export function toRole(data?: Partial<SystemModel.Role>): TransformData {
   return {
+    roleId: data?.id,
     pid: data?.id,
+    roleName: data?.name,
     rolename: data?.name,
     remark: data?.remark,
+    status: data?.status === 0 ? '0' : data?.status === 1 ? '1' : void 0,
     stateSel: data?.status === 0 ? '1' : '0',
     menuIds: data?.permissions ?? [],
   };

+ 63 - 26
apps/smart-pharmacy/src/api/model/user.ts

@@ -1,44 +1,81 @@
 import type { SystemModel, TransformData } from '#/api';
 
-import { fromRole, fromRow, toRole } from '#/api/model';
+import { fromRole, fromRow } from '#/api/model';
 
 export function fromUser(data?: TransformData): SystemModel.User {
+  const userId = data?.userId ?? data?.pid ?? data?.id;
+  const id = userId === undefined || userId === null ? '' : String(userId);
   return {
-    ...fromRow(data),
-    id: data?.id,
-    access: data?.userid,
-    name: data?.username,
+    ...fromRow({
+      ...data,
+      id,
+      createUser: data?.createBy ?? data?.createUser,
+      createTime: data?.createTime,
+    }),
+    id,
+    access: data?.userName ?? data?.userid,
+    name: data?.nickName ?? data?.username,
     worker: data?.jobnumber,
-    mobile: data?.mobile,
-    pid: data?.pid,
+    mobile: data?.phonenumber ?? data?.mobile,
+    phone: data?.phonenumber ?? data?.mobile ?? data?.phone,
+    pid: id,
     roles: data?.roles?.map((item: TransformData) => fromRole(item)) ?? [],
-    sititutionId: data?.sititutionId,
-    status: data?.stateSel === 0 || data?.stateSel === '0' ? 0 : 1,
-    hospitalName: data?.hospitalName,
+    sititutionId:
+      data?.deptId === undefined || data?.deptId === null
+        ? data?.sititutionId
+        : String(data.deptId),
+    status:
+      data?.status === 0 ||
+      data?.status === '0' ||
+      data?.stateSel === 0 ||
+      data?.stateSel === '0'
+        ? 0
+        : 1,
+    hospitalName: data?.dept?.deptName ?? data?.hospitalName,
     roleNames:
-      data?.roles?.map((item: TransformData) => item.rolename).join(',') ?? '',
-    createUser: data?.createUser,
+      data?.roles
+        ?.map(
+          (item: TransformData) => item.roleName ?? item.rolename ?? item.name,
+        )
+        .filter(Boolean)
+        .join(',') ?? '',
+    remark: data?.remark,
+    createUser: data?.createBy ?? data?.createUser,
   };
 }
 
 export function toUser(data?: Partial<SystemModel.User>): TransformData {
-  const roles =
-    data?.roles?.map((item) =>
-      typeof item === 'string' ? { pid: item } : toRole(item),
-    ) ?? [];
+  const roleIds =
+    data?.roles
+      ?.map((item) => {
+        if (typeof item === 'string' || typeof item === 'number') return item;
+        return item.id ?? item.pid;
+      })
+      .filter((item) => item !== undefined && item !== '') ?? [];
+
+  const userId = data?.pid ?? data?.id;
+  const status =
+    data?.status === 0 || data?.status === 1
+      ? String(data.status)
+      : undefined;
+
   return {
-    pid: data?.pid,
-    userid: data?.access,
-    username: data?.name,
+    userId: userId || void 0,
+    userName: data?.access,
+    nickName: data?.name,
     password: data?.password,
     jobnumber: data?.worker,
-    mobile: data?.mobile,
-    hospitalName: data?.hospitalName,
-    roles: roles.length > 0 ? roles : void 0,
-    roleIds: roles.map((item) => item.pid).join(',') || void 0,
+    phonenumber: data?.phone ?? data?.mobile,
+    deptId: data?.sititutionId,
+    roleIds: roleIds.length > 0 ? roleIds : void 0,
+    status,
+    remark: data?.remark,
+    // 兼容旧接口查询
+    pid: userId || void 0,
+    userid: data?.access,
+    username: data?.name,
+    mobile: data?.phone ?? data?.mobile,
     sititutionId: data?.sititutionId,
-    // 查询时:当 status 为空/undefined 时传 null;创建/编辑时为 0/1 则直传
-    stateSel:
-      data?.status === 0 || data?.status === 1 ? (data.status as 0 | 1) : null,
+    stateSel: status === undefined ? null : (Number(status) as 0 | 1),
   };
 }

+ 28 - 56
apps/smart-pharmacy/src/views/system/user/data.ts

@@ -10,11 +10,19 @@ import {
   optionsRoleMethod,
 } from '#/api/method/system';
 import { $t } from '#/locales';
-import { mockData } from './mock';
 
 export function useUserSearchFormSchema(): VbenFormSchema[] {
   return [
-    { component: 'Input', fieldName: 'name', label: $t('system.role.name') },
+    {
+      component: 'Input',
+      fieldName: 'access',
+      label: $t('system.user.access'),
+    },
+    {
+      component: 'Input',
+      fieldName: 'name',
+      label: $t('system.user.name'),
+    },
     {
       component: 'Select',
       componentProps: {
@@ -56,24 +64,25 @@ export function useUserTableColumns<T = SystemModel.User>(
       title: $t('system.organization.phone'),
       minWidth: 100,
     },
-    // {
-    //   field: 'rolename',
-    //   title: $t('system.role._'),
-    //   minWidth: 100,
-    // },
     {
-      field: 'rolename',
+      field: 'roleNames',
       title: $t('system.role._'),
       minWidth: 150,
       slots: {
         default: ({ row }) => {
-          // 使用 map 提取所有 rolename,然后用逗号连接
+          const user = row as SystemModel.User;
           const roleNames =
-            row.roles
-              ?.map((item: any) => item?.rolename?.trim?.())
-              .filter(Boolean) || [];
-
-          return roleNames.join(',') || '-';
+            user.roleNames ||
+            user.roles
+              ?.map(
+                (item) =>
+                  typeof item === 'string'
+                    ? item
+                    : (item?.name ?? item?.roleName ?? item?.rolename),
+              )
+              .filter(Boolean)
+              .join(',');
+          return roleNames || '-';
         },
       },
     },
@@ -90,7 +99,6 @@ export function useUserTableColumns<T = SystemModel.User>(
     {
       cellRender: {
         attrs: { beforeChange: onStatusChange },
-        // props: { accessRole: '超级管理员' },
         props: { _props: { checkedValue: 0, unCheckedValue: 1 } },
         name: onStatusChange ? 'CellSwitch' : 'CellTag',
       },
@@ -122,28 +130,14 @@ export function useUserFormSchema(): VbenFormSchema[] {
       component: 'ApiTreeSelect',
       componentProps: {
         class: 'w-full',
-        // api: listUsersInstitutionMethodTree,
-        options: [
-          {
-            label: '京慈堂杭州分堂',
-            value: 1,
-          },
-          {
-            label: '京慈堂',
-            value: 2,
-          },
-          {
-            label: '测试机构1',
-            value: 3,
-          },
-        ],
+        api: listUsersInstitutionMethodTree,
         labelField: 'name',
         valueField: 'pid',
         childrenField: 'children',
         treeDefaultExpandAll: true,
         dropdownStyle: { maxHeight: 400, overflow: 'auto' },
       },
-      fieldName: 'hospitalName',
+      fieldName: 'sititutionId',
       label: $t('system.organization.belong'),
       rules: 'required',
     },
@@ -188,42 +182,20 @@ export function useUserFormSchema(): VbenFormSchema[] {
       component: 'ApiSelect',
       componentProps: {
         allowClear: true,
-        // api: optionsRoleMethod,
-        options: [
-          {
-            label: '科长',
-            value: '760631a1-58ca-49e7-9ec9-82475dbbcb5c',
-          },
-          {
-            label: '治疗师',
-            value: "ee272511-ecd9-45f7-a405-50c58395629d",
-          },
-          {
-            label: '账号',
-            value: "8e317a00-d83e-40ed-b1ba-b7d5a9757cbb",
-          },
-          {
-            label: '系统管理',
-            value: "53c0c7dc-3cd9-4b35-988e-2d6d57715787",
-          },
-        ],
+        api: optionsRoleMethod,
         class: 'w-full',
-        // labelField: 'name',
-        // valueField: 'id',
-        childrenField: 'children',
+        labelField: 'name',
+        valueField: 'id',
         mode: 'multiple',
       },
       fieldName: 'roles',
-      // fieldName: 'rolesNew',
       label: $t('system.role._'),
       rules: 'selectRequired',
     },
-
     {
       component: 'Input',
       fieldName: 'remark',
       label: $t('system.user.remark'),
-      rules: '',
     },
   ];
 }

+ 12 - 40
apps/smart-pharmacy/src/views/system/user/list.vue

@@ -13,10 +13,14 @@ import { Plus } from '@vben/icons';
 import { Button, message, Modal, notification } from 'ant-design-vue';
 
 import { useVbenVxeGrid } from '#/adapter/vxe-table';
+import {
+  deleteUserMethod,
+  listUsersMethod,
+  updateUserStatusMethod,
+} from '#/api';
 import { $t } from '#/locales';
 
 import { useUserSearchFormSchema, useUserTableColumns } from './data';
-import { mockData } from './mock';
 import Form from './modules/form.vue';
 
 const [FormModal, formModalApi] = useVbenModal({
@@ -33,35 +37,15 @@ const [Grid, gridApi] = useVbenVxeGrid({
     columns: useUserTableColumns(onActionClick, onStatusChange),
     height: 'auto',
     keepSource: true,
-    // proxyConfig: {
-    //   ajax: {
-    //     query({ page }, formValues) {
-    //       return listUsersMethod(page.currentPage, page.pageSize, formValues);
-    //     },
-    //   },
-    // },
-    // rowConfig: {
-    //   keyField: 'id',
-    // },
     proxyConfig: {
-      response: {
-        result: 'Data.Items',
-        total: 'Data.TotalRecordCount',
-      },
-
       ajax: {
-        query() {
-          return Promise.resolve({
-            Data: mockData,
-            ResultInfo: '操作成功',
-            ResultCode: 0,
-          });
+        query({ page }, formValues) {
+          return listUsersMethod(page.currentPage, page.pageSize, formValues);
         },
       },
     },
-
     rowConfig: {
-      keyField: 'pid',
+      keyField: 'id',
     },
   } as VxeTableGridOptions<SystemModel.User>,
 });
@@ -117,26 +101,17 @@ async function onStatusChange(newStatus: 0 | 1, row: SystemModel.User) {
     );
 
     try {
-      // await updateUserStatusMethod(row.pid!, { status: newStatus });
-      mockData.Items = mockData.Items.map((item) => {
-        if (item.pid === row.pid) {
-          return {
-            ...item,
-            status: newStatus,
-          };
-        }
-        return item;
-      });
+      await updateUserStatusMethod(row.pid ?? row.id, { status: newStatus });
       notification.success({
         message: '切换状态成功',
       });
+      return true;
     } catch (error: any) {
       notification.error({
         message: error.message || '切换状态失败',
       });
+      return false;
     }
-
-    return true;
   } catch {
     return false;
   }
@@ -148,8 +123,6 @@ function onRefresh() {
 
 function onEditHandle(row?: SystemModel.User) {
   formModalApi.setData(row ?? {}).open();
-  console.log('row', row);
-  console.log('mockdata', mockData)
 }
 
 async function onDeleteHandle(row: SystemModel.User) {
@@ -159,8 +132,7 @@ async function onDeleteHandle(row: SystemModel.User) {
     key: 'action_process_msg',
   });
   try {
-    console.log('删除', row);;
-    // await deleteUserMethod(row);
+    await deleteUserMethod(row);
     message.success({
       content: $t('ui.actionMessage.deleteSuccess', [row.name]),
       key: 'action_process_msg',

+ 2 - 4
apps/smart-pharmacy/src/views/system/user/modules/form.vue

@@ -28,7 +28,6 @@ const getTitle = computed(() => {
 });
 
 const [Form, formApi] = useVbenForm({
-  // layout: 'vertical',
   schema: useUserFormSchema(),
   showDefaultActions: false,
 });
@@ -45,8 +44,7 @@ const [Modal, modalApi] = useVbenModal({
       modalApi.lock();
       const data = await formApi.getValues();
       try {
-        console.log('data', data)
-        // await edit.send({ ...formData.value, ...data });
+        await edit.send({ ...formData.value, ...data });
         await modalApi.close();
       } finally {
         modalApi.lock(false);
@@ -68,7 +66,7 @@ const [Modal, modalApi] = useVbenModal({
         }
         formData.value = data;
         formData.value.roles = data.roles?.map((role) =>
-          typeof role === 'string' ? role : role.pid,
+          typeof role === 'string' ? role : role.id,
         );
         formApi.setValues(formData.value);
       }