-
Notifications
You must be signed in to change notification settings - Fork 293
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e86e83f
commit 2f3986b
Showing
1,300 changed files
with
171 additions
and
63,368 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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import store from "./store"; | ||
|
||
class Shared { | ||
/** | ||
* 获取 Token | ||
*/ | ||
public getToken(): string { | ||
const state = store.getState(); | ||
return state.token || ""; | ||
} | ||
|
||
/** | ||
* 设置 Token | ||
*/ | ||
public setToken(token: string): void { | ||
// 将 token 的值记录在 store 中 | ||
store.dispatch({ | ||
type: "SET_TOKEN", | ||
payload: token | ||
}); | ||
} | ||
} | ||
|
||
const shared = new Shared(); | ||
export default shared; |
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,27 @@ | ||
import { createStore } from "redux"; | ||
|
||
export type State = { | ||
token?: string; | ||
}; | ||
|
||
type Action = { | ||
type: string; | ||
payload: any; | ||
}; | ||
|
||
const reducer = (state: State = {}, action: Action): State => { | ||
switch (action.type) { | ||
default: | ||
return state; | ||
// 设置 Token | ||
case "SET_TOKEN": | ||
return { | ||
...state, | ||
token: action.payload, | ||
}; | ||
} | ||
}; | ||
|
||
const store = createStore<State, Action, unknown, unknown>(reducer); | ||
|
||
export default store; |
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,35 @@ | ||
class Shared { | ||
/** | ||
* 获取 Token | ||
*/ | ||
getToken() { | ||
return localStorage.getItem("token") || ""; | ||
} | ||
|
||
/** | ||
* 设置 Token | ||
*/ | ||
setToken(token) { | ||
localStorage.setItem("token", token); | ||
} | ||
} | ||
|
||
class SharedModule { | ||
static shared = new Shared(); | ||
|
||
/** | ||
* 重载 shared | ||
*/ | ||
static overloadShared(shared) { | ||
SharedModule.shared = shared; | ||
} | ||
|
||
/** | ||
* 获取 shared 实例 | ||
*/ | ||
static getShared() { | ||
return SharedModule.shared; | ||
} | ||
} | ||
|
||
export default SharedModule; |
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,37 @@ | ||
class Shared { | ||
/** | ||
* 获取 Token | ||
*/ | ||
getToken() { | ||
// 子应用独立运行时,在 localStorage 中获取 token | ||
return localStorage.getItem("token") || ""; | ||
} | ||
|
||
/** | ||
* 设置 Token | ||
*/ | ||
setToken(token) { | ||
// 子应用独立运行时,在 localStorage 中设置 token | ||
localStorage.setItem("token", token); | ||
} | ||
} | ||
|
||
class SharedModule { | ||
static shared = new Shared(); | ||
|
||
/** | ||
* 重载 shared | ||
*/ | ||
static overloadShared(shared) { | ||
SharedModule.shared = shared; | ||
} | ||
|
||
/** | ||
* 获取 shared 实例 | ||
*/ | ||
static getShared() { | ||
return SharedModule.shared; | ||
} | ||
} | ||
|
||
export default SharedModule; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.