Browse Source

feat: 使用自定义hooks接管巡检列表、弹窗功能逻辑

lanjianrong 4 years ago
parent
commit
36ef8129fd

+ 17 - 9
src/components/Authorization/index.tsx

@@ -1,6 +1,8 @@
 import { tenderStore } from '@/store/mobx'
-import React from 'react'
-import { Redirect } from 'react-router'
+import history from '@/utils/history'
+import { storage } from '@/utils/util'
+import { observer } from 'mobx-react'
+import React, { useEffect } from 'react'
 interface Authorization {
   type: 'contract' | 'safe' | 'quality'
   auth: 'access' | 'add' | 'delete'
@@ -9,14 +11,20 @@ interface Authorization {
 
 /** auth的格式化为:delete | add | access */
 const Authorization: React.FC<Authorization> = ({ type, auth, children }) => {
-
+  useEffect(() => {
+    if (tenderStore.bid) {
+      tenderStore.saveTenderPermission(tenderStore.bid)
+    }
+    if (!tenderStore.tender.bidsectionId) {
+      tenderStore.cloneTenderFromStorage()
+    }
+  }, [ ])
   const authPass = 1
-  // 获取store存储的权限
+
+
+  // 获取mobx存储的权限
   const permission = tenderStore.permission[type]
-  // 根本没有权限进入标段
-  if (!permission.access) {
-    return <Redirect to="/"></Redirect>
-  }
+
   if (permission[auth] === authPass) {
     return <>{children}</>
   }
@@ -24,4 +32,4 @@ const Authorization: React.FC<Authorization> = ({ type, auth, children }) => {
 }
 
 
-export default Authorization
+export default observer(Authorization)

+ 4 - 4
src/pages/Contract/List/index.tsx

@@ -35,9 +35,9 @@ const List: React.FC<RouteComponentProps> = props => {
   const [ tree, setTree ] = useContractTree()
   const [ expandedRowKeys, setRowKeys ] = useTableExpand(tree)
 
-  const handleLinkClick = async (id: string, name: string) => {
-    await tenderStore.saveTenderInfo({ bidsectionId: id, name })
-    handleIntoBidsection("contract")
+  const handleLinkClick = (id: string, name: string) => {
+    tenderStore.saveTenderInfo({ bidsectionId: id, name })
+    handleIntoBidsection("contract", id)
   }
 
   const columns: ColumnsType<ContractTree> = [
@@ -137,7 +137,7 @@ const List: React.FC<RouteComponentProps> = props => {
           rowKey={record => record.id}
           indentSize={20}
           expandable={{ expandedRowKeys, onExpand: setRowKeys }}
-          bordered></Table>
+          bordered />
       </div>
     </div>
   )

+ 30 - 35
src/pages/Quality/Content/List/index.tsx

@@ -8,6 +8,7 @@ import { tenderStore } from '@/store/mobx'
 import { iFileModal } from '@/types/file'
 import { iCreateSafe } from '@/types/safe'
 import { safeStatus } from '@/utils/common/constStatus'
+import { useListModal } from '@/utils/common/customHooks'
 import consts from '@/utils/consts'
 import { dayjsFormat } from '@/utils/util'
 import { Button, message, Table } from 'antd'
@@ -34,19 +35,7 @@ interface iModal {
 }
 
 const QualityList: React.FC<{}> = () => {
-  const [ ruleModal, setRuleModal ] = useState<iModal>({
-    visible: false,
-    loading: false
-  })
-  const [ addModal, setAddModal ] = useState<iModal>({
-    visible: false,
-    loading: false
-  })
-  const [ fileModal, setFileModal ] = useState<iFileModal>({
-    visible: false,
-    dataType: consts.DATA_TYPE.QUALITY,
-    dataId: ''
-  })
+  const [ state, setState ] = useListModal(consts.DATA_TYPE.QUALITY)
   useEffect(() => {
     initData()
   }, [])
@@ -96,8 +85,8 @@ const QualityList: React.FC<{}> = () => {
       // eslint-disable-next-line react/display-name
       render: (text: string, record) => {
         return (
-          <span className="pi-pointer" onClick={() => setFileModal({ ...fileModal, dataId: record.id, visible: true })}>
-            <SvgIcon type="xxh-paperclip1"></SvgIcon> {text}
+          <span className="pi-pointer" onClick={() => setState({ ...state, fileModal: { ...state.fileModal, dataId: record.id, visible: true } })}>
+            <SvgIcon type="xxh-paperclip1" /> {text}
           </span>
         )
       }
@@ -111,14 +100,17 @@ const QualityList: React.FC<{}> = () => {
       }
     }
   ]
-  const [ qualityList, setQualityList ] = useState<iQualityList[]>([])
-  const [ total, setTotal ] = useState<number>(0)
+  // const [ qualityList, setQualityList ] = useState<iQualityList[]>([])
+  // const [ total, setTotal ] = useState<number>(0)
   const initData = (pageNo: number = 1, pageSize: number = consts.PAGE_SIZE) => {
+    const initModal = {
+      ruleModal: { loading: false, visible: false },
+      addModal: { loading: false, visible: false }
+    }
     apiQualityList(tenderStore.bid, pageNo, pageSize)
       .then(({ code = -1, data = [], total = 0 }) => {
         if (code === consts.RET_CODE.SUCCESS) {
-          setQualityList(data)
-          setTotal(total)
+          setState({ ...state, dataList: data, total, ...initModal })
         }
       })
       .catch(err => {
@@ -127,68 +119,71 @@ const QualityList: React.FC<{}> = () => {
   }
 
   const onRuleCreate = async (ruleValue: any) => {
-    setRuleModal({ ...ruleModal, loading: true })
+    setState({ ...state, ruleModal: { ...state.ruleModal, loading: true } })
     const { code = -1 } = await apiSaveRule({ bidsectionId: tenderStore.bid, type: 'quality_rule', rule: ruleValue })
     if (code === consts.RET_CODE.SUCCESS) {
-      message.success('规则更改成功!')
       initData()
+      return message.success('规则更改成功!')
+    } else {
+      setState({ ...state, ruleModal: { ...state.ruleModal, loading: false } })
     }
-    setRuleModal({ ...ruleModal, loading: false, visible: false })
   }
   const onAddCreate = async (payload: iCreateSafe) => {
-    setAddModal({ ...addModal, loading: true })
+    setState({ ...state, addModal: { ...state.addModal, loading: true } })
     const createTime = dayjsFormat(payload.createTime)
     const { code = -1 } = await apiCreateQuality({ ...payload, createTime })
     if (code === consts.RET_CODE.SUCCESS) {
       initData()
+      return message.success('添加新的巡检记录成功!')
+    }else {
+      setState({ ...state, addModal: { ...state.addModal, loading: false } })
     }
-    setAddModal({ ...addModal, loading: false, visible: false })
   }
 
   return (
     <div className="wrap-contaniner">
       <Header title="质量巡检">
         <Slot position="right">
-          {!qualityList.length ? (
+          {!state.dataList.length ? (
             <Button
               type="ghost"
               size="small"
               icon={<SvgIcon type="xxh-cog" />}
               className="pi-mg-right-3"
               style={{ color: '#007bff' }}
-              onClick={() => setRuleModal({ ...ruleModal, visible: true })}>
+              onClick={() => setState({ ...state, ruleModal: { ...state.ruleModal, visible: true } })}>
               设置
             </Button>
           ) : null}
 
           <Authorization type="quality" auth="add">
-            <Button type="primary" size="small" onClick={() => setAddModal({ ...addModal, visible: true })}>
+            <Button type="primary" size="small" onClick={() => setState({ ...state, addModal: { ...state.addModal, visible: true } })}>
               新建巡检
             </Button>
           </Authorization>
         </Slot>
       </Header>
       <Table
-        dataSource={qualityList}
+        dataSource={state.dataList}
         columns={columns}
         pagination={{
           hideOnSinglePage: true,
           size: 'small',
           pageSize: consts.PAGE_SIZE,
           onChange: (page, pageSize) => initData(page, pageSize),
-          total
+          total: state.total
         }}
         rowKey={record => record.id}
-        bordered></Table>
+        bordered />
       <RuleModal
         type={consts.RULE.QUALITY}
         title="质量巡检编号设置"
-        visible={ruleModal.visible}
+        visible={state.ruleModal.visible}
         onCreate={onRuleCreate}
-        loading={ruleModal.loading}
-        onCancel={() => setRuleModal({ ...ruleModal, visible: false })}></RuleModal>
-      <AddModel visible={addModal.visible} onCreate={onAddCreate} loading={addModal.loading} onCancel={() => setAddModal({ ...addModal, visible: false })}></AddModel>
-      <FileModal visible={fileModal.visible} dataType={fileModal.dataType} dataId={fileModal.dataId} onCancel={() => setFileModal({ ...fileModal, visible: false })}></FileModal>
+        loading={state.ruleModal.loading}
+        onCancel={() => setState({ ...state, ruleModal: { ...state.ruleModal, visible: false } })} />
+      <AddModel visible={state.addModal.visible} onCreate={onAddCreate} loading={state.addModal.loading} onCancel={() => setState({ ...state, addModal: { ...state.addModal, visible: false } })} />
+      <FileModal visible={state.fileModal.visible} dataType={state.fileModal.dataType} dataId={state.fileModal.dataId} onCancel={() => setState({ ...state, fileModal: { ...state.fileModal, visible: false } })} />
     </div>
   )
 }

+ 4 - 4
src/pages/Quality/List/index.tsx

@@ -34,9 +34,9 @@ const List: React.FC<RouteComponentProps> = () => {
     }
   }
 
-  const handleLinkClick = async (id: string, name: string) => {
-    await tenderStore.saveTenderInfo({ bidsectionId: id, name })
-    handleIntoBidsection("quality")
+  const handleLinkClick = (id: string, name: string) => {
+    tenderStore.saveTenderInfo({ bidsectionId: id, name })
+    handleIntoBidsection("quality", id)
 
   }
   const columns: ColumnsType<ContractTree> = [
@@ -121,7 +121,7 @@ const List: React.FC<RouteComponentProps> = () => {
           rowKey={record => record.id}
           indentSize={20}
           expandable={{ expandedRowKeys, onExpand: setRowKeys }}
-          bordered></Table>
+          bordered />
       </div>
     </div>
   )

+ 16 - 14
src/pages/Safe/Content/Info/Detail/index.tsx

@@ -22,6 +22,7 @@ import { RouteComponentProps } from 'react-router'
 import { apiGetSafeDetail, apiResfulSafeAudit } from './api'
 import AuditModal from '@/pages/Quality/Content/Info/Detail/components/Modal'
 import styles from './index.module.scss'
+import Authorization from '@/components/Authorization'
 const { TextArea } = Input
 interface iModalObj {
   ossModal: boolean
@@ -226,7 +227,9 @@ const Detail: React.FC<RouteComponentProps> = props => {
     if (!status) {
       return (
         <div className="pi-flex-row pi-align-center">
-          <ZhCloseButton size="small" onClick={() => btnClick('delete')}>删除巡检</ZhCloseButton>
+          <Authorization type="safe" auth="delete">
+            <ZhCloseButton size="small" onClick={() => btnClick('delete')}>删除巡检</ZhCloseButton>
+          </Authorization>
           <ZhSubmitButton size="small" className="pi-mg-left-5" onClick={() => btnClick('start')}>提交审批</ZhSubmitButton>
         </div>
       )
@@ -275,7 +278,7 @@ const Detail: React.FC<RouteComponentProps> = props => {
                 <th style={{ width: '150px' }}>检查项目</th>
                 <td>
                   {
-                    isEdited ? <span>{detail.inspection}</span> : <TextArea value={detail.inspection} onChange={(e) => { setDetail({ ...detail, inspection: e.currentTarget.value }) }}></TextArea>
+                    isEdited ? <span>{detail.inspection}</span> : <TextArea value={detail.inspection} onChange={(e) => { setDetail({ ...detail, inspection: e.currentTarget.value }) }} />
                   }
                 </td>
               </tr>
@@ -283,7 +286,7 @@ const Detail: React.FC<RouteComponentProps> = props => {
                 <th style={{ width: '150px' }}>现场检查情况</th>
                 <td>
                   {
-                    isEdited ? <span>{detail.inspectionDetail}</span> : <TextArea value={detail.inspectionDetail} onChange={(e) => { setDetail({ ...detail, inspectionDetail: e.currentTarget.value }) }}></TextArea>
+                    isEdited ? <span>{detail.inspectionDetail}</span> : <TextArea value={detail.inspectionDetail} onChange={(e) => { setDetail({ ...detail, inspectionDetail: e.currentTarget.value }) }} />
                   }
                 </td>
               </tr>
@@ -291,7 +294,7 @@ const Detail: React.FC<RouteComponentProps> = props => {
                 <th style={{ width: '150px' }}>处理要求及措施</th>
                 <td>
                   {
-                    isEdited ? <span>{detail.demand}</span> : <TextArea value={detail.demand} onChange={(e) => { setDetail({ ...detail, demand: e.currentTarget.value }) }}></TextArea>
+                    isEdited ? <span>{detail.demand}</span> : <TextArea value={detail.demand} onChange={(e) => { setDetail({ ...detail, demand: e.currentTarget.value }) }} />
                   }
                 </td>
               </tr>
@@ -305,7 +308,7 @@ const Detail: React.FC<RouteComponentProps> = props => {
                         locale={locale}
                         allowClear={false}
                         value={dayjs(detail.createTime)}
-                        onChange={value => setDetail({ ...detail, createTime: value?.format() })}></DatePicker>
+                        onChange={value => setDetail({ ...detail, createTime: value?.format() })} />
                   }
 
                 </td>
@@ -330,7 +333,7 @@ const Detail: React.FC<RouteComponentProps> = props => {
                   <tr>
                     <th style={{ width: '150px' }}>整改情况</th>
                     <td>
-                      <TextArea value={detail.checkOrder.opinion} onChange={(e) => setDetail({ ...detail, checkOrder: { ...detail.checkOrder, opinion: e.currentTarget.value } })}></TextArea>
+                      <TextArea value={detail.checkOrder.opinion} onChange={(e) => setDetail({ ...detail, checkOrder: { ...detail.checkOrder, opinion: e.currentTarget.value } })} />
                     </td>
                   </tr>
                   <tr>
@@ -341,7 +344,7 @@ const Detail: React.FC<RouteComponentProps> = props => {
                         locale={locale}
                         allowClear={false}
                         value={dayjs(detail.checkOrder.create_time)}
-                        onChange={value => setDetail({ ...detail, checkOrder: { ...detail.checkOrder, create_time: value?.format() } })}></DatePicker>
+                        onChange={value => setDetail({ ...detail, checkOrder: { ...detail.checkOrder, create_time: value?.format() } })} />
                     </td>
                   </tr>
                   <tr>
@@ -380,7 +383,7 @@ const Detail: React.FC<RouteComponentProps> = props => {
           <table className="pi-table pi-bordered mt-3">
             <thead>
               <tr>
-                <th></th>
+                <th />
                 <th className="pi-text-center">附件</th>
                 <th className="pi-text-center">上传者</th>
                 <th className="pi-text-center" style={{ width: 200 }}>
@@ -410,7 +413,7 @@ const Detail: React.FC<RouteComponentProps> = props => {
                   <td className="pi-text-center">{dayjsFormat(file.createTime)}</td>
                   <td className="pi-text-center pi-width-90">
                     <Tooltip title="移除">
-                      <Button size="small" type="text" icon={<SvgIcon type="xxh-times-circle1" />} style={{ color: '#df3f45' }} onClick={() => delFile(file.id, !idx)}></Button>
+                      <Button size="small" type="text" icon={<SvgIcon type="xxh-times-circle1" />} style={{ color: '#df3f45' }} onClick={() => delFile(file.id, !idx)} />
                     </Tooltip>
                   </td>
                 </tr>
@@ -424,28 +427,27 @@ const Detail: React.FC<RouteComponentProps> = props => {
                       pageSize={consts.PAGE_SIZE}
                       hideOnSinglePage={true}
                       total={detail.file.total}
-                      onChange={(page, pageSize) => fileListChange(page, pageSize)}></Pagination>
+                      onChange={(page, pageSize) => fileListChange(page, pageSize)} />
                   </td>
                 </tr>
               ) : null}
             </tbody>
           </table>
-          <AuditContent data={auditData} onSelect={addAuditor} onDelete={delAuditor}></AuditContent>
+          <AuditContent data={auditData} onSelect={addAuditor} onDelete={delAuditor} />
         </div>
       </div>
       <OssUploadModal
         visible={modalObj.ossModal}
         onCancel={() => setModalObj({ ...modalObj, ossModal: false })}
         onCreate={onCreate}
-        onShow={onOssModalShow}>
-      </OssUploadModal>
+        onShow={onOssModalShow} />
       <AuditModal
         type="safe"
         modalObj={modalProps}
         onCancel={() => setModalObj({ ...modalObj, auditModal: false })}
         onCreate={onModalConfirm}
         auditors={detail.auditors}
-        curAuditor={detail.latestAuditor}></AuditModal>
+        curAuditor={detail.latestAuditor} />
     </div>
   )
 }

+ 46 - 51
src/pages/Safe/Content/List/index.tsx

@@ -6,8 +6,9 @@ import RuleModal from '@/components/RuleModal'
 import SvgIcon from '@/components/SvgIcon'
 import { tenderStore } from '@/store/mobx'
 import { iFileModal } from '@/types/file'
-import { iCreateSafe } from '@/types/safe'
+import { iCreateSafe, iSafeList } from '@/types/safe'
 import { safeStatus } from '@/utils/common/constStatus'
+import { useListModal } from '@/utils/common/customHooks'
 import consts from '@/utils/consts'
 import { dayjsFormat } from '@/utils/util'
 import { Button, message, Table } from 'antd'
@@ -16,39 +17,29 @@ import React, { useEffect, useState } from 'react'
 import { Link } from 'react-router-dom'
 import { apiCreateSafe, apiSafeList, apiSaveRule } from './api'
 import AddModel from './modal'
-interface iSafeList {
-  id: string
-  code: string
-  createTime: string
-  position: string
-  inspection: string
-  inspectionDetail: string
-  demand: string
-  status: number
-  auditName: string
-  fileCounts: number
-}
+
 interface iModal {
   visible: boolean
   loading: boolean
 }
 
 const SafeList: React.FC<{}> = () => {
-  const [ ruleModal, setRuleModal ] = useState<iModal>({
-    visible: false,
-    loading: false
-  })
-  const [ addModal, setAddModal ] = useState<iModal>({
-    visible: false,
-    loading: false
-  })
-  const [ fileModal, setFileModal ] = useState<iFileModal>({
-    visible: false,
-    dataType: consts.DATA_TYPE.SAFE,
-    dataId: ''
-  })
-  const [ safeList, setSafeList ] = useState<iSafeList[]>([])
-  const [ total, setTotal ] = useState<number>(0)
+  const [ state, setState ] = useListModal(consts.DATA_TYPE.SAFE)
+  // const [ ruleModal, setRuleModal ] = useState<iModal>({
+  //   visible: false,
+  //   loading: false
+  // })
+  // const [ addModal, setAddModal ] = useState<iModal>({
+  //   visible: false,
+  //   loading: false
+  // })
+  // const [ fileModal, setFileModal ] = useState<iFileModal>({
+  //   visible: false,
+  //   dataType: consts.DATA_TYPE.SAFE,
+  //   dataId: ''
+  // })
+  // const [ safeList, setSafeList ] = useState<iSafeList[]>([])
+  // const [ total, setTotal ] = useState<number>(0)
   useEffect(() => {
     initData()
   }, [])
@@ -98,8 +89,8 @@ const SafeList: React.FC<{}> = () => {
       // eslint-disable-next-line react/display-name
       render: (text: string, record) => {
         return (
-          <span className="pi-pointer" onClick={() => setFileModal({ ...fileModal, dataId: record.id, visible: true })}>
-            <SvgIcon type="xxh-paperclip1"></SvgIcon> {text}
+          <span className="pi-pointer" onClick={() => setState({ ...state, fileModal: { ...state.fileModal, dataId: record.id, visible: true } })}>
+            <SvgIcon type="xxh-paperclip1" /> {text}
           </span>
         )
       }
@@ -115,11 +106,14 @@ const SafeList: React.FC<{}> = () => {
   ]
 
   const initData = (pageNo: number = 1, pageSize: number = consts.PAGE_SIZE) => {
+    const initModal = {
+      ruleModal: { loading: false, visible: false },
+      addModal: { loading: false, visible: false }
+    }
     apiSafeList(tenderStore.bid, pageNo, pageSize)
       .then(({ code = -1, data = [], total = 0 }) => {
         if (code === consts.RET_CODE.SUCCESS) {
-          setSafeList(data)
-          setTotal(total)
+          setState({ ...state, dataList: data, total, ...initModal })
         }
       })
       .catch(err => {
@@ -128,70 +122,71 @@ const SafeList: React.FC<{}> = () => {
   }
 
   const onRuleCreate = async (ruleValue: any) => {
-    setRuleModal({ ...ruleModal, loading: true })
+    setState({ ...state, ruleModal: { ...state.ruleModal, loading: true } })
     const { code = -1 } = await apiSaveRule({ bidsectionId: tenderStore.bid, type: 'safe_rule', rule: ruleValue })
     if (code === consts.RET_CODE.SUCCESS) {
-      message.success('规则更改成功!')
       initData()
+      return message.success('规则更改成功!')
+    } else {
+      setState({ ...state, ruleModal: { ...state.ruleModal, loading: false } })
     }
-    setRuleModal({ ...ruleModal, loading: false, visible: false })
   }
   const onAddCreate = async (payload: iCreateSafe) => {
-    setAddModal({ ...addModal, loading: true })
+    setState({ ...state, addModal: { ...state.addModal, loading: true } })
     const createTime = dayjsFormat(payload.createTime)
     const { code = -1 } = await apiCreateSafe({ ...payload, createTime })
     if (code === consts.RET_CODE.SUCCESS) {
       initData()
+      return message.success('添加新的巡检记录成功!')
+    }else {
+      setState({ ...state, addModal: { ...state.addModal, loading: false } })
     }
-    setAddModal({ ...addModal, loading: false, visible: false })
   }
 
   return (
     <div className="wrap-contaniner">
       <Header title="安全巡检">
         <Slot position="right">
-          {!safeList.length ? (
+          {!state.dataList.length ? (
             <Button
               type="ghost"
               size="small"
               icon={<SvgIcon type="xxh-cog" />}
               className="pi-mg-right-3"
               style={{ color: '#007bff' }}
-              onClick={() => setRuleModal({ ...ruleModal, visible: true })}>
+              onClick={() => setState({ ...state, ruleModal: { ...state.ruleModal, visible: true } })}>
               设置
             </Button>
-          ) : (
-            ''
-          )}
+          ) : null}
 
           <Authorization type="safe" auth="add">
-            <Button type="primary" size="small" onClick={() => setAddModal({ ...addModal, visible: true })}>
+            <Button type="primary" size="small" onClick={() => setState({ ...state, addModal: { ...state.addModal, visible: true } })}>
               新建巡检
             </Button>
           </Authorization>
         </Slot>
       </Header>
       <Table
-        dataSource={safeList}
+        dataSource={state.dataList}
         columns={columns}
         pagination={{
           hideOnSinglePage: true,
           size: 'small',
           pageSize: consts.PAGE_SIZE,
           onChange: (page, pageSize) => initData(page, pageSize),
-          total
+          total: state.total
         }}
         rowKey={record => record.id}
-        bordered></Table>
+        bordered />
       <RuleModal
         type={consts.RULE.SAFE}
         title="安全巡检编号设置"
-        visible={ruleModal.visible}
+        visible={state.ruleModal.visible}
         onCreate={onRuleCreate}
-        loading={ruleModal.loading}
-        onCancel={() => setRuleModal({ ...ruleModal, visible: false })}></RuleModal>
-      <AddModel visible={addModal.visible} onCreate={onAddCreate} loading={addModal.loading} onCancel={() => setAddModal({ ...addModal, visible: false })}></AddModel>
-      <FileModal visible={fileModal.visible} dataType={fileModal.dataType} dataId={fileModal.dataId} onCancel={() => setFileModal({ ...fileModal, visible: false })}></FileModal>
+        loading={state.ruleModal.loading}
+        onCancel={() => setState({ ...state, ruleModal: { ...state.ruleModal, visible: false } })} />
+      <AddModel visible={state.addModal.visible} onCreate={onAddCreate} loading={state.addModal.loading} onCancel={() => setState({ ...state, addModal: { ...state.addModal, visible: false } })} />
+      <FileModal visible={state.fileModal.visible} dataType={state.fileModal.dataType} dataId={state.fileModal.dataId} onCancel={() => setState({ ...state, fileModal: { ...state.fileModal, visible: false } })} />
     </div>
   )
 }

+ 1 - 1
src/pages/Safe/Content/List/modal.tsx

@@ -83,7 +83,7 @@ const SafeCreateForm: React.FC<iSafeCreateFormProps> = ({
           <Input placeholder="请填写巡检项"/>
         </Form.Item>
         <Form.Item name="createTime" label="日期" rules={[ { required: true, message: '请选择日期' } ]}>
-          <DatePicker locale={locale} allowClear className="pi-width-100P"></DatePicker>
+          <DatePicker locale={locale} allowClear className="pi-width-100P" />
         </Form.Item>
         <div className={styles.warningFooter}>添加后再补充完善其余信息</div>
       </Form>

+ 2 - 2
src/pages/Safe/Content/index.tsx

@@ -7,10 +7,10 @@ const Content:React.FC<NavigationGuardsProps> = props => {
   const { routeConfig, match, location } = props
   return (
     <>
-      <LeftSide childRoutes={routeConfig} location={location}></LeftSide>
+      <LeftSide childRoutes={routeConfig} location={location} />
       <div className="panel-content">
         <Switch>
-              <Guards routeConfig={routeConfig} match={match} location={location}></Guards>
+              <Guards routeConfig={routeConfig} match={match} location={location} />
         </Switch>
       </div>
     </>

+ 4 - 4
src/pages/Safe/List/index.tsx

@@ -33,9 +33,9 @@ const List: React.FC<RouteComponentProps> = props => {
   const [ tree, setTree ] = useContractTree()
   const [ expandedRowKeys, setRowKeys ] = useTableExpand(tree)
 
-  const handleLinkClick = async (id: string, name: string) => {
-    await tenderStore.saveTenderInfo({ bidsectionId: id, name })
-    handleIntoBidsection("safe")
+  const handleLinkClick = (id: string, name: string) => {
+    tenderStore.saveTenderInfo({ bidsectionId: id, name })
+    handleIntoBidsection("safe", id)
   }
   const columns: ColumnsType<ContractTree> = [
     {
@@ -119,7 +119,7 @@ const List: React.FC<RouteComponentProps> = props => {
           rowKey={record => record.id}
           indentSize={20}
           expandable={{ expandedRowKeys, onExpand: setRowKeys }}
-          bordered></Table>
+          bordered />
       </div>
     </div>
   )

+ 23 - 22
src/store/mobx/tender/index.ts

@@ -7,7 +7,6 @@ import { action, computed, observable } from "mobx"
 interface iTenderState {
   bidsectionId: string
   name: string
-  permission: AuthState
 }
 
 interface AuthState {
@@ -19,15 +18,28 @@ class Tender {
 
   @observable tender:iTenderState = {
     bidsectionId: '',
-    name: '',
-    permission : {
-      contract: { access: 0, add: 0, delete: 0 },
-      quality: { access: 0, add: 0, delete: 0 },
-      safe: { access: 0, add: 0, delete: 0 }
-    }
+    name: ''
+  }
+  @observable permission: AuthState = {
+    contract: { access: 0, add: 0, delete: 0 },
+    quality: { access: 0, add: 0, delete: 0 },
+    safe: { access: 0, add: 0, delete: 0 }
+  }
+
+  // 保存标段id、名称
+  @action saveTenderInfo ({ bidsectionId, name }: {bidsectionId: string, name: string}) {
+    this.tender = { bidsectionId, name }
+    storage.set('tenderInfo', { bidsectionId, name })
+  }
+
+  // 从本地存储中获取标段信息
+  @action cloneTenderFromStorage() {
+    const tender = storage.get('tenderInfo')
+    tender && (this.tender = tender)
   }
 
-  @action async saveTenderInfo({ bidsectionId, name }: {bidsectionId: string, name: string}) {
+  // 保存标段权限
+  @action async saveTenderPermission(bidsectionId: string) {
     const { code = -1, data } = await apiGetPermission(bidsectionId)
     const permissionObj = {} as AuthState
     if (code === consts.RET_CODE.SUCCESS) {
@@ -38,27 +50,16 @@ class Tender {
         }
       }
     }
-    this.tender = { bidsectionId, name, permission: permissionObj }
-    storage.set('tenderInfo', this.tender)
+    this.permission = permissionObj
   }
 
   @computed get bid() {
     if (!this.tender.bidsectionId) {
-      const tender = storage.get('tenderInfo')
-      this.saveTenderInfo(tender)
-      return tender.bidsectionId
+      const tenderInfo = storage.get('tenderInfo')
+      return tenderInfo.bidsectionId
     }
     return this.tender.bidsectionId
   }
-
-  @computed get permission(): AuthState {
-    if (!this.tender.bidsectionId) {
-      const tender = storage.get('tenderInfo')
-      this.saveTenderInfo(tender)
-      return tender.permission as AuthState
-    }
-    return this.tender.permission as AuthState
-  }
 }
 
 export default new Tender()

+ 31 - 0
src/types/safe.d.ts

@@ -55,3 +55,34 @@ export interface iAuditor {
 export interface iAuditors {
   (key: string): iAuditor[]
 }
+
+export interface iSafeList {
+  id: string
+  code: string
+  createTime: string
+  position: string
+  inspection: string
+  inspectionDetail: string
+  demand: string
+  status: number
+  auditName: string
+  fileCounts: number
+}
+
+export interface ListModal {
+  ruleModal: {
+    visible: boolean
+    loading: boolean
+  },
+  addModal: {
+    visible: boolean
+    loading: boolean
+  },
+  fileModal: {
+    visible: boolean,
+    dataType: number,
+    dataId: string
+  },
+  dataList: iSafeList[]
+  total: number
+}

+ 29 - 0
src/utils/common/customHooks.ts

@@ -1,6 +1,8 @@
 /** 自定义hooks库 */
 import { useState } from 'react'
 import { ContractTree } from '@/types/contract'
+import { ListModal } from '@/types/safe'
+import consts from '../consts'
 
 /** 合同树的自定义hook */
 export const useContractTree = (): [ContractTree, (newTree: ContractTree) => void] => {
@@ -39,6 +41,7 @@ export const useContractTree = (): [ContractTree, (newTree: ContractTree) => voi
   return [ tree, onChange ]
 }
 
+/** 树列表展开收起自定义hook */
 export const useTableExpand = (tree: ContractTree): [string[], (expanded: boolean, record?: ContractTree) => void] => {
   const [ ids, setIds ] = useState<Array<string>>([])
   const onChange = (expanded: boolean, record?: ContractTree) => {
@@ -75,3 +78,29 @@ export const useTableExpand = (tree: ContractTree): [string[], (expanded: boolea
 
   return [ ids, onChange ]
 }
+
+
+/** 巡检列表页自定义hook*/
+export const useListModal = (dataType: number): [ListModal, (newData: ListModal) => void] => {
+  const [ state, setState ] = useState<ListModal>({
+    ruleModal: {
+      visible: false,
+      loading: false
+    },
+    addModal: {
+      visible: false,
+      loading: false
+    },
+    fileModal: {
+      visible: false,
+      dataType,
+      dataId: ''
+    },
+    dataList: [],
+    total: 0
+  })
+  const onChange = (newData: ListModal) => {
+    setState({ ...state, ...newData })
+  }
+  return [ state, onChange ]
+}

+ 3 - 2
src/utils/util.ts

@@ -208,8 +208,9 @@ const formatMoney = (num: number | undefined) => {
 }
 
 // 控制是否有权限进入标段
-const handleIntoBidsection = (permission_type: 'contract' | 'safe' | 'quality'): void => {
-  const permission = !!tenderStore.tender.permission[permission_type].access
+const handleIntoBidsection = async (permission_type: 'contract' | 'safe' | 'quality', bid: string) => {
+  await tenderStore.saveTenderPermission(bid)
+  const permission = !!tenderStore.permission[permission_type].access
   if (permission) {
     history.push(`/console/${permission_type}/content/summary`)
   } else {