forked from dataelement/bisheng
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
新增用户管理功能 mvp 版本的部分 bug 修复
- Loading branch information
Showing
31 changed files
with
952 additions
and
276 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "bisheng", | ||
"version": "0.1.2", | ||
"version": "0.0.2", | ||
"private": true, | ||
"dependencies": { | ||
"@emotion/react": "^11.10.5", | ||
|
@@ -71,8 +71,9 @@ | |
"build": "vite build", | ||
"serve": "vite preview", | ||
"format": "npx prettier --write \"**/*.{js,jsx,ts,tsx,json,md}\"", | ||
"test": "scp -r ./src/* [email protected]:/data/langflow/frontend/src", | ||
"test120": "scp -r ./src/* [email protected]:/data/langflow/frontend120/src" | ||
"demo": "scp -r ./build/* [email protected]:/data/webroot/bisheng", | ||
"dev": "scp -r ./build/* [email protected]:/data/webroot/bisheng-dev", | ||
"test": "scp -r ./build/* [email protected]:/data/webroot/bisheng-test" | ||
}, | ||
"eslintConfig": { | ||
"extends": [ | ||
|
@@ -115,6 +116,7 @@ | |
"prettier-plugin-tailwindcss": "^0.3.0", | ||
"tailwindcss": "^3.3.2", | ||
"typescript": "^5.0.2", | ||
"vite-plugin-static-copy": "^0.17.0", | ||
"vite": "^4.3.9" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ import { locationContext } from "./contexts/locationContext"; | |
import { TabsContext } from "./contexts/tabsContext"; | ||
import { LoginPage } from "./pages/login"; | ||
import router from "./routes"; | ||
import { userContext } from "./contexts/userContext"; | ||
|
||
export default function App() { | ||
let { setCurrent, setShowSideBar, setIsStackedOpen } = useContext(locationContext); | ||
|
@@ -121,34 +122,14 @@ export default function App() { | |
); | ||
}; | ||
|
||
const localUserStr = localStorage.getItem('auth') | ||
const localUser = localUserStr ? JSON.parse(atob(localUserStr)) : { name: '', role: '', time: Date.now() } | ||
// if (Date.now() - localUser.time > 10 * 1000) localUser.name = '' | ||
if (Date.now() - localUser.time > 24 * 60 * 60 * 1000) localUser.name = '' | ||
const [user, setUser] = useState(localUser) | ||
const handleLogin = (name, pwd) => { | ||
if (name === '[email protected]' && pwd === 'admin') { | ||
const data = { name: 'bisheng', role: 'admin', time: Date.now() } | ||
setUser(data) | ||
localStorage.setItem('auth', btoa(JSON.stringify(data))) | ||
} else if (name === '[email protected]' && pwd === 'test') { | ||
const data = { name: 'test', role: 'user', time: Date.now() } | ||
setUser(data) | ||
localStorage.setItem('auth', btoa(JSON.stringify(data))) | ||
} else { | ||
setErrorData({ | ||
title: "账号密码不正确: ", | ||
list: [], | ||
}); | ||
} | ||
} | ||
const { user, setUser } = useContext(userContext); | ||
|
||
// 退出 | ||
useEffect(() => { | ||
const handleKeyDown = (event) => { | ||
if (event.ctrlKey && event.keyCode === 81) { | ||
setUser({ name: '', role: '', time: Date.now() }) | ||
localStorage.setItem('auth', '') | ||
setUser(null) | ||
localStorage.setItem('UUR_INFO', '') | ||
} | ||
}; | ||
document.addEventListener('keydown', handleKeyDown); | ||
|
@@ -171,7 +152,7 @@ export default function App() { | |
FallbackComponent={CrashErrorComponent} | ||
> | ||
{/* <Header /> */} | ||
{!user.name ? <LoginPage onLogin={handleLogin}></LoginPage> : <RouterProvider router={router} />} | ||
{user ? <RouterProvider router={router} /> : <LoginPage></LoginPage>} | ||
</ErrorBoundary> | ||
<div></div> | ||
<div className="app-div" style={{ zIndex: 999 }}> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { ReactNode, createContext, useState } from "react"; | ||
|
||
type userContextType = { | ||
user: any; | ||
setUser: (newState: any) => void; | ||
} | ||
|
||
const userInfoLocalStr = localStorage.getItem('UUR_INFO') | ||
const initialValue = { | ||
user: userInfoLocalStr ? JSON.parse(atob(userInfoLocalStr)) : null, | ||
setUser: () => { } | ||
} | ||
|
||
console.log('initialValue :>> ', initialValue); | ||
|
||
export const userContext = createContext<userContextType>(initialValue); | ||
|
||
export function UserProvider({ children }: { children: ReactNode }) { | ||
const [user, setUser] = useState(initialValue.user); | ||
|
||
return ( | ||
<userContext.Provider | ||
value={{ | ||
user, setUser | ||
}} | ||
> | ||
{children} | ||
</userContext.Provider> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.