Skip to content

Commit

Permalink
feat: 允许resize悬浮窗
Browse files Browse the repository at this point in the history
  • Loading branch information
SSmJaE committed Mar 31, 2023
1 parent 56141a0 commit 381f88d
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 24 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"react-dom": "^18.2.0",
"react-draggable": "^4.4.5",
"react-error-boundary": "^3.1.4",
"react-rnd": "^10.4.1",
"simplebar-react": "^3.2.1",
"valtio": "^1.10.3"
},
Expand Down
44 changes: 44 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion src/views/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,14 @@ export default function App() {
<Global
// 某些页面,会修改lineHeight,所以手动重置回来
styles={css`
#ecos-helper {
#eocs-helper {
all: initial;
font-family: 华文新魏 !important;
line-height: normal !important;
/* 页面可能很长,所以这里使用 fixed 定位 */
position: fixed;
top: 0;
left: 0;
}
`}
></Global>
Expand Down
59 changes: 37 additions & 22 deletions src/views/Log/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import "simplebar-react/dist/simplebar.min.css";

import { useEffect, useMemo, useRef, useState } from "react";
import Draggable from "react-draggable";
import { Rnd } from "react-rnd";
import SimpleBar from "simplebar-react";

import { Global, useTheme } from "@emotion/react";
Expand All @@ -13,9 +13,9 @@ import { store, useStore } from "../../store";
import { MenuBar } from "../components/MenuBar";
import { MenuButton } from "../components/MenuButton";
import PopOver from "../components/PopOver";
import { ErrorRecord } from "./records/Error";
import { InfoRecord } from "./records/Info";
import { QuestionRecord } from "./records/Question";
import { ErrorRecord } from "./records/Error";

function getAppTitle() {
const defaultTitle = "EOCS网课助手";
Expand Down Expand Up @@ -223,47 +223,62 @@ export function LogPanel() {
}, [visibility.log]);

return (
<Draggable
handle="#log-panel-menu-bar"
<Rnd
default={{
x: 100,
y: 100,
width: 600,
height: 100,
}}
minWidth={350}
maxWidth={600}
minHeight={100}
maxHeight={600}
bounds="window"
cancel="#log-panel-menu-buttons"
bounds="body"
onStart={() => {
dragHandleClassName="log-panel-menu-bar"
onDragStart={() => {
setIsDragging(true);
}}
onStop={(e, data) => {
onDragStop={() => {
setIsDragging(false);
// store.setPosition("log", {
// x: data.x,
// y: data.y,
// });
}}
// 默认grid为1,导致rerender次数过多,看起来很卡顿
// 所以主动调大grid增加卡顿感,掩盖因为render导致的卡顿
resizeGrid={[20, 20]}
enableResizing={{
top: false,
right: true,
bottom: false,
left: true,
topRight: false,
bottomRight: false,
bottomLeft: false,
topLeft: false,
}}
>
<animated.div
style={{
// 页面可能很长,所以这里使用 fixed 定位
position: "fixed",
top: 100,
left: 100,
zIndex: 99,
// minWidth: 300,
// maxWidth: 500,
width: 600,
width: "100%",
maxHeight: 600,

background: "rgba(255, 255, 255, 0.95)",
border: "black 2px solid",
borderRadius: 10,

boxShadow:
"0 11px 15px -7px rgba(0, 0, 0, 0.2),0 24px 38px 3px rgba(0, 0, 0, 0.14), 0 9px 46px 8px rgba(0, 0, 0, 0.12)",
// display: visibility.log ? "flex" : "none",
display: display ? "flex" : "none",
flexDirection: "column",
lineHeight: "24px !important",
...spring,
}}
>
<MenuBar id="log-panel-menu-bar" isDragging={isDragging}>
<MenuBar
id="log-panel-menu-bar"
className="log-panel-menu-bar"
isDragging={isDragging}
>
<div
style={{
fontSize: 24,
Expand Down Expand Up @@ -359,6 +374,6 @@ export function LogPanel() {
})}
</SimpleBar>
</animated.div>
</Draggable>
</Rnd>
);
}
1 change: 0 additions & 1 deletion 项目

This file was deleted.

0 comments on commit 381f88d

Please sign in to comment.