Skip to content

Commit 6d29be4

Browse files
authored
[type:improve] Optimize namespace (#491)
1 parent d65062e commit 6d29be4

File tree

6 files changed

+64
-69
lines changed

6 files changed

+64
-69
lines changed

src/components/GlobalHeader/index.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import { getCurrentLocale, getIntlContent } from "../../utils/IntlUtils";
3535
import { checkUserPassword } from "../../services/api";
3636
import { emit } from "../../utils/emit";
3737
import { resetAuthMenuCache } from "../../utils/AuthRoute";
38+
import { defaultNamespaceId } from "../_utils/utils";
3839

3940
const TranslationOutlinedSvg = () => (
4041
<svg
@@ -159,23 +160,23 @@ class GlobalHeader extends PureComponent {
159160

160161
handleNamespacesValueChange = (value) => {
161162
const { dispatch } = this.props;
162-
const namespaceId = value?.key || "649330b6-c2d7-4edc-be8e-8a54df9eb385";
163-
window.sessionStorage.setItem("currentNamespaceId", namespaceId);
163+
const namespaceId = value?.key || defaultNamespaceId;
164+
dispatch({
165+
type: "global/saveCurrentNamespaceId",
166+
payload: namespaceId,
167+
});
168+
if (namespaceId !== defaultNamespaceId) {
169+
message.warn(getIntlContent("SHENYU.NAMESPACE.ALERTNAMESPACEID.CHANGED"));
170+
}
164171
dispatch({
165172
type: "global/fetchPermission",
166173
payload: {
174+
namespaceId,
167175
callback: () => {
168176
resetAuthMenuCache();
169177
},
170178
},
171179
});
172-
dispatch({
173-
type: "global/saveCurrentNamespaceId",
174-
payload: value.key,
175-
});
176-
if (value.key !== "649330b6-c2d7-4edc-be8e-8a54df9eb385") {
177-
message.warn(getIntlContent("SHENYU.NAMESPACE.ALERTNAMESPACEID.CHANGED"));
178-
}
179180
};
180181

181182
importConfigClick = () => {

src/components/_utils/utils.ts

Lines changed: 42 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -15,52 +15,55 @@
1515
* limitations under the License.
1616
*/
1717

18+
// 默认 namespaceId
19+
export const defaultNamespaceId = "649330b6-c2d7-4edc-be8e-8a54df9eb385";
20+
1821
// 随机数字
1922
export function randomNum(m: number, n: number) {
20-
return Math.floor(Math.random() * (n - m + 1) + m);
23+
return Math.floor(Math.random() * (n - m + 1) + m);
2124
}
2225

2326
// 随机颜色
2427
export function randomColor() {
25-
return `rgb(${randomNum(0, 255)}, ${randomNum(0, 255)}, ${randomNum(
26-
0,
27-
255
28-
)})`;
28+
return `rgb(${randomNum(0, 255)}, ${randomNum(0, 255)}, ${randomNum(
29+
0,
30+
255,
31+
)})`;
2932
}
3033

3134
export const originalCharacter = [
32-
"1",
33-
"2",
34-
"3",
35-
"4",
36-
"5",
37-
"6",
38-
"7",
39-
"8",
40-
"9",
41-
"a",
42-
"b",
43-
"c",
44-
"d",
45-
"e",
46-
"f",
47-
"g",
48-
"h",
49-
"i",
50-
"j",
51-
"k",
52-
"l",
53-
"m",
54-
"n",
55-
"p",
56-
"q",
57-
"r",
58-
"s",
59-
"t",
60-
"u",
61-
"v",
62-
"w",
63-
"x",
64-
"y",
65-
"z"
35+
"1",
36+
"2",
37+
"3",
38+
"4",
39+
"5",
40+
"6",
41+
"7",
42+
"8",
43+
"9",
44+
"a",
45+
"b",
46+
"c",
47+
"d",
48+
"e",
49+
"f",
50+
"g",
51+
"h",
52+
"i",
53+
"j",
54+
"k",
55+
"l",
56+
"m",
57+
"n",
58+
"p",
59+
"q",
60+
"r",
61+
"s",
62+
"t",
63+
"u",
64+
"v",
65+
"w",
66+
"x",
67+
"y",
68+
"z",
6669
];

src/models/global.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
getUserPermissionByToken,
2626
} from "../services/api";
2727
import { getIntlContent } from "../utils/IntlUtils";
28+
import { defaultNamespaceId } from "../components/_utils/utils";
2829

2930
export default {
3031
namespace: "global",
@@ -37,7 +38,7 @@ export default {
3738
permissions: {},
3839
language: "",
3940
namespaces: [],
40-
currentNamespaceId: "649330b6-c2d7-4edc-be8e-8a54df9eb385",
41+
currentNamespaceId: defaultNamespaceId,
4142
},
4243

4344
effects: {
@@ -57,9 +58,6 @@ export default {
5758
type: "saveNamespaces",
5859
payload: json.data,
5960
});
60-
const namespaceId =
61-
json.data[0]?.namespaceId || "649330b6-c2d7-4edc-be8e-8a54df9eb385";
62-
window.sessionStorage.setItem("currentNamespaceId", namespaceId);
6361
}
6462
},
6563
*fetchPlugins({ payload }, { call, put }) {
@@ -92,11 +90,13 @@ export default {
9290
message.warn(json.message);
9391
}
9492
},
95-
*fetchPermission({ payload }, { call, put }) {
93+
*fetchPermission({ payload }, { call, put, select }) {
9694
const { callback } = payload;
9795
let permissions = { menu: [], button: [] };
9896
const token = window.sessionStorage.getItem("token");
99-
const namespaceId = window.sessionStorage.getItem("currentNamespaceId");
97+
const namespaceId = yield select(
98+
({ global }) => global.currentNamespaceId,
99+
);
100100
if (namespaceId) {
101101
const params = { token, namespaceId };
102102
const json = yield call(getUserPermissionByToken, params);

src/routes/System/Namespace/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import AddModal from "./AddModal";
2323
import { getCurrentLocale, getIntlContent } from "../../../utils/IntlUtils";
2424
import AuthButton from "../../../utils/AuthButton";
2525
import { refreshAuthMenus } from "../../../utils/AuthRoute";
26+
import { defaultNamespaceId } from "../../../components/_utils/utils";
2627

2728
@connect(({ namespace, resource, loading, global }) => ({
2829
namespace,
@@ -201,7 +202,7 @@ export default class Namespace extends Component {
201202
if (deletedCurrentNamespace) {
202203
dispatch({
203204
type: "global/saveCurrentNamespaceId",
204-
payload: "649330b6-c2d7-4edc-be8e-8a54df9eb385",
205+
payload: defaultNamespaceId,
205206
});
206207
}
207208
dispatch({ type: "global/fetchNamespaces" });
@@ -294,8 +295,7 @@ export default class Namespace extends Component {
294295
width: 160,
295296
fixed: "right",
296297
render: (text, record) => {
297-
return record.namespaceId ===
298-
"649330b6-c2d7-4edc-be8e-8a54df9eb385" ? (
298+
return record.namespaceId === defaultNamespaceId ? (
299299
""
300300
) : (
301301
<div className="optionParts">
@@ -357,7 +357,7 @@ export default class Namespace extends Component {
357357
selectedRowKeys,
358358
onChange: this.onSelectChange,
359359
getCheckboxProps: (record) => ({
360-
disabled: record.namespaceId === "649330b6-c2d7-4edc-be8e-8a54df9eb385",
360+
disabled: record.namespaceId === defaultNamespaceId,
361361
}),
362362
};
363363
const flatList = (map, list) => {

src/routes/System/User/DataPermModal.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import {
3333
import { connect } from "dva";
3434
import { getIntlContent } from "../../../utils/IntlUtils";
3535
import { titleCase } from "../../../utils/utils";
36+
import { defaultNamespaceId } from "../../../components/_utils/utils";
3637

3738
const { TreeNode } = Tree;
3839
const { Search } = Input;
@@ -57,7 +58,7 @@ export default class DataPermModal extends Component {
5758
pageSize: 12,
5859
ruleListMap: {},
5960
searchValue: "",
60-
currentNamespaceId: "649330b6-c2d7-4edc-be8e-8a54df9eb385",
61+
currentNamespaceId: defaultNamespaceId,
6162
selectorExpandedRowKeys: [],
6263
};
6364
}

src/services/api.js

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -814,16 +814,6 @@ export async function getUserPermissionByToken(params) {
814814
);
815815
}
816816

817-
// get userPermission
818-
export async function getUserPermission(params) {
819-
return request(
820-
`${baseUrl}/permission/getUserPermissionByToken?namespaceId=${params.namespaceId}`,
821-
{
822-
method: `GET`,
823-
},
824-
);
825-
}
826-
827817
/* get dataPermision's selectors by page */
828818
export async function getDataPermisionSelectors(params) {
829819
return request(`${baseUrl}/data-permission/selector?${stringify(params)}`, {

0 commit comments

Comments
 (0)