|
@@ -1,26 +1,32 @@
|
|
|
import { useState, useEffect } from "react"
|
|
import { useState, useEffect } from "react"
|
|
|
-import { useStore } from 'umi'
|
|
|
|
|
|
|
|
|
|
-const useAutoTable = () => {
|
|
|
|
|
- const collapsed = useStore(state => state.getState().global.collapsed)
|
|
|
|
|
- const needSubtractLength = {
|
|
|
|
|
- // header: 48 main: (margin: 24) card: (padding: 24) table-hedaer: 64
|
|
|
|
|
- height: 48 + 48 + 48 + 64, // 需要被裁掉的高度
|
|
|
|
|
- // collapsed ? 48 : 208 , main: (margin: 24) card: (padding: 24) card-body(padding: 24)
|
|
|
|
|
- width: (collapsed ? 48 : 208) + 48 + 48 + 48
|
|
|
|
|
- }
|
|
|
|
|
- const [scroll, setScroll] = useState({ x: document.body.clientWidth - needSubtractLength.width, y: document.body.clientWidth - needSubtractLength.height })
|
|
|
|
|
|
|
+const useAutoTable = (collapsed) => {
|
|
|
|
|
+ // console.log(collapsed)
|
|
|
|
|
+ const needSubtractHeight = 48 + 48 + 48 + 64 // 需要被裁掉的高度
|
|
|
|
|
+ const needSubtractWidth = (collapsed ? 208 : 48) + 48 + 48 + 48// 需要被裁掉的高度
|
|
|
|
|
+
|
|
|
|
|
+ // const needSubtractLength = {
|
|
|
|
|
+ // // header: 48 main: (margin: 24) card: (padding: 24) table-hedaer: 64
|
|
|
|
|
+ // height: 48 + 48 + 48 + 64, // 需要被裁掉的高度
|
|
|
|
|
+ // // collapsed ? 48 : 208 , main: (margin: 24) card: (padding: 24) card-body(padding: 24)
|
|
|
|
|
+ // width: (collapsed ? 208 : 48) + 48 + 48 + 48
|
|
|
|
|
+ // }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ const [scroll, setScroll] = useState({ x: 0, y: 0 })
|
|
|
|
|
+
|
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
|
|
|
+ setScroll({ ...scroll, x: document.body.clientWidth - needSubtractWidth, y: document.body.clientWidth - needSubtractHeight })
|
|
|
window.addEventListener('resize', () => {
|
|
window.addEventListener('resize', () => {
|
|
|
- setScroll({ ...scroll, x: document.body.clientWidth - needSubtractLength.width, y: document.body.clientWidth - needSubtractLength.height })
|
|
|
|
|
|
|
+ setScroll({ ...scroll, x: document.body.clientWidth - needSubtractWidth, y: document.body.clientWidth - needSubtractHeight })
|
|
|
})
|
|
})
|
|
|
return () => {
|
|
return () => {
|
|
|
window.removeEventListener('resize', () => { })
|
|
window.removeEventListener('resize', () => { })
|
|
|
}
|
|
}
|
|
|
- }, [])
|
|
|
|
|
|
|
+ }, [collapsed])
|
|
|
|
|
|
|
|
// 实际返回的宽度要大一点让table出现滚动条,反正折叠菜单栏卡顿
|
|
// 实际返回的宽度要大一点让table出现滚动条,反正折叠菜单栏卡顿
|
|
|
- return [scroll.x + 10, scroll.y]
|
|
|
|
|
|
|
+ return [scroll.x, scroll.y]
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
export default useAutoTable
|
|
export default useAutoTable
|