Sfoglia il codice sorgente

feat: 菜单下创建角色-关联员工流程已走通

lanjianrong 4 anni fa
parent
commit
216581c119

+ 5 - 0
config/proxy.ts

@@ -11,6 +11,11 @@ export default {
       target: 'http://cld2.com',
       changeOrigin: true,
       pathRewrite: { '^': '' }
+    },
+    '/api/': {
+      target: 'http://cld2.com',
+      changeOrigin: true,
+      pathRewrite: { '^': '' }
     }
   },
   test: {

+ 1 - 1
package.json

@@ -86,7 +86,7 @@
     "@umijs/plugin-esbuild": "^1.0.1",
     "@umijs/preset-ant-design-pro": "^1.2.0",
     "@umijs/preset-dumi": "^1.1.7",
-    "@umijs/preset-react": "^1.7.4",
+    "@umijs/preset-react": "1.8.11",
     "@umijs/yorkie": "^2.0.3",
     "carlo": "^0.9.46",
     "cross-env": "^7.0.0",

+ 26 - 8
src/pages/Role/System/index.tsx

@@ -6,6 +6,7 @@ import React, { useMemo, useState, useEffect } from 'react'
 import RoleMenu from './components/RoleMenu/roleMenu'
 import { fetchRoleStaffListByRoleId } from '@/services/user/api'
 import type { ColumnsType } from 'antd/lib/table'
+import ConnectModal from './components/ConnectModal'
 
 const System: React.FC = () => {
   const { TabPane } = Tabs
@@ -55,25 +56,42 @@ const System: React.FC = () => {
     setState({ ...state, id })
   }
 
-  const { run: tryGetRoleStaffList } = useRequest((id: string) => fetchRoleStaffListByRoleId(id), {
-    manual: true,
-    onSuccess: result => {
-      setState({ ...state, roleStaff: result })
+  const { run: tryGetRoleStaffList } = useRequest(
+    (id: string) => fetchRoleStaffListByRoleId({ id }),
+    {
+      manual: true,
+      onSuccess: result => {
+        setState({ ...state, roleStaff: result })
+      }
     }
-  })
+  )
   useEffect(() => {
     if (state.id) {
-      tryGetRoleStaffList()
+      tryGetRoleStaffList(state.id)
     }
   }, [state.id])
+
   return (
     <div className="h-full w-full flex flex-row">
       <RoleMenu menuId={menuId} onSelect={onSelect} />
       <div className="w-max-3/4">
-        <div className="ml-8 bg-white p-4 shadow-md shadow-hex-3e2c5a">
+        <div className="ml-8 bg-white p-4 shadow-md shadow-hex-3e2c5a relative">
+          <div className="absolute right-4 top-4 z-100">
+            {state.id && (
+              <ConnectModal
+                title="关联员工"
+                dataId={state.id}
+                onSelect={() => tryGetRoleStaffList(state.id)}
+              />
+            )}
+          </div>
           <Tabs defaultActiveKey="1" type="card">
             <TabPane tab="员工列表" key="1">
-              <Table<API.RoleStaffListItem> dataSource={state.roleStaff} columns={columns} />
+              <Table<API.RoleStaffListItem>
+                dataSource={state.roleStaff}
+                columns={columns}
+                rowKey={row => row.staffId}
+              />
             </TabPane>
             <TabPane tab="角色权限" key="2">
               <ProForm layout="horizontal" initialValues={{ staff: ['1', '2'] }}>

+ 13 - 6
src/services/user/api.ts

@@ -12,10 +12,10 @@ export async function currentUser(options?: { [key: string]: any }) {
 
 /** 退出登录接口 POST /login/outLogin */
 export async function outLogin(options?: { [key: string]: any }) {
-  return request<Record<string, any>>('/login/outLogin', {
-    method: 'POST',
-    ...(options || {})
-  })
+  // return request<Record<string, any>>('/login/outLogin', {
+  //   method: 'POST',
+  //   ...(options || {})
+  // })
 }
 
 /** 登录接口 POST /login */
@@ -60,12 +60,19 @@ export async function createRoleWithMenuId(params: API.CreateRoleParams) {
 }
 
 /** 获取角色下员工列表 */
-export async function fetchRoleStaffListByRoleId({ id: string }) {
+export async function fetchRoleStaffListByRoleId(params: { id: string }) {
   return request<API.RoleStaffListItem[]>('/role/staff', {
-    params: { id }
+    params
   })
 }
 
+/** 角色下关联员工 */
+export async function addRoleStaff(params: API.AddRoleStaffParams) {
+  return request('/role/staff/add', {
+    method: 'POST',
+    data: params
+  })
+}
 /** 获取员工列表 */
 export async function fetchStaffList(params: API.GetStaffListParams) {
   return request<API.StaffItem[]>('/api/staff/list', {

+ 11 - 3
src/services/user/typings.d.ts

@@ -28,6 +28,11 @@ declare namespace API {
     pageSize?: number
   }
 
+  type BasicFetchResult<T extends any> = {
+    list: T[]
+    total: number
+  }
+
   type MenuListItem = {
     id: string
     parend_id: string
@@ -102,11 +107,9 @@ declare namespace API {
   }
 
   type GetStaffListParams = {
-    current: number
-    pageSize: number
     search?: string
     departmentId?: string
-  }
+  } & PageParams
 
   type StaffItem = {
     staffId: string
@@ -155,4 +158,9 @@ declare namespace API {
     householdRegistrationType: string
     IDcardsValidity: string
   }
+
+  type AddRoleStaffParams = {
+    id: string
+    staffId: string
+  }
 }

+ 4 - 0
windi.config.ts

@@ -21,6 +21,10 @@ export default defineConfig({
         '2xl': '1600px'
       }
     }
+  },
+  shortcuts: {
+    'btn-outline':
+      'text-xs text-primary bg-white border border-primary rounded py-1 px-1 cursor-pointer hover:text-white hover:bg-primary'
   }
 })