outaozhen 3 rokov pred
rodič
commit
3830b5e624

+ 36 - 31
src/pages/Permission/Role/components/SetPermission/index.tsx

@@ -8,10 +8,9 @@ const { TabPane } = Tabs
 const SetPermission = ({ ID, activeKey }) => {
   const bottom = 10
   const [state, setState] = useState({
-    checkValue: []
+    checked: true
   })
-  console.log(state.checkValue)
-
+  const [selectdType, setSelectdType] = useState<any[]>([])
   const { run: trySetRolePermission } = useRequest(
     (params: API.SetRolePermissionParams) => setRolePermission(params),
     {
@@ -21,11 +20,22 @@ const SetPermission = ({ ID, activeKey }) => {
       }
     }
   )
-  const handleOnchange = e => {
-    setState({ ...state, checkValue: e })
+  const handleOnchange = (e, type) => {
+    setState({ ...state, checked: e.target.checked })
+    const types = [...selectdType]
+    const checked = e.target.checked
+    if (checked) {
+      if (!selectdType.includes(type)) {
+        types.push(type)
+      } else {
+        types = types.filter(item => item !== type)
+      }
+      setSelectdType(types)
+      console.log(type)
+    }
   }
   const handleSubmit = () => {
-    trySetRolePermission({ ID, frontPermission: state.checkValue })
+    // trySetRolePermission({ ID, frontPermission: state.checkValue })
   }
   useEffect(() => {
     if (activeKey === '2') {
@@ -41,15 +51,9 @@ const SetPermission = ({ ID, activeKey }) => {
               <div>
                 {/* <h4>我的项目</h4> */}
                 <div className="my-2">
-                  <Checkbox.Group
-                    onChange={handleOnchange}
-                    options={[
-                      {
-                        value: 'todo',
-                        label: '已办待办'
-                      }
-                    ]}
-                  />
+                  <Checkbox onChange={e => handleOnchange(e, 'todo')} checked={state.checked}>
+                    已办待办
+                  </Checkbox>
                 </div>
               </div>
             </Card>
@@ -59,32 +63,33 @@ const SetPermission = ({ ID, activeKey }) => {
               <div>
                 <h4>我的项目</h4>
                 <div className="my-2">
-                  <Checkbox.Group
-                    onChange={handleOnchange}
-                    options={[
-                      { value: 'access', label: '查看项目' },
-                      { value: 'add', label: '新建项目' },
-                      { value: 'report', label: '项目上报' }
-                    ]}
-                  />
+                  <Checkbox onChange={e => handleOnchange(e, 'access')} checked={state.checked}>
+                    查看项目
+                  </Checkbox>
+                  <Checkbox onChange={e => handleOnchange(e, 'add')} checked={state.checked}>
+                    新建项目
+                  </Checkbox>
+                  <Checkbox onChange={e => handleOnchange(e, 'report')} checked={state.checked}>
+                    项目上报
+                  </Checkbox>
                 </div>
               </div>
               <div>
                 <h4 className="pt-3">我参与的项目</h4>
                 <div className="my-2">
-                  <Checkbox.Group
-                    onChange={handleOnchange}
-                    options={[{ value: 'access', label: '查看项目' }]}
-                  />
+                  <Checkbox onChange={e => handleOnchange(e, 'access')} checked={state.checked}>
+                    查看项目
+                  </Checkbox>
                 </div>
               </div>
               <div>
                 <h4 className="pt-3">全部项目</h4>
                 <div className="my-2">
-                  <Checkbox.Group
-                    onChange={handleOnchange}
-                    options={[{ value: 'viewAllProjects', label: '查看项目' }]}
-                  />
+                  <Checkbox
+                    onChange={e => handleOnchange(e, 'viewAllProjects')}
+                    checked={state.checked}>
+                    查看项目
+                  </Checkbox>
                 </div>
               </div>
               <div>