lanjianrong 3 سال پیش
والد
کامیت
1a2d791479

+ 1 - 0
package.json

@@ -55,6 +55,7 @@
     "@umijs/route-utils": "^1.0.36",
     "antd": "^4.14.0",
     "classnames": "^2.2.6",
+    "dayjs": "^1.10.7",
     "lodash": "^4.17.11",
     "moment": "^2.25.3",
     "omit.js": "^2.0.2",

+ 1 - 1
src/pages/Institutions/Company/components/CompanyModal.tsx

@@ -78,7 +78,7 @@ const CompanyModal: React.FC<CompanyModalProps> = ({
       title={type === ModalType.ADD ? '新增企事业单位' : '编辑企事业单位'}
       onOk={() => handleOnFinish()}>
       <ProForm formRef={ref} submitter={{ render: false }} {...layout}>
-        {type === ModalType.UPDATE ? <ProFormText name="id" hidden /> : null}
+        {type === ModalType.UPDATE ? <ProFormText name="ID" hidden /> : null}
         <ProFormText
           name="name"
           label="项目名称"

+ 4 - 4
src/pages/Institutions/Company/index.tsx

@@ -44,11 +44,11 @@ const CompanyList: React.FC<ListProps> = ({ dispatch, pTypeList }) => {
       title: '企事业单位简称'
     },
     {
-      dataIndex: 'institution_account_total',
+      dataIndex: 'institutionAccountTotal',
       title: '人员账号'
     },
     {
-      dataIndex: 'create_time',
+      dataIndex: 'createdTime',
       title: '创建时间'
     },
     // {
@@ -103,7 +103,7 @@ const CompanyList: React.FC<ListProps> = ({ dispatch, pTypeList }) => {
   return (
     <div>
       <ProTable<API.InstitutionListItem>
-        rowKey="id"
+        rowKey="ID"
         params={state.params}
         actionRef={tRef}
         columns={columns}
@@ -147,5 +147,5 @@ const CompanyList: React.FC<ListProps> = ({ dispatch, pTypeList }) => {
 }
 
 export default connect(({ project }: { project: ProjectModelState }) => ({
-  pTypeList: project.projectTypeList.map(item => ({ label: item.name, value: item.id }))
+  pTypeList: project.projectTypeList.map(item => ({ label: item.name, value: item.ID }))
 }))(CompanyList)

+ 95 - 0
src/pages/Institutions/Staff/components/StaffModal.tsx

@@ -0,0 +1,95 @@
+import { useRequest } from 'umi'
+import { useRef, useEffect } from 'react'
+import ProForm, { ProFormSelect, ProFormText } from '@ant-design/pro-form'
+import { message, Modal } from 'antd'
+import type { FormInstance } from 'antd'
+import { addAccount, updateAccount } from '@/services/api/institution'
+
+export enum ModalType {
+  ADD = 0,
+  UPDATE = 1
+}
+
+type StaffModalProps = {
+  visible: boolean
+  setVisible: (visible: boolean) => void
+  type: ModalType
+  defaultFormData?: API.AccountListItem
+  // pTypeList: API.ProjectTypeList
+  reloadTable: () => void
+}
+const StaffModal: React.FC<StaffModalProps> = ({
+  visible,
+  setVisible,
+  type,
+  defaultFormData,
+  // pTypeList,
+  reloadTable
+}) => {
+  const layout = {
+    layout: 'horizontal',
+    labelCol: { flex: '100px' }
+  }
+  const ref = useRef<FormInstance>(null)
+  useEffect(() => {
+    defaultFormData && ref.current?.setFieldsValue({ ...defaultFormData })
+  }, [defaultFormData])
+  const { run: tryUpdateAccount } = useRequest(updateAccount, {
+    manual: true,
+    onSuccess: () => {
+      message.success('更新成功')
+    }
+  })
+  const { run: tryAddAccount } = useRequest(addAccount, {
+    manual: true,
+    onSuccess: () => {
+      message.success('创建成功')
+    }
+  })
+
+  const handleOnFinish = () => {
+    ref.current?.validateFields().then(async values => {
+      try {
+        // 执行表单提交
+        if (type === ModalType.ADD) {
+          await tryAddAccount(values)
+        } else {
+          await tryUpdateAccount(values)
+        }
+        setVisible(false)
+        reloadTable()
+        ref.current?.resetFields()
+      } catch (error) {
+        message.error(error)
+      }
+    })
+  }
+  return (
+    <Modal
+      width="35vw"
+      visible={visible}
+      onCancel={() => {
+        ref.current?.resetFields()
+        setVisible(false)
+      }}
+      title={type === ModalType.ADD ? '新增账号' : '编辑账号'}
+      onOk={() => handleOnFinish()}>
+      <ProForm formRef={ref} submitter={{ render: false }} {...layout}>
+        {type === ModalType.UPDATE ? <ProFormText name="ID" hidden /> : null}
+        <ProFormText
+          name="name"
+          label="名称"
+          rules={[{ required: true, message: '请输入账号名称' }]}
+        />
+        <ProFormSelect
+          name="institutionID"
+          label="企事业单位"
+          rules={[{ required: true, message: '请选择企事业单位' }]}
+        />
+        <ProFormText name="phone" label="手机号" />
+      </ProForm>
+    </Modal>
+  )
+}
+
+export default StaffModal

+ 161 - 3
src/pages/Institutions/Staff/index.tsx

@@ -1,5 +1,163 @@
-const Staff = () => {
-  return <div>员工管理</div>
+import ProTable from '@ant-design/pro-table'
+import type { ProColumnType, ActionType } from '@ant-design/pro-table'
+import { Button } from 'antd'
+import consts from '@/utils/consts'
+import { useRef, useState, useEffect } from 'react'
+import { connect } from 'umi'
+import type { ConnectProps } from 'umi'
+import type { ProjectModelState } from '../model'
+import StaffModal, { ModalType } from './components/StaffModal'
+import { queryAcountList } from '@/services/api/institution'
+import dayjs from 'dayjs'
+
+type ListProps = ConnectProps & {
+  pTypeList: { label: string; value: string }[]
+}
+
+const CompanyList: React.FC<ListProps> = ({ dispatch, pTypeList }) => {
+  const tRef = useRef<ActionType>(null)
+  useEffect(() => {
+    if (!pTypeList.length) {
+      dispatch({
+        type: 'project/queryProjectTypeList'
+      })
+    }
+  }, [])
+  const [state, setState] = useState({
+    params: {
+      search: null
+    },
+    visible: false,
+    currentModalType: ModalType.ADD,
+    defaultFormData: null
+  })
+  // const { run: tryDelProject } = useRequest(delProject, {
+  //   manual: true,
+  //   onSuccess: () => tRef.current?.reload()
+  // })
+  const columns: ProColumnType<API.AccountListItem>[] = [
+    {
+      dataIndex: 'account',
+      title: '账号'
+    },
+    {
+      dataIndex: 'name',
+      title: '名称'
+    },
+    {
+      dataIndex: 'accountType',
+      title: '账号类型'
+    },
+    {
+      dataIndex: 'institution',
+      title: '所属企事业单位',
+      renderText: (_, record) => record.institution.name
+      // valueEnum:
+    },
+    {
+      dataIndex: 'createdTime',
+      title: '创建时间',
+      renderText: text => dayjs(text).format('YYYY-MM-DD')
+    },
+    {
+      dataIndex: 'created',
+      title: '创建者'
+    },
+    // {
+    //   dataIndex: 'project_type_id',
+    //   title: '项目类型',
+    //   filters: true,
+    //   filterMultiple: false,
+    //   render: (_, record) => <div>{record.project_type.name}</div>,
+    //   valueEnum: pTypeList.reduce((prev, curr) => {
+    //     const items = { ...prev }
+    //     items[curr.value] = {
+    //       text: curr.label
+    //     }
+    //     return items
+    //   }, {})
+    // },
+    {
+      dataIndex: 'created',
+      title: '创建人'
+    },
+    {
+      title: '操作',
+      dataIndex: 'operation',
+      render: (_, record) => (
+        <div className="divide-x divide-bg-gray-400 flex flex-row">
+          <div
+            className="pr-2 text-primary cursor-pointer hover:text-hex-967bbd"
+            onClick={() => {
+              setState({
+                ...state,
+                visible: true,
+                currentModalType: ModalType.UPDATE,
+                defaultFormData: record
+              })
+            }}>
+            编辑
+          </div>
+          {/* <Popconfirm
+            title="确认删除吗?"
+            okText="确认"
+            cancelText="取消"
+            onConfirm={() => tryDelProject({ id: record.id })}
+          >
+            <div className="pl-2 text-hex-fd3995 cursor-pointer hover:text-hex-e7026e">
+              <DeleteOutlined />
+            </div>
+          </Popconfirm> */}
+        </div>
+      )
+    }
+  ]
+  return (
+    <div>
+      <ProTable<API.AccountListItem>
+        rowKey="ID"
+        params={state.params}
+        actionRef={tRef}
+        columns={columns}
+        request={async (params, filter, sorter) => {
+          const { code = -1, data: { items = [], totle = 0 } = {} } = await queryAcountList({
+            ...params,
+            ...filter,
+            ...sorter
+          })
+          return {
+            data: items,
+            success: code === consts.RET_CODE.SUCCESS,
+            totle
+          }
+        }}
+        toolbar={{
+          search: {
+            onSearch: val => setState({ ...state, params: { ...state.params, search: val } })
+          },
+          actions: [
+            <Button
+              onClick={() =>
+                setState({ ...state, visible: true, currentModalType: ModalType.ADD })
+              }>
+              新建账号
+            </Button>
+          ]
+        }}
+        search={false}
+      />
+      <StaffModal
+        type={state.currentModalType}
+        defaultFormData={state.defaultFormData}
+        pTypeList={pTypeList}
+        visible={state.visible}
+        reloadTable={() => tRef.current?.reload()}
+        setVisible={(visible: boolean) => setState({ ...state, visible })}
+      />
+    </div>
+  )
 }
 
-export default Staff
+export default connect(({ project }: { project: ProjectModelState }) => ({
+  pTypeList: project.projectTypeList.map(item => ({ label: item.name, value: item.ID }))
+}))(CompanyList)

+ 54 - 0
src/pages/Institutions/model.ts

@@ -0,0 +1,54 @@
+import { getProjectTypeList } from '@/services/api/project'
+import consts from '@/utils/consts'
+import type { Effect, Reducer } from 'umi'
+
+export interface InstitutionsModelState {
+  list: API.InstitutionListItem[]
+}
+
+export interface InstitutionsModelType {
+  namespace: 'institutions'
+  state: InstitutionsModelState
+  effects: {
+    query: Effect
+  }
+  reducers: {
+    save: Reducer<InstitutionsModelState>
+    // 启用 immer 之后
+    // save: ImmerReducer<ProjectModelState>;
+  }
+}
+
+const InstitutionsModel: InstitutionsModelType = {
+  namespace: 'institutions',
+  state: {
+    list: []
+  },
+  effects: {
+    *queryInstitutionTypeList({ payload }, { call, put }) {
+      // const response = yield call(getProjectTypeList, payload)
+      // if (response?.code === consts.RET_CODE.SUCCESS) {
+      //   yield put({
+      //     type: 'save',
+      //     payload: {
+      //       projectTypeList: response.data
+      //     }
+      //   })
+      // }
+    }
+  },
+  reducers: {
+    save(state, action) {
+      return {
+        ...state,
+        ...action.payload
+      }
+    }
+    // 启用 immer 之后
+    // save(state, action) {
+    //   state.name = action.payload;
+    // },
+  }
+}
+
+export default InstitutionsModel

+ 4 - 4
src/pages/Project/Management/components/ProjectModal.tsx

@@ -15,9 +15,9 @@ type ProjectModalProps = {
   setVisible: (visible: boolean) => void
   type: ModalType
   defaultFormData?: {
-    id: string
+    ID: string
     name: string
-    project_type_id: string
+    projectTypeID: string
   }
   pTypeList: API.ProjectTypeList
   reloadTable: () => void
@@ -75,14 +75,14 @@ const ProjectModal: React.FC<ProjectModalProps> = ({
       title={type === ModalType.ADD ? '新增项目' : '编辑项目'}
       onOk={() => handleOnFinish()}>
       <ProForm formRef={ref} submitter={{ render: false }}>
-        {type === ModalType.UPDATE ? <ProFormText name="id" hidden /> : null}
+        {type === ModalType.UPDATE ? <ProFormText name="ID" hidden /> : null}
         <ProFormText
           name="name"
           label="项目名称"
           rules={[{ required: true, message: '请输入项目名称' }]}
         />
         <ProFormSelect
-          name="project_type_id"
+          name="projectTypeID"
           label="项目类型"
           rules={[{ required: true, message: '请选择项目类型' }]}
           options={pTypeList}

+ 15 - 14
src/pages/Project/Management/index.tsx

@@ -9,6 +9,7 @@ import type { ConnectProps } from 'umi'
 import type { ProjectModelState } from '../model'
 import { DeleteOutlined } from '@ant-design/icons'
 import ProjectModal, { ModalType } from './components/ProjectModal'
+import dayjs from 'dayjs'
 
 type ListProps = ConnectProps & {
   pTypeList: { label: string; value: string }[]
@@ -41,15 +42,16 @@ const List: React.FC<ListProps> = ({ dispatch, pTypeList }) => {
       title: '项目名称'
     },
     {
-      dataIndex: 'create_time',
-      title: '创建时间'
+      dataIndex: 'createdTime',
+      title: '创建时间',
+      renderText: text => dayjs(text).format('YYYY-MM-DD')
     },
     {
-      dataIndex: 'project_type_id',
+      dataIndex: 'projectTypeID',
       title: '项目类型',
       filters: true,
       filterMultiple: false,
-      render: (_, record) => <div>{record.project_type.name}</div>,
+      render: (_, record) => <div>{record.projectType.name}</div>,
       valueEnum: pTypeList.reduce((prev, curr) => {
         const items = { ...prev }
         items[curr.value] = {
@@ -75,21 +77,19 @@ const List: React.FC<ListProps> = ({ dispatch, pTypeList }) => {
                 visible: true,
                 currentModalType: ModalType.UPDATE,
                 defaultFormData: {
-                  id: record.id,
+                  ID: record.ID,
                   name: record.name,
-                  project_type_id: record.project_type?.id
+                  projectTypeID: record.projectType?.ID
                 }
               })
-            }}
-          >
+            }}>
             编辑
           </div>
           <Popconfirm
             title="确认删除吗?"
             okText="确认"
             cancelText="取消"
-            onConfirm={() => tryDelProject({ id: record.id })}
-          >
+            onConfirm={() => tryDelProject({ ID: record.ID })}>
             <div className="pl-2 text-hex-fd3995 cursor-pointer hover:text-hex-e7026e">
               <DeleteOutlined />
             </div>
@@ -101,7 +101,7 @@ const List: React.FC<ListProps> = ({ dispatch, pTypeList }) => {
   return (
     <div>
       <ProTable<API.ProjectListItem>
-        rowKey="id"
+        rowKey="ID"
         params={state.params}
         actionRef={tRef}
         columns={columns}
@@ -123,8 +123,9 @@ const List: React.FC<ListProps> = ({ dispatch, pTypeList }) => {
           },
           actions: [
             <Button
-              onClick={() => setState({ ...state, visible: true, currentModalType: ModalType.ADD })}
-            >
+              onClick={() =>
+                setState({ ...state, visible: true, currentModalType: ModalType.ADD })
+              }>
               新建项目
             </Button>
           ]
@@ -144,5 +145,5 @@ const List: React.FC<ListProps> = ({ dispatch, pTypeList }) => {
 }
 
 export default connect(({ project }: { project: ProjectModelState }) => ({
-  pTypeList: project.projectTypeList.map(item => ({ label: item.name, value: item.id }))
+  pTypeList: project.projectTypeList.map(item => ({ label: item.name, value: item.ID }))
 }))(List)

+ 26 - 0
src/services/api/institution.ts

@@ -7,6 +7,7 @@ export async function queryInstitutionList(params: API.InstitutionListParams) {
     data: params
   })
 }
+
 /** 编辑企事业单位 */
 export async function updateInstitution(params: API.InstitutionUpdateParams) {
   return request('/Institution/update', {
@@ -14,6 +15,7 @@ export async function updateInstitution(params: API.InstitutionUpdateParams) {
     data: params
   })
 }
+
 /** 新增企事业单位 */
 export async function addInstitution(params: API.InstitutionAddParams) {
   return request('/Institution/add', {
@@ -21,3 +23,27 @@ export async function addInstitution(params: API.InstitutionAddParams) {
     data: params
   })
 }
+
+/** 新增企事业单位下账号 */
+export async function queryAcountList(params: API.InstitutionAddParams) {
+  return request('/Institution/add', {
+    method: 'POST',
+    data: params
+  })
+}
+
+/** 编辑账号 */
+export async function updateAccount(params: API.AcountUpdateParams) {
+  return request('/account/update', {
+    method: 'POST',
+    data: params
+  })
+}
+
+/** 新增账号 */
+export async function addAccount(params: API.AcountAddParams) {
+  return request('/account/add', {
+    method: 'POST',
+    data: params
+  })
+}

+ 73 - 34
src/services/api/typings.d.ts

@@ -17,71 +17,110 @@ declare namespace API {
   type ProjectList = BasicFetchResult<ProjectListItem>
 
   type ProjectListItem = {
-    create_time?: string
-    name?: string
-    created?: string
-    created_id?: string
-    project_type?: ProjectTypeListItem
-    update_time?: string
-    id?: string
+    createdTime: string
+    name: string
+    created: string
+    createdID: string
+    projectType: ProjectTypeListItem
+    ID: string
   }
 
   type ProjectListParams = BasicPageParams & {
     search?: string
-    projectTypeId?: string
+    projectTypeID?: string
   }
 
   type ProjectDelParams = {
-    id: string
+    ID: string
   }
 
   type ProjectUpdateParams = {
-    id: string
+    ID: string
     name: string
-    project_type_id: string
+    projectTypeID: string
   }
-  type ProjectAddParams = Omit<ProjectUpdateParams, 'id'>
+  type ProjectAddParams = Omit<ProjectUpdateParams, 'ID'>
 
   type ProjectTypeList = ProjectTypeListItem[]
 
   type ProjectTypeListItem = {
-    name?: string
-    id?: string
-    update_time?: string
-    create_time?: string
+    name: string
+    ID: string
+    updatedTime: string
+    createdTime: string
   }
 
   /** 事业单位列表 */
   type InstitutionList = BasicFetchResult<InstitutionListItem>
 
   type InstitutionListItem = {
-    name?: string
+    name: string
     /** @name 简称 */
-    acronym?: string
+    acronym: string
     /** @name 企业代码 */
-    enterprise_code?: string
+    enterpriseCode: string
     /** @name 组织结构代码 */
-    organization_code?: string
+    organizationCode: string
     /** @name 人员账号数量 */
-    institution_account_total?: number
-    bank?: string
-    bank_account?: string
-    phone?: string
-    address?: string
-    fax?: string
-    legal_person?: string
-    id_card?: string
-    create_time?: string
-    update_time?: string
-    id?: string
+    institutionAccountTotal: number
+    bank: string
+    bankAccount: string
+    phone: string
+    address: string
+    fax: string
+    legalPerson: string
+    IDCard: string
+    createdTime: string
+    updatedTime: string
+    ID: string
   }
 
   type InstitutionListParams = BasicPageParams & {
     search?: string
-    institution_type_id?: string
+    institutionTypeId?: string
+  }
+
+  type InstitutionAddParams = Omit<InstitutionListItem, 'createdTime' | 'updatedTime' | 'ID'>
+
+  type InstitutionUpdateParams = Omit<InstitutionListItem, 'createdTime' | 'updatedTime'>
+
+  /** 账号列表 */
+  type AccountList = BasicFetchResult<AccountListItem>
+
+  type AccountListItem = {
+    ID: string
+    createdTime: number
+    accountType: string
+    account: string
+    name: string
+    phone: string
+    institution: {
+      ID: string
+      name: string
+    }
+    created: string
+    createdID: string
+    id: string
+  }
+
+  type AccountListParams = BasicPageParams & {
+    search?: string
+    /** @name 账号类型(1-企事业账号) ... */
+    accountType: number
   }
 
-  type InstitutionAddParams = Omit<InstitutionListItem, 'create_time' | 'update_time' | 'id'>
+  type AcountAddParams = {
+    /** @name 企事业ID */
+    institutionID: string
+    /** @name 账号类型(1-企事业账号) ... */
+    accountType: string
+    account: string
+    password: string
+    name: string
+    phone?: string
+  }
 
-  type InstitutionUpdateParams = Omit<InstitutionListItem, 'create_time' | 'update_time'>
+  type AcountUpdateParams = Omit<AcountAddParams, 'account' | 'accountType' | 'password'> & {
+    ID: string
+  }
 }